bug-coreutils
[Top][All Lists]
Advanced

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

dcgen minor tweaks


From: Paul Eggert
Subject: dcgen minor tweaks
Date: Wed, 28 Jul 2004 17:01:43 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

I noticed that dcgen generated C code with wider integers than it had
to, so I cleaned that up, and while I was at it I modified it to
remove comments, trailing white space, and empty lines.

2004-07-28  Paul Eggert  <address@hidden>

        * src/dcgen: Remove comments, trailing white space, and empty
        lines from the output strings, to save space.
        Use a narrower type like 'unsigned char' for line lengths, if
        that will do.
        Make the output variables static, not extern.

Index: dcgen
===================================================================
RCS file: /home/eggert/coreutils/cu/src/dcgen,v
retrieving revision 1.2
retrieving revision 1.3
diff -p -u -r1.2 -r1.3
--- dcgen       6 Feb 1998 20:48:10 -0000       1.2
+++ dcgen       28 Jul 2004 23:59:11 -0000      1.3
@@ -5,7 +5,7 @@ eval 'exec /p/bin/perl -S $0 ${1+"$@"}'
     if 0;
 
 # dcgen -- generate C declarations of arrays of lines and line lengths
-# Copyright (C) 1996, 1998 Free Software Foundation, Inc.
+# Copyright (C) 1996, 1998, 2004 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -38,16 +38,38 @@ local @line;
 while (<>)
   {
     chop;
-    push (@line, $_);
+    s/[[:blank:]]*#.*//;
+    if ($_)
+      {
+       push (@line, $_);
+      }
   }
 
 local $n = @line;
 print "#define ${prefix}N_LINES $n\n\n";
 
 local $indent = '  ';
-print "const size_t ${prefix}line_length[${prefix}N_LINES] =\n{\n$indent";
-local $ind = $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 ? ',' : '');
@@ -57,7 +79,7 @@ for ($i = 0; $i < @line; $i++)
   }
 print "};\n\n";
 
-print "const char *const ${prefix}line[${prefix}N_LINES] =\n{\n";
+print "static char const *const ${prefix}line[${prefix}N_LINES] =\n{\n";
 while (1)
   {
     $_ = shift (@line);





reply via email to

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