Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/dist/nvi 1. fix PR/44455, nonprintable character doesn't sho...



details:   https://anonhg.NetBSD.org/src/rev/068fd3503f2a
branches:  trunk
changeset: 763476:068fd3503f2a
user:      tnozaki <tnozaki%NetBSD.org@localhost>
date:      Mon Mar 21 14:53:02 2011 +0000

description:
1. fix PR/44455, nonprintable character doesn't show hex-visual
   under big endian.
2. ":set octal" with nonprintable character causes nbwcurses move error.
3. moving (big)words by wW/eE/bB can't handle non-ascii characters.
4. toggle uppercase/lowercase by ~ can't handle non-ascii characters.
5. don't feed CHAR_T(=wchar_t) to is* function directly.
   is* funcs with over UCHAR_MAX value may cause undefined behavior.
   some ctype implementation(such as FreeBSD) return unexpected
   result(same result as isw* func).
6. using non-ascii digit character with count/line number of ex/vi
   command may causes unexpeced result.

diffstat:

 dist/nvi/clib/mkstemp.c     |   4 +-
 dist/nvi/common/cut.c       |   6 +-
 dist/nvi/common/cut.h       |  10 +++---
 dist/nvi/common/extern.h    |   4 +-
 dist/nvi/common/gs.h        |  23 ++++++--------
 dist/nvi/common/key.c       |  64 +++++++++++++++++----------------------
 dist/nvi/common/key.h       |  63 +------------------------------------
 dist/nvi/common/msg.c       |  10 +++---
 dist/nvi/common/multibyte.h |  73 +++++++++++++++++++++++++++++++++++---------
 dist/nvi/common/options.c   |   4 +-
 dist/nvi/common/seq.c       |  16 ++++----
 dist/nvi/common/util.c      |   4 +-
 dist/nvi/ex/ex.c            |  64 +++++++++++++++++++-------------------
 dist/nvi/ex/ex_abbrev.c     |   4 +-
 dist/nvi/ex/ex_argv.c       |  17 +++++----
 dist/nvi/ex/ex_cscope.c     |   8 ++--
 dist/nvi/ex/ex_display.c    |   6 +-
 dist/nvi/ex/ex_global.c     |   4 +-
 dist/nvi/ex/ex_join.c       |  13 ++++---
 dist/nvi/ex/ex_map.c        |   6 +-
 dist/nvi/ex/ex_perl.c       |   4 +-
 dist/nvi/ex/ex_shell.c      |   7 ++-
 dist/nvi/ex/ex_subst.c      |  18 +++++-----
 dist/nvi/ex/ex_tag.c        |   4 +-
 dist/nvi/ex/ex_tcl.c        |   4 +-
 dist/nvi/ex/ex_txt.c        |   4 +-
 dist/nvi/ex/ex_usage.c      |  10 +++---
 dist/nvi/ex/ex_write.c      |   8 ++--
 dist/nvi/ip/ip_main.c       |   6 +-
 dist/nvi/motif_l/m_vi.c     |  12 +++---
 dist/nvi/regex/regcomp.c    |  14 ++++----
 dist/nvi/regex/regex2.h     |   4 +-
 dist/nvi/vi/getc.c          |  10 +++---
 dist/nvi/vi/v_increment.c   |  22 ++++++-------
 dist/nvi/vi/v_match.c       |   4 +-
 dist/nvi/vi/v_replace.c     |   4 +-
 dist/nvi/vi/v_search.c      |   4 +-
 dist/nvi/vi/v_sentence.c    |  16 ++++----
 dist/nvi/vi/v_txt.c         |  50 +++++++++++++++---------------
 dist/nvi/vi/v_ulcase.c      |   8 ++--
 dist/nvi/vi/v_util.c        |   4 +-
 dist/nvi/vi/v_word.c        |  30 +++++++++---------
 dist/nvi/vi/vi.c            |  10 +++---
 dist/nvi/vi/vi.h            |  17 +++------
 44 files changed, 323 insertions(+), 354 deletions(-)

diffs (truncated from 2195 to 300 lines):

diff -r 8dfe103122b8 -r 068fd3503f2a dist/nvi/clib/mkstemp.c
--- a/dist/nvi/clib/mkstemp.c   Mon Mar 21 12:53:50 2011 +0000
+++ b/dist/nvi/clib/mkstemp.c   Mon Mar 21 14:53:02 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkstemp.c,v 1.1.1.2 2008/05/18 14:29:38 aymeric Exp $ */
+/*     $NetBSD: mkstemp.c,v 1.2 2011/03/21 14:53:02 tnozaki Exp $ */
 
 /*
  * Copyright (c) 1987, 1993
@@ -119,7 +119,7 @@
                        if (*trv == 'z')
                                *trv++ = 'a';
                        else {
-                               if (isdigit(*trv))
+                               if (isdigit((unsigned char)*trv))
                                        *trv = 'a';
                                else
                                        ++*trv;
diff -r 8dfe103122b8 -r 068fd3503f2a dist/nvi/common/cut.c
--- a/dist/nvi/common/cut.c     Mon Mar 21 12:53:50 2011 +0000
+++ b/dist/nvi/common/cut.c     Mon Mar 21 14:53:02 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cut.c,v 1.3 2009/12/23 12:44:21 mlelstv Exp $ */
+/*     $NetBSD: cut.c,v 1.4 2011/03/21 14:53:02 tnozaki Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -69,7 +69,7 @@
 cut(SCR *sp, CHAR_T *namep, MARK *fm, MARK *tm, int flags)
 {
        CB *cbp;
-       CHAR_T name = '\0';
+       ARG_CHAR_T name = '\0';
        db_recno_t lno;
        int append, copy_one, copy_def;
 
@@ -97,7 +97,7 @@
         */
        append = copy_one = copy_def = 0;
        if (namep != NULL) {
-               name = *namep;
+               name = (UCHAR_T)*namep;
                if (LF_ISSET(CUT_NUMREQ) || (LF_ISSET(CUT_NUMOPT) &&
                    (LF_ISSET(CUT_LINEMODE) || fm->lno != tm->lno))) {
                        copy_one = 1;
diff -r 8dfe103122b8 -r 068fd3503f2a dist/nvi/common/cut.h
--- a/dist/nvi/common/cut.h     Mon Mar 21 12:53:50 2011 +0000
+++ b/dist/nvi/common/cut.h     Mon Mar 21 14:53:02 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cut.h,v 1.3 2009/12/23 12:44:21 mlelstv Exp $ */
+/*     $NetBSD: cut.h,v 1.4 2011/03/21 14:53:02 tnozaki Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -19,7 +19,7 @@
        LIST_ENTRY(_cb) q;              /* Linked list of cut buffers. */
        TEXTH    textq;                 /* Linked list of TEXT structures. */
        /* XXXX Needed ? Can non ascii-chars be cut buffer names ? */
-       CHAR_T   name;                  /* Cut buffer name. */
+       ARG_CHAR_T name;                /* Cut buffer name. */
        size_t   len;                   /* Total length of cut text. */
 
 #define        CB_LMODE        0x01            /* Cut was in line mode. */
@@ -66,9 +66,9 @@
  * Translate upper-case buffer names to lower-case buffer names.
  */
 #define        CBNAME(sp, cbp, nch) {                                          \
-       CHAR_T L__name;                                                 \
-       L__name = ISUPPER((unsigned char)nch) ?                         \
-           TOLOWER((unsigned char)nch) : (nch);                        \
+       ARG_CHAR_T L__name;                                             \
+       L__name = ISUPPER(nch) ?                                        \
+           TOLOWER(nch) : (nch);                                       \
        for (cbp = sp->wp->cutq.lh_first;                               \
            cbp != NULL; cbp = cbp->q.le_next)                          \
                if (cbp->name == L__name)                               \
diff -r 8dfe103122b8 -r 068fd3503f2a dist/nvi/common/extern.h
--- a/dist/nvi/common/extern.h  Mon Mar 21 12:53:50 2011 +0000
+++ b/dist/nvi/common/extern.h  Mon Mar 21 14:53:02 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.3 2009/11/14 23:31:37 christos Exp $ */
+/*     $NetBSD: extern.h,v 1.4 2011/03/21 14:53:02 tnozaki Exp $ */
 
 /* Do not edit: automatically built by build/distrib. */
 SCR *api_fscreen __P((int, char *));
@@ -66,7 +66,7 @@
 void v_key_ilookup __P((SCR *));
 size_t v_key_len __P((SCR *, ARG_CHAR_T));
 u_char *v_key_name __P((SCR *, ARG_CHAR_T));
-int v_key_val __P((SCR *, ARG_CHAR_T));
+e_key_t v_key_val __P((SCR *, ARG_CHAR_T));
 int v_event_push __P((SCR *, EVENT *, const CHAR_T *, size_t, u_int));
 int v_event_get __P((SCR *, EVENT *, int, u_int32_t));
 void v_event_err __P((SCR *, EVENT *));
diff -r 8dfe103122b8 -r 068fd3503f2a dist/nvi/common/gs.h
--- a/dist/nvi/common/gs.h      Mon Mar 21 12:53:50 2011 +0000
+++ b/dist/nvi/common/gs.h      Mon Mar 21 14:53:02 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gs.h,v 1.4 2009/01/18 03:43:45 lukem Exp $ */
+/*     $NetBSD: gs.h,v 1.5 2011/03/21 14:53:02 tnozaki Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -81,7 +81,7 @@
        DB      *msg;                   /* Message catalog DB. */
        MSGH     msgq;                  /* User message list. */
 #define        DEFAULT_NOPRINT '\1'            /* Emergency non-printable character. */
-       CHAR_T   noprint;               /* Cached, unprintable character. */
+       int      noprint;               /* Cached, unprintable character. */
 
        char    *c_option;              /* Ex initial, command-line command. */
 
@@ -89,16 +89,16 @@
        FILE    *tracefp;               /* Trace file pointer. */
 #endif
 
-#define        MAX_BIT_SEQ     128             /* Max + 1 fast check character. */
+#define        MAX_BIT_SEQ     0x7f            /* Max + 1 fast check character. */
        LIST_HEAD(_seqh, _seq) seqq;    /* Linked list of maps, abbrevs. */
-       bitstr_t bit_decl(seqb, MAX_BIT_SEQ);
+       bitstr_t bit_decl(seqb, MAX_BIT_SEQ + 1);
 
-#define        MAX_FAST_KEY    254             /* Max fast check character.*/
+#define        MAX_FAST_KEY    0xff            /* Max fast check character.*/
 #define        KEY_LEN(sp, ch)                                                 \
-       ((UCHAR_T)(ch) <= MAX_FAST_KEY ?                        \
+       (((ch) & ~MAX_FAST_KEY) == 0 ?                                  \
            sp->gp->cname[(unsigned char)ch].len : v_key_len(sp, ch))
 #define        KEY_NAME(sp, ch)                                                \
-       ((UCHAR_T)(ch) <= MAX_FAST_KEY ?                                \
+       (((ch) & ~MAX_FAST_KEY) == 0 ?                                  \
            sp->gp->cname[(unsigned char)ch].name : v_key_name(sp, ch))
        struct {
                u_char   name[MAX_CHARACTER_COLUMNS + 1];
@@ -106,12 +106,9 @@
        } cname[MAX_FAST_KEY + 1];      /* Fast lookup table. */
 
 #define        KEY_VAL(sp, ch)                                                 \
-       ((UCHAR_T)(ch) <= MAX_FAST_KEY ?                                \
-           sp->gp->special_key[(UCHAR_T)ch] :                          \
-           (UCHAR_T)(ch) > (UCHAR_T)sp->gp->max_special ?              \
-               K_NOTUSED : v_key_val(sp,ch))
-       CHAR_T   max_special;           /* Max special character. */
-       u_char                          /* Fast lookup table. */
+       (((ch) & ~MAX_FAST_KEY) == 0 ?                                  \
+           sp->gp->special_key[(unsigned char)ch] : v_key_val(sp,ch))
+       e_key_t                         /* Fast lookup table. */
            special_key[MAX_FAST_KEY + 1];
 
 /* Flags. */
diff -r 8dfe103122b8 -r 068fd3503f2a dist/nvi/common/key.c
--- a/dist/nvi/common/key.c     Mon Mar 21 12:53:50 2011 +0000
+++ b/dist/nvi/common/key.c     Mon Mar 21 14:53:02 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: key.c,v 1.5 2009/01/18 03:45:50 lukem Exp $ */
+/*     $NetBSD: key.c,v 1.6 2011/03/21 14:53:02 tnozaki Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -138,16 +138,12 @@
        qsort(keylist, nkeylist, sizeof(keylist[0]), v_key_cmp);
 
        /* Initialize the fast lookup table. */
-       for (gp->max_special = 0, kp = keylist, cnt = nkeylist; cnt--; ++kp) {
-               if (gp->max_special < kp->ch)
-                       gp->max_special = kp->ch;
-               if (kp->ch <= MAX_FAST_KEY)
-                       gp->special_key[kp->ch] = kp->value;
-       }
+       for (kp = keylist, cnt = nkeylist; cnt--; ++kp)
+               gp->special_key[kp->ch] = kp->value;
 
        /* Find a non-printable character to use as a message separator. */
-       for (ch = 1; (unsigned)ch <= MAX_CHAR_T; ++ch)
-               if (!ISPRINT(ch)) {
+       for (ch = 1; ch <= UCHAR_MAX; ++ch)
+               if (!isprint(ch)) {
                        gp->noprint = ch;
                        break;
                }
@@ -243,12 +239,13 @@
 {
        static const char hexdigit[] = "0123456789abcdef";
        static const char octdigit[] = "01234567";
-       CHAR_T ch, mask;
-       size_t len;
-       int cnt, shift;
+       int ch;
+       size_t len, i;
        const char *chp;
 
-       ch = ach;
+       if (INTISWIDE(ach))
+               goto vis;
+       ch = (unsigned char)ach;
 
        /* See if the character was explicitly declared printable or not. */
        if ((chp = O_STR(sp, O_PRINT)) != NULL)
@@ -279,38 +276,33 @@
         * NB: There's an assumption here that all printable characters take
         * up a single column on the screen.  This is not always correct.
         */
-       if (ISPRINT(ch)) {
+       if (isprint(ch)) {
 pr:            sp->cname[0] = ch;
                len = 1;
                goto done;
        }
-nopr:  if (ISCNTRL(ch) && (ch < 0x20 || ch == 0x7f)) {
+nopr:  if (iscntrl(ch) && (ch < 0x20 || ch == 0x7f)) {
                sp->cname[0] = '^';
                sp->cname[1] = ch == 0x7f ? '?' : '@' + ch;
                len = 2;
-       } else if (O_ISSET(sp, O_OCTAL)) {
-#define        BITS    (sizeof(CHAR_T) * 8)
-#define        SHIFT   (BITS - BITS % 3)
-#define        TOPMASK (BITS % 3 == 2 ? 3 : 1) << (BITS - BITS % 3)
+               goto done;
+       }
+vis:   for (i = 1; i <= sizeof(CHAR_T); ++i)
+               if ((ach >> i * CHAR_BIT) == 0) 
+                       break;
+       ch = (ach >> --i * CHAR_BIT) & UCHAR_MAX;
+       if (O_ISSET(sp, O_OCTAL)) {
                sp->cname[0] = '\\';
-               sp->cname[1] = octdigit[(ch & TOPMASK) >> SHIFT];
-               shift = SHIFT - 3;
-               for (len = 2, mask = 7 << (SHIFT - 3),
-                   cnt = BITS / 3; cnt-- > 0; mask >>= 3, shift -= 3)
-                       sp->cname[len++] = octdigit[(ch & mask) >> shift];
+               sp->cname[1] = octdigit[(ch & 0300) >> 6];
+               sp->cname[2] = octdigit[(ch &  070) >> 3];
+               sp->cname[3] = octdigit[ ch &   07      ];
        } else {
                sp->cname[0] = '\\';
                sp->cname[1] = 'x';
-               for (len = 2, chp = (char *)&ch,
-                   /* sizeof(CHAR_T) conflict with MAX_CHARACTER_COLUMNS
-                    * and code depends on big endian
-                    * and might not be needed in the long run
-                    */
-                   cnt = /*sizeof(CHAR_T)*/1; cnt-- > 0; ++chp) {
-                       sp->cname[len++] = hexdigit[(*chp & 0xf0) >> 4];
-                       sp->cname[len++] = hexdigit[*chp & 0x0f];
-               }
+               sp->cname[2] = hexdigit[(ch & 0xf0) >> 4];
+               sp->cname[3] = hexdigit[ ch & 0x0f      ];
        }
+       len = 4;
 done:  sp->cname[sp->clen = len] = '\0';
        return (sp->cname);
 }
@@ -322,7 +314,7 @@
  *
  * PUBLIC: int v_key_val __P((SCR *, ARG_CHAR_T));
  */
-int
+e_key_t
 v_key_val(SCR *sp, ARG_CHAR_T ch)
 {
        KEYLIST k, *kp;
@@ -628,8 +620,8 @@
         */
        if (istimeout || FL_ISSET(evp->e_flags, CH_NOMAP) ||
            !LF_ISSET(EC_MAPCOMMAND | EC_MAPINPUT) ||
-           ((UCHAR_T)evp->e_c < MAX_BIT_SEQ &&
-           !bit_test(gp->seqb, (UCHAR_T)evp->e_c)))
+           ((evp->e_c & ~MAX_BIT_SEQ) == 0 &&
+           !bit_test(gp->seqb, evp->e_c)))
                goto nomap;
 
        /* Search the map. */
diff -r 8dfe103122b8 -r 068fd3503f2a dist/nvi/common/key.h
--- a/dist/nvi/common/key.h     Mon Mar 21 12:53:50 2011 +0000
+++ b/dist/nvi/common/key.h     Mon Mar 21 14:53:02 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: key.h,v 1.1.1.2 2008/05/18 14:29:46 aymeric Exp $ */
+/*     $NetBSD: key.h,v 1.2 2011/03/21 14:53:02 tnozaki Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -13,20 +13,6 @@
 
 #include "multibyte.h"
 
-/*
- * Fundamental character types.
- *
- * CHAR_T      An integral type that can hold any character.
- * ARG_CHAR_T  The type of a CHAR_T when passed as an argument using
- *             traditional promotion rules.  It should also be able
- *             to be compared against any CHAR_T for equality without
- *             problems.
- * MAX_CHAR_T  The maximum value of any character.
- *
- * If no integral type can hold a character, don't even try the port.
- */
-typedef        u_int           ARG_CHAR_T;
-
 #ifdef USE_WIDECHAR



Home | Main Index | Thread Index | Old Index