home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / FLEX / FLEX-2.4 / FLEX-2 / flex-2.4.7 / MISC / VMS / VMS.more-stuff / cli.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-26  |  7.4 KB  |  259 lines

  1. /*============================================================================
  2. =
  3.  
  4.     CLI.C -- Simple C interfaces to VMS CLI$ utilities.
  5.  
  6. -----------------------------------------------------------------------------*
  7. /
  8.  
  9. #include descrip
  10. #include climsgdef
  11. #define STS$M_SUCCESS 1
  12.  
  13. /*============================================================================
  14. =
  15.  
  16.     cli_value -- Get the value of a CLI parameter or qualifier.
  17.  
  18.     This is an interface to the VMS utility routine CLI$VALUE that
  19.     is easy to call in a C language program.  It does the grunge
  20.     work of creating string descriptors from C style NUL terminated
  21.     strings etc.  cli_value returns the value associated with the
  22.     specified command line entity in the character array pointed to
  23.     by 'value'.
  24.  
  25.     If the requested entity was present in the command line (even in
  26.     negated form), cli_value's function return value is a non-zero
  27.     (TRUE) value.  If the entity was absent, a zero value (FALSE) is
  28.     returned by cli_value.  The actual value returned depends on whether
  29.     'value' was NULL or not.  If it wasn't, cli_value returns a TRUE
  30.     value that is the status returned by CLI$VALUE.  If 'value' was
  31.     NULL, cli_value returns the status returned by CLI$PRESENT.  (This
  32.     to provide access to the return values from CLI$PRESENT since CLI_-
  33.     KEYWORD returns only 0 or 1).
  34.  
  35.  
  36.     Calling sequence:
  37.     n = cli_value (name, value, value_size);
  38.  
  39.     Parameters:
  40.     char *name;
  41.       Pointer to a NUL terminated character string that contains
  42.       the name of the parameter, qualifier or keyword path whose
  43.       value is wanted.
  44.     char *value;
  45.       NULL or a pointer to a character buffer of 'value_size' bytes
  46.       that will receive the entity's value.  If not NULL, the entity's
  47.       value is copied into 'value' in the form of a NUL terminated
  48.       text string.  If the entity was absent, 'value' is set to a
  49.       null string ("").
  50.     int value_size;
  51.       The size of the buffer 'value' in bytes.  No more than this many
  52.       byte will be written to 'value'.
  53.  
  54.     Returns:  int n;
  55.     cli_value returns 0 (FALSE) if the requested parameter,
  56.     qualifier, or keyword path, was absent from the command
  57.     line.  If it was present (even in negated form), cli_value
  58.     returns a non-zero (TRUE) value that depends on whether or
  59.     not 'value' is non-NULL.  
  60.  
  61.     If 'value' was non-NULL, the value returned is the status
  62.     from the CLI$VALUE routine (CLI$_COMMA, CLI$_CONCAT,
  63.     CLI$_NORMAL).
  64.  
  65.     If 'value' was NULL, then cli_value returns the status from
  66.     the CLI$PRESENT routine (CLI$_PRESENT, CLI$NEGATED, CLI$_LOCPRES,
  67.     CLI$LOCNEG, CLI$_DEFAULTED).
  68.  
  69.     Examples:
  70.     The most common way of using cli_value is to get the value of
  71.     a parameter or qualifier.  If a .CLD file contained:
  72.  
  73.         PARAMETER P1, LABEL=INFILE,
  74.             VALUE (REQUIRED, TYPE=$INFILE)
  75.  
  76.     then the call below would read the value of the parameter and put
  77.     it in 'input_fn'.
  78.  
  79.         char input_fn[256];
  80.          ....
  81.         cli_value ("INFILE", input_fn, sizeof (input_fn));
  82.  
  83.     Reading a list of values is just as easy:
  84.  
  85.         PARAMETER P1, LABEL=INFILE, 
  86.             VALUE (REQUIRED, LIST, TYPE=$INFILE)
  87.  
  88.         char input_fn[256];
  89.          ....
  90.         while (cli_value ("INFILE", input_fn, sizeof (input_fn)))
  91.             {
  92.             ....process 'input_fn'....
  93.             }
  94.  
  95.  
  96. -----------------------------------------------------------------------------
  97.  
  98.     4/12/88 - Stuart McGraw.
  99.     Put a trailing NUL in 'value' regardless of the return code
  100.     since CLI$GET_VALUE will blank fill it even if the requested
  101.     qualifier is absent.
  102.     3/2/86 - Stuart McGraw, GTE Labs (sjm0@gte.com)
  103.  
  104. -----------------------------------------------------------------------------*
  105. /
  106.  
  107. int
  108. cli_value (name, value, vsize)
  109.     char *name;
  110.     char *value;
  111.     int vsize;
  112.     {
  113.     int status;
  114.     short ret_length = 0;
  115.     struct dsc$descriptor qul;
  116.     struct dsc$descriptor qvl;
  117.  
  118.     qul.dsc$b_class = DSC$K_CLASS_S;
  119.     qul.dsc$b_dtype = DSC$K_DTYPE_T;
  120.     qul.dsc$w_length = strlen (name);
  121.     qul.dsc$a_pointer = name;
  122.  
  123.     if (value) {
  124.         qvl.dsc$b_class = DSC$K_CLASS_S;
  125.         qvl.dsc$b_dtype = DSC$K_DTYPE_T;
  126.         qvl.dsc$w_length = vsize - 1;
  127.         qvl.dsc$a_pointer = value;
  128.  
  129.         status = CLI$GET_VALUE (&qul, &qvl, &ret_length);
  130.         value[ret_length] = 0;
  131.         if (status == CLI$_ABSENT)
  132.         return (0);
  133.         return (status);
  134.         }
  135.     status = CLI$PRESENT (&qul);
  136.     return (status == CLI$_ABSENT ? 0 : status);
  137.     }
  138.  
  139. /*============================================================================
  140. =
  141.  
  142.     cli_qualifier -- Return TRUE or FALSE depending on presence of entity.
  143.  
  144.     Will return a 1 (TRUE) if the entity 'name' was specified or
  145.     present by default in the DCL command line or 0 (FALSE) if it was
  146.     specified and negated.  If it wasn't specified at all (and no default
  147.     was specified in the CLD tables), the value 'deflt' is returned.
  148.  
  149.     Calling sequence:
  150.     n = cli_qualifier (name, deflt);
  151.  
  152.     Parameters:
  153.     char *name;
  154.       Pointer to a NUL terminated string that contains the name
  155.       of the command line parameter, qualifier, or keyword path.
  156.     int deflt;
  157.       A value that will be returned if the entity was not present
  158.       in the command line (either explicitly or by default).
  159.  
  160.     Returns:
  161.     int n;
  162.       1 if the entity was present and not negated.  0 if the
  163.       entity was present and negated.  The value of 'deflt'
  164.       if the entity wasn't present.
  165.  
  166.     Examples:
  167.     This simplest use is to set the value of a variable depending
  168.     on whether or not a qualifier was specified in the command line.
  169.     Assuming a .CLD file like:
  170.  
  171.         QUALIFIER DEBUG
  172.  
  173.     we could use the this code to set the variable 'dbg':
  174.  
  175.         dbg = cli_qualifier ("DEBUG", 0);
  176.  
  177.     For this use, you generally don't want to make use  of the
  178.         'deflt' parameter.   To make /DEBUG the default it is better
  179.     to modify the .CLD file to:
  180.  
  181.         QUALIFIER FLAG, DEFAULT
  182.  
  183.     since this lets you change defaults without recompiling the
  184.     program.
  185.  
  186.     The next example illustrate where the 'deflt' parameter is 
  187.     useful.  Assume a command definition file that looks like:
  188.  
  189.         DEFINE TYPE DEBUG_TYPES
  190.             keyword ALL
  191.             keyword RANGE
  192.             keyword AUDIO
  193.             keyword INITIAL
  194.             keyword CLEANUP
  195.         QUALIFIER DEBUG, VALUE (TYPE=DEBUG_TYPES)
  196.  
  197.     where we want to be able to use the qualifier like:
  198.  
  199.         /DEBUG=(RANGE,AUDIO)
  200.         /DBUG=ALL
  201.         /DEBUG=(ALL,NOCLEANUP)
  202.  
  203.     Here is how that can easily be done by using the ALL value as a
  204.     default for the remainder:
  205.  
  206.         all       = cli_qualifier ("DEBUG.ALL", 0);
  207.         dbg_rng   = cli_qualifier ("DEBUG.RANGE", all);
  208.         dbg_audio = cli_qualifier ("DEBUG.AUDIO", all);
  209.         dbg_init  = cli_qualifier ("DEBUG.INITIAL", all);
  210.         dbg_clnup = cli_qualifier ("DEBUG.CLEANUP", all);
  211.  
  212.  
  213. ------------------------------------------------------------------------------
  214.  
  215.     3/2/86 - Stuart McGraw, GTE Labs. (sjm0@gte.com)
  216.  
  217. -----------------------------------------------------------------------------*
  218. /
  219.  
  220. int
  221. cli_qualifier (name, deflt)
  222.     char *name;
  223.     int deflt;
  224.     {
  225.     int status;
  226.     struct dsc$descriptor qul;
  227.  
  228.     qul.dsc$b_class = DSC$K_CLASS_S;
  229.     qul.dsc$b_dtype = DSC$K_DTYPE_T;
  230.     qul.dsc$w_length = strlen (name);
  231.     qul.dsc$a_pointer = name;
  232.  
  233.     status = CLI$PRESENT (&qul);
  234.     if (status == CLI$_PRESENT  ||
  235.       status == CLI$_DEFAULTED ||
  236.       status == CLI$_LOCPRES) {
  237.         return (1);
  238.         }
  239.     if (status == CLI$_NEGATED ||
  240.       status == CLI$_LOCNEG) {
  241.         return (0);
  242.         }
  243.     /* else (status == CLI$_ABSENT) */
  244.     return (deflt);
  245.     }
  246.  
  247. /*
  248.     cli_qualifier used to be called cli_keyword.  The routine below is
  249.     so that old programs that call the former will still link and run
  250.     without any source code changes.
  251. */
  252. int
  253. cli_keyword (name, deflt)
  254.     char *name;
  255.     int deflt;
  256.     {
  257.     return cli_qualifier (name, deflt);
  258.     }
  259.