X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Fcmdline.ml;h=f98e0a819e2976350ca86e27bf0cb5d54418094b;hb=70a08a62b9312ed1bbcb7c89d47f9a25fa221e34;hp=53ab0f9721f6e0da1b231605e92e8fe7bcef794d;hpb=6afdc65fcdb592dccb751849f65b1f482ef97cd6;p=goals.git diff --git a/src/cmdline.ml b/src/cmdline.ml index 53ab0f9..f98e0a8 100644 --- a/src/cmdline.ml +++ b/src/cmdline.ml @@ -23,7 +23,7 @@ open Utils (* See also "let id" in [lexer.mll]. *) let var_regexp = - Str.regexp "\\([a-zA-Z_][a-zA-Z0-9_]*\\)[ \t]*=[ \t]*\\(.*\\)" + Str.regexp "\\([a-zA-Z_][-a-zA-Z0-9_]*\\)[ \t]*=[ \t]*\\(.*\\)" let usage = "\ @@ -43,14 +43,17 @@ let print_version () = let datadir = try Sys.getenv "GOALS_DATADIR" with Not_found -> Config.datadir let stdlibdir = datadir // "stdlib" -let prelude_file = stdlibdir // "prelude.gl" +let prelude_gl_file = stdlibdir // "prelude.gl" +let prelude_sh_file = stdlibdir // "prelude.sh" let () = - if not (is_directory stdlibdir) || not (Sys.file_exists prelude_file) then + if not (is_directory stdlibdir) || not (Sys.file_exists prelude_gl_file) then failwithf "%s: cannot find the standard library directory, expected %s. If the standard library directory is in a non-standard location then set GOALS_DATADIR. If you can trying to run goals from the build directory then use ‘./run goals ...’" Sys.executable_name stdlibdir -let input_file, directory, includes, use_prelude, anon_vars, targets = +let input_file, + debug_flag, directory, includes, use_prelude, anon_vars, targets = let args = ref [] in + let debug_flag = ref false in let directory = ref "." in let input_file = ref "Goalfile" in let includes = ref [stdlibdir] in @@ -60,6 +63,8 @@ let input_file, directory, includes, use_prelude, anon_vars, targets = let argspec = [ "-C", Arg.Set_string directory, "directory Change to directory before running"; + "-d", Arg.Set debug_flag, + " Print debug information."; "--directory", Arg.Set_string directory, "directory Change to directory before running"; "-f", Arg.Set_string input_file, @@ -72,7 +77,7 @@ let input_file, directory, includes, use_prelude, anon_vars, targets = "dir Add include directory"; "--no-prelude",Arg.Clear use_prelude, " Do not automatically use prelude.gl from stdlib"; - "-V", Arg.Unit print_version, + "-v", Arg.Unit print_version, " Print version and exit"; "--version", Arg.Unit print_version, " Print version and exit"; @@ -82,6 +87,7 @@ let input_file, directory, includes, use_prelude, anon_vars, targets = Arg.parse argspec anon_fun usage; let args = List.rev !args in + let debug_flag = !debug_flag in let directory = !directory in let input_file = absolute_path !input_file in (* Don't reverse includes - we want newer -I options to take precedence. *) @@ -102,4 +108,10 @@ let input_file, directory, includes, use_prelude, anon_vars, targets = (name, expr) ) anon_vars in - input_file, directory, includes, use_prelude, anon_vars, targets + input_file, + debug_flag, directory, includes, use_prelude, anon_vars, targets + +(* Create the debug function. *) +let debug fs = + let display str = if debug_flag then prerr_endline str in + ksprintf display fs