]> bicyclesonthemoon.info Git - ott/bsta/blob - update.1.pl
include password in empty goto redirect
[ott/bsta] / update.1.pl
1 #!/usr/bin/perl
2
3 # update.pl is generated from update.1.pl.
4 #
5 # update already ONGed frames & stuff
6 #
7 # Copyright (C) 2016, 2017, 2023, 2024  Balthasar SzczepaƄski
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU Affero General Public License as
11 # published by the Free Software Foundation, either version 3 of the
12 # License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU Affero General Public License for more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22 use strict;
23 use utf8;
24 use Encode::Locale ('decode_argv');
25 use Encode ('encode', 'decode');
26
27 ###PERL_LIB: use lib /botm/lib/bsta
28 use botm_common (
29 );
30 use bsta_lib (
31         'STATE',
32         'ong',
33         'write_index', 'write_static_viewer_page', 'write_static_goto',
34         'read_frame_data', 'read_default', 'read_words_list',
35         'read_settings', 'read_state'
36 );
37
38 binmode STDIN,  ':encoding(UTF-8)';
39 binmode STDOUT, ':encoding(UTF-8)';
40 binmode STDERR, ':encoding(UTF-8)';
41 decode_argv();
42
43 my $time = time();
44 srand ($time-$$);
45
46 my %settings  = read_settings();
47 my %default   = read_default();
48 my %state     = read_state();
49 my %all_frame_data = ();
50 my %all_words_data = ();
51
52 my $update_goto = 0;
53
54 my $ong_state  = int($state{'state'});
55 my $last_frame = ($ong_state > STATE->{'inactive'}) ? 
56         int($state{'last'}) :
57         0;
58
59 my @list;
60
61 my $fail = 0;
62
63 print $time."\n";
64
65 foreach my $id (@ARGV) {
66         if ($id eq 'all') {
67                 $update_goto = 1;
68                 push @list, 'i';
69                 push @list, 'c';
70                 for (my $f=0; $f<=$last_frame; $f+=1) {
71                         push @list, $f;
72                 }
73         }
74         elsif ($id =~ /^[0-9]+$/) {
75                 $update_goto = 1;
76                 my $f = int($&);
77                 if ($f <= $last_frame) {
78                         push @list, $f
79                 }
80                 else {
81                         print "$f > $last_frame\n";
82                         $fail += 1;
83                 }
84         }
85         elsif ($id =~ /^[ic]$/) {
86                 push @list, $&;
87         }
88         else {
89                 print "$id ???\n";
90                 $fail += 1;
91         }
92 }
93
94 # duplicated - before AND after normal pages!
95 if ($update_goto) {
96         print 'static GOTO';
97         my $r = write_static_goto(
98                 \%state,
99                 \%settings,
100                 '' # \%goto_list
101         );
102         if ($r) {
103                 print " OK\n";
104         }
105         else {
106                 print " FAIL\n";
107                 $fail += 1;
108         }
109 }
110
111 foreach my $id (@list) {
112         print "ONG $id\n";
113         my $r = ong(
114                 $id,   # frame ID
115                 $time, # ONG time
116                 '',    # timer value; not relevant
117                 1,     # update
118                 1,     # print
119                 \%settings,
120                 \%default,
121                 get_frame_data($id),
122                 ''    # %goto_list
123         );
124         unless ($r) {
125                 $fail += 1;
126                 print "ONG FAIL!\n";
127         }
128         make_static_pages($id);
129 }
130
131 # duplicated - before AND after normal pages!
132 if ($update_goto) {
133         print 'static GOTO';
134         my $r = write_static_goto(
135                 \%state,
136                 \%settings,
137                 '' # \%goto_list
138         );
139         if ($r) {
140                 print " OK\n";
141         }
142         else {
143                 print " FAIL\n";
144                 $fail += 1;
145         }
146 }
147
148 print "\n";
149
150
151 sub get_frame_data {
152         (my $id) = @_;
153         
154         unless ($id =~ /^[0-9]+$/) {
155                 return '';
156         }
157         my $f = int($id);
158         
159         unless (($f >= 0) && ($f <= $last_frame)) {
160                 return '';
161         }
162         
163         my $r = $all_frame_data{$f};
164         if (ref ($r)) {
165                 return $r;
166         }
167         
168         my %frame_data = read_frame_data($f);
169         $all_frame_data{$f} = \%frame_data;
170         return \%frame_data;
171 }
172
173 sub get_words_data {
174         (my $id) = @_;
175         
176         unless ($id =~ /^[0-9]+$/) {
177                 return '';
178         }
179         my $f = int($id);
180         
181         unless (($f >= 0) && ($f <= $last_frame)) {
182                 return '';
183         }
184         
185         my $r = $all_words_data{$f};
186         if (ref ($r)) {
187                 return $r;
188         }
189         
190         my %words_data = read_words_list($f, 1);
191         $all_words_data{$f} = \%words_data;
192         return \%words_data;
193 }
194
195 sub make_static_page {
196         (my $id) = @_;
197         unless ($id =~ /^[0-9]+$/) {
198                 return;
199         }
200         my $f = int($id);
201         unless (
202                 ($f >= 0) && (
203                         ($f < $last_frame) || (
204                                 ($ong_state >= STATE->{'end'}) &&
205                                 ($f <= $last_frame)
206                         )
207                 )
208         ) {
209                 return;
210         }
211         my $r;
212         
213         if (($f == 0) && ($ong_state > STATE->{'inactive'})) {
214                 print 'index';
215                 $r = write_index(
216                         \%state,
217                         \%settings,
218                 );
219                 print (($r) ? " OK\n" : " FAIL\n");
220         }
221         elsif ($f > 0) {
222                 print 'static page '.$f;
223                 $r = write_static_viewer_page (
224                         $f,
225                         \%state,
226                         \%settings,
227                         \%default,
228                         get_frame_data($f),
229                         get_frame_data($f-1),
230                         get_frame_data($f+1),
231                         get_words_data($f)
232                 );
233                 print (($r) ? " OK\n" : " FAIL\n");
234         }
235 }
236
237 sub make_static_pages {
238         (my $id) = @_;
239         unless ($id =~ /^[0-9]+$/) {
240                 return;
241         }
242         my $f = int($id);
243         unless (($f >= 0) && ($f <= $last_frame)) {
244                 return '';
245         }
246         
247         make_static_page($f);
248         make_static_page($f-1);
249         make_static_page($f+1);
250         make_static_page($f);
251 }
252
253 exit $fail;