]> bicyclesonthemoon.info Git - botm/oldlogs/commitdiff
frame update tool; fix ong function
authorb <rowerynaksiezycu@gmail.com>
Thu, 4 Jan 2024 18:52:18 +0000 (18:52 +0000)
committerb <rowerynaksiezycu@gmail.com>
Thu, 4 Jan 2024 18:52:18 +0000 (18:52 +0000)
bsta_lib.1.pm
update.1.pl

index 884614c5b5a94c786a9a650e8b969c6224f6f603..331c4a39e344b71c9ba06c90c345fcff1e3c55c6 100644 (file)
@@ -1580,14 +1580,22 @@ sub ong {
                        }
                        if ($write_data) {
                                $r = write_data_file($frame_data_path, '', '', \%frame_data);
-                       }
-                       unless ($r) {
-                               return $r;
+                               unless ($r) {
+                                       print STDERR "fail writing $frame_data_path\n";
+                                       if ($print) {
+                                               print "write frame data fail\n";
+                                       }
+                                       return $r;
+                               }
                        }
                        $goto_list{'title-'  .$frame} = $frame_full_data{'title'};
                        $goto_list{'ongtime-'.$frame} = $frame_full_data{'ongtime'};
                        $r = write_data_file(DATA_LIST_PATH(), '', '', \%goto_list);
                        unless ($r) {
+                               print STDERR "fail writing ".DATA_LIST_PATH()."\n";
+                               if ($print) {
+                                       print "write GOTO list fail\n";
+                               }
                                return $r;
                        }
                }
@@ -1603,6 +1611,7 @@ sub ong {
                        print (($r) ? " OK\n" : " FAIL\n");
                }
                unless ($r) {
+                       print STDERR "fail copy $in_path $out_path\n";
                        return $r
                }
        }
index e2e59f67cff6c14b007ff2a4a2191a8b60a1b779..af04ce37b82be0ae84009dcb0796841e0db45f6e 100644 (file)
@@ -4,7 +4,7 @@
 #
 # update already ONGed frames & stuff
 #
-# Copyright (C) 2016, 2017, 2023  Balthasar Szczepański
+# Copyright (C) 2016, 2017, 2023, 2024  Balthasar Szczepański
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 use strict;
-#use warnings;
+use utf8;
+use Encode::Locale ('decode_argv');
+use Encode ('encode', 'decode');
+
 ###PERL_LIB: use lib /botm/lib/bsta
-use bsta_lib qw(readdatafile writedatafile);
-use File::Copy;
+use botm_common (
+       'read_data_file'
+);
+use bsta_lib (
+       'STATE',
+       'ong'
+);
+
+###PERL_DATA_DEFAULT_PATH:  DATA_DEFAULT_PATH  = /botm/data/bsta/default
+###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
+###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
+
+binmode STDIN,  ':encoding(UTF-8)';
+binmode STDOUT, ':encoding(UTF-8)';
+binmode STDERR, ':encoding(UTF-8)';
+decode_argv();
+
+my $time = time();
+srand ($time-$$);
+
+my %settings  = read_data_file(DATA_SETTINGS_PATH());
+my %default   = read_data_file(DATA_DEFAULT_PATH());
+my %state     = read_data_file(DATA_STATE_PATH());
+
+my $ong_state  = int($state{'state'});
+my $last_frame = ($ong_state > STATE->{'inactive'}) ? 
+       int($state{'last'}) :
+       0;
 
-###PERL_DATA_PATH:      DATA_PATH      = /botm/data/bsta/
-###PERL_DATA_LIST_PATH: DATA_LIST_PATH = /botm/data/bsta/list
+my @list;
 
-my %framedata;
-my %gotolist;
+my $fail = 0;
 
-my $frame;
+print $time."\n";
 
-%gotolist=readdatafile(DATA_LIST_PATH);
+foreach my $id (@ARGV) {
+       if ($id eq 'all') {
+               push @list, 'i';
+               push @list, 'c';
+               for (my $f=0; $f<=$last_frame; $f+=1) {
+                       push @list, $f;
+               }
+       }
+       elsif ($id =~ /^[0-9]+$/) {
+               my $f = int($&);
+               if ($f <= $last_frame) {
+                       push @list, $f
+               }
+               else {
+                       print "$f > $last_frame\n";
+                       $fail += 1;
+               }
+       }
+       elsif ($id =~ /^[ic]$/) {
+               push @list, $&;
+       }
+       else {
+               print "$id ???\n";
+               $fail += 1;
+       }
+}
 
-for($frame=0; ; ++$frame) {
-       %framedata=readdatafile(DATA_PATH.$frame);
-       if($framedata{'ongtime'} eq '') {
-               last;
+foreach my $id (@list) {
+       print "ONG $id\n";
+       my $r = ong(
+               $id,   # frame ID
+               $time, # ONG time
+               '',    # timer value; not relevant
+               1,     # update
+               1,     # print
+               \%settings,
+               \%default,
+               '',    # %frame_data
+               ''    # %goto_list
+       );
+       unless ($r) {
+               $fail += 1;
+               print "ONG FAIL!\n";
        }
-       
-       print $frame.' '.$framedata{'ongtime'}.' '.$framedata{'title'}."\n";
-       
-       $gotolist{'title-'.$frame}=$framedata{'title'};
-       $gotolist{'ongtime-'.$frame}=$framedata{'ongtime'};
 }
+print "\n";
 
-writedatafile (DATA_LIST_PATH,%gotolist);
+exit $fail;