home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c019 / 1.ddi / ARC521_C / ARCMATCH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-01  |  3.0 KB  |  132 lines

  1. /*
  2.  * $Header: arcmatch.c,v 1.5 88/06/01 19:41:08 hyc Locked $
  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(), strlen();
  23. void    abort();
  24. char    *strcpy();
  25.  
  26. int
  27. match(n, t)            /* test name against template */
  28.     char           *n;    /* name to test */
  29.     char           *t;    /* template to test against */
  30. {
  31. #if    MTS
  32.     fortran         patbuild(), patmatch(), patfree();
  33.     static int      patlen = (-1);
  34.     static int      patwork = 0;
  35.     static int      patswch = 0;
  36.     char            patccid[4];
  37.     static char     patchar[2] = "?";
  38.     static char     oldtemp[16] = 0;
  39.     int             namlen, RETCODE;
  40.  
  41.     if (strcmp(t, oldtemp)) {
  42.         if (patwork)
  43.             patfree(&patwork);
  44.         strcpy(oldtemp, t);
  45.         patlen = strlen(oldtemp);
  46.         patbuild(oldtemp, &patlen, &patwork, &patswch, patccid, patchar, _retcode RETCODE);
  47.         if (RETCODE > 8) {
  48.             printf("MTS: patbuild returned %d\n", RETCODE);
  49.             abort("bad wildcard in filename");
  50.         }
  51.     }
  52.     namlen = strlen(n);
  53.     patmatch(n, &namlen, &patwork, _retcode RETCODE);
  54.     switch (RETCODE) {
  55.     case 0:
  56.         return (1);
  57.     case 4:
  58.         return (0);
  59.     default:
  60.         abort("wildcard pattern match failed");
  61.     }
  62. }
  63.  
  64. #else
  65. #if    !UNIX
  66.     upper(n);
  67.     upper(t);        /* avoid case problems */
  68. #endif    /* UNIX */
  69. #if    GEMDOS
  70.     return(pnmatch(n, t, 0));
  71. #else
  72.     /* first match name part */
  73.  
  74.     while ((*n && *n != '.') || (*t && *t != '.')) {
  75.         if (*n != *t && *t != '?') {    /* match fail? */
  76.             if (*t != '*')    /* wildcard fail? */
  77.                 return 0;    /* then no match */
  78.             else {    /* else jump over wildcard */
  79.                 while (*n && *n != '.')
  80.                     n++;
  81.                 while (*t && *t != '.')
  82.                     t++;
  83.                 break;    /* name part matches wildcard */
  84.             }
  85.         } else {    /* match good for this char */
  86.             n++;    /* advance to next char */
  87.             t++;
  88.         }
  89.     }
  90.  
  91.     if (*n && *n == '.')
  92.         n++;        /* skip extension delimiters */
  93.     if (*t && *t == '.')
  94.         t++;
  95.  
  96.     /* now match name part */
  97.  
  98.     while (*n || *t) {
  99.         if (*n != *t && *t != '?') {    /* match fail? */
  100.             if (*t != '*')    /* wildcard fail? */
  101.                 return 0;    /* then no match */
  102.             else
  103.                 return 1;    /* else good enough */
  104.         } else {    /* match good for this char */
  105.             n++;    /* advance to next char */
  106.             t++;
  107.         }
  108.     }
  109.  
  110.     return 1;        /* match worked */
  111. #endif    /* GEMDOS */
  112. }
  113. #endif
  114.  
  115. void
  116. rempath(nargs, arg)        /* remove paths from filenames */
  117.     int             nargs;    /* number of names */
  118.     char           *arg[];    /* pointers to names */
  119. {
  120.     char           *i, *rindex();    /* string index, reverse indexer */
  121.     int             n;    /* index */
  122.  
  123.     for (n = 0; n < nargs; n++) {    /* for each supplied name */
  124.         if (!(i = rindex(arg[n], '\\')))    /* search for end of
  125.                              * path */
  126.             if (!(i = rindex(arg[n], '/')))
  127.                 i = rindex(arg[n], ':');
  128.         if (i)        /* if path was found */
  129.             arg[n] = i + 1;    /* then skip it */
  130.     }
  131. }
  132.