main.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).
- 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. - interrupt(+Signal)[private]
- We received an interrupt. This handler is installed using on_signal/3.
- argv_options(+Argv, -RestArgv, -Options) is det
- Generic transformation of long commandline arguments to options.
Each --Name=Value is mapped to Name(Value). Each plain name is
mapped to Name(true), unless Name starts with
no-
, in which case the option is mapped to Name(false). Numeric option values are mapped to Prolog numbers.