nano-devel
[Top][All Lists]
Advanced

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

Re: [Nano-devel] iscntrl() ambiguity


From: David Lawrence Ramsey
Subject: Re: [Nano-devel] iscntrl() ambiguity
Date: Sat, 13 Jul 2002 12:07:28 -0700 (PDT)

Check that; I'm not sure the testing against -1 will work on
systems where the default char is unsigned (since some of
the ints are cast from chars).  The test now is if the
character is ASCII 127 after having its high bit stripped
(i. e. whether it's 255).  It's available at the same URL as
the last version, and I'm attaching it (again).


_____________________________________________________________
Sluggy.Net: The Sluggy Freelance Community!

_____________________________________________________________
Promote your group and strengthen ties to your members with address@hidden by 
Everyone.net  http://www.everyone.net/?btn=tag
diff -urN nano-1.1.9-cvs-fixed/ChangeLog nano-1.1.9-cvs-fixed2/ChangeLog
--- nano-1.1.9-cvs-fixed/ChangeLog      2002-07-13 15:08:29.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/ChangeLog     2002-07-13 15:08:36.000000000 -0400
@@ -78,6 +78,12 @@
          including all the header files, as rcfile.c does; this fixes
          a warning about ANSI C'S inability to handle blank files.
          (DLR)
+       - Add new function is_cntrl_char() as a wrapper for iscntrl();
+         this is needed to treat ASCII 0x80-0x9f as control characters
+         consistently.  (Without this, they will only be treated as
+         such when gettext is used; when it isn't used, they will be
+         printed as-is and be interpreted as commands by xterm, which
+         will corrupt the display.) (DLR)
        - Add command line option -I/--ignorercfiles to ignore
          /etc/nanorc and ~/.nanorc. (Carl Drinkwater)
 - files.c:
@@ -263,9 +269,6 @@
          (which should never occur under normal circumstances; they will
          only be there if the line had nulls in it and was unsunder()ed
          beforehand) as ^@'s. (DLR)
-       - Display ASCII 0x80-0x9f as backslashes followed by 3-digit
-         octal values to keep xterm from screwing up the display when
-         some of them are printed as-is. (David Benbennick)
   statusbar():
        - Limit statusbar display to the number of columns less four, and
          don't allow it to go over its original row. (David Benbennick)
diff -urN nano-1.1.9-cvs-fixed/files.c nano-1.1.9-cvs-fixed2/files.c
--- nano-1.1.9-cvs-fixed/files.c        2002-07-13 15:08:29.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/files.c       2002-07-13 15:08:36.000000000 -0400
@@ -185,10 +185,10 @@
     }
     /* Read the entire file into file struct */
     while ((input_int = getc(f)) != EOF) {
-        input = (char) input_int;
+        input = (char)input_int;
 #ifndef NANO_SMALL
-       if (!ISSET(NO_CONVERT) && iscntrl((int)input) && input != '\t'
-               && input != '\r' && input != '\n') {
+       if (!ISSET(NO_CONVERT) && is_cntrl_char((int)input)
+               && input != '\t' && input != '\r' && input != '\n') {
            /* If the file has binary chars in it, don't stupidly
               assume it's a DOS or Mac formatted file! */
            SET(NO_CONVERT);
diff -urN nano-1.1.9-cvs-fixed/nano.c nano-1.1.9-cvs-fixed2/nano.c
--- nano-1.1.9-cvs-fixed/nano.c 2002-07-13 15:08:29.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/nano.c        2002-07-13 15:08:36.000000000 -0400
@@ -2142,10 +2142,8 @@
            space_loc = cur_loc;
        assert(*line != '\t');
 
-       if (iscntrl(*line))
+       if (is_cntrl_char(*line))
            goal -= 2;
-       else if ((unsigned char) *line >= 0x80 && (unsigned char) *line <= 0x9f)
-           goal -= 4;
        else
            goal--;
     }
diff -urN nano-1.1.9-cvs-fixed/proto.h nano-1.1.9-cvs-fixed2/proto.h
--- nano-1.1.9-cvs-fixed/proto.h        2002-07-13 15:08:29.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/proto.h       2002-07-13 15:08:36.000000000 -0400
@@ -239,6 +239,7 @@
 const char *stristr(const char *haystack, const char *needle);
 const char *strstrwrapper(const char *haystack, const char *needle,
                const char *rev_start, int line_pos);
+int is_cntrl_char(int c);
 int num_of_digits(int n);
 int check_wildcard_match(const char *text, const char *pattern);
 void align(char **strp);
diff -urN nano-1.1.9-cvs-fixed/utils.c nano-1.1.9-cvs-fixed2/utils.c
--- nano-1.1.9-cvs-fixed/utils.c        2002-07-13 15:08:29.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/utils.c       2002-07-13 15:09:04.000000000 -0400
@@ -36,6 +36,14 @@
 #define _(string) (string)
 #endif
 
+int is_cntrl_char(int c)
+{
+    if (iscntrl(c) || ((c & 127) != 127 && iscntrl(c & 127)))
+       return 1;
+    else
+       return 0;
+}
+
 int num_of_digits(int n)
 {
     int i = 1;
diff -urN nano-1.1.9-cvs-fixed/winio.c nano-1.1.9-cvs-fixed2/winio.c
--- nano-1.1.9-cvs-fixed/winio.c        2002-07-13 15:08:29.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/winio.c       2002-07-13 15:08:36.000000000 -0400
@@ -87,10 +87,8 @@
     for (c = fileptr->data; length < xplus && *c != '\0'; i++, c++) {
        if (*c == '\t')
            length += tabsize - length % tabsize;
-       else if (iscntrl((int)*c))
+       else if (is_cntrl_char((int)*c))
            length += 2;
-       else if ((unsigned char) *c >= 0x80 && (unsigned char) *c <= 0x9f)
-           length += 4;
        else
            length++;
     }
@@ -116,10 +114,8 @@
        for (; *buf != '\0' && size != 0; size--, buf++) {
            if (*buf == '\t')
                length += tabsize - (length % tabsize);
-           else if (iscntrl((int)*buf))
+           else if (is_cntrl_char((int)*buf))
                length += 2;
-           else if ((unsigned char) *buf >= 0x80 && (unsigned char) *buf <= 
0x9f)
-               length += 4;
            else
                length++;
        }
@@ -952,7 +948,7 @@
            do {
                converted[pos++] = ' ';
            } while (pos % tabsize);
-       else if (iscntrl((int)*original)) {
+       else if (is_cntrl_char((int)*original)) {
            converted[pos++] = '^';
            if (*original == 127)
                converted[pos++] = '?';
@@ -963,13 +959,6 @@
                converted[pos++] = '@';
            else
                converted[pos++] = *original + 64;
-       } else if ((unsigned char)*original >= 0x80 && (unsigned char)*original 
<= 0x9f) {
-               /* xterm treats some of these characters as commands
-                  and screws up the display if we print them, so print
-                  backslashes followed by 3-digit octal values
-                  instead.  emacs does this too. */
-           sprintf(converted + pos, "\\%o", (unsigned char)*original);
-           pos += 4;
        } else
            converted[pos++] = *original;
     }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]