diff options
author | Jacques Garrigue <garrigue at math.nagoya-u.ac.jp> | 2000-02-07 03:29:29 +0000 |
---|---|---|
committer | Jacques Garrigue <garrigue at math.nagoya-u.ac.jp> | 2000-02-07 03:29:29 +0000 |
commit | d518a3348590be05e13b0c23bee0f8a81715b8cf (patch) | |
tree | d3086bc597e879077226cdbafbe74a57a127fcf6 | |
parent | f723d5394fc26b889966972a0c6a071be932e3b2 (diff) |
new handling of Sys.argv in scripts
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2790 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | man/ocaml.m | 11 | ||||
-rw-r--r-- | toplevel/toploop.ml | 11 | ||||
-rw-r--r-- | toplevel/toploop.mli | 3 | ||||
-rw-r--r-- | toplevel/topmain.ml | 4 |
4 files changed, 24 insertions, 5 deletions
diff --git a/man/ocaml.m b/man/ocaml.m index f4e89c384..dd01069fa 100644 --- a/man/ocaml.m +++ b/man/ocaml.m @@ -15,7 +15,9 @@ ocaml \- The Objective Caml interactive toplevel [ .BI \-I \ lib-dir ] - +[ +.I script-file +] .SH DESCRIPTION The @@ -37,6 +39,13 @@ output, errors on standard error. End-of-file on standard input terminates .BR ocaml (1). +If a +.I script-file +is given, phrases are read silently from the file, errors printed on +standard error. +.BR ocaml (1) +exits after the execution of the last phrase. + .SH OPTIONS The following command-line options are recognized by diff --git a/toplevel/toploop.ml b/toplevel/toploop.ml index 077303f0f..fca2428be 100644 --- a/toplevel/toploop.ml +++ b/toplevel/toploop.ml @@ -316,7 +316,16 @@ let loop() = (* Execute a script *) -let run_script name = +let run_script 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 + if Array.length Sys.argv < len then invalid_arg "Toploop.run_script"; + Array.blit args pos Sys.argv 0 len; + Obj.truncate (Obj.repr Sys.argv) len; Compile.init_path(); toplevel_env := Compile.initial_env(); Formatmsg.set_output Format.err_formatter; diff --git a/toplevel/toploop.mli b/toplevel/toploop.mli index e2ad52b5b..945065b19 100644 --- a/toplevel/toploop.mli +++ b/toplevel/toploop.mli @@ -18,7 +18,8 @@ val loop: unit -> unit (* Read and execute a script from the given file *) -val run_script: string -> bool (* true if successful, false if error *) +val run_script: string -> string array -> bool + (* true if successful, false if error *) (* Interface with toplevel directives *) diff --git a/toplevel/topmain.ml b/toplevel/topmain.ml index acfa97a60..f7791cf50 100644 --- a/toplevel/topmain.ml +++ b/toplevel/topmain.ml @@ -14,10 +14,10 @@ open Clflags -let usage = "Usage: ocaml <options>\noptions are:" +let usage = "Usage: ocaml <options> [script-file]\noptions are:" let file_argument name = - exit (if Toploop.run_script name then 0 else 2) + exit (if Toploop.run_script name Sys.argv then 0 else 2) let main () = Arg.parse [ |