X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=libiberty%2Fregex.c;h=7d2031994f79ee2d511b51f641a2a673d7231f26;hb=refs%2Fheads%2Fconcurrent-displaced-stepping-2020-04-01;hp=e2763dc2a514a968298d49a065c8c0944df65dd0;hpb=01cea6990b59b90f2a8900d1ab9ff20305e487d7;p=deliverable%2Fbinutils-gdb.git diff --git a/libiberty/regex.c b/libiberty/regex.c index e2763dc2a5..7d2031994f 100644 --- a/libiberty/regex.c +++ b/libiberty/regex.c @@ -2,7 +2,8 @@ version 0.12. (Implements POSIX draft P1003.2/D11.2, except for some of the internationalization features.) - Copyright (C) 1993-1999, 2000, 2001, 2002 Free Software Foundation, Inc. + + Copyright (C) 1993-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -17,8 +18,8 @@ You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. */ /* This file has been modified for usage in libiberty. It includes "xregex.h" instead of . The "xregex.h" header file renames all external @@ -32,25 +33,23 @@ #undef _GNU_SOURCE #define _GNU_SOURCE -#ifdef HAVE_CONFIG_H -# include +#ifndef INSIDE_RECURSION +# ifdef HAVE_CONFIG_H +# include +# endif #endif -#ifndef PARAMS -# if defined __GNUC__ || (defined __STDC__ && __STDC__) -# define PARAMS(args) args -# else -# define PARAMS(args) () -# endif /* GCC. */ -#endif /* Not PARAMS. */ +#include #ifndef INSIDE_RECURSION # if defined STDC_HEADERS && !defined emacs # include +# define PTR_INT_TYPE ptrdiff_t # else /* We need this for `regex.h', and perhaps for the Emacs include files. */ # include +# define PTR_INT_TYPE long # endif # define WIDE_CHAR_SUPPORT (HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC) @@ -151,7 +150,7 @@ char *realloc (); # include # ifndef bzero # ifndef _LIBC -# define bzero(s, n) (memset (s, '\0', n), (s)) +# define bzero(s, n) ((void) memset (s, '\0', n)) # else # define bzero(s, n) __bzero (s, n) # endif @@ -273,10 +272,10 @@ extern char *re_syntax_table; static char re_syntax_table[CHAR_SET_SIZE]; -static void init_syntax_once PARAMS ((void)); +static void init_syntax_once (void); static void -init_syntax_once () +init_syntax_once (void) { register int c; static int done = 0; @@ -407,44 +406,44 @@ typedef char boolean; # define false 0 # define true 1 -static reg_errcode_t byte_regex_compile _RE_ARGS ((const char *pattern, size_t size, - reg_syntax_t syntax, - struct re_pattern_buffer *bufp)); - -static int byte_re_match_2_internal PARAMS ((struct re_pattern_buffer *bufp, - const char *string1, int size1, - const char *string2, int size2, - int pos, - struct re_registers *regs, - int stop)); -static int byte_re_search_2 PARAMS ((struct re_pattern_buffer *bufp, - const char *string1, int size1, - const char *string2, int size2, - int startpos, int range, - struct re_registers *regs, int stop)); -static int byte_re_compile_fastmap PARAMS ((struct re_pattern_buffer *bufp)); +static reg_errcode_t byte_regex_compile (const char *pattern, size_t size, + reg_syntax_t syntax, + struct re_pattern_buffer *bufp); + +static int byte_re_match_2_internal (struct re_pattern_buffer *bufp, + const char *string1, int size1, + const char *string2, int size2, + int pos, + struct re_registers *regs, + int stop); +static int byte_re_search_2 (struct re_pattern_buffer *bufp, + const char *string1, int size1, + const char *string2, int size2, + int startpos, int range, + struct re_registers *regs, int stop); +static int byte_re_compile_fastmap (struct re_pattern_buffer *bufp); #ifdef MBS_SUPPORT -static reg_errcode_t wcs_regex_compile _RE_ARGS ((const char *pattern, size_t size, - reg_syntax_t syntax, - struct re_pattern_buffer *bufp)); - - -static int wcs_re_match_2_internal PARAMS ((struct re_pattern_buffer *bufp, - const char *cstring1, int csize1, - const char *cstring2, int csize2, - int pos, - struct re_registers *regs, - int stop, - wchar_t *string1, int size1, - wchar_t *string2, int size2, - int *mbs_offset1, int *mbs_offset2)); -static int wcs_re_search_2 PARAMS ((struct re_pattern_buffer *bufp, - const char *string1, int size1, - const char *string2, int size2, - int startpos, int range, - struct re_registers *regs, int stop)); -static int wcs_re_compile_fastmap PARAMS ((struct re_pattern_buffer *bufp)); +static reg_errcode_t wcs_regex_compile (const char *pattern, size_t size, + reg_syntax_t syntax, + struct re_pattern_buffer *bufp); + + +static int wcs_re_match_2_internal (struct re_pattern_buffer *bufp, + const char *cstring1, int csize1, + const char *cstring2, int csize2, + int pos, + struct re_registers *regs, + int stop, + wchar_t *string1, int size1, + wchar_t *string2, int size2, + int *mbs_offset1, int *mbs_offset2); +static int wcs_re_search_2 (struct re_pattern_buffer *bufp, + const char *string1, int size1, + const char *string2, int size2, + int startpos, int range, + struct re_registers *regs, int stop); +static int wcs_re_compile_fastmap (struct re_pattern_buffer *bufp); #endif /* These are the command codes that appear in compiled regular @@ -612,11 +611,7 @@ typedef enum # define UCHAR_T unsigned char # define COMPILED_BUFFER_VAR bufp->buffer # define OFFSET_ADDRESS_SIZE 2 -# if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE) -# define PREFIX(name) byte_##name -# else -# define PREFIX(name) byte_/**/name -# endif +# define PREFIX(name) byte_##name # define ARG_PREFIX(name) name # define PUT_CHAR(c) putchar (c) #else @@ -626,13 +621,8 @@ typedef enum # define COMPILED_BUFFER_VAR wc_buffer # define OFFSET_ADDRESS_SIZE 1 /* the size which STORE_NUMBER macro use */ # define CHAR_CLASS_SIZE ((__alignof__(wctype_t)+sizeof(wctype_t))/sizeof(CHAR_T)+1) -# if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE) -# define PREFIX(name) wcs_##name -# define ARG_PREFIX(name) c##name -# else -# define PREFIX(name) wcs_/**/name -# define ARG_PREFIX(name) c/**/name -# endif +# define PREFIX(name) wcs_##name +# define ARG_PREFIX(name) c##name /* Should we use wide stream?? */ # define PUT_CHAR(c) printf ("%C", c); # define TRUE 1 @@ -694,16 +684,14 @@ typedef enum # define EXTRACT_NUMBER(destination, source) \ do { \ (destination) = *(source) & 0377; \ - (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \ + (destination) += ((unsigned) SIGN_EXTEND_CHAR (*((source) + 1))) << 8; \ } while (0) # endif # ifdef DEBUG -static void PREFIX(extract_number) _RE_ARGS ((int *dest, UCHAR_T *source)); +static void PREFIX(extract_number) (int *dest, UCHAR_T *source); static void -PREFIX(extract_number) (dest, source) - int *dest; - UCHAR_T *source; +PREFIX(extract_number) (int *dest, UCHAR_T *source) { # ifdef WCHAR *dest = *source; @@ -731,12 +719,10 @@ PREFIX(extract_number) (dest, source) } while (0) # ifdef DEBUG -static void PREFIX(extract_number_and_incr) _RE_ARGS ((int *destination, - UCHAR_T **source)); +static void PREFIX(extract_number_and_incr) (int *destination, + UCHAR_T **source); static void -PREFIX(extract_number_and_incr) (destination, source) - int *destination; - UCHAR_T **source; +PREFIX(extract_number_and_incr) (int *destination, UCHAR_T **source) { PREFIX(extract_number) (destination, *source); *source += OFFSET_ADDRESS_SIZE; @@ -787,8 +773,7 @@ static int debug; # ifndef DEFINED_ONCE void -print_fastmap (fastmap) - char *fastmap; +print_fastmap (char *fastmap) { unsigned was_a_range = 0; unsigned i = 0; @@ -820,9 +805,7 @@ print_fastmap (fastmap) the START pointer into it and ending just before the pointer END. */ void -PREFIX(print_partial_compiled_pattern) (start, end) - UCHAR_T *start; - UCHAR_T *end; +PREFIX(print_partial_compiled_pattern) (UCHAR_T *start, UCHAR_T *end) { int mcnt, mcnt2; UCHAR_T *p1; @@ -1155,8 +1138,7 @@ PREFIX(print_partial_compiled_pattern) (start, end) void -PREFIX(print_compiled_pattern) (bufp) - struct re_pattern_buffer *bufp; +PREFIX(print_compiled_pattern) (struct re_pattern_buffer *bufp) { UCHAR_T *buffer = (UCHAR_T*) bufp->buffer; @@ -1188,12 +1170,8 @@ PREFIX(print_compiled_pattern) (bufp) void -PREFIX(print_double_string) (where, string1, size1, string2, size2) - const CHAR_T *where; - const CHAR_T *string1; - const CHAR_T *string2; - int size1; - int size2; +PREFIX(print_double_string) (const CHAR_T *where, const CHAR_T *string1, + int size1, const CHAR_T *string2, int size2) { int this_char; @@ -1226,8 +1204,7 @@ PREFIX(print_double_string) (where, string1, size1, string2, size2) # ifndef DEFINED_ONCE void -printchar (c) - int c; +printchar (int c) { putc (c, stderr); } @@ -1264,11 +1241,8 @@ static size_t convert_mbs_to_wcs (CHAR_T *dest, const unsigned char* src, size_t len, int *offset_buffer, char *is_binary); static size_t -convert_mbs_to_wcs (dest, src, len, offset_buffer, is_binary) - CHAR_T *dest; - const unsigned char* src; - size_t len; /* the length of multibyte string. */ - +convert_mbs_to_wcs (CHAR_T *dest, const unsigned char*src, size_t len, + int *offset_buffer, char *is_binary) /* It hold correspondances between src(char string) and dest(wchar_t string) for optimization. e.g. src = "xxxyzz" @@ -1278,8 +1252,6 @@ convert_mbs_to_wcs (dest, src, len, offset_buffer, is_binary) offset_buffer = {0, 0+3("xxx"), 0+3+1("y"), 0+3+1+2("zz")} = {0, 3, 4, 6} */ - int *offset_buffer; - char *is_binary; { wchar_t *pdest = dest; const unsigned char *psrc = src; @@ -1350,8 +1322,7 @@ reg_syntax_t re_syntax_options; defined in regex.h. We return the old syntax. */ reg_syntax_t -re_set_syntax (syntax) - reg_syntax_t syntax; +re_set_syntax (reg_syntax_t syntax) { reg_syntax_t ret = re_syntax_options; @@ -1870,35 +1841,35 @@ static CHAR_T PREFIX(reg_unset_dummy); # define REG_UNSET(e) ((e) == REG_UNSET_VALUE) /* Subroutine declarations and macros for regex_compile. */ -static void PREFIX(store_op1) _RE_ARGS ((re_opcode_t op, UCHAR_T *loc, int arg)); -static void PREFIX(store_op2) _RE_ARGS ((re_opcode_t op, UCHAR_T *loc, - int arg1, int arg2)); -static void PREFIX(insert_op1) _RE_ARGS ((re_opcode_t op, UCHAR_T *loc, - int arg, UCHAR_T *end)); -static void PREFIX(insert_op2) _RE_ARGS ((re_opcode_t op, UCHAR_T *loc, - int arg1, int arg2, UCHAR_T *end)); -static boolean PREFIX(at_begline_loc_p) _RE_ARGS ((const CHAR_T *pattern, - const CHAR_T *p, - reg_syntax_t syntax)); -static boolean PREFIX(at_endline_loc_p) _RE_ARGS ((const CHAR_T *p, - const CHAR_T *pend, - reg_syntax_t syntax)); +static void PREFIX(store_op1) (re_opcode_t op, UCHAR_T *loc, int arg); +static void PREFIX(store_op2) (re_opcode_t op, UCHAR_T *loc, + int arg1, int arg2); +static void PREFIX(insert_op1) (re_opcode_t op, UCHAR_T *loc, + int arg, UCHAR_T *end); +static void PREFIX(insert_op2) (re_opcode_t op, UCHAR_T *loc, + int arg1, int arg2, UCHAR_T *end); +static boolean PREFIX(at_begline_loc_p) (const CHAR_T *pattern, + const CHAR_T *p, + reg_syntax_t syntax); +static boolean PREFIX(at_endline_loc_p) (const CHAR_T *p, + const CHAR_T *pend, + reg_syntax_t syntax); # ifdef WCHAR -static reg_errcode_t wcs_compile_range _RE_ARGS ((CHAR_T range_start, - const CHAR_T **p_ptr, - const CHAR_T *pend, - char *translate, - reg_syntax_t syntax, - UCHAR_T *b, - CHAR_T *char_set)); -static void insert_space _RE_ARGS ((int num, CHAR_T *loc, CHAR_T *end)); +static reg_errcode_t wcs_compile_range (CHAR_T range_start, + const CHAR_T **p_ptr, + const CHAR_T *pend, + char *translate, + reg_syntax_t syntax, + UCHAR_T *b, + CHAR_T *char_set); +static void insert_space (int num, CHAR_T *loc, CHAR_T *end); # else /* BYTE */ -static reg_errcode_t byte_compile_range _RE_ARGS ((unsigned int range_start, - const char **p_ptr, - const char *pend, - char *translate, - reg_syntax_t syntax, - unsigned char *b)); +static reg_errcode_t byte_compile_range (unsigned int range_start, + const char **p_ptr, + const char *pend, + char *translate, + reg_syntax_t syntax, + unsigned char *b); # endif /* WCHAR */ /* Fetch the next character in the uncompiled pattern---translating it @@ -1950,7 +1921,7 @@ static reg_errcode_t byte_compile_range _RE_ARGS ((unsigned int range_start, ? (char) translate[(unsigned char) (d)] : (d)) # else /* BYTE */ # define TRANSLATE(d) \ - (translate ? (char) translate[(unsigned char) (d)] : (d)) + (translate ? (char) translate[(unsigned char) (d)] : (char) (d)) # endif /* WCHAR */ # endif @@ -2075,7 +2046,7 @@ static reg_errcode_t byte_compile_range _RE_ARGS ((unsigned int range_start, /* How many characters the new buffer can have? */ \ wchar_count = bufp->allocated / sizeof(UCHAR_T); \ if (wchar_count == 0) wchar_count = 1; \ - /* Truncate the buffer to CHAR_T align. */ \ + /* Truncate the buffer to CHAR_T align. */ \ bufp->allocated = wchar_count * sizeof(UCHAR_T); \ RETALLOC (COMPILED_BUFFER_VAR, wchar_count, UCHAR_T); \ bufp->buffer = (char*)COMPILED_BUFFER_VAR; \ @@ -2084,7 +2055,7 @@ static reg_errcode_t byte_compile_range _RE_ARGS ((unsigned int range_start, /* If the buffer moved, move all the pointers into it. */ \ if (old_buffer != COMPILED_BUFFER_VAR) \ { \ - int incr = COMPILED_BUFFER_VAR - old_buffer; \ + PTR_INT_TYPE incr = COMPILED_BUFFER_VAR - old_buffer; \ MOVE_BUFFER_POINTER (b); \ MOVE_BUFFER_POINTER (begalt); \ if (fixup_alt_jump) \ @@ -2112,7 +2083,7 @@ static reg_errcode_t byte_compile_range _RE_ARGS ((unsigned int range_start, /* If the buffer moved, move all the pointers into it. */ \ if (old_buffer != COMPILED_BUFFER_VAR) \ { \ - int incr = COMPILED_BUFFER_VAR - old_buffer; \ + PTR_INT_TYPE incr = COMPILED_BUFFER_VAR - old_buffer; \ MOVE_BUFFER_POINTER (b); \ MOVE_BUFFER_POINTER (begalt); \ if (fixup_alt_jump) \ @@ -2256,8 +2227,7 @@ static PREFIX(register_info_type) *PREFIX(reg_info_dummy); but don't make them smaller. */ static void -PREFIX(regex_grow_registers) (num_regs) - int num_regs; +PREFIX(regex_grow_registers) (int num_regs) { if (num_regs > regs_allocated_size) { @@ -2278,9 +2248,8 @@ PREFIX(regex_grow_registers) (num_regs) # endif /* not MATCH_MAY_ALLOCATE */ # ifndef DEFINED_ONCE -static boolean group_in_compile_stack _RE_ARGS ((compile_stack_type - compile_stack, - regnum_t regnum)); +static boolean group_in_compile_stack (compile_stack_type compile_stack, + regnum_t regnum); # endif /* not DEFINED_ONCE */ /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. @@ -2311,11 +2280,9 @@ static boolean group_in_compile_stack _RE_ARGS ((compile_stack_type # endif /* WCHAR */ static reg_errcode_t -PREFIX(regex_compile) (ARG_PREFIX(pattern), ARG_PREFIX(size), syntax, bufp) - const char *ARG_PREFIX(pattern); - size_t ARG_PREFIX(size); - reg_syntax_t syntax; - struct re_pattern_buffer *bufp; +PREFIX(regex_compile) (const char *ARG_PREFIX(pattern), + size_t ARG_PREFIX(size), reg_syntax_t syntax, + struct re_pattern_buffer *bufp) { /* We fetch characters from PATTERN here. Even though PATTERN is `char *' (i.e., signed), we declare these variables as unsigned, so @@ -2525,6 +2492,7 @@ PREFIX(regex_compile) (ARG_PREFIX(pattern), ARG_PREFIX(size), syntax, bufp) if ((syntax & RE_BK_PLUS_QM) || (syntax & RE_LIMITED_OPS)) goto normal_char; + /* Fall through. */ handle_plus: case '*': /* If there is no previous pattern... */ @@ -3428,7 +3396,7 @@ PREFIX(regex_compile) (ARG_PREFIX(pattern), ARG_PREFIX(size), syntax, bufp) class. */ PATFETCH (c); - /* Now we have to go throught the whole table + /* Now we have to go through the whole table and find all characters which have the same first level weight. @@ -4260,10 +4228,7 @@ PREFIX(regex_compile) (ARG_PREFIX(pattern), ARG_PREFIX(size), syntax, bufp) /* ifdef WCHAR, integer parameter is 1 wchar_t. */ static void -PREFIX(store_op1) (op, loc, arg) - re_opcode_t op; - UCHAR_T *loc; - int arg; +PREFIX(store_op1) (re_opcode_t op, UCHAR_T *loc, int arg) { *loc = (UCHAR_T) op; STORE_NUMBER (loc + 1, arg); @@ -4274,10 +4239,7 @@ PREFIX(store_op1) (op, loc, arg) /* ifdef WCHAR, integer parameter is 1 wchar_t. */ static void -PREFIX(store_op2) (op, loc, arg1, arg2) - re_opcode_t op; - UCHAR_T *loc; - int arg1, arg2; +PREFIX(store_op2) (re_opcode_t op, UCHAR_T *loc, int arg1, int arg2) { *loc = (UCHAR_T) op; STORE_NUMBER (loc + 1, arg1); @@ -4290,11 +4252,7 @@ PREFIX(store_op2) (op, loc, arg1, arg2) /* ifdef WCHAR, integer parameter is 1 wchar_t. */ static void -PREFIX(insert_op1) (op, loc, arg, end) - re_opcode_t op; - UCHAR_T *loc; - int arg; - UCHAR_T *end; +PREFIX(insert_op1) (re_opcode_t op, UCHAR_T *loc, int arg, UCHAR_T *end) { register UCHAR_T *pfrom = end; register UCHAR_T *pto = end + 1 + OFFSET_ADDRESS_SIZE; @@ -4310,11 +4268,8 @@ PREFIX(insert_op1) (op, loc, arg, end) /* ifdef WCHAR, integer parameter is 1 wchar_t. */ static void -PREFIX(insert_op2) (op, loc, arg1, arg2, end) - re_opcode_t op; - UCHAR_T *loc; - int arg1, arg2; - UCHAR_T *end; +PREFIX(insert_op2) (re_opcode_t op, UCHAR_T *loc, int arg1, + int arg2, UCHAR_T *end) { register UCHAR_T *pfrom = end; register UCHAR_T *pto = end + 1 + 2 * OFFSET_ADDRESS_SIZE; @@ -4331,9 +4286,8 @@ PREFIX(insert_op2) (op, loc, arg1, arg2, end) least one character before the ^. */ static boolean -PREFIX(at_begline_loc_p) (pattern, p, syntax) - const CHAR_T *pattern, *p; - reg_syntax_t syntax; +PREFIX(at_begline_loc_p) (const CHAR_T *pattern, const CHAR_T *p, + reg_syntax_t syntax) { const CHAR_T *prev = p - 2; boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; @@ -4350,9 +4304,8 @@ PREFIX(at_begline_loc_p) (pattern, p, syntax) at least one character after the $, i.e., `P < PEND'. */ static boolean -PREFIX(at_endline_loc_p) (p, pend, syntax) - const CHAR_T *p, *pend; - reg_syntax_t syntax; +PREFIX(at_endline_loc_p) (const CHAR_T *p, const CHAR_T *pend, + reg_syntax_t syntax) { const CHAR_T *next = p; boolean next_backslash = *next == '\\'; @@ -4373,9 +4326,7 @@ PREFIX(at_endline_loc_p) (p, pend, syntax) false if it's not. */ static boolean -group_in_compile_stack (compile_stack, regnum) - compile_stack_type compile_stack; - regnum_t regnum; +group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum) { int this_element; @@ -4395,10 +4346,7 @@ group_in_compile_stack (compile_stack, regnum) /* This insert space, which size is "num", into the pattern at "loc". "end" must point the end of the allocated buffer. */ static void -insert_space (num, loc, end) - int num; - CHAR_T *loc; - CHAR_T *end; +insert_space (int num, CHAR_T *loc, CHAR_T *end) { register CHAR_T *pto = end; register CHAR_T *pfrom = end - num; @@ -4410,13 +4358,9 @@ insert_space (num, loc, end) #ifdef WCHAR static reg_errcode_t -wcs_compile_range (range_start_char, p_ptr, pend, translate, syntax, b, - char_set) - CHAR_T range_start_char; - const CHAR_T **p_ptr, *pend; - CHAR_T *char_set, *b; - RE_TRANSLATE_TYPE translate; - reg_syntax_t syntax; +wcs_compile_range (CHAR_T range_start_char, const CHAR_T **p_ptr, + const CHAR_T *pend, RE_TRANSLATE_TYPE translate, + reg_syntax_t syntax, CHAR_T *b, CHAR_T *char_set) { const CHAR_T *p = *p_ptr; CHAR_T range_start, range_end; @@ -4497,12 +4441,9 @@ wcs_compile_range (range_start_char, p_ptr, pend, translate, syntax, b, `regex_compile' itself. */ static reg_errcode_t -byte_compile_range (range_start_char, p_ptr, pend, translate, syntax, b) - unsigned int range_start_char; - const char **p_ptr, *pend; - RE_TRANSLATE_TYPE translate; - reg_syntax_t syntax; - unsigned char *b; +byte_compile_range (unsigned int range_start_char, const char **p_ptr, + const char *pend, RE_TRANSLATE_TYPE translate, + reg_syntax_t syntax, unsigned char *b) { unsigned this_char; const char *p = *p_ptr; @@ -4583,8 +4524,7 @@ byte_compile_range (range_start_char, p_ptr, pend, translate, syntax, b) static unsigned char truncate_wchar (CHAR_T c); static unsigned char -truncate_wchar (c) - CHAR_T c; +truncate_wchar (CHAR_T c) { unsigned char buf[MB_CUR_MAX]; mbstate_t state; @@ -4600,8 +4540,7 @@ truncate_wchar (c) #endif /* WCHAR */ static int -PREFIX(re_compile_fastmap) (bufp) - struct re_pattern_buffer *bufp; +PREFIX(re_compile_fastmap) (struct re_pattern_buffer *bufp) { int j, k; #ifdef MATCH_MAY_ALLOCATE @@ -4648,7 +4587,7 @@ PREFIX(re_compile_fastmap) (bufp) while (1) { - if (p == pend || *p == succeed) + if (p == pend || *p == (UCHAR_T) succeed) { /* We have reached the (effective) end of pattern. */ if (!FAIL_STACK_EMPTY ()) @@ -4920,8 +4859,7 @@ PREFIX(re_compile_fastmap) (bufp) #else /* not INSIDE_RECURSION */ int -re_compile_fastmap (bufp) - struct re_pattern_buffer *bufp; +re_compile_fastmap (struct re_pattern_buffer *bufp) { # ifdef MBS_SUPPORT if (MB_CUR_MAX != 1) @@ -4949,11 +4887,9 @@ weak_alias (__re_compile_fastmap, re_compile_fastmap) freeing the old data. */ void -re_set_registers (bufp, regs, num_regs, starts, ends) - struct re_pattern_buffer *bufp; - struct re_registers *regs; - unsigned num_regs; - regoff_t *starts, *ends; +re_set_registers (struct re_pattern_buffer *bufp, + struct re_registers *regs, unsigned num_regs, + regoff_t *starts, regoff_t *ends) { if (num_regs) { @@ -4979,11 +4915,8 @@ weak_alias (__re_set_registers, re_set_registers) doesn't let you say where to stop matching. */ int -re_search (bufp, string, size, startpos, range, regs) - struct re_pattern_buffer *bufp; - const char *string; - int size, startpos, range; - struct re_registers *regs; +re_search (struct re_pattern_buffer *bufp, const char *string, int size, + int startpos, int range, struct re_registers *regs) { return re_search_2 (bufp, NULL, 0, string, size, startpos, range, regs, size); @@ -5015,14 +4948,9 @@ weak_alias (__re_search, re_search) stack overflow). */ int -re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int startpos; - int range; - struct re_registers *regs; - int stop; +re_search_2 (struct re_pattern_buffer *bufp, const char *string1, int size1, + const char *string2, int size2, int startpos, int range, + struct re_registers *regs, int stop) { # ifdef MBS_SUPPORT if (MB_CUR_MAX != 1) @@ -5044,7 +4972,7 @@ weak_alias (__re_search_2, re_search_2) #ifdef MATCH_MAY_ALLOCATE # define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL #else -# define FREE_VAR(var) if (var) free (var); var = NULL +# define FREE_VAR(var) free (var); var = NULL #endif #ifdef WCHAR @@ -5078,15 +5006,10 @@ weak_alias (__re_search_2, re_search_2) static int -PREFIX(re_search_2) (bufp, string1, size1, string2, size2, startpos, range, - regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int startpos; - int range; - struct re_registers *regs; - int stop; +PREFIX(re_search_2) (struct re_pattern_buffer *bufp, const char *string1, + int size1, const char *string2, int size2, + int startpos, int range, + struct re_registers *regs, int stop) { int val; register char *fastmap = bufp->fastmap; @@ -5469,11 +5392,8 @@ PREFIX(re_search_2) (bufp, string1, size1, string2, size2, startpos, range, /* re_match is like re_match_2 except it takes only a single string. */ int -re_match (bufp, string, size, pos, regs) - struct re_pattern_buffer *bufp; - const char *string; - int size, pos; - struct re_registers *regs; +re_match (struct re_pattern_buffer *bufp, const char *string, + int size, int pos, struct re_registers *regs) { int result; # ifdef MBS_SUPPORT @@ -5500,17 +5420,17 @@ weak_alias (__re_match, re_match) #endif /* not INSIDE_RECURSION */ #ifdef INSIDE_RECURSION -static boolean PREFIX(group_match_null_string_p) _RE_ARGS ((UCHAR_T **p, - UCHAR_T *end, - PREFIX(register_info_type) *reg_info)); -static boolean PREFIX(alt_match_null_string_p) _RE_ARGS ((UCHAR_T *p, - UCHAR_T *end, - PREFIX(register_info_type) *reg_info)); -static boolean PREFIX(common_op_match_null_string_p) _RE_ARGS ((UCHAR_T **p, - UCHAR_T *end, - PREFIX(register_info_type) *reg_info)); -static int PREFIX(bcmp_translate) _RE_ARGS ((const CHAR_T *s1, const CHAR_T *s2, - int len, char *translate)); +static boolean PREFIX(group_match_null_string_p) (UCHAR_T **p, + UCHAR_T *end, + PREFIX(register_info_type) *reg_info); +static boolean PREFIX(alt_match_null_string_p) (UCHAR_T *p, + UCHAR_T *end, + PREFIX(register_info_type) *reg_info); +static boolean PREFIX(common_op_match_null_string_p) (UCHAR_T **p, + UCHAR_T *end, + PREFIX(register_info_type) *reg_info); +static int PREFIX(bcmp_translate) (const CHAR_T *s1, const CHAR_T *s2, + int len, char *translate); #else /* not INSIDE_RECURSION */ /* re_match_2 matches the compiled pattern in BUFP against the @@ -5527,13 +5447,9 @@ static int PREFIX(bcmp_translate) _RE_ARGS ((const CHAR_T *s1, const CHAR_T *s2, matched substring. */ int -re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int pos; - struct re_registers *regs; - int stop; +re_match_2 (struct re_pattern_buffer *bufp, const char *string1, int size1, + const char *string2, int size2, int pos, + struct re_registers *regs, int stop) { int result; # ifdef MBS_SUPPORT @@ -5562,7 +5478,7 @@ weak_alias (__re_match_2, re_match_2) #ifdef INSIDE_RECURSION #ifdef WCHAR -static int count_mbs_length PARAMS ((int *, int)); +static int count_mbs_length (int *, int); /* This check the substring (from 0, to length) of the multibyte string, to which offset_buffer correspond. And count how many wchar_t_characters @@ -5570,9 +5486,7 @@ static int count_mbs_length PARAMS ((int *, int)); See convert_mbs_to_wcs. */ static int -count_mbs_length(offset_buffer, length) - int *offset_buffer; - int length; +count_mbs_length(int *offset_buffer, int length) { int upper, lower; @@ -5613,33 +5527,26 @@ count_mbs_length(offset_buffer, length) afterwards. */ #ifdef WCHAR static int -wcs_re_match_2_internal (bufp, cstring1, csize1, cstring2, csize2, pos, - regs, stop, string1, size1, string2, size2, - mbs_offset1, mbs_offset2) - struct re_pattern_buffer *bufp; - const char *cstring1, *cstring2; - int csize1, csize2; - int pos; - struct re_registers *regs; - int stop; +wcs_re_match_2_internal (struct re_pattern_buffer *bufp, + const char *cstring1, int csize1, + const char *cstring2, int csize2, + int pos, + struct re_registers *regs, + int stop, /* string1 == string2 == NULL means string1/2, size1/2 and mbs_offset1/2 need seting up in this function. */ /* We need wchar_t* buffers correspond to cstring1, cstring2. */ - wchar_t *string1, *string2; - /* We need the size of wchar_t buffers correspond to csize1, csize2. */ - int size1, size2; + wchar_t *string1, int size1, + wchar_t *string2, int size2, /* offset buffer for optimizatoin. See convert_mbs_to_wc. */ - int *mbs_offset1, *mbs_offset2; + int *mbs_offset1, int *mbs_offset2) #else /* BYTE */ static int -byte_re_match_2_internal (bufp, string1, size1,string2, size2, pos, - regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int pos; - struct re_registers *regs; - int stop; +byte_re_match_2_internal (struct re_pattern_buffer *bufp, + const char *string1, int size1, + const char *string2, int size2, + int pos, + struct re_registers *regs, int stop) #endif /* BYTE */ { /* General temporaries. */ @@ -6005,11 +5912,14 @@ byte_re_match_2_internal (bufp, string1, size1,string2, size2, pos, { /* 1 if this match ends in the same string (string1 or string2) as the best previous match. */ - boolean same_str_p = (FIRST_STRING_P (match_end) - == MATCHING_IN_FIRST_STRING); + boolean same_str_p; + /* 1 if this match is the best seen so far. */ boolean best_match_p; + same_str_p = (FIRST_STRING_P (match_end) + == MATCHING_IN_FIRST_STRING); + /* AIX compiler got confused when this was combined with the previous declaration. */ if (same_str_p) @@ -6269,9 +6179,9 @@ byte_re_match_2_internal (bufp, string1, size1,string2, size2, pos, uint32_t nrules; # endif /* _LIBC */ #endif /* WCHAR */ - boolean not = (re_opcode_t) *(p - 1) == charset_not; + boolean negate = (re_opcode_t) *(p - 1) == charset_not; - DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : ""); + DEBUG_PRINT2 ("EXECUTING charset%s.\n", negate ? "_not" : ""); PREFETCH (); c = TRANSLATE (*d); /* The character to match. */ #ifdef WCHAR @@ -6638,20 +6548,20 @@ byte_re_match_2_internal (bufp, string1, size1,string2, size2, pos, if (c == *workp) goto char_set_matched; - not = !not; + negate = !negate; char_set_matched: - if (not) goto fail; + if (negate) goto fail; #else /* Cast to `unsigned' instead of `unsigned char' in case the bit list is a full 32 bytes long. */ if (c < (unsigned) (*p * BYTEWIDTH) && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; + negate = !negate; p += 1 + *p; - if (!not) goto fail; + if (!negate) goto fail; #undef WORK_BUFFER_SIZE #endif /* WCHAR */ SET_REGS_MATCHED (); @@ -6787,6 +6697,7 @@ byte_re_match_2_internal (bufp, string1, size1,string2, size2, pos, { case jump_n: is_a_jump_n = true; + /* Fall through. */ case pop_failure_jump: case maybe_pop_jump: case jump: @@ -7141,15 +7052,15 @@ byte_re_match_2_internal (bufp, string1, size1,string2, size2, pos, else if ((re_opcode_t) p1[3] == charset || (re_opcode_t) p1[3] == charset_not) { - int not = (re_opcode_t) p1[3] == charset_not; + int negate = (re_opcode_t) p1[3] == charset_not; if (c < (unsigned) (p1[4] * BYTEWIDTH) && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; + negate = !negate; - /* `not' is equal to 1 if c would match, which means + /* `negate' is equal to 1 if c would match, which means that we can't change to pop_failure_jump. */ - if (!not) + if (!negate) { p[-3] = (unsigned char) pop_failure_jump; DEBUG_PRINT1 (" No match => pop_failure_jump.\n"); @@ -7215,7 +7126,7 @@ byte_re_match_2_internal (bufp, string1, size1,string2, size2, pos, DEBUG_PRINT1 (" Match => jump.\n"); goto unconditional_jump; } - /* Note fall through. */ + /* Fall through. */ /* The end of a simple repeat has a pop_failure_jump back to @@ -7232,15 +7143,15 @@ byte_re_match_2_internal (bufp, string1, size1,string2, size2, pos, register from the stack, since lowest will == highest in `pop_failure_point'. */ active_reg_t dummy_low_reg, dummy_high_reg; - UCHAR_T *pdummy = NULL; - const CHAR_T *sdummy = NULL; + UCHAR_T *pdummy ATTRIBUTE_UNUSED = NULL; + const CHAR_T *sdummy ATTRIBUTE_UNUSED = NULL; DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n"); POP_FAILURE_POINT (sdummy, pdummy, dummy_low_reg, dummy_high_reg, reg_dummy, reg_dummy, reg_info_dummy); } - /* Note fall through. */ + /* Fall through. */ unconditional_jump: #ifdef _LIBC @@ -7543,6 +7454,7 @@ byte_re_match_2_internal (bufp, string1, size1,string2, size2, pos, { case jump_n: is_a_jump_n = true; + /* Fall through. */ case maybe_pop_jump: case pop_failure_jump: case jump: @@ -7589,9 +7501,8 @@ byte_re_match_2_internal (bufp, string1, size1,string2, size2, pos, We don't handle duplicates properly (yet). */ static boolean -PREFIX(group_match_null_string_p) (p, end, reg_info) - UCHAR_T **p, *end; - PREFIX(register_info_type) *reg_info; +PREFIX(group_match_null_string_p) (UCHAR_T **p, UCHAR_T *end, + PREFIX(register_info_type) *reg_info) { int mcnt; /* Point to after the args to the start_memory. */ @@ -7701,9 +7612,8 @@ PREFIX(group_match_null_string_p) (p, end, reg_info) byte past the last. The alternative can contain groups. */ static boolean -PREFIX(alt_match_null_string_p) (p, end, reg_info) - UCHAR_T *p, *end; - PREFIX(register_info_type) *reg_info; +PREFIX(alt_match_null_string_p) (UCHAR_T *p, UCHAR_T *end, + PREFIX(register_info_type) *reg_info) { int mcnt; UCHAR_T *p1 = p; @@ -7738,9 +7648,8 @@ PREFIX(alt_match_null_string_p) (p, end, reg_info) Sets P to one after the op and its arguments, if any. */ static boolean -PREFIX(common_op_match_null_string_p) (p, end, reg_info) - UCHAR_T **p, *end; - PREFIX(register_info_type) *reg_info; +PREFIX(common_op_match_null_string_p) (UCHAR_T **p, UCHAR_T *end, + PREFIX(register_info_type) *reg_info) { int mcnt; boolean ret; @@ -7811,6 +7720,7 @@ PREFIX(common_op_match_null_string_p) (p, end, reg_info) case set_number_at: p1 += 2 * OFFSET_ADDRESS_SIZE; + return false; default: /* All other opcodes mean we cannot match the empty string. */ @@ -7826,10 +7736,8 @@ PREFIX(common_op_match_null_string_p) (p, end, reg_info) bytes; nonzero otherwise. */ static int -PREFIX(bcmp_translate) (s1, s2, len, translate) - const CHAR_T *s1, *s2; - register int len; - RE_TRANSLATE_TYPE translate; +PREFIX(bcmp_translate) (const CHAR_T *s1, const CHAR_T *s2, register int len, + RE_TRANSLATE_TYPE translate) { register const UCHAR_T *p1 = (const UCHAR_T *) s1; register const UCHAR_T *p2 = (const UCHAR_T *) s2; @@ -7862,10 +7770,8 @@ PREFIX(bcmp_translate) (s1, s2, len, translate) We call regex_compile to do the actual compilation. */ const char * -re_compile_pattern (pattern, length, bufp) - const char *pattern; - size_t length; - struct re_pattern_buffer *bufp; +re_compile_pattern (const char *pattern, size_t length, + struct re_pattern_buffer *bufp) { reg_errcode_t ret; @@ -7911,15 +7817,14 @@ char * regcomp/regexec below without link errors. */ weak_function #endif -re_comp (s) - const char *s; +re_comp (const char *s) { reg_errcode_t ret; if (!s) { if (!re_comp_buf.buffer) - return gettext ("No previous regular expression"); + return (char *) gettext ("No previous regular expression"); return 0; } @@ -7960,8 +7865,7 @@ int #ifdef _LIBC weak_function #endif -re_exec (s) - const char *s; +re_exec (const char *s) { const int len = strlen (s); return @@ -8010,10 +7914,7 @@ re_exec (s) the return codes and their meanings.) */ int -regcomp (preg, pattern, cflags) - regex_t *preg; - const char *pattern; - int cflags; +regcomp (regex_t *preg, const char *pattern, int cflags) { reg_errcode_t ret; reg_syntax_t syntax @@ -8030,7 +7931,7 @@ regcomp (preg, pattern, cflags) if (cflags & REG_ICASE) { - unsigned i; + int i; preg->translate = (RE_TRANSLATE_TYPE) malloc (CHAR_SET_SIZE @@ -8106,12 +8007,8 @@ weak_alias (__regcomp, regcomp) We return 0 if we find a match and REG_NOMATCH if not. */ int -regexec (preg, string, nmatch, pmatch, eflags) - const regex_t *preg; - const char *string; - size_t nmatch; - regmatch_t pmatch[]; - int eflags; +regexec (const regex_t *preg, const char *string, size_t nmatch, + regmatch_t pmatch[], int eflags) { int ret; struct re_registers regs; @@ -8173,11 +8070,8 @@ weak_alias (__regexec, regexec) from either regcomp or regexec. We don't use PREG here. */ size_t -regerror (errcode, preg, errbuf, errbuf_size) - int errcode; - const regex_t *preg; - char *errbuf; - size_t errbuf_size; +regerror (int errcode, const regex_t *preg ATTRIBUTE_UNUSED, + char *errbuf, size_t errbuf_size) { const char *msg; size_t msg_size; @@ -8200,14 +8094,14 @@ regerror (errcode, preg, errbuf, errbuf_size) if (msg_size > errbuf_size) { #if defined HAVE_MEMPCPY || defined _LIBC - *((char *) __mempcpy (errbuf, msg, errbuf_size - 1)) = '\0'; + *((char *) mempcpy (errbuf, msg, errbuf_size - 1)) = '\0'; #else - memcpy (errbuf, msg, errbuf_size - 1); + (void) memcpy (errbuf, msg, errbuf_size - 1); errbuf[errbuf_size - 1] = 0; #endif } else - memcpy (errbuf, msg, msg_size); + (void) memcpy (errbuf, msg, msg_size); } return msg_size; @@ -8220,23 +8114,19 @@ weak_alias (__regerror, regerror) /* Free dynamically allocated space used by PREG. */ void -regfree (preg) - regex_t *preg; +regfree (regex_t *preg) { - if (preg->buffer != NULL) - free (preg->buffer); + free (preg->buffer); preg->buffer = NULL; preg->allocated = 0; preg->used = 0; - if (preg->fastmap != NULL) - free (preg->fastmap); + free (preg->fastmap); preg->fastmap = NULL; preg->fastmap_accurate = 0; - if (preg->translate != NULL) - free (preg->translate); + free (preg->translate); preg->translate = NULL; } #ifdef _LIBC