Changeset 3058
- Timestamp:
- Apr 8, 2007, 8:51:40 PM (18 years ago)
- Location:
- branches/libc-0.6/src/emx
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/libc-0.6/src/emx/include/regex.h
r2240 r3058 1 1 /* Definitions for data structures and routines for the regular 2 2 expression library. 3 Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003 3 Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005,2006 4 4 Free Software Foundation, Inc. 5 5 This file is part of the GNU C Library. … … 28 28 #ifdef __cplusplus 29 29 extern "C" { 30 #endif31 32 /* POSIX says that <sys/types.h> must be included (by the caller) before33 <regex.h>. */34 35 #if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS36 /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it37 should be there. */38 # include <stddef.h>39 30 #endif 40 31 … … 209 200 | RE_CONTEXT_INVALID_OPS )) 210 201 211 #define RE_SYNTAX_POSIX_AWK 202 #define RE_SYNTAX_POSIX_AWK \ 212 203 (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ 213 204 | RE_INTERVALS | RE_NO_GNU_OPS) … … 350 341 351 342 #ifndef RE_TRANSLATE_TYPE 352 # define RE_TRANSLATE_TYPE char *343 # define RE_TRANSLATE_TYPE unsigned char * 353 344 #endif 354 345 355 346 struct re_pattern_buffer 356 347 { 357 /* [[[begin pattern_buffer]]] */ 358 /* Space that holds the compiled pattern. It is declared as 359 `unsigned char *' because its elements are 360 sometimes used as array indexes. */ 348 /* Space that holds the compiled pattern. It is declared as 349 `unsigned char *' because its elements are sometimes used as 350 array indexes. */ 361 351 unsigned char *buffer; 362 352 363 353 /* Number of bytes to which `buffer' points. */ 364 354 unsigned long int allocated; 365 355 366 356 /* Number of bytes actually used in `buffer'. */ 367 357 unsigned long int used; 368 358 369 359 /* Syntax setting with which the pattern was compiled. */ 370 360 reg_syntax_t syntax; 371 361 372 /* Pointer to a fastmap, if any, otherwise zero. re_search uses373 the fastmap, if there is one, to skip over impossible374 starting pointsfor matches. */362 /* Pointer to a fastmap, if any, otherwise zero. re_search uses the 363 fastmap, if there is one, to skip over impossible starting points 364 for matches. */ 375 365 char *fastmap; 376 366 377 378 comparing them, or zero for no translation. The translation379 is applied to a pattern when it is compiled and to a string380 when itis matched. */367 /* Either a translate table to apply to all characters before 368 comparing them, or zero for no translation. The translation is 369 applied to a pattern when it is compiled and to a string when it 370 is matched. */ 381 371 RE_TRANSLATE_TYPE translate; 382 372 383 373 /* Number of subexpressions found by the compiler. */ 384 374 size_t re_nsub; 385 375 386 /* Zero if this pattern cannot match the empty string, one else. 387 Well, in truth it's used only in `re_search_2', to see 388 whether or not we should use the fastmap, so we don't set 389 this absolutely perfectly; see `re_compile_fastmap' (the 390 `duplicate' case). */ 376 /* Zero if this pattern cannot match the empty string, one else. 377 Well, in truth it's used only in `re_search_2', to see whether or 378 not we should use the fastmap, so we don't set this absolutely 379 perfectly; see `re_compile_fastmap' (the `duplicate' case). */ 391 380 unsigned can_be_null : 1; 392 381 393 394 395 396 382 /* If REGS_UNALLOCATED, allocate space in the `regs' structure 383 for `max (RE_NREGS, re_nsub + 1)' groups. 384 If REGS_REALLOCATE, reallocate space if necessary. 385 If REGS_FIXED, use what's there. */ 397 386 #define REGS_UNALLOCATED 0 398 387 #define REGS_REALLOCATE 1 … … 400 389 unsigned regs_allocated : 2; 401 390 402 403 391 /* Set to zero when `regex_compile' compiles a pattern; set to one 392 by `re_compile_fastmap' if it updates the fastmap. */ 404 393 unsigned fastmap_accurate : 1; 405 394 406 407 395 /* If set, `re_match_2' does not return information about 396 subexpressions. */ 408 397 unsigned no_sub : 1; 409 398 410 /* If set, a beginning-of-line anchor doesn't match at the411 beginningof the string. */399 /* If set, a beginning-of-line anchor doesn't match at the beginning 400 of the string. */ 412 401 unsigned not_bol : 1; 413 402 414 403 /* Similarly for an end-of-line anchor. */ 415 404 unsigned not_eol : 1; 416 405 417 406 /* If true, an anchor at a newline matches. */ 418 407 unsigned newline_anchor : 1; 419 420 /* [[[end pattern_buffer]]] */421 408 }; 422 409 … … 458 445 /* Declarations for routines. */ 459 446 460 /* To avoid duplicating every routine declaration -- once with a461 prototype (if we are ANSI), and once without (if we aren't) -- we462 use the following macro to declare argument types. This463 unfortunately clutters up the declarations a bit, but I think it's464 worth it. */465 466 #if __STDC__467 468 # define _RE_ARGS(args) args469 470 #else /* not __STDC__ */471 472 # define _RE_ARGS(args) ()473 #error "asdf"474 475 #endif /* not __STDC__ */476 477 447 /* Sets the current default syntax to SYNTAX, and return the old syntax. 478 448 You can also simply assign to the `re_syntax_options' variable. */ 479 extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));449 extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); 480 450 481 451 /* Compile the regular expression PATTERN, with length LENGTH 482 452 and syntax given by the global `re_syntax_options', into the buffer 483 453 BUFFER. Return NULL if successful, and an error string if not. */ 484 extern const char *re_compile_pattern 485 _RE_ARGS ((const char *pattern, size_t length, 486 struct re_pattern_buffer *buffer)); 454 extern const char *re_compile_pattern (const char *__pattern, size_t __length, 455 struct re_pattern_buffer *__buffer); 487 456 488 457 … … 490 459 accelerate searches. Return 0 if successful and -2 if was an 491 460 internal error. */ 492 extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));461 extern int re_compile_fastmap (struct re_pattern_buffer *__buffer); 493 462 494 463 … … 498 467 match, or -2 for an internal error. Also return register 499 468 information in REGS (if REGS and BUFFER->no_sub are nonzero). */ 500 extern int re_search 501 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,502 int length, int start, int range, struct re_registers *regs));469 extern int re_search (struct re_pattern_buffer *__buffer, const char *__string, 470 int __length, int __start, int __range, 471 struct re_registers *__regs); 503 472 504 473 505 474 /* Like `re_search', but search in the concatenation of STRING1 and 506 475 STRING2. Also, stop searching at index START + STOP. */ 507 extern int re_search_2 508 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,509 int length1, const char *string2, int length2,510 int start, int range, struct re_registers *regs, int stop));476 extern int re_search_2 (struct re_pattern_buffer *__buffer, 477 const char *__string1, int __length1, 478 const char *__string2, int __length2, int __start, 479 int __range, struct re_registers *__regs, int __stop); 511 480 512 481 513 482 /* Like `re_search', but return how many characters in STRING the regexp 514 483 in BUFFER matched, starting at position START. */ 515 extern int re_match 516 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, 517 int length, int start, struct re_registers *regs)); 484 extern int re_match (struct re_pattern_buffer *__buffer, const char *__string, 485 int __length, int __start, struct re_registers *__regs); 518 486 519 487 520 488 /* Relates to `re_match' as `re_search_2' relates to `re_search'. */ 521 extern int re_match_2 522 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,523 int length1, const char *string2, int length2,524 int start, struct re_registers *regs, int stop));489 extern int re_match_2 (struct re_pattern_buffer *__buffer, 490 const char *__string1, int __length1, 491 const char *__string2, int __length2, int __start, 492 struct re_registers *__regs, int __stop); 525 493 526 494 … … 537 505 PATTERN_BUFFER will allocate its own register data, without 538 506 freeing the old data. */ 539 extern void re_set_registers 540 _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, 541 unsigned num_regs, regoff_t *starts, regoff_t *ends)); 507 extern void re_set_registers (struct re_pattern_buffer *__buffer, 508 struct re_registers *__regs, 509 unsigned int __num_regs, 510 regoff_t *__starts, regoff_t *__ends); 542 511 543 512 #if defined _REGEX_RE_COMP || defined _LIBC 544 513 # ifndef _CRAY 545 514 /* 4.2 bsd compatibility. */ 546 extern char *re_comp _RE_ARGS ((const char *));547 extern int re_exec _RE_ARGS ((const char *));515 extern char *re_comp (const char *); 516 extern int re_exec (const char *); 548 517 # endif 549 518 #endif … … 562 531 /* gcc 3.1 and up support the [restrict] syntax. */ 563 532 #ifndef __restrict_arr 564 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) 533 # if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) \ 534 && !defined __GNUG__ 565 535 # define __restrict_arr __restrict 566 536 # else … … 570 540 571 541 /* POSIX compatibility. */ 572 extern int regcomp _RE_ARGS ((regex_t *__restrict __preg,573 574 int __cflags));575 576 extern int regexec _RE_ARGS ((const regex_t *__restrict __preg,577 578 579 int __eflags));580 581 extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg,582 char *__errbuf, size_t __errbuf_size));583 584 extern void regfree _RE_ARGS ((regex_t *__preg));542 extern int regcomp (regex_t *__restrict __preg, 543 const char *__restrict __pattern, 544 int __cflags); 545 546 extern int regexec (const regex_t *__restrict __preg, 547 const char *__restrict __string, size_t __nmatch, 548 regmatch_t __pmatch[__restrict_arr], 549 int __eflags); 550 551 extern size_t regerror (int __errcode, const regex_t *__restrict __preg, 552 char *__restrict __errbuf, size_t __errbuf_size); 553 554 extern void regfree (regex_t *__preg); 585 555 586 556 … … 590 560 591 561 #endif /* regex.h */ 592 593 594 /*595 Local variables:596 make-backup-files: t597 version-control: t598 trim-versions-without-asking: nil599 End:600 */ -
branches/libc-0.6/src/emx/src/lib/lgpl/include/config.h
r2259 r3058 52 52 #define HAVE___ARGZ_STRINGIFY 1 53 53 #define HAVE___ARGZ_NEXT 1 54 #define HAVE_STDINT_H 1 54 55 #define HAVE_STDINT_H_WITH_UINTMAX 1 55 56 #define HAVE_STRCASECMP 1 … … 61 62 #define HAVE_STDLIB_H 1 62 63 #define HAVE_STRING_H 1 64 #define HAVE_LANGINFO_H 1 63 65 #define HAVE_LANGINFO_CODESET 1 64 66 #define HAVE_SETLOCALE 1 … … 73 75 #define HAVE_WCSCOLL 0 74 76 #define HAVE_DECL_GETC_UNLOCKED 1 77 #define HAVE_STDBOOL_H 1 75 78 76 79 #define STRERROR_R_CHAR_P 0 -
branches/libc-0.6/src/emx/src/lib/lgpl/posix/regcomp.c
r2260 r3058 1 1 /* Extended regular expression matching and search library. 2 Copyright (C) 2002, 2003, 2004, 2005Free Software Foundation, Inc.2 Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc. 3 3 This file is part of the GNU C Library. 4 4 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. … … 20 20 21 21 static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern, 22 int length, reg_syntax_t syntax);22 size_t length, reg_syntax_t syntax); 23 23 static void re_compile_fastmap_iter (regex_t *bufp, 24 24 const re_dfastate_t *init_state, 25 25 char *fastmap); 26 static reg_errcode_t init_dfa (re_dfa_t *dfa, int pat_len); 27 static void init_word_char (re_dfa_t *dfa); 26 static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len); 28 27 #ifdef RE_ENABLE_I18N 29 28 static void free_charset (re_charset_t *cset); … … 35 34 #endif 36 35 static reg_errcode_t analyze (regex_t *preg); 37 static reg_errcode_t create_initial_state (re_dfa_t *dfa);38 36 static reg_errcode_t preorder (bin_tree_t *root, 39 37 reg_errcode_t (fn (void *, bin_tree_t *)), … … 49 47 static reg_errcode_t calc_next (void *extra, bin_tree_t *node); 50 48 static reg_errcode_t link_nfa_nodes (void *extra, bin_tree_t *node); 51 static reg_errcode_t duplicate_node_closure (re_dfa_t *dfa, int top_org_node, 52 int top_clone_node, int root_node, 53 unsigned int constraint); 54 static reg_errcode_t duplicate_node (int *new_idx, re_dfa_t *dfa, int org_idx, 55 unsigned int constraint); 56 static int search_duplicated_node (re_dfa_t *dfa, int org_node, 49 static int duplicate_node (re_dfa_t *dfa, int org_idx, unsigned int constraint); 50 static int search_duplicated_node (const re_dfa_t *dfa, int org_node, 57 51 unsigned int constraint); 58 52 static reg_errcode_t calc_eclosure (re_dfa_t *dfa); … … 62 56 static int fetch_number (re_string_t *input, re_token_t *token, 63 57 reg_syntax_t syntax); 64 static void fetch_token (re_token_t *result, re_string_t *input,65 reg_syntax_t syntax);66 58 static int peek_token (re_token_t *token, re_string_t *input, 67 reg_syntax_t syntax); 68 static int peek_token_bracket (re_token_t *token, re_string_t *input, 69 reg_syntax_t syntax); 59 reg_syntax_t syntax) internal_function; 70 60 static bin_tree_t *parse (re_string_t *regexp, regex_t *preg, 71 61 reg_syntax_t syntax, reg_errcode_t *err); … … 97 87 re_string_t *regexp, 98 88 re_token_t *token); 99 #ifndef _LIBC 100 # ifdef RE_ENABLE_I18N 101 static reg_errcode_t build_range_exp (re_bitset_ptr_t sbcset, 102 re_charset_t *mbcset, int *range_alloc, 103 bracket_elem_t *start_elem, 104 bracket_elem_t *end_elem); 105 static reg_errcode_t build_collating_symbol (re_bitset_ptr_t sbcset, 106 re_charset_t *mbcset, 107 int *coll_sym_alloc, 108 const unsigned char *name); 109 # else /* not RE_ENABLE_I18N */ 110 static reg_errcode_t build_range_exp (re_bitset_ptr_t sbcset, 111 bracket_elem_t *start_elem, 112 bracket_elem_t *end_elem); 113 static reg_errcode_t build_collating_symbol (re_bitset_ptr_t sbcset, 114 const unsigned char *name); 115 # endif /* not RE_ENABLE_I18N */ 116 #endif /* not _LIBC */ 117 #ifdef RE_ENABLE_I18N 118 static reg_errcode_t build_equiv_class (re_bitset_ptr_t sbcset, 89 #ifdef RE_ENABLE_I18N 90 static reg_errcode_t build_equiv_class (bitset_t sbcset, 119 91 re_charset_t *mbcset, 120 92 int *equiv_class_alloc, 121 93 const unsigned char *name); 122 static reg_errcode_t build_charclass ( unsignedRE_TRANSLATE_TYPE trans,123 re_bitset_ptr_t sbcset,94 static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans, 95 bitset_t sbcset, 124 96 re_charset_t *mbcset, 125 97 int *char_class_alloc, … … 127 99 reg_syntax_t syntax); 128 100 #else /* not RE_ENABLE_I18N */ 129 static reg_errcode_t build_equiv_class ( re_bitset_ptr_t sbcset,101 static reg_errcode_t build_equiv_class (bitset_t sbcset, 130 102 const unsigned char *name); 131 static reg_errcode_t build_charclass ( unsignedRE_TRANSLATE_TYPE trans,132 re_bitset_ptr_t sbcset,103 static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans, 104 bitset_t sbcset, 133 105 const unsigned char *class_name, 134 106 reg_syntax_t syntax); 135 107 #endif /* not RE_ENABLE_I18N */ 136 108 static bin_tree_t *build_charclass_op (re_dfa_t *dfa, 137 unsignedRE_TRANSLATE_TYPE trans,109 RE_TRANSLATE_TYPE trans, 138 110 const unsigned char *class_name, 139 111 const unsigned char *extra, … … 330 302 331 303 static void 332 re_compile_fastmap_iter (bufp, init_state, fastmap) 333 regex_t *bufp; 334 const re_dfastate_t *init_state; 335 char *fastmap; 304 re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, 305 char *fastmap) 336 306 { 337 307 re_dfa_t *dfa = (re_dfa_t *) bufp->buffer; … … 359 329 && dfa->nodes[node].mb_partial) 360 330 *p++ = dfa->nodes[node].opr.c; 361 memset (&state, 0, sizeof (state));331 memset (&state, '\0', sizeof (state)); 362 332 if (mbrtowc (&wc, (const char *) buf, p - buf, 363 333 &state) == p - buf … … 370 340 else if (type == SIMPLE_BRACKET) 371 341 { 372 int i, j, ch; 373 for (i = 0, ch = 0; i < BITSET_UINTS; ++i) 374 for (j = 0; j < UINT_BITS; ++j, ++ch) 375 if (dfa->nodes[node].opr.sbcset[i] & (1 << j)) 376 re_set_fastmap (fastmap, icase, ch); 342 int i, ch; 343 for (i = 0, ch = 0; i < BITSET_WORDS; ++i) 344 { 345 int j; 346 bitset_word_t w = dfa->nodes[node].opr.sbcset[i]; 347 for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) 348 if (w & ((bitset_word_t) 1 << j)) 349 re_set_fastmap (fastmap, icase, ch); 350 } 377 351 } 378 352 #ifdef RE_ENABLE_I18N … … 393 367 'b' since 'b' is the only collation element 394 368 which starts from 'b'. */ 395 int j, ch;396 369 const int32_t *table = (const int32_t *) 397 370 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB); 398 for (i = 0, ch = 0; i < BITSET_UINTS; ++i) 399 for (j = 0; j < UINT_BITS; ++j, ++ch) 400 if (table[ch] < 0) 401 re_set_fastmap (fastmap, icase, ch); 371 for (i = 0; i < SBC_MAX; ++i) 372 if (table[i] < 0) 373 re_set_fastmap (fastmap, icase, i); 402 374 } 403 375 # else … … 419 391 if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state) 420 392 != (size_t) -1) 421 re_set_fastmap (fastmap, 0, *(unsigned char *) buf);393 re_set_fastmap (fastmap, 0, *(unsigned char *) buf); 422 394 } 423 395 } … … 540 512 _STD(regerror) (errcode, preg, errbuf, errbuf_size) 541 513 int errcode; 542 const regex_t * preg;543 char * errbuf;514 const regex_t *__restrict preg; 515 char *__restrict errbuf; 544 516 size_t errbuf_size; 545 517 { … … 587 559 it the same all the time. UTF-8 is the preferred encoding so this is 588 560 a worthwhile optimization. */ 589 static const bitset utf8_sb_map =561 static const bitset_t utf8_sb_map = 590 562 { 591 563 /* Set the first 128 bits. */ 592 # if UINT_MAX == 0xffffffff 593 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff 594 # else 595 # error "Add case for new unsigned int size" 596 # endif 564 [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX 597 565 }; 598 566 #endif … … 745 713 746 714 static reg_errcode_t 747 re_compile_internal (preg, pattern, length, syntax) 748 regex_t *preg; 749 const char * pattern; 750 int length; 751 reg_syntax_t syntax; 715 re_compile_internal (regex_t *preg, const char * pattern, size_t length, 716 reg_syntax_t syntax) 752 717 { 753 718 reg_errcode_t err = REG_NOERROR; … … 780 745 preg->used = sizeof (re_dfa_t); 781 746 782 /* __libc_lock_init (dfa->lock); - why init before memsetting the whole thing? */783 784 747 err = init_dfa (dfa, length); 785 748 if (BE (err != REG_NOERROR, 0)) … … 790 753 return err; 791 754 } 792 __libc_lock_init (dfa->lock); /* bird */793 794 755 #ifdef DEBUG 756 /* Note: length+1 will not overflow since it is checked in init_dfa. */ 795 757 dfa->re_str = re_malloc (char, length + 1); 796 758 strncpy (dfa->re_str, pattern, length + 1); 797 759 #endif 760 761 __libc_lock_init (dfa->lock); 798 762 799 763 err = re_string_construct (®exp, pattern, length, preg->translate, … … 848 812 849 813 static reg_errcode_t 850 init_dfa (dfa, pat_len) 851 re_dfa_t *dfa; 852 int pat_len; 853 { 854 int table_size; 814 init_dfa (re_dfa_t *dfa, size_t pat_len) 815 { 816 unsigned int table_size; 855 817 #ifndef _LIBC 856 818 char *codeset_name; … … 862 824 dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE; 863 825 826 /* Avoid overflows. */ 827 if (pat_len == SIZE_MAX) 828 return REG_ESPACE; 829 864 830 dfa->nodes_alloc = pat_len + 1; 865 831 dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc); 866 832 867 dfa->states_alloc = pat_len + 1;868 869 833 /* table_size = 2 ^ ceil(log pat_len) */ 870 for (table_size = 1; table_size > 0; table_size <<= 1)834 for (table_size = 1; ; table_size <<= 1) 871 835 if (table_size > pat_len) 872 836 break; … … 915 879 int i, j, ch; 916 880 917 dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset ), 1);881 dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); 918 882 if (BE (dfa->sb_char == NULL, 0)) 919 883 return REG_ESPACE; 920 884 921 /* Clear all bits by, then set those corresponding to single 922 byte chars. */ 923 bitset_empty (dfa->sb_char); 924 925 for (i = 0, ch = 0; i < BITSET_UINTS; ++i) 926 for (j = 0; j < UINT_BITS; ++j, ++ch) 885 /* Set the bits corresponding to single byte chars. */ 886 for (i = 0, ch = 0; i < BITSET_WORDS; ++i) 887 for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) 927 888 { 928 889 wint_t wch = __btowc (ch); 929 890 if (wch != WEOF) 930 dfa->sb_char[i] |= 1 << j;931 # if !defined (_LIBC) && !defined (__INNOTEK_LIBC__)932 if (isascii (ch) && wch != (wchar_t)ch)891 dfa->sb_char[i] |= (bitset_word_t) 1 << j; 892 # if !defined (_LIBC) 893 if (isascii (ch) && wch != ch) 933 894 dfa->map_notascii = 1; 934 895 # endif … … 948 909 949 910 static void 950 in it_word_char (dfa)951 re_dfa_t *dfa; 911 internal_function 912 init_word_char (re_dfa_t *dfa) 952 913 { 953 914 int i, j, ch; 954 915 dfa->word_ops_used = 1; 955 for (i = 0, ch = 0; i < BITSET_ UINTS; ++i)956 for (j = 0; j < UINT_BITS; ++j, ++ch)916 for (i = 0, ch = 0; i < BITSET_WORDS; ++i) 917 for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) 957 918 if (isalnum (ch) || ch == '_') 958 dfa->word_char[i] |= 1 << j;919 dfa->word_char[i] |= (bitset_word_t) 1 << j; 959 920 } 960 921 … … 962 923 963 924 static void 964 free_workarea_compile (preg) 965 regex_t *preg; 925 free_workarea_compile (regex_t *preg) 966 926 { 967 927 re_dfa_t *dfa = (re_dfa_t *) preg->buffer; … … 982 942 983 943 static reg_errcode_t 984 create_initial_state (dfa) 985 re_dfa_t *dfa; 944 create_initial_state (re_dfa_t *dfa) 986 945 { 987 946 int first, i; … … 1066 1025 1067 1026 static void 1068 optimize_utf8 (dfa) 1069 re_dfa_t *dfa; 1027 optimize_utf8 (re_dfa_t *dfa) 1070 1028 { 1071 1029 int node, i, mb_chars = 0, has_period = 0; … … 1104 1062 return; 1105 1063 case SIMPLE_BRACKET: 1106 /* Just double check. */ 1107 for (i = 0x80 / UINT_BITS; i < BITSET_UINTS; ++i) 1064 /* Just double check. The non-ASCII range starts at 0x80. */ 1065 assert (0x80 % BITSET_WORD_BITS == 0); 1066 for (i = 0x80 / BITSET_WORD_BITS; i < BITSET_WORDS; ++i) 1108 1067 if (dfa->nodes[node].opr.sbcset[i]) 1109 1068 return; … … 1135 1094 1136 1095 static reg_errcode_t 1137 analyze (preg) 1138 regex_t *preg; 1096 analyze (regex_t *preg) 1139 1097 { 1140 1098 re_dfa_t *dfa = (re_dfa_t *) preg->buffer; … … 1199 1157 some hairy code in these two functions. */ 1200 1158 static reg_errcode_t 1201 postorder (root, fn, extra) 1202 bin_tree_t *root; 1203 reg_errcode_t (fn (void *, bin_tree_t *)); 1204 void *extra; 1159 postorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)), 1160 void *extra) 1205 1161 { 1206 1162 bin_tree_t *node, *prev; … … 1233 1189 1234 1190 static reg_errcode_t 1235 preorder (root, fn, extra) 1236 bin_tree_t *root; 1237 reg_errcode_t (fn (void *, bin_tree_t *)); 1238 void *extra; 1191 preorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)), 1192 void *extra) 1239 1193 { 1240 1194 bin_tree_t *node; … … 1268 1222 backreferences as well. Requires a preorder visit. */ 1269 1223 static reg_errcode_t 1270 optimize_subexps (extra, node) 1271 void *extra; 1272 bin_tree_t *node; 1224 optimize_subexps (void *extra, bin_tree_t *node) 1273 1225 { 1274 1226 re_dfa_t *dfa = (re_dfa_t *) extra; … … 1291 1243 1292 1244 dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx]; 1293 if (other_idx < 8 * sizeof (dfa->used_bkref_map))1294 dfa->used_bkref_map &= ~(1 << other_idx);1245 if (other_idx < BITSET_WORD_BITS) 1246 dfa->used_bkref_map &= ~((bitset_word_t) 1 << other_idx); 1295 1247 } 1296 1248 … … 1301 1253 of OP_OPEN_SUBEXP, the body of the SUBEXP (if any) and OP_CLOSE_SUBEXP. */ 1302 1254 static reg_errcode_t 1303 lower_subexps (extra, node) 1304 void *extra; 1305 bin_tree_t *node; 1255 lower_subexps (void *extra, bin_tree_t *node) 1306 1256 { 1307 1257 regex_t *preg = (regex_t *) extra; … … 1325 1275 1326 1276 static bin_tree_t * 1327 lower_subexp (err, preg, node) 1328 reg_errcode_t *err; 1329 regex_t *preg; 1330 bin_tree_t *node; 1277 lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node) 1331 1278 { 1332 1279 re_dfa_t *dfa = (re_dfa_t *) preg->buffer; … … 1340 1287 this case is the sed "script" /\(\)/x. */ 1341 1288 && node->left != NULL 1342 && (node->token.opr.idx >= 8 * sizeof (dfa->used_bkref_map) 1343 || !(dfa->used_bkref_map & (1 << node->token.opr.idx)))) 1289 && (node->token.opr.idx >= BITSET_WORD_BITS 1290 || !(dfa->used_bkref_map 1291 & ((bitset_word_t) 1 << node->token.opr.idx)))) 1344 1292 return node->left; 1345 1293 … … 1364 1312 nodes. Requires a postorder visit. */ 1365 1313 static reg_errcode_t 1366 calc_first (extra, node) 1367 void *extra; 1368 bin_tree_t *node; 1314 calc_first (void *extra, bin_tree_t *node) 1369 1315 { 1370 1316 re_dfa_t *dfa = (re_dfa_t *) extra; … … 1386 1332 /* Pass 2: compute NEXT on the tree. Preorder visit. */ 1387 1333 static reg_errcode_t 1388 calc_next (extra, node) 1389 void *extra; 1390 bin_tree_t *node; 1334 calc_next (void *extra, bin_tree_t *node) 1391 1335 { 1392 1336 switch (node->token.type) … … 1411 1355 /* Pass 3: link all DFA nodes to their NEXT node (any order will do). */ 1412 1356 static reg_errcode_t 1413 link_nfa_nodes (extra, node) 1414 void *extra; 1415 bin_tree_t *node; 1357 link_nfa_nodes (void *extra, bin_tree_t *node) 1416 1358 { 1417 1359 re_dfa_t *dfa = (re_dfa_t *) extra; … … 1473 1415 1474 1416 static reg_errcode_t 1475 duplicate_node_closure (dfa, top_org_node, top_clone_node, root_node, 1476 init_constraint) 1477 re_dfa_t *dfa; 1478 int top_org_node, top_clone_node, root_node; 1479 unsigned int init_constraint; 1480 { 1481 reg_errcode_t err; 1417 internal_function 1418 duplicate_node_closure (re_dfa_t *dfa, int top_org_node, int top_clone_node, 1419 int root_node, unsigned int init_constraint) 1420 { 1482 1421 int org_node, clone_node, ret; 1483 1422 unsigned int constraint = init_constraint; … … 1493 1432 org_dest = dfa->nexts[org_node]; 1494 1433 re_node_set_empty (dfa->edests + clone_node); 1495 err = duplicate_node (&clone_dest,dfa, org_dest, constraint);1496 if (BE ( err != REG_NOERROR, 0))1497 return err;1434 clone_dest = duplicate_node (dfa, org_dest, constraint); 1435 if (BE (clone_dest == -1, 0)) 1436 return REG_ESPACE; 1498 1437 dfa->nexts[clone_node] = dfa->nexts[org_node]; 1499 1438 ret = re_node_set_insert (dfa->edests + clone_node, clone_dest); … … 1531 1470 constraint |= dfa->nodes[org_node].opr.ctx_type; 1532 1471 } 1533 err = duplicate_node (&clone_dest,dfa, org_dest, constraint);1534 if (BE ( err != REG_NOERROR, 0))1535 return err;1472 clone_dest = duplicate_node (dfa, org_dest, constraint); 1473 if (BE (clone_dest == -1, 0)) 1474 return REG_ESPACE; 1536 1475 ret = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1537 1476 if (BE (ret < 0, 0)) … … 1549 1488 { 1550 1489 /* There are no such a duplicated node, create a new one. */ 1551 err = duplicate_node (&clone_dest, dfa, org_dest, constraint); 1552 if (BE (err != REG_NOERROR, 0)) 1553 return err; 1490 reg_errcode_t err; 1491 clone_dest = duplicate_node (dfa, org_dest, constraint); 1492 if (BE (clone_dest == -1, 0)) 1493 return REG_ESPACE; 1554 1494 ret = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1555 1495 if (BE (ret < 0, 0)) … … 1570 1510 1571 1511 org_dest = dfa->edests[org_node].elems[1]; 1572 err = duplicate_node (&clone_dest,dfa, org_dest, constraint);1573 if (BE ( err != REG_NOERROR, 0))1574 return err;1512 clone_dest = duplicate_node (dfa, org_dest, constraint); 1513 if (BE (clone_dest == -1, 0)) 1514 return REG_ESPACE; 1575 1515 ret = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1576 1516 if (BE (ret < 0, 0)) … … 1587 1527 1588 1528 static int 1589 search_duplicated_node (dfa, org_node, constraint) 1590 re_dfa_t *dfa; 1591 int org_node; 1592 unsigned int constraint; 1529 search_duplicated_node (const re_dfa_t *dfa, int org_node, 1530 unsigned int constraint) 1593 1531 { 1594 1532 int idx; … … 1603 1541 1604 1542 /* Duplicate the node whose index is ORG_IDX and set the constraint CONSTRAINT. 1605 The new index will be stored in NEW_IDX and return REG_NOERROR if succeeded, 1606 otherwise return the error code. */ 1543 Return the index of the new node, or -1 if insufficient storage is 1544 available. */ 1545 1546 static int 1547 duplicate_node (re_dfa_t *dfa, int org_idx, unsigned int constraint) 1548 { 1549 int dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]); 1550 if (BE (dup_idx != -1, 1)) 1551 { 1552 dfa->nodes[dup_idx].constraint = constraint; 1553 if (dfa->nodes[org_idx].type == ANCHOR) 1554 dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].opr.ctx_type; 1555 dfa->nodes[dup_idx].duplicated = 1; 1556 1557 /* Store the index of the original node. */ 1558 dfa->org_indices[dup_idx] = org_idx; 1559 } 1560 return dup_idx; 1561 } 1607 1562 1608 1563 static reg_errcode_t 1609 duplicate_node (new_idx, dfa, org_idx, constraint) 1610 re_dfa_t *dfa; 1611 int *new_idx, org_idx; 1612 unsigned int constraint; 1613 { 1614 int dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]); 1615 if (BE (dup_idx == -1, 0)) 1616 return REG_ESPACE; 1617 dfa->nodes[dup_idx].constraint = constraint; 1618 if (dfa->nodes[org_idx].type == ANCHOR) 1619 dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].opr.ctx_type; 1620 dfa->nodes[dup_idx].duplicated = 1; 1621 1622 /* Store the index of the original node. */ 1623 dfa->org_indices[dup_idx] = org_idx; 1624 *new_idx = dup_idx; 1625 return REG_NOERROR; 1626 } 1627 1628 static reg_errcode_t 1629 calc_inveclosure (dfa) 1630 re_dfa_t *dfa; 1564 calc_inveclosure (re_dfa_t *dfa) 1631 1565 { 1632 1566 int src, idx, ret; … … 1651 1585 1652 1586 static reg_errcode_t 1653 calc_eclosure (dfa) 1654 re_dfa_t *dfa; 1587 calc_eclosure (re_dfa_t *dfa) 1655 1588 { 1656 1589 int node_idx, incomplete; … … 1696 1629 1697 1630 static reg_errcode_t 1698 calc_eclosure_iter (new_set, dfa, node, root) 1699 re_node_set *new_set; 1700 re_dfa_t *dfa; 1701 int node, root; 1631 calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, int node, int root) 1702 1632 { 1703 1633 reg_errcode_t err; … … 1722 1652 && !dfa->nodes[dfa->edests[node].elems[0]].duplicated) 1723 1653 { 1724 int org_node, cur_node;1725 org_node = cur_node = node;1726 1654 err = duplicate_node_closure (dfa, node, node, node, constraint); 1727 1655 if (BE (err != REG_NOERROR, 0)) … … 1780 1708 1781 1709 static void 1782 fetch_token (result, input, syntax) 1783 re_token_t *result; 1784 re_string_t *input; 1785 reg_syntax_t syntax; 1710 internal_function 1711 fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax) 1786 1712 { 1787 1713 re_string_skip_bytes (input, peek_token (result, input, syntax)); … … 1792 1718 1793 1719 static int 1794 peek_token (token, input, syntax) 1795 re_token_t *token; 1796 re_string_t *input; 1797 reg_syntax_t syntax; 1720 internal_function 1721 peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) 1798 1722 { 1799 1723 unsigned char c; … … 2033 1957 2034 1958 static int 2035 peek_token_bracket (token, input, syntax) 2036 re_token_t *token; 2037 re_string_t *input; 2038 reg_syntax_t syntax; 1959 internal_function 1960 peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax) 2039 1961 { 2040 1962 unsigned char c; … … 2133 2055 2134 2056 static bin_tree_t * 2135 parse (regexp, preg, syntax, err) 2136 re_string_t *regexp; 2137 regex_t *preg; 2138 reg_syntax_t syntax; 2139 reg_errcode_t *err; 2057 parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax, 2058 reg_errcode_t *err) 2140 2059 { 2141 2060 re_dfa_t *dfa = (re_dfa_t *) preg->buffer; … … 2170 2089 2171 2090 static bin_tree_t * 2172 parse_reg_exp (regexp, preg, token, syntax, nest, err) 2173 re_string_t *regexp; 2174 regex_t *preg; 2175 re_token_t *token; 2176 reg_syntax_t syntax; 2177 int nest; 2178 reg_errcode_t *err; 2091 parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, 2092 reg_syntax_t syntax, int nest, reg_errcode_t *err) 2179 2093 { 2180 2094 re_dfa_t *dfa = (re_dfa_t *) preg->buffer; … … 2216 2130 2217 2131 static bin_tree_t * 2218 parse_branch (regexp, preg, token, syntax, nest, err) 2219 re_string_t *regexp; 2220 regex_t *preg; 2221 re_token_t *token; 2222 reg_syntax_t syntax; 2223 int nest; 2224 reg_errcode_t *err; 2132 parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token, 2133 reg_syntax_t syntax, int nest, reg_errcode_t *err) 2225 2134 { 2226 2135 bin_tree_t *tree, *exp; … … 2261 2170 2262 2171 static bin_tree_t * 2263 parse_expression (regexp, preg, token, syntax, nest, err) 2264 re_string_t *regexp; 2265 regex_t *preg; 2266 re_token_t *token; 2267 reg_syntax_t syntax; 2268 int nest; 2269 reg_errcode_t *err; 2172 parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, 2173 reg_syntax_t syntax, int nest, reg_errcode_t *err) 2270 2174 { 2271 2175 re_dfa_t *dfa = (re_dfa_t *) preg->buffer; … … 2482 2386 2483 2387 static bin_tree_t * 2484 parse_sub_exp (regexp, preg, token, syntax, nest, err) 2485 re_string_t *regexp; 2486 regex_t *preg; 2487 re_token_t *token; 2488 reg_syntax_t syntax; 2489 int nest; 2490 reg_errcode_t *err; 2388 parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, 2389 reg_syntax_t syntax, int nest, reg_errcode_t *err) 2491 2390 { 2492 2391 re_dfa_t *dfa = (re_dfa_t *) preg->buffer; … … 2508 2407 return NULL; 2509 2408 } 2510 dfa->completed_bkref_map |= 1 << cur_nsub; 2409 2410 if (cur_nsub <= '9' - '1') 2411 dfa->completed_bkref_map |= 1 << cur_nsub; 2511 2412 2512 2413 tree = create_tree (dfa, tree, NULL, SUBEXP); … … 2523 2424 2524 2425 static bin_tree_t * 2525 parse_dup_op (elem, regexp, dfa, token, syntax, err) 2526 bin_tree_t *elem; 2527 re_string_t *regexp; 2528 re_dfa_t *dfa; 2529 re_token_t *token; 2530 reg_syntax_t syntax; 2531 reg_errcode_t *err; 2426 parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa, 2427 re_token_t *token, reg_syntax_t syntax, reg_errcode_t *err) 2532 2428 { 2533 2429 bin_tree_t *tree = NULL, *old_tree = NULL; … … 2668 2564 2669 2565 static reg_errcode_t 2566 internal_function 2670 2567 # ifdef RE_ENABLE_I18N 2671 build_range_exp (sbcset, mbcset, range_alloc, start_elem, end_elem) 2672 re_charset_t *mbcset; 2673 int *range_alloc; 2568 build_range_exp (bitset_t sbcset, re_charset_t *mbcset, int *range_alloc, 2569 bracket_elem_t *start_elem, bracket_elem_t *end_elem, reg_syntax_t syntax) /* bird: syntax */ 2674 2570 # else /* not RE_ENABLE_I18N */ 2675 build_range_exp (sbcset, start_elem, end_elem) 2571 build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem, 2572 bracket_elem_t *end_elem, reg_syntax_t syntax) /* bird: syntax */ 2676 2573 # endif /* not RE_ENABLE_I18N */ 2677 re_bitset_ptr_t sbcset;2678 bracket_elem_t *start_elem, *end_elem;2679 2574 { 2680 2575 unsigned int start_ch, end_ch; … … 2695 2590 # ifdef RE_ENABLE_I18N 2696 2591 { 2697 wint_t wc, start_wc, end_wc; 2592 wchar_t wc; 2593 wint_t start_wc; 2594 wint_t end_wc; 2698 2595 wchar_t cmp_buf[6] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'}; 2699 2596 … … 2712 2609 cmp_buf[0] = start_wc; 2713 2610 cmp_buf[4] = end_wc; 2714 if ( wcscoll (cmp_buf, cmp_buf + 4) > 0)2611 if ((syntax & RE_NO_EMPTY_RANGES) && wcscoll (cmp_buf, cmp_buf + 4) > 0) /* bird: RE_NO_EMPTY_RANGES */ 2715 2612 return REG_ERANGE; 2716 2613 … … 2769 2666 : 0)); 2770 2667 if (start_ch > end_ch) 2771 return REG_ERANGE; 2668 return (syntax & RE_NO_EMPTY_RANGES) ? REG_ERANGE : REG_NOERROR; /* bird: added RE_NO_EMPTY_RANGES check. */ 2669 2772 2670 /* Build the table for single byte characters. */ 2773 2671 for (ch = 0; ch < SBC_MAX; ++ch) … … 2788 2686 2789 2687 static reg_errcode_t 2688 internal_function 2790 2689 # ifdef RE_ENABLE_I18N 2791 build_collating_symbol (sbcset, mbcset, coll_sym_alloc, name) 2792 re_charset_t *mbcset; 2793 int *coll_sym_alloc; 2690 build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset, 2691 int *coll_sym_alloc, const unsigned char *name) 2794 2692 # else /* not RE_ENABLE_I18N */ 2795 build_collating_symbol ( sbcset,name)2693 build_collating_symbol (bitset_t sbcset, const unsigned char *name) 2796 2694 # endif /* not RE_ENABLE_I18N */ 2797 re_bitset_ptr_t sbcset;2798 const unsigned char *name;2799 2695 { 2800 2696 size_t name_len = strlen ((const char *) name); … … 2813 2709 2814 2710 static bin_tree_t * 2815 parse_bracket_exp (regexp, dfa, token, syntax, err) 2816 re_string_t *regexp; 2817 re_dfa_t *dfa; 2818 re_token_t *token; 2819 reg_syntax_t syntax; 2820 reg_errcode_t *err; 2711 parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, 2712 reg_syntax_t syntax, reg_errcode_t *err) 2821 2713 { 2822 2714 #ifdef _LIBC … … 2840 2732 int32_t hash = elem_hash ((const char *) name, name_len); 2841 2733 int32_t elem = hash % table_size; 2842 int32_t second = hash % (table_size - 2); 2843 while (symb_table[2 * elem] != 0) 2844 { 2845 /* First compare the hashing value. */ 2846 if (symb_table[2 * elem] == hash 2847 /* Compare the length of the name. */ 2848 && name_len == extra[symb_table[2 * elem + 1]] 2849 /* Compare the name. */ 2850 && memcmp (name, &extra[symb_table[2 * elem + 1] + 1], 2851 name_len) == 0) 2734 if (symb_table[2 * elem] != 0) 2735 { 2736 int32_t second = hash % (table_size - 2) + 1; 2737 2738 do 2852 2739 { 2853 /* Yep, this is the entry. */ 2854 break; 2740 /* First compare the hashing value. */ 2741 if (symb_table[2 * elem] == hash 2742 /* Compare the length of the name. */ 2743 && name_len == extra[symb_table[2 * elem + 1]] 2744 /* Compare the name. */ 2745 && memcmp (name, &extra[symb_table[2 * elem + 1] + 1], 2746 name_len) == 0) 2747 { 2748 /* Yep, this is the entry. */ 2749 break; 2750 } 2751 2752 /* Next entry. */ 2753 elem += second; 2855 2754 } 2856 2857 /* Next entry. */ 2858 elem += second; 2755 while (symb_table[2 * elem] != 0); 2859 2756 } 2860 2757 return elem; … … 2938 2835 re_charset_t *mbcset; 2939 2836 int *range_alloc; 2940 re_bitset_ptr_t sbcset;2837 bitset_t sbcset; 2941 2838 bracket_elem_t *start_elem, *end_elem; 2942 2839 { … … 3021 2918 re_charset_t *mbcset; 3022 2919 int *coll_sym_alloc; 3023 re_bitset_ptr_t sbcset;2920 bitset_t sbcset; 3024 2921 const unsigned char *name; 3025 2922 { … … 3098 2995 if (MB_CUR_MAX > 1) 3099 2996 */ 3100 2997 collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC); 3101 2998 table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB); 3102 2999 symb_table = (const int32_t *) _NL_CURRENT (LC_COLLATE, … … 3106 3003 } 3107 3004 #endif 3108 sbcset = (re_bitset_ptr_t) calloc (sizeof ( unsigned int), BITSET_UINTS);3005 sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); 3109 3006 #ifdef RE_ENABLE_I18N 3110 3007 mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); … … 3217 3114 *err = build_range_exp (sbcset, 3218 3115 dfa->mb_cur_max > 1 ? mbcset : NULL, 3219 &range_alloc, &start_elem, &end_elem );3116 &range_alloc, &start_elem, &end_elem, syntax); 3220 3117 # else 3221 *err = build_range_exp (sbcset, &start_elem, &end_elem );3118 *err = build_range_exp (sbcset, &start_elem, &end_elem, syntax); 3222 3119 # endif 3223 3120 #endif /* RE_ENABLE_I18N */ … … 3316 3213 if (BE (mbc_tree == NULL, 0)) 3317 3214 goto parse_bracket_exp_espace; 3318 for (sbc_idx = 0; sbc_idx < BITSET_ UINTS; ++sbc_idx)3215 for (sbc_idx = 0; sbc_idx < BITSET_WORDS; ++sbc_idx) 3319 3216 if (sbcset[sbc_idx]) 3320 3217 break; 3321 3218 /* If there are no bits set in sbcset, there is no point 3322 3219 of having both SIMPLE_BRACKET and COMPLEX_BRACKET. */ 3323 if (sbc_idx < BITSET_ UINTS)3220 if (sbc_idx < BITSET_WORDS) 3324 3221 { 3325 3222 /* Build a tree for simple bracket. */ … … 3369 3266 3370 3267 static reg_errcode_t 3371 parse_bracket_element (elem, regexp, token, token_len, dfa, syntax, 3372 accept_hyphen) 3373 bracket_elem_t *elem; 3374 re_string_t *regexp; 3375 re_token_t *token; 3376 int token_len; 3377 re_dfa_t *dfa; 3378 reg_syntax_t syntax; 3379 int accept_hyphen; 3268 parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp, 3269 re_token_t *token, int token_len, re_dfa_t *dfa, 3270 reg_syntax_t syntax, int accept_hyphen) 3380 3271 { 3381 3272 #ifdef RE_ENABLE_I18N … … 3415 3306 3416 3307 static reg_errcode_t 3417 parse_bracket_symbol (elem, regexp, token) 3418 bracket_elem_t *elem; 3419 re_string_t *regexp; 3420 re_token_t *token; 3308 parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp, 3309 re_token_t *token) 3421 3310 { 3422 3311 unsigned char ch, delim = token->opr.c; … … 3465 3354 static reg_errcode_t 3466 3355 #ifdef RE_ENABLE_I18N 3467 build_equiv_class (sbcset, mbcset, equiv_class_alloc, name) 3468 re_charset_t *mbcset; 3469 int *equiv_class_alloc; 3356 build_equiv_class (bitset_t sbcset, re_charset_t *mbcset, 3357 int *equiv_class_alloc, const unsigned char *name) 3470 3358 #else /* not RE_ENABLE_I18N */ 3471 build_equiv_class ( sbcset,name)3359 build_equiv_class (bitset_t sbcset, const unsigned char *name) 3472 3360 #endif /* not RE_ENABLE_I18N */ 3473 re_bitset_ptr_t sbcset; 3474 const unsigned char *name; 3475 { 3476 #if defined _LIBC 3361 { 3362 #ifdef _LIBC 3477 3363 uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); 3478 3364 if (nrules != 0) … … 3560 3446 static reg_errcode_t 3561 3447 #ifdef RE_ENABLE_I18N 3562 build_charclass ( trans, sbcset, mbcset, char_class_alloc, class_name, syntax)3563 re_charset_t *mbcset; 3564 int *char_class_alloc; 3448 build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset, 3449 re_charset_t *mbcset, int *char_class_alloc, 3450 const unsigned char *class_name, reg_syntax_t syntax) 3565 3451 #else /* not RE_ENABLE_I18N */ 3566 build_charclass (trans, sbcset, class_name, syntax) 3452 build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset, 3453 const unsigned char *class_name, reg_syntax_t syntax) 3567 3454 #endif /* not RE_ENABLE_I18N */ 3568 unsigned RE_TRANSLATE_TYPE trans;3569 re_bitset_ptr_t sbcset;3570 const unsigned char *class_name;3571 reg_syntax_t syntax;3572 3455 { 3573 3456 int i; … … 3599 3482 3600 3483 #define BUILD_CHARCLASS_LOOP(ctype_func) \ 3601 for (i = 0; i < SBC_MAX; ++i) \ 3484 do { \ 3485 if (BE (trans != NULL, 0)) \ 3602 3486 { \ 3603 if (ctype_func (i)) \ 3604 { \ 3605 int ch = trans ? trans[i] : i; \ 3606 bitset_set (sbcset, ch); \ 3607 } \ 3608 } 3487 for (i = 0; i < SBC_MAX; ++i) \ 3488 if (ctype_func (i)) \ 3489 bitset_set (sbcset, trans[i]); \ 3490 } \ 3491 else \ 3492 { \ 3493 for (i = 0; i < SBC_MAX; ++i) \ 3494 if (ctype_func (i)) \ 3495 bitset_set (sbcset, i); \ 3496 } \ 3497 } while (0) 3609 3498 3610 3499 if (strcmp (name, "alnum") == 0) 3611 BUILD_CHARCLASS_LOOP (isalnum) 3500 BUILD_CHARCLASS_LOOP (isalnum); 3612 3501 else if (strcmp (name, "cntrl") == 0) 3613 BUILD_CHARCLASS_LOOP (iscntrl) 3502 BUILD_CHARCLASS_LOOP (iscntrl); 3614 3503 else if (strcmp (name, "lower") == 0) 3615 BUILD_CHARCLASS_LOOP (islower) 3504 BUILD_CHARCLASS_LOOP (islower); 3616 3505 else if (strcmp (name, "space") == 0) 3617 BUILD_CHARCLASS_LOOP (isspace) 3506 BUILD_CHARCLASS_LOOP (isspace); 3618 3507 else if (strcmp (name, "alpha") == 0) 3619 BUILD_CHARCLASS_LOOP (isalpha) 3508 BUILD_CHARCLASS_LOOP (isalpha); 3620 3509 else if (strcmp (name, "digit") == 0) 3621 BUILD_CHARCLASS_LOOP (isdigit) 3510 BUILD_CHARCLASS_LOOP (isdigit); 3622 3511 else if (strcmp (name, "print") == 0) 3623 BUILD_CHARCLASS_LOOP (isprint) 3512 BUILD_CHARCLASS_LOOP (isprint); 3624 3513 else if (strcmp (name, "upper") == 0) 3625 BUILD_CHARCLASS_LOOP (isupper) 3514 BUILD_CHARCLASS_LOOP (isupper); 3626 3515 else if (strcmp (name, "blank") == 0) 3627 BUILD_CHARCLASS_LOOP (isblank) 3516 BUILD_CHARCLASS_LOOP (isblank); 3628 3517 else if (strcmp (name, "graph") == 0) 3629 BUILD_CHARCLASS_LOOP (isgraph) 3518 BUILD_CHARCLASS_LOOP (isgraph); 3630 3519 else if (strcmp (name, "punct") == 0) 3631 BUILD_CHARCLASS_LOOP (ispunct) 3520 BUILD_CHARCLASS_LOOP (ispunct); 3632 3521 else if (strcmp (name, "xdigit") == 0) 3633 BUILD_CHARCLASS_LOOP (isxdigit) 3522 BUILD_CHARCLASS_LOOP (isxdigit); 3634 3523 else 3635 3524 return REG_ECTYPE; … … 3639 3528 3640 3529 static bin_tree_t * 3641 build_charclass_op (dfa, trans, class_name, extra, non_match, err) 3642 re_dfa_t *dfa; 3643 unsigned RE_TRANSLATE_TYPE trans; 3644 const unsigned char *class_name; 3645 const unsigned char *extra; 3646 int non_match; 3647 reg_errcode_t *err; 3530 build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans, 3531 const unsigned char *class_name, 3532 const unsigned char *extra, int non_match, 3533 reg_errcode_t *err) 3648 3534 { 3649 3535 re_bitset_ptr_t sbcset; … … 3656 3542 bin_tree_t *tree; 3657 3543 3658 sbcset = (re_bitset_ptr_t) calloc (sizeof ( unsigned int), BITSET_UINTS);3544 sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); 3659 3545 #ifdef RE_ENABLE_I18N 3660 3546 mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); … … 3759 3645 3760 3646 static int 3761 fetch_number (input, token, syntax) 3762 re_string_t *input; 3763 re_token_t *token; 3764 reg_syntax_t syntax; 3647 fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) 3765 3648 { 3766 3649 int num = -1; … … 3804 3687 3805 3688 static bin_tree_t * 3806 create_tree (dfa, left, right, type) 3807 re_dfa_t *dfa; 3808 bin_tree_t *left; 3809 bin_tree_t *right; 3810 re_token_type_t type; 3689 create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, 3690 re_token_type_t type) 3811 3691 { 3812 3692 re_token_t t; … … 3816 3696 3817 3697 static bin_tree_t * 3818 create_token_tree (dfa, left, right, token) 3819 re_dfa_t *dfa; 3820 bin_tree_t *left; 3821 bin_tree_t *right; 3822 const re_token_t *token; 3698 create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, 3699 const re_token_t *token) 3823 3700 { 3824 3701 bin_tree_t *tree; … … 3856 3733 3857 3734 static reg_errcode_t 3858 mark_opt_subexp (extra, node) 3859 void *extra; 3860 bin_tree_t *node; 3735 mark_opt_subexp (void *extra, bin_tree_t *node) 3861 3736 { 3862 3737 int idx = (int) (long) extra; … … 3898 3773 3899 3774 static bin_tree_t * 3900 duplicate_tree (root, dfa) 3901 const bin_tree_t *root; 3902 re_dfa_t *dfa; 3775 duplicate_tree (const bin_tree_t *root, re_dfa_t *dfa) 3903 3776 { 3904 3777 const bin_tree_t *node; -
branches/libc-0.6/src/emx/src/lib/lgpl/posix/regex.c
r2240 r3058 1 1 /* Extended regular expression matching and search library. 2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.2 Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. 3 3 This file is part of the GNU C Library. 4 4 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. … … 23 23 #endif 24 24 25 #define RE_ENABLE_I18N 1 26 27 /* BSD 4.2, not delcared in the header */ 28 char * re_comp (const char *); 29 int re_exec (const char *); 30 31 32 #ifdef _AIX 33 #pragma alloca 34 #else 35 # ifndef allocax /* predefined by HP cc +Olibcalls */ 36 # ifdef __GNUC__ 37 # define alloca(size) __builtin_alloca (size) 38 # else 39 # if HAVE_ALLOCA_H 40 # include <alloca.h> 41 # else 42 # ifdef __hpux 43 void *alloca (); 44 # else 45 # if !defined __OS2__ && !defined WIN32 46 char *alloca (); 47 # else 48 # include <malloc.h> /* OS/2 defines alloca in here */ 49 # endif 50 # endif 51 # endif 52 # endif 53 # endif 25 /* Make sure noone compiles this code with a C++ compiler. */ 26 #ifdef __cplusplus 27 # error "This is C code, use a C compiler" 54 28 #endif 55 29 … … 79 53 #endif 80 54 81 /* POSIX says that <sys/types.h> must be included (by the caller) before82 <regex.h>. */83 #include <sys/types.h>84 85 55 /* On some systems, limits.h sets RE_DUP_MAX to a lower value than 86 56 GNU regex allows. Include it before <regex.h>, which correctly … … 96 66 97 67 /* Binary backward compatibility. */ 98 #if defined _LIBC &&_LIBC68 #if _LIBC 99 69 # include <shlib-compat.h> 100 70 # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3) -
branches/libc-0.6/src/emx/src/lib/lgpl/posix/regex_internal.c
r2240 r3058 1 1 /* Extended regular expression matching and search library. 2 Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.2 Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 3 3 This file is part of the GNU C Library. 4 4 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. … … 23 23 RE_TRANSLATE_TYPE trans, int icase, 24 24 const re_dfa_t *dfa) internal_function; 25 #ifdef RE_ENABLE_I18N 26 static int re_string_skip_chars (re_string_t *pstr, int new_raw_idx, 27 wint_t *last_wc) internal_function; 28 #endif /* RE_ENABLE_I18N */ 29 static reg_errcode_t register_state (re_dfa_t *dfa, re_dfastate_t *newstate, 30 unsigned int hash) internal_function; 31 static re_dfastate_t *create_ci_newstate (re_dfa_t *dfa, 25 static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa, 32 26 const re_node_set *nodes, 33 27 unsigned int hash) internal_function; 34 static re_dfastate_t *create_cd_newstate ( re_dfa_t *dfa,28 static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa, 35 29 const re_node_set *nodes, 36 30 unsigned int context, 37 31 unsigned int hash) internal_function; 38 static unsigned int inline calc_state_hash (const re_node_set *nodes,39 unsigned int context) internal_function;40 32 41 33 … … 46 38 47 39 static reg_errcode_t 48 re_string_allocate (pstr, str, len, init_len, trans, icase, dfa) 49 re_string_t *pstr; 50 const char *str; 51 int len, init_len, icase; 52 RE_TRANSLATE_TYPE trans; 53 const re_dfa_t *dfa; 40 internal_function 41 re_string_allocate (re_string_t *pstr, const char *str, int len, int init_len, 42 RE_TRANSLATE_TYPE trans, int icase, const re_dfa_t *dfa) 54 43 { 55 44 reg_errcode_t ret; … … 77 66 78 67 static reg_errcode_t 79 re_string_construct (pstr, str, len, trans, icase, dfa) 80 re_string_t *pstr; 81 const char *str; 82 int len, icase; 83 RE_TRANSLATE_TYPE trans; 84 const re_dfa_t *dfa; 68 internal_function 69 re_string_construct (re_string_t *pstr, const char *str, int len, 70 RE_TRANSLATE_TYPE trans, int icase, const re_dfa_t *dfa) 85 71 { 86 72 reg_errcode_t ret; … … 143 129 144 130 static reg_errcode_t 145 re_string_realloc_buffers (pstr, new_buf_len) 146 re_string_t *pstr; 147 int new_buf_len; 131 internal_function 132 re_string_realloc_buffers (re_string_t *pstr, int new_buf_len) 148 133 { 149 134 #ifdef RE_ENABLE_I18N 150 135 if (pstr->mb_cur_max > 1) 151 136 { 152 wint_t *new_ array= re_realloc (pstr->wcs, wint_t, new_buf_len);153 if (BE (new_ array== NULL, 0))137 wint_t *new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len); 138 if (BE (new_wcs == NULL, 0)) 154 139 return REG_ESPACE; 155 pstr->wcs = new_ array;140 pstr->wcs = new_wcs; 156 141 if (pstr->offsets != NULL) 157 142 { 158 int *new_ array= re_realloc (pstr->offsets, int, new_buf_len);159 if (BE (new_ array== NULL, 0))143 int *new_offsets = re_realloc (pstr->offsets, int, new_buf_len); 144 if (BE (new_offsets == NULL, 0)) 160 145 return REG_ESPACE; 161 pstr->offsets = new_ array;146 pstr->offsets = new_offsets; 162 147 } 163 148 } … … 165 150 if (pstr->mbs_allocated) 166 151 { 167 unsigned char *new_ array= re_realloc (pstr->mbs, unsigned char,168 169 if (BE (new_ array== NULL, 0))152 unsigned char *new_mbs = re_realloc (pstr->mbs, unsigned char, 153 new_buf_len); 154 if (BE (new_mbs == NULL, 0)) 170 155 return REG_ESPACE; 171 pstr->mbs = new_ array;156 pstr->mbs = new_mbs; 172 157 } 173 158 pstr->bufs_len = new_buf_len; … … 177 162 178 163 static void 179 re_string_construct_common (str, len, pstr, trans, icase, dfa) 180 const char *str; 181 int len; 182 re_string_t *pstr; 183 RE_TRANSLATE_TYPE trans; 184 int icase; 185 const re_dfa_t *dfa; 164 internal_function 165 re_string_construct_common (const char *str, int len, re_string_t *pstr, 166 RE_TRANSLATE_TYPE trans, int icase, 167 const re_dfa_t *dfa) 186 168 { 187 169 pstr->raw_mbs = (const unsigned char *) str; 188 170 pstr->len = len; 189 171 pstr->raw_len = len; 190 pstr->trans = (unsigned RE_TRANSLATE_TYPE)trans;172 pstr->trans = trans; 191 173 pstr->icase = icase ? 1 : 0; 192 174 pstr->mbs_allocated = (trans != NULL || icase); … … 212 194 213 195 static void 214 build_wcs_buffer (pstr) 215 re_string_t *pstr; 196 internal_function 197 build_wcs_buffer (re_string_t *pstr) 216 198 { 217 199 #ifdef _LIBC … … 279 261 but for REG_ICASE. */ 280 262 281 static int282 build_wcs_upper_buffer (pstr) 283 re_string_t *pstr; 263 static reg_errcode_t 264 internal_function 265 build_wcs_upper_buffer (re_string_t *pstr) 284 266 { 285 267 mbstate_t prev_st; … … 496 478 497 479 static int 498 re_string_skip_chars (pstr, new_raw_idx, last_wc) 499 re_string_t *pstr; 500 int new_raw_idx; 501 wint_t *last_wc; 480 internal_function 481 re_string_skip_chars (re_string_t *pstr, int new_raw_idx, wint_t *last_wc) 502 482 { 503 483 mbstate_t prev_st; 504 484 int rawbuf_idx; 505 485 size_t mbclen; 506 wchar_t wc = 0;486 wchar_t wc = WEOF; 507 487 508 488 /* Skip the characters which are not necessary to check. */ … … 517 497 if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0)) 518 498 { 519 /* We treat these cases as a singlebyte character. */ 499 /* We treat these cases as a single byte character. */ 500 if (mbclen == 0 || remain_len == 0) 501 wc = L'\0'; 502 else 503 wc = *(unsigned char *) (pstr->raw_mbs + rawbuf_idx); 520 504 mbclen = 1; 521 505 pstr->cur_state = prev_st; … … 533 517 534 518 static void 535 build_upper_buffer (pstr) 536 re_string_t *pstr; 519 internal_function 520 build_upper_buffer (re_string_t *pstr) 537 521 { 538 522 int char_idx, end_idx; … … 556 540 557 541 static void 558 re_string_translate_buffer (pstr) 559 re_string_t *pstr; 542 internal_function 543 re_string_translate_buffer (re_string_t *pstr) 560 544 { 561 545 int buf_idx, end_idx; … … 577 561 578 562 static reg_errcode_t 579 re_string_reconstruct (pstr, idx, eflags) 580 re_string_t *pstr; 581 int idx, eflags; 563 internal_function 564 re_string_reconstruct (re_string_t *pstr, int idx, int eflags) 582 565 { 583 566 int offset = idx - pstr->raw_mbs_idx; … … 604 587 if (BE (offset != 0, 1)) 605 588 { 606 /* Are the characters which are already checked remain? */ 607 if (BE (offset < pstr->valid_raw_len, 1) 608 #ifdef RE_ENABLE_I18N 609 /* Handling this would enlarge the code too much. 610 Accept a slowdown in that case. */ 611 && pstr->offsets_needed == 0 589 /* Should the already checked characters be kept? */ 590 if (BE (offset < pstr->valid_raw_len, 1)) 591 { 592 /* Yes, move them to the front of the buffer. */ 593 #ifdef RE_ENABLE_I18N 594 if (BE (pstr->offsets_needed, 0)) 595 { 596 int low = 0, high = pstr->valid_len, mid; 597 do 598 { 599 mid = (high + low) / 2; 600 if (pstr->offsets[mid] > offset) 601 high = mid; 602 else if (pstr->offsets[mid] < offset) 603 low = mid + 1; 604 else 605 break; 606 } 607 while (low < high); 608 if (pstr->offsets[mid] < offset) 609 ++mid; 610 pstr->tip_context = re_string_context_at (pstr, mid - 1, 611 eflags); 612 /* This can be quite complicated, so handle specially 613 only the common and easy case where the character with 614 different length representation of lower and upper 615 case is present at or after offset. */ 616 if (pstr->valid_len > offset 617 && mid == offset && pstr->offsets[mid] == offset) 618 { 619 memmove (pstr->wcs, pstr->wcs + offset, 620 (pstr->valid_len - offset) * sizeof (wint_t)); 621 memmove (pstr->mbs, pstr->mbs + offset, pstr->valid_len - offset); 622 pstr->valid_len -= offset; 623 pstr->valid_raw_len -= offset; 624 for (low = 0; low < pstr->valid_len; low++) 625 pstr->offsets[low] = pstr->offsets[low + offset] - offset; 626 } 627 else 628 { 629 /* Otherwise, just find out how long the partial multibyte 630 character at offset is and fill it with WEOF/255. */ 631 pstr->len = pstr->raw_len - idx + offset; 632 pstr->stop = pstr->raw_stop - idx + offset; 633 pstr->offsets_needed = 0; 634 while (mid > 0 && pstr->offsets[mid - 1] == offset) 635 --mid; 636 while (mid < pstr->valid_len) 637 if (pstr->wcs[mid] != WEOF) 638 break; 639 else 640 ++mid; 641 if (mid == pstr->valid_len) 642 pstr->valid_len = 0; 643 else 644 { 645 pstr->valid_len = pstr->offsets[mid] - offset; 646 if (pstr->valid_len) 647 { 648 for (low = 0; low < pstr->valid_len; ++low) 649 pstr->wcs[low] = WEOF; 650 memset (pstr->mbs, 255, pstr->valid_len); 651 } 652 } 653 pstr->valid_raw_len = pstr->valid_len; 654 } 655 } 656 else 612 657 #endif 613 ) 614 { 615 /* Yes, move them to the front of the buffer. */ 616 pstr->tip_context = re_string_context_at (pstr, offset - 1, eflags); 617 #ifdef RE_ENABLE_I18N 618 if (pstr->mb_cur_max > 1) 619 memmove (pstr->wcs, pstr->wcs + offset, 620 (pstr->valid_len - offset) * sizeof (wint_t)); 658 { 659 pstr->tip_context = re_string_context_at (pstr, offset - 1, 660 eflags); 661 #ifdef RE_ENABLE_I18N 662 if (pstr->mb_cur_max > 1) 663 memmove (pstr->wcs, pstr->wcs + offset, 664 (pstr->valid_len - offset) * sizeof (wint_t)); 621 665 #endif /* RE_ENABLE_I18N */ 622 if (BE (pstr->mbs_allocated, 0))623 624 625 pstr->valid_len -= offset;626 pstr->valid_raw_len -= offset;627 #if def DEBUG //bird628 assert (pstr->valid_len > 0);666 if (BE (pstr->mbs_allocated, 0)) 667 memmove (pstr->mbs, pstr->mbs + offset, 668 pstr->valid_len - offset); 669 pstr->valid_len -= offset; 670 pstr->valid_raw_len -= offset; 671 #if DEBUG 672 assert (pstr->valid_len > 0); 629 673 #endif 674 } 630 675 } 631 676 else 632 677 { 633 678 /* No, skip all characters until IDX. */ 679 int prev_valid_len = pstr->valid_len; 680 634 681 #ifdef RE_ENABLE_I18N 635 682 if (BE (pstr->offsets_needed, 0)) … … 641 688 #endif 642 689 pstr->valid_len = 0; 643 pstr->valid_raw_len = 0;644 690 #ifdef RE_ENABLE_I18N 645 691 if (pstr->mb_cur_max > 1) … … 656 702 raw = pstr->raw_mbs + pstr->raw_mbs_idx; 657 703 end = raw + (offset - pstr->mb_cur_max); 658 for (p = raw + offset - 1; p >= end; --p) 659 if ((*p & 0xc0) != 0x80) 660 { 661 mbstate_t cur_state; 662 wchar_t wc2; 663 int mlen = raw + pstr->len - p; 664 unsigned char buf[6]; 665 666 q = p; 667 if (BE (pstr->trans != NULL, 0)) 668 { 669 int i = mlen < 6 ? mlen : 6; 670 while (--i >= 0) 671 buf[i] = pstr->trans[p[i]]; 672 q = buf; 673 } 674 /* XXX Don't use mbrtowc, we know which conversion 675 to use (UTF-8 -> UCS4). */ 676 memset (&cur_state, 0, sizeof (cur_state)); 677 mlen = (mbrtowc (&wc2, (const char *) p, mlen, 678 &cur_state) 679 - (raw + offset - p)); 680 if (mlen >= 0) 681 { 682 memset (&pstr->cur_state, '\0', 683 sizeof (mbstate_t)); 684 pstr->valid_len = mlen; 685 wc = wc2; 686 } 687 break; 688 } 704 if (end < pstr->raw_mbs) 705 end = pstr->raw_mbs; 706 p = raw + offset - 1; 707 #ifdef _LIBC 708 /* We know the wchar_t encoding is UCS4, so for the simple 709 case, ASCII characters, skip the conversion step. */ 710 if (isascii (*p) && BE (pstr->trans == NULL, 1)) 711 { 712 memset (&pstr->cur_state, '\0', sizeof (mbstate_t)); 713 /* pstr->valid_len = 0; */ 714 wc = (wchar_t) *p; 715 } 716 else 717 #endif 718 for (; p >= end; --p) 719 if ((*p & 0xc0) != 0x80) 720 { 721 mbstate_t cur_state; 722 wchar_t wc2; 723 int mlen = raw + pstr->len - p; 724 unsigned char buf[6]; 725 size_t mbclen; 726 727 q = p; 728 if (BE (pstr->trans != NULL, 0)) 729 { 730 int i = mlen < 6 ? mlen : 6; 731 while (--i >= 0) 732 buf[i] = pstr->trans[p[i]]; 733 q = buf; 734 } 735 /* XXX Don't use mbrtowc, we know which conversion 736 to use (UTF-8 -> UCS4). */ 737 memset (&cur_state, 0, sizeof (cur_state)); 738 mbclen = mbrtowc (&wc2, (const char *) p, mlen, 739 &cur_state); 740 if (raw + offset - p <= mbclen 741 && mbclen < (size_t) -2) 742 { 743 memset (&pstr->cur_state, '\0', 744 sizeof (mbstate_t)); 745 pstr->valid_len = mbclen - (raw + offset - p); 746 wc = wc2; 747 } 748 break; 749 } 689 750 } 690 751 691 752 if (wc == WEOF) 692 753 pstr->valid_len = re_string_skip_chars (pstr, idx, &wc) - idx; 754 if (wc == WEOF) 755 pstr->tip_context 756 = re_string_context_at (pstr, prev_valid_len - 1, eflags); 757 else 758 pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0) 759 && IS_WIDE_WORD_CHAR (wc)) 760 ? CONTEXT_WORD 761 : ((IS_WIDE_NEWLINE (wc) 762 && pstr->newline_anchor) 763 ? CONTEXT_NEWLINE : 0)); 693 764 if (BE (pstr->valid_len, 0)) 694 765 { … … 699 770 } 700 771 pstr->valid_raw_len = pstr->valid_len; 701 pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0)702 && IS_WIDE_WORD_CHAR (wc))703 ? CONTEXT_WORD704 : ((IS_WIDE_NEWLINE (wc)705 && pstr->newline_anchor)706 ? CONTEXT_NEWLINE : 0));707 772 } 708 773 else … … 710 775 { 711 776 int c = pstr->raw_mbs[pstr->raw_mbs_idx + offset - 1]; 777 pstr->valid_raw_len = 0; 712 778 if (pstr->trans) 713 779 c = pstr->trans[c]; … … 731 797 if (pstr->icase) 732 798 { 733 int ret = build_wcs_upper_buffer (pstr);799 reg_errcode_t ret = build_wcs_upper_buffer (pstr); 734 800 if (BE (ret != REG_NOERROR, 0)) 735 801 return ret; … … 740 806 else 741 807 #endif /* RE_ENABLE_I18N */ 742 if (BE (pstr->mbs_allocated, 0))743 {744 745 build_upper_buffer (pstr);746 747 re_string_translate_buffer (pstr);748 }749 else750 pstr->valid_len = pstr->len;808 if (BE (pstr->mbs_allocated, 0)) 809 { 810 if (pstr->icase) 811 build_upper_buffer (pstr); 812 else if (pstr->trans != NULL) 813 re_string_translate_buffer (pstr); 814 } 815 else 816 pstr->valid_len = pstr->len; 751 817 752 818 pstr->cur_idx = 0; … … 755 821 756 822 static unsigned char 757 re_string_peek_byte_case (pstr, idx) 758 const re_string_t *pstr; 759 int idx; 823 internal_function __attribute ((pure)) 824 re_string_peek_byte_case (const re_string_t *pstr, int idx) 760 825 { 761 826 int ch, off; … … 792 857 793 858 static unsigned char 794 re_string_fetch_byte_case (pstr)795 re_string_t *pstr; 859 internal_function __attribute ((pure)) 860 re_string_fetch_byte_case (re_string_t *pstr) 796 861 { 797 862 if (BE (!pstr->mbs_allocated, 1)) … … 829 894 830 895 static void 831 re_string_destruct (pstr) 832 re_string_t *pstr; 896 internal_function 897 re_string_destruct (re_string_t *pstr) 833 898 { 834 899 #ifdef RE_ENABLE_I18N … … 843 908 844 909 static unsigned int 845 re_string_context_at (input, idx, eflags) 846 const re_string_t *input; 847 int idx, eflags; 910 internal_function 911 re_string_context_at (const re_string_t *input, int idx, int eflags) 848 912 { 849 913 int c; … … 890 954 891 955 static reg_errcode_t 892 re_node_set_alloc (set, size) 893 re_node_set *set; 894 int size; 956 internal_function 957 re_node_set_alloc (re_node_set *set, int size) 895 958 { 896 959 set->alloc = size; … … 903 966 904 967 static reg_errcode_t 905 re_node_set_init_1 (set, elem) 906 re_node_set *set; 907 int elem; 968 internal_function 969 re_node_set_init_1 (re_node_set *set, int elem) 908 970 { 909 971 set->alloc = 1; … … 920 982 921 983 static reg_errcode_t 922 re_node_set_init_2 (set, elem1, elem2) 923 re_node_set *set; 924 int elem1, elem2; 984 internal_function 985 re_node_set_init_2 (re_node_set *set, int elem1, int elem2) 925 986 { 926 987 set->alloc = 2; … … 951 1012 952 1013 static reg_errcode_t 953 re_node_set_init_copy (dest, src) 954 re_node_set *dest; 955 const re_node_set *src; 1014 internal_function 1015 re_node_set_init_copy (re_node_set *dest, const re_node_set *src) 956 1016 { 957 1017 dest->nelem = src->nelem; … … 977 1037 978 1038 static reg_errcode_t 979 re_node_set_add_intersect (dest, src1, src2) 980 re_node_set *dest; 981 const re_node_set *src1, *src2; 1039 internal_function 1040 re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1, 1041 const re_node_set *src2) 982 1042 { 983 1043 int i1, i2, is, id, delta, sbase; … … 1068 1128 1069 1129 static reg_errcode_t 1070 re_node_set_init_union (dest, src1, src2) 1071 re_node_set *dest; 1072 const re_node_set *src1, *src2; 1130 internal_function 1131 re_node_set_init_union (re_node_set *dest, const re_node_set *src1, 1132 const re_node_set *src2) 1073 1133 { 1074 1134 int i1, i2, id; … … 1121 1181 1122 1182 static reg_errcode_t 1123 re_node_set_merge (dest, src) 1124 re_node_set *dest; 1125 const re_node_set *src; 1183 internal_function 1184 re_node_set_merge (re_node_set *dest, const re_node_set *src) 1126 1185 { 1127 1186 int is, id, sbase, delta; … … 1205 1264 1206 1265 static int 1207 re_node_set_insert (set, elem) 1208 re_node_set *set; 1209 int elem; 1266 internal_function 1267 re_node_set_insert (re_node_set *set, int elem) 1210 1268 { 1211 1269 int idx; … … 1230 1288 if (set->alloc == set->nelem) 1231 1289 { 1232 int *new_ array;1290 int *new_elems; 1233 1291 set->alloc = set->alloc * 2; 1234 new_ array= re_realloc (set->elems, int, set->alloc);1235 if (BE (new_ array== NULL, 0))1292 new_elems = re_realloc (set->elems, int, set->alloc); 1293 if (BE (new_elems == NULL, 0)) 1236 1294 return -1; 1237 set->elems = new_ array;1295 set->elems = new_elems; 1238 1296 } 1239 1297 … … 1263 1321 1264 1322 static int 1265 re_node_set_insert_last (set, elem) 1266 re_node_set *set; 1267 int elem; 1323 internal_function 1324 re_node_set_insert_last (re_node_set *set, int elem) 1268 1325 { 1269 1326 /* Realloc if we need. */ 1270 1327 if (set->alloc == set->nelem) 1271 1328 { 1272 int *new_ array;1329 int *new_elems; 1273 1330 set->alloc = (set->alloc + 1) * 2; 1274 new_ array= re_realloc (set->elems, int, set->alloc);1275 if (BE (new_ array== NULL, 0))1331 new_elems = re_realloc (set->elems, int, set->alloc); 1332 if (BE (new_elems == NULL, 0)) 1276 1333 return -1; 1277 set->elems = new_ array;1334 set->elems = new_elems; 1278 1335 } 1279 1336 … … 1287 1344 1288 1345 static int 1289 re_node_set_compare (set1, set2)1290 const re_node_set *set1, *set2; 1346 internal_function __attribute ((pure)) 1347 re_node_set_compare (const re_node_set *set1, const re_node_set *set2) 1291 1348 { 1292 1349 int i; … … 1302 1359 1303 1360 static int 1304 re_node_set_contains (set, elem) 1305 const re_node_set *set; 1306 int elem; 1361 internal_function __attribute ((pure)) 1362 re_node_set_contains (const re_node_set *set, int elem) 1307 1363 { 1308 1364 unsigned int idx, right, mid; … … 1325 1381 1326 1382 static void 1327 re_node_set_remove_at (set, idx) 1328 re_node_set *set; 1329 int idx; 1383 internal_function 1384 re_node_set_remove_at (re_node_set *set, int idx) 1330 1385 { 1331 1386 if (idx < 0 || idx >= set->nelem) … … 1342 1397 1343 1398 static int 1344 re_dfa_add_node (dfa, token) 1345 re_dfa_t *dfa; 1346 re_token_t token; 1347 { 1348 #ifdef RE_ENABLE_I18N //bird 1399 internal_function 1400 re_dfa_add_node (re_dfa_t *dfa, re_token_t token) 1401 { 1349 1402 int type = token.type; 1350 #endif1351 1403 if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0)) 1352 1404 { 1353 int new_nodes_alloc = dfa->nodes_alloc * 2;1405 size_t new_nodes_alloc = dfa->nodes_alloc * 2; 1354 1406 int *new_nexts, *new_indices; 1355 1407 re_node_set *new_edests, *new_eclosures; 1356 1357 re_token_t *new_array = re_realloc (dfa->nodes, re_token_t, 1358 new_nodes_alloc); 1359 if (BE (new_ array == NULL, 0))1408 re_token_t *new_nodes; 1409 1410 /* Avoid overflows. */ 1411 if (BE (new_nodes_alloc < dfa->nodes_alloc, 0)) 1360 1412 return -1; 1361 dfa->nodes = new_array; 1413 1414 new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc); 1415 if (BE (new_nodes == NULL, 0)) 1416 return -1; 1417 dfa->nodes = new_nodes; 1362 1418 new_nexts = re_realloc (dfa->nexts, int, new_nodes_alloc); 1363 1419 new_indices = re_realloc (dfa->org_indices, int, new_nodes_alloc); … … 1385 1441 } 1386 1442 1387 static unsigned int inline 1388 calc_state_hash (nodes, context) 1389 const re_node_set *nodes; 1390 unsigned int context; 1443 static inline unsigned int 1444 internal_function 1445 calc_state_hash (const re_node_set *nodes, unsigned int context) 1391 1446 { 1392 1447 unsigned int hash = nodes->nelem + context; … … 1406 1461 optimization. */ 1407 1462 1408 static re_dfastate_t* 1409 re_acquire_state (err, dfa, nodes) 1410 reg_errcode_t *err; 1411 re_dfa_t *dfa; 1412 const re_node_set *nodes; 1463 static re_dfastate_t * 1464 internal_function 1465 re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa, 1466 const re_node_set *nodes) 1413 1467 { 1414 1468 unsigned int hash; … … 1435 1489 /* There are no appropriate state in the dfa, create the new one. */ 1436 1490 new_state = create_ci_newstate (dfa, nodes, hash); 1437 if (BE (new_state != NULL, 1)) 1438 return new_state; 1439 else 1440 { 1441 *err = REG_ESPACE; 1442 return NULL; 1443 } 1491 if (BE (new_state == NULL, 0)) 1492 *err = REG_ESPACE; 1493 1494 return new_state; 1444 1495 } 1445 1496 … … 1454 1505 optimization. */ 1455 1506 1456 static re_dfastate_t* 1457 re_acquire_state_context (err, dfa, nodes, context) 1458 reg_errcode_t *err; 1459 re_dfa_t *dfa; 1460 const re_node_set *nodes; 1461 unsigned int context; 1507 static re_dfastate_t * 1508 internal_function 1509 re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa, 1510 const re_node_set *nodes, unsigned int context) 1462 1511 { 1463 1512 unsigned int hash; … … 1483 1532 /* There are no appropriate state in `dfa', create the new one. */ 1484 1533 new_state = create_cd_newstate (dfa, nodes, context, hash); 1485 if (BE (new_state != NULL, 1)) 1486 return new_state; 1487 else 1488 { 1489 *err = REG_ESPACE; 1490 return NULL; 1491 } 1534 if (BE (new_state == NULL, 0)) 1535 *err = REG_ESPACE; 1536 1537 return new_state; 1492 1538 } 1493 1539 … … 1497 1543 1498 1544 static reg_errcode_t 1499 register_state (dfa, newstate, hash) 1500 re_dfa_t *dfa; 1501 re_dfastate_t *newstate; 1502 unsigned int hash; 1545 register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, 1546 unsigned int hash) 1503 1547 { 1504 1548 struct re_state_table_entry *spot; … … 1532 1576 } 1533 1577 1578 static void 1579 free_state (re_dfastate_t *state) 1580 { 1581 re_node_set_free (&state->non_eps_nodes); 1582 re_node_set_free (&state->inveclosure); 1583 if (state->entrance_nodes != &state->nodes) 1584 { 1585 re_node_set_free (state->entrance_nodes); 1586 re_free (state->entrance_nodes); 1587 } 1588 re_node_set_free (&state->nodes); 1589 re_free (state->word_trtable); 1590 re_free (state->trtable); 1591 re_free (state); 1592 } 1593 1534 1594 /* Create the new state which is independ of contexts. 1535 1595 Return the new state if succeeded, otherwise return NULL. */ 1536 1596 1537 1597 static re_dfastate_t * 1538 create_ci_newstate (dfa, nodes, hash) 1539 re_dfa_t *dfa; 1540 const re_node_set *nodes; 1541 unsigned int hash; 1598 internal_function 1599 create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes, 1600 unsigned int hash) 1542 1601 { 1543 1602 int i; … … 1587 1646 1588 1647 static re_dfastate_t * 1589 create_cd_newstate (dfa, nodes, context, hash) 1590 re_dfa_t *dfa; 1591 const re_node_set *nodes; 1592 unsigned int context, hash; 1648 internal_function 1649 create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes, 1650 unsigned int context, unsigned int hash) 1593 1651 { 1594 1652 int i, nctx_nodes = 0; … … 1661 1719 return newstate; 1662 1720 } 1663 1664 static void1665 free_state (state)1666 re_dfastate_t *state;1667 {1668 re_node_set_free (&state->non_eps_nodes);1669 re_node_set_free (&state->inveclosure);1670 if (state->entrance_nodes != &state->nodes)1671 {1672 re_node_set_free (state->entrance_nodes);1673 re_free (state->entrance_nodes);1674 }1675 re_node_set_free (&state->nodes);1676 re_free (state->word_trtable);1677 re_free (state->trtable);1678 re_free (state);1679 } -
branches/libc-0.6/src/emx/src/lib/lgpl/posix/regex_internal.h
r2240 r3058 40 40 # include <wctype.h> 41 41 #endif /* HAVE_WCTYPE_H || _LIBC */ 42 #if defined HAVE_STDBOOL_H || defined _LIBC 43 # include <stdbool.h> 44 #endif /* HAVE_STDBOOL_H || _LIBC */ 45 #if defined HAVE_STDINT_H || defined _LIBC 46 # include <stdint.h> 47 #endif /* HAVE_STDINT_H || _LIBC */ 42 48 #if defined _LIBC || defined __INNOTEK_LIBC__ 43 49 # include <bits/libc-lock.h> … … 81 87 #endif 82 88 89 /* For loser systems without the definition. */ 90 #ifndef SIZE_MAX 91 # define SIZE_MAX ((size_t) -1) 92 #endif 93 83 94 #ifndef __INNOTEK_LIBC__ 84 95 #if (defined MB_CUR_MAX && HAVE_LOCALE_H && HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_WCRTOMB && HAVE_MBRTOWC && HAVE_WCSCOLL) || _LIBC 85 96 # define RE_ENABLE_I18N 86 97 #endif 87 #endif 98 #else 99 #endif 100 #define RE_ENABLE_I18N 88 101 89 102 #if __GNUC__ >= 3 … … 94 107 #endif 95 108 96 /* Number of bits in a byte. */97 #define BYTE_BITS 898 109 /* Number of single byte character. */ 99 110 #define SBC_MAX 256 … … 125 136 extern const size_t __re_error_msgid_idx[] attribute_hidden; 126 137 127 /* Number of bits in an unsinged int. */ 128 #define UINT_BITS (sizeof (unsigned int) * BYTE_BITS) 129 /* Number of unsigned int in an bit_set. */ 130 #define BITSET_UINTS ((SBC_MAX + UINT_BITS - 1) / UINT_BITS) 131 typedef unsigned int bitset[BITSET_UINTS]; 132 typedef unsigned int *re_bitset_ptr_t; 133 typedef const unsigned int *re_const_bitset_ptr_t; 134 135 #define bitset_set(set,i) (set[i / UINT_BITS] |= 1 << i % UINT_BITS) 136 #define bitset_clear(set,i) (set[i / UINT_BITS] &= ~(1 << i % UINT_BITS)) 137 #define bitset_contain(set,i) (set[i / UINT_BITS] & (1 << i % UINT_BITS)) 138 #define bitset_empty(set) memset (set, 0, sizeof (unsigned int) * BITSET_UINTS) 139 #define bitset_set_all(set) \ 140 memset (set, 255, sizeof (unsigned int) * BITSET_UINTS) 141 #define bitset_copy(dest,src) \ 142 memcpy (dest, src, sizeof (unsigned int) * BITSET_UINTS) 143 static inline void bitset_not (bitset set); 144 static inline void bitset_merge (bitset dest, const bitset src); 145 static inline void bitset_not_merge (bitset dest, const bitset src); 146 static inline void bitset_mask (bitset dest, const bitset src); 138 /* An integer used to represent a set of bits. It must be unsigned, 139 and must be at least as wide as unsigned int. */ 140 typedef unsigned long int bitset_word_t; 141 /* All bits set in a bitset_word_t. */ 142 #define BITSET_WORD_MAX ULONG_MAX 143 /* Number of bits in a bitset_word_t. */ 144 #define BITSET_WORD_BITS (sizeof (bitset_word_t) * CHAR_BIT) 145 /* Number of bitset_word_t in a bit_set. */ 146 #define BITSET_WORDS (SBC_MAX / BITSET_WORD_BITS) 147 typedef bitset_word_t bitset_t[BITSET_WORDS]; 148 typedef bitset_word_t *re_bitset_ptr_t; 149 typedef const bitset_word_t *re_const_bitset_ptr_t; 150 151 #define bitset_set(set,i) \ 152 (set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS) 153 #define bitset_clear(set,i) \ 154 (set[i / BITSET_WORD_BITS] &= ~((bitset_word_t) 1 << i % BITSET_WORD_BITS)) 155 #define bitset_contain(set,i) \ 156 (set[i / BITSET_WORD_BITS] & ((bitset_word_t) 1 << i % BITSET_WORD_BITS)) 157 #define bitset_empty(set) memset (set, '\0', sizeof (bitset_t)) 158 #define bitset_set_all(set) memset (set, '\xff', sizeof (bitset_t)) 159 #define bitset_copy(dest,src) memcpy (dest, src, sizeof (bitset_t)) 147 160 148 161 #define PREV_WORD_CONSTRAINT 0x0001 … … 350 363 unsigned int tip_context; 351 364 /* The translation passed as a part of an argument of re_compile_pattern. */ 352 unsignedRE_TRANSLATE_TYPE trans;365 RE_TRANSLATE_TYPE trans; 353 366 /* Copy of re_dfa_t's word_char. */ 354 367 re_const_bitset_ptr_t word_char; … … 377 390 #endif 378 391 379 #ifndef RE_NO_INTERNAL_PROTOTYPES380 static reg_errcode_t re_string_allocate (re_string_t *pstr, const char *str,381 int len, int init_len,382 RE_TRANSLATE_TYPE trans, int icase,383 const re_dfa_t *dfa)384 internal_function;385 static reg_errcode_t re_string_construct (re_string_t *pstr, const char *str,386 int len, RE_TRANSLATE_TYPE trans,387 int icase, const re_dfa_t *dfa)388 internal_function;389 static reg_errcode_t re_string_reconstruct (re_string_t *pstr, int idx,390 int eflags) internal_function;391 392 static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr, 392 393 int new_buf_len) 393 394 internal_function; 394 # 395 #ifdef RE_ENABLE_I18N 395 396 static void build_wcs_buffer (re_string_t *pstr) internal_function; 396 397 static int build_wcs_upper_buffer (re_string_t *pstr) internal_function; 397 # 398 #endif /* RE_ENABLE_I18N */ 398 399 static void build_upper_buffer (re_string_t *pstr) internal_function; 399 400 static void re_string_translate_buffer (re_string_t *pstr) internal_function; 400 static void re_string_destruct (re_string_t *pstr) internal_function;401 # ifdef RE_ENABLE_I18N402 static int re_string_elem_size_at (const re_string_t *pstr, int idx)403 internal_function __attribute ((pure));404 static inline int re_string_char_size_at (const re_string_t *pstr, int idx)405 internal_function __attribute ((pure));406 static inline wint_t re_string_wchar_at (const re_string_t *pstr, int idx)407 internal_function __attribute ((pure));408 # endif /* RE_ENABLE_I18N */409 401 static unsigned int re_string_context_at (const re_string_t *input, int idx, 410 402 int eflags) 411 403 internal_function __attribute ((pure)); 412 static unsigned char re_string_peek_byte_case (const re_string_t *pstr,413 int idx)414 internal_function __attribute ((pure));415 static unsigned char re_string_fetch_byte_case (re_string_t *pstr)416 internal_function __attribute ((pure));417 #endif418 404 #define re_string_peek_byte(pstr, offset) \ 419 405 ((pstr)->mbs[(pstr)->cur_idx + offset]) … … 433 419 #define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx)) 434 420 421 #include <alloca.h> 422 423 #ifndef _LIBC 424 # if HAVE_ALLOCA 425 /* The OS usually guarantees only one guard page at the bottom of the stack, 426 and a page size can be as small as 4096 bytes. So we cannot safely 427 allocate anything larger than 4096 bytes. Also care for the possibility 428 of a few compiler-allocated temporary stack slots. */ 429 # define __libc_use_alloca(n) ((n) < 4032) 430 # else 431 /* alloca is implemented with malloc, so just use malloc. */ 432 # define __libc_use_alloca(n) 0 433 # endif 434 #endif 435 435 436 #define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t))) 436 437 #define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t))) … … 544 545 int str_idx; 545 546 int node; 546 int next_last_offset;547 547 state_array_t *path; 548 548 int alasts; /* Allocation size of LASTS. */ … … 567 567 re_string_t input; 568 568 #if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) 569 re_dfa_t *const dfa;569 const re_dfa_t *const dfa; 570 570 #else 571 re_dfa_t *dfa;571 const re_dfa_t *dfa; 572 572 #endif 573 573 /* EFLAGS of the argument of regexec. */ … … 616 616 { 617 617 re_token_t *nodes; 618 int nodes_alloc;619 int nodes_len;618 size_t nodes_alloc; 619 size_t nodes_len; 620 620 int *nexts; 621 621 int *org_indices; … … 635 635 /* number of subexpressions `re_nsub' is in regex_t. */ 636 636 unsigned int state_hash_mask; 637 int states_alloc;638 637 int init_node; 639 638 int nbackref; /* The number of backreference in this dfa. */ 640 639 641 640 /* Bitmap expressing which backreference is used. */ 642 unsigned int used_bkref_map;643 unsigned int completed_bkref_map;641 bitset_word_t used_bkref_map; 642 bitset_word_t completed_bkref_map; 644 643 645 644 unsigned int has_plural_match : 1; … … 652 651 unsigned int word_ops_used : 1; 653 652 int mb_cur_max; 654 bitset word_char;653 bitset_t word_char; 655 654 reg_syntax_t syntax; 656 655 int *subexp_map; … … 661 660 }; 662 661 663 #ifndef RE_NO_INTERNAL_PROTOTYPES664 static reg_errcode_t re_node_set_alloc (re_node_set *set, int size) internal_function;665 static reg_errcode_t re_node_set_init_1 (re_node_set *set, int elem) internal_function;666 static reg_errcode_t re_node_set_init_2 (re_node_set *set, int elem1,667 int elem2) internal_function;668 662 #define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set)) 669 static reg_errcode_t re_node_set_init_copy (re_node_set *dest,670 const re_node_set *src) internal_function;671 static reg_errcode_t re_node_set_add_intersect (re_node_set *dest,672 const re_node_set *src1,673 const re_node_set *src2) internal_function;674 static reg_errcode_t re_node_set_init_union (re_node_set *dest,675 const re_node_set *src1,676 const re_node_set *src2) internal_function;677 static reg_errcode_t re_node_set_merge (re_node_set *dest,678 const re_node_set *src) internal_function;679 static int re_node_set_insert (re_node_set *set, int elem) internal_function;680 static int re_node_set_insert_last (re_node_set *set,681 int elem) internal_function;682 static int re_node_set_compare (const re_node_set *set1,683 const re_node_set *set2)684 internal_function __attribute ((pure));685 static int re_node_set_contains (const re_node_set *set, int elem)686 internal_function __attribute ((pure));687 static void re_node_set_remove_at (re_node_set *set, int idx) internal_function;688 663 #define re_node_set_remove(set,id) \ 689 664 (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1)) 690 665 #define re_node_set_empty(p) ((p)->nelem = 0) 691 666 #define re_node_set_free(set) re_free ((set)->elems) 692 static int re_dfa_add_node (re_dfa_t *dfa, re_token_t token) internal_function;693 static re_dfastate_t *re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa,694 const re_node_set *nodes) internal_function;695 static re_dfastate_t *re_acquire_state_context (reg_errcode_t *err,696 re_dfa_t *dfa,697 const re_node_set *nodes,698 unsigned int context) internal_function;699 static void free_state (re_dfastate_t *state) internal_function;700 #endif701 667 702 668 … … 725 691 /* Inline functions for bitset operation. */ 726 692 static inline void 727 bitset_not (bitset set)693 bitset_not (bitset_t set) 728 694 { 729 695 int bitset_i; 730 for (bitset_i = 0; bitset_i < BITSET_ UINTS; ++bitset_i)696 for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i) 731 697 set[bitset_i] = ~set[bitset_i]; 732 698 } 733 699 734 700 static inline void 735 bitset_merge (bitset dest, const bitset src)701 bitset_merge (bitset_t dest, const bitset_t src) 736 702 { 737 703 int bitset_i; 738 for (bitset_i = 0; bitset_i < BITSET_ UINTS; ++bitset_i)704 for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i) 739 705 dest[bitset_i] |= src[bitset_i]; 740 706 } 741 707 742 708 static inline void 743 bitset_not_merge (bitset dest, const bitset src) 744 { 745 int i; 746 for (i = 0; i < BITSET_UINTS; ++i) 747 dest[i] |= ~src[i]; 748 } 749 750 static inline void 751 bitset_mask (bitset dest, const bitset src) 709 bitset_mask (bitset_t dest, const bitset_t src) 752 710 { 753 711 int bitset_i; 754 for (bitset_i = 0; bitset_i < BITSET_ UINTS; ++bitset_i)712 for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i) 755 713 dest[bitset_i] &= src[bitset_i]; 756 714 } 757 715 758 #if defined RE_ENABLE_I18N && !defined RE_NO_INTERNAL_PROTOTYPES716 #ifdef RE_ENABLE_I18N 759 717 /* Inline functions for re_string. */ 760 718 static inline int 761 internal_function 719 internal_function __attribute ((pure)) 762 720 re_string_char_size_at (const re_string_t *pstr, int idx) 763 721 { … … 772 730 773 731 static inline wint_t 774 internal_function 732 internal_function __attribute ((pure)) 775 733 re_string_wchar_at (const re_string_t *pstr, int idx) 776 734 { … … 781 739 782 740 static int 783 internal_function 741 internal_function __attribute ((pure)) 784 742 re_string_elem_size_at (const re_string_t *pstr, int idx) 785 743 { 786 # ifdef _LIBC744 # ifdef _LIBC 787 745 const unsigned char *p, *extra; 788 746 const int32_t *table, *indirect; 789 747 int32_t tmp; 790 # include <locale/weight.h>748 # include <locale/weight.h> 791 749 uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); 792 750 … … 803 761 } 804 762 else 805 # endif /* _LIBC */763 # endif /* _LIBC */ 806 764 return 1; 807 765 } -
branches/libc-0.6/src/emx/src/lib/lgpl/posix/regexec.c
r2240 r3058 26 26 int str_idx, int from, int to) 27 27 internal_function; 28 static int search_cur_bkref_entry ( re_match_context_t *mctx, int str_idx)28 static int search_cur_bkref_entry (const re_match_context_t *mctx, int str_idx) 29 29 internal_function; 30 30 static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, int node, … … 53 53 static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, 54 54 int nregs, int regs_allocated) internal_function; 55 static inline re_dfastate_t *acquire_init_state_context56 (reg_errcode_t *err, const re_match_context_t *mctx, int idx)57 __attribute ((always_inline)) internal_function;58 55 static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx) 59 56 internal_function; 60 57 static int check_matching (re_match_context_t *mctx, int fl_longest_match, 61 int *p_match_first) 62 internal_function; 63 static int check_halt_node_context (const re_dfa_t *dfa, int node, 64 unsigned int context) internal_function; 58 int *p_match_first) internal_function; 65 59 static int check_halt_state_context (const re_match_context_t *mctx, 66 60 const re_dfastate_t *state, int idx) 67 61 internal_function; 68 static void update_regs ( re_dfa_t *dfa, regmatch_t *pmatch,62 static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, 69 63 regmatch_t *prev_idx_match, int cur_node, 70 64 int cur_idx, int nmatch) internal_function; 71 static int proceed_next_node (const re_match_context_t *mctx,72 int nregs, regmatch_t *regs,73 int *pidx, int node, re_node_set *eps_via_nodes,74 struct re_fail_stack_t *fs) internal_function;75 65 static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs, 76 66 int str_idx, int dest_node, int nregs, 77 67 regmatch_t *regs, 78 re_node_set *eps_via_nodes) internal_function; 79 static int pop_fail_stack (struct re_fail_stack_t *fs, int *pidx, int nregs, 80 regmatch_t *regs, re_node_set *eps_via_nodes) internal_function; 68 re_node_set *eps_via_nodes) 69 internal_function; 81 70 static reg_errcode_t set_regs (const regex_t *preg, 82 71 const re_match_context_t *mctx, 83 72 size_t nmatch, regmatch_t *pmatch, 84 73 int fl_backtrack) internal_function; 85 static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) internal_function; 74 static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) 75 internal_function; 86 76 87 77 #ifdef RE_ENABLE_I18N 88 78 static int sift_states_iter_mb (const re_match_context_t *mctx, 89 79 re_sift_context_t *sctx, 90 int node_idx, int str_idx, int max_str_idx) internal_function; 80 int node_idx, int str_idx, int max_str_idx) 81 internal_function; 91 82 #endif /* RE_ENABLE_I18N */ 92 static reg_errcode_t sift_states_backward (re_match_context_t *mctx, 93 re_sift_context_t *sctx) internal_function; 94 static reg_errcode_t build_sifted_states (re_match_context_t *mctx, 83 static reg_errcode_t sift_states_backward (const re_match_context_t *mctx, 84 re_sift_context_t *sctx) 85 internal_function; 86 static reg_errcode_t build_sifted_states (const re_match_context_t *mctx, 95 87 re_sift_context_t *sctx, int str_idx, 96 re_node_set *cur_dest) internal_function; 97 static reg_errcode_t update_cur_sifted_state (re_match_context_t *mctx, 88 re_node_set *cur_dest) 89 internal_function; 90 static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx, 98 91 re_sift_context_t *sctx, 99 92 int str_idx, 100 re_node_set *dest_nodes) internal_function; 101 static reg_errcode_t add_epsilon_src_nodes (re_dfa_t *dfa, 93 re_node_set *dest_nodes) 94 internal_function; 95 static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa, 102 96 re_node_set *dest_nodes, 103 const re_node_set *candidates) internal_function; 104 static reg_errcode_t sub_epsilon_src_nodes (re_dfa_t *dfa, int node, 105 re_node_set *dest_nodes, 106 const re_node_set *and_nodes) internal_function; 107 static int check_dst_limits (re_match_context_t *mctx, re_node_set *limits, 97 const re_node_set *candidates) 98 internal_function; 99 static int check_dst_limits (const re_match_context_t *mctx, 100 re_node_set *limits, 108 101 int dst_node, int dst_idx, int src_node, 109 102 int src_idx) internal_function; 110 static int check_dst_limits_calc_pos_1 ( re_match_context_t *mctx,103 static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, 111 104 int boundaries, int subexp_idx, 112 int from_node, int bkref_idx) internal_function; 113 static int check_dst_limits_calc_pos (re_match_context_t *mctx, 105 int from_node, int bkref_idx) 106 internal_function; 107 static int check_dst_limits_calc_pos (const re_match_context_t *mctx, 114 108 int limit, int subexp_idx, 115 109 int node, int str_idx, 116 110 int bkref_idx) internal_function; 117 static reg_errcode_t check_subexp_limits ( re_dfa_t *dfa,111 static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa, 118 112 re_node_set *dest_nodes, 119 113 const re_node_set *candidates, … … 121 115 struct re_backref_cache_entry *bkref_ents, 122 116 int str_idx) internal_function; 123 static reg_errcode_t sift_states_bkref ( re_match_context_t *mctx,117 static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx, 124 118 re_sift_context_t *sctx, 125 int str_idx, const re_node_set *candidates) internal_function; 126 static reg_errcode_t clean_state_log_if_needed (re_match_context_t *mctx, 127 int next_state_log_idx) internal_function; 128 static reg_errcode_t merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, 129 re_dfastate_t **src, int num) internal_function; 119 int str_idx, const re_node_set *candidates) 120 internal_function; 121 static reg_errcode_t merge_state_array (const re_dfa_t *dfa, 122 re_dfastate_t **dst, 123 re_dfastate_t **src, int num) 124 internal_function; 130 125 static re_dfastate_t *find_recover_state (reg_errcode_t *err, 131 126 re_match_context_t *mctx) internal_function; … … 135 130 static re_dfastate_t *merge_state_with_log (reg_errcode_t *err, 136 131 re_match_context_t *mctx, 137 re_dfastate_t *next_state) internal_function; 132 re_dfastate_t *next_state) 133 internal_function; 138 134 static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx, 139 135 re_node_set *cur_nodes, … … 142 138 static re_dfastate_t *transit_state_sb (reg_errcode_t *err, 143 139 re_match_context_t *mctx, 144 re_dfastate_t *pstate) internal_function; 140 re_dfastate_t *pstate) 141 internal_function; 145 142 #endif 146 143 #ifdef RE_ENABLE_I18N 147 144 static reg_errcode_t transit_state_mb (re_match_context_t *mctx, 148 re_dfastate_t *pstate) internal_function; 145 re_dfastate_t *pstate) 146 internal_function; 149 147 #endif /* RE_ENABLE_I18N */ 150 148 static reg_errcode_t transit_state_bkref (re_match_context_t *mctx, 151 const re_node_set *nodes) internal_function; 149 const re_node_set *nodes) 150 internal_function; 152 151 static reg_errcode_t get_subexp (re_match_context_t *mctx, 153 int bkref_node, int bkref_str_idx) internal_function; 152 int bkref_node, int bkref_str_idx) 153 internal_function; 154 154 static reg_errcode_t get_subexp_sub (re_match_context_t *mctx, 155 155 const re_sub_match_top_t *sub_top, 156 156 re_sub_match_last_t *sub_last, 157 int bkref_node, int bkref_str) internal_function; 157 int bkref_node, int bkref_str) 158 internal_function; 158 159 static int find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, 159 160 int subexp_idx, int type) internal_function; … … 165 166 int str_idx, 166 167 re_node_set *cur_nodes, 167 re_node_set *next_nodes) internal_function; 168 static reg_errcode_t check_arrival_expand_ecl (re_dfa_t *dfa, 168 re_node_set *next_nodes) 169 internal_function; 170 static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa, 169 171 re_node_set *cur_nodes, 170 int ex_subexp, int type) internal_function; 171 static reg_errcode_t check_arrival_expand_ecl_sub (re_dfa_t *dfa, 172 int ex_subexp, int type) 173 internal_function; 174 static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa, 172 175 re_node_set *dst_nodes, 173 176 int target, int ex_subexp, … … 175 178 static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx, 176 179 re_node_set *cur_nodes, int cur_str, 177 int subexp_num, int type) internal_function; 178 static int build_trtable (re_dfa_t *dfa, 180 int subexp_num, int type) 181 internal_function; 182 static int build_trtable (const re_dfa_t *dfa, 179 183 re_dfastate_t *state) internal_function; 180 184 #ifdef RE_ENABLE_I18N 181 static int check_node_accept_bytes (re_dfa_t *dfa, int node_idx, 182 const re_string_t *input, int idx) internal_function; 185 static int check_node_accept_bytes (const re_dfa_t *dfa, int node_idx, 186 const re_string_t *input, int idx) 187 internal_function; 183 188 # ifdef _LIBC 184 189 static unsigned int find_collation_sequence_value (const unsigned char *mbs, 185 size_t name_len) internal_function; 190 size_t name_len) 191 internal_function; 186 192 # endif /* _LIBC */ 187 193 #endif /* RE_ENABLE_I18N */ 188 static int group_nodes_into_DFAstates ( re_dfa_t *dfa,194 static int group_nodes_into_DFAstates (const re_dfa_t *dfa, 189 195 const re_dfastate_t *state, 190 196 re_node_set *states_node, 191 bitset *states_ch) internal_function;197 bitset_t *states_ch) internal_function; 192 198 static int check_node_accept (const re_match_context_t *mctx, 193 const re_token_t *node, int idx) internal_function; 194 static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function; 199 const re_token_t *node, int idx) 200 internal_function; 201 static reg_errcode_t extend_buffers (re_match_context_t *mctx) 202 internal_function; 195 203 196 204 … … 221 229 reg_errcode_t err; 222 230 int start, length; 223 re_dfa_t *dfa = (re_dfa_t *) preg->buffer;231 re_dfa_t *dfa = (re_dfa_t *) preg->buffer; 224 232 225 233 if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND)) … … 375 383 if (BE (s == NULL, 0)) 376 384 return -2; 385 #ifdef _LIBC 386 memcpy (__mempcpy (s, string1, length1), string2, length2); 387 #else 377 388 memcpy (s, string1, length1); 378 389 memcpy (s + length1, string2, length2); 390 #endif 379 391 str = s; 380 392 free_str = 1; … … 408 420 int nregs, rval; 409 421 int eflags = 0; 410 re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;422 re_dfa_t *dfa = (re_dfa_t *) bufp->buffer; 411 423 412 424 /* Check for out-of-range. */ … … 618 630 { 619 631 reg_errcode_t err; 620 re_dfa_t *dfa = (re_dfa_t *)preg->buffer;632 const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer; 621 633 int left_lim, right_lim, incr; 622 634 int fl_longest_match, match_first, match_kind, match_last = -1; … … 630 642 char *fastmap = (preg->fastmap != NULL && preg->fastmap_accurate 631 643 && range && !preg->can_be_null) ? preg->fastmap : NULL; 632 unsigned RE_TRANSLATE_TYPE t = (unsigned RE_TRANSLATE_TYPE)preg->translate;644 RE_TRANSLATE_TYPE t = preg->translate; 633 645 634 646 #if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)) … … 887 899 if (BE (mctx.input.offsets_needed != 0, 0)) 888 900 { 889 if (pmatch[reg_idx].rm_so == mctx.input.valid_len)890 pmatch[reg_idx].rm_so += mctx.input.valid_raw_len - mctx.input.valid_len;891 else892 pmatch[reg_idx].rm_so = mctx.input.offsets[pmatch[reg_idx].rm_so];893 if (pmatch[reg_idx].rm_eo == mctx.input.valid_len)894 pmatch[reg_idx].rm_eo += mctx.input.valid_raw_len - mctx.input.valid_len;895 else896 pmatch[reg_idx].rm_eo = mctx.input.offsets[pmatch[reg_idx].rm_eo];901 pmatch[reg_idx].rm_so = 902 (pmatch[reg_idx].rm_so == mctx.input.valid_len 903 ? mctx.input.valid_raw_len 904 : mctx.input.offsets[pmatch[reg_idx].rm_so]); 905 pmatch[reg_idx].rm_eo = 906 (pmatch[reg_idx].rm_eo == mctx.input.valid_len 907 ? mctx.input.valid_raw_len 908 : mctx.input.offsets[pmatch[reg_idx].rm_eo]); 897 909 } 898 910 #else … … 931 943 re_match_context_t *mctx; 932 944 { 933 re_dfa_t *const dfa = mctx->dfa;945 const re_dfa_t *const dfa = mctx->dfa; 934 946 int halt_node, match_last; 935 947 reg_errcode_t ret; … … 1014 1026 1015 1027 static inline re_dfastate_t * 1016 acquire_init_state_context (err, mctx, idx) 1017 reg_errcode_t *err; 1018 const re_match_context_t *mctx; 1019 int idx; 1020 { 1021 re_dfa_t *const dfa = mctx->dfa; 1028 __attribute ((always_inline)) internal_function 1029 acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx, 1030 int idx) 1031 { 1032 const re_dfa_t *const dfa = mctx->dfa; 1022 1033 if (dfa->init_state->has_constraint) 1023 1034 { … … 1057 1068 1058 1069 static int 1059 check_matching (mctx, fl_longest_match, p_match_first) 1060 re_match_context_t *mctx; 1061 int fl_longest_match; 1062 int *p_match_first; 1063 { 1064 re_dfa_t *const dfa = mctx->dfa; 1070 internal_function 1071 check_matching (re_match_context_t *mctx, int fl_longest_match, 1072 int *p_match_first) 1073 { 1074 const re_dfa_t *const dfa = mctx->dfa; 1065 1075 reg_errcode_t err; 1066 1076 int match = 0; … … 1189 1199 /* Check NODE match the current context. */ 1190 1200 1191 static int check_halt_node_context (dfa, node, context) 1192 const re_dfa_t *dfa; 1193 int node; 1194 unsigned int context; 1201 static int 1202 internal_function 1203 check_halt_node_context (const re_dfa_t *dfa, int node, unsigned int context) 1195 1204 { 1196 1205 re_token_type_t type = dfa->nodes[node].type; … … 1210 1219 1211 1220 static int 1212 check_halt_state_context (mctx, state, idx) 1213 const re_match_context_t *mctx; 1214 const re_dfastate_t *state; 1215 int idx; 1221 internal_function 1222 check_halt_state_context (const re_match_context_t *mctx, 1223 const re_dfastate_t *state, int idx) 1216 1224 { 1217 1225 int i; … … 1233 1241 1234 1242 static int 1235 proceed_next_node (mctx, nregs, regs, pidx, node, eps_via_nodes, fs) 1236 const re_match_context_t *mctx; 1237 regmatch_t *regs; 1238 int nregs, *pidx, node; 1239 re_node_set *eps_via_nodes; 1240 struct re_fail_stack_t *fs; 1241 { 1242 re_dfa_t *const dfa = mctx->dfa; 1243 int i, err, dest_node; 1244 dest_node = -1; 1243 internal_function 1244 proceed_next_node (const re_match_context_t *mctx, int nregs, regmatch_t *regs, 1245 int *pidx, int node, re_node_set *eps_via_nodes, 1246 struct re_fail_stack_t *fs) 1247 { 1248 const re_dfa_t *const dfa = mctx->dfa; 1249 int i, err; 1245 1250 if (IS_EPSILON_NODE (dfa->nodes[node].type)) 1246 1251 { … … 1308 1313 if (naccepted == 0) 1309 1314 { 1315 int dest_node; 1310 1316 err = re_node_set_insert (eps_via_nodes, node); 1311 1317 if (BE (err < 0, 0)) … … 1321 1327 || check_node_accept (mctx, dfa->nodes + node, *pidx)) 1322 1328 { 1323 dest_node = dfa->nexts[node];1329 int dest_node = dfa->nexts[node]; 1324 1330 *pidx = (naccepted == 0) ? *pidx + 1 : *pidx + naccepted; 1325 1331 if (fs && (*pidx > mctx->match_last || mctx->state_log[*pidx] == NULL … … 1335 1341 1336 1342 static reg_errcode_t 1337 push_fail_stack (fs, str_idx, dest_node, nregs, regs, eps_via_nodes) 1338 struct re_fail_stack_t *fs; 1339 int str_idx, dest_node, nregs; 1340 regmatch_t *regs; 1341 re_node_set *eps_via_nodes; 1343 internal_function 1344 push_fail_stack (struct re_fail_stack_t *fs, int str_idx, int dest_node, 1345 int nregs, regmatch_t *regs, re_node_set *eps_via_nodes) 1342 1346 { 1343 1347 reg_errcode_t err; … … 1364 1368 1365 1369 static int 1366 pop_fail_stack (fs, pidx, nregs, regs, eps_via_nodes) 1367 struct re_fail_stack_t *fs; 1368 int *pidx, nregs; 1369 regmatch_t *regs; 1370 re_node_set *eps_via_nodes; 1370 internal_function 1371 pop_fail_stack (struct re_fail_stack_t *fs, int *pidx, int nregs, 1372 regmatch_t *regs, re_node_set *eps_via_nodes) 1371 1373 { 1372 1374 int num = --fs->num; … … 1386 1388 1387 1389 static reg_errcode_t 1388 set_regs (preg, mctx, nmatch, pmatch, fl_backtrack) 1389 const regex_t *preg; 1390 const re_match_context_t *mctx; 1391 size_t nmatch; 1392 regmatch_t *pmatch; 1393 int fl_backtrack; 1394 { 1395 re_dfa_t *dfa = (re_dfa_t *) preg->buffer; 1390 internal_function 1391 set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, 1392 regmatch_t *pmatch, int fl_backtrack) 1393 { 1394 const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer; 1396 1395 int idx, cur_node; 1397 1396 re_node_set eps_via_nodes; … … 1399 1398 struct re_fail_stack_t fs_body = { 0, 2, NULL }; 1400 1399 regmatch_t *prev_idx_match; 1400 int prev_idx_match_malloced = 0; 1401 1401 1402 1402 #ifdef DEBUG … … 1417 1417 re_node_set_init_empty (&eps_via_nodes); 1418 1418 1419 prev_idx_match = (regmatch_t *) alloca (sizeof (regmatch_t) * nmatch); 1419 if (__libc_use_alloca (nmatch * sizeof (regmatch_t))) 1420 prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t)); 1421 else 1422 { 1423 prev_idx_match = re_malloc (regmatch_t, nmatch); 1424 if (prev_idx_match == NULL) 1425 { 1426 free_fail_stack_return (fs); 1427 return REG_ESPACE; 1428 } 1429 prev_idx_match_malloced = 1; 1430 } 1420 1431 memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); 1421 1432 … … 1435 1446 { 1436 1447 re_node_set_free (&eps_via_nodes); 1448 if (prev_idx_match_malloced) 1449 re_free (prev_idx_match); 1437 1450 return free_fail_stack_return (fs); 1438 1451 } … … 1443 1456 { 1444 1457 re_node_set_free (&eps_via_nodes); 1458 if (prev_idx_match_malloced) 1459 re_free (prev_idx_match); 1445 1460 return REG_NOERROR; 1446 1461 } … … 1456 1471 { 1457 1472 re_node_set_free (&eps_via_nodes); 1473 if (prev_idx_match_malloced) 1474 re_free (prev_idx_match); 1458 1475 free_fail_stack_return (fs); 1459 1476 return REG_ESPACE; … … 1465 1482 { 1466 1483 re_node_set_free (&eps_via_nodes); 1484 if (prev_idx_match_malloced) 1485 re_free (prev_idx_match); 1467 1486 return REG_NOMATCH; 1468 1487 } … … 1470 1489 } 1471 1490 re_node_set_free (&eps_via_nodes); 1491 if (prev_idx_match_malloced) 1492 re_free (prev_idx_match); 1472 1493 return free_fail_stack_return (fs); 1473 1494 } 1474 1495 1475 1496 static reg_errcode_t 1476 free_fail_stack_return (fs) 1477 struct re_fail_stack_t *fs; 1497 internal_function 1498 free_fail_stack_return (struct re_fail_stack_t *fs) 1478 1499 { 1479 1500 if (fs) … … 1491 1512 1492 1513 static void 1493 update_regs (dfa, pmatch, prev_idx_match, cur_node, cur_idx, nmatch) 1494 re_dfa_t *dfa; 1495 regmatch_t *pmatch, *prev_idx_match; 1496 int cur_node, cur_idx, nmatch; 1514 internal_function 1515 update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, 1516 regmatch_t *prev_idx_match, int cur_node, int cur_idx, int nmatch) 1497 1517 { 1498 1518 int type = dfa->nodes[cur_node].type; … … 1564 1584 1565 1585 static reg_errcode_t 1566 sift_states_backward (mctx, sctx) 1567 re_match_context_t *mctx; 1568 re_sift_context_t *sctx; 1586 internal_function 1587 sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) 1569 1588 { 1570 1589 reg_errcode_t err; … … 1623 1642 1624 1643 static reg_errcode_t 1625 build_sifted_states (mctx, sctx, str_idx, cur_dest) 1626 re_match_context_t *mctx; 1627 re_sift_context_t *sctx; 1628 int str_idx; 1629 re_node_set *cur_dest; 1630 { 1631 re_dfa_t *const dfa = mctx->dfa; 1632 re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes; 1644 internal_function 1645 build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx, 1646 int str_idx, re_node_set *cur_dest) 1647 { 1648 const re_dfa_t *const dfa = mctx->dfa; 1649 const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes; 1633 1650 int i; 1634 1651 … … 1687 1704 1688 1705 static reg_errcode_t 1689 clean_state_log_if_needed (mctx, next_state_log_idx) 1690 re_match_context_t *mctx; 1691 int next_state_log_idx; 1706 internal_function 1707 clean_state_log_if_needed (re_match_context_t *mctx, int next_state_log_idx) 1692 1708 { 1693 1709 int top = mctx->state_log_top; … … 1713 1729 1714 1730 static reg_errcode_t 1715 merge_state_array (dfa, dst, src, num) 1716 re_dfa_t *dfa; 1717 re_dfastate_t **dst; 1718 re_dfastate_t **src; 1719 int num; 1731 internal_function 1732 merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst, 1733 re_dfastate_t **src, int num) 1720 1734 { 1721 1735 int st_idx; … … 1742 1756 1743 1757 static reg_errcode_t 1744 update_cur_sifted_state (mctx, sctx, str_idx, dest_nodes) 1745 re_match_context_t *mctx; 1746 re_sift_context_t *sctx; 1747 int str_idx; 1748 re_node_set *dest_nodes; 1749 { 1750 re_dfa_t *const dfa = mctx->dfa; 1751 reg_errcode_t err; 1758 internal_function 1759 update_cur_sifted_state (const re_match_context_t *mctx, 1760 re_sift_context_t *sctx, int str_idx, 1761 re_node_set *dest_nodes) 1762 { 1763 const re_dfa_t *const dfa = mctx->dfa; 1764 reg_errcode_t err = REG_NOERROR; 1752 1765 const re_node_set *candidates; 1753 1766 candidates = ((mctx->state_log[str_idx] == NULL) ? NULL … … 1791 1804 1792 1805 static reg_errcode_t 1793 add_epsilon_src_nodes (dfa, dest_nodes, candidates) 1794 re_dfa_t *dfa; 1795 re_node_set *dest_nodes; 1796 const re_node_set *candidates; 1806 internal_function 1807 add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes, 1808 const re_node_set *candidates) 1797 1809 { 1798 1810 reg_errcode_t err = REG_NOERROR; … … 1817 1829 1818 1830 static reg_errcode_t 1819 sub_epsilon_src_nodes (dfa, node, dest_nodes, candidates) 1820 re_dfa_t *dfa; 1821 int node; 1822 re_node_set *dest_nodes; 1823 const re_node_set *candidates; 1831 internal_function 1832 sub_epsilon_src_nodes (const re_dfa_t *dfa, int node, re_node_set *dest_nodes, 1833 const re_node_set *candidates) 1824 1834 { 1825 1835 int ecl_idx; … … 1868 1878 1869 1879 static int 1870 check_dst_limits (mctx, limits, dst_node, dst_idx, src_node, src_idx) 1871 re_match_context_t *mctx; 1872 re_node_set *limits; 1873 int dst_node, dst_idx, src_node, src_idx; 1874 { 1875 re_dfa_t *const dfa = mctx->dfa; 1880 internal_function 1881 check_dst_limits (const re_match_context_t *mctx, re_node_set *limits, 1882 int dst_node, int dst_idx, int src_node, int src_idx) 1883 { 1884 const re_dfa_t *const dfa = mctx->dfa; 1876 1885 int lim_idx, src_pos, dst_pos; 1877 1886 … … 1905 1914 1906 1915 static int 1907 check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx, from_node, bkref_idx) 1908 re_match_context_t *mctx; 1909 int boundaries, subexp_idx, from_node, bkref_idx; 1910 { 1911 re_dfa_t *const dfa = mctx->dfa;1912 re_node_set *eclosures = dfa->eclosures + from_node;1916 internal_function 1917 check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, 1918 int subexp_idx, int from_node, int bkref_idx) 1919 { 1920 const re_dfa_t *const dfa = mctx->dfa; 1921 const re_node_set *eclosures = dfa->eclosures + from_node; 1913 1922 int node_idx; 1914 1923 … … 1931 1940 continue; 1932 1941 1933 if (subexp_idx <= 8 * sizeof (ent->eps_reachable_subexps_map) 1934 && !(ent->eps_reachable_subexps_map & (1 << subexp_idx))) 1942 if (subexp_idx < BITSET_WORD_BITS 1943 && !(ent->eps_reachable_subexps_map 1944 & ((bitset_word_t) 1 << subexp_idx))) 1935 1945 continue; 1936 1946 … … 1958 1968 return 0; 1959 1969 1960 ent->eps_reachable_subexps_map &= ~(1 << subexp_idx); 1970 if (subexp_idx < BITSET_WORD_BITS) 1971 ent->eps_reachable_subexps_map 1972 &= ~((bitset_word_t) 1 << subexp_idx); 1961 1973 } 1962 1974 while (ent++->more); … … 1983 1995 1984 1996 static int 1985 check_dst_limits_calc_pos (mctx, limit, subexp_idx, from_node, str_idx, bkref_idx) 1986 re_match_context_t *mctx; 1987 int limit, subexp_idx, from_node, str_idx, bkref_idx; 1997 internal_function 1998 check_dst_limits_calc_pos (const re_match_context_t *mctx, int limit, 1999 int subexp_idx, int from_node, int str_idx, 2000 int bkref_idx) 1988 2001 { 1989 2002 struct re_backref_cache_entry *lim = mctx->bkref_ents + limit; … … 2012 2025 2013 2026 static reg_errcode_t 2014 check_subexp_limits (dfa, dest_nodes, candidates, limits, bkref_ents, str_idx) 2015 re_dfa_t *dfa; 2016 re_node_set *dest_nodes; 2017 const re_node_set *candidates; 2018 re_node_set *limits; 2019 struct re_backref_cache_entry *bkref_ents; 2020 int str_idx; 2027 internal_function 2028 check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes, 2029 const re_node_set *candidates, re_node_set *limits, 2030 struct re_backref_cache_entry *bkref_ents, int str_idx) 2021 2031 { 2022 2032 reg_errcode_t err; … … 2103 2113 2104 2114 static reg_errcode_t 2105 sift_states_bkref (mctx, sctx, str_idx, candidates) 2106 re_match_context_t *mctx; 2107 re_sift_context_t *sctx; 2108 int str_idx; 2109 const re_node_set *candidates; 2110 { 2111 re_dfa_t *const dfa = mctx->dfa; 2115 internal_function 2116 sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx, 2117 int str_idx, const re_node_set *candidates) 2118 { 2119 const re_dfa_t *const dfa = mctx->dfa; 2112 2120 reg_errcode_t err; 2113 2121 int node_idx, node; … … 2137 2145 do 2138 2146 { 2139 int subexp_len, to_idx, dst_node; 2147 int subexp_len; 2148 int to_idx; 2149 int dst_node; 2150 int ret; 2140 2151 re_dfastate_t *cur_state; 2141 2152 … … 2163 2174 local_sctx.last_node = node; 2164 2175 local_sctx.last_str_idx = str_idx; 2165 err= re_node_set_insert (&local_sctx.limits, enabled_idx);2166 if (BE ( err< 0, 0))2176 ret = re_node_set_insert (&local_sctx.limits, enabled_idx); 2177 if (BE (ret < 0, 0)) 2167 2178 { 2168 2179 err = REG_ESPACE; … … 2202 2213 #ifdef RE_ENABLE_I18N 2203 2214 static int 2204 sift_states_iter_mb (mctx, sctx, node_idx, str_idx, max_str_idx) 2205 const re_match_context_t *mctx; 2206 re_sift_context_t *sctx; 2207 int node_idx, str_idx, max_str_idx; 2208 { 2209 re_dfa_t *const dfa = mctx->dfa; 2215 internal_function 2216 sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx, 2217 int node_idx, int str_idx, int max_str_idx) 2218 { 2219 const re_dfa_t *const dfa = mctx->dfa; 2210 2220 int naccepted; 2211 2221 /* Check the node can accept `multi byte'. */ … … 2234 2244 2235 2245 static re_dfastate_t * 2236 transit_state (err, mctx, state) 2237 reg_errcode_t *err; 2238 re_match_context_t *mctx; 2239 re_dfastate_t *state; 2246 internal_function 2247 transit_state (reg_errcode_t *err, re_match_context_t *mctx, 2248 re_dfastate_t *state) 2240 2249 { 2241 2250 re_dfastate_t **trtable; … … 2292 2301 2293 2302 /* Update the state_log if we need */ 2294 static re_dfastate_t * 2295 merge_state_with_log (err, mctx, next_state) 2296 reg_errcode_t *err; 2297 re_match_context_t *mctx; 2298 re_dfastate_t *next_state; 2299 { 2300 re_dfa_t *const dfa = mctx->dfa; 2303 re_dfastate_t * 2304 internal_function 2305 merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, 2306 re_dfastate_t *next_state) 2307 { 2308 const re_dfa_t *const dfa = mctx->dfa; 2301 2309 int cur_idx = re_string_cur_idx (&mctx->input); 2302 2310 … … 2373 2381 from which to restart matching. */ 2374 2382 re_dfastate_t * 2375 find_recover_state (err, mctx) 2376 reg_errcode_t *err; 2377 re_match_context_t *mctx; 2378 { 2379 re_dfastate_t *cur_state = NULL; 2383 internal_function 2384 find_recover_state (reg_errcode_t *err, re_match_context_t *mctx) 2385 { 2386 re_dfastate_t *cur_state; 2380 2387 do 2381 2388 { … … 2393 2400 cur_state = merge_state_with_log (err, mctx, NULL); 2394 2401 } 2395 while ( err == REG_NOERROR && cur_state == NULL);2402 while (*err == REG_NOERROR && cur_state == NULL); 2396 2403 return cur_state; 2397 2404 } … … 2405 2412 2406 2413 static reg_errcode_t 2407 check_subexp_matching_top (mctx, cur_nodes, str_idx) 2408 re_match_context_t *mctx; 2409 re_node_set *cur_nodes; 2410 int str_idx; 2411 { 2412 re_dfa_t *const dfa = mctx->dfa; 2414 internal_function 2415 check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, 2416 int str_idx) 2417 { 2418 const re_dfa_t *const dfa = mctx->dfa; 2413 2419 int node_idx; 2414 2420 reg_errcode_t err; … … 2423 2429 int node = cur_nodes->elems[node_idx]; 2424 2430 if (dfa->nodes[node].type == OP_OPEN_SUBEXP 2425 && dfa->nodes[node].opr.idx < (8 * sizeof (dfa->used_bkref_map)) 2426 && dfa->used_bkref_map & (1 << dfa->nodes[node].opr.idx)) 2431 && dfa->nodes[node].opr.idx < BITSET_WORD_BITS 2432 && (dfa->used_bkref_map 2433 & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx))) 2427 2434 { 2428 2435 err = match_ctx_add_subtop (mctx, node, str_idx); … … 2439 2446 2440 2447 static re_dfastate_t * 2441 transit_state_sb (err, mctx, state) 2442 reg_errcode_t *err; 2443 re_match_context_t *mctx; 2444 re_dfastate_t *state; 2445 { 2446 re_dfa_t *const dfa = mctx->dfa; 2448 transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx, 2449 re_dfastate_t *state) 2450 { 2451 const re_dfa_t *const dfa = mctx->dfa; 2447 2452 re_node_set next_nodes; 2448 2453 re_dfastate_t *next_state; … … 2480 2485 #ifdef RE_ENABLE_I18N 2481 2486 static reg_errcode_t 2482 transit_state_mb (mctx, pstate) 2483 re_match_context_t *mctx; 2484 re_dfastate_t *pstate; 2485 { 2486 re_dfa_t *const dfa = mctx->dfa; 2487 internal_function 2488 transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) 2489 { 2490 const re_dfa_t *const dfa = mctx->dfa; 2487 2491 reg_errcode_t err; 2488 2492 int i; … … 2537 2541 return err; 2538 2542 } 2539 context = re_string_context_at (&mctx->input, dest_idx - 1, mctx->eflags); 2543 context = re_string_context_at (&mctx->input, dest_idx - 1, 2544 mctx->eflags); 2540 2545 mctx->state_log[dest_idx] 2541 2546 = re_acquire_state_context (&err, dfa, &dest_nodes, context); … … 2550 2555 2551 2556 static reg_errcode_t 2552 transit_state_bkref (mctx, nodes) 2553 re_match_context_t *mctx; 2554 const re_node_set *nodes; 2555 { 2556 re_dfa_t *const dfa = mctx->dfa; 2557 internal_function 2558 transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) 2559 { 2560 const re_dfa_t *const dfa = mctx->dfa; 2557 2561 reg_errcode_t err; 2558 2562 int i; … … 2665 2669 2666 2670 static reg_errcode_t 2667 get_subexp (mctx, bkref_node, bkref_str_idx) 2668 re_match_context_t *mctx; 2669 int bkref_node, bkref_str_idx; 2670 { 2671 re_dfa_t *const dfa = mctx->dfa; 2671 internal_function 2672 get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx) 2673 { 2674 const re_dfa_t *const dfa = mctx->dfa; 2672 2675 int subexp_num, sub_top_idx; 2673 2676 const char *buf = (const char *) re_string_get_buffer (&mctx->input); … … 2676 2679 if (cache_idx != -1) 2677 2680 { 2678 const struct re_backref_cache_entry *entry = mctx->bkref_ents + cache_idx; 2681 const struct re_backref_cache_entry *entry 2682 = mctx->bkref_ents + cache_idx; 2679 2683 do 2680 2684 if (entry->node == bkref_node) … … 2723 2727 } 2724 2728 if (memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0) 2725 break; /* We don't need to search this sub expression any more. */ 2729 /* We don't need to search this sub expression any more. */ 2730 break; 2726 2731 } 2727 2732 bkref_str_off += sl_str_diff; … … 2774 2779 /* Does this state have a ')' of the sub expression? */ 2775 2780 nodes = &mctx->state_log[sl_str]->nodes; 2776 cls_node = find_subexp_node (dfa, nodes, subexp_num, OP_CLOSE_SUBEXP); 2781 cls_node = find_subexp_node (dfa, nodes, subexp_num, 2782 OP_CLOSE_SUBEXP); 2777 2783 if (cls_node == -1) 2778 2784 continue; /* No. */ … … 2787 2793 in the current context? */ 2788 2794 err = check_arrival (mctx, sub_top->path, sub_top->node, 2789 sub_top->str_idx, cls_node, sl_str, OP_CLOSE_SUBEXP); 2795 sub_top->str_idx, cls_node, sl_str, 2796 OP_CLOSE_SUBEXP); 2790 2797 if (err == REG_NOMATCH) 2791 2798 continue; … … 2811 2818 2812 2819 static reg_errcode_t 2813 get_subexp_sub (mctx, sub_top, sub_last, bkref_node, bkref_str) 2814 re_match_context_t *mctx; 2815 const re_sub_match_top_t *sub_top; 2816 re_sub_match_last_t *sub_last; 2817 int bkref_node, bkref_str; 2820 internal_function 2821 get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top, 2822 re_sub_match_last_t *sub_last, int bkref_node, int bkref_str) 2818 2823 { 2819 2824 reg_errcode_t err; … … 2821 2826 /* Can the subexpression arrive the back reference? */ 2822 2827 err = check_arrival (mctx, &sub_last->path, sub_last->node, 2823 sub_last->str_idx, bkref_node, bkref_str, OP_OPEN_SUBEXP); 2828 sub_last->str_idx, bkref_node, bkref_str, 2829 OP_OPEN_SUBEXP); 2824 2830 if (err != REG_NOERROR) 2825 2831 return err; … … 2841 2847 2842 2848 static int 2843 find_subexp_node (dfa, nodes, subexp_idx, type) 2844 const re_dfa_t *dfa; 2845 const re_node_set *nodes; 2846 int subexp_idx, type; 2849 internal_function 2850 find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, 2851 int subexp_idx, int type) 2847 2852 { 2848 2853 int cls_idx; … … 2864 2869 2865 2870 static reg_errcode_t 2866 check_arrival (mctx, path, top_node, top_str, last_node, last_str, 2867 type) 2868 re_match_context_t *mctx; 2869 state_array_t *path; 2870 int top_node, top_str, last_node, last_str, type; 2871 { 2872 re_dfa_t *const dfa = mctx->dfa; 2873 reg_errcode_t err; 2871 internal_function 2872 check_arrival (re_match_context_t *mctx, state_array_t *path, int top_node, 2873 int top_str, int last_node, int last_str, int type) 2874 { 2875 const re_dfa_t *const dfa = mctx->dfa; 2876 reg_errcode_t err = REG_NOERROR; 2874 2877 int subexp_num, backup_cur_idx, str_idx, null_cnt; 2875 2878 re_dfastate_t *cur_state = NULL; … … 2886 2889 path->alloc += last_str + mctx->max_mb_elem_len + 1; 2887 2890 new_array = re_realloc (path->array, re_dfastate_t *, path->alloc); 2888 if ( new_array == NULL)2891 if (BE (new_array == NULL, 0)) 2889 2892 { 2890 2893 path->alloc = old_alloc; … … 2896 2899 } 2897 2900 2898 str_idx = path->next_idx == 0 ? top_str : path->next_idx;2901 str_idx = path->next_idx ?: top_str; 2899 2902 2900 2903 /* Temporary modify MCTX. */ … … 2924 2927 { 2925 2928 err = re_node_set_init_copy (&next_nodes, &cur_state->nodes); 2926 if (BE ( 2929 if (BE (err != REG_NOERROR, 0)) 2927 2930 return err; 2928 2931 } … … 2936 2939 err = expand_bkref_cache (mctx, &next_nodes, str_idx, 2937 2940 subexp_num, type); 2938 if (BE ( 2941 if (BE (err != REG_NOERROR, 0)) 2939 2942 { 2940 2943 re_node_set_free (&next_nodes); … … 2967 2970 { 2968 2971 err = check_arrival_add_next_nodes (mctx, str_idx, 2969 &cur_state->non_eps_nodes, &next_nodes); 2972 &cur_state->non_eps_nodes, 2973 &next_nodes); 2970 2974 if (BE (err != REG_NOERROR, 0)) 2971 2975 { … … 2985 2989 err = expand_bkref_cache (mctx, &next_nodes, str_idx, 2986 2990 subexp_num, type); 2987 if (BE ( 2991 if (BE (err != REG_NOERROR, 0)) 2988 2992 { 2989 2993 re_node_set_free (&next_nodes); … … 3026 3030 3027 3031 static reg_errcode_t 3028 check_arrival_add_next_nodes (mctx, str_idx, cur_nodes, next_nodes) 3029 re_match_context_t *mctx; 3030 int str_idx; 3031 re_node_set *cur_nodes, *next_nodes; 3032 { 3033 re_dfa_t *const dfa = mctx->dfa; 3032 internal_function 3033 check_arrival_add_next_nodes (re_match_context_t *mctx, int str_idx, 3034 re_node_set *cur_nodes, re_node_set *next_nodes) 3035 { 3036 const re_dfa_t *const dfa = mctx->dfa; 3034 3037 int result; 3035 3038 int cur_idx; 3036 #ifdef RE_ENABLE_I18N 3037 reg_errcode_t err; 3038 #endif 3039 reg_errcode_t err = REG_NOERROR; 3039 3040 re_node_set union_set; 3040 3041 re_node_set_init_empty (&union_set); … … 3108 3109 3109 3110 static reg_errcode_t 3110 check_arrival_expand_ecl (dfa, cur_nodes, ex_subexp, type) 3111 re_dfa_t *dfa; 3112 re_node_set *cur_nodes; 3113 int ex_subexp, type; 3111 internal_function 3112 check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, 3113 int ex_subexp, int type) 3114 3114 { 3115 3115 reg_errcode_t err; … … 3128 3128 { 3129 3129 int cur_node = cur_nodes->elems[idx]; 3130 re_node_set *eclosure = dfa->eclosures + cur_node;3130 const re_node_set *eclosure = dfa->eclosures + cur_node; 3131 3131 outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type); 3132 3132 if (outside_node == -1) … … 3162 3162 3163 3163 static reg_errcode_t 3164 check_arrival_expand_ecl_sub (dfa, dst_nodes, target, ex_subexp, type) 3165 re_dfa_t *dfa; 3166 int target, ex_subexp, type; 3167 re_node_set *dst_nodes; 3164 internal_function 3165 check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes, 3166 int target, int ex_subexp, int type) 3168 3167 { 3169 3168 int cur_node; … … 3207 3206 3208 3207 static reg_errcode_t 3209 expand_bkref_cache (mctx, cur_nodes, cur_str, subexp_num, 3210 type) 3211 re_match_context_t *mctx; 3212 int cur_str, subexp_num, type; 3213 re_node_set *cur_nodes; 3214 { 3215 re_dfa_t *const dfa = mctx->dfa; 3208 internal_function 3209 expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, 3210 int cur_str, int subexp_num, int type) 3211 { 3212 const re_dfa_t *const dfa = mctx->dfa; 3216 3213 reg_errcode_t err; 3217 3214 int cache_idx_start = search_cur_bkref_entry (mctx, cur_str); … … 3298 3295 3299 3296 static int 3300 build_trtable (dfa, state) 3301 re_dfa_t *dfa; 3302 re_dfastate_t *state; 3297 internal_function 3298 build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) 3303 3299 { 3304 3300 reg_errcode_t err; 3305 3301 int i, j, ch, need_word_trtable = 0; 3306 unsigned int elem, mask; 3307 int dests_node_malloced = 0, dest_states_malloced = 0; 3302 bitset_word_t elem, mask; 3303 bool dests_node_malloced = false; 3304 bool dest_states_malloced = false; 3308 3305 int ndests; /* Number of the destination states from `state'. */ 3309 3306 re_dfastate_t **trtable; 3310 3307 re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl; 3311 3308 re_node_set follows, *dests_node; 3312 bitset *dests_ch; 3313 bitset acceptable; 3309 bitset_t *dests_ch; 3310 bitset_t acceptable; 3311 3312 struct dests_alloc 3313 { 3314 re_node_set dests_node[SBC_MAX]; 3315 bitset_t dests_ch[SBC_MAX]; 3316 } *dests_alloc; 3314 3317 3315 3318 /* We build DFA states which corresponds to the destination nodes … … 3317 3320 destination state contains, and `dests_ch[i]' represents the 3318 3321 characters which i-th destination state accepts. */ 3319 #ifdef _LIBC 3320 if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX)) 3321 dests_node = (re_node_set *) 3322 alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX); 3322 if (__libc_use_alloca (sizeof (struct dests_alloc))) 3323 dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc)); 3323 3324 else 3324 #endif 3325 { 3326 dests_node = (re_node_set *) 3327 malloc ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX); 3328 if (BE (dests_node == NULL, 0)) 3325 { 3326 dests_alloc = re_malloc (struct dests_alloc, 1); 3327 if (BE (dests_alloc == NULL, 0)) 3329 3328 return 0; 3330 dests_node_malloced = 1; 3331 } 3332 dests_ch = (bitset *) (dests_node + SBC_MAX); 3329 dests_node_malloced = true; 3330 } 3331 dests_node = dests_alloc->dests_node; 3332 dests_ch = dests_alloc->dests_ch; 3333 3333 3334 3334 /* Initialize transiton table. */ … … 3341 3341 { 3342 3342 if (dests_node_malloced) 3343 free (dests_ node);3343 free (dests_alloc); 3344 3344 /* Return 0 in case of an error, 1 otherwise. */ 3345 3345 if (ndests == 0) … … 3356 3356 goto out_free; 3357 3357 3358 #ifdef _LIBC 3359 if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX 3358 if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX 3360 3359 + ndests * 3 * sizeof (re_dfastate_t *))) 3361 3360 dest_states = (re_dfastate_t **) 3362 3361 alloca (ndests * 3 * sizeof (re_dfastate_t *)); 3363 3362 else 3364 #endif3365 3363 { 3366 3364 dest_states = (re_dfastate_t **) … … 3375 3373 re_node_set_free (dests_node + i); 3376 3374 if (dests_node_malloced) 3377 free (dests_ node);3375 free (dests_alloc); 3378 3376 return 0; 3379 3377 } 3380 dest_states_malloced = 1;3378 dest_states_malloced = true; 3381 3379 } 3382 3380 dest_states_word = dest_states + ndests; … … 3440 3438 3441 3439 /* For all characters ch...: */ 3442 for (i = 0; i < BITSET_ UINTS; ++i)3443 for (ch = i * UINT_BITS, elem = acceptable[i], mask = 1;3440 for (i = 0; i < BITSET_WORDS; ++i) 3441 for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; 3444 3442 elem; 3445 3443 mask <<= 1, elem >>= 1, ++ch) … … 3471 3469 3472 3470 /* For all characters ch...: */ 3473 for (i = 0; i < BITSET_ UINTS; ++i)3474 for (ch = i * UINT_BITS, elem = acceptable[i], mask = 1;3471 for (i = 0; i < BITSET_WORDS; ++i) 3472 for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; 3475 3473 elem; 3476 3474 mask <<= 1, elem >>= 1, ++ch) … … 3513 3511 3514 3512 if (dests_node_malloced) 3515 free (dests_ node);3513 free (dests_alloc); 3516 3514 3517 3515 return 1; … … 3524 3522 3525 3523 static int 3526 group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch) 3527 re_dfa_t *dfa; 3528 const re_dfastate_t *state; 3529 re_node_set *dests_node; 3530 bitset *dests_ch; 3524 internal_function 3525 group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, 3526 re_node_set *dests_node, bitset_t *dests_ch) 3531 3527 { 3532 3528 reg_errcode_t err; … … 3534 3530 int i, j, k; 3535 3531 int ndests; /* Number of the destinations from `state'. */ 3536 bitset accepts; /* Characters a node can accept. */3532 bitset_t accepts; /* Characters a node can accept. */ 3537 3533 const re_node_set *cur_nodes = &state->nodes; 3538 3534 bitset_empty (accepts); … … 3569 3565 else if (type == OP_UTF8_PERIOD) 3570 3566 { 3571 memset (accepts, 255, sizeof (unsigned int) * BITSET_UINTS/ 2);3567 memset (accepts, '\xff', sizeof (bitset_t) / 2); 3572 3568 if (!(dfa->syntax & RE_DOT_NEWLINE)) 3573 3569 bitset_clear (accepts, '\n'); … … 3585 3581 if (constraint & NEXT_NEWLINE_CONSTRAINT) 3586 3582 { 3587 intaccepts_newline = bitset_contain (accepts, NEWLINE_CHAR);3583 bool accepts_newline = bitset_contain (accepts, NEWLINE_CHAR); 3588 3584 bitset_empty (accepts); 3589 3585 if (accepts_newline) … … 3600 3596 if (constraint & NEXT_WORD_CONSTRAINT) 3601 3597 { 3602 unsigned int any_set = 0;3598 bitset_word_t any_set = 0; 3603 3599 if (type == CHARACTER && !node->word_char) 3604 3600 { … … 3608 3604 #ifdef RE_ENABLE_I18N 3609 3605 if (dfa->mb_cur_max > 1) 3610 for (j = 0; j < BITSET_ UINTS; ++j)3606 for (j = 0; j < BITSET_WORDS; ++j) 3611 3607 any_set |= (accepts[j] &= (dfa->word_char[j] | ~dfa->sb_char[j])); 3612 3608 else 3613 3609 #endif 3614 for (j = 0; j < BITSET_ UINTS; ++j)3610 for (j = 0; j < BITSET_WORDS; ++j) 3615 3611 any_set |= (accepts[j] &= dfa->word_char[j]); 3616 3612 if (!any_set) … … 3619 3615 if (constraint & NEXT_NOTWORD_CONSTRAINT) 3620 3616 { 3621 unsigned int any_set = 0;3617 bitset_word_t any_set = 0; 3622 3618 if (type == CHARACTER && node->word_char) 3623 3619 { … … 3627 3623 #ifdef RE_ENABLE_I18N 3628 3624 if (dfa->mb_cur_max > 1) 3629 for (j = 0; j < BITSET_ UINTS; ++j)3625 for (j = 0; j < BITSET_WORDS; ++j) 3630 3626 any_set |= (accepts[j] &= ~(dfa->word_char[j] & dfa->sb_char[j])); 3631 3627 else 3632 3628 #endif 3633 for (j = 0; j < BITSET_ UINTS; ++j)3629 for (j = 0; j < BITSET_WORDS; ++j) 3634 3630 any_set |= (accepts[j] &= ~dfa->word_char[j]); 3635 3631 if (!any_set) … … 3642 3638 for (j = 0; j < ndests; ++j) 3643 3639 { 3644 bitset intersec; /* Intersection sets, see below. */3645 bitset remains;3640 bitset_t intersec; /* Intersection sets, see below. */ 3641 bitset_t remains; 3646 3642 /* Flags, see below. */ 3647 int has_intersec, not_subset, not_consumed;3643 bitset_word_t has_intersec, not_subset, not_consumed; 3648 3644 3649 3645 /* Optimization, skip if this state doesn't accept the character. */ … … 3653 3649 /* Enumerate the intersection set of this state and `accepts'. */ 3654 3650 has_intersec = 0; 3655 for (k = 0; k < BITSET_ UINTS; ++k)3651 for (k = 0; k < BITSET_WORDS; ++k) 3656 3652 has_intersec |= intersec[k] = accepts[k] & dests_ch[j][k]; 3657 3653 /* And skip if the intersection set is empty. */ … … 3661 3657 /* Then check if this state is a subset of `accepts'. */ 3662 3658 not_subset = not_consumed = 0; 3663 for (k = 0; k < BITSET_ UINTS; ++k)3659 for (k = 0; k < BITSET_WORDS; ++k) 3664 3660 { 3665 3661 not_subset |= remains[k] = ~accepts[k] & dests_ch[j][k]; … … 3716 3712 3717 3713 static int 3718 check_node_accept_bytes (dfa, node_idx, input, str_idx) 3719 re_dfa_t *dfa; 3720 int node_idx, str_idx; 3721 const re_string_t *input; 3714 internal_function 3715 check_node_accept_bytes (const re_dfa_t *dfa, int node_idx, 3716 const re_string_t *input, int str_idx) 3722 3717 { 3723 3718 const re_token_t *node = dfa->nodes + node_idx; … … 3953 3948 # ifdef _LIBC 3954 3949 static unsigned int 3955 find_collation_sequence_value (mbs, mbs_len) 3956 const unsigned char *mbs; 3957 size_t mbs_len; 3950 internal_function 3951 find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len) 3958 3952 { 3959 3953 uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); … … 4017 4011 4018 4012 static int 4019 check_node_accept (mctx, node, idx) 4020 const re_match_context_t *mctx; 4021 const re_token_t *node; 4022 int idx; 4013 internal_function 4014 check_node_accept (const re_match_context_t *mctx, const re_token_t *node, 4015 int idx) 4023 4016 { 4024 4017 unsigned char ch; … … 4068 4061 4069 4062 static reg_errcode_t 4070 extend_buffers (mctx) 4071 re_match_context_t *mctx; 4063 internal_function 4064 extend_buffers (re_match_context_t *mctx) 4072 4065 { 4073 4066 reg_errcode_t ret; … … 4128 4121 4129 4122 static reg_errcode_t 4130 match_ctx_init (mctx, eflags, n) 4131 re_match_context_t *mctx; 4132 int eflags, n; 4123 internal_function 4124 match_ctx_init (re_match_context_t *mctx, int eflags, int n) 4133 4125 { 4134 4126 mctx->eflags = eflags; … … 4157 4149 4158 4150 static void 4159 match_ctx_clean (mctx) 4160 re_match_context_t *mctx; 4151 internal_function 4152 match_ctx_clean (re_match_context_t *mctx) 4161 4153 { 4162 4154 int st_idx; … … 4187 4179 4188 4180 static void 4189 match_ctx_free (mctx) 4190 re_match_context_t *mctx; 4181 internal_function 4182 match_ctx_free (re_match_context_t *mctx) 4191 4183 { 4192 4184 /* First, free all the memory associated with MCTX->SUB_TOPS. */ … … 4202 4194 4203 4195 static reg_errcode_t 4204 match_ctx_add_entry (mctx, node, str_idx, from, to) 4205 re_match_context_t *mctx; 4206 int node, str_idx, from, to; 4196 internal_function 4197 match_ctx_add_entry (re_match_context_t *mctx, int node, int str_idx, int from, 4198 int to) 4207 4199 { 4208 4200 if (mctx->nbkref_ents >= mctx->abkref_ents) … … 4251 4243 4252 4244 static int 4253 search_cur_bkref_entry (mctx, str_idx) 4254 re_match_context_t *mctx; 4255 int str_idx; 4245 internal_function 4246 search_cur_bkref_entry (const re_match_context_t *mctx, int str_idx) 4256 4247 { 4257 4248 int left, right, mid, last; … … 4275 4266 4276 4267 static reg_errcode_t 4277 match_ctx_add_subtop (mctx, node, str_idx) 4278 re_match_context_t *mctx; 4279 int node, str_idx; 4268 internal_function 4269 match_ctx_add_subtop (re_match_context_t *mctx, int node, int str_idx) 4280 4270 { 4281 4271 #ifdef DEBUG … … 4306 4296 4307 4297 static re_sub_match_last_t * 4308 match_ctx_add_sublast (subtop, node, str_idx) 4309 re_sub_match_top_t *subtop; 4310 int node, str_idx; 4298 internal_function 4299 match_ctx_add_sublast (re_sub_match_top_t *subtop, int node, int str_idx) 4311 4300 { 4312 4301 re_sub_match_last_t *new_entry; … … 4334 4323 4335 4324 static void 4336 sift_ctx_init (sctx, sifted_sts, limited_sts, last_node, last_str_idx) 4337 re_sift_context_t *sctx; 4338 re_dfastate_t **sifted_sts, **limited_sts; 4339 int last_node, last_str_idx; 4325 internal_function 4326 sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts, 4327 re_dfastate_t **limited_sts, int last_node, int last_str_idx) 4340 4328 { 4341 4329 sctx->sifted_states = sifted_sts;
Note:
See TracChangeset
for help on using the changeset viewer.