home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / BRIK.ZIP / VMS.C < prev   
C/C++ Source or Header  |  1989-03-10  |  2KB  |  82 lines

  1. /*
  2. **   A wildcard expansion function for VAX/VMS
  3. **   -- Rahul Dhesi
  4. */
  5. /* ::[[ @(#) vms.c 1.5 89/03/10 19:09:28 ]]:: */
  6. #ifndef LINT
  7. static char sccsid[]="::[[ @(#) vms.c 1.5 89/03/10 19:09:28 ]]::";
  8. #endif
  9.  
  10. /*
  11. Checksum: 3221488897     (verify or update with "brik")
  12. */
  13.  
  14. #include <descrip.h>
  15.  
  16. #define  FMAX  3        /* Number of different filename patterns */
  17. #define  PATHSIZE 1024  /* buffer area to store pathname */
  18.  
  19. char *nextfile (what, filespec, fileset)
  20. int what;                        /* whether to initialize or match      */
  21. register char *filespec;         /* filespec to match if initializing   */
  22. register int fileset;            /* which set of files                  */
  23. {
  24.    int status;
  25.    char *p;                      /* temp ptr */
  26.    struct dsc$descriptor_s d_fwild, d_ffound;
  27.    static int first_time [FMAX+1];
  28.    static char saved_fspec [FMAX+1][PATHSIZE];  /* our own copy of filespec */
  29.    static char found_fspec [FMAX+1][PATHSIZE];  /* matched filename */
  30.    static unsigned long context [FMAX+1]; /* needed by VMS */
  31.    if (what == 0) {
  32.       strcpy (saved_fspec[fileset], filespec);  /* save the filespec */
  33.       first_time[fileset] = 1;
  34.       return (0);
  35.    }
  36.  
  37.    /* Reach here if what is not 0, so it must be 1 */
  38.  
  39.    /* Create a descriptor for the wildcarded filespec */
  40.    d_fwild.dsc$w_length = strlen (saved_fspec[fileset]);
  41.    d_fwild.dsc$a_pointer = saved_fspec[fileset];
  42.    d_fwild.dsc$b_class = DSC$K_CLASS_S;
  43.    d_fwild.dsc$b_dtype = DSC$K_DTYPE_T;
  44.  
  45.    d_ffound.dsc$w_length = sizeof (found_fspec[fileset]);
  46.    d_ffound.dsc$a_pointer = found_fspec[fileset];
  47.    d_ffound.dsc$b_class = DSC$K_CLASS_S;
  48.    d_ffound.dsc$b_dtype = DSC$K_DTYPE_T;
  49.  
  50.    if (first_time[fileset]) {
  51.       first_time[fileset] = 0;
  52.       context[fileset] = 0L;   /* tell VMS this is first search */
  53.    }
  54.    status = LIB$FIND_FILE (&d_fwild, &d_ffound, &context[fileset]);
  55.    status = status & 1; /* use only lowest bit */
  56.  
  57.    if (status == 0) {
  58.       LIB$FIND_FILE_END (&context[fileset]);
  59.       return ((char *) 0);
  60.    } else {
  61.       found_fspec[fileset][d_ffound.dsc$w_length] = '\0'; /* just in case */
  62.       p = found_fspec[fileset];
  63.       while (*p != ' ' && *p != '\0')
  64.          p++;
  65.       if (*p != '\0')
  66.          *p = '\0';
  67.       return (found_fspec[fileset]);
  68.    }
  69. }
  70.  
  71. /* Compensate for bug in VAX/VMS C exit() function */
  72.  
  73. #ifdef exit
  74. # undef exit
  75. #endif
  76.  
  77. int bugexit (n)
  78. int n;
  79. {
  80.    exit (1);
  81. }
  82.