109
if (not /\*\//) { # multiline comment...
110
$line = $_; # ... just accumulate
113
s/\/\*.*?\*\///gs; # wipe it
119
$cpp-- if /^#\s*endif/;
106
122
$cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
108
$cpp = 0 if /^#.*endif/;
112
124
next if (/^\#/); # skip preprocessor directives
114
s/\/\*.*?\*\///gs; # ignore comments
115
126
s/{[^{}]*}//gs; # ignore {} blocks
117
128
if (/\{|\/\*/) { # Add a } so editor works...
129
140
print STDERR "def: $defnr\r" if $debug;
142
# The goal is to collect function names from function declarations.
133
next if(/typedef\W/);
134
if (/\(\*(\w*)\([^\)]+/) {
136
$name =~ tr/[a-z]/[A-Z]/;
138
} elsif (/\w+\W+(\w+)\W*\(\s*\)(\s*__attribute__\(.*\)\s*)?$/s){
141
} elsif (/\w+\W+\w+\W*\(.*\)(\s*__attribute__\(.*\)\s*)?$/s) {
142
while (not /\(\)(\s*__attribute__\(.*\)\s*)?$/s) {
143
s/[^\(\)]*\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
144
s/\([^\(\)]*\)\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
147
/(\w+(\{[0-9]+\})?)\W*\(\)/s;
149
$name =~ tr/[a-z]/[A-Z]/;
151
} elsif (/\(/ and not (/=/ or /DECLARE_STACK/ or /TYPEDEF_D2I2D_OF/)) {
147
# Skip over recognized non-function declarations
148
next if(/typedef\W/ or /DECLARE_STACK_OF/ or /TYPEDEF_.*_OF/);
150
# Reduce argument lists to empty ()
151
# fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
153
s/\([^\(\)]+\)/\{\}/gs;
154
s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f
156
# pretend as we didn't use curly braces: {} -> ()
159
if (/(\w+)\s*\(\).*/s) { # first token prior [first] () is
160
my $name = $1; # a function name!
161
$name =~ tr/[a-z]/[A-Z]/;
163
} elsif (/[\(\)]/ and not (/=/)) {
152
164
print STDERR "Header $hdr: cannot parse: $_;\n";
174
186
$rcodes{$name} = $code;
187
if ($rassigned{$lib} =~ /:$code:/) {
188
print STDERR "!! ERROR: $lib reason code $code assigned twice\n";
190
$rassigned{$lib} .= "$code:";
175
191
if(!(exists $rextra{$name}) &&
176
192
($code > $rmax{$lib}) ) {
177
193
$rmax{$lib} = $code;
196
if ($fassigned{$lib} =~ /:$code:/) {
197
print STDERR "!! ERROR: $lib function code $code assigned twice\n";
199
$fassigned{$lib} .= "$code:";
180
200
if($code > $fmax{$lib}) {
181
201
$fmax{$lib} = $code;
183
203
$fcodes{$name} = $code;
210
if (defined($fmax{$lib})) {
211
print STDERR "Max function code fmax" . "{" . "$lib" . "} = $fmax{$lib}\n";
212
$fassigned{$lib} =~ m/^:(.*):$/;
213
@fassigned = sort {$a <=> $b} split(":", $1);
214
print STDERR " @fassigned\n";
216
if (defined($rmax{$lib})) {
217
print STDERR "Max reason code rmax" . "{" . "$lib" . "} = $rmax{$lib}\n";
218
$rassigned{$lib} =~ m/^:(.*):$/;
219
@rassigned = sort {$a <=> $b} split(":", $1);
220
print STDERR " @rassigned\n";
225
if ($rmax{$lib} >= 1000) {
226
print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n";
227
print STDERR "!! Any new alerts must be added to $config.\n";
200
243
# so all those unreferenced can be printed out.
203
print STDERR "Files loaded: " if $debug;
204
246
foreach $file (@source) {
205
247
# Don't parse the error source file.
206
248
next if exists $cskip{$file};
207
print STDERR $file if $debug;
249
print STDERR "File loaded: ".$file."\r" if $debug;
208
250
open(IN, "<$file") || die "Can't open source file $file\n";
210
252
if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
355
397
foreach $i (@function) {
356
398
$z=6-int(length($i)/8);
357
399
if($fcodes{$i} eq "X") {
358
$fcodes{$i} = ++$fmax{$lib};
400
$fassigned{$lib} =~ m/^:([^:]*):/;
402
if (!defined($findcode)) {
403
$findcode = $fmax{$lib};
405
while ($fassigned{$lib} =~ m/:$findcode:/) {
408
$fcodes{$i} = $findcode;
409
$fassigned{$lib} .= "$findcode:";
359
410
print STDERR "New Function code $i\n" if $debug;
361
412
printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
366
417
foreach $i (@reasons) {
367
418
$z=6-int(length($i)/8);
368
419
if($rcodes{$i} eq "X") {
369
$rcodes{$i} = ++$rmax{$lib};
420
$rassigned{$lib} =~ m/^:([^:]*):/;
422
if (!defined($findcode)) {
423
$findcode = $rmax{$lib};
425
while ($rassigned{$lib} =~ m/:$findcode:/) {
428
$rcodes{$i} = $findcode;
429
$rassigned{$lib} .= "$findcode:";
370
430
print STDERR "New Reason code $i\n" if $debug;
372
432
printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;