init_cli,init_cli_argv,init_cli_for Routines

These routines are used to "DCL parse" (foreign) command-lines independent of the way the command was invoked:
It may be by a command defined as a DCL symbol
(e.g. test := $dev:[dir]test.exe).
It may be called via "MCR dev:[dir]file"
Or it may be defined in DCL tables via "SET COMMAND file.CLD"
In all cases DCL syntax is checked, and the items for CLI$ calls are prepared.

init_cli comes in two versions: init_cli.c for C-programs, passing strings as "char *" pointer.
init_cli_for.for for Fortran (or Pascal...) programs , passing strings by descriptor.
Both versions produce the same results.
The original C routine has been written by Joe Meadows. I changed slightly the way the command verb is checked to decide if it is necessary to call CLI$DCL_parse, and added a check for "MCR" or "RUN" imvocation method.

Calling sequences:

C:

int init_cli(char *table, char *name)

Fortran and other "by descriptor" languages:
integer function init_cli_for(table, name)
byte table , character*(*) name

Table is a pointer to a CLI table module, as produced by SET COMMAND/OBJECT, and the resulting .OBJ linked together with the program.
Usually this will be an external reference to the calling program. ("extern" in C, "external" in Fortran).
name is the VERB defined in the command definition (CLD) .

Verb is matched against the $VERB item of the actual commandline invoking the program: if it is identical, CLI$DCL_parse is not called, and the routine returns succes without doing more.
(If verb is identical, it is assumed to be in DCLtables, and therefore is alread parsed by DCL before program invocation. To make this working, a foreign command overriding the verb should not be defined if the verb is already in DCLtables.)
The funtion result is the result of the last library call, usually the one from CLI$DCL_parse().

After calling init_cli or init_cli_for, the program can start to get the parsed command line items by means of cli$present and cli$get_value calls.
This way the programmer does not have to worry about how a system manager or user is installing and using the program produced.

Just because I'm curious, I made a 3rd version, init_cli_argv.c:

int init_cli_argv(char *table, char *verb, int argc, char *argv[])
It does not use the CLI$ $LINE item to get the commandline to be parsed, but uses the standard C main(argn,argv[]) arguments to produce the command-line. There might be subtle differences in handling of string quotes and/or upper/lower case.


Joseph Huber