]>
Commit | Line | Data |
---|---|---|
db3b92b4 CS |
1 | /**********************************************************************\r |
2 | regposerr.c - Oniguruma (regular expression library)\r | |
3 | **********************************************************************/\r | |
4 | /*-\r | |
5 | * Copyright (c) 2002-2007 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>\r | |
6 | * All rights reserved.\r | |
7 | *\r | |
8 | * Copyright (c) 2015, Hewlett Packard Enterprise Development, L.P.<BR> \r | |
9 | *\r | |
10 | * Redistribution and use in source and binary forms, with or without\r | |
11 | * modification, are permitted provided that the following conditions\r | |
12 | * are met:\r | |
13 | * 1. Redistributions of source code must retain the above copyright\r | |
14 | * notice, this list of conditions and the following disclaimer.\r | |
15 | * 2. Redistributions in binary form must reproduce the above copyright\r | |
16 | * notice, this list of conditions and the following disclaimer in the\r | |
17 | * documentation and/or other materials provided with the distribution.\r | |
18 | *\r | |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r | |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r | |
29 | * SUCH DAMAGE.\r | |
30 | */\r | |
31 | \r | |
32 | /*#include "config.h"*/\r | |
33 | #include "onigposix.h"\r | |
34 | \r | |
35 | #if 0\r | |
36 | #ifdef HAVE_STRING_H\r | |
37 | # include <string.h>\r | |
38 | #else\r | |
39 | # include <strings.h>\r | |
40 | #endif\r | |
41 | #endif\r | |
42 | \r | |
43 | #if defined(__GNUC__)\r | |
44 | # define ARG_UNUSED __attribute__ ((unused))\r | |
45 | #else\r | |
46 | # define ARG_UNUSED\r | |
47 | #endif\r | |
48 | \r | |
49 | static char* ESTRING[] = {\r | |
50 | NULL,\r | |
51 | "failed to match", /* REG_NOMATCH */\r | |
52 | "Invalid regular expression", /* REG_BADPAT */\r | |
53 | "invalid collating element referenced", /* REG_ECOLLATE */\r | |
54 | "invalid character class type referenced", /* REG_ECTYPE */\r | |
55 | "bad backslash-escape sequence", /* REG_EESCAPE */\r | |
56 | "invalid back reference number", /* REG_ESUBREG */\r | |
57 | "imbalanced [ and ]", /* REG_EBRACK */\r | |
58 | "imbalanced ( and )", /* REG_EPAREN */\r | |
59 | "imbalanced { and }", /* REG_EBRACE */\r | |
60 | "invalid repeat range {n,m}", /* REG_BADBR */\r | |
61 | "invalid range", /* REG_ERANGE */\r | |
62 | "Out of memory", /* REG_ESPACE */\r | |
63 | "? * + not preceded by valid regular expression", /* REG_BADRPT */\r | |
64 | \r | |
65 | /* Extended errors */\r | |
66 | "internal error", /* REG_EONIG_INTERNAL */\r | |
67 | "invalid wide char value", /* REG_EONIG_BADWC */\r | |
68 | "invalid argument", /* REG_EONIG_BADARG */\r | |
69 | "multi-thread error" /* REG_EONIG_THREAD */\r | |
70 | };\r | |
71 | \r | |
72 | //#include <stdio.h>\r | |
73 | \r | |
74 | \r | |
75 | extern size_t\r | |
76 | regerror(int posix_ecode, const regex_t* reg ARG_UNUSED, char* buf,\r | |
77 | size_t size)\r | |
78 | {\r | |
79 | char* s;\r | |
80 | char tbuf[35];\r | |
81 | size_t len;\r | |
82 | \r | |
83 | if (posix_ecode > 0\r | |
84 | && posix_ecode < (int )(sizeof(ESTRING) / sizeof(ESTRING[0]))) {\r | |
85 | s = ESTRING[posix_ecode];\r | |
86 | }\r | |
87 | else if (posix_ecode == 0) {\r | |
88 | s = "";\r | |
89 | }\r | |
90 | else {\r | |
91 | sprintf(tbuf, "undefined error code (%d)", posix_ecode);\r | |
92 | s = tbuf;\r | |
93 | }\r | |
94 | \r | |
95 | len = strlen_s(s, MAX_STRING_SIZE) + 1; /* use strlen() because s is ascii encoding. */\r | |
96 | \r | |
97 | if (buf != NULL && size > 0) {\r | |
98 | strncpy_s(buf, size, s, size - 1);\r | |
99 | buf[size - 1] = '\0';\r | |
100 | }\r | |
101 | return len;\r | |
102 | }\r |