X-Git-Url: https://git.jankratochvil.net/?p=www.energie.vellum.cz.git;a=blobdiff_plain;f=obsah_init.pl;h=1f7be3374d533d041bd5b0b3e6db8702d9c4c8a8;hp=917e2da098fd62ead1c8d2578b8d626ecca061e6;hb=5184524480f39a76f89f6de59c4a5f21c778ae33;hpb=72ed4b0b640d8896f479b36c119cf61f3e7c7925 diff --git a/obsah_init.pl b/obsah_init.pl index 917e2da..1f7be33 100755 --- a/obsah_init.pl +++ b/obsah_init.pl @@ -6,7 +6,7 @@ use strict; use DBI; use vars qw/$db_driver $db_host $db_user $db_pwd $DB_PWD $db_name $db/; -use vars qw/$tb_obsah/; +use vars qw/$tb_obsah $tb_clanek/; $db_driver="mysql"; $db_host=""; @@ -14,6 +14,7 @@ $db_user="short"; $DB_PWD=$ENV{"HOME"}."/priv/mysql.${db_user}.pwd"; $db_name="short"; $tb_obsah="energie_obsah"; +$tb_clanek="energie_clanek"; open DB_PWD or die "Failed open \"$DB_PWD\": $!"; $db_pwd=; @@ -36,13 +37,24 @@ eval { &db_do("drop table $tb_obsah") }; ."month tinyint not null," ."month_last tinyint not null," ."sequential smallint not null," - ."contents text not null" + ."contents text null" .")"); &db_do("alter table $tb_obsah add unique (year,month)"); +eval { &db_do("drop table $tb_clanek") }; + +&db_do("create table $tb_clanek (" + ."year year(4) not null," + ."month tinyint not null," + ."id tinyint not null," + ."name text not null," + ."contents text not null" + .")"); -use vars qw/$insert_tb_obsah $year $month $month_last $sequential $contents $first/; +&db_do("alter table $tb_clanek add unique (year,month,id)"); + +use vars qw/$insert_tb_obsah $insert_tb_clanek $year $month $month_last $sequential $contents $first $article_id/; sub where { @@ -54,7 +66,8 @@ sub flush_month $_=$contents; return if !defined $_; if (!$_) { - print("Empty contents".&where()."!\n"); + # Permitted to show just the title image + #print("Empty contents".&where()."!\n"); } else { tr/ \t\n/ \n/s; @@ -64,14 +77,17 @@ sub flush_month tr/\002//d; $_=substr($_,1); } - $insert_tb_obsah->execute($year,$month,$month_last,$sequential,$_) or die "SQL insert failure: $!"; + $insert_tb_obsah->execute($year,$month,$month_last,$sequential,($_ || undef())) or die "SQL insert failure: $!"; undef $year,$month; undef $contents; undef $first; + undef $article_id; } $insert_tb_obsah=$db->prepare("insert into $tb_obsah (year,month,month_last,sequential,contents) values (?,?,?,?,?)") or die "Prepare fail: $!"; +$insert_tb_clanek=$db->prepare("insert into $tb_clanek (year,month,id,name,contents) values (?,?,?,?,?)") + or die "Prepare fail: $!"; while (<>) { chomp; @@ -84,12 +100,23 @@ while (<>) { $contents=""; next; } + if (/^#(.+)$/) { +my( $clanek )=""; +my( $line ); + while (($line=<>)!~/^#$/) { + die "Article EOF marker not found".&where() if (!$line); + $clanek.=$line; + } + # $article_id probably should not be zero + $insert_tb_clanek->execute($year,$month,++$article_id,$1,$clanek) or die "SQL insert failure: $!"; + next; + } if (/^Pøíloha:$/) { die "Multiple \"Pøíloha\"s".&where() if ($contents=~/\004/); $contents.="\004"; next; } - if (/^[^[:space:]]/ || (/^\s/ && $contents=~/\004/)) { + if (/^[^ \t]/ || (/^\s/ && $contents=~/\004/)) { $contents.="\001$_\002"; $first=$_; next;