From: b Date: Sat, 14 Feb 2026 21:56:18 +0000 (+0100) Subject: added epilogue loop (state=5) X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;p=ott%2Faftertime added epilogue loop (state=5) --- diff --git a/bot4.awk b/bot4.awk index 2610000..3b81a6c 100644 --- a/bot4.awk +++ b/bot4.awk @@ -1,8 +1,7 @@ #// bot4.awk #// The bot to post frames to the OTT -#// 24.04.2021 #// -#// Copyright (C) 2015, 2018-2019, 2021 Balthasar Szczepański +#// Copyright (C) 2015, 2018-2019, 2021, 2025 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 @@ -129,10 +128,7 @@ END{ exit 1 } - - - if(state<2 && force=="" && f==last) - { + if (!((force != 0) || ((state ~ /^[235]$/) && (f <= last)) || ((state == 1) && (f < last)))) { print "Wrong state." exit 1 } diff --git a/frame.awk b/frame.awk index ab3d227..dd970e7 100644 --- a/frame.awk +++ b/frame.awk @@ -1,8 +1,7 @@ #// frame.awk #// Dynamic frame for the viewer -#// 10.03.2019 #// -#// Copyright (C) 2015, 2018-2019 Balthasar Szczepański +#// Copyright (C) 2015, 2018-2019, 2025 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 @@ -46,139 +45,144 @@ BEGIN{ } } { - file=1 + file = 1 gsub(/[\r\n]/, "", $0) - eq=index($0, "=") - - if($0 ~ /^sf-[0-9]+=/) - { - sf=1 - i=int(substr($0, 4, eq-4)) - if(i==f) - this_sf= tolower(substr($0, eq+1)) - if(i==f-1) - prev_sf=tolower(substr($0, eq+1)) - + eq = index($0, "=") + ind = substr($0, 1, eq-1) + val = substr($0, eq+1) + + if ($0 ~ /^sf-[0-9]+=/) { + sf = 1 + ind = "sf-"int(substr($0, 4, eq-4)) + val = tolower(val) } - argtab[substr($0, 1, eq-1)]=substr($0, eq+1) + argtab[ind] = val } END{ if (file=="") exit 1 - if (sf=="") - s="" - else if(this_sf=="") - s="" - else if(s>this_sf && argtab["cfrt"]=="") - s=this_sf - - ongoing=int(argtab["ongoing"]) - if(ongoing>0) - { - statefile= datapath argtab["story"]"/ongstate" + ongoing = int(argtab["ongoing"]) + if (ongoing > 0) { + statefile = datapath argtab["story"] "/ongstate" getline temp < statefile - close(statefile) + close (statefile) split(temp, temptab, " ") - state=int(temptab[1]) - last=int(temptab[2]) - nextong=int(temptab[3]) - ongfailcount=int(temptab[4]) + state = int(temptab[1]) + last = int(temptab[2]) + nextong = int(temptab[3]) + ongfailcount = int(temptab[4]) } - else - { - last=int(argtab["last"]) - state=3 - nextong=0 - ongfailcount=0 + else { + last = int(argtab["last"]) + state = 3 + nextong = 0 + ongfailcount = 0 } - first=int(argtab["first"]) + first = int(argtab["first"]) - if(frame=="") - { - if(ongoing>0) - { - f=last - onlyframe=1 + if (sf == "") { + s = "" + last_sf = "" + this_sf = "" + prev_sf = "" + } + else { + last_sf = argtab["sf-" last] + this_sf = argtab["sf-" f ] + prev_sf = argtab["sf-"(f-1)] + } + + if (frame == "") { + if (ongoing > 0) { + f = last + s = last_sf + onlyframe = 1 } - else - { - f=first - onlyframe="" + else { + f = first + s = "" + onlyframe = "" } } - if(flast && argtab["cfrt"]=="") - f=last + if (state !~ /^[1235]$/) { + cfrt = 1 + invalid = 1 + } + else if (f < first) { + f = first + s = "" + cfrt = 1 + } + else if (f > last) { + f = last + s = last_sf + cfrt = 1 + } + else if (sf != "") { + if ((s != "") && (this_sf == "")) { + s = "" + cfrt = 1 + } + else if ((s != "") && (this_sf != "") && (s > this_sf)) { + s = this_sf + cfrt =1 + } + } - if(argtab["special"] != "") - { - specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,s) - line="" - undertext="" + if (cfrt && (argtab["cfrt"] != "")) { + } + else if (invalid) { + print "Status: 404 Not Found" + print "" + exit 0 + } + else if (argtab["special"] != "") { + specialfile = datapath argtab["story"] "/" sprintf(argtab["special"], f, s) + line = "" + undertext = "" - while((getline line < specialfile)>0) - { + while ((getline line < specialfile) > 0) { gsub(/[\r\n]/, "", line) - if (line == "" && !undertext) - { - undertext=1 - argtab["text"]="" + if ((line == "") && (!undertext)) { + undertext = 1 + argtab["text"] = "" continue } - if (undertext) - { + if (undertext) { argtab["text"] = argtab["text"] line "\n" } - else - { - - eq=index(line, "=") - argtab[substr(line, 1, eq-1)]=substr(line, eq+1) + else { + eq = index(line, "=") + argtab[substr(line, 1, eq-1)] = substr(line, eq+1) } } close (specialfile) } - framedir= (argtab["framedir"]!="" ? argtab["framedir"] : "/aftertime/"argtab["story"]"/") - # if(sf!="") - # { - frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f,s) - if (system("[ -f " framepath frame" ]")!=0) - frame= framedir sprintf(argtab["frame"],f,s) - # } - # else - # { - # s="" - # frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f) - # if (system("[ -f " framepath frame" ]")!=0) - # frame=framedir sprintf(argtab["frame"],f) - # } - - if(f==last && state==1) - { - print "2 "f" "nextong" "ongfailcount > statefile - close (statefile) + framedir = ((argtab["framedir"] != "") ? argtab["framedir"] : ("/aftertime/" argtab["story"]"/")) + if (cfrt && (argtab["cfrt"] != "")) + frame = framedir argtab["cfrt"] + else { + frame = framedir sprintf(argtab["frame"(e>0 ? "-"e : "")], f ,s) + if (system("[ -f " framepath frame" ]") != 0) + frame = framedir sprintf(argtab["frame"], f , s) } - if((f>last || fthis_sf)) || state==0 && argtab["cfrt"]!="") - frame= framedir argtab["cfrt"] - - if(state==0 && argtab["cfrt"]=="") - { - print "Status: 404 Not Found" - print "" + if ((f == last) && (state == 1)) { + print "2 " f " " nextong " " ongfailcount > statefile + close (statefile) } print "Status: 302 Temporal Relocation" print "Location: "frame print "" - } diff --git a/info.awk b/info.awk index 949a124..7875681 100644 --- a/info.awk +++ b/info.awk @@ -1,8 +1,7 @@ #// info.awk #// Info about an aftertime story. -#// 10.03.2019 #// -#// Copyright (C) 2015-2016, 2018-2019 Balthasar Szczepański +#// Copyright (C) 2015-2016, 2018-2019, 2025 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 @@ -36,352 +35,321 @@ BEGIN{ listfile = datapath "stories" stories=0 - line="" - while((getline line < listfile)>0) - { + line = "" + while ((getline line < listfile) > 0) { gsub(/[\r\n]/,"",line) - eq=index(line,"=") + eq = index(line,"=") - storytab[stories]=substr(line, 1, eq-1) - storyname[stories]=substr(line, eq+1) + storytab[stories] = substr(line, 1, eq-1) + storyname[stories] = substr(line, eq+1) ++stories } - close(listfile) + close (listfile) - if(frame !~ /^[0-9]+[a-z]?$/){ - noframe=1 + if (frame !~ /^[0-9]+[a-z]?$/) { + noframe = 1 } - else if(frame ~ /[a-zA-Z]$/) - { - f=int(substr(frame,1,length(frame)-1)) - s=substr(frame, length(frame)) + else if (frame ~ /[a-zA-Z]$/) { + f = int(substr(frame,1,length(frame)-1)) + s = substr(frame, length(frame)) } - else - { - f=int(frame) - s="" + else { + f = int(frame) + s = "" + } + e = int(enhance) + if (notice ~ /^[0-9]+$/) + n = int(notice) + else if (notice == "i") { + n = -1 + noframe = "" + s = "" } - e=int(enhance) - if(notice~/^[0-9]+$/) - n=int(notice) + else + n = "" + timecmd | getline thistime close(timecmd) - lastalt=0 + lastalt = 0 - ch2num[0]="" - num2ch[""]=0 - for(i=1;i<=26;++i) - { - ch=sprintf("%c",i+96) - num2ch[i]=ch - ch2num[ch]=i + ch2num[0] = "" + num2ch[""] = 0 + for(i=1;i<=26;++i) { + ch = sprintf("%c",i+96) + num2ch[i] = ch + ch2num[ch] = i } - alttabsize=0 - argtabsize=0 + alttabsize = 0 + argtabsize = 0 } { - file=1 + file = 1 gsub(/[\r\n]/, "", $0) - eq=index($0, "=") - if($0 ~ /^[0-9]+=/) - { - i=int(substr($0, 1, eq-1)) - alttab[alttabsize]=substr($0, eq+1) - alttabn[alttabsize]=i + eq = index($0, "=") + ind = substr($0, 1, eq-1) + val = substr($0, eq+1) + + if ($0 ~ /^[0-9]+=/) { + alttab [alttabsize] = val + alttabn[alttabsize] = int(ind) ++alttabsize - - # i=int(substr($0, 1, eq-1)) - # if(f>=i && i>=lastalt) - # { - # alt=substr($0, eq+1) - # lastalt=i - # } } - else if($0 ~ /^sf-[0-9]+=/) - { - sf=1 - i=int(substr($0, 4, eq-4)) - if(i==f) - this_sf= tolower(substr($0, eq+1)) - if(i==f-1) - prev_sf=tolower(substr($0, eq+1)) - + else if($0 ~ /^sf-[0-9]+=/) { + sf = 1 + ind = "sf-"int(substr($0, 4, eq-4)) + val = tolower(val) } - if (!(substr($0, 1, eq-1) in argtab)) - { - argtabind[argtabsize]=substr($0, 1, eq-1) + if (!(ind in argtab)) { + argtabind[argtabsize] = ind ++argtabsize } - argtab[substr($0, 1, eq-1)]=substr($0, eq+1) + argtab[ind] = val } END{ - - if (story=="" && f=="") - { + if ((story == "") && (f == "") && (n != -1)) { for (i=0; i0) - { + if (ongoing > 0) { statefile= datapath argtab["story"]"/ongstate" getline temp < statefile close(statefile) split(temp, temptab, " ") - state=int(temptab[1]) - last=int(temptab[2]) - nextong=int(temptab[3]) - ongfailcount=int(temptab[4]) + state = int(temptab[1]) + last = int(temptab[2]) + nextong = int(temptab[3]) + ongfailcount = int(temptab[4]) } - else - { - last=int(argtab["last"]) - state=3 + else { + last = int(argtab["last"]) + state = 3 + nextong = 0 + ongfailcount = 0 + } + first = int(argtab["first"]) + + if (sf == "") { + s = "" + last_sf = "" + this_sf = "" + prev_sf = "" + } + else { + last_sf = argtab["sf-" last] + this_sf = argtab["sf-" f ] + prev_sf = argtab["sf-"(f-1)] } - first=int(argtab["first"]) - if(noframe!=""){ - if(ongoing>0) - { - print "state="state - print "last="last - print "nextong="nextong - print "ongfailcount="ongfailcount + if (noframe != "") { + if (ongoing > 0) { + print "state=" state + print "last=" last last_sf + print "nextong=" nextong + print "ongfailcount=" ongfailcount + if ((state ~ /^[35]&/) && (argtab["loop"] != "")) + print "loop=" argtab["loop"] } - for (i=0; i< argtabsize; ++i) - { - if((argtabind[i] ~ /^[0-9]+$/)&&(ongoing>0)) - { - j=int(argtabind[i]) - if(j<=last) - print argtabind[i]"="argtab[argtabind[i]] + if (state !~ /^[1235]$/) + exit 0 + for (i=0; i< argtabsize; ++i) { + if ((argtabind[i] ~ /^[0-9]+$/) && (ongoing > 0)) { + j = int(argtabind[i]) + if (j<=last) + print argtabind[i] "=" argtab[argtabind[i]] } - else if((argtabind[i] ~ /^sf-[0-9]+$/)&&(ongoing>0)) - { - j=int(substr(argtabind[i],3)) - if(j<=last) - print argtabind[i]"="argtab[argtabind[i]] + else if ((argtabind[i] ~ /^sf-[0-9]+$/) && (ongoing > 0)) { + j = int(substr(argtabind[i], 4)) + if (j <= last) + print argtabind[i] "=" argtab[argtabind[i]] } - else if((argtabind[i] ~ /^(last|finalreplacetime|finalreplaceframe)$/)&&(ongoing>0)) - { + else if ((argtabind[i] ~ /^(last|finalreplacetime|finalreplaceframe|loop)$/) && (ongoing > 0)) { } else - print argtabind[i]"="argtab[argtabind[i]] + print argtabind[i] "=" argtab[argtabind[i]] } + exit 0 } - else{ - if(f>last || fthis_sf)) - exit 0 - - if(this_sf=="") - s="" - - if (s!="") - { - if(argtab[s] != "") - s2=argtab[s] - else - s2=s - n=-1 - } + + if (state !~ /^[1235]$/) + exit 0 - if(n>0) - { - noticepost=noticepath argtab["story"]"-"sprintf("%04u",f)"-"sprintf("%02u",n) - noticetabsize=0 - for(j=0;(getline line < noticepost)>0;++j) - { - gsub(/[\r\n]/,"",line) - eq=index(line,"=") - noticeind=substr(line, 1, eq-1) - noticeval=substr(line, eq+1) - - if (!(noticeind in noticetab)) - { - noticetabind[noticetabsize]=noticeind - ++noticetabsize - } - noticetab[noticeind]=noticeval - - } - if(j==0) - exit 0 - nposttime=noticetab["y"]noticetab["m"]noticetab["d"]noticetab["h"] - if (thistimelast) || (fthis_sf))) + exit 0 + + if (s != "") { + if(argtab[s] != "") + s2 = argtab[s] + else + s2 = s + } + + if (n != "") { + if (n == -1) + noticepost = noticepath argtab["story"] "-i" + else + noticepost = noticepath argtab["story"] "-" sprintf("%04u%s",f,s) "-" sprintf("%02u",n) + noticetabsize = 0 + for (j=0; (getline line < noticepost)>0; ++j) { + gsub(/[\r\n]/,"",line) + eq = index(line,"=") + noticeind = substr(line, 1, eq-1) + noticeval = substr(line, eq+1) + + if (!(noticeind in noticetab)) { + noticetabind[noticetabsize] = noticeind + ++noticetabsize + } + noticetab[noticeind] = noticeval + + } + if (j == 0) exit 0 + nposttime = noticetab["y"] noticetab["m"] noticetab["d"] noticetab["h"] + if (thistime < nposttime) + exit 0 + + for (j=0; j 0) { + gsub(/[\r\n]/, "", line) - while((getline line < specialfile)>0) - { - gsub(/[\r\n]/, "", line) - - if (line == "" && !undertext) - { - undertext=1 - argtab["text"]="" - continue - } - - if (undertext) - { - argtab["text"] = argtab["text"] line "\n" - } - else - { - eq=index(line, "=") - argtab[substr(line, 1, eq-1)]=substr(line, eq+1) - } + if (line == "" && (!undertext)) { + undertext = 1 + argtab["text"] = "" + continue } - close (specialfile) - } - - ongtimefile= datapath argtab["story"]"/ongtime" - - while((getline line < ongtimefile)>0) - { - ongind=index(line," ") - ongft=substr(line,1,ongind-1) - ongt=substr(line,ongind+1,4) substr(line,ongind+6,2) substr(line,ongind+9,2) substr(line,ongind+12,2) substr(line,ongind+15,2) - if(ongft ~ /^[0-9]+[a-z]$/) - ongf=int(substr(ongft,1,ongind-2)) substr(ongft,ongind-1,1) - else - ongf=int(ongft) - if(ongf==(f s) && ongt ~ /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/) - ongtime=ongt - } - close(ongtimefile) - - if ("alt" in argtab) - alt=argtab["alt"] - else - { - for(i=0; i=alttabn[i] && alttabn[i]>=lastalt) - { - alt=alttab[i] - lastalt=alttabn[i] - } + if (undertext) { + argtab["text"] = argtab["text"] line "\n" + } + else { + eq = index(line, "=") + argtab[substr(line, 1, eq-1)] = substr(line, eq+1) } } - - if(argtab["number"]!="") - numberformat=argtab["number"] + close (specialfile) + } + + ongtimefile = datapath argtab["story"] "/ongtime" + + while ((getline line < ongtimefile) > 0) { + ongind = index(line, " ") + ongft = substr(line, 1, ongind-1) + ongt = substr(line, ongind+1, 4) substr(line, ongind+6, 2) substr(line, ongind+9, 2) substr(line, ongind+12, 2) substr(line, ongind+15, 2) + if (ongft ~ /^[0-9]+[a-z]$/) + ongf = int(substr(ongft, 1, ongind-2)) substr(ongft, ongind-1, 1) else - { - # if (sf!="") - numberformat="%u%s" - # else - # numberformat="%u" - } - - framedir= "/aftertime/"argtab["story"]"/" - # if(sf!="") - # { - title=sprintf(argtab["title"(e>0 ? "-"e : "")],f,s2) - frame=framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f,s) - otherviewerurl=sprintf(argtab["otherviewerurl"], f+int(argtab["othervieweroffset"]),s2) - # } - # else - # { - # s="" - # title=sprintf(argtab["title"(e>0 ? "-"e : "")],f) - # frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f) - # otherviewerurl=sprintf(argtab["otherviewerurl"], f+int(argtab["othervieweroffset"])) - # } - - if (system("[ -f " framepath frame" ]")!=0) - exit 0 - - print "story="argtab["story"] - print "f="f s - print "e="e - print "frame="frame - print "alt="alt - print "title="title - if(ongtime!="") - print "ongtime="ongtime - - max_enhance=int(argtab["enhance"]) - + ongf = int(ongft) - if(max_enhance>0) - { - for(i=0;i<=max_enhance;++i) - { - # if(sf!="") - enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f,s) - # else - # enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f) - - if (system("[ -f " framepath enhancedframe" ]")==0) - print "enhance-"i"="argtab["enhance-"i] + if ((ongf == (f s)) && (ongt ~ /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/)) + ongtime = ongt + } + close (ongtimefile) + + if ("alt" in argtab) + alt = argtab["alt"] + else { + for(i=0; i= alttabn[i]) && (alttabn[i] >= lastalt)) { + alt = alttab[i] + lastalt = alttabn[i] } } - - for(i=1; i<=99; ++i) - { - noticepost=noticepath argtab["story"]"-"sprintf("%04u",f)"-"sprintf("%02u",i) - for(j=0;(getline line < noticepost)>0;++j) - { - gsub(/[\r\n]/,"",line) - eq=index(line,"=") - noticetab[substr(line, 1, eq-1)]=substr(line, eq+1) - } - if(j==0) - break; - nposttime=noticetab["y"]noticetab["m"]noticetab["d"]noticetab["h"] - if (thistime0 ? "-"e : "")], f, s2) + frame = framedir sprintf(argtab["frame"(e>0 ? "-"e : "")], f, s) + otherviewerurl = sprintf(argtab["otherviewerurl"], f + int(argtab["othervieweroffset"]), s2) + + if (system("[ -f " framepath frame" ]") != 0) + exit 0 + + print "story=" argtab["story"] + print "f=" f s + print "e=" e + print "frame=" frame + print "alt=" alt + print "title=" title + if (ongtime != "") + print "ongtime=" ongtime + + max_enhance = int(argtab["enhance"]) + + if (max_enhance>0) { + for (i=0; i<=max_enhance; ++i) { + enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f,s) + if (system("[ -f " framepath enhancedframe" ]") == 0) + print "enhance-" i "=" argtab["enhance-"i] } - - if(argtab["otherviewerurl"]!="") - print "otherviewerurl="otherviewerurl - - if(argtab["BBHTML"]!="") - print "BBHTML="argtab["BBHTML"] - if(argtab["HTML"]!="") - print "HTML="argtab["HTML"] - - if (argtab["text"] != "") - { - print"" - print argtab["text"] + } + + for (i=0; i<=99; ++i) { + noticepost = noticepath argtab["story"] "-" sprintf("%04u%s",f,s) "-" sprintf("%02u",i) + for(j=0; (getline line < noticepost) > 0; ++j) { + gsub(/[\r\n]/,"",line) + eq = index(line,"=") + noticetab[substr(line, 1, eq-1)] = substr(line, eq+1) } + if (j == 0) + break; + nposttime = noticetab["y"] noticetab["m"] noticetab["d"] noticetab["h"] + if (thistime < nposttime) + break; + print "notice-" i "=yes" + } + + if (argtab["otherviewerurl"] != "") + print "otherviewerurl=" otherviewerurl + + if (argtab["BBHTML"] != "") + print "BBHTML=" argtab["BBHTML"] + if (argtab["HTML"] != "") + print "HTML=" argtab["HTML"] + + if (argtab["text"] != "") { + print "" + print argtab["text"] } } diff --git a/ong.awk b/ong.awk index f6dc1ab..d60ea77 100644 --- a/ong.awk +++ b/ong.awk @@ -1,8 +1,7 @@ #// ong.awk #// The bot to ONG new frames to the viewer. -#// 28.08.2020 #// -#// Copyright (C) 2015, 2018-2020 Balthasar Szczepański +#// Copyright (C) 2015, 2018-2020, 2025 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 @@ -19,19 +18,19 @@ BEGIN{ - FS="" - framepath="/eizm/www/time/" - datapath="/eizm/data/aftertime/" + FS = "" + framepath = "/eizm/www/time/" + datapath = "/eizm/data/aftertime/" - # timecmd="date +\"%H\"" - timecmd2="date -u +\"%Y-%m-%d %H:%M:%S\"" - timecmd3="date -u +\"%s\"" + # timecmd = "date +\"%H\"" + timecmd2 = "date -u +\"%Y-%m-%d %H:%M:%S\"" + timecmd3= " date -u +\"%s\"" - cp="/bin/cp" - mawk="/usr/bin/mawk" - bot4awk="/eizm/pro/aftertime/bot4.awk" - chmod="/bin/chmod" - npb="/eizm/pro/ong1/npb" + cp = "/bin/cp" + mawk = "/usr/bin/mawk" + bot4awk = "/eizm/pro/aftertime/bot4.awk" + chmod = "/bin/chmod" + npb = "/eizm/pro/ong1/npb" timecmd2 | getline thistime2 close(timecmd2) @@ -42,300 +41,313 @@ BEGIN{ thistime3 -= thistime3%3600 - for(i=0;i<256;++i) - { - ch=sprintf("%c",i) - hex=sprintf("%02X",i) - dec=sprintf("%u",i) - ch2hex[ch]=hex - ch2dec[ch]=dec + for (i=0; i<256; ++i) { + ch = sprintf("%c",i) + hex = sprintf("%02X",i) + dec = sprintf("%u",i) + ch2hex[ch] = hex + ch2dec[ch] = dec } } { - file=1 + file = 1 gsub(/[\r\n]/, "", $0) - eq=index($0, "=") + eq = index($0, "=") - argtab[substr($0, 1, eq-1)]=substr($0, eq+1) + argtab[substr($0, 1, eq-1)] = substr($0, eq+1) } END{ print "" - print thistime2" "argtab ["story"] + print thistime2 " " argtab["story"] - if (file=="") - { + if (file == "") { print "No data." exit 1 } - if(int(argtab["ongoing"])!=1) - { + if (int(argtab["ongoing"]) != 1) { print "story is not onged from here." exit 1 } # # replace with actual better conditions - # if(int(thistime) % int(argtab["ongtime"]) != 0) - # { + # if (int(thistime) % int(argtab["ongtime"]) != 0) { # print "Not ongtime yet." # exit 1 # } - framedir = "aftertime/"argtab["story"]"/" + framedir = "aftertime/" argtab["story"] "/" - temp="" - statefile= datapath argtab["story"]"/ongstate" + temp = "" + statefile = datapath argtab["story"] "/ongstate" getline temp < statefile close(statefile) split(temp, temptab, " ") - state=int(temptab[1]) - last=int(temptab[2]) - nextong=int(temptab[3]) - ongfailcount=int(temptab[4]) - enhance=int(argtab["enhance"]) + state = int(temptab[1]) + last = int(temptab[2]) + nextong = int(temptab[3]) + ongfailcount = int(temptab[4]) + enhance = int(argtab["enhance"]) - specialtab[0]="" - effectivetab[0]="" + specialtab[0] = "" + effectivetab[0] = "" - # temp="" - # updatefile= datapath argtab["story"]"/update" + # temp = "" + # updatefile = datapath argtab["story"] "/update" # getline temp < updatefile # close(updatefile) - timefile= datapath argtab["story"]"/ongtime" + timefile = datapath argtab["story"] "/ongtime" - if (state == 1 || state ==2) - { - updatefail="" - temp="" - updatefile= datapath argtab["story"]"/update" - # timefile= datapath argtab["story"]"/ongtime" + if (state == 1 || state == 2 || state == 5) { + updatefail = "" + temp = "" + updatefile = datapath argtab["story"] "/update" + # timefile = datapath argtab["story"] "/ongtime" - updated="" + updated = "" - while((getline temp < updatefile)>0) - { + while ((getline temp < updatefile)>0) { if (temp !~ /^([0-9]+[a-z]?)|(c)$/) continue - if(timeread=="") - { - while((getline line < timefile)>0) - { - ongind=index(line," ") - ongft=substr(line,1,ongind-1) - ongt=substr(line,ongind+1) + if (timeread == "") { + while ((getline line < timefile) > 0) { + ongind = index(line," ") + ongft = substr(line,1,ongind-1) + ongt = substr(line,ongind+1) - if(ongft ~ /^[0-9]+[a-z]$/) - ongf=int(substr(ongft,1,ongind-2)) substr(ongft,ongind-1,1) + if (ongft ~ /^[0-9]+[a-z]$/) + ongf = int(substr(ongft,1,ongind-2)) substr(ongft,ongind-1,1) else - ongf=int(ongft) + ongf = int(ongft) - timetab[ongft]=ongt + timetab[ongft] = ongt } close(timefile) - timeread=1 + timeread = 1 } - if(temp=="c") - { + if (temp == "c") { print "Update CFRT." - if (argtab["cfrt"]=="") - { + if (argtab["cfrt"] == "") { print "There is no cfrt frame." continue } - inframe[0]= datapath argtab["story"]"/"argtab["cfrt"] + inframe[0] = datapath argtab["story"] "/" argtab["cfrt"] - frame[0]= framepath framedir argtab["cfrt"] + frame[0] = framepath framedir argtab["cfrt"] - cpcmd[0] = cp" "inframe[0]" "frame[0] - chmodcmd[0] = chmod" +r "frame[0] + cpcmd[0] = cp " " inframe[0] " " frame[0] + chmodcmd[0] = chmod " +r " frame[0] } - else - { - if (temp ~ /[a-z]$/) - { - i=int(substr(temp,1,length(temp)-1)) - j=substr(temp, length(temp)) + else { + if (temp ~ /[a-z]$/) { + i = int(substr(temp, 1, length(temp)-1)) + j = substr(temp, length(temp)) } - else - { + else { i = int(temp) j = "" } - print "Update frame "i j"." + print "Update frame " i j "." - if(argtab["special"] != "") - { - specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],i,j) - readspecialfile(specialfile,argtab,specialtab,effectivetab) + if (argtab["special"] != "") { + specialfile = datapath argtab["story"] "/" sprintf(argtab["special"], i, j) + readspecialfile(specialfile, argtab, specialtab, effectivetab) } - else - { - readspecialfile("",argtab,specialtab,effectivetab) + else { + readspecialfile("", argtab, specialtab, effectivetab) } - if ((i < int(argtab["first"]))||(i > last)) - { + if ((i < int(argtab["first"])) || (i > last)) { print (i j" not onged yet.") continue } - if(j!="") - { - if(argtab["sf-"i]=="") - { + if (j != "") { + if (argtab["sf-"i] == "") { print (i" doesn't have meteor frames.") continue } - else if(j > argtab["sf-"i]) + else if (j > argtab["sf-"i]) { - print (j" is not a meteor frame of "i".") + print (j" is not a meteor frame of " i ".") continue } - } - for (k=0; k<=enhance; ++k) - { - k2=(k>0)?("-"k):"" - inframe[k]= datapath argtab["story"]"/"sprintf(effectivetab["inframe"k2],i,j) + for (k=0; k<=enhance; ++k) { + k2 = (k>0) ? ("-"k) : "" + inframe[k] = datapath argtab["story"] "/" sprintf(effectivetab["inframe"k2], i, j) - frame[k]= framepath framedir sprintf(effectivetab["frame"k2],i,j) - npbframe[k]= framepath framedir sprintf(effectivetab["npbframe"k2],i,j) + frame[k] = framepath framedir sprintf(effectivetab["frame"k2], i, j) + npbframe[k] = framepath framedir sprintf(effectivetab["npbframe"k2], i, j) - npbcmd[k]= npb" "inframe[k]" "npbframe[k]" q" - cpcmd[k] = cp" "inframe[k]" "frame[k] - chmodcmd[k] = chmod" +r "frame[k] + npbcmd[k] = npb " " inframe[k] " " npbframe[k] " q" + cpcmd[k] = cp " " inframe[k] " " frame[k] + chmodcmd[k] = chmod " +r " frame[k] } - if (specialtab["text"]!="") - { - specialtab["HTML"]=bb2html(specialtab["text"]) - writespecialfile(specialfile,specialtab) + if (specialtab["text"] != "") { + specialtab["HTML"] = bb2html(specialtab["text"]) + writespecialfile(specialfile, specialtab) # print debug } } - if(temp!="c" && timetab[sprintf("%04u%s",i,j)]=="") - { - print sprintf("%04u%s",i,j)" "thistime2 >> timefile + if (temp != "c" && timetab[sprintf("%04u%s",i,j)] == "") { + print sprintf("%04u%s", i, j) " " thistime2 >> timefile close(timefile) - timetab[sprintf("%04u%s",i,j)]=thistime2 + timetab[sprintf("%04u%s", i, j)] = thistime2 } - for(k=0; k<=enhance; ++k) - { - k2=(k>0)?("-"k):"" + for (k=0; k<=enhance; ++k) { + k2 = (k>0) ? ("-"k) : "" - if ((system("[ -f " inframe[k]" ]")!=0)&&(k>0)) + if ((system("[ -f " inframe[k]" ]") != 0) && (k > 0)) continue - if((argtab["npbframe"]!="") && (temp!="c")) - { - if(system(npbcmd[k])!=0) - { - print i j k2" NewpixbOTTification failed." - updatefail=1 + if ((argtab["npbframe"] != "") && (temp != "c")) { + if (system(npbcmd[k]) != 0) { + print i j k2 " NewpixbOTTification failed." + updatefail = 1 break } } - if(system(cpcmd[k])!=0) - { + if (system(cpcmd[k]) != 0) { print i j k2" Upload failed." updatefail=1 break } - if(system(chmodcmd[k])!=0) - { + if (system(chmodcmd[k])!= 0) { print "Chmod failed." updatefail=1 break } - if(temp=="c") - { + if (temp == "c") { break } } - if (updatefail) - { + if (updatefail) { break #come up with other aproach } - updated=1 + updated = 1 print "Updated." } close(updatefile) - if (!updatefail && updated) - { + if (!updatefail && updated) { print "" > updatefile close(updatefile) } } - firstong="" - if (state==4) { + firstong = "" + + if (state == 3) { + if (argtab["last"] == "") + state = 2 + else if (int(argtab["last"]) > last) + state = 2 + else if (argtab["loop"]) + state = 5 + if (state != 3) { + if (thistime3 >= nextong) + nextong = getnextongtime() + print sprintf("%u %u %u 0", state, last, nextong) > statefile + close (statefile) + if (state == 5) + print "Back to epilogue loop." + else + print "Back to onging." + } + } + if (state == 4) { print "Time to start onging." firstong=1 nextong=0 - } - else if(state<1 || state>2) - { + } + else if (state != 1 && state != 2 && state != 5) { print "Onging not active." exit 1 } - else if(thistime3 statefile - close(statefile) + print sprintf("1 %u %u %u",last, nextong, ongfailcount) > statefile + close (statefile) print "Nobody saw frame "last" yet. Wait until "nextong"." exit 1 } - - if(thistime3 last) + state = 2 + if (state != 2) { + nextong = getnextongtime() + print sprintf("5 %u %u 0",last, nextong) > statefile + close (statefile) + print "Still looping. Wait until "nextong"." + exit 1 + } + if ((argtab["last"] != "") && (last >= argtab["last"])) { + print "No looping; T** **d." + print sprintf("3 %u %u 0",last, nextong) > statefile + close (statefile) + exit 0 + } + print sprintf("2 %u %u 0",last, nextong) > statefile + close (statefile) + print "End looping; back to onging." } if (firstong) f = int(argtab["first"]) else - f=last+1 - if(argtab["last"]!="") - { - if (f==int(argtab["last"])) - { - print "T** **d." - nextstate="3" + f = last + 1 + if (argtab["last"] != "") { + if (f >= int(argtab["last"])) { + if (argtab["loop"] == "") { + print "T** **d." + nextstate = "3" + } + else if (f > int(argtab["last"])) { + nextong = getnextongtime() + print sprintf("5 %u %u 0", int(argtab["last"]), nextong) > statefile + close(statefile) + print "Epilogue loop." + exit 1 + } + else { + print "Epilogue loop." + nextstate = "2" + } } else - nextstate="1" + nextstate = "1" } else - nextstate="1" + nextstate = "1" - if(firstong && argtab["cfrt"]!="") - { + if (firstong && argtab["cfrt"] != "") { inframe[0]= datapath argtab["story"]"/"argtab["cfrt"] frame[0]= framepath framedir argtab["cfrt"] cpcmd[0] = cp" "inframe[0]" "frame[0] chmodcmd[0] = chmod" +r "frame[0] - if(system(cpcmd[0])!=0) - { + if (system(cpcmd[0]) != 0) { print "CFRT upload failed." exit 1 } - if(system(chmodcmd[0])!=0) - { + if (system(chmodcmd[0]) != 0) { print "CFRT chmod failed." exit 1 } @@ -343,43 +355,36 @@ END{ } print "ONG frame "f"." - - if(argtab["special"] != "") - { - specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,"") - readspecialfile(specialfile,argtab,specialtab,effectivetab) + + if (argtab["special"] != "") { + specialfile = datapath argtab["story"] "/" sprintf(argtab["special"], f, "") + readspecialfile(specialfile, argtab, specialtab, effectivetab) } - else - { - readspecialfile("",argtab,specialtab,effectivetab) + else { + readspecialfile("", argtab, specialtab, effectivetab) } - for(k=0; k<=enhance; ++k) - { - k2=(k>0)?("-"k):"" + for (k=0; k<=enhance; ++k) { + k2 = (k>0) ? ("-"k) : "" - inframe[k]= datapath argtab["story"]"/"sprintf(effectivetab["inframe"k2],f,"") + inframe[k]= datapath argtab["story"] "/" sprintf(effectivetab["inframe" k2], f, "") - if (system("[ -f " inframe[k] " ]")!=0) - { - if(k>0) #we only care about missing original frame - { + if (system("[ -f " inframe[k] " ]") != 0) { + if (k>0) { #we only care about missing original frame continue } ++ongfailcount print "Frame "f" doesnt't exist. (#"ongfailcount")" - print sprintf("%u %u %u %u",state,last,nextong,ongfailcount) > statefile + print sprintf("%u %u %u %u", state, last, nextong, ongfailcount) > statefile close(statefile) - if((argtab["finalreplaceframe"]!="") && (argtab["finalreplacetime"]!="")) - { - if(((thistime3 - nextong) >= int(argtab["finalreplacetime"])*3600) && (ongfailcount>=int(argtab["finalreplacetime"]))) - { + if ((argtab["finalreplaceframe"] != "") && (argtab["finalreplacetime"] != "")) { + if (((thistime3 - nextong) >= int(argtab["finalreplacetime"]) * 3600) && (ongfailcount >= int(argtab["finalreplacetime"]))) { print "Time to stop trying." print "ONG final replacement frame." - inframe[0]= datapath argtab["story"]"/"argtab["finalreplaceframe"] - nextstate=3 + inframe[0] = datapath argtab["story"] "/" argtab["finalreplaceframe"] + nextstate = 3 } else exit 1 @@ -388,59 +393,51 @@ END{ exit 1 } - frame[k]= framepath framedir sprintf(effectivetab["frame"k2],f,"") - npbframe[k]= framepath framedir sprintf(effectivetab["npbframe"k2],f,"") + frame[k] = framepath framedir sprintf(effectivetab["frame" k2], f, "") + npbframe[k] = framepath framedir sprintf(effectivetab["npbframe"k2],f,"") - npbcmd[k]= npb" "inframe[k]" "npbframe[k]" q" - cpcmd[k] = cp" "inframe[k]" "frame[k] - chmodcmd[k] = chmod" +r "frame[k] + npbcmd[k] = npb " " inframe[k] " " npbframe[k] " q" + cpcmd[k] = cp " " inframe[k] " " frame[k] + chmodcmd[k] = chmod " +r " frame[k] } - ongcmd = mawk" -f " bot4awk" -v story="argtab["story"]" -v frame="last" "datapath argtab["story"]"/settings" -# nextong = thistime3 + int(argtab["ongtime"])*3600 + ongcmd = mawk " -f " bot4awk " -v story=" argtab["story"] " -v frame=" last " " datapath argtab["story"] "/settings" nextong = getnextongtime() ### replace this with actual onging!!! # system("/eizm/pro/ong1/bot4") - if (specialtab["text"]!="") - { - specialtab["HTML"]=bb2html(specialtab["text"]) - writespecialfile(specialfile,specialtab) + if (specialtab["text"] != "") { + specialtab["HTML"] = bb2html(specialtab["text"]) + writespecialfile(specialfile, specialtab) } - # timefile= datapath argtab["story"]"/ongtime" - print sprintf("%04u ",f)thistime2 >> timefile + print sprintf("%04u ",f) thistime2 >> timefile close(timefile) - for(k=0; k<=enhance; ++k) - { - k2=(k>0)?("-"k):"" + for (k=0; k<=enhance; ++k) { + k2 = (k>0) ? ("-"k) : "" - if ((system("[ -f " inframe[k]" ]")!=0)&&(k>0)) + if ((system("[ -f " inframe[k] " ]") != 0) && (k > 0)) continue - if(argtab["npbframe"]!="") - { - if(system(npbcmd[k])!=0) - { - print "NewpixbOTTification"k2" failed." + if (argtab["npbframe"] != "") { + if (system(npbcmd[k])!= 0) { + print "NewpixbOTTification" k2 " failed." exit 1 } } - if(system(cpcmd[k])!=0) - { - print "Frame"k2" upload failed." + if (system(cpcmd[k]) != 0) { + print "Frame" k2 " upload failed." exit 1 } - if(system(chmodcmd[k])!=0) - { - print "Frame"k2" chmod failed." + if (system(chmodcmd[k]) != 0) { + print "Frame" k2 " chmod failed." exit 1 } } - print sprintf("%u %u %u 0",nextstate,f,nextong) > statefile + print sprintf("%u %u %u 0", nextstate, f, nextong) > statefile close(statefile) print sprintf("ONGed. Next ong %u.",nextong) @@ -448,91 +445,78 @@ END{ # add condition here. # Ok, done. - if (!firstong) - { + if (!firstong) { ongbotfile= datapath argtab["story"] "/" ((argtab["ongbot"]!="")?argtab["ongbot"]:"ongbot") if (system("[ -f " ongbotfile " ]")==0) system(ongcmd) } } -function getnextongtime( schedulefile,temp,i) -{ - schedulefile= datapath argtab["story"]"/schedule" +function getnextongtime( schedulefile,temp,i) { + schedulefile = datapath argtab["story"]"/schedule" - while((getline temp < schedulefile)>0) - { + while ((getline temp < schedulefile) > 0) { if (temp !~ /^[0-9]+$/) continue i = int(temp) # print i - if(i>thistime3) - { + if (i > thistime3) { close(schedulefile) print "ok" return i } } close(schedulefile) - return thistime3 + int(argtab["ongtime"])*3600 + return thistime3 + int(argtab["ongtime"]) * 3600 } -function readspecialfile (datafile, argtab, specialtab, effectivetab, line,undertext,eq,i) -{ +function readspecialfile (datafile, argtab, specialtab, effectivetab, line,undertext,eq,i) { for (i in specialtab) delete specialtab[i] for (i in effectivetab) delete effectivetab[i] - if (datafile=="") + if (datafile == "") return - line="" - while((getline line < datafile)>0) - { + line = "" + while ((getline line < datafile) > 0) { gsub(/[\r\n]/, "", line) - if (line == "" && !undertext) - { - undertext=1 - specialtab["text"]="" + if (line == "" && !undertext) { + undertext = 1 + specialtab["text"] = "" } - else if (undertext) - { + else if (undertext) { specialtab["text"] = specialtab["text"] line "\n" } - else - { - eq=index(line, "=") - specialtab[substr(line, 1, eq-1)]=substr(line, eq+1) + else { + eq = index(line, "=") + specialtab[substr(line, 1, eq-1)] = substr(line, eq+1) } } for (i in argtab) - effectivetab[i]=argtab[i] + effectivetab[i] = argtab[i] for (i in specialtab) - effectivetab[i]=specialtab[i] - + effectivetab[i] = specialtab[i] close (datafile) - } -function writespecialfile (datafile, specialtab, i) -{ - for (i in specialtab) - { - if (i!="text") - print i"="specialtab[i] > specialfile +function writespecialfile (datafile, specialtab, i) { + for (i in specialtab) { + if (i != "text") + print i "=" specialtab[i] > specialfile } print "" > specialfile - if (specialtab["text"]!="") - printf("%s",specialtab["text"]) > specialfile + if (specialtab["text"] != "") + printf("%s", specialtab["text"]) > specialfile close (specialfile) } diff --git a/viewer.awk b/viewer.awk index 4857297..ce24764 100644 --- a/viewer.awk +++ b/viewer.awk @@ -1,7 +1,7 @@ #// viewer.awk #// The viewer #// -#// Copyright (C) 2015-2021, 2023 Balthasar Szczepański +#// Copyright (C) 2015-2021, 2023, 2025 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 @@ -29,394 +29,377 @@ BEGIN{ botcastleurl="http://1190.bicyclesonthemoon.info" postlink="http://forums.xkcd.com/viewtopic.php?f=7" - for(i=0;i<256;++i) - { - ch=sprintf("%c",i) - hex=sprintf("%02X",i) - dec=sprintf("%u",i) - ch2hex[ch]=hex - ch2dec[ch]=dec + for (i=0; i<256; ++i) { + ch = sprintf("%c",i) + hex = sprintf("%02X",i) + dec = sprintf("%u",i) + ch2hex[ch] = hex + ch2dec[ch] = dec } listfile = datapath "stories" - stories=0 - line="" - while((getline line < listfile)>0) - { + stories = 0 + line = "" + while ((getline line < listfile) > 0) { gsub(/[\r\n]/,"",line) - eq=index(line,"=") + eq = index(line,"=") - storytab[stories]=htmlescape(substr(line, 1, eq-1),"","") - storyname[stories]=htmlescape(substr(line, eq+1),"","") + storytab[stories] = htmlescape(substr(line, 1, eq-1), "", "") + storyname[stories] = htmlescape(substr(line, eq+1), "" , "") ++stories } - close(listfile) + close (listfile) - if(frame ~ /[a-zA-Z]$/) - { - f=int(substr(frame,1,length(frame)-1)) - s=substr(frame, length(frame)) + if (frame ~ /[a-zA-Z]$/) { + f = int(substr(frame,1,length(frame)-1)) + s = substr(frame, length(frame)) } - else - { - f=int(frame) - s="" + else { + f = int(frame) + s = "" } - e=int(enhance) - n=int(notice) - b=int(bbcode) + e = int(enhance) + n = int(notice) + b = int(bbcode) timecmd | getline thistime - close(timecmd) + close (timecmd) timecmd2 | getline thistime2 - close(timecmd2) + close (timecmd2) timecmd3 | getline thistime3 - close(timecmd3) + close (timecmd3) timecmd4 | getline thistime4 - close(timecmd4) + close (timecmd4) - thistime3=int(thistime3) - thistime4=int(thistime4) + thistime3 = int(thistime3) + thistime4 = int(thistime4) - lastalt=0 + lastalt = 0 - ch2num[0]="" - num2ch[""]=0 - for(i=1;i<=26;++i) - { - ch=sprintf("%c",i+96) - num2ch[i]=ch - ch2num[ch]=i + ch2num[0] = "" + num2ch[""] = 0 + for (i=1; i<=26; ++i) { + ch = sprintf("%c",i+96) + num2ch[i] = ch + ch2num[ch] = i } - for(i=0;i<256;++i) - { - ch=sprintf("%c",i) - dec=sprintf("%u",i) - ch2dec[ch]=dec + for(i=0;i<256;++i) { + ch = sprintf("%c",i) + dec = sprintf("%u",i) + ch2dec[ch] = dec } - alttabsize=0 + alttabsize = 0 } { - file=1 + file = 1 gsub(/[\r\n]/, "", $0) - eq=index($0, "=") - if($0 ~ /^[0-9]+=/) - { - i=int(substr($0, 1, eq-1)) - alttab[alttabsize]=substr($0, eq+1) - alttabn[alttabsize]=i + eq = index($0, "=") + ind = substr($0, 1, eq-1) + val = substr($0, eq+1) + + if ($0 ~ /^[0-9]+=/) { + alttab [alttabsize] = val + alttabn[alttabsize] = int(ind) ++alttabsize - - # i=int(substr($0, 1, eq-1)) - # if(f>=i && i>=lastalt) - # { - # alt=substr($0, eq+1) - # lastalt=i - # } - } - else if($0 ~ /^sf-[0-9]+=/) - { - sf=1 - i=int(substr($0, 4, eq-4)) - if(i==f) - this_sf= tolower(substr($0, eq+1)) - if(i==f-1) - prev_sf=tolower(substr($0, eq+1)) - } - argtab[substr($0, 1, eq-1)]=substr($0, eq+1) + else if($0 ~ /^sf-[0-9]+=/) { + sf = 1 + ind = "sf-"int(substr($0, 4, eq-4)) + val = tolower(val) + i=int(ind) + } + argtab[ind] = val } END{ if (file=="") exit 1 - if(sf=="") - s="" - else if(this_sf=="") - s="" - else if(s>this_sf && argtab["cfrt"]=="") - s=this_sf - ongoing=int(argtab["ongoing"]) - if(ongoing>0) - { - statefile= datapath argtab["story"]"/ongstate" + if (ongoing > 0) { + statefile= datapath argtab["story"] "/ongstate" getline temp < statefile - close(statefile) + close (statefile) split(temp, temptab, " ") - state=int(temptab[1]) - last=int(temptab[2]) - nextong=int(temptab[3]) + state = int(temptab[1]) + last = int(temptab[2]) + nextong = int(temptab[3]) + # ongfailcount = int(temptab[4]) } - else - { - last=int(argtab["last"]) - state=3 + else { + last = int(argtab["last"]) + state = 3 + nextong = 0 + # ongfaicount = 0 } - first=int(argtab["first"]) + first = int(argtab["first"]) - ongtimefile= datapath argtab["story"]"/ongtime" + if (sf=="") { + s = "" + last_sf = "" + this_sf = "" + prev_sf = "" + } + else { + last_sf = argtab["sf-" last] + this_sf = argtab["sf-" f ] + prev_sf = argtab["sf-"(f-1)] + } - if(frame=="") - { - if(ongoing>0) - { - if (int(argtab["onlyframe"])>0) - { - f=last - onlyframe=1 + ongtimefile= datapath argtab["story"] "/ongtime" + + if (frame == "") { + if (ongoing > 0) { + if (int(argtab["onlyframe"]) > 0) { + f = last + s = last_sf + onlyframe = 1 } - else - { - onlyframe="" - if (int(argtab["showlatest"])>0) - f=last - else - f=first + else { + onlyframe = "" + if (int(argtab["showlatest"]) > 0) { + f = last + s = last_sf + } + else { + f = first + s = "" + } } } - else - { - f=first - onlyframe="" - if (replay != "") - { + else { + f = first + s = "" + onlyframe = "" + + if (replay != "") { # print "DEBUG:
" - ongyr=0 - ongsy=0 - line="" - while((getline line < ongtimefile)>0) - { - ongind=index(line," ") - ongft=substr(line,1,ongind-1) - ongt=int((ongsy?(substr(line,ongind+1,4)-ongyr):0) substr(line,ongind+6,2) substr(line,ongind+9,2) substr(line,ongind+12,2) substr(line,ongind+15,2)) - + ongyr = 0 + ongsy = 0 + line = "" + while ((getline line < ongtimefile) > 0) { + ongind = index(line, " ") + ongft = substr(line,1,ongind-1) + ongt = int((ongsy ? (substr(line,ongind+1,4)-ongyr) : 0) substr(line,ongind+6,2) substr(line,ongind+9,2) substr(line,ongind+12,2) substr(line,ongind+15,2)) # printf("o.%d
",ongt) - - if(!ongsy) - { - ongsy=1 - ongyr=substr(line,ongind+1,4) + if (!ongsy) { + ongsy = 1 + ongyr = substr(line,ongind+1,4) # printf("3.%d
",thistime3) - if(thistime3",thistime3) } } - - if(ongt>thistime3) - { + if (ongt > thistime3) { # if(ongsm) # print"BREAK!
" break; } # else # ongsm=1; - if(ongft ~ /^[0-9]+[a-z]$/) - { - f=int(substr(ongft,1,ongind-2)) - s=substr(ongft,ongind-1,1) + if (ongft ~ /^[0-9]+[a-z]$/) { + f = int(substr(ongft,1,ongind-2)) + s = substr(ongft,ongind-1,1) } - else - { - f=int(ongft) - s="" + else { + f = int(ongft) + s = "" } # print"f."f"."s"
" } - close(ongtimefile) + close (ongtimefile) } } } - if (s!="") - { - if(argtab[s] != "") - s2=argtab[s] - else - s2=s - # n=-1 - } + cfrt = "" + invalid = "" - if(flast && argtab["cfrt"]=="") - f=last + if (state !~ /^[1235]$/) { + cfrt = 1 + invalid = 1 + } + else if (f < first) { + f = first + s = "" + cfrt = 1 + } + else if (f > last) { + f = last + s = last_sf + cfrt = 1 + } + else if (sf != "") { + if ((s != "") && (this_sf == "")) { + s = "" + cfrt = 1 + } + else if ((s != "") && (this_sf != "") && (s > this_sf)) { + s = this_sf + cfrt =1 + } + } - if(argtab["special"] != "") - { - specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,s) - line="" - undertext="" + if (cfrt && (argtab["cfrt"] != "")) { + } + else if (invalid) { + print "Status: 302 Temporal Relocation" + print "Location: /aftertime/viewer?story=default" + print "" + exit 0 + } + else if (argtab["special"] != "") { + specialfile = datapath argtab["story"] "/" sprintf(argtab["special"], f, s) + line = "" + undertext = "" - while((getline line < specialfile)>0) - { + while ((getline line < specialfile) > 0) { gsub(/[\r\n]/, "", line) - if (line == "" && !undertext) - { - undertext=1 - argtab["text"]="" + if ((line == "") && (!undertext)) { + undertext = 1 + argtab["text"] = "" continue } - if (undertext) - { + if (undertext) { argtab["text"] = argtab["text"] line "\n" } - else - { - - eq=index(line, "=") - argtab[substr(line, 1, eq-1)]=substr(line, eq+1) + else { + eq = index(line, "=") + argtab[substr(line, 1, eq-1)] = substr(line, eq+1) } } close (specialfile) } - line="" - while((getline line < ongtimefile)>0) - { - ongind=index(line," ") - ongft=substr(line,1,ongind-1) - ongt=substr(line,ongind+9,2)"."substr(line,ongind+6,2)"."substr(line,ongind+1,4)", "substr(line,ongind+12,2)":"substr(line,ongind+15,2)" UTC" - if(ongft ~ /^[0-9]+[a-z]$/) - ongf=int(substr(ongft,1,ongind-2)) substr(ongft,ongind-1,1) + line = "" + while ((getline line < ongtimefile) > 0) { + ongind = index(line," ") + ongft = substr(line,1,ongind-1) + ongt = substr(line,ongind+9,2) "." substr(line,ongind+6,2) "." substr(line,ongind+1,4) ", " substr(line,ongind+12,2) ":" substr(line,ongind+15,2) " UTC" + if (ongft ~ /^[0-9]+[a-z]$/) + ongf = int(substr(ongft,1,ongind-2)) substr(ongft,ongind-1,1) else - ongf=int(ongft) + ongf = int(ongft) - if(ongf==(f s) && ongt ~ /^[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9], [0-9][0-9]:[0-9][0-9] UTC$/) - ongtimetext=ongt + if ((ongf == (f s)) && ongt ~ (/^[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9], [0-9][0-9]:[0-9][0-9] UTC$/)) + ongtimetext = ongt } - close(ongtimefile) + close (ongtimefile) if ("alt" in argtab) - alt=htmlescape(argtab["alt"],"less","bb") - else - { - for(i=0; i=alttabn[i] && alttabn[i]>=lastalt) - { - alt=htmlescape(alttab[i],"less","bb") - lastalt=alttabn[i] + alt = htmlescape(argtab["alt"], "less", "bb") + else { + for(i=0; i= alttabn[i]) && (alttabn[i] >= lastalt)) { + alt = htmlescape(alttab[i], "less", "bb") + lastalt = alttabn[i] } } } - if(argtab["number"]!="") - numberformat=argtab["number"] - else - { + if (argtab["number"] != "") + numberformat = argtab["number"] + else { # if (sf!="") - numberformat="%u%s" + numberformat = "%u%s" # else - # numberformat="%u" - } - - framedir= (argtab["framedir"]!="" ? argtab["framedir"] : "/aftertime/"argtab["story"]"/") - # if(sf!="") - # { - title=htmlescape(sprintf(argtab["title"(e>0 ? "-"e : "")],f,s2),"less","bb") - frame=framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f,s) - if (system("[ -f " framepath frame" ]")!=0) - { - frame= framedir sprintf(argtab["frame"],f,s) - title=htmlescape(sprintf(argtab["title"],f,s2),"less","bb") - noenh=1 - } - otherviewerurl=sprintf(argtab["otherviewerurl"], f+int(argtab["othervieweroffset"]),s2) - # } - # else - # { - # s="" - # title=htmlescape(sprintf(argtab["title"(e>0 ? "-"e : "")],f),"less","bb") - # frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f) - # if (system("[ -f " framepath frame" ]")!=0) - # { - # frame= framedir sprintf(argtab["frame"],f) - # title=htmlescape(sprintf(argtab["title"],f,s),"less","bb") - # noenh=1 - # } - # otherviewerurl=sprintf(argtab["otherviewerurl"], f+int(argtab["othervieweroffset"])) - # } - - dynamicframe="/aftertime/frame?story="argtab["story"](max_enhance>0?"&e="e:"")"&f="f s - - if((f>last || fthis_sf)) && argtab["cfrt"]!="") - frame= framedir argtab["cfrt"] - - border= int(argtab["border"]) - if(argtab["width"]!="") - width= int(argtab["width"]) + 2*border - else - width="100%" - max_enhance=int(argtab["enhance"]) + # numberformat = "%u" + } - if (this_sf=="") + if (s != "") { - next_f= f+1 - next_s= "" + if(argtab[s] != "") + s2 = argtab[s] + else + s2 = s } - else if(s=="") - { - next_f=f - next_s="a" + + framedir = (argtab["framedir"]!="" ? argtab["framedir"] : "/aftertime/"argtab["story"]"/") + title = htmlescape(sprintf(argtab["title"(e>0 ? "-"e : "")], f, s2),"less","bb") + if (cfrt && (argtab["cfrt"] != "")) { + frame = framedir argtab["cfrt"] + dynamicframe = frame } - else if(s>=this_sf) - { - next_f= f+1 - next_s= "" + else { + frame = framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f,s) + if (system("[ -f " framepath frame" ]") !=0 ) { + frame = framedir sprintf(argtab["frame"],f,s) + title = htmlescape(sprintf(argtab["title"],f,s2),"less","bb") + noenh = 1 + } + dynamicframe = "/aftertime/frame?story=" argtab["story"] ((max_enhance>0)?("&e=" e):"") "&f=" f s } + otherviewerurl = sprintf(argtab["otherviewerurl"], f+int(argtab["othervieweroffset"]), s2) + + border = int(argtab["border"]) + if (argtab["width"] != "") + width = int(argtab["width"]) + 2*border else - { + width = "100%" + max_enhance = int(argtab["enhance"]) + + loop = "" + if ((state ~ /^[35]$/) && (argtab["loop"] != "") && (f == last) && ((last_sf == "") || (s == last_sf))) { + loop = 1 + if (argtab["loop"] ~ /[a-zA-Z]$/) { + next_f = int(substr(argtab["loop"],1,length(argtab["loop"])-1)) + next_ss = substr(argtab["loop"], length(argtab["loop"])) + } + else { + next_f = int(argtab["loop"]) + next_s = "" + } + } + else if (this_sf == "") { + next_f = f+1 + next_s = "" + } + else if (s == "") { + next_f = f + next_s = "a" + } + else if (s >= this_sf) { + next_f = f+1 + next_s = "" + } + else { next_f = f next_s = num2ch[ch2num[s]+1] } - if(this_sf!="" && s!="") - { + if ((this_sf != "") && (s != "")) { prev_f = f prev_s = num2ch[ch2num[s]-1] } - else if(prev_sf!="") - { + else if (prev_sf != "") { prev_f = f-1 prev_s = prev_sf } - else - { + else { prev_f = f-1 prev_s = "" } - if(prev_s!=""){ - if(argtab[prev_s]!=""){ - prev_s2=argtab[prev_s] - } + if (prev_s != "") { + if (argtab[prev_s] != "") + prev_s2 = argtab[prev_s] else - { - prev_s2=prev_s - } + prev_s2 = prev_s } else prev_s2 = "" - if (next_s!="") - { - if(argtab[next_s]!=""){ - next_s2=argtab[next_s] - } + if (next_s != "") { + if (argtab[next_s] != "") + next_s2 = argtab[next_s] else - { - next_s2=next_s - } + next_s2 = next_s } else next_s2 = "" @@ -429,12 +412,10 @@ END{ print "" print "" print "0?"&e="e:"")"&f="first"\">" - if(f>first) - { + if ((f > first) || ((this_sf != "") && (s != ""))) { print "0?"&e="e:"")"&f="prev_f prev_s"\">" } - if(f0?"&e="e:"")"&f="next_f next_s"\">" print "0?"&e="e:"")"&f="next_f next_s"\">" } @@ -446,72 +427,63 @@ END{ if(onlyframe!="") print "0?"&e="e:"")"&f="f s"\">" print "0 && state <2 && f==last)?dynamicframe:frame)"\" alt=\""title"\" title=\""alt"\" border=\""border"\">" - if(onlyframe!="") + if (onlyframe != "") print "" print "" - if(ongoing==1) - { - # print "" - if(state<3) - { - # ongtime=int(argtab["ongtime"]) - # dt = (3600*ongtime - ( int(substr(thistime2,5,2)) + 60*int(substr(thistime2,3,2)) + 3600*( int(substr(thistime2,1,2))%int(argtab["ongtime"]) ) ))%(ongtime*3600) - # ss=(dt>0 ? sprintf("%02u",dt%60) : "NG") - # mm=sprintf("%02u",int(dt/60)%60) - # hh=sprintf("%02u",int(dt/3600)) - dt=nextong-thistime4 - if (dt<-5) - { - ss="EE" - mm="EE" - hh="EE" - } - else if (dt>0) - { - ss=sprintf("%02u",dt%60) - mm=sprintf("%02u",int(dt/60)%60) - if ((dt/3600)>99) - hh="EE" - else - hh=sprintf("%02u",int(dt/3600)) - } - else { - ss="NG" - mm="00" - hh="00" - } - } + if (state ~ /^[35]$/) { + if (argtab["last"] == "") + showtime = 1 + else if (last < int(argtab["last"])) + showtime = 1 else - { + showtime = "" + } + else if (state ~ /^[12]$/) + showtime = 1 + else + showtime = "" + + if (showtime) { + # print "" + dt = nextong - thistime4 + if (dt < -5) { ss="EE" mm="EE" hh="EE" } + else if (dt > 0) { + ss=sprintf("%02u",dt%60) + mm=sprintf("%02u",int(dt/60)%60) + if ((dt/3600)>99) + hh="EE" + else + hh=sprintf("%02u",int(dt/3600)) + } + else { + ss = "NG" + mm = "00" + hh = "00" + } # hh=nextong" "thistime4 - timecolor=(state>1?"br":"ni") + timecolor = ((state == 1)? "ni" : ((state == 2) ? "br" : "cz")) print ""hh":"mm":"ss"" } - if(onlyframe=="") - { - if(max_enhance>0) - { + if (onlyframe == "") { + if (max_enhance > 0) { print "[" - for(i=0;i<=max_enhance;++i) - { - if(i!=0) + for (i=0; i<= max_enhance; ++i) { + if (i != 0) print "|" # if(sf!="") enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f,s) # else # enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f) - - if (system("[ -f " framepath enhancedframe" ]")==0) - { - if(i==e) + if (system("[ -f " framepath enhancedframe" ]") == 0) { + if (i == e) print""argtab["enhance-"i]"" else print"0)?("&b="b):"")"\">"argtab["enhance-"i]"" @@ -524,15 +496,13 @@ END{ print "" print "0?"&e="e:"")"&f="first"\">|< "sprintf(numberformat,first,"")"" - print ""(f>first?"0?"&e="e:"")"&f="prev_f prev_s"\">< "sprintf(numberformat,prev_f,prev_s2)"":"")"" - print ""(f0?"&e="e:"")"&f="next_f next_s"\">"sprintf(numberformat,next_f,next_s2)" >":"")"" + print ""(((f > first) || ((this_sf != "") && (s != "")))?"0?"&e="e:"")"&f="prev_f prev_s"\">< "sprintf(numberformat,prev_f,prev_s2)"":"")"" + print ""(((f < last) || ((this_sf != "") && (s < this_sf)) || loop)?"0?"&e="e:"")"&f="next_f next_s"\">"sprintf(numberformat,next_f,next_s2)" >":"")"" print "0?"&e="e:"")"&f="last"\">"sprintf(numberformat,last,"")" >|" print "" - if(ongtimetext!="") - { - if(argtab["ID"]!="") - { + if (ongtimetext != "") { + if (argtab["ID"] != "") { print ""ongtimetext"" } # else if (argtab["otherviewerurl"]!="") @@ -543,60 +513,50 @@ END{ print ""ongtimetext"" } - if(argtab["HTML"]!="" && b==0) - { + if (argtab["HTML"]!="" && b==0) { print ""argtab["HTML"]"" } - for(i=-1; i<=n+1; ++i) - { + for (i=-1; i<=n+1; ++i) { # print "" if(i<0) - noticepost=noticepath argtab["story"]"-i" + noticepost = noticepath argtab["story"] "-i" else - noticepost=noticepath argtab["story"]"-"sprintf("%04u%s",f,s)"-"sprintf("%02u",i) + noticepost = noticepath argtab["story"] "-" sprintf("%04u%s",f,s) "-" sprintf("%02u",i) split("", noticetab, ":") - for(j=0;(getline line < noticepost)>0;++j) - { + for (j=0; (getline line < noticepost)>0; ++j) { gsub(/[\r\n]/,"",line) - eq=index(line,"=") - noticetab[substr(line, 1, eq-1)]=substr(line, eq+1) + eq = index(line,"=") + noticetab[substr(line, 1, eq-1)] = substr(line, eq+1) } - close(noticepost) - if(j==0) - { - if(i<=0) + close (noticepost) + if (j == 0) { + if (i <= 0) continue; else break; } - if(i>=0) - { - nposttime=noticetab["y"]noticetab["m"]noticetab["d"]noticetab["h"] + if (i >= 0) { + nposttime = noticetab["y"] noticetab["m"] noticetab["d"] noticetab["h"] if ((thistime0)) break; } - if(i<=n) - { - if(i>=0) + if (i <= n) { + if (i >= 0) print ""noticetab["subject_h"]" "(noticetab["ID"]!=""?"        (OTT time travel)":"")"" print""((noticetab["HTML"]!="")?noticetab["HTML"]:noticetab["BBHTML"])"" } - else - { + else { print "0?"&e="e:"")"&f="f s"&n="i"\">"noticetab["subject_h"]"" } } - if(b>0) - { - if (argtab["BBHTML"]!="") - { - bbtext=argtab["BBHTML"] + if (b > 0) { + if (argtab["BBHTML"] != "") { + bbtext = argtab["BBHTML"] } - else if (argtab["text"]!="") - { - bbtext=htmlescape(argtab["text"],"less","bb") + else if (argtab["text"] != "") { + bbtext = htmlescape(argtab["text"],"less","bb") gsub(/ /,"\\  ",bbtext) gsub(/ /," \\ ",bbtext) } @@ -605,38 +565,36 @@ END{ print"[url="botcastleurl"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&e="e:"")"&f="f s"][img]"botcastleurl frame"[/img][/url]"(bbtext!=""?"
"bbtext:"")(b>1 && alt!=""?"[spoiler]"alt"[/spoiler]":"") print"
" - ongbotdefined="" - ongbotfile= datapath argtab["story"] "/" ((argtab["pleaseongbot"]!="")?argtab["pleaseongbot"]:"pleaseongbot") - if (system("[ -f " ongbotfile " ]")==0) - ongbotdefined=1 + ongbotdefined = "" + ongbotfile = datapath argtab["story"] "/" ((argtab["pleaseongbot"]!="")?argtab["pleaseongbot"]:"pleaseongbot") + if (system("[ -f " ongbotfile " ]") == 0) + ongbotdefined = 1 - if(ongbotdefined && ongoing>0 && state>0 && state<4 && f==last && b==(alt!=""?2:1)) - { + if (ongbotdefined && ongoing>0 && state>0 && state<4 && f==last && b==(alt!=""?2:1)) { print "" print "
" print "[]" print "" - if(e>0 && noenh=="") + if (e>0 && noenh=="") print "" print "
" } - if(b==1 && alt!="") + if (b==1 && alt!="") print "[0?"&e="e:"")"&f="f s"&b=2\">spoiler]" } else print "[0?"&e="e:"")"&f="f s"&b=1\">bbcode]" - if(argtab["otherviewerurl"]!="") + if (argtab["otherviewerurl"]!="") print "["argtab["otherviewertext"]"]" print "
Go to frame:" print "" - if(max_enhance>0) + if (max_enhance>0) print "" print "" print "" - if(ongtimetext!="" && ongoing==0) - { + if (ongtimetext!="" && ongoing==0) { # print ongoing # print"" # print "" @@ -650,7 +608,7 @@ END{ print"
" print "
Go to story:
"