]>
git.saurik.com Git - apple/libc.git/blob - regex/regerror.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1992, 1993, 1994
27 * The Regents of the University of California. All rights reserved.
29 * This code is derived from software contributed to Berkeley by
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 #if defined(LIBC_SCCS) && !defined(lint)
62 static char sccsid
[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94";
63 #endif /* LIBC_SCCS and not lint */
65 #include <sys/types.h>
75 /* ========= begin header generated by ./mkh ========= */
80 /* === regerror.c === */
81 static char *regatoi
__P((const regex_t
*preg
, char *localbuf
));
86 /* ========= end header generated by ./mkh ========= */
88 = #define REG_NOMATCH 1
89 = #define REG_BADPAT 2
90 = #define REG_ECOLLATE 3
91 = #define REG_ECTYPE 4
92 = #define REG_EESCAPE 5
93 = #define REG_ESUBREG 6
94 = #define REG_EBRACK 7
95 = #define REG_EPAREN 8
96 = #define REG_EBRACE 9
97 = #define REG_BADBR 10
98 = #define REG_ERANGE 11
99 = #define REG_ESPACE 12
100 = #define REG_BADRPT 13
101 = #define REG_EMPTY 14
102 = #define REG_ASSERT 15
103 = #define REG_INVARG 16
104 = #define REG_ATOI 255 // convert name to number (!)
105 = #define REG_ITOA 0400 // convert number to name (!)
112 REG_NOMATCH
, "REG_NOMATCH", "regexec() failed to match",
113 REG_BADPAT
, "REG_BADPAT", "invalid regular expression",
114 REG_ECOLLATE
, "REG_ECOLLATE", "invalid collating element",
115 REG_ECTYPE
, "REG_ECTYPE", "invalid character class",
116 REG_EESCAPE
, "REG_EESCAPE", "trailing backslash (\\)",
117 REG_ESUBREG
, "REG_ESUBREG", "invalid backreference number",
118 REG_EBRACK
, "REG_EBRACK", "brackets ([ ]) not balanced",
119 REG_EPAREN
, "REG_EPAREN", "parentheses not balanced",
120 REG_EBRACE
, "REG_EBRACE", "braces not balanced",
121 REG_BADBR
, "REG_BADBR", "invalid repetition count(s)",
122 REG_ERANGE
, "REG_ERANGE", "invalid character range",
123 REG_ESPACE
, "REG_ESPACE", "out of memory",
124 REG_BADRPT
, "REG_BADRPT", "repetition-operator operand invalid",
125 REG_EMPTY
, "REG_EMPTY", "empty (sub)expression",
126 REG_ASSERT
, "REG_ASSERT", "\"can't happen\" -- you found a bug",
127 REG_INVARG
, "REG_INVARG", "invalid argument to regex routine",
128 0, "", "*** unknown regexp error code ***",
132 - regerror - the interface to error numbers
133 = extern size_t regerror(int, const regex_t *, char *, size_t);
137 regerror(errcode
, preg
, errbuf
, errbuf_size
)
143 register struct rerr
*r
;
145 register int target
= errcode
&~ REG_ITOA
;
149 if (errcode
== REG_ATOI
)
150 s
= regatoi(preg
, convbuf
);
152 for (r
= rerrs
; r
->code
!= 0; r
++)
153 if (r
->code
== target
)
156 if (errcode
®_ITOA
) {
158 (void) strcpy(convbuf
, r
->name
);
160 sprintf(convbuf
, "REG_0x%x", target
);
161 assert(strlen(convbuf
) < sizeof(convbuf
));
168 if (errbuf_size
> 0) {
169 if (errbuf_size
> len
)
170 (void) strcpy(errbuf
, s
);
172 (void) strncpy(errbuf
, s
, errbuf_size
-1);
173 errbuf
[errbuf_size
-1] = '\0';
181 - regatoi - internal routine to implement REG_ATOI
182 == static char *regatoi(const regex_t *preg, char *localbuf);
185 regatoi(preg
, localbuf
)
189 register struct rerr
*r
;
193 for (r
= rerrs
; r
->code
!= 0; r
++)
194 if (strcmp(r
->name
, preg
->re_endp
) == 0)
199 sprintf(localbuf
, "%d", r
->code
);