home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / c / WILDCARD.ZIP / WILDCARD.C < prev   
Encoding:
Text File  |  1993-01-04  |  1.9 KB  |  77 lines

  1. /*
  2.  *    Wildcard matching routine for MSDOS V2.xx, Lattice C V2.xx.
  3.  *
  4.  *    Requires "find1st" and "findnext" from FIND.ASM.  User passes
  5.  *    in a legal MSDOS wildcard, an attribute bit mask, and a buffer.
  6.  *    On the first call, the wildcard is passed to DOS, and the
  7.  *    routine returns 0 if there was no match.  If a match occurs,
  8.  *    the first matching file name in the directory is copied into
  9.  *    the buffer.  Subsequent calls ignore the first two parameters
  10.  *    and copy the next succeding files to the buffer at the third
  11.  *    parameter.  When no further matches exist the function returns
  12.  *    FALSE (0).  Typical usage is:
  13.  *
  14.  *        if (!wildcard(pattern, 0x10, filename))
  15.  *            /* error, no match */
  16.  *        else
  17.  *            do {
  18.  *                /* process filename */
  19.  *            } while (wildcard(0, 0, filename));
  20.  *
  21.  *    Author:        Ross Nelson
  22.  *            10 November 1983
  23.  *    Modified:    Tony Movshon
  24.  *            8 August 1984
  25.  */
  26.  
  27. #include <ctype.h>
  28.  
  29. struct dta {
  30.     char reserve[21];
  31.     char attrib;
  32.     unsigned time;
  33.     unsigned date;
  34.     long size;
  35.     char name[13];
  36.     };
  37.  
  38. static struct dta info;
  39. static int repeat = 0;
  40. static char dir[64];
  41.  
  42. int wildcard (wc, attr, file)
  43. char *wc, attr, *file;
  44. {
  45.     if (!repeat) {
  46.         get_header (wc, dir);    /* save directory prefix */
  47.         repeat = find1st (wc, attr, &info);
  48.         }
  49.     else
  50.         repeat = findnext (&info);
  51.     if (repeat) {
  52.         strcpy (file, dir);    /* directory prefix */
  53.         strcat (file, info.name);  /* file name */
  54.         while (*file) {
  55.             *file = tolower (*file);
  56.             file++;
  57.             }
  58.         }
  59.     return (int) repeat;
  60. }
  61. /*
  62.  * Strip device or directory header, i.e. dev: or \dir\ or /dir/
  63.  */
  64. static get_header (s, head)
  65. char *s, *head;
  66. {
  67.     char *ptr;
  68.  
  69.     ptr = s + strlen (s);
  70.     while (s < ptr--)
  71.         if ((*ptr == '\\') || (*ptr == '\/') || (*ptr == ':'))
  72.             break;
  73.     while (s <= ptr)
  74.         *head++ = *s++;
  75.     *head = '\0';
  76. }
  77.