home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / debug / common / wild.c < prev   
Encoding:
C/C++ Source or Header  |  1995-03-21  |  1.7 KB  |  74 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. /* This is file WILD.C */
  3. /*
  4. ** Copyright (C) 1993 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. **
  6. ** This file is distributed under the terms listed in the document
  7. ** "copying.dj", available from DJ Delorie at the address above.
  8. ** A copy of "copying.dj" should accompany this file; if not, a copy
  9. ** should be available from where this file was obtained.  This file
  10. ** may not be distributed without a verbatim copy of "copying.dj".
  11. **
  12. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  13. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. */
  15.  
  16. #include <string.h>
  17. #include <debug/wild.h>
  18.  
  19. int wild(char *pattern, char *string)
  20. {
  21.   int nlit;
  22.   while (*pattern)
  23.   {
  24.     switch (*pattern)
  25.     {
  26.       case '*':
  27.         pattern++;
  28.         if (*pattern == 0)
  29.           return 1;
  30.         nlit=0;
  31.         while ((pattern[nlit] != 0)
  32.             && (pattern[nlit] != '*')
  33.             && (pattern[nlit] != '?') )
  34.           nlit++;
  35.         while (1)
  36.         {
  37.           if (strncmp(string, pattern, nlit) == 0)
  38.             break;
  39.           string++;
  40.           if (*string == 0)
  41.             return 0;
  42.         }
  43.         break;
  44.       case '?':
  45.         if (*string == 0)
  46.           return 0;
  47.         pattern++;
  48.         string++;
  49.         break;
  50.       default:
  51.         if (*pattern != *string)
  52.           return 0;
  53.         pattern++;
  54.         string++;
  55.         break;
  56.     }
  57.   }
  58.   if (*string)
  59.     return 0;
  60.   return 1;
  61. }
  62.  
  63. #ifdef DEBUG
  64. main(int argc, char **argv)
  65. {
  66.   int i;
  67.   if (argc < 3)
  68.     return 1;
  69.   for (i=2; argv[i]; i++)
  70.     printf("%s %s %d\n", argv[1], argv[i], wild(argv[1], argv[i]));
  71.   return 0;
  72. }
  73. #endif
  74.