/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2012 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223/*24* posix regex error message handler25*/2627static const char id[] = "\n@(#)$Id: regex (AT&T Research) 2012-05-31 $\0\n";2829#include "reglib.h"3031static const char* reg_error[] =32{33/* REG_ENOSYS */ "not supported",34/* REG_SUCCESS */ "success",35/* REG_NOMATCH */ "no match",36/* REG_BADPAT */ "invalid regular expression",37/* REG_ECOLLATE */ "invalid collation element",38/* REG_ECTYPE */ "invalid character class",39/* REG_EESCAPE */ "trailing \\ in pattern",40/* REG_ESUBREG */ "invalid \\digit backreference",41/* REG_EBRACK */ "[...] imbalance",42/* REG_EPAREN */ "\\(...\\) or (...) imbalance",43/* REG_EBRACE */ "\\{...\\} or {...} imbalance",44/* REG_BADBR */ "invalid {...} digits",45/* REG_ERANGE */ "invalid [...] range endpoint",46/* REG_ESPACE */ "out of space",47/* REG_BADRPT */ "unary op not preceded by re",48/* REG_ENULL */ "empty subexpr in pattern",49/* REG_ECOUNT */ "re component count overflow",50/* REG_BADESC */ "invalid \\char escape",51/* REG_VERSIONID*/ &id[10],52/* REG_EFLAGS */ "conflicting flags",53/* REG_EDELIM */ "invalid or omitted delimiter",54/* REG_PANIC */ "unrecoverable internal error",55};5657size_t58regerror(int code, const regex_t* p, char* buf, size_t size)59{60const char* s;6162NoP(p);63if (code++ == REG_VERSIONID)64s = (const char*)fmtident(&id[1]);65else if (code >= 0 && code < elementsof(reg_error))66s = reg_error[code];67else68s = (const char*)"unknown error";69if (size)70{71strlcpy(buf, s, size);72buf[size - 1] = 0;73}74else75buf = (char*)s;76return strlen(buf) + 1;77}7879/*80* discipline error intercept81*/8283int84fatal(regdisc_t* disc, int code, const char* pattern)85{86if (disc->re_errorf)87{88if (pattern)89(*disc->re_errorf)(NiL, disc, disc->re_errorlevel, "regular expression: %s: %s", pattern, reg_error[code+1]);90else91(*disc->re_errorf)(NiL, disc, disc->re_errorlevel, "regular expression: %s", reg_error[code+1]);92}93return code;94}959697