| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include <config.h> |
| 18 |
|
| 19 |
#include "regex.h" |
| 20 |
|
| 21 |
#include <locale.h> |
| 22 |
#include <limits.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <string.h> |
| 25 |
#if HAVE_DECL_ALARM |
| 26 |
# include <unistd.h> |
| 27 |
# include <signal.h> |
| 28 |
#endif |
| 29 |
|
| 30 |
#include "localcharset.h" |
| 31 |
|
| 32 |
int |
| 33 |
main (void) |
| 34 |
{ |
| 35 |
int result = 0; |
| 36 |
static struct re_pattern_buffer regex; |
| 37 |
unsigned char folded_chars[UCHAR_MAX + 1]; |
| 38 |
int i; |
| 39 |
const char *s; |
| 40 |
struct re_registers regs; |
| 41 |
|
| 42 |
#if HAVE_DECL_ALARM |
| 43 |
|
| 44 |
int alarm_value = 2; |
| 45 |
signal (SIGALRM, SIG_DFL); |
| 46 |
alarm (alarm_value); |
| 47 |
#endif |
| 48 |
if (setlocale (LC_ALL, "en_US.UTF-8")) |
| 49 |
{ |
| 50 |
{ |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
static char const pat[] = "insert into"; |
| 57 |
static char const data[] = |
| 58 |
"\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK"; |
| 59 |
re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE |
| 60 |
| RE_ICASE); |
| 61 |
memset (®ex, 0, sizeof regex); |
| 62 |
s = re_compile_pattern (pat, sizeof pat - 1, ®ex); |
| 63 |
if (s) |
| 64 |
result |= 1; |
| 65 |
else |
| 66 |
{ |
| 67 |
memset (®s, 0, sizeof regs); |
| 68 |
if (re_search (®ex, data, sizeof data - 1, |
| 69 |
0, sizeof data - 1, ®s) |
| 70 |
!= -1) |
| 71 |
result |= 1; |
| 72 |
regfree (®ex); |
| 73 |
free (regs.start); |
| 74 |
free (regs.end); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
if (strcmp (locale_charset (), "UTF-8") == 0) |
| 83 |
{ |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
static char const pat[] = "[^x]x"; |
| 89 |
static char const data[] = |
| 90 |
|
| 91 |
"\xe1\x80\x80" |
| 92 |
"\xe1\x80\xbb" |
| 93 |
"\xe1\x80\xbd" |
| 94 |
"\xe1\x80\x94" |
| 95 |
"\xe1\x80\xba" |
| 96 |
"\xe1\x80\xaf" |
| 97 |
"\xe1\x80\x95" |
| 98 |
"\xe1\x80\xba" |
| 99 |
"x"; |
| 100 |
re_set_syntax (0); |
| 101 |
memset (®ex, 0, sizeof regex); |
| 102 |
s = re_compile_pattern (pat, sizeof pat - 1, ®ex); |
| 103 |
if (s) |
| 104 |
result |= 1; |
| 105 |
else |
| 106 |
{ |
| 107 |
memset (®s, 0, sizeof regs); |
| 108 |
i = re_search (®ex, data, sizeof data - 1, |
| 109 |
0, sizeof data - 1, 0); |
| 110 |
if (i != 0 && i != 21) |
| 111 |
result |= 1; |
| 112 |
regfree (®ex); |
| 113 |
free (regs.start); |
| 114 |
free (regs.end); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
if (! setlocale (LC_ALL, "C")) |
| 119 |
return 1; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE); |
| 124 |
memset (®ex, 0, sizeof regex); |
| 125 |
s = re_compile_pattern ("a[^x]b", 6, ®ex); |
| 126 |
if (s) |
| 127 |
result |= 2; |
| 128 |
|
| 129 |
else |
| 130 |
{ |
| 131 |
memset (®s, 0, sizeof regs); |
| 132 |
if (re_search (®ex, "a\nb", 3, 0, 3, ®s) != -1) |
| 133 |
result |= 2; |
| 134 |
regfree (®ex); |
| 135 |
free (regs.start); |
| 136 |
free (regs.end); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
re_set_syntax (RE_SYNTAX_POSIX_EGREP); |
| 142 |
memset (®ex, 0, sizeof regex); |
| 143 |
for (i = 0; i <= UCHAR_MAX; i++) |
| 144 |
folded_chars[i] = i; |
| 145 |
regex.translate = folded_chars; |
| 146 |
s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, ®ex); |
| 147 |
|
| 148 |
if (!s) |
| 149 |
{ |
| 150 |
result |= 4; |
| 151 |
regfree (®ex); |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
re_set_syntax (RE_SYNTAX_POSIX_EGREP | RE_NO_EMPTY_RANGES); |
| 157 |
memset (®ex, 0, sizeof regex); |
| 158 |
s = re_compile_pattern ("a[b-a]", 6, ®ex); |
| 159 |
if (s == 0) |
| 160 |
{ |
| 161 |
result |= 8; |
| 162 |
regfree (®ex); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
memset (®ex, 0, sizeof regex); |
| 167 |
s = re_compile_pattern ("{1", 2, ®ex); |
| 168 |
if (s) |
| 169 |
result |= 8; |
| 170 |
else |
| 171 |
regfree (®ex); |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
memset (®ex, 0, sizeof regex); |
| 176 |
s = re_compile_pattern ("[an\371]*n", 7, ®ex); |
| 177 |
if (s) |
| 178 |
result |= 8; |
| 179 |
|
| 180 |
else |
| 181 |
{ |
| 182 |
memset (®s, 0, sizeof regs); |
| 183 |
if (re_match (®ex, "an", 2, 0, ®s) != 2) |
| 184 |
result |= 8; |
| 185 |
regfree (®ex); |
| 186 |
free (regs.start); |
| 187 |
free (regs.end); |
| 188 |
} |
| 189 |
|
| 190 |
memset (®ex, 0, sizeof regex); |
| 191 |
s = re_compile_pattern ("x", 1, ®ex); |
| 192 |
if (s) |
| 193 |
result |= 8; |
| 194 |
|
| 195 |
else |
| 196 |
{ |
| 197 |
memset (®s, 0, sizeof regs); |
| 198 |
if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1) |
| 199 |
result |= 8; |
| 200 |
regfree (®ex); |
| 201 |
free (regs.start); |
| 202 |
free (regs.end); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE); |
| 208 |
memset (®ex, 0, sizeof regex); |
| 209 |
s = re_compile_pattern ("x", 1, ®ex); |
| 210 |
if (s) |
| 211 |
result |= 16; |
| 212 |
else |
| 213 |
{ |
| 214 |
memset (®s, 0, sizeof regs); |
| 215 |
if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0) |
| 216 |
result |= 16; |
| 217 |
regfree (®ex); |
| 218 |
free (regs.start); |
| 219 |
free (regs.end); |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
re_set_syntax (RE_SYNTAX_POSIX_BASIC |
| 226 |
& ~RE_CONTEXT_INVALID_DUP |
| 227 |
& ~RE_NO_EMPTY_RANGES); |
| 228 |
memset (®ex, 0, sizeof regex); |
| 229 |
s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, ®ex); |
| 230 |
if (s) |
| 231 |
result |= 32; |
| 232 |
else |
| 233 |
regfree (®ex); |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
if (! REG_STARTEND) |
| 238 |
result |= 64; |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
re_set_syntax (RE_SYNTAX_POSIX_EGREP); |
| 246 |
memset (®ex, 0, sizeof regex); |
| 247 |
s = re_compile_pattern ("0|()0|\\1|0", 10, ®ex); |
| 248 |
if (!s || strcmp (s, "Invalid back reference")) |
| 249 |
result |= 64; |
| 250 |
|
| 251 |
#if 0 |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
if (sizeof (regoff_t) < sizeof (ptrdiff_t) |
| 259 |
|| sizeof (regoff_t) < sizeof (ssize_t)) |
| 260 |
result |= 64; |
| 261 |
#endif |
| 262 |
|
| 263 |
return result; |
| 264 |
} |