home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / arcppc / src / rcs / arcmatch.c,v < prev    next >
Text File  |  1998-04-23  |  5KB  |  300 lines

  1. head     1.6;
  2. branch   ;
  3. access   ;
  4. symbols  patch1:1.6;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.6
  10. date     88.07.31.18.50.18;  author hyc;  state Exp;
  11. branches ;
  12. next     1.5;
  13.  
  14. 1.5
  15. date     88.06.01.19.41.08;  author hyc;  state Exp;
  16. branches ;
  17. next     1.4;
  18.  
  19. 1.4
  20. date     88.06.01.15.53.59;  author hyc;  state Exp;
  21. branches ;
  22. next     1.3;
  23.  
  24. 1.3
  25. date     88.06.01.15.51.54;  author hyc;  state Exp;
  26. branches ;
  27. next     1.2;
  28.  
  29. 1.2
  30. date     88.04.11.18.20.43;  author hyc;  state Exp;
  31. branches ;
  32. next     1.1;
  33.  
  34. 1.1
  35. date     88.04.11.18.12.56;  author hyc;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39.  
  40. desc
  41. @@
  42.  
  43.  
  44. 1.6
  45. log
  46. @Allow "*.*" to mean '*' for GEMDOS wildcard
  47. @
  48. text
  49. @/*
  50.  * $Header: arcmatch.c,v 1.5 88/06/01 19:41:08 hyc Locked $
  51.  */
  52.  
  53. /*
  54.  * ARC - Archive utility - ARCMATCH
  55.  * 
  56.  * Version 2.17, created on 12/17/85 at 20:32:18
  57.  * 
  58.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  59.  * 
  60.  * By:  Thom Henderson
  61.  * 
  62.  * Description: This file contains service routines needed to maintain an
  63.  * archive.
  64.  * 
  65.  * Language: Computer Innovations Optimizing C86
  66.  */
  67. #include <stdio.h>
  68. #include "arc.h"
  69.  
  70. int    strcmp(), strlen();
  71. void    abort();
  72. char    *strcpy();
  73.  
  74. int
  75. match(n, t)            /* test name against template */
  76.     char           *n;    /* name to test */
  77.     char           *t;    /* template to test against */
  78. {
  79. #if    MTS
  80.     fortran         patbuild(), patmatch(), patfree();
  81.     static int      patlen = (-1);
  82.     static int      patwork = 0;
  83.     static int      patswch = 0;
  84.     char            patccid[4];
  85.     static char     patchar[2] = "?";
  86.     static char     oldtemp[16] = 0;
  87.     int             namlen, RETCODE;
  88.  
  89.     if (strcmp(t, oldtemp)) {
  90.         if (patwork)
  91.             patfree(&patwork);
  92.         strcpy(oldtemp, t);
  93.         patlen = strlen(oldtemp);
  94.         patbuild(oldtemp, &patlen, &patwork, &patswch, patccid, patchar, _retcode RETCODE);
  95.         if (RETCODE > 8) {
  96.             printf("MTS: patbuild returned %d\n", RETCODE);
  97.             abort("bad wildcard in filename");
  98.         }
  99.     }
  100.     namlen = strlen(n);
  101.     patmatch(n, &namlen, &patwork, _retcode RETCODE);
  102.     switch (RETCODE) {
  103.     case 0:
  104.         return (1);
  105.     case 4:
  106.         return (0);
  107.     default:
  108.         abort("wildcard pattern match failed");
  109.     }
  110. }
  111.  
  112. #else
  113. #if    !UNIX
  114.     upper(n);
  115.     upper(t);        /* avoid case problems */
  116. #endif    /* UNIX */
  117. #if    GEMDOS
  118.     char *strstr(), *i;    /* allow "*.*" to mean '*' */
  119.     if (i=strstr(t,"*.*")) {
  120.         i++;
  121.         *i='\0';
  122.     }
  123.     return(pnmatch(n, t, 0));
  124. #else
  125.     /* first match name part */
  126.  
  127.     while ((*n && *n != '.') || (*t && *t != '.')) {
  128.         if (*n != *t && *t != '?') {    /* match fail? */
  129.             if (*t != '*')    /* wildcard fail? */
  130.                 return 0;    /* then no match */
  131.             else {    /* else jump over wildcard */
  132.                 while (*n && *n != '.')
  133.                     n++;
  134.                 while (*t && *t != '.')
  135.                     t++;
  136.                 break;    /* name part matches wildcard */
  137.             }
  138.         } else {    /* match good for this char */
  139.             n++;    /* advance to next char */
  140.             t++;
  141.         }
  142.     }
  143.  
  144.     if (*n && *n == '.')
  145.         n++;        /* skip extension delimiters */
  146.     if (*t && *t == '.')
  147.         t++;
  148.  
  149.     /* now match name part */
  150.  
  151.     while (*n || *t) {
  152.         if (*n != *t && *t != '?') {    /* match fail? */
  153.             if (*t != '*')    /* wildcard fail? */
  154.                 return 0;    /* then no match */
  155.             else
  156.                 return 1;    /* else good enough */
  157.         } else {    /* match good for this char */
  158.             n++;    /* advance to next char */
  159.             t++;
  160.         }
  161.     }
  162.  
  163.     return 1;        /* match worked */
  164. #endif    /* GEMDOS */
  165. }
  166. #endif
  167.  
  168. void
  169. rempath(nargs, arg)        /* remove paths from filenames */
  170.     int             nargs;    /* number of names */
  171.     char           *arg[];    /* pointers to names */
  172. {
  173.     char           *i, *rindex();    /* string index, reverse indexer */
  174.     int             n;    /* index */
  175.  
  176.     for (n = 0; n < nargs; n++) {    /* for each supplied name */
  177.         if (!(i = rindex(arg[n], '\\')))    /* search for end of
  178.                              * path */
  179.             if (!(i = rindex(arg[n], '/')))
  180.                 i = rindex(arg[n], ':');
  181.         if (i)        /* if path was found */
  182.             arg[n] = i + 1;    /* then skip it */
  183.     }
  184. }
  185. @
  186.  
  187.  
  188. 1.5
  189. log
  190. @Changed compilation conditionals
  191. @
  192. text
  193. @d2 1
  194. a2 1
  195.  * $Header: arcmatch.c,v 1.4 88/06/01 15:53:59 hyc Locked $
  196. d70 5
  197. @
  198.  
  199.  
  200. 1.4
  201. log
  202. @Merge Atari ST code
  203. @
  204. text
  205. @d2 1
  206. a2 1
  207.  * $Header: arcmatch.c,v 1.3 88/06/01 15:51:54 hyc Locked $
  208. d31 1
  209. a31 1
  210. #ifdef MTS
  211. d65 1
  212. a65 1
  213. #ifndef    BSD
  214. d68 2
  215. a69 2
  216. #endif    /* BSD */
  217. #ifdef    GEMDOS
  218. @
  219.  
  220.  
  221. 1.3
  222. log
  223. @Fix declarations
  224. @
  225. text
  226. @d2 1
  227. a2 1
  228.  * $Header: arcmatch.c,v 1.4 88/04/19 01:40:01 hyc Exp $
  229. d69 3
  230. a71 1
  231.  
  232. d111 1
  233. @
  234.  
  235.  
  236. 1.2
  237. log
  238. @fixup pattern matching for BSD...
  239. @
  240. text
  241. @d2 1
  242. a2 16
  243.  * $Log:    arcmatch.c,v $
  244.  * Revision 1.1  88/04/11  18:12:56  hyc
  245.  * Initial revision
  246.  * 
  247.  * Revision 1.2  87/12/19  04:39:35  hyc
  248.  * Don't convert names to upper case for BSD...
  249.  * 
  250.  * Revision 1.1  87/12/19  04:39:06  hyc
  251.  * Initial revision
  252.  * 
  253.  * Revision 1.3  87/08/13  17:05:01  hyc
  254.  * Run thru indent, fixed some signed vs. unsigned problems
  255.  * with bp <-> buf, and inbuf and localbuf...
  256.  *  Revision 1.2  87/07/21  08:48:16  hyc ***
  257.  * empty log message ***
  258.  * 
  259. d22 5
  260. a26 1
  261. INT
  262. d68 1
  263. a93 2
  264. #endif    /* BSD */
  265.  
  266. d112 1
  267. a112 1
  268. INT
  269. d114 1
  270. a114 1
  271.     INT             nargs;    /* number of names */
  272. d118 1
  273. a118 1
  274.     INT             n;    /* index */
  275. @
  276.  
  277.  
  278. 1.1
  279. log
  280. @Initial revision
  281. @
  282. text
  283. @d3 3
  284. d50 1
  285. a50 1
  286.     int             namlen;
  287. d57 1
  288. a57 1
  289.         patbuild(oldtemp, &patlen, &patwork, &patswch, patccid, patchar);
  290. d64 1
  291. a64 1
  292.     patmatch(n, &namlen, &patwork);
  293. a78 1
  294. #endif
  295. d104 2
  296. d133 1
  297. a133 1
  298.         if (!(i = rindex(arg[n], '\\')))    /* search for end of *
  299. @
  300.