1 #!/usr/local/bin/perl -w
3 # Modified by Steve Henson. It should now read in the .err
4 # file and only add new error codes, retaining the old
7 # Before it re-sorted new codes and re-ordered the whole thing.
8 # This is the motivation for the change: the re numbering caused large
9 # patch files even if only one error or reason code was added.
10 # To force regeneration of all error codes (the old behaviour) use the
21 open(IN,"<$in") || die "unable to open '$in'\n";
27 if (/^L\s+(\S+)\s+(\S+)$/)
31 elsif (/^R\s+(\S+)\s+(\S+)$/)
33 else { die "bad input line: $in:$.\n"; }
38 elsif ($in =~ /^-regen/)
44 open(IN,"<$in") || die "unable to open '$in'\n";
48 if (/err\(([A-Z0-9]+_F_[0-9A-Z_]+)\s*,\s*([0-9A-Z]+_R_[0-9A-Z_]+)\s*\)/)
50 # Not sure what this was supposed to be for: it's broken anyway [steve]
53 # if ($function{$1} == 0)
55 # printf STDERR "$. $1 is bad\n";
66 foreach (keys %function,keys %reason)
72 @F=sort keys %function;
74 foreach $j (sort keys %prefix)
76 next if !defined $errfile{$j};
77 next if $errfile{$j} eq "NONE";
78 printf STDERR "doing %-6s - ",$j;
81 if (defined($errfile{$j}))
83 read_errcodes($errfile{$j});
84 # Check to see if any new codes: if not ignore.
87 if(!exists $func_codes{$_}) {
94 if(!exists $reason_codes{$_}) {
101 print STDERR "No New Codes\n";
104 open(OUT,">$errfile{$j}") ||
105 die "unable to open '$errfile{$j}':$!\n";
116 print OUT "/* Error codes for the $j functions. */\n\n";
117 print OUT "/* Function codes. */\n";
121 $z=6-int(length($i)/8);
122 if(exists $func_codes{$i}) {
123 printf OUT "#define $i%s $func_codes{$i}\n","\t" x $z;
125 printf OUT "#define $i%s $num\n","\t" x $z;
131 print OUT "\n/* Reason codes. */\n";
135 $z=6-int(length($i)/8);
136 if (exists $reason_codes{$i}) {
137 printf OUT "#define $i%s $reason_codes{$i}\n","\t" x $z;
138 } elsif (exists $r_value{$i}) {
139 printf OUT "#define $i%s $r_value{$i}\n","\t" x $z;
141 printf OUT "#define $i%s $num\n","\t" x $z;
146 close(OUT) if $close_file;
148 printf STDERR "%3d functions, %3d reasons\n",$f_count,$r_count;
151 # Read in the error codes and populate %function and %reason with the
152 # old codes. Also define $min_func and $min_reason with the smallest
153 # unused function and reason codes. Care is needed because the
154 # config file can define larger reason codes and these should be
164 if (open IN, $file) {
166 if(/^#define\s*(\S*)\s*(\S*)/) {
167 if (exists $function{$1} ) {
168 if($2 >= $min_func) {$min_func = $2 + 1;}
169 $func_codes{$1} = $2;
170 } elsif ((defined %reason) && exists $reason{$1}) {
171 $reason_codes{$1} = $2;
172 if( !(exists $r_value{$1}) &&
174 {$min_reason = $2 + 1;}