summaryrefslogtreecommitdiff
path: root/src/dcgen
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-03-27 08:35:16 +0000
committerJim Meyering <jim@meyering.net>2005-03-27 08:35:16 +0000
commite2b271d81d32e20310a704d26efe1bb79c81fb73 (patch)
tree0257956514068885fe39213626825cb5c997b25f /src/dcgen
parentf01ef502f2ddef15b7a04728f1e558b3062019cb (diff)
downloadcoreutils-e2b271d81d32e20310a704d26efe1bb79c81fb73.tar.xz
Simplify further, clean up. Require perl-5.002.
Add a standard-output-closing global destructor.
Diffstat (limited to 'src/dcgen')
-rwxr-xr-xsrc/dcgen57
1 files changed, 25 insertions, 32 deletions
diff --git a/src/dcgen b/src/dcgen
index 6e90ed0d4..39b4f5ee5 100755
--- a/src/dcgen
+++ b/src/dcgen
@@ -1,10 +1,6 @@
#!/usr/bin/perl -w
-# -*- perl -*-
+# dcgen -- convert dircolors.hin to dircolors.h.
-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, 2004, 2005 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
@@ -24,40 +20,37 @@ eval 'exec /p/bin/perl -S $0 ${1+"$@"}'
# written by Jim Meyering
-# If you uncomment the following lines, you should also do
-# s/chop/chomp and s/local/my/.
-#require 5.002;
-#use strict;
-
-# Convert an arbitrary file to dcl of two arrays.
-# One of lines, the other of lengths.
-
-local $prefix = 'G_';
-
-local @line;
+require 5.002;
+use strict;
+(my $ME = $0) =~ s|.*/||;
+
+# A global destructor to close standard output with error checking.
+sub END
+{
+ defined fileno STDOUT
+ or return;
+ close STDOUT
+ and return;
+ warn "$ME: closing standard output: $!\n";
+ $? ||= 1;
+}
+
+my @line;
while (<>)
{
- chop;
+ chomp;
s/[[:blank:]]*#.*//;
s/[[:blank:]]+/ /g;
- if ($_)
- {
- push (@line, $_);
- }
+ $_
+ and push @line, $_;
}
-local $indent = ' ';
+my $last_line = pop @line;
+my $indent = ' ';
-print "static char const ${prefix}line[] =\n";
-while (1)
+print "static char const G_line[] =\n";
+foreach (@line)
{
- $_ = shift (@line);
- if (!@line)
- {
- print "$indent\"$_\";\n";
- last;
- }
print "$indent\"$_\\0\"\n";
}
-
-exit (0);
+print "$indent\"$last_line\";\n";