1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
25 * posix regex error message handler
28 static const char id
[] = "\n@(#)$Id: regex (AT&T Research) 2009-12-11 $\0\n";
32 static const char* reg_error
[] =
34 /* REG_ENOSYS */ "not supported",
35 /* REG_SUCCESS */ "success",
36 /* REG_NOMATCH */ "no match",
37 /* REG_BADPAT */ "invalid regular expression",
38 /* REG_ECOLLATE */ "invalid collation element",
39 /* REG_ECTYPE */ "invalid character class",
40 /* REG_EESCAPE */ "trailing \\ in pattern",
41 /* REG_ESUBREG */ "invalid \\digit backreference",
42 /* REG_EBRACK */ "[...] imbalance",
43 /* REG_EPAREN */ "\\(...\\) or (...) imbalance",
44 /* REG_EBRACE */ "\\{...\\} or {...} imbalance",
45 /* REG_BADBR */ "invalid {...} digits",
46 /* REG_ERANGE */ "invalid [...] range endpoint",
47 /* REG_ESPACE */ "out of space",
48 /* REG_BADRPT */ "unary op not preceded by re",
49 /* REG_ENULL */ "empty subexpr in pattern",
50 /* REG_ECOUNT */ "re component count overflow",
51 /* REG_BADESC */ "invalid \\char escape",
52 /* REG_VERSIONID*/ &id
[10],
53 /* REG_EFLAGS */ "conflicting flags",
54 /* REG_EDELIM */ "invalid or omitted delimiter",
55 /* REG_PANIC */ "unrecoverable internal error",
59 regerror(int code
, const regex_t
* p
, char* buf
, size_t size
)
64 if (code
++ == REG_VERSIONID
)
65 s
= (const char*)fmtident(&id
[1]);
66 else if (code
>= 0 && code
< elementsof(reg_error
))
69 s
= (const char*)"unknown error";
72 strncpy(buf
, s
, size
);
77 return strlen(buf
) + 1;
81 * discipline error intercept
85 fatal(regdisc_t
* disc
, int code
, const char* pattern
)
90 (*disc
->re_errorf
)(NiL
, disc
, disc
->re_errorlevel
, "regular expression: %s: %s", pattern
, reg_error
[code
+1]);
92 (*disc
->re_errorf
)(NiL
, disc
, disc
->re_errorlevel
, "regular expression: %s", reg_error
[code
+1]);