32 #if defined(__sun__) && defined(StupidSunHeaders)
33 # include <sys/types.h>
34 # include <sys/time.h>
40 const char *
re_cmp(
const char *,
const char *);
70 const char *
re_cmp(
const char *str,
const char *regexp) {
71 const char *next_regexp;
79 if (regexp == NULL || str == NULL)
96 while (*str !=
'\0' && !(matched =
re_match_token(*str, re_token[0])))
99 if (matched && *next_regexp == 0)
106 switch (re_token[0]->repeat) {
108 if (matched ==
False)
113 if (matched ==
False)
121 if (matched ==
False)
122 return re_cmp_step(str, next_regexp, 1, 0) ? str : NULL;
130 return re_cmp_step(str, next_regexp, 1, 0) ? str : NULL;
135 return re_cmp_step(str+1, next_regexp, 1, 0) ? str : NULL;
139 switch (re_token[0]->repeat) {
168 else if (*(str+1) != 0)
169 return re_cmp(str+1, regexp);
192 const char *next_regexp;
209 if (re_token[slot] == NULL)
212 if (next_regexp == NULL) {
226 return (*next_regexp == 0 || re_token[slot]->type ==
sel_end) && matched;
228 switch (re_token[slot]->repeat) {
248 }
else if (matches == 1) {
276 if (re_token[0] == NULL)
306 return (c >= sel->
u.
range.low && c <= sel->u.range.high);
315 return (c < sel->u.range.low && c > sel->
u.
range.high);
334 # define exit_if_null if (*regexp == 0) return NULL
336 # define exit_if_null
342 if (sel == NULL || regexp == NULL || *regexp == 0)
347 looking_at = *regexp++;
348 switch (looking_at) {
379 uchar first, last = 0;
382 looking_at = *regexp++;
384 if (looking_at ==
'^') {
387 looking_at = *regexp++;
391 looking_at = *regexp++;
392 if (looking_at ==
']') {
397 }
else if (looking_at ==
'-') {
411 looking_at = *regexp++;
412 if (looking_at ==
']') {
442 for (i = first; i <= last; i++) {
447 sel->
u.
array[first] = !neg;
449 sel->
u.
array[looking_at] = !neg;
452 previous = looking_at;
453 looking_at = *regexp++;
461 while (looking_at !=
']') {
462 if (looking_at ==
'-') {
464 looking_at = *regexp++;
465 if (looking_at !=
']') {
467 if (previous > looking_at)
470 for (i = previous+1; i < looking_at; i++) {
482 sel->
u.
array[looking_at] = !neg;
483 previous = looking_at;
485 looking_at = *regexp++;
509 if (*regexp ==
'*') {
512 }
else if (*regexp ==
'?') {
515 }
else if (*regexp ==
'+') {
534 static void re_dump_sel(
selection *sel) {
555 for (i = 0; i < UCHAR_MAX; i++) {
565 printf(
"[^%c]", sel->
u.
single);
569 printf(
"[^%c-%c]", sel->
u.
range.low, sel->
u.
range.high);
573 printf(
"<UNKNOWN TOKEN!>");
594 printf(
"<UNKNOWN REP-TOKEN!>");
599 int main(
int argc,
char *argv[]) {
605 printf(
"'%s' -> '%s'\n", argv[1], re);
608 m =
re_cmp(argv[2], argv[1]);
610 printf(
"MATCH! -> '%s'\n", m);
static Boolean re_init_done
static void re_init(void)
static const char * re_substr[RE_TOKEN_MAX]
static int matches(const char *exp, const char *text)
static Boolean re_match_token(uchar, selection *)
static const char * re_get_token(selection *, const char *)
const char * re_cmp(const char *, const char *)
struct selection::@1::@2 range
static Boolean re_cmp_step(const char *, const char *, unsigned, int)
static selection * re_token[RE_TOKEN_MAX]
static unsigned int re_token_depth
int main(int argc, char **argv)