2 # Derive #define directives from specially formatted `case ...:' statements.
4 # Copyright (C) 2003, 2005 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 (my $VERSION = '$Revision: 1.5 $ ') =~ tr/[0-9].//cd;
25 (my $ME = $0) =~ s
|.*/||;
29 # Nobody ever checks the status of print()s. That's okay, because
30 # if any do fail, we're guaranteed to get an indicator when we close()
33 # Close stdout now, and if there were no errors, return happy status.
34 # If stdout has already been closed by the script, though, do nothing.
40 # Errors closing stdout. Indicate that, and hope stderr is OK.
41 warn "$ME: closing standard output: $!\n";
43 # Don't be so arrogant as to assume that we're the first END handler
44 # defined, and thus the last one invoked. There may be others yet
45 # to come. $? will be passed on to them, and to the final _exit().
47 # If it isn't already an error, make it one (and if it _is_ an error,
48 # preserve the value: it might be important).
55 my $STREAM = ($exit_code == 0 ?
*STDOUT
: *STDERR
);
58 print $STREAM "Try `$ME --help' for more information.\n";
63 Usage: $ME [OPTIONS] FILE
69 Derive #define directives from specially formatted `case ...:' statements.
71 --help display this help and exit
72 --version output version information and exit
82 help
=> sub { usage
0 },
83 version
=> sub { print "$ME version $VERSION\n"; exit },
89 and (warn "$ME: missing FILE arguments\n"), $fail = 1;
91 and (warn "$ME: too many arguments\n"), $fail = 1;
98 or die "$ME: can't open `$file' for reading: $!\n";
100 # For each line like this:
101 # case S_MAGIC_ROMFS: /* 0x7275 */
102 # emit one like this:
103 # # define S_MAGIC_ROMFS 0x7275
104 # Fail if there is a `case S_MAGIC_.*' line without
105 # a properly formed comment.
108 /* Define the magic numbers as given by statfs(2).
109 Please send additions to bug-coreutils\@gnu.org and meskes\@debian.org.
110 This file is generated automatically from $file. */
112 #if defined __linux__
115 while (defined (my $line = <FH
>))
117 $line =~ /^[ \t]+case S_MAGIC_/
119 $line =~ m!^[ \t]+case (S_MAGIC_\w+): /\* (0x[0-9A-Fa-f]+) \*/$!
120 or (warn "$ME:$file:$.: malformed case S_MAGIC_... line"),
124 print "# define $name $value\n";
128 #elif defined __GNU__
129 # include <hurd/hurd_types.h>