Changeset 2382
- Timestamp:
- Nov 17, 2004, 4:06:25 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/doc/misc/parseErrorCodes.pl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/misc/parseErrorCodes.pl
r2377 r2382 1 1 #!/usr/bin/perl 2 3 # Copyright (C) 2004 Somebody 4 # 5 # $somekeyword$ 6 7 use strict; 8 use warnings; 2 9 3 10 # Provides functions for handling long command line options 4 11 use Getopt::Long; 5 12 6 my @ ErrorCodes = ();7 my @ ErrorDescriptions = ();13 my @errorCodes; 14 my @errorDescriptions; 8 15 9 16 my $data = "psErrorCodes.dat"; 17 my $verbose; 18 my $help; 10 19 11 20 # Assign variables based on the presence of command line options to the script … … 18 27 if ($help) { 19 28 print "Usage: parseErrorCodes ", "[--data=$data] ", "[--help] ", 20 "[--verbose] filename [filename ...]\n\n";29 "[--verbose] filename [filename ...]\n\n"; 21 30 exit(0); 22 31 } 23 32 24 33 print "Using data file '$data'\n" if $verbose; 25 unless ( open( DATAFILE, "<", $data ) ) { 26 die "Can not open data file $data."; 27 } 34 open(my $dataFile, "<", $data) or die "Can not open data file $data"; 28 35 29 36 print "Datafile:\n" if $verbose; 30 while (<DATAFILE>) { 31 chop; 32 if (/^\s*\#/) { 33 print "C $_\n" if $verbose; 34 } 35 else { 36 if (/^\s*(\w+)\s+([\%\w].*)/) { 37 my $ErrorCode = $1; 38 my $ErrorDescription = $2; 39 print " $ErrorCode: '$ErrorDescription'\n" if $verbose; 40 push( @ErrorCodes, $ErrorCode ); 41 push( @ErrorDescriptions, $ErrorDescription ); 37 foreach my $record (<$dataFile>) { 38 chop $record; 39 if ($record =~ /^\s*\#/) { 40 print "C $record\n" if $verbose; 41 } else { 42 if ($record =~ /^\s*(\w+)\s+([\%\w].*)/) { 43 my $errorCode = $1; 44 my $errorDescription = $2; 45 print " $errorCode: '$errorDescription'\n" if $verbose; 46 push(@errorCodes, $errorCode); 47 push(@errorDescriptions, $errorDescription); 42 48 } else { 43 print "I $ _\n" if $verbose;49 print "I $record\n" if $verbose; 44 50 } 45 51 } 46 52 } 47 close( DATAFILE);53 close($dataFile) or die "Can not close file $data"; 48 54 49 my $found = $# ErrorCodes + 1;55 my $found = $#errorCodes + 1; 50 56 print "\nFound $found error codes.\n" if $verbose; 51 57 52 foreach (@ARGV) { 53 my $filename = $_; 54 my @result = (); 58 foreach my $filename (@ARGV) { 59 my @result; 55 60 56 die "Failed to open input file" 57 if !open( INFILE, "<", $filename ); 61 open(my $inFile, "<", $filename) or die "Failed to open input file"; 58 62 59 63 print "\nOutput File:\n" if $verbose; 60 while (<INFILE>) { 61 chop; 62 push( @result, $_ ); 63 if (/^\s*\/\/~Start(.*)$/) { 64 $line = $1; 65 for ( $n = 0 ; $n < $found ; $n++ ) { 66 $_ = $line; 67 s/\$1/$ErrorCodes[$n]/g; 68 s/\$2/$ErrorDescriptions[$n]/g; 69 s/\$n/$n/g; 70 push( @result, $_ ); 71 print "$_\n" if $verbose; 64 foreach my $record (<$inFile>) { 65 chop $record; 66 push(@result, $record); 67 if ($record =~ /^\s*\/\/~Start(.*)$/) { 68 my $line = $1; 69 for (my $n = 0; $n < $found; $n++) { 70 $line =~ s/\$1/$errorCodes[$n]/g; 71 $line =~ s/\$2/$errorDescriptions[$n]/g; 72 $line =~ s/\$n/$n/g; 73 push(@result, $line); 74 print "$line\n" if $verbose; 72 75 } 73 76 74 $break = 0;75 while ( ( $break == 0 ) && ( $_ = <INFILE> )) {76 if ( /^\s*\/\/~End/) {77 my $break = 0; 78 while (($break == 0) && (my $record = <$inFile>)) { 79 if ($record =~ /^\s*\/\/~End/) { 77 80 $break = 1; 78 81 } 79 82 } 80 83 chop; 81 push( @result, $_);84 push(@result, $record); 82 85 } 83 86 } 84 87 85 close( INFILE);88 close($inFile) or die "Can not close file $filename"; 86 89 87 die "Failed to overwrite input file" 88 if !open( OUTFILE, ">", $filename ); 90 open(my $outFile, ">", $filename) or die "Failed to overwrite input file"; 89 91 90 foreach (@result) {91 print OUTFILE "$_\n";92 print "$ _\n" if $verbose;92 foreach my $res (@result) { 93 print $outFile, "$res\n"; 94 print "$res\n" if $verbose; 93 95 } 94 96 95 close( OUTFILE);97 close($outFile) or die "Can not close file $filename"; 96 98 97 99 }
Note:
See TracChangeset
for help on using the changeset viewer.
