=================================================================== RCS file: /cvs/pta/pta_import.pl,v retrieving revision 1.13 retrieving revision 1.14 diff -u -p -r1.13 -r1.14 --- pta/pta_import.pl 2020/11/18 21:32:16 1.13 +++ pta/pta_import.pl 2020/11/18 22:25:05 1.14 @@ -118,20 +118,18 @@ sub usage () { # === MAIN PROGRAM ===================================================== -my ($csv_account, $fn, $in, $account_name, $delim, @compiled); - -# Parse command line arguments. getopts 'I:' or usage; -if ($opt_I) { - $account_name = $opt_I; - $banks{$account_name} or die "unknown accountname: $account_name"; - $fn = "import_" . $account_name . ".txt"; - open $in, $fn or die "$fn: $!"; -} else { +unless ($opt_I) { + warn "The option -I is required."; usage; } +my $account_name = $opt_I; +$banks{$account_name} or die "unknown accountname: $account_name"; # Parse the configuration file. +my $fn = "import_" . $account_name . ".txt"; +open my $in, '<', $fn or die "$fn: $!"; +my ($csv_account, $delim, $header, @compiled); while (<$in>) { chomp; next if /^(?:#|$)/; @@ -146,6 +144,11 @@ while (<$in>) { $delim = $1; next; } + if (/^HEADER\s+(.*)$/) { + $header and die "duplicate HEADER line: $1"; + $header = $1; + next; + } $delim or die "no DELIM line in $fn"; s/^(.*)$delim\s+(\d+)\s+(\S+)// or die "$fn import parse error: $line"; @@ -159,11 +162,16 @@ close $in; $csv_account or die "no ACCOUNT line in $fn"; # Parse the CSV file from the bank. -chomp(my $header = <>); while (<>) { chomp; next if (/^$/); my $line = $_; + if ($header) { + $line eq $header + or die "expected HEADER $header\nbut got $line"; + undef $header; + next; + } my @fields = split /$delim/, $line; my $matches = 0; my ($account, $booking);