bug-coreutils
[Top][All Lists]
Advanced

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

Re: dircolors database documentation


From: Eric Blake
Subject: Re: dircolors database documentation
Date: Thu, 20 Oct 2005 07:24:52 -0600
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Paul Eggert on 10/20/2005 2:37 AM:
> 
>>How about adopting the C rule of parsing and use at most 3 digits in octal
>>escapes?
> 
> 
> Makes sense.  C says that octal escapes may be at most 3 digits, and
> "\400" is an error (assuming 8-bit chars).

Easy enough.  Patch attached, although I should also fold this style of
test into the testsuite:
seq='\400'
result=`LS_COLORS="lc=:no=:rc=:di=$seq:" ls --color -d .`
test "x$result" = "x 0." || fail=1

> 
> C also says that hex escapes are of unlimited length.  That's a bit
> strange, but I guess ls might as well be consistent.  Like octal
> escapes, if the value is out of range it is an error (e.g., "\x100",
> again assuming 8-bit chars).  "\x0000000000000000001" is valid and is
> the same as "\1".

So am I allowed to assume 8-bit chars, or should I add code that checks
for char overflow, one hex digit at a time?  And with 8-bit chars, should
"\x100" parse as "\x10" "0", or should it raise a parse error?

Also, should I try to attempt fixes where ls assumes ASCII?  In parsing ^
escape sequences, ls currently checks for *p >= '@' && *p <= '~'; and when
handling ESC, ls treats \e as 37, and hardcodes \033 into the default lc
color sequence.

2005-10-20  Eric Blake  <address@hidden>

        * src/ls.c (get_funky_string): Limit octal sequence to 3 digits, 8
        bits.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDV5qj84KuGfSFAYARAg76AKDMH+fpdigMEDcwsv0INpB9uIpDoQCePL8G
+3LnAD6vlhTMkcY24XYk4qU=
=PZjx
-----END PGP SIGNATURE-----
Index: src/ls.c
===================================================================
RCS file: /cvsroot/coreutils/coreutils/src/ls.c,v
retrieving revision 1.400
diff -u -p -b -r1.400 ls.c
--- src/ls.c    15 Oct 2005 09:56:21 -0000      1.400
+++ src/ls.c    20 Oct 2005 13:15:24 -0000
@@ -1909,7 +1909,8 @@ get_funky_string (char **dest, const cha
   char num;                    /* For numerical codes */
   size_t count;                        /* Something to count with */
   enum {
-    ST_GND, ST_BACKSLASH, ST_OCTAL, ST_HEX, ST_CARET, ST_END, ST_ERROR
+    ST_GND, ST_BACKSLASH, ST_OCTAL1, ST_OCTAL2, ST_OCTAL3, ST_HEX, ST_CARET,
+    ST_END, ST_ERROR
   } state;
   const char *p;
   char *q;
@@ -1961,11 +1962,14 @@ get_funky_string (char **dest, const cha
            case '1':
            case '2':
            case '3':
+             state = ST_OCTAL1;        /* Octal sequence, max 3 chars */
+             num = *p - '0';
+             break;
            case '4':
            case '5':
            case '6':
            case '7':
-             state = ST_OCTAL; /* Octal sequence */
+             state = ST_OCTAL2;        /* Octal sequence, max 2 chars */
              num = *p - '0';
              break;
            case 'x':
@@ -2019,15 +2023,20 @@ get_funky_string (char **dest, const cha
          ++p;
          break;
 
-       case ST_OCTAL:          /* Octal sequence */
-         if (*p < '0' || *p > '7')
+       case ST_OCTAL1:         /* Octal sequence */
+       case ST_OCTAL2:
+       case ST_OCTAL3:
+         if (state == ST_OCTAL3 || *p < '0' || *p > '7')
            {
              *(q++) = num;
              ++count;
              state = ST_GND;
            }
          else
+           {
            num = (num << 3) + (*(p++) - '0');
+             state++;
+           }
          break;
 
        case ST_HEX:            /* Hex sequence */

reply via email to

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