."year year(4) not null,"
."month tinyint not null,"
."month_last tinyint not null,"
+ ."sequential smallint not null,"
."contents text not null"
.")");
&db_do("alter table $tb_obsah add unique (year,month)");
-use vars qw/$insert_tb_obsah $year $month $month_last $contents/;
+use vars qw/$insert_tb_obsah $year $month $month_last $sequential $contents $first/;
sub where
{
else {
tr/ \t\n/ \n/s;
s/([\001\n]) | ([\002\n])/$1$2/g;
- s/\nstrana \.\.\. ([\d ,]+\002)/\003$1/g;
- die "Page marker not found somewhere in this month".&where() if (/\001[^\003]*\002/);
+ die "Page marker not found somewhere in this month".&where() if (/^[^\004]*\001[^\003\004]*\002/);
+ die "Duplicate page markers in this month".&where() if (/strana /);
tr/\002//d;
$_=substr($_,1);
}
- $insert_tb_obsah->execute($year,$month,$month_last,$_) or die "SQL insert failure: $!";
+ $insert_tb_obsah->execute($year,$month,$month_last,$sequential,$_) or die "SQL insert failure: $!";
undef $year,$month;
undef $contents;
+ undef $first;
}
-$insert_tb_obsah=$db->prepare("insert into $tb_obsah (year,month,month_last,contents) values (?,?,?,?)")
+$insert_tb_obsah=$db->prepare("insert into $tb_obsah (year,month,month_last,sequential,contents) values (?,?,?,?,?)")
or die "Prepare fail: $!";
while (<>) {
chomp;
- if (m#^EaP (\d+)(-(\d+))?/(\d+)$#) {
+ if (m#^EaP (\d+)(-(\d+))?/(\d+) \((\d+)(-\d+)?\)$#) {
&flush_month();
$month=$1;
$month_last=($3 ? $3 : $1);
$year =$4;
+ $sequential=$5;
$contents="";
next;
}
- if (/^\.\s(.*)$/) {
- $contents.="\001$1\002";
+ if (/^Pøíloha:$/) {
+ die "Multiple \"Pøíloha\"s".&where() if ($contents=~/\004/);
+ $contents.="\004";
+ next;
+ }
+ if (/^[^[:space:]]/ || (/^\s/ && $contents=~/\004/)) {
+ $contents.="\001$_\002";
+ $first=$_;
+ next;
+ }
+ if (/^\s+strana \.\.\. ([\d ,-]+)$/) {
+ die "Page number without start".&where() if ("\002"!=substr($contents,-1,1));
+ die "Page number already specified".&where() if ($contents=~/\003[^\001\002\004]*\002$/);
+ $contents=substr($contents,0,-1)."\003$1\002";
next;
}
if (/^\s(.*)$/) {
- $contents=substr($contents,0,-1)."\n$1\002";
+ my( $s )=$1;
+ die "INTERNAL: continuation for \"Pøíloha\"".&where() if ($contents=~/\004/);
+ die "Continuation contents without start".&where() if ("\002"!=substr($contents,-1,1));
+ if ($contents=~/\003[^\001\002\004]*\002$/) {
+ die "First line not found".&where() if !defined($first);
+ $contents.="\001$first\002";
+ }
+ $contents=substr($contents,0,-1)."\n$s\002";
next;
}
die "Unexpected text".&where().": $_" if (/\S/);