Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
UnixCommandLine


NAME

UnixCommandLine - Args scanner for the UNIX command line

SYNOPSIS

CONST missingValue = 0;
CONST invalidValue = 1;
CONST unknownOption = 2;
CONST unexpectedArgs = 3;
CONST helpRequested = 4;
CONST errors = 5;
TYPE ErrorEvent = POINTER TO ErrorEventRec;
TYPE ErrorEventRec =
      RECORD
	 (Events.EventRec)
	 args: Args.Arguments;
	 code: SHORTINT; (* missingValue..unexpectedArgs *)
	 name: ARRAY 80 OF CHAR;
      END;
VAR error: Events.EventType;
VAR errormsg: ARRAY errors OF Events.Message;


PROCEDURE Include(scanners: Args.ScannerList; priority: Args.Priority);

DESCRIPTION

UnixCommandLine provides a scanner for the Args module that processes the UNIX command line on base of UnixArguments.

Include adds the scanner of this module to scanners with the given priority. Multiple invocations of Include for different scanner lists are permitted. Actual scans by this module are later on triggered by invocations of Args.Scan with a scanner list that includes this implementation.

During its initialization, UnixCommandLine includes itself to Args.systemScanners at Args.highPriority.

DIAGNOSTICS

A command line that does not match the specification associated with args passed to Args.Scan leads to error events that are related to args:
missingValue
An option was given without an associated value.
invalidValue
An invalid value was given for an option.
unknownOption
An unknown flag or option name was used.
unexpectedArgs
More arguments than expected were found.
helpRequested
Explicit usage help is requested.

EXAMPLE

MODULE ArgsDemo;

   IMPORT Args, Conclusions, Errors, IntArgs, RelatedEvents, StringArgs,
      UnixCommandLine;

   VAR
      args: Args.Arguments;

   PROCEDURE FetchArgs(VAR args: Args.Arguments);
   BEGIN
      Args.Create(args);
      RelatedEvents.QueueEvents(args);
      Args.Define(args, "copies",  "#", IntArgs.type,    "number of copies");
      Args.Define(args, "file",    "f", StringArgs.type, "file to be printed");
      Args.Define(args, "printer", "p", StringArgs.type, "name of the printer");
      Args.Scan(args, Args.systemScanners);
      IF RelatedEvents.EventsPending(args) THEN
         Conclusions.Conclude(args, Errors.fatal, "");
      END;
   END FetchArgs;

BEGIN
   FetchArgs(args);
END ArgsDemo.

SEE ALSO

Args
general abstraction for arguments and options
UnixArguments
interface to the UNIX command line

Edited by: borchert, last change: 2005/08/23, revision: 1.1, converted to HTML: 2005/08/23

Oberon || Library || Module Index || Search Engine || Definition || Module