=================================================================== RCS file: /cvs/pta/pta_import.pl,v retrieving revision 1.27 retrieving revision 1.28 diff -u -p -r1.27 -r1.28 --- pta/pta_import.pl 2020/11/30 16:22:36 1.27 +++ pta/pta_import.pl 2020/12/11 19:28:12 1.28 @@ -64,53 +64,71 @@ my ($cost_center_field, $csv_account, $date_field, $da @compiled, @description_fields, @ignored); while (<$in>) { chomp; + s/\s+$//; next if /^(?:#|$)/; my $line = $_; - if (/^ACCOUNT\s+(\S+)$/) { - $csv_account and die "duplicate ACCOUNT line: $1"; + if (s/^ACCOUNT\s+//) { + $csv_account and die "duplicate ACCOUNT line: $_"; + /^(\d+)$/ or die "ACCOUNT parse error: $_"; $csv_account = $1; next; } if (s/^AMOUNT\s+//) { + @amount_fields and die "duplicate AMOUNT line: $_"; push @amount_fields, $1 - 1 while s/(\d+)\s*//; $_ eq '' or die "trailing garbage: AMOUNT ... $_"; next; } - if (/^COSTCENTER\s+(\d+)/) { + if (s/^COSTCENTER\s+//) { + $cost_center_field and + die "duplicate COSTCENTER line: $_"; + /^(\d+)$/ or die "COSTCENTER parse error: $_"; $cost_center_field = $1 - 1; next; } - if (/^DATE\s+(\d+)\s+(\S+)/) { - $date_field = $1 - 1; + if (s/^DATE\s+//) { + $date_field || $date_regex and + die "duplicate DATE line: $_"; + s/^(\d+)\s+(\S+)$//; + $date_field = $1 or + die "DATE date_field parse error: $_"; + $date_field -= 1; $date_regex = $date_formats{$2} or die "unknown date format: $2"; next; } - if (/^DELIM\s+(\S)$/) { + if (s/^DELIM\s+//) { $delim and die "duplicate DELIM line: $1"; + /^([^|\^\$\*\+\?\(\)\[\]\{\}\\])$/ or + die "DELIM parse error: $_"; $delim = $1; next; } if (s/^DESCRIPTION\s+//) { - push @description_fields, $1 - 1 while s/(\d+)\s*//; - $_ eq '' or die "trailing garbage: DESCRIPTION ... $_"; - next; + @description_fields and die "duplicate DESCRIPTION line: $_"; + push @description_fields, $1 - 1 while s/(\d+)\s*//; + $_ eq '' or die "trailing garbage: DESCRIPTION ... $_"; + next; } - if (/^HEADER\s+(.*)$/) { + if (s/^HEADER\s+//) { $header and die "duplicate HEADER line: $1"; - $header = $1; + $header = $_; next; } - if (/^IGNORE\s+(.*)/) { - push @ignored, qr/$1/; + if (s/^IGNORE\s+//) { + push @ignored, qr/$_/; next; } - if (/^QUANTITY\s+(\d+)/) { + if (s/^QUANTITY\s+//) { + $quantity_field and die "duplicate QUANTITY line: $1"; + /^(\d+)$/ or die "QUANTITY parse error: $_"; $quantity_field = $1 - 1; next; } - if (/^QUOTE\s+(\S)$/) { + if (s/^QUOTE\s+//) { $quote and die "duplicate QUOTE line: $1"; + /^([^|\^\$\*\+\?\(\)\[\]\{\}\\])$/ or + die "QUOTE parse error: $_"; $quote = $1; next; } @@ -132,6 +150,7 @@ if (@ARGV) { } LINE: while () { chomp; + s/\s*$//; next if (/^$/); foreach my $ignore (@ignored) { next LINE if /$ignore/;