meilleur parsing de la ligne de commande pour les scripts
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5579 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
313d77d1cb
commit
96f5cf75a6
|
@ -397,14 +397,9 @@ let loop ppf =
|
|||
(* Execute a script *)
|
||||
|
||||
let run_script ppf name args =
|
||||
let rec find n =
|
||||
if n >= Array.length args then invalid_arg "Toploop.run_script";
|
||||
if args.(n) = name then n else find (n+1)
|
||||
in
|
||||
let pos = find 0 in
|
||||
let len = Array.length args - pos in
|
||||
let len = Array.length args in
|
||||
if Array.length Sys.argv < len then invalid_arg "Toploop.run_script";
|
||||
Array.blit args pos Sys.argv 0 len;
|
||||
Array.blit args 0 Sys.argv 0 len;
|
||||
Obj.truncate (Obj.repr Sys.argv) len;
|
||||
Arg.current := 0;
|
||||
Compile.init_path();
|
||||
|
|
|
@ -31,8 +31,15 @@ let file_argument name =
|
|||
let ppf = Format.err_formatter in
|
||||
if Filename.check_suffix name ".cmo" || Filename.check_suffix name ".cma"
|
||||
then preload_objects := name :: !preload_objects
|
||||
else exit
|
||||
(if prepare ppf && Toploop.run_script ppf name Sys.argv then 0 else 2)
|
||||
else
|
||||
begin
|
||||
let newargs = Array.sub Sys.argv !Arg.current
|
||||
(Array.length Sys.argv - !Arg.current)
|
||||
in
|
||||
if prepare ppf && Toploop.run_script ppf name newargs
|
||||
then exit 0
|
||||
else exit 2
|
||||
end
|
||||
|
||||
let main () =
|
||||
Arg.parse [
|
||||
|
|
Loading…
Reference in New Issue