home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d050 / unixarc.lha / UnixArc / arcmatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-17  |  2.6 KB  |  77 lines

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