Prolog Command Line Argument Handling

There are three ways a Prolog system can be invoked:

     % program Prolog's arguments
     
     % program Prolog's arguments + emacs' arguments
     
     % program Prolog's arguments +z user's arguments
     

where program, generally prolog, but can be an executable QOF file (see ref-sls-sst) or a stand-alone program (see sap-srs).


Prolog's arguments consists of:

user's arguments
these arguments can be retrieved in a program by calling unix(argv(ArgList)).
system arguments
The current valid system arguments are:

+
invoke Emacs; subsequent arguments passed to Emacs;
+f
fast startup; do not load user's prolog.ini file;
+l file
load the specified file on startup; file may be a Prolog file or a QOF file, and it may be specified either as a string (e.g. file, ~/prolog/file.pl) or as a file search path specification (e.g. library(file), home(language(file))); note, however, that the latter needs to be quoted to escape the shell interpretation of the parentheses; giving the extension is not necessary; if both source (.pl) and QOF (.qof) files exist, the more recent of the two will be loaded;
+L file
like +l, but search for file in the directories given by the shell environment variable PATH; and
+p [path-name]
prints the Prolog file search path definitions that begin with the string path-name (e.g. library if +p lib is specified); path-name is optional, and if not given, causes prolog to print all file search path definitions; prolog exits after producing the required output to stdout;
+P [path-name]
same as +p, but the absolutized versions of the file search path definitions are printed;
+tty
force the three standard streams associated with a Prolog process to act as tty streams; a tty stream is usually line buffered and handles the prompt automatically;
+z
all subsequent arguments are user's arguments.

Only one of + or +z is possible on one command line.


emacs' arguments
arguments to the Emacs interface. This may include file names to edit and may also include GNU Emacs arguments (see ema-emi).

All command line arguments beginning with a + are reserved for system arguments. If user arguments need to begin with a +, they should be given as ++ instead. The ++ is converted into a single + by the argument handling routines, and thus, to the user's code, only the single + argument is visible. An exception to this is when an argument is given following a +z option in which case no conversion is done.

Runtime systems do not interpret system arguments; they treat all arguments as user's arguments.

There can be any number of +l and +L arguments. In Release 3, invoking a saved-state, an executable QOF-file, as a command causes the corresponding Prolog executable, the one from which the saved-state was created, to be invoked with the arguments +L saved-state.

The user's arguments are accessible in Prolog via unix(argv(ArgList)), which returns a list of all the user's arguments. For example, if Prolog is invoked by the command (A), then the Prolog goal (B) returns (C):

     % prolog ++file1 -file2      (A)
     
     | ?- unix(argv(ArgList)).    (B)
     
     ArgList = ['+file1','-file2']   (C)