home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ARC521-2.ZIP / ARCMATCH.C < prev    next >
C/C++ Source or Header  |  1989-12-29  |  3KB  |  140 lines

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