Debian Codegraph @

tools/spgen/source/main.ml

raw
1 (*
2 * This file is part of Coccinelle, licensed under the terms of the GPL v2.
3 * See copyright.txt in the Coccinelle source code for more information.
4 * The Coccinelle source code can be obtained at http://coccinelle.lip6.fr
5 *)
6
7 (* ------------------------------------------------------------------------- *)
8 (* OPTIONS *)
9
10 (* the cocci script to be generated *)
11 let file = ref ""
12
13 (* the config file to draw user input from *)
14 let config = ref ""
15
16 (* whether to draw user input interactively *)
17 let interactive = ref false
18
19 (* whether to generate without user input (using default values) *)
20 let default = ref false
21
22 (* where to output the resulting generated file *)
23 let output = ref ""
24
25 (* hide resulting generated file *)
26 let hide = ref false
27
28 (* path to directory with spgen tests *)
29 let test_dir = ref ""
30
31 let set_config x = config := x; interactive := false
32
33 let anonymous s = if !file = "" then file := s
34
35 let usage =
36 let msg =
37 "Usage: %s [options] <filename>\n" ^^ (* format string concatenation *)
38 "Example: spgen --config file.config file.cocci.\n\n" ^^
39 "Options are:" in
40 Printf.sprintf msg (Filename.basename Sys.argv.(0))
41
42 let speclist =
43 [
44 ("--config", Arg.String set_config,
45 "<file> Configuration file for the generated file.");
46
47 ("-c", Arg.String set_config,
48 "<file> Shorthand for --config.");
49
50 ("--interactive", Arg.Set interactive,
51 " Run the program in interactive mode.");
52
53 ("-i", Arg.Set interactive,
54 " Shorthand for --interactive.");
55
56 ("-o", Arg.Set_string output,
57 "<file> Output result to this file instead of standard output.");
58
59 ("--default", Arg.Set default,
60 " Generate the file using generic default values instead of user input.");
61
62 ("--no-output", Arg.Set hide,
63 " Don't print the result.");
64
65 ("--test", Arg.Set_string test_dir,
66 "<path_to_tests_dir> Run the regression tests.");
67 ]
68
69 (* ------------------------------------------------------------------------- *)
70 (* ENTRY POINT *)
71
72 let main _ =
73
74 Arg.parse (Arg.align speclist) anonymous usage;
75
76 if !test_dir <> "" then
77
78 Spgen_test.regression_test ~test_dir:(!test_dir)
79
80 else begin
81
82 if !file = "" then (Arg.usage (Arg.align speclist) usage; exit 1);
83 let options =
84 Spgen.make_options
85 ~config:!config
86 ~interactive:!interactive
87 ~default:!default
88 ~output:!output
89 ~hide:!hide
90 !file in
91 Spgen.run options
92
93 end
94
95 let _ = main ()