diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | dfa.c | 80 | ||||
-rw-r--r-- | mbsupport.h | 17 | ||||
-rw-r--r-- | missing_d/ChangeLog | 4 | ||||
-rw-r--r-- | missing_d/wcmisc.c | 88 | ||||
-rw-r--r-- | regex_internal.h | 8 | ||||
-rw-r--r-- | replace.c | 4 |
7 files changed, 125 insertions, 84 deletions
@@ -1,3 +1,11 @@ +2011-11-01 Arnold D. Robbins <arnold@skeeve.com> + + * dfa.c: Move glop for ! MBS_SUPPORT to ... + * mbsupport.h: ... here. + * replace.c: Include missing_d/wcmisc.c if ! MBS_SUPPORT. + * regex_internal.h: Move include of mbsupport.h up and add + additional checks to avoid inclusion of wctype.h and wchar.h. + 2011-10-27 Arnold D. Robbins <arnold@skeeve.com> * builtin.c (do_strftime): Per Pat Rankin, instead of casting @@ -68,18 +68,6 @@ #define bool int #define true (1) #define false (0) -#if ! MBS_SUPPORT -#define wctype_t int -#define wint_t int -#define mbstate_t int -#define WEOF EOF -#define towupper toupper -#define towlower tolower -#define btowc(x) (x) -#define iswalnum isalnum -#define iswalpha isalpha -#define iswupper isupper -#endif /* ! MBS_SUPPORT */ #endif /* GAWK */ #include "regex.h" @@ -92,74 +80,6 @@ is_blank (int c) { return (c == ' ' || c == '\t'); } - -#if ! MBS_SUPPORT -static const char *classes[] = { - "<dummy>", - "alnum", - "alpha", - "blank", - "cntrl", - "digit", - "graph", - "lower", - "print", - "punct", - "space", - "upper", - "xdigit", - NULL -}; - -static wctype_t wctype(const char *name) -{ - int i; - - for (i = 1; classes[i] != NULL; i++) - if (strcmp(name, classes[i]) == 0) - return i; - - return 0; -} - -static int iswctype(wint_t wc, wctype_t desc) -{ - int j = sizeof(classes) / sizeof(classes[0]); - - if (desc >= j || desc == 0) - return 0; - - switch (desc) { - case 1: return isalnum(wc); - case 2: return isalpha(wc); - case 3: return is_blank(wc); - case 4: return iscntrl(wc); - case 5: return isdigit(wc); - case 6: return isgraph(wc); - case 7: return islower(wc); - case 8: return isprint(wc); - case 9: return ispunct(wc); - case 10: return isspace(wc); - case 11: return isupper(wc); - case 12: return isxdigit(wc); - default: return 0; - } -} - -static int wcscoll(const wchar_t *ws1, const wchar_t *ws2) -{ - size_t i; - - for (i = 0; ws1[i] != 0 && ws2[i] != 0; i++) { - if (ws1[i] < ws2[i]) - return -1; - else if (ws1[i] > ws2[i]) - return 1; - } - - return (ws1[i] - ws2[i]); -} -#endif /* ! MBS_SUPPORT */ #endif /* GAWK */ /* HPUX, define those as macros in sys/param.h */ diff --git a/mbsupport.h b/mbsupport.h index 6008da77..1a30785d 100644 --- a/mbsupport.h +++ b/mbsupport.h @@ -67,4 +67,21 @@ #if ! MBS_SUPPORT # undef MB_CUR_MAX # define MB_CUR_MAX 1 + +/* All this glop is for dfa.c. Bleah. */ + +#define wctype_t int +#define wint_t int +#define mbstate_t int +#define WEOF EOF +#define towupper toupper +#define towlower tolower +#define btowc(x) (x) +#define iswalnum isalnum +#define iswalpha isalpha +#define iswupper isupper + +extern wctype_t wctype(const char *name); +extern int iswctype(wint_t wc, wctype_t desc); +extern int wcscoll(const wchar_t *ws1, const wchar_t *ws2); #endif diff --git a/missing_d/ChangeLog b/missing_d/ChangeLog index 8aaeb418..45cc1acc 100644 --- a/missing_d/ChangeLog +++ b/missing_d/ChangeLog @@ -1,3 +1,7 @@ +2011-11-01 Arnold D. Robbins <arnold@skeeve.com> + + * wcmisc.c: New file. + 2011-06-23 Arnold D. Robbins <arnold@skeeve.com> * ChangeLog.0: Rotated ChangeLog into this file. diff --git a/missing_d/wcmisc.c b/missing_d/wcmisc.c new file mode 100644 index 00000000..e53730ea --- /dev/null +++ b/missing_d/wcmisc.c @@ -0,0 +1,88 @@ +/* wcmisc.c - replace wcXXXX routines + Copyright (C) 2011 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 + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., + 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA */ + +static const char *classes[] = { + "<dummy>", + "alnum", + "alpha", + "blank", + "cntrl", + "digit", + "graph", + "lower", + "print", + "punct", + "space", + "upper", + "xdigit", + NULL +}; + +static int is_blank (int c) +{ + return (c == ' ' || c == '\t'); +} + +wctype_t wctype(const char *name) +{ + int i; + + for (i = 1; classes[i] != NULL; i++) + if (strcmp(name, classes[i]) == 0) + return i; + + return 0; +} + +int iswctype(wint_t wc, wctype_t desc) +{ + int j = sizeof(classes) / sizeof(classes[0]); + + if (desc >= j || desc == 0) + return 0; + + switch (desc) { + case 1: return isalnum(wc); + case 2: return isalpha(wc); + case 3: return is_blank(wc); + case 4: return iscntrl(wc); + case 5: return isdigit(wc); + case 6: return isgraph(wc); + case 7: return islower(wc); + case 8: return isprint(wc); + case 9: return ispunct(wc); + case 10: return isspace(wc); + case 11: return isupper(wc); + case 12: return isxdigit(wc); + default: return 0; + } +} + +int wcscoll(const wchar_t *ws1, const wchar_t *ws2) +{ + size_t i; + + for (i = 0; ws1[i] != 0 && ws2[i] != 0; i++) { + if (ws1[i] < ws2[i]) + return -1; + else if (ws1[i] > ws2[i]) + return 1; + } + + return (ws1[i] - ws2[i]); +} diff --git a/regex_internal.h b/regex_internal.h index b5dc7b46..5fcab48a 100644 --- a/regex_internal.h +++ b/regex_internal.h @@ -27,16 +27,18 @@ #include <stdlib.h> #include <string.h> +#include "mbsupport.h" /* gawk */ + #if defined HAVE_LANGINFO_H || defined HAVE_LANGINFO_CODESET || defined _LIBC # include <langinfo.h> #endif #if defined HAVE_LOCALE_H || defined _LIBC # include <locale.h> #endif -#if defined HAVE_WCHAR_H || defined _LIBC +#if MBS_SUPPORT && (defined HAVE_WCHAR_H || defined _LIBC) # include <wchar.h> #endif /* HAVE_WCHAR_H || _LIBC */ -#if defined HAVE_WCTYPE_H || defined _LIBC +#if MBS_SUPPORT && (defined HAVE_WCTYPE_H || defined _LIBC) # include <wctype.h> #endif /* HAVE_WCTYPE_H || _LIBC */ #if defined HAVE_STDBOOL_H || defined _LIBC @@ -108,8 +110,6 @@ is_blank (int c) # define SIZE_MAX ((size_t) -1) #endif -#include "mbsupport.h" /* gawk */ - #if MBS_SUPPORT || _LIBC # define RE_ENABLE_I18N #endif @@ -111,3 +111,7 @@ #ifndef HAVE_STRCOLL #include "missing_d/strcoll.c" #endif + +#if ! MBS_SUPPORT +#include "missing_d/wcmisc.c" +#endif |