a5ba05a7966d7593eb519b626a973960b0cd8b19
[openssl.git] / util / mkerr.pl
1 #!/usr/local/bin/perl -w
2
3 my $config = "crypto/err/openssl.ec";
4 my $debug = 0;
5 my $rebuild = 0;
6 my $static = 1;
7 my $recurse = 0;
8 my $reindex = 0;
9 my $dowrite = 0;
10 my $staticloader = "";
11
12 my $pack_errcode;
13 my $load_errcode;
14
15 while (@ARGV) {
16         my $arg = $ARGV[0];
17         if($arg eq "-conf") {
18                 shift @ARGV;
19                 $config = shift @ARGV;
20         } elsif($arg eq "-debug") {
21                 $debug = 1;
22                 shift @ARGV;
23         } elsif($arg eq "-rebuild") {
24                 $rebuild = 1;
25                 shift @ARGV;
26         } elsif($arg eq "-recurse") {
27                 $recurse = 1;
28                 shift @ARGV;
29         } elsif($arg eq "-reindex") {
30                 $reindex = 1;
31                 shift @ARGV;
32         } elsif($arg eq "-nostatic") {
33                 $static = 0;
34                 shift @ARGV;
35         } elsif($arg eq "-staticloader") {
36                 $staticloader = "static ";
37                 shift @ARGV;
38         } elsif($arg eq "-write") {
39                 $dowrite = 1;
40                 shift @ARGV;
41         } else {
42                 last;
43         }
44 }
45
46 if($recurse) {
47         @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>);
48 } else {
49         @source = @ARGV;
50 }
51
52 # Read in the config file
53
54 open(IN, "<$config") || die "Can't open config file $config";
55
56 # Parse config file
57
58 while(<IN>)
59 {
60         if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
61                 $hinc{$1} = $2;
62                 $libinc{$2} = $1;
63                 $cskip{$3} = $1;
64                 if($3 ne "NONE") {
65                         $csrc{$1} = $3;
66                         $fmax{$1} = 99;
67                         $rmax{$1} = 99;
68                         $fnew{$1} = 0;
69                         $rnew{$1} = 0;
70                 }
71         } elsif (/^F\s+(\S+)/) {
72         # Add extra function with $1
73         } elsif (/^R\s+(\S+)\s+(\S+)/) {
74                 $rextra{$1} = $2;
75                 $rcodes{$1} = $2;
76         }
77 }
78
79 close IN;
80
81 # Scan each header file in turn and make a list of error codes
82 # and function names
83
84 while (($hdr, $lib) = each %libinc)
85 {
86         next if($hdr eq "NONE");
87         print STDERR "Scanning header file $hdr\n" if $debug; 
88         my $line = "", $def= "", $linenr = 0, $gotfile = 0;
89         if (open(IN, "<$hdr")) {
90             $gotfile = 1;
91             while(<IN>) {
92                 $linenr++;
93                 print STDERR "line: $linenr\r" if $debug;
94
95                 last if(/BEGIN\s+ERROR\s+CODES/);
96                 if ($line ne '') {
97                     $_ = $line . $_;
98                     $line = '';
99                 }
100
101                 if (/\\$/) {
102                     $line = $_;
103                     next;
104                 }
105
106                 if(/\/\*/) {
107                     if (not /\*\//) {           # multiline comment...
108                         $line = $_;             # ... just accumulate
109                         next; 
110                     } else {
111                         s/\/\*.*?\*\///gs;      # wipe it
112                     }
113                 }
114
115                 if ($cpp) {
116                     $cpp++ if /^#\s*if/;
117                     $cpp-- if /^#\s*endif/;
118                     next;
119                 }
120                 $cpp = 1 if /^#.*ifdef.*cplusplus/;  # skip "C" declaration
121
122                 next if (/^\#/);                      # skip preprocessor directives
123
124                 s/{[^{}]*}//gs;                      # ignore {} blocks
125
126                 if (/\{|\/\*/) { # Add a } so editor works...
127                     $line = $_;
128                 } else {
129                     $def .= $_;
130                 }
131             }
132         }
133
134         print STDERR "                                  \r" if $debug;
135         $defnr = 0;
136         foreach (split /;/, $def) {
137             $defnr++;
138             print STDERR "def: $defnr\r" if $debug;
139
140             # The goal is to collect function names from function declarations.
141
142             s/^[\n\s]*//g;
143             s/[\n\s]*$//g;
144
145             # Skip over recognized non-function declarations
146             next if(/typedef\W/ or /DECLARE_STACK_OF/ or /TYPEDEF_.*_OF/);
147
148             # Reduce argument lists to empty ()
149             # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
150             while(/\(.*\)/s) {
151                 s/\([^\(\)]+\)/\{\}/gs;
152                 s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs;    #(*f{}) -> f
153             }
154             # pretend as we didn't use curly braces: {} -> ()
155             s/\{\}/\(\)/gs;
156
157             if (/(\w+)\s*\(\).*/s) {    # first token prior [first] () is
158                 my $name = $1;          # a function name!
159                 $name =~ tr/[a-z]/[A-Z]/;
160                 $ftrans{$name} = $1;
161             } elsif (/[\(\)]/ and not (/=/)) {
162                 print STDERR "Header $hdr: cannot parse: $_;\n";
163             }
164         }
165
166         print STDERR "                                  \r" if $debug;
167
168         next if $reindex;
169
170         # Scan function and reason codes and store them: keep a note of the
171         # maximum code used.
172
173         if ($gotfile) {
174             while(<IN>) {
175                 if(/^\#define\s+(\S+)\s+(\S+)/) {
176                         $name = $1;
177                         $code = $2;
178                         next if $name =~ /^${lib}err/;
179                         unless($name =~ /^${lib}_([RF])_(\w+)$/) {
180                                 print STDERR "Invalid error code $name\n";
181                                 next;
182                         }
183                         if($1 eq "R") {
184                                 $rcodes{$name} = $code;
185                                 if(!(exists $rextra{$name}) &&
186                                          ($code > $rmax{$lib}) ) {
187                                         $rmax{$lib} = $code;
188                                 }
189                         } else {
190                                 if($code > $fmax{$lib}) {
191                                         $fmax{$lib} = $code;
192                                 }
193                                 $fcodes{$name} = $code;
194                         }
195                 }
196             }
197         }
198
199         if ($debug) {
200                 if (defined($rmax{$lib})) {
201                         print STDERR "Max reason code rmax" . "{" . "$lib" . "} = $rmax{$lib}\n";
202                 }
203                 if (defined($fmax{$lib})) {
204                         print STDERR "Max function code fmax" . "{" . "$lib" . "} = $fmax{$lib}\n";
205                 }
206         }
207
208         if ($lib eq "SSL") {
209                 if ($rmax{$lib} >= 1000) {
210                         print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n";
211                         print STDERR "!!        Any new alerts must be added to $config.\n";
212                         print STDERR "\n";
213                 }
214         }
215         close IN;
216 }
217
218 # Scan each C source file and look for function and reason codes
219 # This is done by looking for strings that "look like" function or
220 # reason codes: basically anything consisting of all upper case and
221 # numerics which has _F_ or _R_ in it and which has the name of an
222 # error library at the start. This seems to work fine except for the
223 # oddly named structure BIO_F_CTX which needs to be ignored.
224 # If a code doesn't exist in list compiled from headers then mark it
225 # with the value "X" as a place holder to give it a value later.
226 # Store all function and reason codes found in %ufcodes and %urcodes
227 # so all those unreferenced can be printed out.
228
229
230 foreach $file (@source) {
231         # Don't parse the error source file.
232         next if exists $cskip{$file};
233         print STDERR "File loaded: ".$file."\r" if $debug;
234         open(IN, "<$file") || die "Can't open source file $file\n";
235         while(<IN>) {
236                 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
237                         next unless exists $csrc{$2};
238                         next if($1 eq "BIO_F_BUFFER_CTX");
239                         $ufcodes{$1} = 1;
240                         if(!exists $fcodes{$1}) {
241                                 $fcodes{$1} = "X";
242                                 $fnew{$2}++;
243                         }
244                         $notrans{$1} = 1 unless exists $ftrans{$3};
245                 }
246                 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
247                         next unless exists $csrc{$2};
248                         $urcodes{$1} = 1;
249                         if(!exists $rcodes{$1}) {
250                                 $rcodes{$1} = "X";
251                                 $rnew{$2}++;
252                         }
253                 } 
254         }
255         close IN;
256 }
257 print STDERR "                                  \n" if $debug;
258
259 # Now process each library in turn.
260
261 foreach $lib (keys %csrc)
262 {
263         my $hfile = $hinc{$lib};
264         my $cfile = $csrc{$lib};
265         if(!$fnew{$lib} && !$rnew{$lib}) {
266                 print STDERR "$lib:\t\tNo new error codes\n";
267                 next unless $rebuild;
268         } else {
269                 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
270                 print STDERR " $rnew{$lib} New Reasons.\n";
271                 next unless $dowrite;
272         }
273
274         # If we get here then we have some new error codes so we
275         # need to rebuild the header file and C file.
276
277         # Make a sorted list of error and reason codes for later use.
278
279         my @function = sort grep(/^${lib}_/,keys %fcodes);
280         my @reasons = sort grep(/^${lib}_/,keys %rcodes);
281
282         # Rewrite the header file
283
284         if (open(IN, "<$hfile")) {
285             # Copy across the old file
286             while(<IN>) {
287                 push @out, $_;
288                 last if (/BEGIN ERROR CODES/);
289             }
290             close IN;
291         } else {
292             push @out,
293 "/* ====================================================================\n",
294 " * Copyright (c) 2001-2005 The OpenSSL Project.  All rights reserved.\n",
295 " *\n",
296 " * Redistribution and use in source and binary forms, with or without\n",
297 " * modification, are permitted provided that the following conditions\n",
298 " * are met:\n",
299 " *\n",
300 " * 1. Redistributions of source code must retain the above copyright\n",
301 " *    notice, this list of conditions and the following disclaimer. \n",
302 " *\n",
303 " * 2. Redistributions in binary form must reproduce the above copyright\n",
304 " *    notice, this list of conditions and the following disclaimer in\n",
305 " *    the documentation and/or other materials provided with the\n",
306 " *    distribution.\n",
307 " *\n",
308 " * 3. All advertising materials mentioning features or use of this\n",
309 " *    software must display the following acknowledgment:\n",
310 " *    \"This product includes software developed by the OpenSSL Project\n",
311 " *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n",
312 " *\n",
313 " * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n",
314 " *    endorse or promote products derived from this software without\n",
315 " *    prior written permission. For written permission, please contact\n",
316 " *    openssl-core\@openssl.org.\n",
317 " *\n",
318 " * 5. Products derived from this software may not be called \"OpenSSL\"\n",
319 " *    nor may \"OpenSSL\" appear in their names without prior written\n",
320 " *    permission of the OpenSSL Project.\n",
321 " *\n",
322 " * 6. Redistributions of any form whatsoever must retain the following\n",
323 " *    acknowledgment:\n",
324 " *    \"This product includes software developed by the OpenSSL Project\n",
325 " *    for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n",
326 " *\n",
327 " * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n",
328 " * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n",
329 " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n",
330 " * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\n",
331 " * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n",
332 " * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n",
333 " * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n",
334 " * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n",
335 " * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n",
336 " * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n",
337 " * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n",
338 " * OF THE POSSIBILITY OF SUCH DAMAGE.\n",
339 " * ====================================================================\n",
340 " *\n",
341 " * This product includes cryptographic software written by Eric Young\n",
342 " * (eay\@cryptsoft.com).  This product includes software written by Tim\n",
343 " * Hudson (tjh\@cryptsoft.com).\n",
344 " *\n",
345 " */\n",
346 "\n",
347 "#ifndef HEADER_${lib}_ERR_H\n",
348 "#define HEADER_${lib}_ERR_H\n",
349 "\n",
350 "/* BEGIN ERROR CODES */\n";
351         }
352         open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
353
354         print OUT @out;
355         undef @out;
356         print OUT <<"EOF";
357 /* The following lines are auto generated by the script mkerr.pl. Any changes
358  * made after this point may be overwritten when the script is next run.
359  */
360 EOF
361         if($static) {
362                 print OUT <<"EOF";
363 ${staticloader}void ERR_load_${lib}_strings(void);
364
365 EOF
366         } else {
367                 print OUT <<"EOF";
368 ${staticloader}void ERR_load_${lib}_strings(void);
369 ${staticloader}void ERR_unload_${lib}_strings(void);
370 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
371 #define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
372
373 EOF
374         }
375         print OUT <<"EOF";
376 /* Error codes for the $lib functions. */
377
378 /* Function codes. */
379 EOF
380
381         foreach $i (@function) {
382                 $z=6-int(length($i)/8);
383                 if($fcodes{$i} eq "X") {
384                         $fcodes{$i} = ++$fmax{$lib};
385                         print STDERR "New Function code $i\n" if $debug;
386                 }
387                 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
388         }
389
390         print OUT "\n/* Reason codes. */\n";
391
392         foreach $i (@reasons) {
393                 $z=6-int(length($i)/8);
394                 if($rcodes{$i} eq "X") {
395                         $rcodes{$i} = ++$rmax{$lib};
396                         print STDERR "New Reason code   $i\n" if $debug;
397                 }
398                 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
399         }
400         print OUT <<"EOF";
401
402 #ifdef  __cplusplus
403 }
404 #endif
405 #endif
406 EOF
407         close OUT;
408
409         # Rewrite the C source file containing the error details.
410
411         # First, read any existing reason string definitions:
412         my %err_reason_strings;
413         if (open(IN,"<$cfile")) {
414                 while (<IN>) {
415                         if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
416                                 $err_reason_strings{$1} = $2;
417                         }
418                 }
419                 close(IN);
420         }
421
422         my $hincf;
423         if($static) {
424                 $hfile =~ /([^\/]+)$/;
425                 $hincf = "<openssl/$1>";
426         } else {
427                 $hincf = "\"$hfile\"";
428         }
429
430         # If static we know the error code at compile time so use it
431         # in error definitions.
432
433         if ($static)
434                 {
435                 $pack_errcode = "ERR_LIB_${lib}";
436                 $load_errcode = "0";
437                 }
438         else
439                 {
440                 $pack_errcode = "0";
441                 $load_errcode = "ERR_LIB_${lib}";
442                 }
443
444
445         open (OUT,">$cfile") || die "Can't open $cfile for writing";
446
447         print OUT <<"EOF";
448 /* $cfile */
449 /* ====================================================================
450  * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
451  *
452  * Redistribution and use in source and binary forms, with or without
453  * modification, are permitted provided that the following conditions
454  * are met:
455  *
456  * 1. Redistributions of source code must retain the above copyright
457  *    notice, this list of conditions and the following disclaimer. 
458  *
459  * 2. Redistributions in binary form must reproduce the above copyright
460  *    notice, this list of conditions and the following disclaimer in
461  *    the documentation and/or other materials provided with the
462  *    distribution.
463  *
464  * 3. All advertising materials mentioning features or use of this
465  *    software must display the following acknowledgment:
466  *    "This product includes software developed by the OpenSSL Project
467  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
468  *
469  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
470  *    endorse or promote products derived from this software without
471  *    prior written permission. For written permission, please contact
472  *    openssl-core\@OpenSSL.org.
473  *
474  * 5. Products derived from this software may not be called "OpenSSL"
475  *    nor may "OpenSSL" appear in their names without prior written
476  *    permission of the OpenSSL Project.
477  *
478  * 6. Redistributions of any form whatsoever must retain the following
479  *    acknowledgment:
480  *    "This product includes software developed by the OpenSSL Project
481  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
482  *
483  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
484  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
485  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
486  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
487  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
488  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
489  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
490  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
491  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
492  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
493  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
494  * OF THE POSSIBILITY OF SUCH DAMAGE.
495  * ====================================================================
496  *
497  * This product includes cryptographic software written by Eric Young
498  * (eay\@cryptsoft.com).  This product includes software written by Tim
499  * Hudson (tjh\@cryptsoft.com).
500  *
501  */
502
503 /* NOTE: this file was auto generated by the mkerr.pl script: any changes
504  * made to it will be overwritten when the script next updates this file,
505  * only reason strings will be preserved.
506  */
507
508 #include <stdio.h>
509 #include <openssl/err.h>
510 #include $hincf
511
512 /* BEGIN ERROR CODES */
513 #ifndef OPENSSL_NO_ERR
514
515 #define ERR_FUNC(func) ERR_PACK($pack_errcode,func,0)
516 #define ERR_REASON(reason) ERR_PACK($pack_errcode,0,reason)
517
518 static ERR_STRING_DATA ${lib}_str_functs[]=
519         {
520 EOF
521         # Add each function code: if a function name is found then use it.
522         foreach $i (@function) {
523                 my $fn;
524                 $i =~ /^${lib}_F_(\S+)$/;
525                 $fn = $1;
526                 if(exists $ftrans{$fn}) {
527                         $fn = $ftrans{$fn};
528                 }
529 #               print OUT "{ERR_PACK($pack_errcode,$i,0),\t\"$fn\"},\n";
530                 print OUT "{ERR_FUNC($i),\t\"$fn\"},\n";
531         }
532         print OUT <<"EOF";
533 {0,NULL}
534         };
535
536 static ERR_STRING_DATA ${lib}_str_reasons[]=
537         {
538 EOF
539         # Add each reason code.
540         foreach $i (@reasons) {
541                 my $rn;
542                 my $rstr = "ERR_REASON($i)";
543                 my $nspc = 0;
544                 if (exists $err_reason_strings{$i}) {
545                         $rn = $err_reason_strings{$i};
546                 } else {
547                         $i =~ /^${lib}_R_(\S+)$/;
548                         $rn = $1;
549                         $rn =~ tr/_[A-Z]/ [a-z]/;
550                 }
551                 $nspc = 40 - length($rstr) unless length($rstr) > 40;
552                 $nspc = " " x $nspc;
553                 print OUT "{${rstr}${nspc},\"$rn\"},\n";
554         }
555 if($static) {
556         print OUT <<"EOF";
557 {0,NULL}
558         };
559
560 #endif
561
562 ${staticloader}void ERR_load_${lib}_strings(void)
563         {
564         static int init=1;
565
566         if (init)
567                 {
568                 init=0;
569 #ifndef OPENSSL_NO_ERR
570                 ERR_load_strings($load_errcode,${lib}_str_functs);
571                 ERR_load_strings($load_errcode,${lib}_str_reasons);
572 #endif
573
574                 }
575         }
576 EOF
577 } else {
578         print OUT <<"EOF";
579 {0,NULL}
580         };
581
582 #endif
583
584 #ifdef ${lib}_LIB_NAME
585 static ERR_STRING_DATA ${lib}_lib_name[]=
586         {
587 {0      ,${lib}_LIB_NAME},
588 {0,NULL}
589         };
590 #endif
591
592
593 static int ${lib}_lib_error_code=0;
594 static int ${lib}_error_init=1;
595
596 ${staticloader}void ERR_load_${lib}_strings(void)
597         {
598         if (${lib}_lib_error_code == 0)
599                 ${lib}_lib_error_code=ERR_get_next_error_library();
600
601         if (${lib}_error_init)
602                 {
603                 ${lib}_error_init=0;
604 #ifndef OPENSSL_NO_ERR
605                 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
606                 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
607 #endif
608
609 #ifdef ${lib}_LIB_NAME
610                 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
611                 ERR_load_strings(0,${lib}_lib_name);
612 #endif
613                 }
614         }
615
616 ${staticloader}void ERR_unload_${lib}_strings(void)
617         {
618         if (${lib}_error_init == 0)
619                 {
620 #ifndef OPENSSL_NO_ERR
621                 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs);
622                 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons);
623 #endif
624
625 #ifdef ${lib}_LIB_NAME
626                 ERR_unload_strings(0,${lib}_lib_name);
627 #endif
628                 ${lib}_error_init=1;
629                 }
630         }
631
632 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
633         {
634         if (${lib}_lib_error_code == 0)
635                 ${lib}_lib_error_code=ERR_get_next_error_library();
636         ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
637         }
638 EOF
639
640 }
641
642         close OUT;
643         undef %err_reason_strings;
644 }
645
646 if($debug && defined(%notrans)) {
647         print STDERR "The following function codes were not translated:\n";
648         foreach(sort keys %notrans)
649         {
650                 print STDERR "$_\n";
651         }
652 }
653
654 # Make a list of unreferenced function and reason codes
655
656 foreach (keys %fcodes) {
657         push (@funref, $_) unless exists $ufcodes{$_};
658 }
659
660 foreach (keys %rcodes) {
661         push (@runref, $_) unless exists $urcodes{$_};
662 }
663
664 if($debug && defined(@funref) ) {
665         print STDERR "The following function codes were not referenced:\n";
666         foreach(sort @funref)
667         {
668                 print STDERR "$_\n";
669         }
670 }
671
672 if($debug && defined(@runref) ) {
673         print STDERR "The following reason codes were not referenced:\n";
674         foreach(sort @runref)
675         {
676                 print STDERR "$_\n";
677         }
678 }