Releasing debian version 3:6.03+dfsg-10.
[syslinux-debian.git] / com32 / lib / makeerrlist.pl
blob9243b9dd28314cb3b9521aba74d60727535a46b5
1 #!/usr/bin/perl
3 # This creates sys_errlist from <asm/errno.h> through somewhat
4 # heuristic matching. It presumes the relevant entries are of the form
5 # #define Exxxx <integer> /* comment */
8 use FileHandle;
10 %errors = ();
11 %errmsg = ();
12 $maxerr = -1;
13 @includelist = (); # Include directories
15 sub parse_file($) {
16 my($file) = @_;
17 my($fh) = new FileHandle;
18 my($line, $error, $msg);
19 my($kernelonly) = 0;
20 my($root);
22 print STDERR "opening $file\n" unless ( $quiet );
24 $ok = 0;
25 foreach $root ( @includelist ) {
26 if ( $fh->open($root.'//'.$file, '<') ) {
27 $ok = 1;
28 last;
32 if ( ! $ok ) {
33 die "$0: Cannot find file $file\n";
36 while ( defined($line = <$fh>) ) {
37 if ( $kernelonly ) {
38 if ( $line =~ /^\#\s*endif/ ) {
39 $kernelonly--;
40 } elsif ( $line =~ /^\#\sif/ ) {
41 $kernelonly++;
43 } else {
44 if ( $line =~ /^\#\s*define\s+([A-Z0-9_]+)\s+([0-9]+)\s*\/\*\s*(.*\S)\s*\*\// ) {
45 $error = $1;
46 $errno = $2+0;
47 $msg = $3;
48 print STDERR "$error ($errno) => \"$msg\"\n" unless ( $quiet );
49 $errors{$errno} = $error;
50 $errmsg{$errno} = $msg;
51 $maxerr = $errno if ( $errno > $maxerr );
52 } elsif ( $line =~ /^\#\s*include\s+[\<\"](.*)[\>\"]/ ) {
53 parse_file($1);
54 } elsif ( $line =~ /^\#\s*ifdef\s+__KERNEL__/ ) {
55 $kernelonly++;
59 close($fh);
60 print STDERR "closing $file\n" unless ( $quiet );
63 $v = $ENV{'KBUILD_VERBOSE'};
64 $quiet = defined($v) ? !$v : 0;
66 foreach $arg ( @ARGV ) {
67 if ( $arg eq '-q' ) {
68 $quiet = 1;
69 } elsif ( $arg =~ /^-(errlist|errnos|maxerr)$/ ) {
70 $type = $arg;
71 } elsif ( $arg =~ '^\-I' ) {
72 push(@includelist, "$'");
73 } else {
74 # Ignore
78 parse_file('errno.h');
80 if ( $type eq '-errlist' ) {
81 print "#include <errno.h>\n";
82 printf "const int sys_nerr = %d;\n", $maxerr+1;
83 printf "const char * const sys_errlist[%d] = {\n", $maxerr+1;
84 foreach $e ( sort(keys(%errors)) ) {
85 printf " [%s] = \"%s\",\n", $errors{$e}, $errmsg{$e};
87 print "};\n";
88 } elsif ( $type eq '-errnos' ) {
89 print "#include <errno.h>\n";
90 printf "const int sys_nerr = %d;\n", $maxerr+1;
91 printf "const char * const sys_errlist[%d] = {\n", $maxerr+1;
92 foreach $e ( sort(keys(%errors)) ) {
93 printf " [%s] = \"%s\",\n", $errors{$e}, $errors{$e};
95 print "};\n";
96 } elsif ( $type eq '-maxerr' ) {
97 print $maxerr, "\n";