bug-coreutils
[Top][All Lists]
Advanced

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

Re: color support for TERM=cygwin


From: Paul Eggert
Subject: Re: color support for TERM=cygwin
Date: Fri, 25 Mar 2005 23:16:19 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

address@hidden (Eric Blake) writes:

> The cygwin terminal supports color, so it would be nice to have this
> patch.

Thanks; I installed the obvious change to src/dircolors.hin.

> Also, I think src/dcgen should not strip comments from
> src/dircolors.hin, so that a user typing `dircolors -p' gets the
> comments as well as the default settings.

I'm not so sure.  Such users are not casual, and they can look at the
source.  In fact, I had rather the reverse in mind: dircolors and
dcgen could be simplified as shown below.

> Also, for those who prefer British spellings, should we be looking
> at supporting colour synonyms (dircolours, LS_COLOURS, ls --colour,
> etc.)?

No, option and environment variable names are American English.  If we
wanted to localize them (I'm dubious), we should support French,
Chinese, etc., not just British English.

Jim, what do you think?  Is the following minor patch worth the
hassle?  It does save a couple of hundred bytes in the dircolors
executable, but its main advantage to my mind is that it shortens the
code by about 30 lines and removes some casts.

2005-03-25  Paul Eggert  <address@hidden>

        * src/dcgen: Squeeze multiple blanks into one.  Output a simple
        array of adjacent strings rather than a more complicated data
        structure; this saves space in the dircolors executable.
        * src/dircolors.c (parse_line): Use char *, not unsigned char *.
        This avoids casts.
        (dc_parse_stream, main): Avoid casts.
        Adjust to simpler data structure generated by new dcgen.

Index: src/dcgen
===================================================================
RCS file: /fetish/cu/src/dcgen,v
retrieving revision 1.3
diff -p -u -r1.3 dcgen
--- src/dcgen   28 Jul 2004 23:59:11 -0000      1.3
+++ src/dcgen   26 Mar 2005 07:04:50 -0000
@@ -39,54 +39,25 @@ while (<>)
   {
     chop;
     s/[[:blank:]]*#.*//;
+    s/[[:blank:]]+/ /g;
     if ($_)
       {
        push (@line, $_);
       }
   }
 
-local $n = @line;
-print "#define ${prefix}N_LINES $n\n\n";
-
 local $indent = '  ';
-local $i;
-
-local $max_line_length = 0;
-for ($i = 0; $i < @line; $i++)
-  {
-    local $len = length ($line[$i]);
-    $max_line_length = $len if $max_line_length < $len;
-  }
-
-local $line_length_type = 'unsigned char';
-if ((1 << 8) <= $max_line_length)
-  {
-    $line_length_type = 'unsigned short int';
-    if ((1 << 16) <= $max_line_length)
-      {
-        $line_length_type = 'unsigned int';
-      }
-  }
 
-print "static $line_length_type const ${prefix}line_length[${prefix}N_LINES] 
=\n{\n$indent";
-local $ind = $indent;
-for ($i = 0; $i < @line; $i++)
-  {
-    local $comma = ($i < @line - 1 ? ',' : '');
-    $ind = '' if $i == @line - 1;
-    local $sep = ($i && $i % 18 == 0 || $i == @line - 1 ? "\n$ind" : ' ');
-    print length ($line[$i]), $comma, $sep;
-  }
-print "};\n\n";
-
-print "static char const *const ${prefix}line[${prefix}N_LINES] =\n{\n";
+print "static char const ${prefix}line[] =\n";
 while (1)
   {
     $_ = shift (@line);
-    local $comma = (@line ? ',' : '');
-    print "$indent\"$_\"$comma\n";
-    last if address@hidden;
+    if (address@hidden)
+      {
+       print "$indent\"$_\";\n";
+       last;
+      }
+    print "$indent\"$_\\0\"\n";
   }
-print "};\n";
 
 exit (0);
Index: src/dircolors.c
===================================================================
RCS file: /fetish/cu/src/dircolors.c,v
retrieving revision 1.83
diff -p -u -r1.83 dircolors.c
--- src/dircolors.c     2 Aug 2004 23:36:33 -0000       1.83
+++ src/dircolors.c     26 Mar 2005 07:04:51 -0000
@@ -145,16 +145,16 @@ guess_shell_syntax (void)
 }
 
 static void
-parse_line (unsigned char const *line, char **keyword, char **arg)
+parse_line (char const *line, char **keyword, char **arg)
 {
-  unsigned char const *p;
-  unsigned char const *keyword_start;
-  unsigned char const *arg_start;
+  char const *p;
+  char const *keyword_start;
+  char const *arg_start;
 
   *keyword = NULL;
   *arg = NULL;
 
-  for (p = line; ISSPACE (*p); ++p)
+  for (p = line; ISSPACE (to_uchar (*p)); ++p)
     ;
 
   /* Ignore blank lines and shell-style comments.  */
@@ -163,12 +163,12 @@ parse_line (unsigned char const *line, c
 
   keyword_start = p;
 
-  while (!ISSPACE (*p) && *p != '\0')
+  while (!ISSPACE (to_uchar (*p)) && *p != '\0')
     {
       ++p;
     }
 
-  *keyword = xstrndup ((const char *) keyword_start, p - keyword_start);
+  *keyword = xstrndup (keyword_start, p - keyword_start);
   if (*p  == '\0')
     return;
 
@@ -176,7 +176,7 @@ parse_line (unsigned char const *line, c
     {
       ++p;
     }
-  while (ISSPACE (*p));
+  while (ISSPACE (to_uchar (*p)));
 
   if (*p == '\0' || *p == '#')
     return;
@@ -186,13 +186,13 @@ parse_line (unsigned char const *line, c
   while (*p != '\0' && *p != '#')
     ++p;
 
-  for (--p; ISSPACE (*p); --p)
+  for (--p; ISSPACE (to_uchar (*p)); --p)
     {
       /* empty */
     }
   ++p;
 
-  *arg = xstrndup ((const char *) arg_start, p - arg_start);
+  *arg = xstrndup (arg_start, p - arg_start);
 }
 
 /* FIXME: Write a string to standard out, while watching for "dangerous"
@@ -239,8 +239,10 @@ static bool
 dc_parse_stream (FILE *fp, const char *filename)
 {
   size_t line_number = 0;
-  char *line = NULL;
-  size_t line_chars_allocated = 0;
+  char const *next_G_line = G_line;
+  char *input_line = NULL;
+  size_t input_line_size = 0;
+  char const *line;
   char *term;
   bool ok = true;
 
@@ -254,7 +256,6 @@ dc_parse_stream (FILE *fp, const char *f
 
   while (1)
     {
-      ssize_t line_length;
       char *keywd, *arg;
       bool unrecognized;
 
@@ -262,23 +263,22 @@ dc_parse_stream (FILE *fp, const char *f
 
       if (fp)
        {
-         line_length = getline (&line, &line_chars_allocated, fp);
-         if (line_length <= 0)
+         if (getline (&input_line, &input_line_size, fp) <= 0)
            {
-             if (line)
-               free (line);
+             free (input_line);
              break;
            }
+         line = input_line;
        }
       else
        {
-         line = (char *) (G_line[line_number - 1]);
-         line_length = G_line_length[line_number - 1];
-         if (line_number > G_N_LINES)
+         if (next_G_line == G_line + sizeof G_line)
            break;
+         line = next_G_line;
+         next_G_line += strlen (next_G_line) + 1;
        }
 
-      parse_line ((unsigned char *) line, &keywd, &arg);
+      parse_line (line, &keywd, &arg);
 
       if (keywd == NULL)
        continue;
@@ -471,11 +471,11 @@ to select a shell syntax are mutually ex
 
   if (print_database)
     {
-      int i;
-      for (i = 0; i < G_N_LINES; i++)
+      char const *p = G_line;
+      while (p < G_line + sizeof G_line)
        {
-         fwrite (G_line[i], 1, G_line_length[i], stdout);
-         fputc ('\n', stdout);
+         puts (p);
+         p += strlen (p) + 1;
        }
     }
   else




reply via email to

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