diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2011-09-21 22:45:28 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2011-09-21 22:45:28 +0300 |
commit | 997dbc7f520c811e4c5325b9536f72cb454560cc (patch) | |
tree | 14dcc0a02d36df67d0016145a4a34c2d4243be77 | |
parent | bc5591ac396525b1cf2a2e43f4396b4b854edd9b (diff) | |
download | egawk-997dbc7f520c811e4c5325b9536f72cb454560cc.tar.gz egawk-997dbc7f520c811e4c5325b9536f72cb454560cc.tar.bz2 egawk-997dbc7f520c811e4c5325b9536f72cb454560cc.zip |
Make no mbs support work everywhere. Sheesh.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | array.c | 2 | ||||
-rw-r--r-- | awk.h | 12 | ||||
-rw-r--r-- | awkgram.c | 8 | ||||
-rw-r--r-- | awkgram.y | 8 | ||||
-rw-r--r-- | builtin.c | 36 | ||||
-rw-r--r-- | dfa.c | 10 | ||||
-rw-r--r-- | eval.c | 4 | ||||
-rw-r--r-- | field.c | 20 | ||||
-rw-r--r-- | io.c | 4 | ||||
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | mbsupport.h | 6 | ||||
-rw-r--r-- | node.c | 22 | ||||
-rw-r--r-- | re.c | 4 | ||||
-rw-r--r-- | regex_internal.h | 7 |
15 files changed, 84 insertions, 72 deletions
@@ -4,7 +4,12 @@ that remove many ifdefs, moving many conditions for multibyte support into regular C code and relying GCC's dead code optimization to elimnate code that won't be needed. - * dfa.c: Further edits now that MBS_SUPPORT is always defined. + * dfa.c: For gawk, add a number of additional defines so that things + will compile if MBS_SUPPORT is 0. + * array.c, awk.h, awkgram.y, builtin.c, eval.c, field.c, main.c, + node.c, re.c: Change `#ifdef MBS_SUPPORT' to `#if MBS_SUPPORT'. + * awk.h, regex_internal.h: Move NO_MBSUPPORT handling to ... + * mbsupport.h: ...here. 2011-09-16 Arnold D. Robbins <arnold@skeeve.com> @@ -1266,7 +1266,7 @@ cmp_string(const NODE *n1, const NODE *n2) const unsigned char *cp1 = (const unsigned char *) s1; const unsigned char *cp2 = (const unsigned char *) s2; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) { ret = strncasecmpmbs((const unsigned char *) cp1, (const unsigned char *) cp2, lmin); @@ -76,11 +76,9 @@ extern int errno; #endif -#ifndef NO_MBSUPPORT #include "mbsupport.h" /* defines MBS_SUPPORT */ -#endif -#if defined(MBS_SUPPORT) +#if MBS_SUPPORT /* We can handle multibyte strings. */ #include <wchar.h> #include <wctype.h> @@ -336,7 +334,7 @@ typedef struct exp_node { size_t slen; long sref; int idx; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT wchar_t *wsp; size_t wslen; #endif @@ -934,7 +932,7 @@ extern int exit_val; extern int do_lint; extern int do_lint_old; #endif -#ifdef MBS_SUPPORT +#if MBS_SUPPORT extern int gawk_mb_cur_max; #else extern const int gawk_mb_cur_max; @@ -1221,7 +1219,7 @@ extern AWKNUM nondec2awknum(char *str, size_t len); extern NODE *do_dcgettext(int nargs); extern NODE *do_dcngettext(int nargs); extern NODE *do_bindtextdomain(int nargs); -#ifdef MBS_SUPPORT +#if MBS_SUPPORT extern int strncasecmpmbs(const unsigned char *, const unsigned char *, size_t); #endif @@ -1359,7 +1357,7 @@ extern NODE *r_make_str_node(const char *s, unsigned long len, int scan); extern NODE *more_nodes(void); extern void unref(NODE *tmp); extern int parse_escape(const char **string_ptr); -#ifdef MBS_SUPPORT +#if MBS_SUPPORT extern NODE *str2wstr(NODE *n, size_t **ptr); extern NODE *wstr2str(NODE *n); #define force_wstring(n) str2wstr(n, NULL) @@ -4584,7 +4584,7 @@ static const struct token tokentab[] = { {"xor", Op_builtin, LEX_BUILTIN, GAWKX|A(2), do_xor}, }; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT /* Variable containing the current shift state. */ static mbstate_t cur_mbstate; /* Ring buffer containing current characters. */ @@ -5343,7 +5343,7 @@ tokexpand() /* nextc --- get the next input character */ -#ifdef MBS_SUPPORT +#if MBS_SUPPORT static int nextc(void) @@ -5431,7 +5431,7 @@ nextc() static inline void pushback(void) { -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) cur_ring_idx = (cur_ring_idx == 0)? RING_BUFFER_SIZE - 1 : cur_ring_idx - 1; @@ -5624,7 +5624,7 @@ retry: thisline = NULL; tok = tokstart; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) #endif switch (c) { @@ -1894,7 +1894,7 @@ static const struct token tokentab[] = { {"xor", Op_builtin, LEX_BUILTIN, GAWKX|A(2), do_xor}, }; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT /* Variable containing the current shift state. */ static mbstate_t cur_mbstate; /* Ring buffer containing current characters. */ @@ -2653,7 +2653,7 @@ tokexpand() /* nextc --- get the next input character */ -#ifdef MBS_SUPPORT +#if MBS_SUPPORT static int nextc(void) @@ -2741,7 +2741,7 @@ nextc() static inline void pushback(void) { -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) cur_ring_idx = (cur_ring_idx == 0)? RING_BUFFER_SIZE - 1 : cur_ring_idx - 1; @@ -2934,7 +2934,7 @@ retry: thisline = NULL; tok = tokstart; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) #endif switch (c) { @@ -214,7 +214,7 @@ do_fflush(int nargs) return make_number((AWKNUM) status); } -#ifdef MBS_SUPPORT +#if MBS_SUPPORT /* strncasecmpmbs --- like strncasecmp (multibyte string version) */ int @@ -312,7 +312,7 @@ do_index(int nargs) const char *p1, *p2; size_t l1, l2; long ret; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT int do_single_byte = FALSE; mbstate_t mbs1, mbs2; @@ -348,7 +348,7 @@ do_index(int nargs) goto out; } -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) { s1 = force_wstring(s1); s2 = force_wstring(s2); @@ -366,7 +366,7 @@ do_index(int nargs) while (l1 > 0) { if (l2 > l1) break; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (! do_single_byte && gawk_mb_cur_max > 1) { const wchar_t *pos; @@ -389,7 +389,7 @@ do_index(int nargs) } l1--; p1++; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT } #endif } @@ -402,7 +402,7 @@ do_index(int nargs) ret = 1 + s1->stlen - l1; break; } -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (! do_single_byte && gawk_mb_cur_max > 1) { const wchar_t *pos; @@ -500,7 +500,7 @@ do_length(int nargs) lintwarn(_("length: received non-string argument")); (void) force_string(tmp); -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) { tmp = force_wstring(tmp); len = tmp->wstlen; @@ -1007,7 +1007,7 @@ out0: * used to work? 6/2003.) */ cp = arg->stptr; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT /* * First character can be multiple bytes if * it's a multibyte character. Grr. @@ -1538,7 +1538,7 @@ do_substr(int nargs) if (nargs == 2) { /* third arg. missing */ /* use remainder of string */ length = t1->stlen - indx; /* default to bytes */ -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) { t1 = force_wstring(t1); if (t1->wstlen > 0) /* use length of wide char string if we have one */ @@ -1557,7 +1557,7 @@ do_substr(int nargs) } /* get total len of input string, for following checks */ -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) { t1 = force_wstring(t1); src_len = t1->wstlen; @@ -1580,7 +1580,7 @@ do_substr(int nargs) length = src_len - indx; } -#ifdef MBS_SUPPORT +#if MBS_SUPPORT /* force_wstring() already called */ if (gawk_mb_cur_max == 1 || t1->wstlen == t1->stlen) /* single byte case */ @@ -1940,7 +1940,7 @@ do_print_rec(int nargs, int redirtype) fflush(rp->fp); } -#ifdef MBS_SUPPORT +#if MBS_SUPPORT /* is_wupper --- function version of iswupper for passing function pointers */ @@ -2029,7 +2029,7 @@ do_tolower(int nargs) if (isupper(*cp)) *cp = tolower(*cp); } -#ifdef MBS_SUPPORT +#if MBS_SUPPORT else { force_wstring(t2); wide_tolower(t2->wstptr, t2->wstlen); @@ -2063,7 +2063,7 @@ do_toupper(int nargs) if (islower(*cp)) *cp = toupper(*cp); } -#ifdef MBS_SUPPORT +#if MBS_SUPPORT else { force_wstring(t2); wide_toupper(t2->wstptr, t2->wstlen); @@ -2219,7 +2219,7 @@ do_match(int nargs) size_t *wc_indices = NULL; rlength = REEND(rp, t1->stptr) - RESTART(rp, t1->stptr); /* byte length */ -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (rlength > 0 && gawk_mb_cur_max > 1) { t1 = str2wstr(t1, & wc_indices); rlength = wc_indices[rstart + rlength - 1] - wc_indices[rstart] + 1; @@ -2247,7 +2247,7 @@ do_match(int nargs) start = t1->stptr + s; subpat_start = s; subpat_len = len = SUBPATEND(rp, t1->stptr, ii) - s; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (len > 0 && gawk_mb_cur_max > 1) { subpat_start = wc_indices[s]; subpat_len = wc_indices[s + len - 1] - subpat_start + 1; @@ -3295,7 +3295,7 @@ do_bindtextdomain(int nargs) static size_t mbc_byte_count(const char *ptr, size_t numchars) { -#ifdef MBS_SUPPORT +#if MBS_SUPPORT mbstate_t cur_state; size_t sum = 0; int mb_len; @@ -3326,7 +3326,7 @@ mbc_byte_count(const char *ptr, size_t numchars) static size_t mbc_char_count(const char *ptr, size_t numbytes) { -#ifdef MBS_SUPPORT +#if MBS_SUPPORT mbstate_t cur_state; size_t sum = 0; int mb_len; @@ -68,7 +68,15 @@ #define bool int #define true (1) #define false (0) -#endif +#if ! MBS_SUPPORT +#define wctype_t int +#define wint_t int +#define mbstate_t int +#define WEOF EOF +#define towupper toupper +#define towlower tolower +#endif /* ! MBS_SUPPORT */ +#endif /* GAWK */ #include "regex.h" #include "dfa.h" @@ -543,7 +543,7 @@ posix_compare(NODE *s1, NODE *s2) * In either case, ret will be the right thing to return. */ } -#ifdef MBS_SUPPORT +#if MBS_SUPPORT else { /* Similar logic, using wide characters */ (void) force_wstring(s1); @@ -626,7 +626,7 @@ cmp_nodes(NODE *t1, NODE *t2) const unsigned char *cp1 = (const unsigned char *) t1->stptr; const unsigned char *cp2 = (const unsigned char *) t2->stptr; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) { ret = strncasecmpmbs((const unsigned char *) cp1, (const unsigned char *) cp2, l); @@ -373,7 +373,7 @@ re_parse_field(long up_to, /* parse only up to this field number */ char *end = scan + len; int regex_flags = RE_NEED_START; char *sep; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT size_t mbclen = 0; mbstate_t mbs; if (gawk_mb_cur_max > 1) @@ -405,7 +405,7 @@ re_parse_field(long up_to, /* parse only up to this field number */ && nf < up_to) { regex_flags |= RE_NO_BOL; if (REEND(rp, scan) == RESTART(rp, scan)) { /* null match */ -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) { mbclen = mbrlen(scan, end-scan, &mbs); if ((mbclen == 1) || (mbclen == (size_t) -1) @@ -617,7 +617,7 @@ null_parse_field(long up_to, /* parse only up to this field number */ if (len == 0) return nf; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) { mbstate_t mbs; memset(&mbs, 0, sizeof(mbstate_t)); @@ -669,7 +669,7 @@ sc_parse_field(long up_to, /* parse only up to this field number */ char *field; char *end = scan + len; char sav; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT size_t mbclen = 0; mbstate_t mbs; if (gawk_mb_cur_max > 1) @@ -693,7 +693,7 @@ sc_parse_field(long up_to, /* parse only up to this field number */ for (; nf < up_to;) { field = scan; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) { while (*scan != fschar) { mbclen = mbrlen(scan, end-scan, &mbs); @@ -747,7 +747,7 @@ fw_parse_field(long up_to, /* parse only up to this field number */ char *scan = *buf; long nf = parse_high_water; char *end = scan + len; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT int nmbc; size_t mbclen; size_t mbslen; @@ -763,7 +763,7 @@ fw_parse_field(long up_to, /* parse only up to this field number */ if (len == 0) return nf; for (; nf < up_to && (len = FIELDWIDTHS[nf+1]) != -1; ) { -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1) { nmbc = 0; mbslen = 0; @@ -1426,13 +1426,13 @@ set_fpat_function: * Implementation varies if doing MBS or not. */ -#ifdef MBS_SUPPORT +#if MBS_SUPPORT #define increment_scan(scanp, len) incr_scan(scanp, len, & mbs) #else #define increment_scan(scanp, len) ((*scanp)++) #endif -#ifdef MBS_SUPPORT +#if MBS_SUPPORT /* incr_scan --- MBS version of increment_scan() */ static void @@ -1578,7 +1578,7 @@ fpat_parse_field(long up_to, /* parse only up to this field number */ int need_to_set_sep; int non_empty; int eosflag; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT mbstate_t mbs; if (gawk_mb_cur_max > 1) @@ -2582,7 +2582,7 @@ rs1scan(IOBUF *iop, struct recmatch *recm, SCANSTATE *state) { char *bp; char rs; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT size_t mbclen = 0; mbstate_t mbs; #endif @@ -2596,7 +2596,7 @@ rs1scan(IOBUF *iop, struct recmatch *recm, SCANSTATE *state) if (*state == INDATA) /* skip over data we've already seen */ bp += iop->scanoff; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT /* * From: Bruno Haible <bruno@clisp.org> * To: Aharon Robbins <arnold@skeeve.com>, gnits@gnits.org @@ -148,7 +148,7 @@ int do_binary = FALSE; /* hands off my data! */ int do_sandbox = FALSE; /* sandbox mode - disable 'system' function & redirections */ int use_lc_numeric = FALSE; /* obey locale for decimal point */ -#ifdef MBS_SUPPORT +#if MBS_SUPPORT int gawk_mb_cur_max; /* MB_CUR_MAX value, see comment in main() */ #else const int gawk_mb_cur_max = 1; @@ -267,7 +267,7 @@ main(int argc, char **argv) setlocale(LC_TIME, ""); #endif -#ifdef MBS_SUPPORT +#if MBS_SUPPORT /* * In glibc, MB_CUR_MAX is actually a function. This value is * tested *a lot* in many speed-critical places in gawk. Caching @@ -556,7 +556,7 @@ out: if (do_lint && os_is_setuid()) warning(_("running %s setuid root may be a security problem"), myname); -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (do_binary) { if (do_posix) warning(_("`--posix' overrides `--binary'")); diff --git a/mbsupport.h b/mbsupport.h index 4c9e9bfb..6008da77 100644 --- a/mbsupport.h +++ b/mbsupport.h @@ -36,6 +36,8 @@ #include <stdlib.h> #endif +#ifndef NO_MBSUPPORT + #if defined(HAVE_ISWCTYPE) \ && defined(HAVE_LOCALE_H) \ && defined(HAVE_MBRLEN) \ @@ -58,6 +60,10 @@ # define MBS_SUPPORT 0 #endif +#else /* NO_MBSUPPORT is defined */ +# define MBS_SUPPORT 0 +#endif + #if ! MBS_SUPPORT # undef MB_CUR_MAX # define MB_CUR_MAX 1 @@ -297,7 +297,7 @@ dupnode(NODE *n) r->flags &= ~FIELD; r->flags |= MALLOC; r->valref = 1; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT /* * DON'T call free_wstr(r) here! * r->wstptr still points at n->wstptr's value, and we @@ -305,13 +305,13 @@ dupnode(NODE *n) */ r->wstptr = NULL; r->wstlen = 0; -#endif /* defined MBS_SUPPORT */ +#endif /* MBS_SUPPORT */ if ((n->flags & STRCUR) != 0) { emalloc(r->stptr, char *, n->stlen + 2, "dupnode"); memcpy(r->stptr, n->stptr, n->stlen); r->stptr[n->stlen] = '\0'; -#if defined MBS_SUPPORT +#if MBS_SUPPORT if ((n->flags & WSTRCUR) != 0) { r->wstlen = n->wstlen; emalloc(r->wstptr, wchar_t *, sizeof(wchar_t) * (n->wstlen + 2), "dupnode"); @@ -319,7 +319,7 @@ dupnode(NODE *n) r->wstptr[n->wstlen] = L'\0'; r->flags |= WSTRCUR; } -#endif /* defined MBS_SUPPORT */ +#endif /* MBS_SUPPORT */ } return r; @@ -354,10 +354,10 @@ r_make_str_node(const char *s, unsigned long len, int flags) r->type = Node_val; r->numbr = 0; r->flags = (STRING|STRCUR|MALLOC); -#ifdef MBS_SUPPORT +#if MBS_SUPPORT r->wstptr = NULL; r->wstlen = 0; -#endif /* defined MBS_SUPPORT */ +#endif /* MBS_SUPPORT */ if (flags & ALREADY_MALLOCED) r->stptr = (char *) s; @@ -372,7 +372,7 @@ r_make_str_node(const char *s, unsigned long len, int flags) char *ptm; int c; const char *end; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT mbstate_t cur_state; memset(& cur_state, 0, sizeof(cur_state)); @@ -380,7 +380,7 @@ r_make_str_node(const char *s, unsigned long len, int flags) end = &(r->stptr[len]); for (pf = ptm = r->stptr; pf < end;) { -#ifdef MBS_SUPPORT +#if MBS_SUPPORT /* * Keep multibyte characters together. This avoids * problems if a subsequent byte of a multibyte @@ -653,7 +653,7 @@ isnondecimal(const char *str, int use_locale) return TRUE; } -#if defined MBS_SUPPORT +#if MBS_SUPPORT /* str2wstr --- convert a multibyte string to a wide string */ NODE * @@ -902,7 +902,7 @@ out: ; return NULL; } -#endif /* defined MBS_SUPPORT */ +#endif /* MBS_SUPPORT */ /* is_ieee_magic_val --- return true for +inf, -inf, +nan, -nan */ @@ -949,7 +949,7 @@ get_ieee_magic_val(const char *val) return v; } -#ifdef MBS_SUPPORT +#if MBS_SUPPORT wint_t btowc_cache[256]; /* init_btowc_cache --- initialize the cache */ @@ -52,7 +52,7 @@ make_regexp(const char *s, size_t len, int ignorecase, int dfa, int canfatal) * It is 0, when the current character is a singlebyte character. */ size_t is_multibyte = 0; -#ifdef MBS_SUPPORT +#if MBS_SUPPORT mbstate_t mbs; if (gawk_mb_cur_max > 1) @@ -85,7 +85,7 @@ make_regexp(const char *s, size_t len, int ignorecase, int dfa, int canfatal) dest = buf; while (src < end) { -#ifdef MBS_SUPPORT +#if MBS_SUPPORT if (gawk_mb_cur_max > 1 && ! is_multibyte) { /* The previous byte is a singlebyte character, or last byte of a multibyte character. We check the next character. */ diff --git a/regex_internal.h b/regex_internal.h index 26b8abe0..b5dc7b46 100644 --- a/regex_internal.h +++ b/regex_internal.h @@ -108,14 +108,9 @@ is_blank (int c) # define SIZE_MAX ((size_t) -1) #endif -#ifndef NO_MBSUPPORT #include "mbsupport.h" /* gawk */ -#endif -#ifndef MB_CUR_MAX -#define MB_CUR_MAX 1 -#endif -#if (defined MBS_SUPPORT) || _LIBC +#if MBS_SUPPORT || _LIBC # define RE_ENABLE_I18N #endif |