IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 17, 2004, 4:06:25 PM (22 years ago)
Author:
jhoblitt
Message:

converted to follow the conventions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/misc/parseErrorCodes.pl

    r2377 r2382  
    11#!/usr/bin/perl
     2
     3# Copyright (C) 2004  Somebody
     4#
     5# $somekeyword$
     6
     7use strict;
     8use warnings;
    29
    310# Provides functions for handling long command line options
    411use Getopt::Long;
    512
    6 my @ErrorCodes        = ();
    7 my @ErrorDescriptions = ();
     13my @errorCodes;
     14my @errorDescriptions;
    815
    916my $data = "psErrorCodes.dat";
     17my $verbose;
     18my $help;
    1019
    1120# Assign variables based on the presence of command line options to the script
     
    1827if ($help) {
    1928    print "Usage: parseErrorCodes ", "[--data=$data] ", "[--help] ",
    20       "[--verbose] filename [filename ...]\n\n";
     29        "[--verbose] filename [filename ...]\n\n";
    2130    exit(0);
    2231}
    2332
    2433print "Using data file '$data'\n" if $verbose;
    25 unless ( open( DATAFILE, "<", $data ) ) {
    26     die "Can not open data file $data.";
    27 }
     34open(my $dataFile, "<", $data) or die "Can not open data file $data";
    2835
    2936print "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 );
     37foreach 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);
    4248        } else {
    43             print "I $_\n" if $verbose;
     49            print "I $record\n" if $verbose;
    4450        }
    4551    }
    4652}
    47 close(DATAFILE);
     53close($dataFile) or die "Can not close file $data";
    4854
    49 my $found = $#ErrorCodes + 1;
     55my $found = $#errorCodes + 1;
    5056print "\nFound $found error codes.\n" if $verbose;
    5157
    52 foreach (@ARGV) {
    53     my $filename = $_;
    54     my @result   = ();
     58foreach my $filename (@ARGV) {
     59    my @result;
    5560
    56     die "Failed to open input file"
    57       if !open( INFILE, "<", $filename );
     61    open(my $inFile, "<", $filename) or die "Failed to open input file";
    5862
    5963    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;
    7275            }
    7376
    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/) {
    7780                    $break = 1;
    7881                }
    7982            }
    8083            chop;
    81             push( @result, $_ );
     84            push(@result, $record);
    8285        }
    8386    }
    8487
    85     close(INFILE);
     88    close($inFile) or die "Can not close file $filename";
    8689
    87     die "Failed to overwrite input file"
    88       if !open( OUTFILE, ">", $filename );
     90    open(my $outFile, ">", $filename) or die "Failed to overwrite input file";
    8991
    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;
    9395    }
    9496
    95     close(OUTFILE);
     97    close($outFile) or die "Can not close file $filename";
    9698
    9799}
Note: See TracChangeset for help on using the changeset viewer.