annotate parsedata.pl @ 181:9c3100ab29cc

Cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 08 Sep 2015 10:48:48 +0300
parents eaac0a84a7d2
children 9f7eb4db99b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #!/usr/bin/perl -w
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 # Fetch and parse HTML format class timetable into more sane formats
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
4 # (C) Copyright 2010-2015 Matti Hämäläinen <ccr@tnsp.org>
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 use strict;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 use Data::Dumper;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 use HTML::Entities;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
10 ###
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
11 ### Some globals
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
12 ###
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
13 my $modes = "php|xml";
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
14 my $opt_mode = "php";
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
15 my $opt_dump = 0;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
16 my $opt_filename;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
17 my $opt_outfile;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
18
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
19 my $cid = 0;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
20 my $hourTimes = [];
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
21 my $hourDefs = {};
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
22 my $hourTable = {};
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
23 my $hourFillTable = {};
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
24 my $maxDays = 0;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
25 my $firstHour = 0;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
26 my $lastHour = 0;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
27 my $totalHours = 0;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
28
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 sub str_trim($)
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 my $str = $_[0];
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
33 if (defined($str))
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
34 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 $str =~ s/^\s*//;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 $str =~ s/\s*$//;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 return $str;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 sub pop_token_a($)
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 my $tokens = $_[0];
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 return shift(@$tokens);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 sub pop_token($)
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 return str_trim(pop_token_a($_[0]));
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 sub parse_html_str($)
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 my $tokens = $_[0];
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 my $token = pop_token($tokens);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 my $str = "";
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 $token =~ s/^\s*//;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 return undef unless (substr($token, 0, 1) eq '"');
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 $token = substr($token, 1);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
65 while (defined($token))
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
66 {
26
eb82a7ddf5bd Oops, 10l.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
67 my $tmp = $token;
25
a076d8d22422 Fix string parsing in the HTML parser.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
68 $tmp =~ s/\s*$//;
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
69 if (substr($tmp, -1) eq '"')
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
70 {
25
a076d8d22422 Fix string parsing in the HTML parser.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
71 $str .= substr($tmp, 0, -1);
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 return $str;
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
73 }
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
74 else
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
75 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 $str .= $token;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 $token = shift(@$tokens);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 return undef;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 sub parse_html_tree($$);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 sub parse_html_tree($$)
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 my ($tokens, $tree) = @_;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
90 while (my $token = pop_token($tokens))
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
91 {
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
92 if ($token =~ /^<[!\/]?[a-zA-Z]+/)
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
93 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 $token = lc($token);
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
95 if ($token =~ /^<\!.*>$/)
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
96 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 # Ignore comments etc.
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
98 }
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
99 elsif ($token =~ /^<([a-z]+)(.*)>$/)
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
100 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 my ($name, $args) = ($1, $2);
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
102 if ($name eq "meta" || $name eq "img")
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
103 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 my $tmp = {};
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 parse_html_tree($tokens, $tree);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 return $tree;
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
107 }
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
108 else
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
109 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 my $tmp = { "name" => $name, "args" => str_trim($args) };
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 parse_html_tree($tokens, $tmp);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 push(@{$$tree{"nodes"}}, $tmp);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 }
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
114 }
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
115 elsif ($token =~ /^<\/([a-z]+)>$/)
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
116 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 return $tree;
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
118 }
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
119 else
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
120 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 die("HORROR TERROR ELITE: $token\n");
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 }
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
123 }
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
124 else
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
125 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 $token = str_trim(decode_entities($token));
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 push(@{$$tree{"nodes"}}, { "name" => "text", "args" => "", "text" => $token }) if length($token) > 0;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 return $tree;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 sub parse_html($)
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 return undef unless defined($_[0]);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 my $str = $_[0];
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 my $res = { "name" => "", "args" => "" };
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 $str =~ tr/\r/ /;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 $str =~ tr/\n/ /;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 my @tokens = grep { !($_ =~ /^\s*$/) } split(/(<\/?[a-zA-Z]+.*?>)/, $str);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 parse_html_tree(\@tokens, $res);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 return $res;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 sub html_find_node($$$);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 sub html_find_node($$$)
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 my ($node, $name, $args) = @_;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
153 if (defined($node))
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
154 {
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
155 if (ref($node) eq "ARRAY")
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
156 {
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
157 foreach my $n (@$node)
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
158 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 my $tmp = html_find_node($n, $name, $args);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 # Must do it like this, in order not to break the loop
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 return $tmp if defined($tmp);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 }
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
163 }
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
164 elsif (ref($node) eq "HASH")
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
165 {
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
166 if (defined($$node{"name"}))
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
167 {
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
168 if ($$node{"name"} eq $name)
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
169 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 if ($args ne "") {
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
171 if (defined($$node{"args"}) && $$node{"args"} =~ /$args/)
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
172 {
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
173 }
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
174 else
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
175 {
33
ad96ed91de92 Fix recursive parsing with attributes.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
176 return html_find_node($$node{"nodes"}, $name, $args);
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 return $node;
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
180 }
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
181 else
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
182 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 return html_find_node($$node{"nodes"}, $name, $args);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 return undef;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 sub fnode($$)
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 return html_find_node($_[0], $_[1], "");
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 sub fnodea($$$)
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 return html_find_node($_[0], $_[1], $_[2]);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 sub escape($)
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 my $s = $_[0];
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 $s =~ s/(['"])/\\$1/g;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 return $s;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 sub html_collapse($$);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 sub html_collapse($$)
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 my ($node, $strip) = @_;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 my $str = "";
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
219 if ($$node{"name"} eq "text")
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
220 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 $str .= $$node{"text"};
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
222 }
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
223 else
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
224 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 $str .= "<".$$node{"name"}.">" unless ($strip);
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
226 foreach my $n (@{$$node{"nodes"}})
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
227 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 $str .= html_collapse($n, $strip);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 $str .= "</".$$node{"name"}.">" unless ($strip);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 return $str;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
237 sub parse_hour_data($$)
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
238 {
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
239 my ($l, $rowspan) = @_;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
240 my $chours = $rowspan / 2; # The table is actually in half cells
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
241 my $cdata = [];
145
c028506aa9cc Separate the concepts of "every other week" classes and split group classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
242 my $cturns = 0;
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
243 my $cgrouped = 0;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
244
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
245 # Pull in data for the class/hour cell
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
246 foreach my $h (@{$l})
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
247 {
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
248 if (defined($$h{"nodes"}))
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
249 {
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
250 foreach my $b (@{$$h{"nodes"}})
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
251 {
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
252 if (defined($$b{"nodes"}))
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
253 {
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
254 my $text = $$b{"nodes"}[0]{"text"};
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
255 $text =~ s/\.$//;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
256
146
1a5994671dcf Oops. Fix a silly 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
257 if ($text =~ /^vuorov/i)
145
c028506aa9cc Separate the concepts of "every other week" classes and split group classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
258 {
c028506aa9cc Separate the concepts of "every other week" classes and split group classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
259 $cturns = 1;
c028506aa9cc Separate the concepts of "every other week" classes and split group classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
260 }
c028506aa9cc Separate the concepts of "every other week" classes and split group classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
261 else
c028506aa9cc Separate the concepts of "every other week" classes and split group classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
262 {
c028506aa9cc Separate the concepts of "every other week" classes and split group classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
263 push(@$cdata, $text);
c028506aa9cc Separate the concepts of "every other week" classes and split group classes.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
264 }
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
265 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
266 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
267 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
268 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
269
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
270 # Increased ID if there is data in this class/hour cell
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
271 my $tid;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
272 if (scalar(@$cdata) > 0) {
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
273 $cid++;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
274 $tid = $cid;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
275 } else {
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
276 $tid = 0;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
277 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
278
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
279 # Determine current day
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
280 my $cday = 0;
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
281 for (my $x = 0; $x < 7; $x++)
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
282 {
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
283 if (!defined($$hourFillTable{$lastHour}{$x}))
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
284 {
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
285 $cday = $x;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
286 last;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
287 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
288 }
170
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
289 for (my $t = 0; $t < $chours; $t++)
34ce8339b956 Cosmetic reformatting.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
290 {
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
291 $$hourFillTable{$lastHour + $t}{$cday} = $tid;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
292 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
293
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
294 if ($tid)
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
295 {
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
296 $maxDays = $cday + 1 if ($cday + 1 > $maxDays);
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
297
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
298 # Grouped, if there is another class ID in second slot
169
04c4f1a95dbd Fix parsing of some course codes.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
299 $cgrouped = 1 if ($$cdata[1] =~ /^([A-Z]\d{5,6}[A-Z]*|[A-Z0-9]{6,8})$/);
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
300 if ($cgrouped)
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
301 {
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
302 my $cdata1 = [];
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
303 my $cdata2 = [];
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
304 for (my $i = 0; $i < length($cdata); $i += 2)
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
305 {
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
306 push(@$cdata1, $$cdata[$i]) if defined($$cdata[$i]);
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
307 push(@$cdata2, $$cdata[$i+1]) if defined($$cdata[$i+1]);
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
308 }
146
1a5994671dcf Oops. Fix a silly 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
309 $$hourDefs{$cid} = { "turns" => $cturns, "grouped" => $cgrouped, "start" => $lastHour, "hours" => $chours, "data" => [ $cdata1, $cdata2 ] };
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
310 }
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
311 else
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
312 {
146
1a5994671dcf Oops. Fix a silly 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
313 $$hourDefs{$cid} = { "turns" => $cturns, "grouped" => $cgrouped, "start" => $lastHour, "hours" => $chours, "data" => [ $cdata ] };
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
314 }
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
315
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
316 push(@{$$hourTable{$cday}}, $tid);
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
317 $totalHours += $chours;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
318 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
319 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
320
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
321 sub parse_hour_header($)
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
322 {
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
323 if ($_[0] =~ /(\d+):(\d+)/)
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
324 {
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
325 return ((int($1) * 60 + int($2)) * 60);
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
326 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
327 return undef;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
328 }
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
330
174
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
331 sub get_hour_data_struct($$);
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
332
174
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
333 sub get_hour_data_struct($$)
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
334 {
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
335 my @out = ();
74
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
336 my ($tmp, $first) = @_;
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
337
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
338 if (ref($tmp) eq "ARRAY")
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
339 {
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
340 my @str = ();
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
341 foreach my $item (@{$tmp})
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
342 {
174
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
343 push(@str, get_hour_data_struct($item, 0));
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
344 }
74
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
345 if (scalar(@str) > 0)
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
346 {
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
347 push(@out, "array(".join(", ", @str).")") if ($opt_mode eq "php");
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
348 push(@out, "<group>".join("", @str)."</group>") if ($opt_mode eq "xml");
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
349 }
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
350 }
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
351 elsif (ref($tmp) eq "HASH")
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
352 {
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
353 my @str = ();
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
354 foreach my $key (keys %{$tmp})
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
355 {
174
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
356 push(@out, "\"".$key."\" => ".get_hour_data_struct($$tmp{$key}, 1)) if ($opt_mode eq "php");
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
357 push(@out, "<".$key.">".get_hour_data_struct($$tmp{$key}, 1)."</".$key.">") if ($opt_mode eq "xml");
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
358 }
74
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
359 if (scalar(@str) > 0)
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
360 {
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
361 push(@out, "array(".join(", ", @str).")") if ($opt_mode eq "php");
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
362 push(@out, join("", @str)) if ($opt_mode eq "xml");
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
363 }
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
364 }
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
365 elsif ($tmp =~ /^\d+$/)
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
366 {
74
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
367 if ($opt_mode eq "php")
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
368 {
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
369 push(@out, $tmp);
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
370 }
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
371 else
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
372 {
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
373 push(@out, $first ? $tmp : "<item>".$tmp."</item>");
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
374 }
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
375 }
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
376 else
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
377 {
74
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
378 if ($opt_mode eq "php")
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
379 {
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
380 push(@out, "\"".$tmp."\"");
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
381 }
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
382 else
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
383 {
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
384 push(@out, $first ? $tmp : "<item>".$tmp."</item>");
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
385 }
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
386 }
74
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
387
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
388 return join(", ", @out) if ($opt_mode eq "php");
b51ad733b624 Improvements in the parser, now also produces "XML" output.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
389 return join("", @out);
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
390 }
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
391
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
392
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
393 ###
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
394 ### Main program
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
395 ###
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
396
181
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
397 while (defined(my $arg = shift))
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
398 {
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
399 if (substr($arg, 0, 1) eq "-")
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
400 {
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
401 if ($arg =~ /^-($modes)$/o)
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
402 {
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
403 $opt_mode = $1;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
404 }
181
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
405 elsif ($arg eq "-dump")
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
406 {
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
407 $opt_dump = 1;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
408 }
181
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
409 elsif ($arg eq "-o")
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
410 {
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
411 $opt_outfile = shift or die("Output filename option -o requires an argument.\n");
181
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
412 }
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
413 else
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
414 {
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
415 die("Invalid option '$arg'.\n");
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
416 }
181
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
417 }
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
418 else
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
419 {
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
420 $opt_filename = $arg;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
421 }
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
422 }
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
423
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
424 die("Usage: $0 [options] <filename>
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
425
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
426 -php Output a PHP include file with data in arrays (default)
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
427 -xml Output a simple XML file.
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
428
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
429 -o <filename> Set output filename. Default is to use stdout.
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
430
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
431 -dump Dump HTML tree to stdout and quit.
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
432
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
433 ") unless defined($opt_filename);
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
434
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
435
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
436 my $data;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
437 open(my $fh, '<:encoding(iso-8859-1)', $opt_filename) or die("Error opening '$opt_filename': $!\n");
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
438 $data = do { local $/; <$fh> };
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
439 close($fh);
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
440
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
441 die("No data in input.\n") unless (defined($data) && $data ne "");
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
442
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
443
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
444 # Filter out certain unneeded elements
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
445 $data =~ s/<font[^>]*>//ig;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
446 $data =~ s/<\/font>//ig;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
447 $data =~ s/<\/?center>//ig;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
448 $data =~ s/<br>//ig;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
449 $data =~ s/&nbsp;/ /ig;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
450
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
451 ### Get some general information
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
452 my $otree = parse_html($data);
163
3790db4eb29b Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
453 if ($opt_dump)
3790db4eb29b Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
454 {
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
455 print Dumper(fnode($otree, "html"));
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
456 exit;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
457 }
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
458
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
459 my %class = ();
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
460 my $body = fnode($otree, "body");
181
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
461 if (defined($body) && defined($$body{"nodes"}))
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
462 {
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
463 foreach my $n (@{$$body{"nodes"}})
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
464 {
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
465 if ($$n{"name"} eq "text")
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
466 {
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
467 push(@{$class{"info"}}, $$n{"text"});
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
468 }
181
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
469 elsif ($$n{"name"} eq "b")
9c3100ab29cc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
470 {
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
471 push(@{$class{"data"}}, $n);
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
472 }
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
473 }
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
474 }
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
475
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
476 # Filter out some more, for easier tree access during table parsing
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
477 $data =~ s/<\/?b>//ig;
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
478 my $tree = parse_html($data);
165
1d17dbb864ff Fix parsing of new format of UNTIS html output.
Matti Hamalainen <ccr@tnsp.org>
parents: 164
diff changeset
479 my $node = fnodea(fnode($tree, "body"), "table", "border=\"3\" rules=\"all\" cellpadding=\"1\" cellspacing=\"1\"");
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
480 die("No table element found in document. Perhaps the format has changed? :(\n") unless defined($node);
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
481
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
482
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
483 ### Parse through the HTML document node tree to find the data we need
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
484
8
a52a0bdb5ea1 Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
485 # Skip zero position this way (can't use foreach here)
164
2654466d2655 Oops, 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 163
diff changeset
486 my $q = $$node{"nodes"};
161
62687fee6f1c Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
487 for (my $i = 1; $i < scalar(@{$q}); $i++)
62687fee6f1c Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
488 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 my $d = $$q[$i]{"nodes"};
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
490 if (defined($d))
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
491 {
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
492 foreach my $n (@{$d})
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
493 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 my $l = $$n{"nodes"}[0]{"nodes"};
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
495 if (defined($l))
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
496 {
165
1d17dbb864ff Fix parsing of new format of UNTIS html output.
Matti Hamalainen <ccr@tnsp.org>
parents: 164
diff changeset
497 if ($$n{"args"} =~ /colspan=12\s+rowspan=(\d+)/)
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
498 {
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
499 parse_hour_data($l, $1);
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 }
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
501 elsif ($$n{"args"} =~ /rowspan=2\s+align/)
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
502 {
162
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
503 my $qstart = parse_hour_header($$l[0]{"nodes"}[0]{"nodes"}[0]{"text"});
70f432e3d1dc Some remodeling here and there.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
504 my $qend = parse_hour_header($$l[1]{"nodes"}[0]{"nodes"}[0]{"text"});
72
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
505 if (defined($qstart) && defined($qend))
6fd715063abc Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
506 {
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
507 push(@$hourTimes, {"start" => $qstart, "end" => $qend});
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 }
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
512 $lastHour++;
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516
8
a52a0bdb5ea1 Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
517 ### Go through hour table, find last day and hour of the week, crop
a52a0bdb5ea1 Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
518 my $flag = 1;
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
519 for (my $y = 0; $y < $lastHour && $flag; $y++) {
51
0db0d485eb59 Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
520 for (my $x = 0; $x < $maxDays && $flag; $x++) {
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
521 $flag = 0 if (defined($$hourFillTable{$y}{$x}) && $$hourFillTable{$y}{$x} != 0);
8
a52a0bdb5ea1 Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
522 }
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
523 $firstHour++ if ($flag);
8
a52a0bdb5ea1 Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
524 }
a52a0bdb5ea1 Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
525
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
526 $flag = 1;
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
527 for (my $y = $lastHour - 1; $y >= 0 && $flag; $y--) {
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
528 for (my $x = 0; $x < $maxDays && $flag; $x++) {
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
529 $flag = 0 if (defined($$hourFillTable{$y}{$x}) && $$hourFillTable{$y}{$x} != 0);
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
530 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
531 $lastHour-- if ($flag);
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
532 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
533
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
534
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
535 ### Open output file, if specified
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 if (defined($opt_outfile)) {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 open(STDOUT, '>', $opt_outfile) or die("Could not open output file '$opt_outfile'.\n");
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539
36
bb00a40252e2 Input in ISO-8859-1 and output in UTF-8.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
540 binmode STDOUT, ':encoding(utf-8)';
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542 ### Output data in desired format
174
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
543 if ($opt_mode eq "php")
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
544 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 print "<?\n".
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 "\$classInfo = array(\n".
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 " \"general\" => array(".join(", ", map { "\"".escape($_)."\""; } @{$class{"info"}})."),\n".
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 " \"info\" => array(".join(", ", map { "\"".escape(html_collapse($_, 1))."\""; } @{$class{"data"}})."),\n".
54
0d574e3248b5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
549 " \"tags\" => array(".join(", ", map { "\"".escape(html_collapse($_, 0))."\""; } @{$class{"data"}})."),\n".
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
550 " \"maxDays\" => $maxDays,\n".
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
551 " \"firstHour\" => $firstHour,\n".
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
552 " \"lastHour\" => $lastHour,\n".
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
553 " \"totalHours\" => $totalHours\n".
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 ");\n\n";
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
556 print "\$classHourTimes = array(\n";
174
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
557 foreach my $chour (@$hourTimes)
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
558 {
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
559 print " array(\"start\" => ".$$chour{"start"}.", \"end\" => ".$$chour{"end"}."),\n";
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
560 }
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
561 print ");\n\n";
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
562
54
0d574e3248b5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
563 print "\$classHourDefs = array(\n";
174
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
564 foreach my $cid (sort { $a <=> $b } keys %{$hourDefs})
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
565 {
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
566 print " $cid => array(".get_hour_data_struct($$hourDefs{$cid}, 0)."),\n";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 }
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
568 print ");\n\n";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
570 print
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
571 "\$classDayTable = array(\n";
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
572 for (my $y = 0; $y < $maxDays; $y++)
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
573 {
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
574 if (defined($$hourTable{$y}))
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
575 {
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
576 print " $y => array(".join(", ", @{$$hourTable{$y}})."),\n";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579 print ");\n?>\n";
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581
174
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
582 elsif ($opt_mode eq "xml")
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
583 {
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 "<timetable>\n".
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586 " <class>\n".
77
49a329e87367 Adjust some tag names to be more sane in the XML output.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
587 " <general>".join("", map { "<item>".$_."</item>"; } @{$class{"info"}})."</general>\n".
49a329e87367 Adjust some tag names to be more sane in the XML output.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
588 " <info>".join("", map { "<item>".html_collapse($_, 1)."</item>"; } @{$class{"data"}})."</info>\n".
52
b2f45dd616bc Oops, the output variable names should not have been changed.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
589 " <maxdays>$maxDays</maxdays>\n".
57
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
590 " <firsthour>$firstHour</firsthour>\n".
93c87f42c803 New parser output format, parser logic cleaned up a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
591 " <lasthour>$lastHour</lasthour>\n".
58
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
592 " <totalhours>$totalHours</totalhours>\n".
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593 " </class>\n";
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594
58
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
595 print " <hours>\n";
75
3d9e42477367 More improvements in the parsing and XML output.
Matti Hamalainen <ccr@tnsp.org>
parents: 74
diff changeset
596 my $cid = 0;
174
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
597 foreach my $chour (@$hourTimes)
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
598 {
75
3d9e42477367 More improvements in the parsing and XML output.
Matti Hamalainen <ccr@tnsp.org>
parents: 74
diff changeset
599 print " <hour id=\"".$cid."\"><start>".$$chour{"start"}."</start><end>".$$chour{"end"}."</end></hour>\n";
3d9e42477367 More improvements in the parsing and XML output.
Matti Hamalainen <ccr@tnsp.org>
parents: 74
diff changeset
600 $cid++;
58
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
601 }
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
602 print " </hours>\n\n";
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
603
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
604 print " <classes>\n";
174
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
605 foreach $cid (sort { $a <=> $b } keys %{$hourDefs})
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
606 {
eaac0a84a7d2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
607 print " <class id=\"$cid\">".get_hour_data_struct($$hourDefs{$cid}, 0)."</class>\n";
58
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
608 }
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
609 print " </classes>\n\n";
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
610
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
611 print " <days>\n";
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
612 for (my $y = 0; $y < $maxDays; $y++)
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
613 {
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
614 if (defined($$hourTable{$y}))
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
615 {
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
616 print " <day id=\"$y\">".join("", map { "<class>".$_."</class>" } @{$$hourTable{$y}})."</day>\n";
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
617 }
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
618 }
119f0cef6498 Work on XML output support (not finished yet.)
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
619 print " </days>\n";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621 print "</timetable>\n";
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
624 close (STDOUT);