[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::hackers_v1

Title:-={ H A C K E R S }=-
Notice:Write locked - see NOTED::HACKERS
Moderator:DIEHRD::MORRIS
Created:Thu Feb 20 1986
Last Modified:Mon Aug 03 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:680
Total number of notes:5456

330.0. "Help on CLI . . ." by THEBUS::KOSTAS (Wisdom is the child of experience.) Tue Oct 07 1986 11:33

    Hello,
    
         This is a very trivial problem for this notes files but I have
    entered here anyway. The problem is this:
    
      What is the best way to implement a command such as 
    
         CAT/VERSION=<string>/DIRECTORY=<vms dir spec>/LOG

      where  <string>        can be any character string of fixed size
                             of 12 characters
             <vms dir spec>  can be a vms directory specification
                             i.e.  DIRECTORY=PIN:[KOSTAS.TEST]

      examples of use:
    
       1.  CAT /DIRECTORY=PIN:[KOSTAS.TEST]  
       2.  CAT /VERSION=V1.0-000 /LOG
       3.  CAT /VERSION=LATEST /DIRECTORY=PIN:[KOSTAS.TEST]/LOG

      Now the qualifiers /VERSION and /DIRECTORY and /LOG are optional,
      they are not required to be present.
    
    What I am interested is a working example that makes use of the
    CLI$xxx system services or the DCL f$xxx lexicals. The examples can
    be in DCl, PASCAL, BLISS, etc...
    
    Thanks,
    
    Kostas G.
    
T.RTitleUserPersonal
Name
DateLines
330.1No ProblemCLOSET::DYERThe Weird Turn ProTue Oct 07 1986 18:10102
Can't do it in DCL, except in a kludgy way.  Your first step is to make
 a .CLD file:

	module CATZ_MEOW

	define verb CAT
	  qualifier DIRECTORY, value(required)
	  qualifier LOG
	  qualifier VERSION, value(required)

Now you compile that with SET COMMAND/OBJECT and you have an .OBJ file.
 Next step is to write a program to link this to.  The program should
  o Get the command line with the LIB$GET_FOREIGN() routine.
   o Parse that command line against the CATZ_MEOW tables using the
    CLI$DCL_PARSE() routine.
    o Check for each of the three qualifiers with the CLI$PRESENT()
     routine to see if they're there.
      o For /DIRECTORY and /VERSION, if they're present, get their
       values with the CLI$GET_VALUE() routine.

Here's a C program to do that, written from the top of my head:

#include <climsgdef.h>
#include <descrip.h>
#include <ssdef.h>
#include <stsdef.h>

main()
{
  globalvalue CATZ_MEOW;

  char buffer[1024];
  short int log_present = 0;
  unsigned int status;
  struct dsc$descriptor_d directory_d = {0,DSC$K_DTYPE_T,DSC$K_CLASS_D,0};
  struct dsc$descriptor_d version_d = {0,DSC$K_DTYPE_T,DSC$K_CLASS_D,0};
  $DESCRIPTOR(buffer_d,buffer);
  $DESCRIPTOR(kwd_DIRECTORY_d,"DIRECTORY");
  $DESCRIPTOR(kwd_LOG_d,"LOG");
  $DESCRIPTOR(kwd_VERSION_d,"VERSION");

  buffer[0] = 'C';			/* 'C' is for CAT. */
  buffer[1] = ' ';			/* Space between verb and arguments. */
  buffer_d.dsc$a_pointer = &buffer[2];
  buffer_d.dsc$w_length -= 2;
  if ((status = lib$get_foreign(
    &buffer_d,
    0,
    &buffer_d.dsc$w_length,
    0
  )) != SS$_NORMAL)
   exit(status);
  buffer_d.dsc$a_pointer = &buffer[0];
  buffer_d.dsc$w_length += 2;

  if ((status = cli$dcl_parse(
    &buffer_d,
    CATZ_MEOW,
    0,0,0
  )) != CLI$_NORMAL)
   exit(status | STS$M_INHIB_MSG);

  if (cli$present(&kwd_DIRECTORY_d) == CLI$_PRESENT)
  {
    if ((status = cli$get_value(
      &kwd_DIRECTORY_d,
      &directory_d,
      &directory_d.dsc$w_length
    )) != SS$_NORMAL)
     exit(status);
  }

  if (cli$present(&kwd_LOG_d) == CLI$_PRESENT)
   log_present = 1;

  if (cli$present(&kwd_VERSION_d) == CLI$_PRESENT)
  {
    if ((status = cli$get_value(
      &kwd_VERSION_d,
      &version_d,
      &version_d.dsc$w_length
    )) != SS$_NORMAL)
     exit(status);
  }

  /* Now you've got all the information you need.  Let's roll it back now. */

  if (directory_d.dsc$w_length)
  {
    printf("\nDirectory:\r");
    lib$put_output(&directory_d);
  }

  if (log_present)
   printf("\n/LOG was specified\r");

  if (version_d.dsc$w_length)
  {
    printf("\nVersion:\r");
    lib$put_output(&version_d);
  }
}