use ISBLANK to test whether CHAR_T represents a blank
authorSven Verdoolaege <skimo@kotnet.org>
Sun, 16 Oct 2011 16:19:26 +0000 (16 18:19 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sun, 16 Oct 2011 16:36:37 +0000 (16 18:36 +0200)
This fixes various issues where some wide characters were incorrectly
being treated as blanks.

Reported-by: Vsevolod Kozlov <zaba@wybt.net>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
14 files changed:
common/util.c
ex/ex_argv.c
ex/ex_join.c
ex/ex_perl.c
ex/ex_subst.c
ex/ex_txt.c
ex/ex_write.c
vi/getc.c
vi/v_match.c
vi/v_replace.c
vi/v_sentence.c
vi/v_txt.c
vi/v_util.c
vi/v_word.c

index af6ff71..972a43f 100644 (file)
@@ -92,7 +92,7 @@ nonblank(SCR *sp, db_recno_t lno, size_t *cnop)
                return (0);
 
        for (cnt = off, p = &p[off],
-           len -= off; len && isblank(*p); ++cnt, ++p, --len);
+           len -= off; len && ISBLANK(*p); ++cnt, ++p, --len);
 
        /* Set the return. */
        *cnop = len ? cnt : cnt - 1;
index 1de4610..4107479 100644 (file)
@@ -105,7 +105,7 @@ argv_exp1(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen, int is_bang)
        /* If it's empty, we're done. */
        if (len != 0) {
                for (p = bp, t = bp + len; p < t; ++p)
-                       if (!isblank(*p))
+                       if (!ISBLANK(*p))
                                break;
                if (p == t)
                        goto ret;
@@ -186,7 +186,7 @@ argv_exp2(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen)
                                        break;
                } else
                        for (; n > 0; --n, ++p)
-                               if (!isblank(*p) &&
+                               if (!ISBLANK(*p) &&
                                    !isalnum(*p) && strchr(mp, *p) != NULL)
                                        break;
        }
@@ -739,7 +739,7 @@ alloc_err:  rval = SEXP_ERR;
                rval = SEXP_EXPANSION_ERR;
 
        for (p = bp; len; ++p, --len)
-               if (!isblank(*p))
+               if (!ISBLANK(*p))
                        break;
        if (len == 0)
                rval = SEXP_EXPANSION_ERR;
index 5420b31..c049335 100644 (file)
@@ -36,9 +36,10 @@ ex_join(SCR *sp, EXCMD *cmdp)
 {
        db_recno_t from, to;
        size_t blen, clen, len, tlen;
-       int echar, extra, first;
+       int extra, first;
        CHAR_T *bp, *tbp;
        CHAR_T *p;
+       CHAR_T echar;
 
        NEEDFILE(sp, cmdp);
 
@@ -103,8 +104,8 @@ ex_join(SCR *sp, EXCMD *cmdp)
                 */
                extra = 0;
                if (!first && !FL_ISSET(cmdp->iflags, E_C_FORCE)) {
-                       if (isblank(echar))
-                               for (; len && isblank(*p); --len, ++p);
+                       if (ISBLANK(echar))
+                               for (; len && ISBLANK(*p); --len, ++p);
                        else if (p[0] != ')') {
                                if (strchr(".?!", echar)) {
                                        *tbp++ = ' ';
@@ -113,7 +114,7 @@ ex_join(SCR *sp, EXCMD *cmdp)
                                }
                                *tbp++ = ' ';
                                ++clen;
-                               for (; len && isblank(*p); --len, ++p);
+                               for (; len && ISBLANK(*p); --len, ++p);
                        }
                }
 
index 872045e..c08d5cd 100644 (file)
@@ -51,7 +51,7 @@ ex_perl(SCR *sp, EXCMD *cmdp)
        if (cmdp->argc != 0)
                for (p = cmdp->argv[0]->bp,
                    len = cmdp->argv[0]->len; len > 0; --len, ++p)
-                       if (!isblank(*p))
+                       if (!ISBLANK(*p))
                                break;
        if (cmdp->argc == 0 || len == 0) {
                ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
index 61711af..c934dd8 100644 (file)
@@ -71,7 +71,7 @@ ex_s(SCR *sp, EXCMD *cmdp)
                goto subagain;
        for (p = cmdp->argv[0]->bp,
            len = cmdp->argv[0]->len; len > 0; --len, ++p) {
-               if (!isblank(*p))
+               if (!ISBLANK(*p))
                        break;
        }
        if (len == 0)
index f551ee5..1152d7f 100644 (file)
@@ -246,7 +246,7 @@ notlast:                    CIRCLEQ_REMOVE(tiqh, tp, q);
                         */
                        if (LF_ISSET(TXT_CNTRLD)) {
                                for (cnt = 0; cnt < tp->len; ++cnt)
-                                       if (!isblank(tp->lb[cnt]))
+                                       if (!ISBLANK(tp->lb[cnt]))
                                                break;
                                if (cnt == tp->len) {
                                        tp->len = 1;
index b8e9e6a..8992ef5 100644 (file)
@@ -142,7 +142,7 @@ exwr(SCR *sp, EXCMD *cmdp, enum which cmd)
 
        /* Skip any leading whitespace. */
        if (cmdp->argc != 0)
-               for (p = cmdp->argv[0]->bp; *p != '\0' && isblank(*p); ++p);
+               for (p = cmdp->argv[0]->bp; *p != '\0' && ISBLANK(*p); ++p);
 
        /* If "write !" it's a pipe to a utility. */
        if (cmdp->argc != 0 && cmd == WRITE && *p == '!') {
@@ -153,7 +153,7 @@ exwr(SCR *sp, EXCMD *cmdp, enum which cmd)
                }
 
                /* Expand the argument. */
-               for (++p; *p && isblank(*p); ++p);
+               for (++p; *p && ISBLANK(*p); ++p);
                if (*p == '\0') {
                        ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
                        return (1);
@@ -194,7 +194,7 @@ exwr(SCR *sp, EXCMD *cmdp, enum which cmd)
                LF_SET(FS_APPEND);
 
                /* Skip ">>" and whitespace. */
-               for (p += 2; *p && isblank(*p); ++p);
+               for (p += 2; *p && ISBLANK(*p); ++p);
        }
 
        /* If no other arguments, just write the file back. */
index 50b0214..399b2f1 100644 (file)
--- a/vi/getc.c
+++ b/vi/getc.c
@@ -121,12 +121,12 @@ cs_next(SCR *sp, VCS *csp)
 int
 cs_fspace(SCR *sp, VCS *csp)
 {
-       if (csp->cs_flags != 0 || !isblank(csp->cs_ch))
+       if (csp->cs_flags != 0 || !ISBLANK(csp->cs_ch))
                return (0);
        for (;;) {
                if (cs_next(sp, csp))
                        return (1);
-               if (csp->cs_flags != 0 || !isblank(csp->cs_ch))
+               if (csp->cs_flags != 0 || !ISBLANK(csp->cs_ch))
                        break;
        }
        return (0);
@@ -145,7 +145,7 @@ cs_fblank(SCR *sp, VCS *csp)
                if (cs_next(sp, csp))
                        return (1);
                if (csp->cs_flags == CS_EOL || csp->cs_flags == CS_EMP ||
-                   csp->cs_flags == 0 && isblank(csp->cs_ch))
+                   csp->cs_flags == 0 && ISBLANK(csp->cs_ch))
                        continue;
                break;
        }
@@ -214,7 +214,7 @@ cs_bblank(SCR *sp, VCS *csp)
                if (cs_prev(sp, csp))
                        return (1);
                if (csp->cs_flags == CS_EOL || csp->cs_flags == CS_EMP ||
-                   csp->cs_flags == 0 && isblank(csp->cs_ch))
+                   csp->cs_flags == 0 && ISBLANK(csp->cs_ch))
                        continue;
                break;
        }
index 81d6b5e..2cbebd7 100644 (file)
@@ -161,7 +161,7 @@ nomatch:            msgq(sp, M_BERR, "184|No match character on this line");
        if (db_get(sp, mp->lno, DBG_FATAL, &p, &len))
                return (1);
        for (p += mp->cno + 1, len -= mp->cno; --len; ++p)
-               if (!isblank(*p))
+               if (!ISBLANK(*p))
                        return (0);
        F_SET(vp, VM_LMODE);
        return (0);
index 66ec12a..722cedc 100644 (file)
@@ -172,7 +172,7 @@ next:               if (v_event_get(sp, &ev, 0, 0))
                p += vp->m_start.cno + cnt;
                len -= vp->m_start.cno + cnt;
                if (len != 0 && O_ISSET(sp, O_AUTOINDENT))
-                       for (; len && isblank(*p); --len, ++p);
+                       for (; len && ISBLANK(*p); --len, ++p);
 
                if ((tp = text_init(sp, p, len, len)) == NULL)
                        goto err_ret;
index c19d386..b824988 100644 (file)
@@ -72,7 +72,7 @@ v_sentencef(SCR *sp, VICMD *vp)
         * This may not handle "  .  " correctly, but it's real unclear
         * what correctly means in that case.
         */
-       if (cs.cs_flags == CS_EMP || cs.cs_flags == 0 && isblank(cs.cs_ch)) {
+       if (cs.cs_flags == CS_EMP || cs.cs_flags == 0 && ISBLANK(cs.cs_ch)) {
                if (cs_fblank(sp, &cs))
                        return (1);
                if (--cnt == 0) {
@@ -93,7 +93,7 @@ v_sentencef(SCR *sp, VICMD *vp)
                                if (cs_next(sp, &cs))
                                        return (1);
                                if (cs.cs_flags == 0 &&
-                                   isblank(cs.cs_ch) && cs_fblank(sp, &cs))
+                                   ISBLANK(cs.cs_ch) && cs_fblank(sp, &cs))
                                        return (1);
                                goto okret;
                        }
@@ -233,11 +233,11 @@ v_sentenceb(SCR *sp, VICMD *vp)
                        if (cs.cs_flags != CS_EOL)
                                break;
                }
-       } else if (cs.cs_flags == 0 && !isblank(cs.cs_ch))
+       } else if (cs.cs_flags == 0 && !ISBLANK(cs.cs_ch))
                for (;;) {
                        if (cs_prev(sp, &cs))
                                return (1);
-                       if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+                       if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
                                break;
                }
 
@@ -280,7 +280,7 @@ ret:                        slno = cs.cs_lno;
                        } while (!cs.cs_flags &&
                            (cs.cs_ch == ')' || cs.cs_ch == ']' ||
                            cs.cs_ch == '"' || cs.cs_ch == '\''));
-                       if ((cs.cs_flags || isblank(cs.cs_ch)) &&
+                       if ((cs.cs_flags || ISBLANK(cs.cs_ch)) &&
                            cs_fblank(sp, &cs))
                                return (1);
 
@@ -303,7 +303,7 @@ ret:                        slno = cs.cs_lno;
                                        return (1);
                                if (cs.cs_flags == CS_EOL)
                                        continue;
-                               if (cs.cs_flags == 0 && isblank(cs.cs_ch))
+                               if (cs.cs_flags == 0 && ISBLANK(cs.cs_ch))
                                        continue;
                                break;
                        }
@@ -321,7 +321,7 @@ ret:                        slno = cs.cs_lno;
                        break;
                default:
                        last =
-                           cs.cs_flags == CS_EOL || isblank(cs.cs_ch) ||
+                           cs.cs_flags == CS_EOL || ISBLANK(cs.cs_ch) ||
                            cs.cs_ch == ')' || cs.cs_ch == ']' ||
                            cs.cs_ch == '"' || cs.cs_ch == '\'' ? 1 : 0;
                }
index 65e33e1..2fd7b83 100644 (file)
@@ -750,16 +750,16 @@ k_cr:             if (LF_ISSET(TXT_CR)) {
                owrite = tp->owrite;
                insert = tp->insert;
                if (LF_ISSET(TXT_REPLACE) && owrite != 0) {
-                       for (p = tp->lb + tp->cno; owrite > 0 && isblank(*p);
+                       for (p = tp->lb + tp->cno; owrite > 0 && ISBLANK(*p);
                            ++p, --owrite, ++tp->R_erase);
                        if (owrite == 0)
-                               for (; insert > 0 && isblank(*p);
+                               for (; insert > 0 && ISBLANK(*p);
                                    ++p, ++tp->R_erase, --insert);
                } else {
                        p = tp->lb + tp->cno + owrite;
                        if (O_ISSET(sp, O_AUTOINDENT))
                                for (; insert > 0 &&
-                                   isblank(*p); ++p, --insert);
+                                   ISBLANK(*p); ++p, --insert);
                        owrite = 0;
                }
 
@@ -1079,7 +1079,7 @@ leftmargin:               tp->lb[tp->cno - 1] = ' ';
                }
 
                /* Skip over trailing space characters. */
-               while (tp->cno > max && isblank(tp->lb[tp->cno - 1])) {
+               while (tp->cno > max && ISBLANK(tp->lb[tp->cno - 1])) {
                        --tp->cno;
                        ++tp->owrite;
                }
@@ -1112,7 +1112,7 @@ leftmargin:               tp->lb[tp->cno - 1] = ' ';
                                ++tp->owrite;
                                if (FL_ISSET(is_flags, IS_RUNNING))
                                        tp->lb[tp->cno] = ' ';
-                               if (isblank(tp->lb[tp->cno - 1]))
+                               if (ISBLANK(tp->lb[tp->cno - 1]))
                                        break;
                        }
                else {
@@ -1121,7 +1121,7 @@ leftmargin:               tp->lb[tp->cno - 1] = ' ';
                                ++tp->owrite;
                                if (FL_ISSET(is_flags, IS_RUNNING))
                                        tp->lb[tp->cno] = ' ';
-                               if (isblank(tp->lb[tp->cno - 1]))
+                               if (ISBLANK(tp->lb[tp->cno - 1]))
                                        break;
                        }
                        if (tp->cno > max)
@@ -1132,7 +1132,7 @@ leftmargin:               tp->lb[tp->cno - 1] = ' ';
                                if (FL_ISSET(is_flags, IS_RUNNING))
                                        tp->lb[tp->cno] = ' ';
                                if (tmp != inword(tp->lb[tp->cno - 1])
-                                   || isblank(tp->lb[tp->cno - 1]))
+                                   || ISBLANK(tp->lb[tp->cno - 1]))
                                        break;
                        }
                }
@@ -1291,7 +1291,7 @@ insq_ch:  /*
                                        goto resolve;
                                }
                        }
-                       if (isblank(evp->e_c) && UNMAP_TST)
+                       if (ISBLANK(evp->e_c) && UNMAP_TST)
                                txt_unmap(sp, tp, &ec_flags);
                }
                if (abb != AB_NOTSET)
@@ -1341,7 +1341,7 @@ insl_ch:  if (txt_insch(sp, tp, &evp->e_c, flags))
                                if (txt_margin(sp, tp, &wmt, &tmp, flags))
                                        goto err;
                                if (tmp) {
-                                       if (isblank(evp->e_c))
+                                       if (ISBLANK(evp->e_c))
                                                wm_skip = 1;
                                        wm_set = 1;
                                        goto k_cr;
@@ -1507,7 +1507,7 @@ txt_abbrev(SCR *sp, TEXT *tp, CHAR_T *pushcp, int isinfoline, int *didsubp, int
        off = tp->cno - 1;                      /* Previous character. */
        p = tp->lb + off;
        len = 1;                                /* One character test. */
-       if (off == tp->offset || isblank(p[-1]))
+       if (off == tp->offset || ISBLANK(p[-1]))
                goto search;
        if (inword(p[-1]))                      /* Move backward to change. */
                for (;;) {
@@ -1519,7 +1519,7 @@ txt_abbrev(SCR *sp, TEXT *tp, CHAR_T *pushcp, int isinfoline, int *didsubp, int
                for (;;) {
                        --off; --p; ++len;
                        if (off == tp->offset ||
-                           inword(p[-1]) || isblank(p[-1]))
+                           inword(p[-1]) || ISBLANK(p[-1]))
                                break;
                }
 
@@ -1643,7 +1643,7 @@ txt_unmap(SCR *sp, TEXT *tp, u_int32_t *ec_flagsp)
 
        /* Find the beginning of this "word". */
        for (off = tp->cno - 1, p = tp->lb + off, len = 0;; --p, --off) {
-               if (isblank(*p)) {
+               if (ISBLANK(*p)) {
                        ++p;
                        break;
                }
@@ -1710,7 +1710,7 @@ txt_ai_resolve(SCR *sp, TEXT *tp, int *changedp)
 
        /* Figure out the last <blank> screen column. */
        for (p = tp->lb, scno = 0, len = tp->len,
-           spaces = tab_after_sp = 0; len-- && isblank(*p); ++p)
+           spaces = tab_after_sp = 0; len-- && ISBLANK(*p); ++p)
                if (*p == '\t') {
                        if (spaces)
                                tab_after_sp = 1;
@@ -1785,7 +1785,7 @@ v_txt_auto(SCR *sp, db_recno_t lno, TEXT *aitp, size_t len, TEXT *tp)
 
        /* Count whitespace characters. */
        for (p = t; len > 0; ++p, --len)
-               if (!isblank(*p))
+               if (!ISBLANK(*p))
                        break;
 
        /* Set count, check for no indentation. */
@@ -2012,7 +2012,7 @@ txt_fc(SCR *sp, TEXT *tp, int *redrawp)
        } else
 retry:         for (len = 0,
                    off = tp->cno - 1, p = tp->lb + off;; --off, --p) {
-                       if (isblank(*p)) {
+                       if (ISBLANK(*p)) {
                                ++p;
                                break;
                        }
@@ -2787,7 +2787,7 @@ txt_margin(SCR *sp, TEXT *tp, TEXT *wmtp, int *didbreak, u_int32_t flags)
 
        /* Find the nearest previous blank. */
        for (off = tp->cno - 1, p = tp->lb + off, len = 0;; --off, --p, ++len) {
-               if (isblank(*p)) {
+               if (ISBLANK(*p)) {
                        wp = p + 1;
                        break;
                }
@@ -2839,7 +2839,7 @@ txt_margin(SCR *sp, TEXT *tp, TEXT *wmtp, int *didbreak, u_int32_t flags)
         * Delete any trailing whitespace from the current line.
         */
        for (;; --p, --off) {
-               if (!isblank(*p))
+               if (!ISBLANK(*p))
                        break;
                --tp->cno;
                --tp->len;
index 9d03be3..8445e2a 100644 (file)
@@ -123,7 +123,7 @@ int
 v_isempty(CHAR_T *p, size_t len)
 {
        for (; len--; ++p)
-               if (!isblank(*p))
+               if (!ISBLANK(*p))
                        return (0);
        return (1);
 }
index d9b166a..0db8658 100644 (file)
@@ -118,7 +118,7 @@ fword(SCR *sp, VICMD *vp, enum which type)
         *      counts as a single word move.  If it's a motion command,
         *      don't move off the end of the line.
         */
-       if (cs.cs_flags == CS_EMP || cs.cs_flags == 0 && isblank(cs.cs_ch)) {
+       if (cs.cs_flags == CS_EMP || cs.cs_flags == 0 && ISBLANK(cs.cs_ch)) {
                if (ISMOTION(vp) && cs.cs_flags != CS_EMP && cnt == 1) {
                        if (ISCMD(vp->rkp, 'c'))
                                return (0);
@@ -146,7 +146,7 @@ fword(SCR *sp, VICMD *vp, enum which type)
                                        return (1);
                                if (cs.cs_flags == CS_EOF)
                                        goto ret;
-                               if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+                               if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
                                        break;
                        }
                        /*
@@ -178,7 +178,7 @@ fword(SCR *sp, VICMD *vp, enum which type)
                                        return (1);
                                if (cs.cs_flags == CS_EOF)
                                        goto ret;
-                               if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+                               if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
                                        break;
                                if (state == INWORD) {
                                        if (!inword(cs.cs_ch))
@@ -197,7 +197,7 @@ fword(SCR *sp, VICMD *vp, enum which type)
                        }
 
                        /* Eat whitespace characters. */
-                       if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+                       if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
                                if (cs_fblank(sp, &cs))
                                        return (1);
                        if (cs.cs_flags == CS_EOF)
@@ -277,10 +277,10 @@ eword(SCR *sp, VICMD *vp, enum which type)
         * it.  (This doesn't count as a word move.)  Stay at the character
         * past the current one, it sets word "state" for the 'e' command.
         */
-       if (cs.cs_flags == 0 && !isblank(cs.cs_ch)) {
+       if (cs.cs_flags == 0 && !ISBLANK(cs.cs_ch)) {
                if (cs_next(sp, &cs))
                        return (1);
-               if (cs.cs_flags == 0 && !isblank(cs.cs_ch))
+               if (cs.cs_flags == 0 && !ISBLANK(cs.cs_ch))
                        goto start;
        }
        if (cs_fblank(sp, &cs))
@@ -299,7 +299,7 @@ start:      if (type == BIGWORD)
                                        return (1);
                                if (cs.cs_flags == CS_EOF)
                                        goto ret;
-                               if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+                               if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
                                        break;
                        }
                        /*
@@ -328,7 +328,7 @@ start:      if (type == BIGWORD)
                                        return (1);
                                if (cs.cs_flags == CS_EOF)
                                        goto ret;
-                               if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+                               if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
                                        break;
                                if (state == INWORD) {
                                        if (!inword(cs.cs_ch))
@@ -345,7 +345,7 @@ start:      if (type == BIGWORD)
                        }
 
                        /* Eat whitespace characters. */
-                       if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+                       if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
                                if (cs_fblank(sp, &cs))
                                        return (1);
                        if (cs.cs_flags == CS_EOF)
@@ -424,10 +424,10 @@ bword(SCR *sp, VICMD *vp, enum which type)
         * character before the current one, it sets word "state" for the
         * 'b' command.
         */
-       if (cs.cs_flags == 0 && !isblank(cs.cs_ch)) {
+       if (cs.cs_flags == 0 && !ISBLANK(cs.cs_ch)) {
                if (cs_prev(sp, &cs))
                        return (1);
-               if (cs.cs_flags == 0 && !isblank(cs.cs_ch))
+               if (cs.cs_flags == 0 && !ISBLANK(cs.cs_ch))
                        goto start;
        }
        if (cs_bblank(sp, &cs))
@@ -446,7 +446,7 @@ start:      if (type == BIGWORD)
                                        return (1);
                                if (cs.cs_flags == CS_SOF)
                                        goto ret;
-                               if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+                               if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
                                        break;
                        }
                        /*
@@ -475,7 +475,7 @@ start:      if (type == BIGWORD)
                                        return (1);
                                if (cs.cs_flags == CS_SOF)
                                        goto ret;
-                               if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+                               if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
                                        break;
                                if (state == INWORD) {
                                        if (!inword(cs.cs_ch))
@@ -492,7 +492,7 @@ start:      if (type == BIGWORD)
                        }
 
                        /* Eat whitespace characters. */
-                       if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+                       if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
                                if (cs_bblank(sp, &cs))
                                        return (1);
                        if (cs.cs_flags == CS_SOF)