From 2135b7ed6a5325dda4fed253c7afac9f6cd4af10 Mon Sep 17 00:00:00 2001 From: b Date: Thu, 4 Jan 2024 18:52:18 +0000 Subject: [PATCH] frame update tool; fix ong function --- bsta_lib.1.pm | 15 ++++++-- update.1.pl | 100 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 92 insertions(+), 23 deletions(-) diff --git a/bsta_lib.1.pm b/bsta_lib.1.pm index 884614c..331c4a3 100644 --- a/bsta_lib.1.pm +++ b/bsta_lib.1.pm @@ -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 } } diff --git a/update.1.pl b/update.1.pl index e2e59f6..af04ce3 100644 --- a/update.1.pl +++ b/update.1.pl @@ -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 @@ -20,31 +20,91 @@ # along with this program. If not, see . 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; -- 2.30.2