command_line_luc_exe.ml 2.73 KB
Newer Older
1 2 3 4 5 6
(*-----------------------------------------------------------------------
** Copyright (C) 2001 - Verimag.
** 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 16
  mutable user_seed : int ;
  mutable verbose : bool 
17 18 19
}

type cmd_line_optionT = 
20
    Seed | Boot | ShowAut | NoShowAut | Verbose
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 31 32 33
  ("-seed", Seed);

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

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

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

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

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

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