diff --git a/ocaml/Command_line.ml b/ocaml/Command_line.ml index 1dd5789..ad52658 100644 --- a/ocaml/Command_line.ml +++ b/ocaml/Command_line.ml @@ -12,12 +12,22 @@ type description = { arg : argument ; } +(* Mutable variables *) let anon_args = ref [] and header_doc = ref "" and description_doc = ref "" and footer_doc = ref "" and specs = ref [] +let reset () = + anon_args := []; + header_doc := ""; + description_doc := ""; + footer_doc := ""; + specs := [] + +(* End mutable variables *) + let set_header_doc s = header_doc := s let set_description_doc s = description_doc := s let set_footer_doc s = footer_doc := s diff --git a/ocaml/Command_line.mli b/ocaml/Command_line.mli index 9f6e702..f02756e 100644 --- a/ocaml/Command_line.mli +++ b/ocaml/Command_line.mli @@ -124,3 +124,6 @@ val set_specs : description list -> unit val anon_args : unit -> string list +(** Reset the internal state *) +val reset : unit -> unit + diff --git a/ocaml/Makefile b/ocaml/Makefile index e299203..2899669 100644 --- a/ocaml/Makefile +++ b/ocaml/Makefile @@ -24,6 +24,8 @@ ALL_EXE=$(patsubst %.ml,%.native,$(wildcard qp_*.ml)) qmcchem.native default: $(ALL_EXE) + mv qmcchem.native $(QMCCHEM_PATH)/bin/qmcchem + tests: $(ALL_TESTS) diff --git a/ocaml/Qmcchem_debug.ml b/ocaml/Qmcchem_debug.ml index 8b32af9..3d51691 100644 --- a/ocaml/Qmcchem_debug.ml +++ b/ocaml/Qmcchem_debug.ml @@ -62,7 +62,7 @@ let run ~t ezfio_filename= -let () = +let command () = let open Command_line in begin set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command"); diff --git a/ocaml/Qmcchem_edit.ml b/ocaml/Qmcchem_edit.ml index 5f57ed2..4f7a589 100644 --- a/ocaml/Qmcchem_edit.ml +++ b/ocaml/Qmcchem_edit.ml @@ -274,7 +274,7 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename = write_input_in_ezfio ezfio_filename fields -let () = +let command () = let open Command_line in begin set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command"); diff --git a/ocaml/Qmcchem_info.ml b/ocaml/Qmcchem_info.ml index 51853d8..09143c6 100644 --- a/ocaml/Qmcchem_info.ml +++ b/ocaml/Qmcchem_info.ml @@ -12,7 +12,7 @@ let run ezfio_filename = ignore @@ Unix.execv prog argv -let () = +let command () = let open Command_line in begin set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command"); diff --git a/ocaml/Qmcchem_md5.ml b/ocaml/Qmcchem_md5.ml index 8254710..7357db3 100644 --- a/ocaml/Qmcchem_md5.ml +++ b/ocaml/Qmcchem_md5.ml @@ -120,7 +120,7 @@ let run ?c ?d ~l ~update ezfio_filename = | _ -> handle_options () -let () = +let command () = let open Command_line in begin set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command"); diff --git a/ocaml/Qmcchem_result.ml b/ocaml/Qmcchem_result.ml index bc26cf1..8ae1816 100644 --- a/ocaml/Qmcchem_result.ml +++ b/ocaml/Qmcchem_result.ml @@ -206,7 +206,7 @@ let run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file = display_summary ~range -let () = +let command () = let open Command_line in begin set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command"); diff --git a/ocaml/Qmcchem_run.ml b/ocaml/Qmcchem_run.ml index bbf5961..ace83f1 100644 --- a/ocaml/Qmcchem_run.ml +++ b/ocaml/Qmcchem_run.ml @@ -192,7 +192,7 @@ let run a d ?q ?s ezfio_filename = -let () = +let command () = let open Command_line in begin set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command"); diff --git a/ocaml/Qmcchem_stop.ml b/ocaml/Qmcchem_stop.ml index 02ec94b..5b5debc 100644 --- a/ocaml/Qmcchem_stop.ml +++ b/ocaml/Qmcchem_stop.ml @@ -3,7 +3,7 @@ let run ezfio_filename = Qputils.set_ezfio_filename ezfio_filename; Status.write Status.Stopping -let () = +let command () = let open Command_line in begin set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command"); diff --git a/ocaml/qmcchem.ml b/ocaml/qmcchem.ml index cdf27a9..80e0331 100644 --- a/ocaml/qmcchem.ml +++ b/ocaml/qmcchem.ml @@ -1,9 +1,11 @@ let update_command_line () = - let last = Array.length Sys.argv - 1 in + let last = (Array.length Sys.argv) - 2 in + Sys.argv.(0) <- Sys.argv.(0) ^ " " ^ Sys.argv.(1); for i=1 to last do Sys.argv.(i) <- Sys.argv.(i+1) done; - Sys.argv.(last) <- "--" + Sys.argv.(last+1) <- "--" + let () = @@ -11,29 +13,24 @@ let () = begin set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command"); set_description_doc "Driver for subcommands."; - [ - anonymous "COMMAND" Mandatory "[debug|edit|info|md5|result|run|stop]"; - anonymous "EZFIO_DIR" Mandatory "EZFIO directory"; - ] - |> set_specs + set_specs [] end; - let command = - match Command_line.anon_args () with - | command :: ezfio_file :: [] -> command - | _ -> (Command_line.help () ; failwith "Inconsistent command line") - in + if Array.length Sys.argv < 2 then + (Command_line.help (); failwith "Inconsistent command line"); + let command = Sys.argv.(1) in update_command_line (); + Command_line.reset (); match command with - | "debug" -> let open Qmcchem_debug in () - | "edit" -> let open Qmcchem_edit in () - | "info" -> let open Qmcchem_info in () - | "md5" -> let open Qmcchem_md5 in () - | "result" -> let open Qmcchem_result in () - | "run" -> let open Qmcchem_run in () - | "stop" -> let open Qmcchem_stop in () + | "debug" -> let open Qmcchem_debug in command () + | "edit" -> let open Qmcchem_edit in command () + | "info" -> let open Qmcchem_info in command () + | "md5" -> let open Qmcchem_md5 in command () + | "result" -> let open Qmcchem_result in command () + | "run" -> let open Qmcchem_run in command () + | "stop" -> let open Qmcchem_stop in command () | _ -> (Command_line.help () ; failwith "Inconsistent command line")