home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / COMPRESS / ARC520S.ZIP / ARCMATCH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-10-23  |  2.7 KB  |  79 lines

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