(*----------------------------------------------------------------------- ** Copyright (C) 2002 - Verimag. ** This file may only be copied under the terms of the GNU Library General ** Public License **----------------------------------------------------------------------- ** ** File: command_line_luc_exe.ml ** Main author: jahier@imag.fr *) type optionsT = { mutable show_automata : bool ; mutable boot : bool ; mutable user_seed : int } type cmd_line_optionT = Seed | Boot | ShowAut | NoShowAut | Verbose (* Names of the command line options to override the defaults. *) let (string_to_option: (string * cmd_line_optionT) list) = [ ("--boot", Boot); ("-boot", Boot); ("-b", Boot); ("--with-seed", Seed); ("-seed", Seed); ("--show-aut", ShowAut); ("-s", ShowAut); ("--no-show-aut", NoShowAut); ("--verbose", Verbose); ("-v", Verbose) ] let (option_to_usage: cmd_line_optionT -> string) = fun opt -> match opt with Boot -> "The automata starts generating values.\n" | ShowAut -> "Run lucky showing the lucky automata step.\n" | NoShowAut -> "Do not show the luc automata (Default).\n" | Seed -> "Set the value of the seed the random engine is initialized with (0 lets the system draw a seed).\n" | Verbose -> "Set on a verbose mode.\n" 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 = ("\n\nusage: ./lucky [options]* .luc ([x] .luc)* \n" ^ " where: " ^ "\n\t o `.luc contains an environment automata. Environments " ^ "\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" ^ "Example: ./lucky env1.luc x env2.luc x env3.luc env4\n\t" ^ "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 ; failwith "\n *** Error when calling lucky.\n"