rev |
line source |
meillo@0
|
1 /*
|
meillo@0
|
2 * Simple Regular Expression functions. Derived from Unix 7th Edition,
|
meillo@0
|
3 * /usr/src/cmd/expr.y
|
meillo@0
|
4 *
|
meillo@0
|
5 * Modified by Gunnar Ritter, Freiburg i. Br., Germany, January 2003.
|
meillo@0
|
6 *
|
meillo@0
|
7 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
|
meillo@0
|
8 *
|
meillo@0
|
9 * Redistribution and use in source and binary forms, with or without
|
meillo@0
|
10 * modification, are permitted provided that the following conditions
|
meillo@0
|
11 * are met:
|
meillo@0
|
12 * Redistributions of source code and documentation must retain the
|
meillo@0
|
13 * above copyright notice, this list of conditions and the following
|
meillo@0
|
14 * disclaimer.
|
meillo@0
|
15 * Redistributions in binary form must reproduce the above copyright
|
meillo@0
|
16 * notice, this list of conditions and the following disclaimer in the
|
meillo@0
|
17 * documentation and/or other materials provided with the distribution.
|
meillo@0
|
18 * All advertising materials mentioning features or use of this software
|
meillo@0
|
19 * must display the following acknowledgement:
|
meillo@0
|
20 * This product includes software developed or owned by Caldera
|
meillo@0
|
21 * International, Inc.
|
meillo@0
|
22 * Neither the name of Caldera International, Inc. nor the names of
|
meillo@0
|
23 * other contributors may be used to endorse or promote products
|
meillo@0
|
24 * derived from this software without specific prior written permission.
|
meillo@0
|
25 *
|
meillo@0
|
26 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
|
meillo@0
|
27 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
|
meillo@0
|
28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
meillo@0
|
29 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
meillo@0
|
30 * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
|
meillo@0
|
31 * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
meillo@0
|
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
meillo@0
|
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
meillo@0
|
34 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
meillo@0
|
35 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
meillo@0
|
36 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
meillo@0
|
37 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
meillo@0
|
38 */
|
meillo@0
|
39
|
meillo@0
|
40 /* Sccsid @(#)regexpr.c 1.8 (gritter) 10/13/04 */
|
meillo@0
|
41
|
meillo@0
|
42 #include <stdlib.h>
|
meillo@0
|
43 #include "regexpr.h"
|
meillo@0
|
44
|
meillo@0
|
45 int regerrno, reglength;
|
meillo@0
|
46 static int circf;
|
meillo@0
|
47
|
meillo@0
|
48 static char *regexpr_compile(char *, char *, const char *, int);
|
meillo@0
|
49
|
meillo@0
|
50 char *
|
meillo@0
|
51 compile(const char *instring, char *ep, char *endbuf)
|
meillo@0
|
52 {
|
meillo@0
|
53 char *cp;
|
meillo@0
|
54 int sz = 0;
|
meillo@0
|
55
|
meillo@0
|
56 if (ep == 0) {
|
meillo@0
|
57 for (cp = (char *)instring; *cp != '\0'; cp++)
|
meillo@0
|
58 if (*cp == '[')
|
meillo@0
|
59 sz += 32;
|
meillo@0
|
60 sz += 2 * (cp - instring) + 5;
|
meillo@0
|
61 if ((ep = malloc(sz)) == 0) {
|
meillo@0
|
62 regerrno = 11;
|
meillo@0
|
63 return 0;
|
meillo@0
|
64 }
|
meillo@0
|
65 endbuf = &ep[sz];
|
meillo@0
|
66 ep[1] = '\0';
|
meillo@0
|
67 }
|
meillo@0
|
68 if ((cp=regexpr_compile((char *)instring, &ep[1], endbuf, '\0')) == 0) {
|
meillo@0
|
69 if (sz)
|
meillo@0
|
70 free(ep);
|
meillo@0
|
71 return 0;
|
meillo@0
|
72 }
|
meillo@0
|
73 ep[0] = circf;
|
meillo@0
|
74 reglength = cp - ep;
|
meillo@0
|
75 return sz ? ep : cp;
|
meillo@0
|
76 }
|
meillo@0
|
77
|
meillo@0
|
78 #define INIT register char *sp = instring;
|
meillo@0
|
79 #define GETC() (*sp++)
|
meillo@0
|
80 #define PEEKC() (*sp)
|
meillo@0
|
81 #define UNGETC(c) (--sp)
|
meillo@0
|
82 #define RETURN(c) return (c);
|
meillo@0
|
83 #define ERROR(c) { regerrno = c; return 0; }
|
meillo@0
|
84
|
meillo@0
|
85 #define compile(a, b, c, d) regexpr_compile(a, b, c, d)
|
meillo@0
|
86 #define regexp_h_static static
|
meillo@0
|
87 #define REGEXP_H_STEP_INIT circf = *p2++;
|
meillo@0
|
88 #define REGEXP_H_ADVANCE_INIT circf = *ep++;
|
meillo@0
|
89
|
meillo@0
|
90 #include "regexp.h"
|