PublicShow sourcemain.pl -- Provide entry point for scripts

This library is intended for supporting PrologScript on Unix using the #! magic sequence for scripts using commandline options. The entry point main/0 calls the user-supplied predicate main/1 passing a list of commandline options. Below is a simle echo implementation in Prolog.

#!/usr/bin/env swipl

:- initialization(main, main).

main(Argv) :-
    echo(Argv).

echo([]) :- nl.
echo([Last]) :- !,
    write(Last), nl.
echo([H|T]) :-
    write(H), write(' '),
    echo(T).
See also
- library(prolog_stack) to force backtraces in case of an uncaught exception.
- XPCE users should have a look at library(pce_main), which starts the GUI and processes events until all windows have gone.
Source main
Call main/1 using the passed command-line arguments. Before calling main/1 this predicate installs a signal handler for SIGINT (Control-C) that terminates the process with status 1.

When main/0 is called interactively it simply calls main/1 with the arguments. This allows for debugging scripts as follows:

$ swipl -l script.pl -- arg ...
?- gspy(suspect/1).		% setup debugging
?- main.			% run program

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

Source cli_parse_debug_options(Arg1, Arg2)
Source argv_options(Arg1, Arg2, Arg3)
Source argv_options(Arg1, Arg2, Arg3, Arg4)
Source cli_debug_opt_meta(Arg1, Arg2)
Source cli_debug_opt_help(Arg1, Arg2)
Source cli_enable_development_system
Source cli_debug_opt_type(Arg1, Arg2, Arg3)
Source argv_usage(Arg1)