Mercurial > hg > CbC > CbC_gcc
comparison libiberty/regex.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | b7f97abdc517 |
children | 84e7813d76e9 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 /* Extended regular expression matching and search library, | 1 /* Extended regular expression matching and search library, |
2 version 0.12. | 2 version 0.12. |
3 (Implements POSIX draft P1003.2/D11.2, except for some of the | 3 (Implements POSIX draft P1003.2/D11.2, except for some of the |
4 internationalization features.) | 4 internationalization features.) |
5 | 5 |
6 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, | 6 Copyright (C) 1993-2017 Free Software Foundation, Inc. |
7 2002, 2005, 2010 Free Software Foundation, Inc. | |
8 This file is part of the GNU C Library. | 7 This file is part of the GNU C Library. |
9 | 8 |
10 The GNU C Library is free software; you can redistribute it and/or | 9 The GNU C Library is free software; you can redistribute it and/or |
11 modify it under the terms of the GNU Lesser General Public | 10 modify it under the terms of the GNU Lesser General Public |
12 License as published by the Free Software Foundation; either | 11 License as published by the Free Software Foundation; either |
44 | 43 |
45 #ifndef INSIDE_RECURSION | 44 #ifndef INSIDE_RECURSION |
46 | 45 |
47 # if defined STDC_HEADERS && !defined emacs | 46 # if defined STDC_HEADERS && !defined emacs |
48 # include <stddef.h> | 47 # include <stddef.h> |
48 # define PTR_INT_TYPE ptrdiff_t | |
49 # else | 49 # else |
50 /* We need this for `regex.h', and perhaps for the Emacs include files. */ | 50 /* We need this for `regex.h', and perhaps for the Emacs include files. */ |
51 # include <sys/types.h> | 51 # include <sys/types.h> |
52 # define PTR_INT_TYPE long | |
52 # endif | 53 # endif |
53 | 54 |
54 # define WIDE_CHAR_SUPPORT (HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC) | 55 # define WIDE_CHAR_SUPPORT (HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC) |
55 | 56 |
56 /* For platform which support the ISO C amendement 1 functionality we | 57 /* For platform which support the ISO C amendement 1 functionality we |
147 # ifndef INHIBIT_STRING_HEADER | 148 # ifndef INHIBIT_STRING_HEADER |
148 # if defined HAVE_STRING_H || defined STDC_HEADERS || defined _LIBC | 149 # if defined HAVE_STRING_H || defined STDC_HEADERS || defined _LIBC |
149 # include <string.h> | 150 # include <string.h> |
150 # ifndef bzero | 151 # ifndef bzero |
151 # ifndef _LIBC | 152 # ifndef _LIBC |
152 # define bzero(s, n) (memset (s, '\0', n), (s)) | 153 # define bzero(s, n) ((void) memset (s, '\0', n)) |
153 # else | 154 # else |
154 # define bzero(s, n) __bzero (s, n) | 155 # define bzero(s, n) __bzero (s, n) |
155 # endif | 156 # endif |
156 # endif | 157 # endif |
157 # else | 158 # else |
681 } while (0) | 682 } while (0) |
682 # else /* BYTE */ | 683 # else /* BYTE */ |
683 # define EXTRACT_NUMBER(destination, source) \ | 684 # define EXTRACT_NUMBER(destination, source) \ |
684 do { \ | 685 do { \ |
685 (destination) = *(source) & 0377; \ | 686 (destination) = *(source) & 0377; \ |
686 (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \ | 687 (destination) += ((unsigned) SIGN_EXTEND_CHAR (*((source) + 1))) << 8; \ |
687 } while (0) | 688 } while (0) |
688 # endif | 689 # endif |
689 | 690 |
690 # ifdef DEBUG | 691 # ifdef DEBUG |
691 static void PREFIX(extract_number) (int *dest, UCHAR_T *source); | 692 static void PREFIX(extract_number) (int *dest, UCHAR_T *source); |
2043 if (bufp->allocated > MAX_BUF_SIZE) \ | 2044 if (bufp->allocated > MAX_BUF_SIZE) \ |
2044 bufp->allocated = MAX_BUF_SIZE; \ | 2045 bufp->allocated = MAX_BUF_SIZE; \ |
2045 /* How many characters the new buffer can have? */ \ | 2046 /* How many characters the new buffer can have? */ \ |
2046 wchar_count = bufp->allocated / sizeof(UCHAR_T); \ | 2047 wchar_count = bufp->allocated / sizeof(UCHAR_T); \ |
2047 if (wchar_count == 0) wchar_count = 1; \ | 2048 if (wchar_count == 0) wchar_count = 1; \ |
2048 /* Truncate the buffer to CHAR_T align. */ \ | 2049 /* Truncate the buffer to CHAR_T align. */ \ |
2049 bufp->allocated = wchar_count * sizeof(UCHAR_T); \ | 2050 bufp->allocated = wchar_count * sizeof(UCHAR_T); \ |
2050 RETALLOC (COMPILED_BUFFER_VAR, wchar_count, UCHAR_T); \ | 2051 RETALLOC (COMPILED_BUFFER_VAR, wchar_count, UCHAR_T); \ |
2051 bufp->buffer = (char*)COMPILED_BUFFER_VAR; \ | 2052 bufp->buffer = (char*)COMPILED_BUFFER_VAR; \ |
2052 if (COMPILED_BUFFER_VAR == NULL) \ | 2053 if (COMPILED_BUFFER_VAR == NULL) \ |
2053 return REG_ESPACE; \ | 2054 return REG_ESPACE; \ |
2054 /* If the buffer moved, move all the pointers into it. */ \ | 2055 /* If the buffer moved, move all the pointers into it. */ \ |
2055 if (old_buffer != COMPILED_BUFFER_VAR) \ | 2056 if (old_buffer != COMPILED_BUFFER_VAR) \ |
2056 { \ | 2057 { \ |
2057 int incr = COMPILED_BUFFER_VAR - old_buffer; \ | 2058 PTR_INT_TYPE incr = COMPILED_BUFFER_VAR - old_buffer; \ |
2058 MOVE_BUFFER_POINTER (b); \ | 2059 MOVE_BUFFER_POINTER (b); \ |
2059 MOVE_BUFFER_POINTER (begalt); \ | 2060 MOVE_BUFFER_POINTER (begalt); \ |
2060 if (fixup_alt_jump) \ | 2061 if (fixup_alt_jump) \ |
2061 MOVE_BUFFER_POINTER (fixup_alt_jump); \ | 2062 MOVE_BUFFER_POINTER (fixup_alt_jump); \ |
2062 if (laststart) \ | 2063 if (laststart) \ |
2080 if (COMPILED_BUFFER_VAR == NULL) \ | 2081 if (COMPILED_BUFFER_VAR == NULL) \ |
2081 return REG_ESPACE; \ | 2082 return REG_ESPACE; \ |
2082 /* If the buffer moved, move all the pointers into it. */ \ | 2083 /* If the buffer moved, move all the pointers into it. */ \ |
2083 if (old_buffer != COMPILED_BUFFER_VAR) \ | 2084 if (old_buffer != COMPILED_BUFFER_VAR) \ |
2084 { \ | 2085 { \ |
2085 int incr = COMPILED_BUFFER_VAR - old_buffer; \ | 2086 PTR_INT_TYPE incr = COMPILED_BUFFER_VAR - old_buffer; \ |
2086 MOVE_BUFFER_POINTER (b); \ | 2087 MOVE_BUFFER_POINTER (b); \ |
2087 MOVE_BUFFER_POINTER (begalt); \ | 2088 MOVE_BUFFER_POINTER (begalt); \ |
2088 if (fixup_alt_jump) \ | 2089 if (fixup_alt_jump) \ |
2089 MOVE_BUFFER_POINTER (fixup_alt_jump); \ | 2090 MOVE_BUFFER_POINTER (fixup_alt_jump); \ |
2090 if (laststart) \ | 2091 if (laststart) \ |
2489 case '+': | 2490 case '+': |
2490 case '?': | 2491 case '?': |
2491 if ((syntax & RE_BK_PLUS_QM) | 2492 if ((syntax & RE_BK_PLUS_QM) |
2492 || (syntax & RE_LIMITED_OPS)) | 2493 || (syntax & RE_LIMITED_OPS)) |
2493 goto normal_char; | 2494 goto normal_char; |
2495 /* Fall through. */ | |
2494 handle_plus: | 2496 handle_plus: |
2495 case '*': | 2497 case '*': |
2496 /* If there is no previous pattern... */ | 2498 /* If there is no previous pattern... */ |
2497 if (!laststart) | 2499 if (!laststart) |
2498 { | 2500 { |
3392 | 3394 |
3393 /* Throw away the ] at the end of the equivalence | 3395 /* Throw away the ] at the end of the equivalence |
3394 class. */ | 3396 class. */ |
3395 PATFETCH (c); | 3397 PATFETCH (c); |
3396 | 3398 |
3397 /* Now we have to go throught the whole table | 3399 /* Now we have to go through the whole table |
3398 and find all characters which have the same | 3400 and find all characters which have the same |
3399 first level weight. | 3401 first level weight. |
3400 | 3402 |
3401 XXX Note that this is not entirely correct. | 3403 XXX Note that this is not entirely correct. |
3402 we would have to match multibyte sequences | 3404 we would have to match multibyte sequences |
4968 #ifdef INSIDE_RECURSION | 4970 #ifdef INSIDE_RECURSION |
4969 | 4971 |
4970 #ifdef MATCH_MAY_ALLOCATE | 4972 #ifdef MATCH_MAY_ALLOCATE |
4971 # define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL | 4973 # define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL |
4972 #else | 4974 #else |
4973 # define FREE_VAR(var) if (var) free (var); var = NULL | 4975 # define FREE_VAR(var) free (var); var = NULL |
4974 #endif | 4976 #endif |
4975 | 4977 |
4976 #ifdef WCHAR | 4978 #ifdef WCHAR |
4977 # define MAX_ALLOCA_SIZE 2000 | 4979 # define MAX_ALLOCA_SIZE 2000 |
4978 | 4980 |
6693 mcnt = 0; | 6695 mcnt = 0; |
6694 switch ((re_opcode_t) *p1++) | 6696 switch ((re_opcode_t) *p1++) |
6695 { | 6697 { |
6696 case jump_n: | 6698 case jump_n: |
6697 is_a_jump_n = true; | 6699 is_a_jump_n = true; |
6700 /* Fall through. */ | |
6698 case pop_failure_jump: | 6701 case pop_failure_jump: |
6699 case maybe_pop_jump: | 6702 case maybe_pop_jump: |
6700 case jump: | 6703 case jump: |
6701 case dummy_failure_jump: | 6704 case dummy_failure_jump: |
6702 EXTRACT_NUMBER_AND_INCR (mcnt, p1); | 6705 EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
7121 { | 7124 { |
7122 p[-1] = (UCHAR_T) jump; | 7125 p[-1] = (UCHAR_T) jump; |
7123 DEBUG_PRINT1 (" Match => jump.\n"); | 7126 DEBUG_PRINT1 (" Match => jump.\n"); |
7124 goto unconditional_jump; | 7127 goto unconditional_jump; |
7125 } | 7128 } |
7126 /* Note fall through. */ | 7129 /* Fall through. */ |
7127 | 7130 |
7128 | 7131 |
7129 /* The end of a simple repeat has a pop_failure_jump back to | 7132 /* The end of a simple repeat has a pop_failure_jump back to |
7130 its matching on_failure_jump, where the latter will push a | 7133 its matching on_failure_jump, where the latter will push a |
7131 failure point. The pop_failure_jump takes off failure | 7134 failure point. The pop_failure_jump takes off failure |
7146 DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n"); | 7149 DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n"); |
7147 POP_FAILURE_POINT (sdummy, pdummy, | 7150 POP_FAILURE_POINT (sdummy, pdummy, |
7148 dummy_low_reg, dummy_high_reg, | 7151 dummy_low_reg, dummy_high_reg, |
7149 reg_dummy, reg_dummy, reg_info_dummy); | 7152 reg_dummy, reg_dummy, reg_info_dummy); |
7150 } | 7153 } |
7151 /* Note fall through. */ | 7154 /* Fall through. */ |
7152 | 7155 |
7153 unconditional_jump: | 7156 unconditional_jump: |
7154 #ifdef _LIBC | 7157 #ifdef _LIBC |
7155 DEBUG_PRINT2 ("\n%p: ", p); | 7158 DEBUG_PRINT2 ("\n%p: ", p); |
7156 #else | 7159 #else |
7449 loop, need to pop this failure point and use the next one. */ | 7452 loop, need to pop this failure point and use the next one. */ |
7450 switch ((re_opcode_t) *p) | 7453 switch ((re_opcode_t) *p) |
7451 { | 7454 { |
7452 case jump_n: | 7455 case jump_n: |
7453 is_a_jump_n = true; | 7456 is_a_jump_n = true; |
7457 /* Fall through. */ | |
7454 case maybe_pop_jump: | 7458 case maybe_pop_jump: |
7455 case pop_failure_jump: | 7459 case pop_failure_jump: |
7456 case jump: | 7460 case jump: |
7457 p1 = p + 1; | 7461 p1 = p + 1; |
7458 EXTRACT_NUMBER_AND_INCR (mcnt, p1); | 7462 EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
7714 return false; | 7718 return false; |
7715 break; | 7719 break; |
7716 | 7720 |
7717 case set_number_at: | 7721 case set_number_at: |
7718 p1 += 2 * OFFSET_ADDRESS_SIZE; | 7722 p1 += 2 * OFFSET_ADDRESS_SIZE; |
7723 return false; | |
7719 | 7724 |
7720 default: | 7725 default: |
7721 /* All other opcodes mean we cannot match the empty string. */ | 7726 /* All other opcodes mean we cannot match the empty string. */ |
7722 return false; | 7727 return false; |
7723 } | 7728 } |
8089 if (msg_size > errbuf_size) | 8094 if (msg_size > errbuf_size) |
8090 { | 8095 { |
8091 #if defined HAVE_MEMPCPY || defined _LIBC | 8096 #if defined HAVE_MEMPCPY || defined _LIBC |
8092 *((char *) mempcpy (errbuf, msg, errbuf_size - 1)) = '\0'; | 8097 *((char *) mempcpy (errbuf, msg, errbuf_size - 1)) = '\0'; |
8093 #else | 8098 #else |
8094 memcpy (errbuf, msg, errbuf_size - 1); | 8099 (void) memcpy (errbuf, msg, errbuf_size - 1); |
8095 errbuf[errbuf_size - 1] = 0; | 8100 errbuf[errbuf_size - 1] = 0; |
8096 #endif | 8101 #endif |
8097 } | 8102 } |
8098 else | 8103 else |
8099 memcpy (errbuf, msg, msg_size); | 8104 (void) memcpy (errbuf, msg, msg_size); |
8100 } | 8105 } |
8101 | 8106 |
8102 return msg_size; | 8107 return msg_size; |
8103 } | 8108 } |
8104 #ifdef _LIBC | 8109 #ifdef _LIBC |
8109 /* Free dynamically allocated space used by PREG. */ | 8114 /* Free dynamically allocated space used by PREG. */ |
8110 | 8115 |
8111 void | 8116 void |
8112 regfree (regex_t *preg) | 8117 regfree (regex_t *preg) |
8113 { | 8118 { |
8114 if (preg->buffer != NULL) | 8119 free (preg->buffer); |
8115 free (preg->buffer); | |
8116 preg->buffer = NULL; | 8120 preg->buffer = NULL; |
8117 | 8121 |
8118 preg->allocated = 0; | 8122 preg->allocated = 0; |
8119 preg->used = 0; | 8123 preg->used = 0; |
8120 | 8124 |
8121 if (preg->fastmap != NULL) | 8125 free (preg->fastmap); |
8122 free (preg->fastmap); | |
8123 preg->fastmap = NULL; | 8126 preg->fastmap = NULL; |
8124 preg->fastmap_accurate = 0; | 8127 preg->fastmap_accurate = 0; |
8125 | 8128 |
8126 if (preg->translate != NULL) | 8129 free (preg->translate); |
8127 free (preg->translate); | |
8128 preg->translate = NULL; | 8130 preg->translate = NULL; |
8129 } | 8131 } |
8130 #ifdef _LIBC | 8132 #ifdef _LIBC |
8131 weak_alias (__regfree, regfree) | 8133 weak_alias (__regfree, regfree) |
8132 #endif | 8134 #endif |