X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/da85a02af7585384008d3ebec836a7b8571f175d..261cb4bb750143d8078bb27a343e0d9560b884df:/src/regex.c diff --git a/src/regex.c b/src/regex.c index 190d1d0fe2..f9a12a3c2d 100644 --- a/src/regex.c +++ b/src/regex.c @@ -2,7 +2,7 @@ 0.12. (Implements POSIX draft P1003.2/D11.2, except for some of the internationalization features.) - Copyright (C) 1993-2011 Free Software Foundation, Inc. + Copyright (C) 1993-2012 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,6 +33,19 @@ #pragma alloca #endif +/* Ignore some GCC warnings for now. This section should go away + once the Emacs and Gnulib regex code is merged. */ +#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic ignored "-Wstrict-overflow" +# ifndef emacs +# pragma GCC diagnostic ignored "-Wunused-but-set-variable" +# pragma GCC diagnostic ignored "-Wunused-function" +# pragma GCC diagnostic ignored "-Wunused-macros" +# pragma GCC diagnostic ignored "-Wunused-result" +# pragma GCC diagnostic ignored "-Wunused-variable" +# endif +#endif + #ifdef HAVE_CONFIG_H # include #endif @@ -53,7 +66,7 @@ (HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC && !emacs) #endif -/* For platform which support the ISO C amendement 1 functionality we +/* For platform which support the ISO C amendment 1 functionality we support user defined character classes. */ #if WIDE_CHAR_SUPPORT /* Solaris 2.5 has a bug: must be included before . */ @@ -67,7 +80,7 @@ # define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef) # define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags) # define regerror(err_code, preg, errbuf, errbuf_size) \ - __regerror(err_code, preg, errbuf, errbuf_size) + __regerror (err_code, preg, errbuf, errbuf_size) # define re_set_registers(bu, re, nu, st, en) \ __re_set_registers (bu, re, nu, st, en) # define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \ @@ -198,7 +211,7 @@ /* When used in Emacs's lib-src, we need xmalloc and xrealloc. */ -void * +static void * xmalloc (size_t size) { register void *val; @@ -211,7 +224,7 @@ xmalloc (size_t size) return val; } -void * +static void * xrealloc (void *block, size_t size) { register void *val; @@ -376,12 +389,12 @@ enum syntaxcode { Swhitespace = 0, Sword = 1, Ssymbol = 2 }; # define ISUPPER(c) isupper (c) # define ISXDIGIT(c) isxdigit (c) -# define ISWORD(c) ISALPHA(c) +# define ISWORD(c) ISALPHA (c) # ifdef _tolower -# define TOLOWER(c) _tolower(c) +# define TOLOWER(c) _tolower (c) # else -# define TOLOWER(c) tolower(c) +# define TOLOWER(c) tolower (c) # endif /* How many characters in the character set. */ @@ -421,17 +434,7 @@ init_syntax_once (void) #endif /* not emacs */ -/* We remove any previous definition of `SIGN_EXTEND_CHAR', - since ours (we hope) works properly with all combinations of - machines, compilers, `char' and `unsigned char' argument types. - (Per Bothner suggested the basic approach.) */ -#undef SIGN_EXTEND_CHAR -#if __STDC__ -# define SIGN_EXTEND_CHAR(c) ((signed char) (c)) -#else /* not __STDC__ */ -/* As in Harbison and Steele. */ -# define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128) -#endif +#define SIGN_EXTEND_CHAR(c) ((signed char) (c)) /* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we use `alloca' instead of `malloc'. This is because using malloc in @@ -530,18 +533,22 @@ init_syntax_once (void) #define MIN(a, b) ((a) < (b) ? (a) : (b)) /* Type of source-pattern and string chars. */ +#ifdef _MSC_VER +typedef unsigned char re_char; +#else typedef const unsigned char re_char; +#endif typedef char boolean; #define false 0 #define true 1 -static regoff_t re_match_2_internal _RE_ARGS ((struct re_pattern_buffer *bufp, - re_char *string1, size_t size1, - re_char *string2, size_t size2, - ssize_t pos, - struct re_registers *regs, - ssize_t stop)); +static regoff_t re_match_2_internal (struct re_pattern_buffer *bufp, + re_char *string1, size_t size1, + re_char *string2, size_t size2, + ssize_t pos, + struct re_registers *regs, + ssize_t stop); /* These are the command codes that appear in compiled regular expressions. Some opcodes are followed by argument bytes. A @@ -633,7 +640,7 @@ typedef enum on_failure_jump_nastyloop, /* A smart `on_failure_jump' used for greedy * and + operators. - It analyses the loop before which it is put and if the + It analyzes the loop before which it is put and if the loop does not require backtracking, it changes itself to `on_failure_keep_string_jump' and short-circuits the loop, else it just defaults to changing itself into `on_failure_jump'. @@ -718,11 +725,8 @@ typedef enum } while (0) #ifdef DEBUG -static void extract_number _RE_ARGS ((int *dest, re_char *source)); static void -extract_number (dest, source) - int *dest; - re_char *source; +extract_number (int *dest, re_char *source) { int temp = SIGN_EXTEND_CHAR (*(source + 1)); *dest = *source & 0377; @@ -746,12 +750,8 @@ extract_number (dest, source) } while (0) #ifdef DEBUG -static void extract_number_and_incr _RE_ARGS ((int *destination, - re_char **source)); static void -extract_number_and_incr (destination, source) - int *destination; - re_char **source; +extract_number_and_incr (int *destination, re_char **source) { extract_number (destination, *source); *source += 2; @@ -1655,25 +1655,22 @@ do { \ /* Subroutine declarations and macros for regex_compile. */ -static reg_errcode_t regex_compile _RE_ARGS ((re_char *pattern, size_t size, - reg_syntax_t syntax, - struct re_pattern_buffer *bufp)); -static void store_op1 _RE_ARGS ((re_opcode_t op, unsigned char *loc, int arg)); -static void store_op2 _RE_ARGS ((re_opcode_t op, unsigned char *loc, - int arg1, int arg2)); -static void insert_op1 _RE_ARGS ((re_opcode_t op, unsigned char *loc, - int arg, unsigned char *end)); -static void insert_op2 _RE_ARGS ((re_opcode_t op, unsigned char *loc, - int arg1, int arg2, unsigned char *end)); -static boolean at_begline_loc_p _RE_ARGS ((re_char *pattern, - re_char *p, - reg_syntax_t syntax)); -static boolean at_endline_loc_p _RE_ARGS ((re_char *p, - re_char *pend, - reg_syntax_t syntax)); -static re_char *skip_one_char _RE_ARGS ((re_char *p)); -static int analyse_first _RE_ARGS ((re_char *p, re_char *pend, - char *fastmap, const int multibyte)); +static reg_errcode_t regex_compile (re_char *pattern, size_t size, + reg_syntax_t syntax, + struct re_pattern_buffer *bufp); +static void store_op1 (re_opcode_t op, unsigned char *loc, int arg); +static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2); +static void insert_op1 (re_opcode_t op, unsigned char *loc, + int arg, unsigned char *end); +static void insert_op2 (re_opcode_t op, unsigned char *loc, + int arg1, int arg2, unsigned char *end); +static boolean at_begline_loc_p (re_char *pattern, re_char *p, + reg_syntax_t syntax); +static boolean at_endline_loc_p (re_char *p, re_char *pend, + reg_syntax_t syntax); +static re_char *skip_one_char (re_char *p); +static int analyse_first (re_char *p, re_char *pend, + char *fastmap, const int multibyte); /* Fetch the next character in the uncompiled pattern, with no translation. */ @@ -2093,26 +2090,26 @@ re_iswctype (int ch, re_wctype_t cc) { switch (cc) { - case RECC_ALNUM: return ISALNUM (ch); - case RECC_ALPHA: return ISALPHA (ch); - case RECC_BLANK: return ISBLANK (ch); - case RECC_CNTRL: return ISCNTRL (ch); - case RECC_DIGIT: return ISDIGIT (ch); - case RECC_GRAPH: return ISGRAPH (ch); - case RECC_LOWER: return ISLOWER (ch); - case RECC_PRINT: return ISPRINT (ch); - case RECC_PUNCT: return ISPUNCT (ch); - case RECC_SPACE: return ISSPACE (ch); - case RECC_UPPER: return ISUPPER (ch); - case RECC_XDIGIT: return ISXDIGIT (ch); - case RECC_ASCII: return IS_REAL_ASCII (ch); + case RECC_ALNUM: return ISALNUM (ch) != 0; + case RECC_ALPHA: return ISALPHA (ch) != 0; + case RECC_BLANK: return ISBLANK (ch) != 0; + case RECC_CNTRL: return ISCNTRL (ch) != 0; + case RECC_DIGIT: return ISDIGIT (ch) != 0; + case RECC_GRAPH: return ISGRAPH (ch) != 0; + case RECC_LOWER: return ISLOWER (ch) != 0; + case RECC_PRINT: return ISPRINT (ch) != 0; + case RECC_PUNCT: return ISPUNCT (ch) != 0; + case RECC_SPACE: return ISSPACE (ch) != 0; + case RECC_UPPER: return ISUPPER (ch) != 0; + case RECC_XDIGIT: return ISXDIGIT (ch) != 0; + case RECC_ASCII: return IS_REAL_ASCII (ch) != 0; case RECC_NONASCII: return !IS_REAL_ASCII (ch); - case RECC_UNIBYTE: return ISUNIBYTE (ch); + case RECC_UNIBYTE: return ISUNIBYTE (ch) != 0; case RECC_MULTIBYTE: return !ISUNIBYTE (ch); - case RECC_WORD: return ISWORD (ch); + case RECC_WORD: return ISWORD (ch) != 0; case RECC_ERROR: return false; default: - abort(); + abort (); } } @@ -2133,7 +2130,7 @@ re_wctype_to_bit (re_wctype_t cc) case RECC_ASCII: case RECC_DIGIT: case RECC_XDIGIT: case RECC_CNTRL: case RECC_BLANK: case RECC_UNIBYTE: case RECC_ERROR: return 0; default: - abort(); + abort (); } } #endif @@ -2425,9 +2422,8 @@ regex_grow_registers (int num_regs) #endif /* not MATCH_MAY_ALLOCATE */ -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); /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. Returns one of error codes defined in `regex.h', or zero for success. @@ -4537,10 +4533,10 @@ WEAK_ALIAS (__re_search_2, re_search_2) /* Declarations and macros for re_match_2. */ -static int bcmp_translate _RE_ARGS((re_char *s1, re_char *s2, - register ssize_t len, - RE_TRANSLATE_TYPE translate, - const int multibyte)); +static int bcmp_translate (re_char *s1, re_char *s2, + register ssize_t len, + RE_TRANSLATE_TYPE translate, + const int multibyte); /* This converts PTR, a pointer into one of the search strings `string1' and `string2' into an offset from the beginning of that string. */ @@ -6276,7 +6272,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1, goto fail; default: - abort(); + abort (); } assert (p >= bufp->buffer && p <= pend); @@ -6381,8 +6377,7 @@ 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; @@ -6421,7 +6416,7 @@ re_comp (s) } -regoff_t +int # ifdef _LIBC weak_function # endif @@ -6558,7 +6553,7 @@ reg_errcode_t regexec (const regex_t *__restrict preg, const char *__restrict string, size_t nmatch, regmatch_t pmatch[__restrict_arr], int eflags) { - reg_errcode_t ret; + regoff_t ret; struct re_registers regs; regex_t private_preg; size_t len = strlen (string);