home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / ArchiveUtils / nx_arc / arcmatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-20  |  3.3 KB  |  144 lines

  1. /*
  2.  * $Log:    arcmatch.c,v $
  3.  * Revision 1.2  88/04/11  18:20:43  hyc
  4.  * fixup pattern matching for BSD...
  5.  * 
  6.  * Revision 1.1  88/04/11  18:12:56  hyc
  7.  * Initial revision
  8.  * 
  9.  * Revision 1.2  87/12/19  04:39:35  hyc
  10.  * Don't convert names to upper case for BSD...
  11.  * 
  12.  * Revision 1.1  87/12/19  04:39:06  hyc
  13.  * Initial revision
  14.  * 
  15.  * Revision 1.3  87/08/13  17:05:01  hyc
  16.  * Run thru indent, fixed some signed vs. unsigned problems
  17.  * with bp <-> buf, and inbuf and localbuf...
  18.  *  Revision 1.2  87/07/21  08:48:16  hyc ***
  19.  * empty log message ***
  20.  * 
  21.  */
  22.  
  23. /*
  24.  * ARC - Archive utility - ARCMATCH
  25.  * 
  26.  * Version 2.17, created on 12/17/85 at 20:32:18
  27.  * 
  28.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  29.  * 
  30.  * By:  Thom Henderson
  31.  * 
  32.  * Description: This file contains service routines needed to maintain an
  33.  * archive.
  34.  * 
  35.  * Language: Computer Innovations Optimizing C86
  36.  */
  37. #include <stdio.h>
  38. #include "arc.h"
  39.  
  40. INT
  41. match(n, t)            /* test name against template */
  42.     char           *n;    /* name to test */
  43.     char           *t;    /* template to test against */
  44. {
  45. #ifdef MTS
  46.     fortran         patbuild(), patmatch(), patfree();
  47.     static int      patlen = (-1);
  48.     static int      patwork = 0;
  49.     static int      patswch = 0;
  50.     char            patccid[4];
  51.     static char     patchar[2] = "?";
  52.     static char     oldtemp[16] = 0;
  53.     int             namlen, RETCODE;
  54.  
  55.     if (strcmp(t, oldtemp)) {
  56.         if (patwork)
  57.             patfree(&patwork);
  58.         strcpy(oldtemp, t);
  59.         patlen = strlen(oldtemp);
  60.         patbuild(oldtemp, &patlen, &patwork, &patswch, patccid, patchar, _retcode RETCODE);
  61.         if (RETCODE > 8) {
  62.             printf("MTS: patbuild returned %d\n", RETCODE);
  63.             arc_abort("bad wildcard in filename");
  64.         }
  65.     }
  66.     namlen = strlen(n);
  67.     patmatch(n, &namlen, &patwork, _retcode RETCODE);
  68.     switch (RETCODE) {
  69.     case 0:
  70.         return (1);
  71.     case 4:
  72.         return (0);
  73.     default:
  74.         arc_abort("wildcard pattern match failed");
  75.     }
  76. }
  77.  
  78. #else
  79. #ifndef    BSD
  80.     upper(n);
  81.     upper(t);        /* avoid case problems */
  82.  
  83.     /* first match name part */
  84.  
  85.     while ((*n && *n != '.') || (*t && *t != '.')) {
  86.         if (*n != *t && *t != '?') {    /* match fail? */
  87.             if (*t != '*')    /* wildcard fail? */
  88.                 return 0;    /* then no match */
  89.             else {    /* else jump over wildcard */
  90.                 while (*n && *n != '.')
  91.                     n++;
  92.                 while (*t && *t != '.')
  93.                     t++;
  94.                 break;    /* name part matches wildcard */
  95.             }
  96.         } else {    /* match good for this char */
  97.             n++;    /* advance to next char */
  98.             t++;
  99.         }
  100.     }
  101.  
  102.     if (*n && *n == '.')
  103.         n++;        /* skip extension delimiters */
  104.     if (*t && *t == '.')
  105.         t++;
  106.  
  107. #endif    /* BSD */
  108.  
  109.     /* now match name part */
  110.  
  111.     while (*n || *t) {
  112.         if (*n != *t && *t != '?') {    /* match fail? */
  113.             if (*t != '*')    /* wildcard fail? */
  114.                 return 0;    /* then no match */
  115.             else
  116.                 return 1;    /* else good enough */
  117.         } else {    /* match good for this char */
  118.             n++;    /* advance to next char */
  119.             t++;
  120.         }
  121.     }
  122.  
  123.     return 1;        /* match worked */
  124. }
  125. #endif
  126.  
  127. INT
  128. rempath(nargs, arg)        /* remove paths from filenames */
  129.     INT             nargs;    /* number of names */
  130.     char           *arg[];    /* pointers to names */
  131. {
  132.     char           *i, *rindex();    /* string index, reverse indexer */
  133.     INT             n;    /* index */
  134.  
  135.     for (n = 0; n < nargs; n++) {    /* for each supplied name */
  136.         if (!(i = rindex(arg[n], '\\')))    /* search for end of
  137.                              * path */
  138.             if (!(i = rindex(arg[n], '/')))
  139.                 i = rindex(arg[n], ':');
  140.         if (i)        /* if path was found */
  141.             arg[n] = i + 1;    /* then skip it */
  142.     }
  143. }
  144.