$Revision: 5.0.2.3 $
Package: SYSTEM
Arguments: ((optstring &rest varlist) (restvar
&key command-line-arguments) &body body)
This macro makes easy the task of parsing command line arguments, in the style similar to teh UNIX getopt(3) and getopt (for use in shell scripts).
The main task of with-command-line-arguments is to bind LISP variables to the given command line arguments. optstring is a getopt(3) style option string describing the expected options. varlist is a list of symbols to which values are bound-the order of the options in optstring is the order in which the variables are bound. The keyword command-line-arguments is used to initialized the command line arguments-if not given, then the function system:command-line-arguments is used to retrieve the actual command line arguments given to the invoked image. body is a list of forms.
For example,
(with-command-line-arguments ("o:bc" output-file bflag cflag) (rest)
...)
will bind output-file to the argument following -o, bflag to
t
or nil
depending on whether or not -b is present, and
cflag to t
or nil
depending on whether or not -c
is present.
Command line arguments, when given to a vanilla LISP are not all that interesting. When developing an application, however, there are often many uses for command line arguments.
EXAMPLES
;; If the below is invoked in an image with a restart function, it ;; would view the command line in this way: 1) -m binds the variable ;; mail, 2) -r binds the variable real, 3) -d cases *debug* to be set ;; and a break loop entered rather than calling the function ;; SCHEDULE, and 4) if no arguments are given, then it is assumed that ;; debugging is desired and a break loop is entered in this case as well. ;; (sys:with-command-line-arguments ("mrd" mail real debug) (arguments) ;; don't bind it, because of multiprocessing... (setq *debug* debug) (when (cdr arguments) (bye 1 "extra arguments:~{ ~a~}" (cdr arguments))) (when (null arguments) (setq *debug* t) (break "debug away...")) (schedule (car arguments) :real real :mail mail) (bye))
The general documentation description is in introduction.htm. The index is in index.htm.
Copyright (C) 1998-1999, Franz Inc., Berkeley, CA. All Rights Reserved.