Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libast/regex/regerror.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1985-2012 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* David Korn <[email protected]> *
19
* Phong Vo <[email protected]> *
20
* *
21
***********************************************************************/
22
#pragma prototyped
23
24
/*
25
* posix regex error message handler
26
*/
27
28
static const char id[] = "\n@(#)$Id: regex (AT&T Research) 2012-05-31 $\0\n";
29
30
#include "reglib.h"
31
32
static const char* reg_error[] =
33
{
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",
56
};
57
58
size_t
59
regerror(int code, const regex_t* p, char* buf, size_t size)
60
{
61
const char* s;
62
63
NoP(p);
64
if (code++ == REG_VERSIONID)
65
s = (const char*)fmtident(&id[1]);
66
else if (code >= 0 && code < elementsof(reg_error))
67
s = reg_error[code];
68
else
69
s = (const char*)"unknown error";
70
if (size)
71
{
72
strlcpy(buf, s, size);
73
buf[size - 1] = 0;
74
}
75
else
76
buf = (char*)s;
77
return strlen(buf) + 1;
78
}
79
80
/*
81
* discipline error intercept
82
*/
83
84
int
85
fatal(regdisc_t* disc, int code, const char* pattern)
86
{
87
if (disc->re_errorf)
88
{
89
if (pattern)
90
(*disc->re_errorf)(NiL, disc, disc->re_errorlevel, "regular expression: %s: %s", pattern, reg_error[code+1]);
91
else
92
(*disc->re_errorf)(NiL, disc, disc->re_errorlevel, "regular expression: %s", reg_error[code+1]);
93
}
94
return code;
95
}
96
97