command_line_luc_exe.ml 2.69 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 user_seed : int 
16 17 18
}

type cmd_line_optionT = 
19
    Seed | Boot | ShowAut | NoShowAut | Verbose
20 21 22 23

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

  ("--with-seed", Seed);
28 29 30 31 32
  ("-seed", Seed);

  ("--show-aut", ShowAut);
  ("-s", ShowAut);

33
  ("--no-show-aut", NoShowAut);
34

35 36
  ("--verbose", Verbose);
  ("-v", Verbose)
37 38 39 40 41
]

let (option_to_usage: cmd_line_optionT -> string) =
  fun opt -> 
    match opt with
42
	Boot -> "The automata starts generating values.\n"
43
      |	ShowAut -> "Run lucky showing the lucky automata step.\n"
44
      | NoShowAut ->  "Do not show the luc automata (Default).\n"
45
      |	Seed -> "Set the value of the seed the random engine is initialized with (0 lets the system draw a seed).\n"
46
      | Verbose -> "Set on a verbose mode.\n"
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

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 = 
72
  ("\n\nusage: ./lucky [options]* <file>.luc ([x] <file>.luc)* \n" ^
73
   "   where: " ^
74
   "\n\t o `<file>.luc contains an environment automata. Environments " ^
75 76 77 78 79 80
   "\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" ^

81
   "Example:    ./lucky env1.luc x env2.luc x env3.luc env4\n\t" ^
82 83 84 85 86 87 88 89 90 91 92 93
   "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 ;
94
	failwith "\n *** Error when calling lucky.\n"
95 96