When spatch is given the name of a directory as an option it will run the semantic patch on every source file in that directory. If the semantic patch file starts with a Python action, then this action will be executed just prior to the processing of every source file. Similarly if the patch file ends with a Python action, then this will be executed at the end of processing of every source file.
The following semantic patch will delimit the output from each source file by “Starting new file”/“Finished file”.
@
script:python @
@@
print "Starting new file"
@ if_stmt1
disable neg_if
@
expression E_1;
statement S_1, S_e;
position p_1;
@@
if@p_1 (E_1)
S_1
else
S_e
@
script:python @
expr_1 << if_stmt1.E_1;
loc_1 << if_stmt1.p_1;
@@
print loc_1[0].line, " ", expr_1
@
script:python @
@@
print "Finished file"