chiark / gitweb /
[PATCH] add prototype for ftruncate to klibc
[elogind.git] / klibc / klibc / makeerrlist.pl
1 #!/usr/bin/perl
2 #
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 */
6 #
7
8 use FileHandle;
9
10 %errors  = ();
11 %errmsg  = ();
12 $maxerr  = -1;
13 $rootdir = 'linux/include/';    # Must have trailing /
14
15 sub parse_file($) {
16     my($file) = @_;
17     my($fh) = new FileHandle;
18     my($line, $error, $msg);
19     my($kernelonly) = 0;
20
21     $file = $rootdir.$file;
22
23     print STDERR "opening $file\n";
24
25     if ( !($fh->open("< ".$file)) ) {
26         die "$0: cannot open $file\n";
27     }
28
29     while ( defined($line = <$fh>) ) {
30         if ( $kernelonly ) {
31             if ( $line =~ /^\#\s*endif/ ) {
32                 $kernelonly--;
33             } elsif ( $line =~ /^\#\sif/ ) {
34                 $kernelonly++;
35             }
36         } else {
37             if ( $line =~ /^\#\s*define\s+([A-Z0-9_]+)\s+([0-9]+)\s*\/\*\s*(.*\S)\s*\*\// ) {
38                 $error = $1;
39                 $errno = $2+0;
40                 $msg   = $3;
41                 print STDERR "$error ($errno) => \"$msg\"\n";
42                 $errors{$errno} = $error;
43                 $errmsg{$errno} = $msg;
44                 $maxerr = $errno if ( $errno > $maxerr );
45             } elsif ( $line =~ /^\#\s*include\s+[\<\"](.*)[\>\"]/ ) {
46                 parse_file($1);
47             } elsif ( $line =~ /^\#\s*ifdef\s+__KERNEL__/ ) {
48                 $kernelonly++;
49             }
50         }
51     }
52     close($fh);
53     print STDERR "closing $file\n";
54 }
55          
56 parse_file('linux/errno.h');
57
58 ($type) = @ARGV;
59
60 if ( $type eq '-errlist' ) {
61     print  "#include <errno.h>\n";
62     printf "const int sys_nerr = %d;\n", $maxerr+1;
63     printf "const char * const sys_errlist[%d] = {\n", $maxerr+1;
64     foreach $e ( sort(keys(%errors)) ) {
65         printf "  [%s] = \"%s\",\n", $errors{$e}, $errmsg{$e};
66     }
67     print "};\n";
68 } elsif ( $type eq '-errnos' ) {
69     print  "#include <errno.h>\n";
70     printf "const int sys_nerr = %d;\n", $maxerr+1;
71     printf "const char * const sys_errlist[%d] = {\n", $maxerr+1;
72     foreach $e ( sort(keys(%errors)) ) {
73         printf "  [%s] = \"%s\",\n", $errors{$e}, $errors{$e};
74     }
75     print "};\n";
76 } elsif ( $type eq '-maxerr' ) {
77     print $maxerr, "\n";
78 }
79
80