OSDN Git Service

untabify all sources.
[lha/lha.git] / src / patmatch.c
1 /* ------------------------------------------------------------------------ */
2 /* LHa for UNIX                                                             */
3 /*              patmatch.c -- path check                                    */
4 /*                                                                          */
5 /*      Modified                Nobutaka Watazaki                           */
6 /*                                                                          */
7 /*  Ver. 1.14   Source All chagned              1995.01.14  N.Watazaki      */
8 /* ------------------------------------------------------------------------ */
9
10 #include <stdio.h>
11 #include <ctype.h>
12 /*
13  * Returns true if string s matches pattern p.
14  */
15 int
16 patmatch(p, s, f)
17     register char  *p;  /* pattern */
18     register char  *s;  /* string to match */
19     int             f;  /* flag for case force */
20 {
21     char            pc; /* a single character from pattern */
22
23     while (pc = ((f && islower(*p)) ? toupper(*p++) : *p++)) {
24         if (pc == '*') {
25             do {    /* look for match till s exhausted */
26                 if (patmatch(p, s, f))
27                     return (1);
28             } while (*s++);
29             return (0);
30         }
31         else if (*s == 0)
32             return (0); /* s exhausted, p not */
33         else if (pc == '?')
34             s++;    /* matches all, just bump */
35         else if (pc != ((f && islower(*s)) ? toupper(*s++) : *s++))
36             return (0);
37     }
38     return (!*s);       /* p exhausted, ret true if s exhausted */
39 }