8 use vars qw/$db_driver $db_host $db_user $db_pwd $DB_PWD $db_name $db/;
9 use vars qw/$tb_obsah $tb_clanek/;
14 $DB_PWD=$ENV{"HOME"}."/priv/mysql.${db_user}.pwd";
16 $tb_obsah="energie_obsah";
17 $tb_clanek="energie_clanek";
19 open DB_PWD or die "Failed open \"$DB_PWD\": $!";
24 $db=DBI->connect("DBI:$db_driver:database=$db_name;host=$db_host",$db_user,$db_pwd) or die "Database open fail: $!";
30 $db->do($cmd) or die("SQL command \"$cmd\" failed: $!");
33 eval { &db_do("drop table $tb_obsah") };
35 &db_do("create table $tb_obsah ("
36 ."year year(4) not null,"
37 ."month tinyint not null,"
38 ."month_last tinyint not null,"
39 ."sequential smallint not null,"
40 ."contents text not null"
43 &db_do("alter table $tb_obsah add unique (year,month)");
45 eval { &db_do("drop table $tb_clanek") };
47 &db_do("create table $tb_clanek ("
48 ."year year(4) not null,"
49 ."month tinyint not null,"
50 ."id tinyint not null,"
51 ."name text not null,"
52 ."contents text not null"
55 &db_do("alter table $tb_clanek add unique (year,month,id)");
57 use vars qw/$insert_tb_obsah $insert_tb_clanek $year $month $month_last $sequential $contents $first $article_id/;
61 return " in file $ARGV on line $.";
67 return if !defined $_;
69 print("Empty contents".&where()."!\n");
73 s/([\001\n]) | ([\002\n])/$1$2/g;
74 die "Page marker not found somewhere in this month".&where() if (/^[^\004]*\001[^\003\004]*\002/);
75 die "Duplicate page markers in this month".&where() if (/strana /);
79 $insert_tb_obsah->execute($year,$month,$month_last,$sequential,$_) or die "SQL insert failure: $!";
86 $insert_tb_obsah=$db->prepare("insert into $tb_obsah (year,month,month_last,sequential,contents) values (?,?,?,?,?)")
87 or die "Prepare fail: $!";
88 $insert_tb_clanek=$db->prepare("insert into $tb_clanek (year,month,id,name,contents) values (?,?,?,?,?)")
89 or die "Prepare fail: $!";
93 if (m#^EaP (\d+)(-(\d+))?/(\d+) \((\d+)(-\d+)?\)$#) {
96 $month_last=($3 ? $3 : $1);
105 while (($line=<>)!~/^#$/) {
106 die "Article EOF marker not found".&where() if (!$line);
109 # $article_id probably should not be zero
110 $insert_tb_clanek->execute($year,$month,++$article_id,$1,$clanek) or die "SQL insert failure: $!";
114 die "Multiple \"Pøíloha\"s".&where() if ($contents=~/\004/);
118 if (/^[^ \t]/ || (/^\s/ && $contents=~/\004/)) {
119 $contents.="\001$_\002";
123 if (/^\s+strana \.\.\. ([\d ,-]+)$/) {
124 die "Page number without start".&where() if ("\002"!=substr($contents,-1,1));
125 die "Page number already specified".&where() if ($contents=~/\003[^\001\002\004]*\002$/);
126 $contents=substr($contents,0,-1)."\003$1\002";
131 die "INTERNAL: continuation for \"Pøíloha\"".&where() if ($contents=~/\004/);
132 die "Continuation contents without start".&where() if ("\002"!=substr($contents,-1,1));
133 if ($contents=~/\003[^\001\002\004]*\002$/) {
134 die "First line not found".&where() if !defined($first);
135 $contents.="\001$first\002";
137 $contents=substr($contents,0,-1)."\n$s\002";
140 die "Unexpected text".&where().": $_" if (/\S/);