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 11:48:52 -0700 (PDT)

I've hacked up a patch against nanodbbehemoth.patch that,
in my preliminary testing, seems to fix the ambiguity
while still avoiding the xterm corruption problem.
Basically, it just adds a wrapper function for iscntrl()
that returns 1 if iscntrl() returns 1 or if the character
stripped of its high bit is a control character (except
for -1; if it were an unsigned char, it'd be 255), and
replaces all calls to iscntrl() with it.  Combined with
the (former) iscntrl() call you added in update_line(),
it displays the characters just as it would if gettext
was used.  It's online at:

http://pooka_regent.tripod.com/patches/nano/nanodbbehemoth2-patch.txt

I'm also attaching it here.  Please let me know if it works
correctly.


_____________________________________________________________
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 14:13:39.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/ChangeLog     2002-07-13 14:25:55.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 14:13:39.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/files.c       2002-07-13 14:28:38.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 14:13:39.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/nano.c        2002-07-13 14:26:48.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 14:13:39.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/proto.h       2002-07-13 14:27:27.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 14:13:39.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/utils.c       2002-07-13 14:29:22.000000000 -0400
@@ -36,6 +36,14 @@
 #define _(string) (string)
 #endif
 
+int is_cntrl_char(int c)
+{
+    if (iscntrl(c) || (c != -1 && 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 14:13:39.000000000 -0400
+++ nano-1.1.9-cvs-fixed2/winio.c       2002-07-13 14:22:19.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;
     }
--- Begin Message --- Subject: [Nano-devel] iscntrl() ambiguity Date: Sat, 13 Jul 2002 00:58:04 -0400 User-agent: Mutt/1.2.5i
Starting a month ago, expressions like "ch < 32 || ch == 127" have been
replaced with "iscntrl(ch)".  In the current behem patch, I add an
iscntrl() statement to winio.c:update_line, the code that chooses how to
display characters.

Here's a fact that took me a long time to figure out: the behavior of
iscntrl() depends on locale settings, and among other things, on the LANG
environment variable.  With LANG=en_US, characters 128 through 159 are
control characters.  That means that with the new patch, the way binary
characters display depends on the locale.

Well, just thought I would explain this odd "feature".

Attachment: pgpnnSEytEkmr.pgp
Description: PGP signature


--- End Message ---

reply via email to

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