1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 #ifndef D_FILE_OFFSET_BITS
28 #define _FILE_OFFSET_BITS 64
30 #ifndef _LARGEFILE64_SOURCE
31 #define _LARGEFILE64_SOURCE 1
34 #include <sys/types.h>
44 #include "regerror.ih"
48 = #define REG_NOMATCH 1
49 = #define REG_BADPAT 2
50 = #define REG_ECOLLATE 3
51 = #define REG_ECTYPE 4
52 = #define REG_EESCAPE 5
53 = #define REG_ESUBREG 6
54 = #define REG_EBRACK 7
55 = #define REG_EPAREN 8
56 = #define REG_EBRACE 9
57 = #define REG_BADBR 10
58 = #define REG_ERANGE 11
59 = #define REG_ESPACE 12
60 = #define REG_BADRPT 13
61 = #define REG_EMPTY 14
62 = #define REG_ASSERT 15
63 = #define REG_INVARG 16
64 = #define REG_ATOI 255 // convert name to number (!)
65 = #define REG_ITOA 0400 // convert number to name (!)
74 { REG_OKAY, "REG_OKAY", "no errors detected" },
75 { REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match" },
76 { REG_BADPAT, "REG_BADPAT", "invalid regular expression" },
77 { REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element" },
78 { REG_ECTYPE, "REG_ECTYPE", "invalid character class" },
79 { REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)" },
80 { REG_ESUBREG, "REG_ESUBREG", "invalid backreference number" },
81 { REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced" },
82 { REG_EPAREN, "REG_EPAREN", "parentheses not balanced" },
83 { REG_EBRACE, "REG_EBRACE", "braces not balanced" },
84 { REG_BADBR, "REG_BADBR", "invalid repetition count(s)" },
85 { REG_ERANGE, "REG_ERANGE", "invalid character range" },
86 { REG_ESPACE, "REG_ESPACE", "out of memory" },
87 { REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid" },
88 { REG_EMPTY, "REG_EMPTY", "empty (sub)expression" },
89 { REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug" },
90 { REG_INVARG, "REG_INVARG", "invalid argument to regex routine" },
91 { -1, "", "*** unknown regexp error code ***" },
95 - regerror - the interface to error numbers
96 = extern size_t regerror(int, const regex_t *, char *, size_t);
100 vogl_regerror(errcode, preg, errbuf, errbuf_size) int errcode;
105 register struct rerr *r;
107 register int target = errcode & ~REG_ITOA;
111 if (errcode == REG_ATOI)
112 s = vogl_regatoi(preg, convbuf);
115 for (r = vogl_rerrs; r->code >= 0; r++)
116 if (r->code == target)
119 if (errcode & REG_ITOA)
122 (void)strcpy(convbuf, r->name);
124 sprintf(convbuf, "REG_0x%x", target);
125 assert(strlen(convbuf) < sizeof(convbuf));
135 if (errbuf_size > len)
136 (void)strcpy(errbuf, s);
139 (void)strncpy(errbuf, s, errbuf_size - 1);
140 errbuf[errbuf_size - 1] = '\0';
148 - vogl_regatoi - internal routine to implement REG_ATOI
149 == static char *vogl_regatoi(const regex_t *preg, char *localbuf);
152 vogl_regatoi(preg, localbuf)
156 register struct rerr *r;
158 for (r = vogl_rerrs; r->code >= 0; r++)
159 if (strcmp(r->name, preg->re_endp) == 0)
164 sprintf(localbuf, "%d", r->code);