void parseargs(argv, argd)
char *argvp[];
ARGDESC argd[];
When invoked interactively, under the UNIX operating system and if parseargs has been compiled for interactive operation, parseargs prompts the user for argument values that are required but are not given on the command line, and values that are supplied but syntactically incorrect.
By default this option is not compiled in to avoid problems in shell scripts, where a program unexpectedly going into interactive mode might tun out to be a little disconcerting.
Given a description of possible arguments, usage prints a reasonably friendly version of this description.
The argument description vector contains one entry for each possible flag. Each entry has five fields:
The list of arguments is terminated using ENDOFARGS.
For example, consider the description:
int RepCount = 2; BOOL Verbose = FALSE; char *InFile; char *OutFile = CHARNULL; BOOL XRated = FALSE; struct namelist *Files = NULL; ARGDESC Args[] = { 'c', ARGOPT, argInt, __ &RepCount, "REPcount", 'v', ARGOPT, argBool, __ &Verbose, "Verbose", ' ', ARGREQ, argStr, __ &InFile, "INPUTfile", ' ', ARGOPT, argStr, __ &OutFile, "OUTPUTfile", 'X', ARGHIDDEN, argBool, __ &XRated, "XratedMODE", ' ', ARGOPT, argList, __ &Files, "File", ENDOFARGS };
This describes a program accepting up to three flag arguments and one or two positional arguments, plus a list of additional file arguments. Only the first positional argument is required. The possible flags (in UNIX) are:
The two positional arguments are both strings, as is the final list. In AmigaDOS, the options would be REP count, V, and MODE.
BOOL argXxx(argd, argp, copyf) ARGDESC *argd; char *argp; BOOL copyf;
The argd argument points to the descriptor for the argument being converted. Its main use is to find the location in which to store the converted value, located in argd->ad_valp. The string value to be converted is passed in argp. The copyf flag is TRUE if the argp string value must be copied when saved. Most non-string types are copied implicitly (for example, integer arguments are stored in binary form, so the original string value need not be saved), so this argument can usually be ignored. Put simply, this flag is TRUE when argp points to a temporary buffer area.
The type function successfully converts the value, it should return TRUE. Otherwise, it should print a message using usrerr(3) and return FALSE. This message should be of the form "invalid xxxx option 'yyyy' for Zzzz", where xxxx is the type of the option, yyyy is the string passed in vp, and zzzz is the name (taken from ad->ad_prompt).
For example, a type function that took a filename and stored an open file pointer might be coded as:
/*ARGSUSED*/ BOOL argReadFile(argd, argp, copyf) register ARGDESC *argd; register char *argp; BOOL copyf; { register FILE *fp; fp = fopen(argp, "r"); if (fp == NULL) { usrerr("cannot open '%s' for reading as %s", argp, argd->ad_prompt); return (FALSE); } *(FILE *) argd->ad_valp = fp; return (TRUE); }