Changeset 5159

Show
Ignore:
Timestamp:
03/24/08 12:28:33 (8 months ago)
Author:
khali
Message:

Make command line parsing more robust.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • i2c-tools/trunk/eeprom/decode-dimms.pl

    r5158 r5159  
    11751175} 
    11761176 
    1177 for (@ARGV) { 
    1178         if (/^-?-h/) { 
     1177# Parse command-line 
     1178foreach (@ARGV) { 
     1179        if ($_ eq '-h' || $_ eq '--help') { 
    11791180                print "Usage: $0 [-c] [-f [-b]] [-x file [files..]]\n", 
    11801181                        "       $0 -h\n\n", 
    1181                         "  -f, --format            print nice html output\n", 
    1182                         "  -b, --bodyonly          don't print html header\n", 
     1182                        "  -f, --format            Print nice html output\n", 
     1183                        "  -b, --bodyonly          Don't print html header\n", 
    11831184                        "                          (useful for postprocessing the output)\n", 
    1184                         "  -c, --checksum          decode completely even if checksum fails\n", 
     1185                        "  -c, --checksum          Decode completely even if checksum fails\n", 
    11851186                        "  -x,                     Read data from hexdump files\n", 
    1186                         "  -h, --help              display this usage summary\n"; 
     1187                        "  -h, --help              Display this usage summary\n"; 
    11871188                print <<"EOF"; 
    11881189 
     
    11951196                exit; 
    11961197        } 
    1197         $opt_html = 1 if (/^-?-f/); 
    1198         $opt_bodyonly = 1 if (/^-?-b/); 
    1199         $opt_igncheck = 1 if (/^-?-c/); 
    1200         $use_hexdump = 1 if (/^-x/); 
    1201         push @dimm_list, $_ if ($use_hexdump && !/^-/); 
     1198 
     1199        if ($_ eq '-f' || $_ eq '--format') { 
     1200                $opt_html = 1; 
     1201                next; 
     1202        } 
     1203        if ($_ eq '-b' || $_ eq '--bodyonly') { 
     1204                $opt_bodyonly = 1; 
     1205                next; 
     1206        } 
     1207        if ($_ eq '-c' || $_ eq '--checksum') { 
     1208                $opt_igncheck = 1; 
     1209                next; 
     1210        } 
     1211        if ($_ eq '-x') { 
     1212                $use_hexdump = 1; 
     1213                next; 
     1214        } 
     1215 
     1216        if (m/^-/) { 
     1217                print STDERR "Unrecognized option $_\n"; 
     1218                exit; 
     1219        } 
     1220 
     1221        push @dimm_list, $_ if $use_hexdump; 
    12021222} 
    12031223$opt_body = $opt_html && ! $opt_bodyonly;