]> bicyclesonthemoon.info Git - ott/bsta/commitdiff
Generate static viewer pages
authorb <rowerynaksiezycu@gmail.com>
Sat, 27 Jan 2024 09:44:19 +0000 (09:44 +0000)
committerb <rowerynaksiezycu@gmail.com>
Sat, 27 Jan 2024 09:44:19 +0000 (09:44 +0000)
bsta_lib.1.pm
ong.1.pl
update.1.pl

index 9774a2dc6c0ac59cc615e6d3917487589598ea2e..a6d4b39c13def32b593e8c8c09f4ff801fa6c081 100644 (file)
@@ -46,7 +46,7 @@ our @EXPORT_OK   = (
        'print_html_head_start', 'print_html_head_end',
        'print_html_body_start', 'print_html_body_end',
        'print_viewer_page',
-       'write_index',
+       'write_index', 'write_static_viewer_page', 'write_static_goto',
        'ong',
        'eval_bb', 'bb_to_bbcode', 'bb_to_html'
 );
@@ -88,6 +88,7 @@ use botm_common (
 ###PERL_DATA_DEFAULT_PATH:  DATA_DEFAULT_PATH  = /botm/data/bsta/default
 ###PERL_DATA_LIST_PATH:     DATA_LIST_PATH     = /botm/data/bsta/list
 ###PERL_DATA_NOACCESS_PATH: DATA_NOACCESS_PATH = /botm/data/bsta/noaccess
+###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
 ###PERL_DATA_WORDS_PATH:    DATA_WORDS_PATH    = /botm/data/bsta/words/
 
 ###PERL_WWW_PATH:           WWW_PATH           = /botm/www/
@@ -1816,6 +1817,131 @@ sub write_index {
        return $r
 }
 
+sub write_static_viewer_page {
+       (
+               my $frame,
+               my $state_ref,
+               my $settings_ref,
+               my $default_ref,
+               my $frame_data_ref,
+               my $prev_frame_data_ref,
+               my $next_frame_data_ref,
+               my $words_data_ref
+       ) = @_;
+       
+       my %state;
+       my %settings;
+       my %default;
+       my %frame_data;
+       my %prev_frame_data;
+       my %next_frame_data;
+       my %words_data;
+       
+       my $file;
+       
+       $frame = int($frame);
+       my $prev_frame = $frame -1;
+       my $next_frame = $frame +1;
+       
+       %state = (ref ($state_ref)) ?
+               %$state_ref :
+               read_data_file(DATA_STATE_PATH());
+       my $ong_state = int($state{'state'});
+       my $last_frame = int($state{'last'});
+       
+       unless ($ong_state > STATE->{'inactive'}) {
+               return 0;
+       }
+       unless (
+               ($frame >= 0) && (
+                       ($frame < $last_frame) || (
+                               ($frame <= $last_frame) &&
+                               ($ong_state >= STATE->{'end'})
+                       )
+               )
+       ) {
+               return 0;
+       }
+       
+       %settings = (ref ($settings_ref)) ?
+               %$settings_ref :
+               read_data_file(DATA_SETTINGS_PATH());
+       %default = (ref ($default_ref)) ?
+               %$default_ref :
+               read_data_file(DATA_DEFAULT_PATH());
+       
+       %frame_data = (ref ($frame_data_ref)) ?
+               %$frame_data_ref :
+               read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $frame));
+       
+       %prev_frame_data = (ref ($prev_frame_data_ref)) ?
+               %$prev_frame_data_ref : (
+                       ($prev_frame >= 0) ?
+                       read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $prev_frame)) :
+                       %default
+               );
+               
+       %next_frame_data = (ref ($next_frame_data_ref)) ?
+               %$next_frame_data_ref : (
+                       (($next_frame < $last_frame) || (
+                               ($next_frame <= $last_frame) &&
+                               ($next_frame >= STATE->{'end'})
+                       )) ?
+                       read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $next_frame)) :
+                       %default
+               );
+       
+       %frame_data      = merge_settings(\%default, \%frame_data);
+       %prev_frame_data = merge_settings(\%default, \%prev_frame_data);
+       %next_frame_data = merge_settings(\%default, \%next_frame_data);
+       
+       %words_data = (ref ($words_data_ref)) ?
+               %$words_data_ref :
+               read_data_file(
+                       join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $frame), # file
+                       '', # encoding
+                       0,  # no header
+                       1,  # header only
+                       1,  # as list; not relevant
+               );
+       
+       if ($frame_data{'page'} ne '') {
+               $file = $frame_data{'page'}
+       }
+       else {
+               $file = sprintf(
+                       $settings{'frame'},
+                       $frame, 'htm'
+               );
+       }
+       $file = join_path(PATH_SEPARATOR(), WWW_PATH(), $file);
+       
+       return print_viewer_page(
+               $file,
+               {
+                       'launch'        => 0,
+                       'frame'         => $frame,
+                       'access'        => 1,
+                       'password_ok'   => 0,
+                       'timer_unlocked'=> 3, # not relevant
+                       'timer'         => 0, # not relevant
+                       'static'        => 1,
+                       'show_command'  => 1,
+                       'text_mode'     => TEXT_MODE->{'normal'},
+                       'words_page'    => 0, # not relevant
+               },
+               \%state,
+               \%settings,
+               \%frame_data,
+               \%prev_frame_data,
+               \%next_frame_data,
+               \%words_data
+       );
+}
+
+sub write_static_goto {
+       
+}
 
 # ONG the frame + attachment & stuff. NOT update state file.
 sub ong {
index c31009d2bf43bf95bf0e68bed8b3e51e0643ea1b..aec693a24adab7f97dbe9795ed3061ce41aeadf3 100644 (file)
--- a/ong.1.pl
+++ b/ong.1.pl
@@ -27,13 +27,19 @@ use Encode ('encode', 'decode');
 ###PERL_LIB: use lib /botm/lib/bsta
 use botm_common (
        'read_data_file', 'write_data_file',
-       'open_encoded'
+       'open_encoded',
+       'join_path'
 );
 use bsta_lib (
        'STATE',
-       'ong'
+       'ong',
+       'write_static_viewer_page', 'write_index'
 );
 
+###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
+
+###PERL_DATA_PATH:          DATA_PATH          = /botm/data/bsta/
+###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
 
@@ -48,6 +54,8 @@ srand ($time-$$);
 my %settings;
 my %state;
 my %goto_list;
+my %default;
+my %frame_data;
 
 my $fh;
 my $ongstate;
@@ -112,6 +120,11 @@ else {
                                if ($ongstate == STATE->{'ready'}) {
                                        print 'next frame: '.$frame."\n";
                                        
+                                       %default = read_data_file(DATA_DEFAULT_PATH());
+                                       %frame_data = read_data_file(
+                                               join_path(PATH_SEPARATOR(), DATA_PATH(), $frame)
+                                       );
+                                       
                                        $r = ong (
                                                $frame, # frame ID
                                                $time,  # ONG time
@@ -119,11 +132,10 @@ else {
                                                0,      # update
                                                1,      # print
                                                \%settings,
-                                               '',     # %default
-                                               '',     # %frame_data
+                                               \%default,
+                                               \%frame_data,
                                                ''      # %goto_list
                                        );
-                                       
                                        if ($r) {
                                                $state{'last'}   = $frame;
                                                $state{'state'}  = 1;
@@ -132,6 +144,63 @@ else {
                                                $state{'ip3'}    = '';
                                                $state{'ongtime'}= $timer;
                                                print "ONG\n";
+                                               
+                                               my %frame_1_data;
+                                               my %frame_2_data;
+                                               my %frame_3_data;
+                                               if ($frame >= 1) {
+                                                       %frame_1_data = read_data_file(
+                                                               join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-1)
+                                                       );
+                                               }
+                                               if ($frame >= 2) {
+                                                       %frame_2_data = read_data_file(
+                                                               join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-2)
+                                                       );
+                                               }
+                                               if ($frame >= 3) {
+                                                       %frame_3_data = read_data_file(
+                                                               join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-3)
+                                                       );
+                                               }
+                                               if ($frame >= 2)
+                                               {
+                                                       print 'static page '.($frame-1);
+                                                       $r = write_static_viewer_page(
+                                                               $frame-1, # frame ID
+                                                               \%state,
+                                                               \%settings,
+                                                               \%default,
+                                                               \%frame_1_data, # frame data
+                                                               \%frame_2_data, # prev frame data
+                                                               \%frame_data,   # next frame data
+                                                               '' # words data
+                                                       );
+                                                       print (($r) ? " OK\n" : " FAIL\n");
+                                               }
+                                               if ($frame >= 3)
+                                               {
+                                                       print 'static page '.($frame-2);
+                                                       $r = write_static_viewer_page(
+                                                               $frame-1, # frame ID
+                                                               \%state,
+                                                               \%settings,
+                                                               \%default,
+                                                               \%frame_2_data, # frame data
+                                                               \%frame_3_data, # prev frame data
+                                                               \%frame_1_data, # next frame data
+                                                               '' # words data
+                                                       );
+                                                       print (($r) ? " OK\n" : " FAIL\n");
+                                               }
+                                               if ($frame <= 2) {
+                                                       print 'index';
+                                                       $r = write_index(
+                                                               \%state,
+                                                               \%settings
+                                                       );
+                                                       print (($r) ? " OK\n" : " FAIL\n");
+                                               }
                                        }
                                        else {
                                                print "NO ONG\n";
index 09ee4e4081590f252aead717711f8c2f44bdea58..fb6766cb5985047f79f8dab4b8235ad257d60594 100644 (file)
@@ -26,17 +26,22 @@ use Encode ('encode', 'decode');
 
 ###PERL_LIB: use lib /botm/lib/bsta
 use botm_common (
-       'read_data_file'
+       'read_data_file',
+       'join_path'
 );
 use bsta_lib (
        'STATE',
        'ong',
-       'write_index'
+       'write_index', 'write_static_viewer_page'
 );
 
+###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
+
+###PERL_DATA_PATH:          DATA_PATH          = /botm/data/bsta/
 ###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
+###PERL_DATA_WORDS_PATH:    DATA_WORDS_PATH    = /botm/data/bsta/words/
 
 binmode STDIN,  ':encoding(UTF-8)';
 binmode STDOUT, ':encoding(UTF-8)';
@@ -49,6 +54,8 @@ 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 %all_frame_data = ();
+my %all_words_data = ();
 
 my $ong_state  = int($state{'state'});
 my $last_frame = ($ong_state > STATE->{'inactive'}) ? 
@@ -98,21 +105,119 @@ foreach my $id (@list) {
                1,     # print
                \%settings,
                \%default,
-               '',    # %frame_data
+               get_frame_data($id),
                ''    # %goto_list
        );
        unless ($r) {
                $fail += 1;
                print "ONG FAIL!\n";
        }
-       if (($id == 0) && ($ong_state > STATE->{'inactive'})) {
-               write_index(
+       make_static_pages($id);
+}
+print "\n";
+
+
+sub get_frame_data {
+       (my $id) = @_;
+       
+       unless ($id =~ /^[0-9]+$/) {
+               return '';
+       }
+       my $f = int($id);
+       
+       unless (($f >= 0) && ($f <= $last_frame)) {
+               return '';
+       }
+       
+       my $r = $all_frame_data{$f};
+       if (ref ($r)) {
+               return $r;
+       }
+       
+       my %frame_data = read_data_file(
+               join_path(PATH_SEPARATOR(), DATA_PATH(), $f)
+       );
+       $all_frame_data{$f} = \%frame_data;
+       return \%frame_data;
+}
+
+sub get_words_data {
+       (my $id) = @_;
+       
+       unless ($id =~ /^[0-9]+$/) {
+               return '';
+       }
+       my $f = int($id);
+       
+       unless (($f >= 0) && ($f <= $last_frame)) {
+               return '';
+       }
+       
+       my $r = $all_words_data{$f};
+       if (ref ($r)) {
+               return $r;
+       }
+       
+       my %frame_data = read_data_file(
+               join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $f),
+               '', # encoding,
+               0,  # no header
+               1,  # header only
+               1,  # as list; not relevant
+       );
+       $all_words_data{$f} = \%frame_data;
+       return \%frame_data;
+}
+
+sub make_static_page {
+       (my $id) = @_;
+       unless ($id =~ /^[0-9]+$/) {
+               return;
+       }
+       my $f = int($id);
+       unless (($f >= 0) && ($f <= $last_frame)) {
+               return;
+       }
+       my $r;
+       
+       if (($f == 0) && ($ong_state > STATE->{'inactive'})) {
+               print 'index';
+               $r = write_index(
+                       \%state,
+                       \%settings,
+               );
+               print (($r) ? " OK\n" : " FAIL\n");
+       }
+       elsif ($f > 0) {
+               print 'static page '.$f;
+               $r = write_static_viewer_page (
+                       $f,
                        \%state,
                        \%settings,
+                       \%default,
+                       get_frame_data($f),
+                       get_frame_data($f-1),
+                       get_frame_data($f+1),
+                       get_words_data($f)
                );
+               print (($r) ? " OK\n" : " FAIL\n");
        }
-               
 }
-print "\n";
+
+sub make_static_pages {
+       (my $id) = @_;
+       unless ($id =~ /^[0-9]+$/) {
+               return;
+       }
+       my $f = int($id);
+       unless (($f >= 0) && ($f <= $last_frame)) {
+               return '';
+       }
+       
+       make_static_page($f);
+       make_static_page($f-1);
+       make_static_page($f+1);
+       make_static_page($f);
+}
 
 exit $fail;