home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 157.lha / Arc_Src / arcmatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-27  |  2.4 KB  |  72 lines

  1. /*  ARC - Archive utility - ARCMATCH
  2.  
  3. System V Version 1.0 based upon:
  4.     Version 2.17, created on 12/17/85) at 20:32:18
  5.  
  6. (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  7.  
  8.     By:  Thom Henderson
  9.  
  10.     Description:
  11.          This file contains service routines needed to maintain an archive.
  12. */
  13. #include "arc.h"
  14.  
  15. INT match(n,t)                         /* test name against template */
  16. char *n;                               /* name to test */
  17. char *t;                               /* template to test against */
  18. {
  19.     /* first match name part */
  20.  
  21.     while((*n && *n!='.') || (*t && *t!='.'))
  22.     {    if(*n!=*t && *t!='?')         /* match fail? */
  23.          {    if(*t!='*')              /* wildcard fail? */
  24.                    return 0;           /* then no match */
  25.               else                     /* else jump over wildcard */
  26.               {    while(*n && *n!='.')
  27.                         n++;
  28.                    while(*t && *t!='.')
  29.                         t++;
  30.                    break;              /* name part matches wildcard */
  31.               }
  32.          }
  33.          else                          /* match good for this char */
  34.          {    n++;                     /* advance to next char */
  35.               t++;
  36.          }
  37.     }
  38.  
  39.     if(*n && *n=='.') n++;             /* skip extension delimiters */
  40.     if(*t && *t=='.') t++;
  41.  
  42.     /* now match name part */
  43.  
  44.     while(*n || *t)
  45.     {    if(*n!=*t && *t!='?')         /* match fail? */
  46.          {    if(*t!='*')              /* wildcard fail? */
  47.                    return 0;           /* then no match */
  48.               else return 1;           /* else good enough */
  49.          }
  50.          else                          /* match good for this char */
  51.          {    n++;                     /* advance to next char */
  52.               t++;
  53.          }
  54.     }
  55.  
  56.     return 1;                          /* match worked */
  57. }
  58.  
  59. INT rempath(nargs,arg)                 /* remove paths from filenames */
  60. INT nargs;                             /* number of names */
  61. char *arg[];                           /* pointers to names */
  62. {
  63.     char *i, *rindex();                /* string index, reverse indexer */
  64.     INT n;                             /* index */
  65.  
  66.     for(n=0; n<nargs; n++)             /* for each supplied name */
  67.     {    i=rindex(arg[n],'/');         /* search for end of path */
  68.          if(i)                         /* if path was found */
  69.               arg[n] = i+1;            /* then skip it */
  70.     }
  71. }
  72.