regerror.c (2891B)
1 /* 2 * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 * 4 * Sccsid @(#)regerror.c 1.4 (gritter) 3/29/03 5 */ 6 /* UNIX(R) Regular Expresssion Library 7 * 8 * Note: Code is released under the GNU LGPL 9 * 10 * Copyright (C) 2001 Caldera International, Inc. 11 * 12 * This library is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU Lesser General Public 14 * License as published by the Free Software Foundation; either 15 * version 2 of the License, or (at your option) any later version. 16 * 17 * This library is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 * Lesser General Public License for more details. 21 * 22 * You should have received a copy of the GNU Lesser General Public 23 * License along with this library; if not, write to: 24 * Free Software Foundation, Inc. 25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 */ 27 28 /* #include "synonyms.h" */ 29 #include <string.h> 30 #include "re.h" 31 /* include "_locale.h" */ 32 33 /* #pragma weak regerror = _regerror */ 34 35 size_t 36 regerror(int err, const regex_t *ep, char *str, size_t max) 37 { 38 const struct 39 { 40 int index; 41 const char *str; 42 } unk = 43 { 44 88, "unknown regular expression error" 45 }, msgs[] = 46 { 47 /*ENOSYS*/ { 89, "feature not implemented" }, 48 /*0*/ { 0, "" }, 49 /*NOMATCH*/ { 90, "regular expression failed to match" }, 50 /*BADPAT*/ { 91, "invalid regular expression" }, 51 /*ECOLLATE*/ { 92, "invalid collating element construct" }, 52 /*ECTYPE*/ { 93, "invalid character class construct" }, 53 /*EEQUIV*/ { 94, "invalid equivalence class construct" }, 54 /*EBKTCHAR*/ { 95, "invalid character in '[ ]' construct" }, 55 /*EESCAPE*/ { 96, "trailing \\ in pattern" }, 56 /*ESUBREG*/ { 97, "'\\digit' out of range" }, 57 /*EBRACK*/ { 98, "'[ ]' imbalance" }, 58 /*EMPTYSUBBKT*/ { 99, "empty nested '[ ]' construct" }, 59 /*EMPTYPAREN*/ { 100, "empty '\\( \\)' or '( )'" }, 60 /*NOPAT*/ { 101, "empty pattern" }, 61 /*EPAREN*/ { 102, "'\\( \\)' or '( )' imbalance" }, 62 /*EBRACE*/ { 103, "'\\{ \\} or '{ }' imbalance" }, 63 /*BADBR*/ { 104, "invalid '\\{ \\}' or '{ }'" }, 64 /*ERANGE*/ { 105, "invalid endpoint in range" }, 65 /*ESPACE*/ { 106, "out of regular expression memory" }, 66 /*BADRPT*/ { 107, "invalid *, +, ?, \\{\\} or {} operator" }, 67 /*BADESC*/ { 108, "invalid escape sequence (e.g. \\0)" }, 68 /*ILLSEQ*/ { 109, "illegal byte sequence"} 69 }; 70 const char *p; 71 size_t len; 72 int i; 73 74 if (err < REG_ENOSYS || REG_ILLSEQ < err) 75 { 76 i = unk.index; 77 p = unk.str; 78 } 79 else 80 { 81 i = msgs[err - REG_ENOSYS].index; 82 p = msgs[err - REG_ENOSYS].str; 83 } 84 /* p = __gtxt(_str_uxlibc, i, p); */ 85 len = strlen(p) + 1; 86 if (max != 0) 87 { 88 if (max > len) 89 max = len; 90 else if (max < len) 91 str[--max] = '\0'; 92 memcpy(str, p, max); 93 } 94 return len; 95 }