Coccinelle release-1.0.0-rc11
[bpt/coccinelle.git] / main.ml
diff --git a/main.ml b/main.ml
index 2dca9d2..eb58708 100644 (file)
--- a/main.ml
+++ b/main.ml
@@ -1,5 +1,7 @@
 (*
- * Copyright 2010, INRIA, University of Copenhagen
+ * Copyright 2012, INRIA
+ * Julia Lawall, Gilles Muller
+ * Copyright 2010-2011, INRIA, University of Copenhagen
  * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
  * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
  * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
@@ -250,7 +252,7 @@ let run_profile p =
 
 let usage_msg =
   "Usage: " ^ basename Sys.argv.(0) ^
-    " -sp_file <SP> <infile> [-o <outfile>] [-iso_file <iso>] [options]" ^
+    " --sp-file <SP> <infile> [-o <outfile>] [--iso-file <iso>] [options]" ^
     "\n" ^ "Options are:"
 
 (* forward reference trick *)
@@ -268,76 +270,76 @@ let long_usage_func  = ref (fun () -> ())
  * use -longhelp to see them.
  *)
 let short_options = [
-  "-sp_file",  Arg.Set_string cocci_file,
+  "--sp-file",  Arg.Set_string cocci_file,
   " <file> the semantic patch file";
 
   "-o", Arg.Set_string output_file,
   "   <file> the output file";
-  "-in_place", Arg.Set inplace_modif,
+  "--in-place", Arg.Set inplace_modif,
   "   do the modification on the file directly";
-  "-backup_suffix", Arg.String (function s -> backup_suffix := Some s),
+  "--backup-suffix", Arg.String (function s -> backup_suffix := Some s),
   "   suffix to use when making a backup for inplace";
-  "-out_place", Arg.Set outplace_modif,
+  "--out-place", Arg.Set outplace_modif,
   "   store modifications in a .cocci_res file";
 
   "-U", Arg.Int (fun n -> Flag_parsing_c.diff_lines := Some (i_to_s n)),
   "  set number of diff context lines";
-  "-partial_match",        Arg.Set Flag_ctl.partial_match,
+  "--partial-match",        Arg.Set Flag_ctl.partial_match,
   "    report partial matches of the SP on the C file";
 
-  "-iso_file", Arg.Set_string Config.std_iso,
+  "--iso-file", Arg.Set_string Config.std_iso,
   " <file> (default=" ^ !Config.std_iso ^")";
-  "-macro_file", Arg.Set_string macro_file,
+  "--macro-file", Arg.Set_string macro_file,
   " <file>";
-  "-macro_file_builtins", Arg.Set_string Config.std_h,
+  "--macro-file-builtins", Arg.Set_string Config.std_h,
   " <file> (default=" ^ !Config.std_h ^ ")";
 
-  "-recursive_includes",
+  "--recursive-includes",
   Arg.Unit (function _ -> FC.include_options := FC.I_REALLY_ALL_INCLUDES),
   "  causes all available include files, both those included in the C file(s) and those included in header files, to be used";
-  "-all_includes",
+  "--all-includes",
   Arg.Unit (function _ -> FC.include_options := FC.I_ALL_INCLUDES),
   "  causes all available include files included in the C file(s) to be used";
-  "-no_includes",
+  "--no-includes",
   Arg.Unit (function _ -> FC.include_options := FC.I_NO_INCLUDES),
   "  causes not even local include files to be used";
-  "-local_includes",
+  "--local-includes",
   Arg.Unit (function _ -> FC.include_options := FC.I_NORMAL_INCLUDES),
   "  causes local include files to be used";
-  "-ignore_unknown_options", Arg.Set ignore_unknown_opt,
+  "--ignore-unknown-options", Arg.Set ignore_unknown_opt,
   "    For integration in a toolchain (must be set before the first unknown option)";
-  "-include_headers", Arg.Set include_headers,
+  "--include-headers", Arg.Set include_headers,
   "    process header files independently";
   "-I",   Arg.String (fun x ->
                        FC.include_path:= x::!FC.include_path
                     ),
   "  <dir> containing the header files (optional)";
 
-  "-preprocess", Arg.Set preprocess,
+  "--preprocess", Arg.Set preprocess,
   " run the C preprocessor before applying the semantic match";
 
   "-c", Arg.Set compat_mode, " gcc/cpp compatibility mode";
 
-  "-dir", Arg.Set dir,
+  "--dir", Arg.Set dir,
   "    <dir> process all files in directory recursively";
 
-  "-use_glimpse", Arg.Unit (function _ -> Flag.scanner := Flag.Glimpse),
+  "--use-glimpse", Arg.Unit (function _ -> Flag.scanner := Flag.Glimpse),
   "    works with -dir, use info generated by glimpseindex";
-  "-use_google", Arg.String (function s -> Flag.scanner := Flag.Google s),
+  "--use-google", Arg.String (function s -> Flag.scanner := Flag.Google s),
   "    find relevant files using google code search";
-  "-use_idutils", Arg.Unit (function s -> Flag.scanner := Flag.IdUtils),
+  "--use-idutils", Arg.Unit (function s -> Flag.scanner := Flag.IdUtils),
   "    find relevant files using id-utils";
-  "-patch",
+  "--patch",
     Arg.String (function s -> Flag.patch := Some (Cocci.normalize_path s)),
   ("    <dir> path name with respect to which a patch should be created\n"^
    "    \"\" for a file in the current directory");
-  "-kbuild_info", Arg.Set_string kbuild_info,
+  "--kbuild-info", Arg.Set_string kbuild_info,
   "    <file> improve -dir by grouping related c files";
-  "-pyoutput", Arg.Set_string Flag.pyoutput,
+  "--pyoutput", Arg.Set_string Flag.pyoutput,
   "    Sets output routine: Standard values: <coccilib.output.Gtk|coccilib.output.Console>";
 
 
-  "-version",   Arg.Unit (fun () ->
+  "--version",   Arg.Unit (fun () ->
     let withpython = if Pycocci.python_support then "with" else "without" in
     let whichregexp =
       if !Regexp.pcre_support then "with PCRE support"
@@ -348,18 +350,18 @@ let short_options = [
   ),
     "  guess what";
 
-  "-date",   Arg.Unit (fun () ->
+  "--date",   Arg.Unit (fun () ->
     pr2 "version: $Date$";
     raise (Common.UnixExit 0)
     ),
   "   guess what";
 
-  "-shorthelp", Arg.Unit (fun () ->
+  "--shorthelp", Arg.Unit (fun () ->
     !short_usage_func();
     raise (Common.UnixExit 0)
   ),
   "    see short list of options";
-  "-longhelp", Arg.Unit (fun () ->
+  "--longhelp", Arg.Unit (fun () ->
     !long_usage_func();
     raise (Common.UnixExit 0)
     ),
@@ -383,10 +385,11 @@ let other_options = [
   "aliases and obsolete options",
   "",
   [
-    "-sp", Arg.Set_string cocci_file,     " short option of -sp_file";
-    "-iso", Arg.Set_string Config.std_iso,   " short option of -iso_file";
+    "--sp", Arg.Unit (function _ -> failwith "impossible"),
+    " command line semantic patch";
+    "--iso", Arg.Set_string Config.std_iso,   " short option of --iso-file";
 
-    "-cocci_file", Arg.Set_string cocci_file,
+    "--cocci-file", Arg.Set_string cocci_file,
     "   <file> the semantic patch file";
 (*     "-c", Arg.Set_string cocci_file,     " short option of -sp_file"; *)
   ];
@@ -394,25 +397,25 @@ let other_options = [
   "most useful show options",
   "",
   [
-    "-show_diff"           , Arg.Set FC.show_diff, " ";
-    "-no_show_diff"           , Arg.Clear FC.show_diff, " ";
-    "-force_diff"           , Arg.Set FC.force_diff,
+    "--show-diff"           , Arg.Set FC.show_diff, " ";
+    "--no-show-diff"           , Arg.Clear FC.show_diff, " ";
+    "--force-diff"           , Arg.Set FC.force_diff,
        "show diff even if only spacing changes";
-    "-show_flow"              , Arg.Set FC.show_flow,        " ";
+    "--show-flow"              , Arg.Set FC.show_flow,        " ";
     (* works in conjunction with -show_ctl_text *)
-    "-ctl_inline_let",
+    "--ctl-inline-let",
     Arg.Unit
     (function _ -> FC.show_ctl_text := true; FC.inline_let_ctl := true), " ";
-    "-ctl_show_mcodekind",
+    "--ctl-show-mcodekind",
     Arg.Unit
     (function _ -> FC.show_ctl_text := true; FC.show_mcodekind_in_ctl := true),
     " ";
-    "-show_bindings",        Arg.Set FC.show_binding_in_out, " ";
-    "-show_transinfo",    Arg.Set Flag.show_transinfo, " ";
-    "-show_misc",         Arg.Set Flag.show_misc, " ";
-    "-show_trying",          Arg.Set Flag.show_trying,
+    "--show-bindings",        Arg.Set FC.show_binding_in_out, " ";
+    "--show-transinfo",    Arg.Set Flag.show_transinfo, " ";
+    "--show-misc",         Arg.Set Flag.show_misc, " ";
+    "--show-trying",          Arg.Set Flag.show_trying,
     " show the name of each function being processed";
-    "-show_dependencies",
+    "--show-dependencies",
     Arg.Unit (function _ -> FC.show_dependencies := true;
       FC.show_binding_in_out := true),
     " show the dependencies related to each rule";
@@ -421,54 +424,54 @@ let other_options = [
   "verbose subsystems options",
   "",
   [
-    "-verbose_ctl_engine",
+    "--verbose-ctl-engine",
     Arg.Unit (function _ ->
       Flag_ctl.verbose_ctl_engine := true; FC.show_ctl_text := true) , " ";
-    "-verbose_match",        Arg.Set Flag_ctl.verbose_match, " ";
-    "-verbose_engine",       Arg.Set Flag_matcher.debug_engine,    " ";
-    "-graphical_trace",      Arg.Set Flag_ctl.graphical_trace, "  generate a pdf file representing the matching process";
-    "-gt_without_label",
+    "--verbose-match",        Arg.Set Flag_ctl.verbose_match, " ";
+    "--verbose-engine",       Arg.Set Flag_matcher.debug_engine,    " ";
+    "--graphical-trace",      Arg.Set Flag_ctl.graphical_trace, "  generate a pdf file representing the matching process";
+    "--gt-without-label",
      Arg.Unit (function _ ->
        Flag_ctl.graphical_trace := true; Flag_ctl.gt_without_label := true),
-       "  remove graph label (requires option -graphical_trace)";
+       "  remove graph label (requires option -graphical-trace)";
 
-    "-parse_error_msg", Arg.Set Flag_parsing_c.show_parsing_error, " ";
-    "-verbose_parsing",
+    "--parse-error-msg", Arg.Set Flag_parsing_c.show_parsing_error, " ";
+    "--verbose-parsing",
        Arg.Unit (fun _ -> Flag_parsing_c.verbose_parsing := true;
         Flag_parsing_c.show_parsing_error := true), " ";
-    "-type_error_msg",  Arg.Set Flag_parsing_c.verbose_type, " ";
+    "--type-error-msg",  Arg.Set Flag_parsing_c.verbose_type, " ";
     (* could also use Flag_parsing_c.options_verbose *)
   ];
 
   "other show options",
   "",
   [
-    "-show_c"                 , Arg.Set FC.show_c,           " ";
-    "-show_cocci"             , Arg.Set FC.show_cocci,       " ";
-    "-show_before_fixed_flow" , Arg.Set FC.show_before_fixed_flow,  " ";
-    "-show_ctl_tex"           , Arg.Set FC.show_ctl_tex,     " ";
-    "-show_ctl_text"          , Arg.Set FC.show_ctl_text,     " ";
-    "-show_SP"             ,    Arg.Set Flag_parsing_cocci.show_SP,  " ";
+    "--show-c"                 , Arg.Set FC.show_c,           " ";
+    "--show-cocci"             , Arg.Set FC.show_cocci,       " ";
+    "--show-before-fixed-flow" , Arg.Set FC.show_before_fixed_flow,  " ";
+    "--show-ctl-tex"           , Arg.Set FC.show_ctl_tex,     " ";
+    "--show-ctl-text"          , Arg.Set FC.show_ctl_text,     " ";
+    "--show-SP"             ,    Arg.Set Flag_parsing_cocci.show_SP,  " ";
   ];
 
 
   "debug C parsing/unparsing",
   "",
   [
-    "-debug_cpp",          Arg.Set  Flag_parsing_c.debug_cpp, " ";
-    "-debug_lexer",        Arg.Set  Flag_parsing_c.debug_lexer , " ";
-    "-debug_etdt",         Arg.Set  Flag_parsing_c.debug_etdt , "  ";
-    "-debug_typedef",      Arg.Set  Flag_parsing_c.debug_typedef, "  ";
+    "--debug-cpp",          Arg.Set  Flag_parsing_c.debug_cpp, " ";
+    "--debug-lexer",        Arg.Set  Flag_parsing_c.debug_lexer , " ";
+    "--debug-etdt",         Arg.Set  Flag_parsing_c.debug_etdt , "  ";
+    "--debug-typedef",      Arg.Set  Flag_parsing_c.debug_typedef, "  ";
 
-    "-filter_msg",         Arg.Set  Flag_parsing_c.filter_msg ,
+    "--filter-msg",         Arg.Set  Flag_parsing_c.filter_msg ,
     "  filter some cpp message when the macro is a \"known\" cpp construct";
-    "-filter_define_error",     Arg.Set Flag_parsing_c.filter_define_error,"  ";
-    "-filter_msg_define_error", Arg.Set Flag_parsing_c.filter_msg_define_error,
+    "--filter-define-error",     Arg.Set Flag_parsing_c.filter_define_error,"  ";
+    "--filter-msg-define-error", Arg.Set Flag_parsing_c.filter_msg_define_error,
     "  filter the error msg";
-    "-filter_passed_level",     Arg.Set_int Flag_parsing_c.filter_passed_level,"  ";
+    "--filter-passed-level",     Arg.Set_int Flag_parsing_c.filter_passed_level,"  ";
 (*  debug cfg doesn't seem to have any effect, so drop it as an option *)
-(*  "-debug_cfg",          Arg.Set Flag_parsing_c.debug_cfg , "  "; *)
-    "-debug_unparsing",         Arg.Set  Flag_parsing_c.debug_unparsing, "  ";
+(*  "--debug_cfg",          Arg.Set Flag_parsing_c.debug_cfg , "  "; *)
+    "--debug-unparsing",         Arg.Set  Flag_parsing_c.debug_unparsing, "  ";
 
   ];
   (* could use Flag_parsing_c.options_debug_with_title instead *)
@@ -478,36 +481,36 @@ let other_options = [
   "",
   [
     (* todo: other profile ? *)
-    "-quiet",   Arg.Unit (fun () -> run_profile quiet_profile), " ";
-    "-very_quiet",   Arg.Unit (fun () -> run_profile very_quiet_profile), " ";
-    "-debug",   Arg.Unit (fun () -> run_profile debug_profile), " ";
-    "-pad",     Arg.Unit (fun () -> run_profile pad_profile),   " ";
+    "--quiet",   Arg.Unit (fun () -> run_profile quiet_profile), " ";
+    "--very-quiet",   Arg.Unit (fun () -> run_profile very_quiet_profile), " ";
+    "--debug",   Arg.Unit (fun () -> run_profile debug_profile), " ";
+    "--pad",     Arg.Unit (fun () -> run_profile pad_profile),   " ";
 
   ];
 
   "bench options",
   "",
   [
-    "-profile", Arg.Unit (function () -> Common.profile := Common.PALL) ,
+    "--profile", Arg.Unit (function () -> Common.profile := Common.PALL) ,
     "   gather timing information about the main coccinelle functions";
-    "-bench", Arg.Int (function x -> Flag_ctl.bench := x),
+    "--bench", Arg.Int (function x -> Flag_ctl.bench := x),
     "   <level> for profiling the CTL engine";
-    "-timeout", Arg.Int (fun x -> FC.timeout := Some x),
+    "--timeout", Arg.Int (fun x -> FC.timeout := Some x),
     "   <sec> timeout in seconds";
-    "-steps", Arg.Int (fun x -> Flag_ctl.steps := Some x),
+    "--steps", Arg.Int (fun x -> Flag_ctl.steps := Some x),
     "   max number of model checking steps per code unit";
-    "-iso_limit", Arg.Int (fun x -> Flag_parsing_cocci.iso_limit := Some x),
+    "--iso-limit", Arg.Int (fun x -> Flag_parsing_cocci.iso_limit := Some x),
     "   max depth of iso application";
-    "-no_iso_limit", Arg.Unit (fun _ -> Flag_parsing_cocci.iso_limit := None),
+    "--no-iso-limit", Arg.Unit (fun _ -> Flag_parsing_cocci.iso_limit := None),
     "   disable limit on max depth of iso application";
-    "-track_iso", Arg.Set Flag.track_iso_usage,
+    "--track-iso", Arg.Set Flag.track_iso_usage,
     "   gather information about isomorphism usage";
-    "-disable_iso",
+    "--disable-iso",
     Arg.String
     (fun s -> Flag_parsing_cocci.disabled_isos :=
       s :: !Flag_parsing_cocci.disabled_isos),
     "   disable a specific isomorphism";
-    "-profile_iso",
+    "--profile-iso",
     Arg.Unit
     (function () ->
       Common.profile :=
@@ -521,155 +524,155 @@ let other_options = [
   "change of algorithm options",
   "",
   [
-    "-popl", Arg.Set FC.popl,
+(*    "--popl", Arg.Set FC.popl,
     "    simplified SmPL, for the popl paper";
 
-    "-popl_mark_all",
+    "--popl_mark_all",
     Arg.Unit
     (function _ -> FC.popl := true; Flag_popl.mark_all := true),
     "    simplified SmPL, for the popl paper";
 
-    "-popl_keep_all_wits",
+    "--popl_keep_all_wits",
     Arg.Unit
     (function _ -> FC.popl := true; Flag_popl.keep_all_wits := true),
     "    simplified SmPL, for the popl paper";
 
-    "-hrule", Arg.String
+    "--hrule", Arg.String
     (function s ->
       Flag.make_hrule := Some s; FC.include_options := FC.I_NO_INCLUDES),
     "    semantic patch generation";
-
-    "-keep_comments", Arg.Set Flag_parsing_c.keep_comments,
+*)
+    "--keep-comments", Arg.Set Flag_parsing_c.keep_comments,
     "   keep comments around removed code";
 
-    "-loop",              Arg.Set Flag_ctl.loop_in_src_code,    " ";
-    "-no_loops",          Arg.Set Flag_parsing_c.no_loops,
+    "--loop",              Arg.Set Flag_ctl.loop_in_src_code,    " ";
+    "--no-loops",          Arg.Set Flag_parsing_c.no_loops,
     "   drop all back edges derived from looping constructs - unsafe";
-    "-no_gotos",          Arg.Set Flag_parsing_c.no_gotos,
+    "--no-gotos",          Arg.Set Flag_parsing_c.no_gotos,
     "   drop all jumps derived from gotos - unsafe";
-    "-no_saved_typedefs", Arg.Clear Flag_cocci.use_saved_typedefs,
+    "--no-saved-typedefs", Arg.Clear Flag_cocci.use_saved_typedefs,
     "   drop all inferred typedefs from one parse of some code to the next";
 
-    "-ocaml_regexps", Arg.Clear Regexp.pcre_support,
+    "--ocaml-regexps", Arg.Clear Regexp.pcre_support,
     "   use OCaml Str regular expressions for constraints";
 
-    "-l1",                Arg.Clear Flag_parsing_c.label_strategy_2, " ";
-    "-ifdef_to_if",       Arg.Set FC.ifdef_to_if,
+    "--l1",                Arg.Clear Flag_parsing_c.label_strategy_2, " ";
+    "--ifdef-to-if",       Arg.Set FC.ifdef_to_if,
     "   convert ifdef to if (experimental)";
-    "-no_ifdef_to_if",              Arg.Clear FC.ifdef_to_if,
+    "--no-ifdef-to-if",              Arg.Clear FC.ifdef_to_if,
     "   convert ifdef to if (experimental)";
 
-    "-disable_multi_pass", Arg.Set Flag_parsing_c.disable_multi_pass, " ";
+    "--disable-multi-pass", Arg.Set Flag_parsing_c.disable_multi_pass, " ";
 
-    "-noif0_passing",      Arg.Clear Flag_parsing_c.if0_passing,
+    "--noif0-passing",      Arg.Clear Flag_parsing_c.if0_passing,
     " ";
-    "-noadd_typedef_root", Arg.Clear Flag_parsing_c.add_typedef_root, " ";
+    "--noadd-typedef-root", Arg.Clear Flag_parsing_c.add_typedef_root, " ";
     (* could use Flag_parsing_c.options_algo instead *)
 
 
-    "-disallow_nested_exps", Arg.Set Flag_matcher.disallow_nested_exps,
+    "--disallow-nested-exps", Arg.Set Flag_matcher.disallow_nested_exps,
        " disallow an expresion pattern from matching a term and its subterm";
-    "-disable_worth_trying_opt", Arg.Clear FC.worth_trying_opt,
+    "--disable-worth-trying-opt", Arg.Clear FC.worth_trying_opt,
     "  ";
-    "-only_return_is_error_exit",
+    "--only-return-is-error-exit",
     Arg.Set Flag_matcher.only_return_is_error_exit,
     "if this flag is not set, then break and continue are also error exits";
     (* the following is a hack to make it easier to add code in sgrep-like
        code, essentially to compensate for the fact that we don't have
        any way of printing things out *)
-    "-allow_inconsistent_paths",
+    "--allow-inconsistent-paths",
     Arg.Set Flag_matcher.allow_inconsistent_paths,
     "   if this flag is set don't check for inconsistent paths; dangerous";
-    "-no_safe_expressions",
+    "--no-safe-expressions",
     Arg.Set Flag_matcher.no_safe_expressions,
     "  make an expression disjunction not prioritise the topmost disjunct";
-    "-int_bits", Arg.Int Flag_parsing_c.set_int_bits,
+    "--int-bits", Arg.Int Flag_parsing_c.set_int_bits,
     "  the number of bits in an unsigned int";
-    "-long_bits", Arg.Int Flag_parsing_c.set_long_bits,
+    "--long-bits", Arg.Int Flag_parsing_c.set_long_bits,
     "  the number of bits in an unsigned long";
-    "-linux_spacing", Arg.Unit Flag_parsing_c.set_linux_spacing,
+    "--linux-spacing", Arg.Unit Flag_parsing_c.set_linux_spacing,
     "  spacing of + code follows the conventions of Linux";
-    "-smpl_spacing", Arg.Unit Flag_parsing_c.set_smpl_spacing,
+    "--smpl-spacing", Arg.Unit Flag_parsing_c.set_smpl_spacing,
     "  spacing of + code follows the semantic patch";
     "-D", Arg.String Flag.set_defined_virtual_rules,
     "  indicate that a virtual rule should be considered to be matched";
-    "-c++", Arg.Set Flag.c_plus_plus,
+    "--c++", Arg.Set Flag.c_plus_plus,
     "  make a small attempt to parse C++ files"
   ];
 
   "misc options",
   "",
   [
-    "-debugger",           Arg.Set Common.debugger,
+    "--debugger",           Arg.Set Common.debugger,
     "   option to set if launch spatch in ocamldebug";
-    "-disable_once",       Arg.Set Common.disable_pr2_once,
+    "--disable-once",       Arg.Set Common.disable_pr2_once,
     "   to print more messages";
-    "-show_trace_profile", Arg.Set Common.show_trace_profile,
+    "--show-trace-profile", Arg.Set Common.show_trace_profile,
     "   show trace";
-    "-save_tmp_files",     Arg.Set Common.save_tmp_files,   " ";
+    "--save-tmp-files",     Arg.Set Common.save_tmp_files,   " ";
   ];
 
   "concurrency",
   "",
   [
-    "-index",       Arg.Int (function x -> distrib_index := Some x) ,
+    "--index",       Arg.Int (function x -> distrib_index := Some x) ,
     "   the processor to use for this run of spatch";
-    "-max",         Arg.Int (function x -> distrib_max := Some x) ,
+    "--max",         Arg.Int (function x -> distrib_max := Some x) ,
     "   the number of processors available";
-    "-mod_distrib", Arg.Set mod_distrib,
+    "--mod-distrib", Arg.Set mod_distrib,
     "   use mod to distribute files among the processors";
   ];
 
   "pad options",
   "",
   [
-    "-use_cache", Arg.Set Flag_parsing_c.use_cache,
+    "--use-cache", Arg.Set Flag_parsing_c.use_cache,
     "   use .ast_raw pre-parsed cached C file";
-    "-cache_prefix",
+    "--cache_prefix",
     Arg.String (function s ->
       Flag_parsing_c.cache_prefix := Some s;
       Flag_parsing_c.use_cache := true),
-    "   directory of cached ASTs, sets -use_cache";
+    "   directory of cached ASTs, sets -use-cache";
     (* could use Flag_parsing_c.options_pad instead *)
-    "-cache_limit",
+    "--cache-limit",
       Arg.Int (function n ->
        Flag_parsing_c.cache_limit := Some n),
-    "   maximum number of cached ASTs, sets -use_cache";
+    "   maximum number of cached ASTs, sets -use-cache";
   ];
 
 
 
   "test mode and test options (works with tests/ or .ok files)",
-  "The test options don't work with the -sp_file and so on.",
+  "The test options don't work with the --sp-file and so on.",
   [
-    "-test",    Arg.Set test_mode,
+    "--test",    Arg.Set test_mode,
     "   <file> launch spatch on tests/file.[c,cocci]";
-    "-testall", Arg.Set test_all,
+    "--testall", Arg.Set test_all,
     "   launch spatch on all files in tests/ having a .res";
-    "-test_okfailed", Arg.Set test_okfailed,
+    "--test-okfailed", Arg.Set test_okfailed,
     "    generates .{ok,failed,spatch_ok} files using .res files";
-    "-test_regression_okfailed", Arg.Set test_regression_okfailed,
+    "--test-regression-okfailed", Arg.Set test_regression_okfailed,
     "    process the .{ok,failed,spatch_ok} files in current dir";
 
-    "-compare_with_expected", Arg.Set compare_with_expected,
+    "--compare-with-expected", Arg.Set compare_with_expected,
     "   use also file.res";
-    "-expected_score_file", Arg.Set_string expected_score_file,
+    "--expected-score-file", Arg.Set_string expected_score_file,
     "   which score file to compare with in -testall";
-    "-relax_include_path", Arg.Set FC.relax_include_path,
+    "--relax-include-path", Arg.Set FC.relax_include_path,
     " ";
   ];
 
   "action mode",
-  ("The action options don't work with the -sp_file and so on." ^ "\n" ^
+  ("The action options don't work with the --sp-file and so on." ^ "\n" ^
    "It's for the other (internal) uses of the spatch program."
   ),
 
     (* -token_c, -parse_c, etc  *)
   ((Common.options_of_actions action (Test_parsing_c.actions())) ++
     [
-    (let s = "-parse_cocci"  in s, Arg.Unit (fun () -> action := s),
+    (let s = "--parse-cocci"  in s, Arg.Unit (fun () -> action := s),
     "   <file>");
-    (let s = "-compare_c"  in s, Arg.Unit (fun () -> action := s),
+    (let s = "--compare-c"  in s, Arg.Unit (fun () -> action := s),
     "   <file1> <file2>");
     ]);
 ]
@@ -734,7 +737,7 @@ let short_usage () =
   Common.short_usage usage_msg short_options;
   pr2 "";
   pr2 "Example of use:";
-  pr2 "  ./spatch -sp_file foo.cocci foo.c -o /tmp/newfoo.c";
+  pr2 "  ./spatch --sp-file foo.cocci foo.c -o /tmp/newfoo.c";
   pr2 "";
  end
 
@@ -833,7 +836,7 @@ let rec main_action xs =
   | _ -> failwith "only one .cocci file allowed");
   Iteration.base_file_list := xs;
   let rec toploop = function
-      [] -> raise Impossible
+      [] -> failwith "no C files provided"
     | x::xs ->
       (* a more general solution would be to use
        * Common.files_of_dir_or_files (x::xs)
@@ -843,7 +846,7 @@ let rec main_action xs =
          dir := (Common.is_directory x);
        
           if !cocci_file =$= ""
-          then failwith "I need a cocci file,  use -sp_file <file>";
+          then failwith "I need a cocci file,  use --sp-file <file>";
          
          if !dir && !Flag.patch =*= None
          then
@@ -945,6 +948,9 @@ let rec main_action xs =
              let res =
                infiles +> List.map (fun cfiles ->
                  pr2 ("HANDLING: " ^ (join " " cfiles));
+                 (*pr2 (List.hd(Common.cmd_to_list "free -m | grep Mem"));*)
+                 flush stderr;
+                   
                  Common.timeout_function_opt !FC.timeout (fun () ->
                    Common.report_if_take_time 10 (join " " cfiles) (fun () ->
                       try
@@ -1045,6 +1051,12 @@ and generate_outfiles outfiles x (* front file *) xs (* other files *) =
           ("-o can not be applied because there are multiple " ^
            "modified files"))
 
+let fix_chars s =
+  if (String.length s) > 2 && String.get s 0 = '-'
+      && not (String.get s 1 = '-')
+  then "-"^(String.concat "-" (Str.split (Str.regexp_string "_") s))
+  else s
+
 (*****************************************************************************)
 (* The coccinelle main entry point *)
 (*****************************************************************************)
@@ -1052,10 +1064,18 @@ let main () =
   begin
     let arglist = Array.to_list Sys.argv in
     let arglist = Command_line.command_line arglist in
-    
+    let arglist = List.map fix_chars arglist in
+
+    let contains_cocci =
+      (* rather a hack... don't want to think about all possible options *)
+      List.exists
+       (function x -> Filename.check_suffix x ".cocci")
+       arglist &&
+      not (List.mem "--parse-cocci" arglist) in
     if not (null (Common.inter_set arglist
-                   ["-cocci_file";"-sp_file";"-sp";"-test";"-testall";
-                      "-test_okfailed";"-test_regression_okfailed"]))
+                   ["--cocci-file";"--sp-file";"--sp";"--test";"--testall";
+                      "--test-okfailed";"--test-regression-okfailed"]))
+       or contains_cocci
     then run_profile quiet_profile;
     
     let args = ref [] in
@@ -1065,6 +1085,19 @@ let main () =
     (* this call can set up many global flag variables via the cmd line *)
     arg_parse2 (Arg.align all_options) (fun x -> args := x::!args) usage_msg
       (Array.of_list arglist);
+    args :=
+      List.filter
+       (function arg ->
+         if Filename.check_suffix arg ".cocci"
+         then
+           begin
+             (if !cocci_file = ""
+             then cocci_file := arg
+             else failwith "only one .cocci file allowed");
+             false
+           end
+         else true)
+       !args;
     
     (* julia hack so that one can override directories specified on
        * the command line. *)
@@ -1157,13 +1190,13 @@ let main () =
     | xs when List.mem !action (Common.action_list all_actions) ->
         Common.do_action !action xs all_actions
 
-    | [file] when !action =$= "-parse_cocci" ->
-       Testing.test_parse_cocci file
+    | [] when !action =$= "--parse-cocci" ->
+       Testing.test_parse_cocci !cocci_file
 
      (* I think this is used by some scripts in some Makefile for our
       * big-tests. So dont remove.
       *)
-    | [file1;file2] when !action =$= "-compare_c" ->
+    | [file1;file2] when !action =$= "--compare-c" ->
        Test_parsing_c.test_compare_c file1 file2 (* result = unix code *)
 
     (* could add the Test_parsing_c.test_actions such as -parse_c & co *)