]> bicyclesonthemoon.info Git - ott/bsta/blob - update.1.pl
09ee4e4081590f252aead717711f8c2f44bdea58
[ott/bsta] / update.1.pl
1 ###RUN_PERL: #!/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         'read_data_file'
30 );
31 use bsta_lib (
32         'STATE',
33         'ong',
34         'write_index'
35 );
36
37 ###PERL_DATA_DEFAULT_PATH:  DATA_DEFAULT_PATH  = /botm/data/bsta/default
38 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
39 ###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
40
41 binmode STDIN,  ':encoding(UTF-8)';
42 binmode STDOUT, ':encoding(UTF-8)';
43 binmode STDERR, ':encoding(UTF-8)';
44 decode_argv();
45
46 my $time = time();
47 srand ($time-$$);
48
49 my %settings  = read_data_file(DATA_SETTINGS_PATH());
50 my %default   = read_data_file(DATA_DEFAULT_PATH());
51 my %state     = read_data_file(DATA_STATE_PATH());
52
53 my $ong_state  = int($state{'state'});
54 my $last_frame = ($ong_state > STATE->{'inactive'}) ? 
55         int($state{'last'}) :
56         0;
57
58 my @list;
59
60 my $fail = 0;
61
62 print $time."\n";
63
64 foreach my $id (@ARGV) {
65         if ($id eq 'all') {
66                 push @list, 'i';
67                 push @list, 'c';
68                 for (my $f=0; $f<=$last_frame; $f+=1) {
69                         push @list, $f;
70                 }
71         }
72         elsif ($id =~ /^[0-9]+$/) {
73                 my $f = int($&);
74                 if ($f <= $last_frame) {
75                         push @list, $f
76                 }
77                 else {
78                         print "$f > $last_frame\n";
79                         $fail += 1;
80                 }
81         }
82         elsif ($id =~ /^[ic]$/) {
83                 push @list, $&;
84         }
85         else {
86                 print "$id ???\n";
87                 $fail += 1;
88         }
89 }
90
91 foreach my $id (@list) {
92         print "ONG $id\n";
93         my $r = ong(
94                 $id,   # frame ID
95                 $time, # ONG time
96                 '',    # timer value; not relevant
97                 1,     # update
98                 1,     # print
99                 \%settings,
100                 \%default,
101                 '',    # %frame_data
102                 ''    # %goto_list
103         );
104         unless ($r) {
105                 $fail += 1;
106                 print "ONG FAIL!\n";
107         }
108         if (($id == 0) && ($ong_state > STATE->{'inactive'})) {
109                 write_index(
110                         \%state,
111                         \%settings,
112                 );
113         }
114                 
115 }
116 print "\n";
117
118 exit $fail;