2004-07-23 Stepan Kasal * awk.h (gawk_mb_cur_max): Without mbs support, define to 1. This fixes a bug in re.c where #ifdef MBS_SUPPORT was missing. * awkgram.y (nextc_is_1stbyte): Without mbs support, define to 1. * builtin.c (index_multibyte_buffer): Define a dummy function when there is no mbs support. * awkgram.y, builtin.c, re.c: Remove some `#ifdef MBS_SUPPORT'. diff -crpaN gawk-3.1.3l.a0/awk.h gawk-3.1.3l.a1/awk.h *** gawk-3.1.3l.a0/awk.h 2004-07-08 11:58:40.000000000 +0200 --- gawk-3.1.3l.a1/awk.h 2004-07-23 11:10:25.854620000 +0200 *************** extern int do_lint_old; *** 720,725 **** --- 720,727 ---- #endif #ifdef MBS_SUPPORT extern int gawk_mb_cur_max; + #else + #define gawk_mb_cur_max 1 #endif #if defined (HAVE_GETGROUPS) && defined(NGROUPS_MAX) && NGROUPS_MAX > 0 diff -crpaN gawk-3.1.3l.a0/awkgram.y gawk-3.1.3l.a1/awkgram.y *** gawk-3.1.3l.a0/awkgram.y 2004-07-15 11:46:35.000000000 +0200 --- gawk-3.1.3l.a1/awkgram.y 2004-07-23 11:21:23.151715000 +0200 *************** static int cur_ring_idx; *** 1105,1110 **** --- 1105,1113 ---- /* This macro means that last nextc() return a singlebyte character or 1st byte of a multibyte character. */ #define nextc_is_1stbyte (cur_char_ring[cur_ring_idx] == 1) + #else /* MBS_SUPPORT */ + /* a dummy */ + #define nextc_is_1stbyte 1 #endif /* MBS_SUPPORT */ /* getfname --- return name of a builtin function (for pretty printing) */ *************** nextc(void) *** 1522,1545 **** /* pushback --- push a character back on the input */ ! #ifdef MBS_SUPPORT ! ! static void pushback(void) { ! if (gawk_mb_cur_max > 1) { cur_ring_idx = (cur_ring_idx == 0)? RING_BUFFER_SIZE - 1 : cur_ring_idx - 1; ! (lexptr && lexptr > lexptr_begin ? lexptr-- : lexptr); ! } else ! (lexptr && lexptr > lexptr_begin ? lexptr-- : lexptr); } - #else - - #define pushback() (lexptr && lexptr > lexptr_begin ? lexptr-- : lexptr) - - #endif /* MBS_SUPPORT */ /* allow_newline --- allow newline after &&, ||, ? and : */ --- 1525,1541 ---- /* pushback --- push a character back on the input */ ! static inline void pushback(void) { ! #ifdef MBS_SUPPORT ! if (gawk_mb_cur_max > 1) cur_ring_idx = (cur_ring_idx == 0)? RING_BUFFER_SIZE - 1 : cur_ring_idx - 1; ! #endif ! (lexptr && lexptr > lexptr_begin ? lexptr-- : lexptr); } /* allow_newline --- allow newline after &&, ||, ? and : */ *************** yylex(void) *** 1630,1639 **** tok = tokstart; for (;;) { c = nextc(); ! #ifdef MBS_SUPPORT ! if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) ! #endif ! switch (c) { case '[': /* one day check for `.' and `=' too */ if (nextc() == ':' || in_brack == 0) --- 1626,1633 ---- tok = tokstart; for (;;) { c = nextc(); ! ! if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) switch (c) { case '[': /* one day check for `.' and `=' too */ if (nextc() == ':' || in_brack == 0) *************** retry: *** 1689,1698 **** tok = tokstart; yylval.nodetypeval = Node_illegal; ! #ifdef MBS_SUPPORT ! if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) ! #endif ! switch (c) { case EOF: if (lasttok != NEWLINE) { lasttok = NEWLINE; --- 1683,1689 ---- tok = tokstart; yylval.nodetypeval = Node_illegal; ! if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) switch (c) { case EOF: if (lasttok != NEWLINE) { lasttok = NEWLINE; *************** retry: *** 1937,1946 **** yyerror(_("unterminated string")); exit(1); } ! #ifdef MBS_SUPPORT ! if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) ! #endif ! if (c == '\\') { c = nextc(); if (c == '\n') { sourceline++; --- 1928,1935 ---- yyerror(_("unterminated string")); exit(1); } ! if ((gawk_mb_cur_max == 1 || nextc_is_1stbyte) && ! c == '\\') { c = nextc(); if (c == '\n') { sourceline++; diff -crpaN gawk-3.1.3l.a0/builtin.c gawk-3.1.3l.a1/builtin.c *** gawk-3.1.3l.a0/builtin.c 2004-07-13 09:55:28.000000000 +0200 --- gawk-3.1.3l.a1/builtin.c 2004-07-23 11:40:12.274426000 +0200 *************** index_multibyte_buffer(char* src, char* *** 310,315 **** --- 310,322 ---- dest[idx] = mbclen; } } + #else + /* a dummy function */ + static void + index_multibyte_buffer(char* src ATTRIBUTE_UNUSED, char* dest ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED) + { + cant_happen(); + } #endif /* do_index --- find index of a string */ *************** do_index(NODE *tree) *** 330,336 **** } #endif - s1 = tree_eval(tree->lnode); s2 = tree_eval(tree->rnode->lnode); if (do_lint) { --- 337,342 ---- *************** sub_common(NODE *tree, long how_many, in *** 2079,2087 **** int global = (how_many == -1); long current; int lastmatchnonzero; ! #ifdef MBS_SUPPORT ! char *mb_indices; ! #endif tmp = tree->lnode; /* regexp */ rp = re_update(tmp); --- 2085,2091 ---- int global = (how_many == -1); long current; int lastmatchnonzero; ! char *mb_indices = NULL; tmp = tree->lnode; /* regexp */ rp = re_update(tmp); *************** sub_common(NODE *tree, long how_many, in *** 2126,2132 **** buf[buflen] = '\0'; buf[buflen + 1] = '\0'; ampersands = 0; ! #ifdef MBS_SUPPORT /* * Some systems' malloc() can't handle being called with an * argument of zero. Thus we have to have some special case --- 2130,2136 ---- buf[buflen] = '\0'; buf[buflen + 1] = '\0'; ampersands = 0; ! /* * Some systems' malloc() can't handle being called with an * argument of zero. Thus we have to have some special case *************** sub_common(NODE *tree, long how_many, in *** 2138,2153 **** if (gawk_mb_cur_max > 1 && repllen > 0) { emalloc(mb_indices, char *, repllen * sizeof(char), "sub_common"); index_multibyte_buffer(repl, mb_indices, repllen); ! } else ! mb_indices = NULL; ! #endif for (scan = repl; scan < replend; scan++) { - #ifdef MBS_SUPPORT if ((gawk_mb_cur_max == 1 || (repllen > 0 && mb_indices[scan - repl] == 1)) ! && (*scan == '&')) { ! #else ! if (*scan == '&') { ! #endif repllen--; ampersands++; } else if (*scan == '\\') { --- 2142,2152 ---- if (gawk_mb_cur_max > 1 && repllen > 0) { emalloc(mb_indices, char *, repllen * sizeof(char), "sub_common"); index_multibyte_buffer(repl, mb_indices, repllen); ! } ! for (scan = repl; scan < replend; scan++) { if ((gawk_mb_cur_max == 1 || (repllen > 0 && mb_indices[scan - repl] == 1)) ! && (*scan == '&')) { repllen--; ampersands++; } else if (*scan == '\\') { *************** sub_common(NODE *tree, long how_many, in *** 2230,2251 **** */ for (scan = repl; scan < replend; scan++) if (*scan == '&' - #ifdef MBS_SUPPORT /* * Don't test repllen here. A simple "&" could * end up with repllen == 0. */ && (gawk_mb_cur_max == 1 || mb_indices[scan - repl] == 1) - #endif ) { for (cp = matchstart; cp < matchend; cp++) *bp++ = *cp; } else if (*scan == '\\' - #ifdef MBS_SUPPORT && (gawk_mb_cur_max == 1 || (repllen > 0 && mb_indices[scan - repl] == 1)) - #endif ) { if (backdigs) { /* gensub, behave sanely */ if (ISDIGIT(scan[1])) { --- 2229,2246 ---- *************** sub_common(NODE *tree, long how_many, in *** 2338,2347 **** (*after_assign)(); t->flags &= ~(NUMCUR|NUMBER); } - #ifdef MBS_SUPPORT if (mb_indices != NULL) free(mb_indices); ! #endif return tmp_number((AWKNUM) matches); } --- 2333,2341 ---- (*after_assign)(); t->flags &= ~(NUMCUR|NUMBER); } if (mb_indices != NULL) free(mb_indices); ! return tmp_number((AWKNUM) matches); } diff -crpaN gawk-3.1.3l.a0/main.c gawk-3.1.3l.a1/main.c *** gawk-3.1.3l.a0/main.c 2004-06-07 15:40:54.000000000 +0200 --- gawk-3.1.3l.a1/main.c 2004-07-23 11:10:10.480653000 +0200 *************** main(int argc, char **argv) *** 249,254 **** --- 249,255 ---- * this value once makes a speed difference. */ gawk_mb_cur_max = MB_CUR_MAX; + /* Without MBS_SUPPORT, gawk_mb_cur_max is defined to 1. */ #endif (void) bindtextdomain(PACKAGE, LOCALEDIR); diff -crpaN gawk-3.1.3l.a0/re.c gawk-3.1.3l.a1/re.c *** gawk-3.1.3l.a0/re.c 2004-07-15 11:51:34.000000000 +0200 --- gawk-3.1.3l.a1/re.c 2004-07-23 11:44:28.629532000 +0200 *************** make_regexp(const char *s, size_t len, i *** 42,51 **** static short first = TRUE; static short no_dfa = FALSE; int has_anchor = FALSE; ! #ifdef MBS_SUPPORT /* The number of bytes in the current multbyte character. It is 0, when the current character is a singlebyte character. */ size_t is_multibyte = 0; mbstate_t mbs; if (gawk_mb_cur_max > 1) --- 42,52 ---- static short first = TRUE; static short no_dfa = FALSE; int has_anchor = FALSE; ! /* The number of bytes in the current multbyte character. It is 0, when the current character is a singlebyte character. */ size_t is_multibyte = 0; + #ifdef MBS_SUPPORT mbstate_t mbs; if (gawk_mb_cur_max > 1) *************** make_regexp(const char *s, size_t len, i *** 81,92 **** } #endif - if ( - #ifdef MBS_SUPPORT /* We skip multibyte character, since it must not be a special character. */ ! (gawk_mb_cur_max == 1 || ! is_multibyte) && ! #endif (*src == '\\')) { c = *++src; switch (c) { --- 82,90 ---- } #endif /* We skip multibyte character, since it must not be a special character. */ ! if ((gawk_mb_cur_max == 1 || ! is_multibyte) && (*src == '\\')) { c = *++src; switch (c) { *************** make_regexp(const char *s, size_t len, i *** 145,154 **** has_anchor = TRUE; *dest++ = *src++; /* not '\\' */ } - #ifdef MBS_SUPPORT if (gawk_mb_cur_max > 1 && is_multibyte) is_multibyte--; - #endif } /* while */ *dest = '\0' ; /* Only necessary if we print dest ? */ --- 143,150 ----