]> pere.pagekite.me Git - homepage.git/blob - gildet98/generate-page.pl
Generated.
[homepage.git] / gildet98 / generate-page.pl
1 #!/store/bin/perl
2 #
3 # Genererer program-rĂ¥data utfra HTP-filer
4
5 ($felt, $test) = $ARGV[0] =~ m/(.+)=(.*)/;
6 (@dirs) = $ARGV[1];
7
8 for $dir (@dirs) {
9 chdir $dir || die "Unable to find $dir";
10
11 for $file (<*.htp>) {
12 # print "$file\n";
13 %info = parse_htp($file);
14 &chech_info(%info);
15 if ($info{$felt} eq $test) {
16 $url = "$dir/$file";
17 $url =~ s/\.htp$/.html/;
18 $hendelse{"$info{dato}\t$info{tid}\t$url"} = $info{'tittel'};
19 }
20 }
21 }
22
23 print "<SET tittel=\"Program $test\">\n";
24 print "<SET type=\"program\">\n";
25 print "<BLOCK artikkel>\n";
26 print "<DL compact=\"compact\">\n";
27
28 $sistedato = "";
29 for $key (sort keys %hendelse) {
30 ($dato, $tid, $file) = split(/\t/, $key);
31
32 if ($dato != $test && $sistedato ne $dato) {
33 print "<DT><STRONG>$dato</STRONG></DT>\n";
34 $sistedato = $dato;
35 }
36 print "<DT>$tid<DD><A HREF=\"$file\">$hendelse{$key}</A>\n";
37 }
38 print "</DL>\n</BLOCK>\n";
39
40 sub chech_info {
41 my(%info) = @_;
42 warn "Bad or missing '<SET dato=\"\">'"
43 if (! ($info{'dato'} =~ m/^\d\d\d\d-\d\d-\d\d$/) );
44 }
45
46 sub parse_htp {
47 my($filename) = @_;
48
49 my(%info);
50
51 open(HTP, "<$filename") || die "Unable to open $filename for reading";
52 while (<HTP>) {
53 ($key, $val) = m/<set (.*)=\"(.*)\">/i;
54 $info{$key} = $val if ($key);
55 }
56 close HTP;
57 return %info;
58 }