home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / OS2ARC_S.ZIP / ARCMATCH.C < prev    next >
Text File  |  1987-10-15  |  3KB  |  85 lines

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