2 * Copyright 2005-2008, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
4 * This file is part of Coccinelle.
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
25 (*****************************************************************************)
27 (*****************************************************************************)
29 (* In addition to flags that can be tweaked via -xxx options (cf the
30 * full list of options in "the spatch options" section below), the
31 * spatch program also depends on external files, described in
32 * globals/config.ml, mainly a standard.h and standard.iso file *)
34 let cocci_file = ref ""
36 let output_file = ref ""
37 let inplace_modif = ref false (* but keeps a .cocci_orig *)
38 let outplace_modif = ref false (* generates a .cocci_res *)
40 (* could be avoided by using Common.files_of_dir_or_files instead *)
43 let include_headers = ref false
44 let kbuild_info = ref ""
47 let test_mode = ref false
48 let test_all = ref false
49 let test_okfailed = ref false
50 let test_regression_okfailed = ref false
56 (* works with -test but also in "normal" spatch mode *)
57 let compare_with_expected = ref false
60 let distrib_index = ref (None
: int option)
61 let distrib_max = ref (None
: int option)
62 let mod_distrib = ref false
65 (*****************************************************************************)
67 (*****************************************************************************)
69 (* pair of (list of flags to set true, list of flags to set false *)
74 (* Flag_cocci.show_diff; just leave this as it is *)
80 Flag_cocci.show_cocci
;
82 Flag_cocci.show_before_fixed_flow
;
83 Flag_cocci.show_ctl_tex
;
84 Flag_cocci.show_ctl_text
;
85 Flag_cocci.show_transinfo
;
86 Flag_cocci.show_binding_in_out
;
88 Flag_parsing_cocci.show_SP
;
89 Flag_parsing_cocci.show_iso_failures
;
90 Flag_ctl.verbose_ctl_engine
;
91 Flag_ctl.verbose_match
;
92 Flag_matcher.debug_engine
;
93 Flag_parsing_c.debug_unparsing
;
94 Flag_parsing_c.verbose_type
;
95 Flag_parsing_c.verbose_parsing
;
100 Flag_cocci.show_diff
;
107 Flag_cocci.show_cocci
;
108 Flag_cocci.show_flow
;
109 Flag_cocci.show_before_fixed_flow
;
110 Flag_cocci.show_ctl_tex
;
111 Flag_cocci.show_ctl_text
;
112 Flag_cocci.show_transinfo
;
113 Flag_cocci.show_binding_in_out
;
115 Flag_parsing_cocci.show_SP
;
116 Flag_parsing_cocci.show_iso_failures
;
117 Flag_ctl.verbose_ctl_engine
;
118 Flag_ctl.verbose_match
;
119 Flag_matcher.debug_engine
;
120 Flag_parsing_c.debug_unparsing
;
121 Flag_parsing_c.verbose_type
;
122 Flag_parsing_c.verbose_parsing
;
125 (*****************************************************************************)
126 (* The spatch options *)
127 (*****************************************************************************)
130 "Usage: " ^ basename
Sys.argv
.(0) ^
131 " -sp_file <SP> <infile> [-o <outfile>] [-iso_file <iso>] [options]" ^
132 "\n" ^
"Options are:"
134 (* forward reference trick *)
135 let short_usage_func = ref (fun () -> ())
136 let long_usage_func = ref (fun () -> ())
139 (* The short_options are user-oriented. The other options are for
140 * the developers of coccinelle or advanced-users that know
141 * quite well the underlying semantics of coccinelle.
145 (* will be printed when use only ./spatch. For the rest you have to
146 * use -longhelp to see them.
148 let short_options = [
149 "-sp_file", Arg.Set_string
cocci_file,
150 " <file> the semantic patch file";
152 "-o", Arg.Set_string
output_file,
153 " <file> the output file";
154 "-inplace", Arg.Set
inplace_modif,
155 " do the modification on the file directly";
156 "-outplace", Arg.Set
outplace_modif,
157 " store modifications in a .cocci_res file";
159 "-U", Arg.Int
(fun n
-> Flag_parsing_c.diff_lines
:= Some
(i_to_s n
)),
160 " set number of diff context lines";
161 "-partial_match", Arg.Set
Flag_ctl.partial_match
,
162 " report partial matches of the SP on the C file";
164 "-iso_file", Arg.Set_string
Config.std_iso
,
165 " <file> (default=" ^
!Config.std_iso ^
")";
166 "-macro_file", Arg.Set_string
Config.std_h
,
167 " <file> (default=" ^
!Config.std_h ^
")";
169 "-all_includes", Arg.Set
Flag_cocci.all_includes
,
170 " causes all available include files to be used";
171 "-no_includes", Arg.Set
Flag_cocci.no_includes
,
172 " causes not even local include files to be used";
173 "-I", Arg.Set_string
Flag_cocci.include_path
,
174 " <dir> containing the Linux headers (optional)";
178 " <dir> process all files in directory recursively";
180 "-include_headers", Arg.Set
include_headers,
181 " process header files independently";
182 "-use_glimpse", Arg.Set
Flag.use_glimpse
,
183 " works with -dir, use info generated by glimpseindex";
184 "-patch", Arg.String
(function s
-> Flag.patch
:= Some s
),
185 (" <dir> path name with respect to which a patch should be created\n"^
186 " \"\" for a file in the current directory");
187 "-kbuild_info", Arg.Set_string
kbuild_info,
188 " <file> improve -dir by grouping related c files";
189 "-pyoutput", Arg.Set_string
Flag.pyoutput
,
190 " Sets output routine: Standard values: <coccilib.output.Gtk|coccilib.output.Console>";
193 "-version", Arg.Unit
(fun () ->
194 pr2
(spf
"spatch version: %s" Config.version
);
199 "-date", Arg.Unit
(fun () ->
200 pr2
"version: $Date: 2008/11/18 20:37:55 $";
201 raise
(Common.UnixExit
0)
205 "-shorthelp", Arg.Unit
(fun () ->
207 raise
(Common.UnixExit
0)
209 " see short list of options";
210 "-longhelp", Arg.Unit
(fun () ->
212 raise
(Common.UnixExit
0)
214 " see all the available options in different categories";
215 "-help", Arg.Unit
(fun () ->
217 raise
(Common.UnixExit
0)
220 "--help", Arg.Unit
(fun () ->
222 raise
(Common.UnixExit
0)
228 (* the format is a list of triples:
229 * (title of section * (optional) explanation of sections * option list)
231 let other_options = [
232 "aliases and obsolete options",
235 "-cocci_file", Arg.Set_string
cocci_file,
236 " <file> the semantic patch file";
237 "-c", Arg.Set_string
cocci_file, " short option of -cocci_file";
238 "-iso", Arg.Set_string
Config.std_iso
, " short option of -iso_file";
239 "-D", Arg.Set_string
Config.std_h
, " short option of -macro_file";
242 "most useful show options",
245 "-show_diff" , Arg.Set
Flag_cocci.show_diff
, " ";
246 "-no_show_diff" , Arg.Clear
Flag_cocci.show_diff
, " ";
247 "-show_flow" , Arg.Set
Flag_cocci.show_flow
, " ";
248 "-no_show_ctl_text" , Arg.Clear
Flag_cocci.show_ctl_text
, " ";
249 (* works in conjunction with -show_ctl *)
250 "-ctl_inline_let", Arg.Set
Flag_cocci.inline_let_ctl
, " ";
251 "-ctl_show_mcodekind", Arg.Set
Flag_cocci.show_mcodekind_in_ctl
, " ";
252 "-show_binding_in_out", Arg.Set
Flag_cocci.show_binding_in_out
, " ";
253 "-no_show_transinfo", Arg.Clear
Flag_cocci.show_transinfo
, " ";
254 "-no_show_misc", Arg.Clear
Flag.show_misc
, " ";
255 "-show_trying", Arg.Set
Flag.show_trying
,
256 " show the name of each function being processed";
257 "-show_dependencies",
258 Arg.Unit
(function _
-> Flag_cocci.show_dependencies
:= true;
259 Flag_cocci.show_binding_in_out
:= true),
260 " show the dependencies related to each rule";
263 "verbose subsystems options",
266 "-verbose_ctl_engine", Arg.Set
Flag_ctl.verbose_ctl_engine
, " ";
267 "-verbose_match", Arg.Set
Flag_ctl.verbose_match
, " ";
268 "-verbose_engine", Arg.Set
Flag_matcher.debug_engine
, " ";
269 "-graphical_trace", Arg.Set
Flag_ctl.graphical_trace
, " generate a pdf file representing the matching process";
270 "-gt_without_label", Arg.Set
Flag_ctl.gt_without_label
, " remove graph label (requires option -graphical_trace)";
272 "-no_parse_error_msg", Arg.Clear
Flag_parsing_c.verbose_parsing
, " ";
273 "-no_type_error_msg", Arg.Clear
Flag_parsing_c.verbose_type
, " ";
274 (* could also use Flag_parsing_c.options_verbose *)
277 "other show options",
280 "-show_c" , Arg.Set
Flag_cocci.show_c
, " ";
281 "-show_cocci" , Arg.Set
Flag_cocci.show_cocci
, " ";
282 "-show_before_fixed_flow" , Arg.Set
Flag_cocci.show_before_fixed_flow
, " ";
283 "-show_ctl_tex" , Arg.Set
Flag_cocci.show_ctl_tex
, " ";
284 "-show_SP_julia" , Arg.Set
Flag_parsing_cocci.show_SP
, " ";
288 "debug C parsing/unparsing",
291 "-debug_cpp", Arg.Set
Flag_parsing_c.debug_cpp
, " ";
292 "-debug_lexer", Arg.Set
Flag_parsing_c.debug_lexer
, " ";
293 "-debug_etdt", Arg.Set
Flag_parsing_c.debug_etdt
, " ";
294 "-debug_typedef", Arg.Set
Flag_parsing_c.debug_typedef
, " ";
296 "-filter_msg", Arg.Set
Flag_parsing_c.filter_msg
,
297 " filter some cpp message when the macro is a \"known\" cpp construct";
298 "-filter_define_error",Arg.Set
Flag_parsing_c.filter_define_error
," ";
299 "-filter_passed_level", Arg.Set_int
Flag_parsing_c.filter_passed_level
," ";
301 "-debug_cfg", Arg.Set
Flag_parsing_c.debug_cfg
, " ";
302 "-debug_unparsing", Arg.Set
Flag_parsing_c.debug_unparsing
, " ";
305 (* could use Flag_parsing_c.options_debug_with_title instead *)
308 "shortcut for enabling/disabling a set of debugging options at once",
311 (* todo: other profile ? *)
312 "-quiet", Arg.Unit
(fun () ->
313 let (set_to_true
, set_to_false
) = quiet_profile in
314 List.iter
(fun x
-> x
:= false) set_to_false
;
315 List.iter
(fun x
-> x
:= true) set_to_true
;
318 "-pad", Arg.Unit
(fun () ->
319 let (set_to_true
, set_to_false
) = pad_profile in
320 List.iter
(fun x
-> x
:= false) set_to_false
;
321 List.iter
(fun x
-> x
:= true) set_to_true
;
329 "-profile", Arg.Unit
(function () -> Common.profile
:= Common.PALL
) ,
330 " gather timing information about the main coccinelle functions";
331 "-bench", Arg.Int
(function x
-> Flag_ctl.bench
:= x
),
332 " <level> for profiling the CTL engine";
333 "-timeout", Arg.Int
(fun x
-> Flag_cocci.timeout
:= Some x
),
334 " <sec> timeout in seconds";
335 "-steps", Arg.Int
(fun x
-> Flag_ctl.steps
:= Some x
),
336 " max number of model checking steps per code unit";
337 "-track_iso", Arg.Set
Flag.track_iso_usage
,
338 " gather information about isomorphism usage";
342 Common.profile
:=PSOME
["parse cocci";"mysat";"asttoctl2";"full_engine"]),
343 " gather information about the cost of isomorphism usage"
348 "change of algorithm options",
351 "-popl", Arg.Set
Flag_cocci.popl
,
352 " simplified SmPL, for the popl paper";
356 (function _
-> Flag_cocci.popl
:= true; Flag_popl.mark_all
:= true),
357 " simplified SmPL, for the popl paper";
359 "-popl_keep_all_wits",
361 (function _
-> Flag_cocci.popl
:= true; Flag_popl.keep_all_wits
:= true),
362 " simplified SmPL, for the popl paper";
364 "-hrule", Arg.String
(function s
-> Flag.make_hrule
:= Some s
),
365 " semantic patch generation";
367 "-loop", Arg.Set
Flag_ctl.loop_in_src_code
, " ";
369 "-l1", Arg.Clear
Flag_parsing_c.label_strategy_2
, " ";
370 "-ifdef_to_if", Arg.Set
Flag_cocci.ifdef_to_if
,
371 " convert ifdef to if (experimental)";
373 "-noif0_passing", Arg.Clear
Flag_parsing_c.if0_passing
,
375 "-noadd_typedef_root", Arg.Clear
Flag_parsing_c.add_typedef_root
, " ";
376 (* could use Flag_parsing_c.options_algo instead *)
379 "-disallow_nested_exps", Arg.Set
Flag_matcher.disallow_nested_exps
,
380 "disallow an expresion pattern from matching a term and its subterm";
381 "-disable_worth_trying_opt", Arg.Clear
Flag_cocci.worth_trying_opt
,
383 "-only_return_is_error_exit",
384 Arg.Set
Flag_matcher.only_return_is_error_exit
,
385 "if this flag is not set, then break and continue are also error exits";
386 (* the following is a hack to make it easier to add code in sgrep-like
387 code, essentially to compensate for the fact that we don't have
388 any way of printing things out *)
389 "-allow_inconsistent_paths",
390 Arg.Set
Flag_matcher.allow_inconsistent_paths
,
391 "if this flag is set don't check for inconsistent paths; dangerous";
397 "-debugger", Arg.Set
Common.debugger
,
398 " option to set if launch spatch in ocamldebug";
399 "-disable_once", Arg.Set
Common.disable_pr2_once
,
400 " to print more messages";
401 "-save_tmp_files", Arg.Set
Common.save_tmp_files
, " ";
407 "-index", Arg.Int
(function x
-> distrib_index := Some x
) ,
408 " the processor to use for this run of spatch";
409 "-max", Arg.Int
(function x
-> distrib_max := Some x
) ,
410 " the number of processors available";
411 "-mod_distrib", Arg.Set
mod_distrib,
412 " use mod to distribute files among the processors";
418 "-use_cache", Arg.Set
Flag_parsing_c.use_cache
,
419 " use .ast_raw pre-parsed cached C file";
420 (* could use Flag_parsing_c.options_pad instead *)
425 "test mode and test options (works with tests/ or .ok files)",
426 "The test options don't work with the -sp_file and so on.",
428 "-test", Arg.Set
test_mode,
429 " <file> launch spatch on tests/file.[c,cocci]";
430 "-testall", Arg.Set
test_all,
431 " launch spatch on all files in tests/ having a .res";
432 "-test_okfailed", Arg.Set
test_okfailed,
433 " generates .{ok,failed,spatch_ok} files using .res files";
434 "-test_regression_okfailed", Arg.Set
test_regression_okfailed,
435 " process the .{ok,failed,spatch_ok} files in current dir";
437 "-compare_with_expected", Arg.Set
compare_with_expected,
438 " use also file.res";
439 "-relax_include_path", Arg.Set
Flag_cocci.relax_include_path
,
445 ("The action options don't work with the -sp_file and so on." ^
"\n" ^
446 "It's for the other (internal) uses of the spatch program."
449 (* -token_c, -parse_c, etc *)
450 ((Common.options_of_actions
action (Test_parsing_c.actions
())) ++
452 (let s = "-parse_cocci" in s, Arg.Unit
(fun () -> action := s),
454 (let s = "-compare_c" in s, Arg.Unit
(fun () -> action := s),
461 short_options ++ List.concat
(List.map
Common.thd3
other_options)
465 (* I don't want the -help and --help that are appended by Arg.align *)
467 Arg.align xs
+> List.rev
+> Common.drop
2 +> List.rev
469 (* copy paste of Arg.parse. Don't want the default -help msg *)
470 let arg_parse2 l f msg
=
472 Arg.parse_argv
Sys.argv l f msg
;
474 | Arg.Bad msg
-> (* eprintf "%s" msg; exit 2; *)
475 let xs = Common.lines msg
in
476 (* take only head, it's where the error msg is *)
479 raise
(Common.UnixExit
(2))
480 | Arg.Help msg
-> (* printf "%s" msg; exit 0; *)
481 raise Impossible
(* -help is specified in speclist *)
487 Common.short_usage usage_msg short_options;
489 pr2
"Example of use:";
490 pr2
" ./spatch -sp_file foo.cocci foo.c -o /tmp/newfoo.c";
496 Common.long_usage usage_msg short_options other_options
498 let _ = short_usage_func := short_usage
499 let _ = long_usage_func := long_usage
501 (*****************************************************************************)
503 (*****************************************************************************)
505 let adjust_stdin cfile k
=
511 let (dir, base
, ext
) = Common.dbe_of_filename cfile
in
512 let varfile = Common.filename_of_dbe
(dir, base
, "var") in
513 if ext
= "c" && Common.lfile_exists
varfile
516 with Invalid_argument
("Filename.chop_extension") -> None
518 Common.redirect_stdin_opt
newin k
520 let glimpse_filter (coccifile
, isofile
) dir =
521 let (astcocci
,_free_var_lists
,_negated_positions
,
522 _used_after_lists
,_positions_lists
,_,query
) =
523 Cocci.sp_of_file coccifile
(Some isofile
) in
525 None
-> pr2
"no glimpse keyword infered from snippet"; None
527 let suffixes = if !include_headers then ["c";"h"] else ["c"] in
528 pr2
("glimpse request = " ^ query
);
529 let command = spf
"glimpse -y -H %s -N -W -w '%s'" dir query
in
530 let (glimpse_res
,stat
) = Common.cmd_to_list_and_status
command in
532 Unix.WEXITED
(0) | Unix.WEXITED
(1) ->
536 (fun file
-> List.mem
(Common.filesuffix file
) suffixes))
537 | _ -> None
(* error, eg due to pattern too big *)
542 (*****************************************************************************)
543 (* The coccinelle main entry point *)
544 (*****************************************************************************)
549 arg_parse2 (Arg.align
all_options) (fun x
-> args := x
::!args) usage_msg;
551 (if !dir && List.length
!args > 1
554 let chosen = List.hd
!args in
555 pr2
("ignoring all but the last specified directory: "^
chosen);
558 args := List.rev
!args;
560 (if !Flag_cocci.all_includes
&& !Flag_cocci.no_includes
561 then failwith
"cannot set both all_includes and no_includes");
563 if !cocci_file <> "" && (not
(!cocci_file =~
".*\\.\\(sgrep\\|spatch\\)$"))
564 then cocci_file := Common.adjust_ext_if_needed
!cocci_file ".cocci";
566 if !Config.std_iso
<> ""
567 then Config.std_iso
:= Common.adjust_ext_if_needed
!Config.std_iso
".iso";
568 if !Config.std_h
<> ""
569 then Config.std_h
:= Common.adjust_ext_if_needed
!Config.std_h
".h";
571 if !Config.std_h
<> ""
572 then Parse_c.init_defs
!Config.std_h
;
575 (* must be done after Arg.parse, because Common.profile is set by it *)
576 Common.profile_code
"Main total" (fun () ->
579 let all_actions = Test_parsing_c.actions
() in
583 (* --------------------------------------------------------- *)
584 (* The test framework. Works with tests/ or .ok and .failed *)
585 (* --------------------------------------------------------- *)
586 | [x
] when !test_mode ->
587 Flag_cocci.include_path
:= "tests/include";
588 Testing.testone x
!compare_with_expected
590 | [] when !test_all ->
591 Flag_cocci.include_path
:= "tests/include";
594 | [] when !test_regression_okfailed ->
595 Testing.test_regression_okfailed ()
597 | x
::xs when !test_okfailed ->
598 (* do its own timeout on Flag_cocci.timeout internally *)
599 Flag_cocci.relax_include_path
:= true;
600 adjust_stdin x
(fun () ->
601 Testing.test_okfailed !cocci_file (x
::xs)
604 (* --------------------------------------------------------- *)
605 (* Actions, useful to debug subpart of coccinelle *)
606 (* --------------------------------------------------------- *)
608 | xs when List.mem
!action (Common.action_list
all_actions) ->
609 Common.do_action
!action xs all_actions
611 | [file
] when !action = "-parse_cocci" ->
612 Testing.test_parse_cocci file
614 (* I think this is used by some scripts in some Makefile for our
615 * big-tests. So dont remove.
617 | [file1
;file2
] when !action = "-compare_c" ->
618 Test_parsing_c.test_compare_c file1 file2
(* result = unix code *)
620 (* could add the Test_parsing_c.test_actions such as -parse_c & co *)
623 (* --------------------------------------------------------- *)
624 (* This is the main entry *)
625 (* --------------------------------------------------------- *)
627 adjust_stdin x
(fun () ->
629 then failwith
"I need a cocci file, use -sp_file <file>";
631 if !dir && !Flag.patch
= None
634 | [] -> Flag.patch
:= Some x
637 ("warning: patch output can only be created when only one\n"^
638 "directory is specified or when the -patch flag is used")
642 Common.profile_code
"Main.infiles computation" (fun () ->
643 match !dir, !kbuild_info, !Flag.use_glimpse
with
646 failwith
"-use_glimpse works only with -dir"
647 | true, s, true when s <> "" ->
648 failwith
"-use_glimpse does not work with -kbuild"
651 then failwith
"-use_glimpse can accept only one dir";
654 match glimpse_filter (!cocci_file, !Config.std_iso
) x
with
656 Common.cmd_to_list
(* same as "true, "", _" case *)
658 then ("find "^
(join
" " (x
::xs))^
" -name \"*.[ch]\"")
659 else ("find "^
(join
" " (x
::xs))^
" -name \"*.c\""))
660 | Some
files -> files in
661 files +> List.map
(fun x
-> [x
])
663 | false, _, _ -> [x
::xs]
667 then ("find "^
(join
" " (x
::xs))^
" -name \"*.[ch]\"")
668 else ("find "^
(join
" " (x
::xs))^
" -name \"*.c\""))
669 +> List.map
(fun x
-> [x
])
672 | true, kbuild_info_file
,_ ->
674 Common.cmd_to_list
("find "^
(join
" " (x
::xs))^
" -type d")
676 let info = Kbuild.parse_kbuild_info kbuild_info_file
in
677 let groups = Kbuild.files_in_dirs
dirs info in
679 groups +> List.map
(function Kbuild.Group
xs -> xs)
684 match (!distrib_index,!distrib_max) with
685 (None
,None
) -> infiles
686 | (Some index
,Some max
) ->
689 failwith
"index starts at 0, and so must be less than max");
692 let rec loop ct
= function
695 if (ct
mod max
) = index
696 then x
::(loop (ct
+1) xs)
697 else loop (ct
+1) xs in
701 let all_files = List.length
infiles in
702 let regions = (all_files + (max
- 1)) / max
in
703 let this_min = index
* regions in
704 let this_max = (index
+1) * regions in
705 let rec loop ct
= function
708 if this_min <= ct
&& ct
< this_max
709 then x
::(loop (ct
+1) xs)
710 else loop (ct
+1) xs in
713 | _ -> failwith
"inconsistent distribution information" in
716 Common.profile_code
"Main.outfiles computation" (fun () ->
717 infiles +> List.map
(fun cfiles
->
718 pr2
("HANDLING: " ^
(join
" " cfiles
));
719 Common.timeout_function_opt
!Flag_cocci.timeout
(fun () ->
720 Common.report_if_take_time
10 (join
" " cfiles
) (fun () ->
723 (* this is the main call *)
724 Cocci.full_engine
(!cocci_file, !Config.std_iso
) cfiles
726 | Common.UnixExit x
-> raise
(Common.UnixExit x
)
730 pr2
("EXN:" ^
Printexc.to_string e
);
737 Common.profile_code
"Main.result analysis" (fun () ->
739 Ctlcocci_integration.print_bench
();
741 let outfiles = Cocci.check_duplicate_modif
outfiles in
743 outfiles +> List.iter
(fun (infile
, outopt
) ->
744 outopt
+> Common.do_option
(fun outfile
->
747 Common.command2
("cp "^infile^
" "^infile^
".cocci_orig");
748 Common.command2
("cp "^outfile^
" "^infile
);
752 then Common.command2
("cp "^outfile^
" "^infile^
".cocci_res");
756 let tmpfile = "/tmp/"^
Common.basename infile
in
757 pr2
(spf
"One file modified. Result is here: %s" tmpfile);
758 Common.command2
("cp "^outfile^
" "^
tmpfile);
761 if !output_file <> "" then
763 | [infile
, Some outfile
] when infile
= x
&& null
xs ->
764 Common.command2
("cp " ^outfile^
" " ^
!output_file);
765 | [infile
, None
] when infile
= x
&& null
xs ->
766 Common.command2
("cp " ^infile^
" " ^
!output_file);
769 ("-o can not be applied because there is multiple " ^
773 if !compare_with_expected
774 then Testing.compare_with_expected outfiles))
776 (* --------------------------------------------------------- *)
778 (* --------------------------------------------------------- *)
779 | [] -> short_usage()
782 if !Pycocci.initialised
&& (Pycocci.py_isinitialized
()) != 0 then begin
783 ignore
(Pycocci.pyrun_simplestring
"cocci.finalise()");
785 then Common.pr2
"Finalizing python\n";
786 Pycocci.py_finalize
();
790 (*****************************************************************************)
792 Common.main_boilerplate
(fun () ->
794 Ctlcocci_integration.print_bench
();