annotate src/osdep/nt/pmatch.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1 /* ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
2 * Copyright 1988-2006 University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
3 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
4 * Licensed under the Apache License, Version 2.0 (the "License");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
5 * you may not use this file except in compliance with the License.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
6 * You may obtain a copy of the License at
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
7 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
8 * http://www.apache.org/licenses/LICENSE-2.0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
9 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
10 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
11 * ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
12 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
13
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
14 /*
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
15 * Program: IMAP Wildcard Matching Routines (case-independent)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
16 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
17 * Author: Mark Crispin
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
18 * Networks and Distributed Computing
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
19 * Computing & Communications
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
20 * University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
21 * Administration Building, AG-44
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
22 * Seattle, WA 98195
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
23 * Internet: MRC@CAC.Washington.EDU
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
24 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
25 * Date: 15 June 2000
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
26 * Last Edited: 30 August 2006
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
27 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
28
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
29 /* Wildcard pattern match
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
30 * Accepts: base string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
31 * pattern string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
32 * delimiter character
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
33 * Returns: T if pattern matches base, else NIL
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
34 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
35
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
36 long pmatch_full (unsigned char *s,unsigned char *pat,unsigned char delim)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
37 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
38 switch (*pat) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
39 case '%': /* non-recursive */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
40 /* % at end, OK if no inferiors */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
41 if (!pat[1]) return (delim && strchr (s,delim)) ? NIL : T;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
42 /* scan remainder of string until delimiter */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
43 do if (pmatch_full (s,pat+1,delim)) return T;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
44 while ((*s != delim) && *s++);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
45 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
46 case '*': /* match 0 or more characters */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
47 if (!pat[1]) return T; /* * at end, unconditional match */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
48 /* scan remainder of string */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
49 do if (pmatch_full (s,pat+1,delim)) return T;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
50 while (*s++);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
51 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
52 case '\0': /* end of pattern */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
53 return *s ? NIL : T; /* success if also end of base */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
54 default: /* match this character */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
55 return compare_uchar (*pat,*s) ? NIL : pmatch_full (s+1,pat+1,delim);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
56 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
57 return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
58 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
59
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
60 /* Directory pattern match
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
61 * Accepts: base string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
62 * pattern string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
63 * delimiter character
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
64 * Returns: T if base is a matching directory of pattern, else NIL
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
65 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
66
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
67 long dmatch (unsigned char *s,unsigned char *pat,unsigned char delim)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
68 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
69 switch (*pat) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
70 case '%': /* non-recursive */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
71 if (!*s) return T; /* end of base means have a subset match */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
72 if (!*++pat) return NIL; /* % at end, no inferiors permitted */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
73 /* scan remainder of string until delimiter */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
74 do if (dmatch (s,pat,delim)) return T;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
75 while ((*s != delim) && *s++);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
76 if (*s && !s[1]) return T; /* ends with delimiter, must be subset */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
77 return dmatch (s,pat,delim);/* do new scan */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
78 case '*': /* match 0 or more characters */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
79 return T; /* unconditional match */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
80 case '\0': /* end of pattern */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
81 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
82 default: /* match this character */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
83 if (*s) return compare_uchar (*pat,*s) ? NIL : dmatch (s+1,pat+1,delim);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
84 /* end of base, return if at delimiter */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
85 else if (*pat == delim) return T;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
86 break;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
87 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
88 return NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
89 }

yatex.org