~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to util/mkerr.pl

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2006-05-15 16:00:58 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20060515160058-pg6lnbkkpkwpdj2e
Tags: upstream-0.9.8b
ImportĀ upstreamĀ versionĀ 0.9.8b

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
                        $csrc{$1} = $3;
66
66
                        $fmax{$1} = 99;
67
67
                        $rmax{$1} = 99;
 
68
                        $fassigned{$1} = ":";
 
69
                        $rassigned{$1} = ":";
68
70
                        $fnew{$1} = 0;
69
71
                        $rnew{$1} = 0;
70
72
                }
103
105
                    next;
104
106
                }
105
107
 
 
108
                if(/\/\*/) {
 
109
                    if (not /\*\//) {           # multiline comment...
 
110
                        $line = $_;             # ... just accumulate
 
111
                        next; 
 
112
                    } else {
 
113
                        s/\/\*.*?\*\///gs;      # wipe it
 
114
                    }
 
115
                }
 
116
 
 
117
                if ($cpp) {
 
118
                    $cpp++ if /^#\s*if/;
 
119
                    $cpp-- if /^#\s*endif/;
 
120
                    next;
 
121
                }
106
122
                $cpp = 1 if /^#.*ifdef.*cplusplus/;  # skip "C" declaration
107
 
                if ($cpp) {
108
 
                    $cpp = 0 if /^#.*endif/;
109
 
                    next;
110
 
                }
111
123
 
112
124
                next if (/^\#/);                      # skip preprocessor directives
113
125
 
114
 
                s/\/\*.*?\*\///gs;                   # ignore comments
115
126
                s/{[^{}]*}//gs;                      # ignore {} blocks
116
127
 
117
128
                if (/\{|\/\*/) { # Add a } so editor works...
128
139
            $defnr++;
129
140
            print STDERR "def: $defnr\r" if $debug;
130
141
 
 
142
            # The goal is to collect function names from function declarations.
 
143
 
131
144
            s/^[\n\s]*//g;
132
145
            s/[\n\s]*$//g;
133
 
            next if(/typedef\W/);
134
 
            if (/\(\*(\w*)\([^\)]+/) {
135
 
                my $name = $1;
136
 
                $name =~ tr/[a-z]/[A-Z]/;
137
 
                $ftrans{$name} = $1;
138
 
            } elsif (/\w+\W+(\w+)\W*\(\s*\)(\s*__attribute__\(.*\)\s*)?$/s){
139
 
                # K&R C
140
 
                next ;
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;
145
 
                }
146
 
                s/\(void\)//;
147
 
                /(\w+(\{[0-9]+\})?)\W*\(\)/s;
148
 
                my $name = $1;
149
 
                $name =~ tr/[a-z]/[A-Z]/;
150
 
                $ftrans{$name} = $1;
151
 
            } elsif (/\(/ and not (/=/ or /DECLARE_STACK/ or /TYPEDEF_D2I2D_OF/)) {
 
146
 
 
147
            # Skip over recognized non-function declarations
 
148
            next if(/typedef\W/ or /DECLARE_STACK_OF/ or /TYPEDEF_.*_OF/);
 
149
 
 
150
            # Reduce argument lists to empty ()
 
151
            # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
 
152
            while(/\(.*\)/s) {
 
153
                s/\([^\(\)]+\)/\{\}/gs;
 
154
                s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs;    #(*f{}) -> f
 
155
            }
 
156
            # pretend as we didn't use curly braces: {} -> ()
 
157
            s/\{\}/\(\)/gs;
 
158
 
 
159
            if (/(\w+)\s*\(\).*/s) {    # first token prior [first] () is
 
160
                my $name = $1;          # a function name!
 
161
                $name =~ tr/[a-z]/[A-Z]/;
 
162
                $ftrans{$name} = $1;
 
163
            } elsif (/[\(\)]/ and not (/=/)) {
152
164
                print STDERR "Header $hdr: cannot parse: $_;\n";
153
165
            }
154
166
        }
161
173
        # maximum code used.
162
174
 
163
175
        if ($gotfile) {
164
 
            while(<IN>) {
 
176
          while(<IN>) {
165
177
                if(/^\#define\s+(\S+)\s+(\S+)/) {
166
178
                        $name = $1;
167
179
                        $code = $2;
172
184
                        }
173
185
                        if($1 eq "R") {
174
186
                                $rcodes{$name} = $code;
 
187
                                if ($rassigned{$lib} =~ /:$code:/) {
 
188
                                        print STDERR "!! ERROR: $lib reason code $code assigned twice\n";
 
189
                                }
 
190
                                $rassigned{$lib} .= "$code:";
175
191
                                if(!(exists $rextra{$name}) &&
176
192
                                         ($code > $rmax{$lib}) ) {
177
193
                                        $rmax{$lib} = $code;
178
194
                                }
179
195
                        } else {
 
196
                                if ($fassigned{$lib} =~ /:$code:/) {
 
197
                                        print STDERR "!! ERROR: $lib function code $code assigned twice\n";
 
198
                                }
 
199
                                $fassigned{$lib} .= "$code:";
180
200
                                if($code > $fmax{$lib}) {
181
201
                                        $fmax{$lib} = $code;
182
202
                                }
183
203
                                $fcodes{$name} = $code;
184
204
                        }
185
205
                }
186
 
            }
 
206
          }
 
207
        }
 
208
 
 
209
        if ($debug) {
 
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";
 
215
                }
 
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";
 
221
                }
 
222
        }
 
223
 
 
224
        if ($lib eq "SSL") {
 
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";
 
228
                        print STDERR "\n";
 
229
                }
187
230
        }
188
231
        close IN;
189
232
}
200
243
# so all those unreferenced can be printed out.
201
244
 
202
245
 
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";
209
251
        while(<IN>) {
210
252
                if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
228
270
        }
229
271
        close IN;
230
272
}
231
 
print STDERR "\n" if $debug;
 
273
print STDERR "                                  \n" if $debug;
232
274
 
233
275
# Now process each library in turn.
234
276
 
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/^:([^:]*):/;
 
401
                        $findcode = $1;
 
402
                        if (!defined($findcode)) {
 
403
                                $findcode = $fmax{$lib};
 
404
                        }
 
405
                        while ($fassigned{$lib} =~ m/:$findcode:/) {
 
406
                                $findcode++;
 
407
                        }
 
408
                        $fcodes{$i} = $findcode;
 
409
                        $fassigned{$lib} .= "$findcode:";
359
410
                        print STDERR "New Function code $i\n" if $debug;
360
411
                }
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/^:([^:]*):/;
 
421
                        $findcode = $1;
 
422
                        if (!defined($findcode)) {
 
423
                                $findcode = $rmax{$lib};
 
424
                        }
 
425
                        while ($rassigned{$lib} =~ m/:$findcode:/) {
 
426
                                $findcode++;
 
427
                        }
 
428
                        $rcodes{$i} = $findcode;
 
429
                        $rassigned{$lib} .= "$findcode:";
370
430
                        print STDERR "New Reason code   $i\n" if $debug;
371
431
                }
372
432
                printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;