command_line_luc_exe.ml 3.28 KB
Newer Older
1
(*-----------------------------------------------------------------------
2
** Copyright (C) 2002 - Verimag.
3 4 5 6
** This file may only be copied under the terms of the GNU Library General
** Public License 
**-----------------------------------------------------------------------
**
7
** File: command_line_luc_exe.ml
8 9 10 11 12
** Main author: jahier@imag.fr
*)


type optionsT = {
13
  mutable show_automata : bool ;
14
  mutable boot : bool ;
15
  mutable locals : bool ;
16
  mutable user_seed : int 
17 18 19
}

type cmd_line_optionT = 
20
    Seed | Inside | Edges | Vertices | Precision | Boot | ShowAut | NoShowAut | Verbose | Locals
21 22 23 24

(* Names of the command line options to override the defaults. *)
let (string_to_option: (string * cmd_line_optionT) list) = [
  ("--boot", Boot);
25 26
  ("-boot", Boot);
  ("-b", Boot);
27 28

  ("--with-seed", Seed);
29 30
  ("-seed", Seed);

31 32 33 34
  ("--precision", Precision);

  ("--draw-inside", Inside);
  ("--draw-edges", Edges);
35
  ("--draw-vertices", Vertices);
36

37 38 39
  ("--show-aut", ShowAut);
  ("-s", ShowAut);

40
  ("--no-show-aut", NoShowAut);
41

42 43
  ("--locals", Locals);

44 45
  ("--verbose", Verbose);
  ("-v", Verbose)
46 47 48 49 50
]

let (option_to_usage: cmd_line_optionT -> string) =
  fun opt -> 
    match opt with
51
	Boot -> "The automata starts generating values.\n"
52
      |	ShowAut -> "Run lucky showing the lucky automata.\n"
53
      | NoShowAut ->  "Do not show the luc automata (Default).\n"
54 55 56
      | Precision ->  "Set the precision used for numerical values (number of digits).\n"
      | Inside -> "Draw inside the convex hull of solutions.\n "
      | Edges -> "Draw inside the convex hull of solutions, but a little bit more at edges and vertices.\n "
57
      | Vertices -> "Draw among the vertices of the convex hull of solutions.\n "
58
      |	Seed -> "Set the value of the seed the random engine is initialized with (0 lets the system draw a seed).\n"
59
      | Locals -> "Shows local variables.\n"
60
      | Verbose -> "Set on a verbose mode.\n"
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

let (group_common_options: (string * cmd_line_optionT) list -> 
       (string * cmd_line_optionT) list) =
  fun list -> 
    List.fold_left
      (fun acc (str, opt) -> 
         match acc with
             (str2, opt2)::tail -> 
	       if 
		 (opt = opt2)
	       then
		 (((str2  ^ "\n\t\t" ^ str), opt)::tail)
	       else
		 ((str, opt)::(str2, opt2)::tail)
	   | [] -> [(str, opt)]
      )
      []
      list
let usage_options = 
  List.fold_left 
    (fun acc (str, opt) -> acc ^ "\n\t\t" ^ str ^ "\n\t\t\t" ^ (option_to_usage opt))
    ""
    (List.rev (group_common_options string_to_option))

let usage = 
86
  ("\n\nusage: lucky [options]* <file>.luc ([x] <file>.luc)* \n" ^
87
   "   where: " ^
88
   "\n\t o `<file>.luc contains an environment automata. Environments " ^
89 90 91 92 93 94
   "\n\t   separated by `x' will executed as if their automata where " ^
   "\n\t   multiplied (necessary if they have common output variables).\n " ^

   "\n\t o `options' is a list of options. The available options are: " ^ 
   usage_options ^ "\n\n" ^

95
   "Example:  lucky env1.luc x env2.luc x env3.luc env4\n\t" ^
96 97 98 99 100 101 102 103 104 105 106 107
   "will run the environment `env1', `env2', and `env3' as a product,  \n\t" ^
   "and `env4' in parallel.\n\n ")


let cmd_line_string_to_int str errmsg =
  try 
    (int_of_string str) 
  with Failure("int_of_string") 
      -> 
	print_string usage ;
	print_string errmsg ;
	flush stdout ;
108
	failwith "\n *** Error when calling lucky.\n"
109 110