aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/makeerrlist.pl
blob: 9243b9dd28314cb3b9521aba74d60727535a46b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/perl
#
# This creates sys_errlist from <asm/errno.h> through somewhat
# heuristic matching.  It presumes the relevant entries are of the form
# #define Exxxx <integer> /* comment */
#

use FileHandle;

%errors  = ();
%errmsg  = ();
$maxerr  = -1;
@includelist = ();		# Include directories

sub parse_file($) {
    my($file) = @_;
    my($fh) = new FileHandle;
    my($line, $error, $msg);
    my($kernelonly) = 0;
    my($root);

    print STDERR "opening $file\n" unless ( $quiet );

    $ok = 0;
    foreach $root ( @includelist ) {
	if ( $fh->open($root.'//'.$file, '<') ) {
	    $ok = 1;
	    last;
	}
    }

    if ( ! $ok ) {
	die "$0: Cannot find file $file\n";
    }

    while ( defined($line = <$fh>) ) {
	if ( $kernelonly ) {
	    if ( $line =~ /^\#\s*endif/ ) {
		$kernelonly--;
	    } elsif ( $line =~ /^\#\sif/ ) {
		$kernelonly++;
	    }
	} else {
	    if ( $line =~ /^\#\s*define\s+([A-Z0-9_]+)\s+([0-9]+)\s*\/\*\s*(.*\S)\s*\*\// ) {
		$error = $1;
		$errno = $2+0;
		$msg   = $3;
		print STDERR "$error ($errno) => \"$msg\"\n" unless ( $quiet );
		$errors{$errno} = $error;
		$errmsg{$errno} = $msg;
		$maxerr = $errno if ( $errno > $maxerr );
	    } elsif ( $line =~ /^\#\s*include\s+[\<\"](.*)[\>\"]/ ) {
		parse_file($1);
	    } elsif ( $line =~ /^\#\s*ifdef\s+__KERNEL__/ ) {
		$kernelonly++;
	    }
	}
    }
    close($fh);
    print STDERR "closing $file\n" unless ( $quiet );
}

$v = $ENV{'KBUILD_VERBOSE'};
$quiet = defined($v) ? !$v : 0;

foreach $arg ( @ARGV ) {
    if ( $arg eq '-q' ) {
	$quiet = 1;
    } elsif ( $arg =~ /^-(errlist|errnos|maxerr)$/ ) {
	$type = $arg;
    } elsif ( $arg =~ '^\-I' ) {
	push(@includelist, "$'");
    } else {
	# Ignore
    }
}

parse_file('errno.h');

if ( $type eq '-errlist' ) {
    print  "#include <errno.h>\n";
    printf "const int sys_nerr = %d;\n", $maxerr+1;
    printf "const char * const sys_errlist[%d] = {\n", $maxerr+1;
    foreach $e ( sort(keys(%errors)) ) {
	printf "  [%s] = \"%s\",\n", $errors{$e}, $errmsg{$e};
    }
    print "};\n";
} elsif ( $type eq '-errnos' ) {
    print  "#include <errno.h>\n";
    printf "const int sys_nerr = %d;\n", $maxerr+1;
    printf "const char * const sys_errlist[%d] = {\n", $maxerr+1;
    foreach $e ( sort(keys(%errors)) ) {
	printf "  [%s] = \"%s\",\n", $errors{$e}, $errors{$e};
    }
    print "};\n";
} elsif ( $type eq '-maxerr' ) {
    print $maxerr, "\n";
}