home *** CD-ROM | disk | FTP | other *** search
- /*============================================================================
- =
-
- CLI.C -- Simple C interfaces to VMS CLI$ utilities.
-
- -----------------------------------------------------------------------------*
- /
-
- #include descrip
- #include climsgdef
- #define STS$M_SUCCESS 1
-
- /*============================================================================
- =
-
- cli_value -- Get the value of a CLI parameter or qualifier.
-
- This is an interface to the VMS utility routine CLI$VALUE that
- is easy to call in a C language program. It does the grunge
- work of creating string descriptors from C style NUL terminated
- strings etc. cli_value returns the value associated with the
- specified command line entity in the character array pointed to
- by 'value'.
-
- If the requested entity was present in the command line (even in
- negated form), cli_value's function return value is a non-zero
- (TRUE) value. If the entity was absent, a zero value (FALSE) is
- returned by cli_value. The actual value returned depends on whether
- 'value' was NULL or not. If it wasn't, cli_value returns a TRUE
- value that is the status returned by CLI$VALUE. If 'value' was
- NULL, cli_value returns the status returned by CLI$PRESENT. (This
- to provide access to the return values from CLI$PRESENT since CLI_-
- KEYWORD returns only 0 or 1).
-
-
- Calling sequence:
- n = cli_value (name, value, value_size);
-
- Parameters:
- char *name;
- Pointer to a NUL terminated character string that contains
- the name of the parameter, qualifier or keyword path whose
- value is wanted.
- char *value;
- NULL or a pointer to a character buffer of 'value_size' bytes
- that will receive the entity's value. If not NULL, the entity's
- value is copied into 'value' in the form of a NUL terminated
- text string. If the entity was absent, 'value' is set to a
- null string ("").
- int value_size;
- The size of the buffer 'value' in bytes. No more than this many
- byte will be written to 'value'.
-
- Returns: int n;
- cli_value returns 0 (FALSE) if the requested parameter,
- qualifier, or keyword path, was absent from the command
- line. If it was present (even in negated form), cli_value
- returns a non-zero (TRUE) value that depends on whether or
- not 'value' is non-NULL.
-
- If 'value' was non-NULL, the value returned is the status
- from the CLI$VALUE routine (CLI$_COMMA, CLI$_CONCAT,
- CLI$_NORMAL).
-
- If 'value' was NULL, then cli_value returns the status from
- the CLI$PRESENT routine (CLI$_PRESENT, CLI$NEGATED, CLI$_LOCPRES,
- CLI$LOCNEG, CLI$_DEFAULTED).
-
- Examples:
- The most common way of using cli_value is to get the value of
- a parameter or qualifier. If a .CLD file contained:
-
- PARAMETER P1, LABEL=INFILE,
- VALUE (REQUIRED, TYPE=$INFILE)
-
- then the call below would read the value of the parameter and put
- it in 'input_fn'.
-
- char input_fn[256];
- ....
- cli_value ("INFILE", input_fn, sizeof (input_fn));
-
- Reading a list of values is just as easy:
-
- PARAMETER P1, LABEL=INFILE,
- VALUE (REQUIRED, LIST, TYPE=$INFILE)
-
- char input_fn[256];
- ....
- while (cli_value ("INFILE", input_fn, sizeof (input_fn)))
- {
- ....process 'input_fn'....
- }
-
-
- -----------------------------------------------------------------------------
-
- 4/12/88 - Stuart McGraw.
- Put a trailing NUL in 'value' regardless of the return code
- since CLI$GET_VALUE will blank fill it even if the requested
- qualifier is absent.
- 3/2/86 - Stuart McGraw, GTE Labs (sjm0@gte.com)
-
- -----------------------------------------------------------------------------*
- /
-
- int
- cli_value (name, value, vsize)
- char *name;
- char *value;
- int vsize;
- {
- int status;
- short ret_length = 0;
- struct dsc$descriptor qul;
- struct dsc$descriptor qvl;
-
- qul.dsc$b_class = DSC$K_CLASS_S;
- qul.dsc$b_dtype = DSC$K_DTYPE_T;
- qul.dsc$w_length = strlen (name);
- qul.dsc$a_pointer = name;
-
- if (value) {
- qvl.dsc$b_class = DSC$K_CLASS_S;
- qvl.dsc$b_dtype = DSC$K_DTYPE_T;
- qvl.dsc$w_length = vsize - 1;
- qvl.dsc$a_pointer = value;
-
- status = CLI$GET_VALUE (&qul, &qvl, &ret_length);
- value[ret_length] = 0;
- if (status == CLI$_ABSENT)
- return (0);
- return (status);
- }
- status = CLI$PRESENT (&qul);
- return (status == CLI$_ABSENT ? 0 : status);
- }
-
- /*============================================================================
- =
-
- cli_qualifier -- Return TRUE or FALSE depending on presence of entity.
-
- Will return a 1 (TRUE) if the entity 'name' was specified or
- present by default in the DCL command line or 0 (FALSE) if it was
- specified and negated. If it wasn't specified at all (and no default
- was specified in the CLD tables), the value 'deflt' is returned.
-
- Calling sequence:
- n = cli_qualifier (name, deflt);
-
- Parameters:
- char *name;
- Pointer to a NUL terminated string that contains the name
- of the command line parameter, qualifier, or keyword path.
- int deflt;
- A value that will be returned if the entity was not present
- in the command line (either explicitly or by default).
-
- Returns:
- int n;
- 1 if the entity was present and not negated. 0 if the
- entity was present and negated. The value of 'deflt'
- if the entity wasn't present.
-
- Examples:
- This simplest use is to set the value of a variable depending
- on whether or not a qualifier was specified in the command line.
- Assuming a .CLD file like:
-
- QUALIFIER DEBUG
-
- we could use the this code to set the variable 'dbg':
-
- dbg = cli_qualifier ("DEBUG", 0);
-
- For this use, you generally don't want to make use of the
- 'deflt' parameter. To make /DEBUG the default it is better
- to modify the .CLD file to:
-
- QUALIFIER FLAG, DEFAULT
-
- since this lets you change defaults without recompiling the
- program.
-
- The next example illustrate where the 'deflt' parameter is
- useful. Assume a command definition file that looks like:
-
- DEFINE TYPE DEBUG_TYPES
- keyword ALL
- keyword RANGE
- keyword AUDIO
- keyword INITIAL
- keyword CLEANUP
- QUALIFIER DEBUG, VALUE (TYPE=DEBUG_TYPES)
-
- where we want to be able to use the qualifier like:
-
- /DEBUG=(RANGE,AUDIO)
- /DBUG=ALL
- /DEBUG=(ALL,NOCLEANUP)
-
- Here is how that can easily be done by using the ALL value as a
- default for the remainder:
-
- all = cli_qualifier ("DEBUG.ALL", 0);
- dbg_rng = cli_qualifier ("DEBUG.RANGE", all);
- dbg_audio = cli_qualifier ("DEBUG.AUDIO", all);
- dbg_init = cli_qualifier ("DEBUG.INITIAL", all);
- dbg_clnup = cli_qualifier ("DEBUG.CLEANUP", all);
-
-
- ------------------------------------------------------------------------------
-
- 3/2/86 - Stuart McGraw, GTE Labs. (sjm0@gte.com)
-
- -----------------------------------------------------------------------------*
- /
-
- int
- cli_qualifier (name, deflt)
- char *name;
- int deflt;
- {
- int status;
- struct dsc$descriptor qul;
-
- qul.dsc$b_class = DSC$K_CLASS_S;
- qul.dsc$b_dtype = DSC$K_DTYPE_T;
- qul.dsc$w_length = strlen (name);
- qul.dsc$a_pointer = name;
-
- status = CLI$PRESENT (&qul);
- if (status == CLI$_PRESENT ||
- status == CLI$_DEFAULTED ||
- status == CLI$_LOCPRES) {
- return (1);
- }
- if (status == CLI$_NEGATED ||
- status == CLI$_LOCNEG) {
- return (0);
- }
- /* else (status == CLI$_ABSENT) */
- return (deflt);
- }
-
- /*
- cli_qualifier used to be called cli_keyword. The routine below is
- so that old programs that call the former will still link and run
- without any source code changes.
- */
- int
- cli_keyword (name, deflt)
- char *name;
- int deflt;
- {
- return cli_qualifier (name, deflt);
- }
-