14887Schin /*********************************************************************** 24887Schin * * 34887Schin * This software is part of the ast package * 4*12068SRoger.Faulkner@Oracle.COM * Copyright (c) 1985-2010 AT&T Intellectual Property * 54887Schin * and is licensed under the * 64887Schin * Common Public License, Version 1.0 * 78462SApril.Chin@Sun.COM * by AT&T Intellectual Property * 84887Schin * * 94887Schin * A copy of the License is available at * 104887Schin * http://www.opensource.org/licenses/cpl1.0.txt * 114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 124887Schin * * 134887Schin * Information and Software Systems Research * 144887Schin * AT&T Research * 154887Schin * Florham Park NJ * 164887Schin * * 174887Schin * Glenn Fowler <gsf@research.att.com> * 184887Schin * David Korn <dgk@research.att.com> * 194887Schin * Phong Vo <kpv@research.att.com> * 204887Schin * * 214887Schin ***********************************************************************/ 224887Schin #pragma prototyped 234887Schin 244887Schin /* 254887Schin * posix regex error message handler 264887Schin */ 274887Schin 28*12068SRoger.Faulkner@Oracle.COM static const char id[] = "\n@(#)$Id: regex (AT&T Research) 2009-12-11 $\0\n"; 294887Schin 304887Schin #include "reglib.h" 314887Schin 324887Schin static const char* reg_error[] = 334887Schin { 344887Schin /* REG_ENOSYS */ "not supported", 354887Schin /* REG_SUCCESS */ "success", 364887Schin /* REG_NOMATCH */ "no match", 374887Schin /* REG_BADPAT */ "invalid regular expression", 384887Schin /* REG_ECOLLATE */ "invalid collation element", 394887Schin /* REG_ECTYPE */ "invalid character class", 404887Schin /* REG_EESCAPE */ "trailing \\ in pattern", 414887Schin /* REG_ESUBREG */ "invalid \\digit backreference", 424887Schin /* REG_EBRACK */ "[...] imbalance", 434887Schin /* REG_EPAREN */ "\\(...\\) or (...) imbalance", 444887Schin /* REG_EBRACE */ "\\{...\\} or {...} imbalance", 454887Schin /* REG_BADBR */ "invalid {...} digits", 464887Schin /* REG_ERANGE */ "invalid [...] range endpoint", 474887Schin /* REG_ESPACE */ "out of space", 48*12068SRoger.Faulkner@Oracle.COM /* REG_BADRPT */ "unary op not preceded by re", 494887Schin /* REG_ENULL */ "empty subexpr in pattern", 504887Schin /* REG_ECOUNT */ "re component count overflow", 514887Schin /* REG_BADESC */ "invalid \\char escape", 524887Schin /* REG_VERSIONID*/ &id[10], 534887Schin /* REG_EFLAGS */ "conflicting flags", 544887Schin /* REG_EDELIM */ "invalid or omitted delimiter", 554887Schin /* REG_PANIC */ "unrecoverable internal error", 564887Schin }; 574887Schin 584887Schin size_t 594887Schin regerror(int code, const regex_t* p, char* buf, size_t size) 604887Schin { 614887Schin const char* s; 624887Schin 634887Schin NoP(p); 644887Schin if (code++ == REG_VERSIONID) 654887Schin s = (const char*)fmtident(&id[1]); 664887Schin else if (code >= 0 && code < elementsof(reg_error)) 674887Schin s = reg_error[code]; 684887Schin else 694887Schin s = (const char*)"unknown error"; 704887Schin if (size) 714887Schin { 724887Schin strncpy(buf, s, size); 734887Schin buf[size - 1] = 0; 744887Schin } 754887Schin else 764887Schin buf = (char*)s; 774887Schin return strlen(buf) + 1; 784887Schin } 794887Schin 804887Schin /* 814887Schin * discipline error intercept 824887Schin */ 834887Schin 844887Schin int 854887Schin fatal(regdisc_t* disc, int code, const char* pattern) 864887Schin { 874887Schin if (disc->re_errorf) 884887Schin { 894887Schin if (pattern) 904887Schin (*disc->re_errorf)(NiL, disc, disc->re_errorlevel, "regular expression: %s: %s", pattern, reg_error[code+1]); 914887Schin else 924887Schin (*disc->re_errorf)(NiL, disc, disc->re_errorlevel, "regular expression: %s", reg_error[code+1]); 934887Schin } 944887Schin return code; 954887Schin } 96