imapext-2007
diff src/osdep/wce/pmatch.c @ 0:ada5e610ab86
imap-2007e
author | yuuji@gentei.org |
---|---|
date | Mon, 14 Sep 2009 15:17:45 +0900 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/osdep/wce/pmatch.c Mon Sep 14 15:17:45 2009 +0900 1.3 @@ -0,0 +1,89 @@ 1.4 +/* ======================================================================== 1.5 + * Copyright 1988-2006 University of Washington 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * 1.14 + * ======================================================================== 1.15 + */ 1.16 + 1.17 +/* 1.18 + * Program: IMAP Wildcard Matching Routines (case-independent) 1.19 + * 1.20 + * Author: Mark Crispin 1.21 + * Networks and Distributed Computing 1.22 + * Computing & Communications 1.23 + * University of Washington 1.24 + * Administration Building, AG-44 1.25 + * Seattle, WA 98195 1.26 + * Internet: MRC@CAC.Washington.EDU 1.27 + * 1.28 + * Date: 15 June 2000 1.29 + * Last Edited: 30 August 2006 1.30 + */ 1.31 + 1.32 +/* Wildcard pattern match 1.33 + * Accepts: base string 1.34 + * pattern string 1.35 + * delimiter character 1.36 + * Returns: T if pattern matches base, else NIL 1.37 + */ 1.38 + 1.39 +long pmatch_full (unsigned char *s,unsigned char *pat,unsigned char delim) 1.40 +{ 1.41 + switch (*pat) { 1.42 + case '%': /* non-recursive */ 1.43 + /* % at end, OK if no inferiors */ 1.44 + if (!pat[1]) return (delim && strchr (s,delim)) ? NIL : T; 1.45 + /* scan remainder of string until delimiter */ 1.46 + do if (pmatch_full (s,pat+1,delim)) return T; 1.47 + while ((*s != delim) && *s++); 1.48 + break; 1.49 + case '*': /* match 0 or more characters */ 1.50 + if (!pat[1]) return T; /* * at end, unconditional match */ 1.51 + /* scan remainder of string */ 1.52 + do if (pmatch_full (s,pat+1,delim)) return T; 1.53 + while (*s++); 1.54 + break; 1.55 + case '\0': /* end of pattern */ 1.56 + return *s ? NIL : T; /* success if also end of base */ 1.57 + default: /* match this character */ 1.58 + return compare_uchar (*pat,*s) ? NIL : pmatch_full (s+1,pat+1,delim); 1.59 + } 1.60 + return NIL; 1.61 +} 1.62 + 1.63 +/* Directory pattern match 1.64 + * Accepts: base string 1.65 + * pattern string 1.66 + * delimiter character 1.67 + * Returns: T if base is a matching directory of pattern, else NIL 1.68 + */ 1.69 + 1.70 +long dmatch (unsigned char *s,unsigned char *pat,unsigned char delim) 1.71 +{ 1.72 + switch (*pat) { 1.73 + case '%': /* non-recursive */ 1.74 + if (!*s) return T; /* end of base means have a subset match */ 1.75 + if (!*++pat) return NIL; /* % at end, no inferiors permitted */ 1.76 + /* scan remainder of string until delimiter */ 1.77 + do if (dmatch (s,pat,delim)) return T; 1.78 + while ((*s != delim) && *s++); 1.79 + if (*s && !s[1]) return T; /* ends with delimiter, must be subset */ 1.80 + return dmatch (s,pat,delim);/* do new scan */ 1.81 + case '*': /* match 0 or more characters */ 1.82 + return T; /* unconditional match */ 1.83 + case '\0': /* end of pattern */ 1.84 + break; 1.85 + default: /* match this character */ 1.86 + if (*s) return compare_uchar (*pat,*s) ? NIL : dmatch (s+1,pat+1,delim); 1.87 + /* end of base, return if at delimiter */ 1.88 + else if (*pat == delim) return T; 1.89 + break; 1.90 + } 1.91 + return NIL; 1.92 +}