/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <descrip.h>

int lib$get_foreign();
int cli$dcl_parse();
int cli$present();
int cli$get_value();

int urlscan_cld();

void cli_dcl_parse()
{
   short l;
   char cmdlin[512],tmp[512];
   $DESCRIPTOR(cmddes,cmdlin);
   lib$get_foreign(&cmddes,0,&l);
   cmdlin[l]='\0';
   strcpy(tmp,cmdlin);
   sprintf(cmdlin,"URLSCAN %s",tmp);
   cmddes.dsc$w_length=strlen(cmdlin);
   cli$dcl_parse(&cmddes,urlscan_cld);
   return;
}

int cli_present(char *itm)
{
   long stat;
   struct dsc$descriptor itmdes;
   itmdes.dsc$w_length=strlen(itm);
   itmdes.dsc$b_dtype=DSC$K_DTYPE_T;
   itmdes.dsc$b_class=DSC$K_CLASS_S;
   itmdes.dsc$a_pointer=itm;
   stat=cli$present(&itmdes);
   if(stat&1) return 1; else return 0;
}

char *cli_get_value(char *itm)
{

   long stat;
   short l;
   char *s;
   struct dsc$descriptor itmdes,sdes;
   s=malloc(256);
   itmdes.dsc$w_length=strlen(itm);
   itmdes.dsc$b_dtype=DSC$K_DTYPE_T;
   itmdes.dsc$b_class=DSC$K_CLASS_S;
   itmdes.dsc$a_pointer=itm;
   sdes.dsc$w_length=256;
   sdes.dsc$b_dtype=DSC$K_DTYPE_T;
   sdes.dsc$b_class=DSC$K_CLASS_S;
   sdes.dsc$a_pointer=s;
   stat=cli$get_value(&itmdes,&sdes,&l);
   if(stat&1) {
      s[l]='\0';
      return s;
   } else {
      return NULL;
   }
}
