]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
Update from src as of 25.05.2021
authorb <rowerynaksiezycu@gmail.com>
Tue, 25 May 2021 20:33:49 +0000 (20:33 +0000)
committerb <rowerynaksiezycu@gmail.com>
Tue, 25 May 2021 20:33:49 +0000 (20:33 +0000)
16 files changed:
bot4.awk
compare-t-1.awk [new file with mode: 0644]
convert1.awk [new file with mode: 0644]
convert2.awk [new file with mode: 0644]
frame.awk
info.awk
mpview.c
ong-bsta.awk
ong-mscha-t-1.awk
ong.awk
post.cpp
preview.awk
remove.c
upload.awk
verify.awk
viewer.awk [new file with mode: 0644]

index d83e26708a3e633c075401642a477aa09e57a4e5..26100008b207283fea1f2bceefd05b6756bc600c 100644 (file)
--- a/bot4.awk
+++ b/bot4.awk
-#// bot4.awk\r
-#// The bot to post frames to the OTT\r
-#// 19.06.2018-\r
-#// \r
-#// Copyright (C) 2015, 2018  Balthasar SzczepaƄski\r
-#// \r
-#// This program is free software: you can redistribute it and/or modify\r
-#// it under the terms of the GNU Affero General Public License as\r
-#// published by the Free Software Foundation, either version 3 of the\r
-#// License, or (at your option) any later version.\r
-#// \r
-#// This program is distributed in the hope that it will be useful,\r
-#// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-#// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-#// GNU Affero General Public License for more details.\r
-#// \r
-#// You should have received a copy of the GNU Affero General Public License\r
-#// along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
-\r
-BEGIN{\r
-       FS=""\r
-       # noticepath="/eizm/mem/aftertime/mpost/"\r
-       # framepath="/eizm/www/time/"\r
-       datapath="/eizm/data/aftertime/"\r
-       timecmd="date"\r
-       timecmd2="date -u +%N%s"\r
-       lastpath ="/eizm/mem/aftertime/lastong/"\r
-       temppath ="/eizm/tmp/aftertime/"\r
-       ott_address="http://forums.xkcd.com/viewtopic.php?f=7&t=101043&start="\r
-       tto_address="http://1190.bicyclesonthemoon.info/ott/view?start="\r
-       mstd_address="http://1190.bicyclesonthemoon.info/ott/mview?start="\r
-       lastpost_address="http://forums.xkcd.com/viewtopic.php?f=7&t=101043&sd=d"\r
-       \r
-       wget="/usr/bin/wget"\r
-       rm="/bin/rm"\r
-       perl="/usr/bin/perl"\r
-       mawk="/usr/bin/mawk"\r
-       automome="/eizm/pro/ong1/mome.pl"\r
-       memedef="/eizm/mem/ong1/mome.txt"\r
-       \r
-       postawk="/eizm/pro/aftertime/post.awk"\r
-       mpostawk="/eizm/pro/aftertime/mpost.awk"\r
-       \r
-       # timecmd2="date +\"%H%M%S\""\r
-       botcastleurl="http://1190.bicyclesonthemoon.info"\r
-       \r
-       if(enhance!="" && int(enhance)!="0")\r
-       {\r
-               enh=int(enhance)\r
-               ext="-"enh\r
-       }\r
-       else\r
-       {\r
-               ext=""\r
-               enh=0\r
-       }\r
-       \r
-       f=int(frame)\r
-       timecmd | getline thistime\r
-       close(timecmd)\r
-       \r
-       timecmd2 | getline ID\r
-       close(timecmd2)\r
-       ID=int(ID/3600)\r
-       ID =int(ID%9999)\r
-       \r
-       for(i=0;i<256;++i)\r
-       {\r
-               ch=sprintf("%c",i)\r
-               hex=sprintf("%02X",i);\r
-               ch2hex[ch]=hex\r
-       }\r
-       \r
-       statefile= datapath story"/ongstate"\r
-       getline temp < statefile\r
-       close(statefile)\r
-       \r
-       split(temp, temptab, " ")\r
-       state=int(temptab[1])\r
-       last=int(temptab[2])\r
-       \r
-       if(frame=="")\r
-               f=last\r
-       \r
-       # srand(ID + f)\r
-       # for(i=0;i<f;++i)\r
-       # {\r
-               # r=rand()\r
-               # # print r\r
-       # }\r
-       lastalt=0\r
-}\r
-{\r
-       # exit\r
-       file=1\r
-       gsub(/[\r\n]/, "", $0)\r
-       eq=index($0, "=")\r
-       if($0 ~ /^[0-9]+=/)\r
-       {\r
-               i=int(substr($0, 1, eq-1))\r
-               if(f>=i && i>=lastalt)\r
-               {\r
-                       alt=substr($0, eq+1)\r
-                       lastalt=i\r
-               }\r
-       }\r
-       argtab[substr($0, 1, eq-1)]=substr($0, eq+1)\r
-}\r
-END{\r
-       # exit\r
-       \r
-       ongbot= (please!=""?((argtab["pleaseongbot"]!="")?argtab["pleaseongbot"]:"pleaseongbot"):((argtab["ongbot"]!="")?argtab["ongbot"]:"ongbot"))\r
-       \r
-       print thistime" "ongbot\r
-       \r
-       tempfile = temppath "ongbot-"argtab["story"]"-"ID\r
-       tempfile_t= tempfile"-t"\r
-       tempfile_c= tempfile"-c"\r
-       tempfile_p= tempfile"-p"\r
-       \r
-       if (file=="")\r
-       {\r
-               print "Can't open story settings file."\r
-               exit 1\r
-       }\r
-       if(argtab["ongoing"]=="")\r
-       {\r
-               print "Story not ONGoing."\r
-               exit 1\r
-       }\r
-       \r
-       \r
-       \r
-       if(state<2 && force=="" && f==last)\r
-       {\r
-               print "Wrong state."\r
-               exit 1\r
-       }\r
-       \r
-       \r
-       botfile=datapath argtab["story"]"/"ongbot\r
-       getline botname  < botfile\r
-       getline username < botfile\r
-       getline password < botfile\r
-       gsub(/[\r\n]/, "", botname)\r
-       gsub(/[\r\n]/, "", username)\r
-       gsub(/[\r\n]/, "", password)\r
-       close(botfile)\r
-       \r
-       if (botname =="" || username=="" || password=="")\r
-       {\r
-               print "Can't get login and password."\r
-               exit 1\r
-       }\r
-       print botname\r
-       \r
-       useragent = "\""botname" (time after Time post bot; http://1190.bicyclesonthemoon.info/aftertime; story="argtab["story"]"; frame "f")\""\r
-       \r
-       temp=""\r
-       lasttime = lastpath argtab["story"] ext\r
-       getline temp < lasttime\r
-       close(lasttime)\r
-       \r
-       split(temp, temptab, " ")\r
-       lastpage=int(temptab[1])\r
-       lastframe=int(temptab[2])\r
-       \r
-       print "Start with page "lastpage", last frame was "lastframe", current frame is "f"."\r
-       if(f <= lastframe && force=="")\r
-       {\r
-               print "Already ONGed."\r
-               exit 1\r
-       }\r
-       \r
-       if(force=="")\r
-       {\r
-               temp=argtab["match"ext]\r
-               for(i=0;(j=index(substr(temp,2),"%"))!=0;++i)\r
-               {\r
-                       temp2=substr(temp,1,j)\r
-                       temp=substr(temp,j+1)\r
-                       regexp = regexp sprintf(temp2,f)\r
-               }\r
-               regexp = regexp sprintf(temp,f)\r
-               print "match "regexp\r
-               \r
-               for(page=lastpage;page<=lastpage;++page)\r
-               {\r
-                       url= "\""ott_address (page-1)*40"\""\r
-                       url2= "\""tto_address (page-1)*40"\""\r
-                       \r
-                       cmd= wget " -q -O "tempfile" -U "useragent" "url\r
-                       cmd2= wget " -q -O "tempfile" -U "useragent" "url2\r
-                       # print "! "cmd" !"\r
-                       if(system(cmd)!=0)\r
-                       {\r
-                               print "Newpage "page" download fail. Retry from mirror."\r
-                               if(system(cmd2)!=0)\r
-                               {\r
-                                       print "Newpage "page" download fail."\r
-                                       system(rm" -f "tempfile)\r
-                                       exit 1\r
-                               }\r
-                       }\r
-                       while((getline temp < tempfile)>0)\r
-                       {\r
-                               if(temp ~ regexp)\r
-                               {\r
-                                       print "Newpage "page" - already ONGed."\r
-                                       system(rm" -f "tempfile)\r
-                                       print page" "f > lasttime\r
-                                       close(lasttime)\r
-                                       exit 1\r
-                               }\r
-                               gsub(/<[^<>]*>/,"",temp)\r
-                               gsub(/ +/," ",temp)\r
-                               temp2=tolower(temp)\r
-                               if((i=match(temp2,/page [0-9]+ of [0-9]+/))!=0)\r
-                               {\r
-                                       temp2=substr(temp2,i)\r
-                                       temp2=substr(temp2,index(temp2,"of")+3)" "\r
-                                       temp2=substr(temp2,1,index(temp2," ")-1)\r
-                                       lastpage=int(temp2)\r
-                               }\r
-                               temp2=tolower(temp)\r
-                               if((i=match(temp2,/[0-9]+ posts/))!=0)\r
-                               {\r
-                                       temp2=substr(temp2,index(temp2,"")-1)\r
-                                       posts=int(temp2)\r
-                                       if(posts%40==0)\r
-                                               pope=1\r
-                                       else\r
-                                               pope=""\r
-                               }\r
-                       }\r
-                       close(tempfile)\r
-                       print "Newpage "page" - nothing found."\r
-               }\r
-               mlastpage=1\r
-               for(mpage=1;mpage<=mlastpage;++mpage)\r
-               {\r
-                       url= "\""mstd_address (mpage-1)*40"\""\r
-                       \r
-                       cmd= wget " -q -O "tempfile" -U "useragent" "url\r
-                       if(system(cmd)!=0)\r
-                       {\r
-                               print "Mustardtime newpage "mpage" not downloaded."\r
-                               break\r
-                       }\r
-                       for(j=0;(getline temp < tempfile)>0;++j)\r
-                       {\r
-                               if(temp ~ regexp)\r
-                               {\r
-                                       print "Newpage "mpage" - already ONGed."\r
-                                       system(rm" -f "tempfile)\r
-                                       #writeout\r
-                                       exit 1\r
-                               }\r
-                               gsub(/<[^<>]*>/,"",temp)\r
-                               gsub(/ +/," ",temp)\r
-                               temp2=tolower(temp)\r
-                               if((i=match(temp2,/page [0-9]+ of [0-9]+/))!=0)\r
-                               {\r
-                                       temp2=substr(temp2,i)\r
-                                       temp2=substr(temp2,index(temp2,"of")+3)\r
-                                       temp2=substr(temp2,1,index(temp2," ")-1)\r
-                                       mlastpage=int(temp2)\r
-                               }\r
-                               temp2=tolower(temp)\r
-                               if((i=match(temp2,/[0-9]+ posts/))!=0)\r
-                               {\r
-                                       temp2=substr(temp2,index(temp2,"")-1)\r
-                                       posts=int(temp2)\r
-                                       if(posts%40==0)\r
-                                               pope=1\r
-                                       else\r
-                                               pope=""\r
-                               }\r
-                       }\r
-                       close(tempfile)\r
-                       print "Mustradtime newpage "mpage" - nothing found."\r
-               }\r
-       }\r
-       \r
-       if(argtab["nomeme"]=="")\r
-       {\r
-               print "Ok, can ONG. Now generate ONGtext"\r
-               cmd = perl" "automome" -lc 150 -n 67 -d "memedef (pope!=""?" -t \"[decrall]\"":"")\r
-               while ((cmd | getline temp)>0)\r
-               {\r
-                       if(sub(/[AEIOUY]-N-G/,"[b]O-N-G[/b]",temp)>0)\r
-                       {\r
-                               ongtext= prepare(temp)\r
-                               break\r
-                       }\r
-                       if(sub(/O+N+G+/,"[b]&[/b]",temp)>0)\r
-                       {\r
-                               ongtext= prepare(temp)\r
-                               break\r
-                       }\r
-                       if(sub(/DON'T/,"D[b]ON'G[/b]T",temp)>0)\r
-                       {\r
-                               ongtext= prepare(temp)\r
-                               break\r
-                       }\r
-                       if(sub(/[AEIOUY]NG/,"[b]ONG[/b]",temp)>0)\r
-                       {\r
-                               if($0!~/TH\[b\]ONG/)\r
-                               {\r
-                                       ongtext= prepare(temp)\r
-                                       break\r
-                               }\r
-                       }\r
-                       if(sub(/ON G/,"[b]ON G[/b] ",temp)>0)\r
-                       {\r
-                               ongtext= prepare(temp)\r
-                               break\r
-                       }\r
-                       if(sub(/ON /,"[b]ONG[/b] ",temp)>0)\r
-                       {\r
-                               ongtext= prepare(temp)\r
-                               break\r
-                       }\r
-                       if(sub(/O\.?$/,"[b]ONG[/b] ",temp)>0)\r
-                       {\r
-                               ongtext= prepare(temp)\r
-                               break\r
-                       }\r
-               }\r
-               close(cmd)\r
-               \r
-               if(ongtext=="")\r
-                       ongtext="ONG"\r
-               print ongtext\r
-       }\r
-       else\r
-               ongtext="ONG"\r
-       \r
-       cmd= wget " -q -O "tempfile" -U "useragent" \""lastpost_address"\""\r
-       if(system(cmd)!=0)\r
-       {\r
-               print "Can't check last post"\r
-               # system(rm" -f "tempfile)\r
-               # exit 1\r
-       }\r
-       \r
-       else\r
-       {\r
-               while((getline temp < tempfile)>0)\r
-               {\r
-                       if ((i=match(temp, /id=\"p[0-9]+\"/))!=0) #"\r
-                       {\r
-                               temp2=substr(temp, i+5)\r
-                               lastpostid=substr(temp2, 1, index(temp2,"\"")-1)\r
-                       }\r
-                       \r
-                       if (temp ~ /class=\"postprofile\"/) #"\r
-                               postprofile = "1"\r
-               \r
-                       else if (postprofile=="")\r
-                               continue\r
-               \r
-                       if(temp ~ /memberlist\.php.*mode=viewprofile[^<>]*>[^<>]+<\/a/)\r
-                       {\r
-                               temp2=substr(temp, index(temp, ">")+1)\r
-                               lastusername=substr(temp2, 1, index(temp2,"<")-1)\r
-                               break\r
-                       }\r
-               }\r
-               close(tempfile)\r
-               if(lastusername=="" || lastpostid=="")\r
-               {\r
-                       print "Can't check last post"\r
-                       # system(rm" -f "tempfile)\r
-                       # exit 1\r
-               }\r
-       }\r
-       \r
-       srand(ID+lastpostid+f)\r
-\r
-       if(rand()<(argtab["npbprob"]+0))\r
-       {\r
-               print "Also, let's do some NewpixbOTTification!"\r
-               npbsel="npbframe"ext\r
-       }\r
-       else\r
-               npbsel="frame"ext\r
-\r
-       \r
-       \r
-       framedir= (argtab["framedir"]!="" ? argtab["framedir"] : "/aftertime/"argtab["story"]"/")\r
-       \r
-       print "username="urlencode(username) > tempfile\r
-       print "password="urlencode(password,1) >> tempfile\r
-       print "subject="urlencode(sprintf(argtab["subject"ext],f)) >> tempfile\r
-       print "message="urlencode(ongtext"\n[url="botcastleurl"/aftertime/viewer?story="argtab["story"]"&f="f((enh>0)?"&e="enh:"")"][img]"botcastleurl framedir sprintf(argtab[npbsel],f)"[/img][/url][spoiler]"alt"[/spoiler]\n[right][size=80] -- posted by "botname"[/size][/right]") >> tempfile\r
-       print "Send post"\r
-       \r
-       cmd= mawk" -f "postawk" -v postfile="tempfile_p" -v cookiefile="tempfile_c" -v tempfile="tempfile_t((lastpostid!="" && lastusername!="")?" -v edit="lastpostid" -v user=\""lastusername"\"":"")" "tempfile\r
-       cmd2= mawk" -f "mpostawk" -v postfile="tempfile_p" -v cookiefile="tempfile_c" -v tempfile="tempfile_t" "tempfile\r
-       \r
-       if(system(cmd)!=0)\r
-       {\r
-               print "Can't post, try again from mirror"\r
-               if(system(cmd2)!=0)\r
-               {\r
-                       print "CAN'T POST EITHER!"\r
-                       system(rm" -f "tempfile)\r
-                       system(rm" -f "tempfile_t)\r
-                       system(rm" -f "tempfile_c)\r
-                       system(rm" -f "tempfile_p)\r
-                       exit 1\r
-               }\r
-       }\r
-       print "ONGed"\r
-       system(rm" -f "tempfile)\r
-       system(rm" -f "tempfile_t)\r
-       system(rm" -f "tempfile_c)\r
-       system(rm" -f "tempfile_p)\r
-       if(force=="")\r
-       {\r
-               print lastpage" "f > lasttime\r
-               close(lasttime)\r
-       }\r
-       \r
-       \r
-}\r
-function urlencode(name, all,  len,iii,escaped,ch)\r
-{\r
-       len=length(name)\r
-       escaped=""\r
-       for(iii=1;iii<=len;++iii)\r
-       {\r
-               ch=substr(name,iii,1);\r
-               if (ch ~ /[a-z]|[A-Z]|[0-9]/ && all=="")\r
-                       escaped = escaped ch\r
-               else\r
-                       escaped = escaped "%" ch2hex[ch]\r
-       }\r
-       return escaped\r
-};\r
-function prepare(rh)\r
-{\r
-       gsub(/\*\*/,"€",rh)\r
-       gsub(/\*[^\*]+\*/,"±&±",rh)\r
-       gsub(/±\*/,"[i]",rh)\r
-       gsub(/\*±/,"[/i]",rh)\r
-       gsub(/€/,"*",rh)\r
-       \r
-       gsub(/__/,"€",rh)\r
-       gsub(/_[^_]+_/,"±&±",rh)\r
-       gsub(/±_/,"[u]",rh)\r
-       gsub(/_±/,"[/u]",rh)\r
-       gsub(/€/,"_",rh)\r
-       \r
-       gsub(/\$\$/,"€",rh)\r
-       gsub(/\$[^\$]+\$/,"±&±",rh)\r
-       gsub(/±\$/,"[size=80]",rh)\r
-       gsub(/\$±/,"[/size]",rh)\r
-       gsub(/€/,"$",rh)\r
-       \r
-       return rh  " -- [url=http://1190.bicyclesonthemoon.info/ongtext?b=on][b]ong[/b]o[/url][url=http://mrob.com/time/automome/]mome[/url]"\r
-}\r
+#// bot4.awk
+#// The bot to post frames to the OTT
+#// 24.04.2021
+#// 
+#// Copyright (C) 2015, 2018-2019, 2021  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
+#// published by the Free Software Foundation, either version 3 of the
+#// License, or (at your option) any later version.
+#// 
+#// This program is distributed in the hope that it will be useful,
+#// but WITHOUT ANY WARRANTY; without even the implied warranty of
+#// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#// GNU Affero General Public License for more details.
+#// 
+#// You should have received a copy of the GNU Affero General Public License
+#// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+BEGIN{
+       FS=""
+       # noticepath="/eizm/mem/aftertime/mpost/"
+       # framepath="/eizm/www/time/"
+       datapath="/eizm/data/aftertime/"
+       timecmd="date"
+       timecmd2="date -u +%N%s"
+       lastpath ="/eizm/mem/aftertime/lastong/"
+       temppath ="/eizm/tmp/aftertime/"
+       ott_address="http://forums.xkcd.com/viewtopic.php?f=7&t=101043&start="
+       tto_address="http://1190.bicyclesonthemoon.info/ott/view?start="
+       mstd_address="http://1190.bicyclesonthemoon.info/ott/mview?start="
+       lastpost_address="http://forums.xkcd.com/viewtopic.php?f=7&t=101043&sd=d"
+       
+       wget="/usr/bin/wget"
+       rm="/bin/rm"
+       perl="/usr/bin/perl"
+       mawk="/usr/bin/mawk"
+       automome="/eizm/pro/ong1/mome.pl"
+       memedef="/eizm/mem/ong1/mome.txt"
+       
+       postawk="/eizm/pro/aftertime/post.awk"
+       mpostawk="/eizm/pro/aftertime/mpost.awk"
+       
+       # timecmd2="date +\"%H%M%S\""
+       botcastleurl="http://1190.bicyclesonthemoon.info"
+       
+       if(enhance!="" && int(enhance)!="0")
+       {
+               enh=int(enhance)
+               ext="-"enh
+       }
+       else
+       {
+               ext=""
+               enh=0
+       }
+       
+       f=int(frame)
+       timecmd | getline thistime
+       close(timecmd)
+       
+       timecmd2 | getline ID
+       close(timecmd2)
+       ID=int(ID/3600)
+       ID =int(ID%9999)
+       
+       for(i=0;i<256;++i)
+       {
+               ch=sprintf("%c",i)
+               hex=sprintf("%02X",i);
+               ch2hex[ch]=hex
+       }
+       
+       statefile= datapath story"/ongstate"
+       getline temp < statefile
+       close(statefile)
+       
+       split(temp, temptab, " ")
+       state=int(temptab[1])
+       last=int(temptab[2])
+       
+       if(frame=="")
+               f=last
+       
+       # srand(ID + f)
+       # for(i=0;i<f;++i)
+       # {
+               # r=rand()
+               # # print r
+       # }
+       lastalt=0
+}
+{
+       # exit
+       file=1
+       gsub(/[\r\n]/, "", $0)
+       eq=index($0, "=")
+       if($0 ~ /^[0-9]+=/)
+       {
+               i=int(substr($0, 1, eq-1))
+               if(f>=i && i>=lastalt)
+               {
+                       alt=substr($0, eq+1)
+                       lastalt=i
+               }
+       }
+       argtab[substr($0, 1, eq-1)]=substr($0, eq+1)
+}
+END{
+       # exit
+       
+       ongbot= (please!=""?((argtab["pleaseongbot"]!="")?argtab["pleaseongbot"]:"pleaseongbot"):((argtab["ongbot"]!="")?argtab["ongbot"]:"ongbot"))
+       
+       print thistime" "ongbot
+       
+       tempfile = temppath "ongbot-"argtab["story"]"-"ID
+       tempfile_t= tempfile"-t"
+       tempfile_c= tempfile"-c"
+       tempfile_p= tempfile"-p"
+       
+       if (file=="")
+       {
+               print "Can't open story settings file."
+               exit 1
+       }
+       if(argtab["ongoing"]=="")
+       {
+               print "Story not ONGoing."
+               exit 1
+       }
+       
+       
+       
+       if(state<2 && force=="" && f==last)
+       {
+               print "Wrong state."
+               exit 1
+       }
+       
+       if(argtab["special"] != "")
+       {
+               specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,"")
+               line=""
+               undertext=""
+               
+               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)
+                       }
+               }
+               close (specialfile)
+       }
+       
+       
+       botfile=datapath argtab["story"]"/"ongbot
+       getline botname  < botfile
+       getline username < botfile
+       getline password < botfile
+       gsub(/[\r\n]/, "", botname)
+       gsub(/[\r\n]/, "", username)
+       gsub(/[\r\n]/, "", password)
+       close(botfile)
+       
+       if (botname =="" || username=="" || password=="")
+       {
+               print "Can't get login and password."
+               exit 1
+       }
+       print botname
+       
+       useragent = "\""botname" (time after Time post bot; http://1190.bicyclesonthemoon.info/aftertime; story="argtab["story"]"; frame "f")\""
+       
+       temp=""
+       lasttime = lastpath argtab["story"] ext
+       getline temp < lasttime
+       close(lasttime)
+       
+       split(temp, temptab, " ")
+       lastpage=int(temptab[1])
+       lastframe=int(temptab[2])
+       
+       print "Start with page "lastpage", last frame was "lastframe", current frame is "f"."
+       if(f <= lastframe && force=="")
+       {
+               print "Already ONGed."
+               exit 1
+       }
+       
+       if(force=="")
+       {
+               temp=argtab["match"ext]
+               for(i=0;(j=index(substr(temp,2),"%"))!=0;++i)
+               {
+                       temp2=substr(temp,1,j)
+                       temp=substr(temp,j+1)
+                       regexp = regexp sprintf(temp2,f)
+               }
+               regexp = regexp sprintf(temp,f)
+               print "match "regexp
+               
+               for(page=lastpage;page<=lastpage;++page)
+               {
+                       url= "\""ott_address (page-1)*40"\""
+                       url2= "\""tto_address (page-1)*40"\""
+                       
+                       cmd= wget " -q -O "tempfile" -U "useragent" "url
+                       cmd2= wget " -q -O "tempfile" -U "useragent" "url2
+                       # print "! "cmd" !"
+                       if(system(cmd)!=0)
+                       {
+                               print "Newpage "page" download fail. Retry from mirror."
+                               if(system(cmd2)!=0)
+                               {
+                                       print "Newpage "page" download fail."
+                                       system(rm" -f "tempfile)
+                                       exit 1
+                               }
+                       }
+                       while((getline temp < tempfile)>0)
+                       {
+                               if(temp ~ regexp)
+                               {
+                                       print "Newpage "page" - already ONGed."
+                                       system(rm" -f "tempfile)
+                                       print page" "f > lasttime
+                                       close(lasttime)
+                                       exit 1
+                               }
+                               gsub(/<[^<>]*>/,"",temp)
+                               gsub(/ +/," ",temp)
+                               temp2=tolower(temp)
+                               if((i=match(temp2,/page [0-9]+ of [0-9]+/))!=0)
+                               {
+                                       temp2=substr(temp2,i)
+                                       temp2=substr(temp2,index(temp2,"of")+3)" "
+                                       temp2=substr(temp2,1,index(temp2," ")-1)
+                                       lastpage=int(temp2)
+                               }
+                               temp2=tolower(temp)
+                               if((i=match(temp2,/[0-9]+ posts/))!=0)
+                               {
+                                       temp2=substr(temp2,index(temp2,"")-1)
+                                       posts=int(temp2)
+                                       if(posts%40==0)
+                                               pope=1
+                                       else
+                                               pope=""
+                               }
+                       }
+                       close(tempfile)
+                       print "Newpage "page" - nothing found."
+               }
+               mlastpage=1
+               for(mpage=1;mpage<=mlastpage;++mpage)
+               {
+                       url= "\""mstd_address (mpage-1)*40"\""
+                       
+                       cmd= wget " -q -O "tempfile" -U "useragent" "url
+                       if(system(cmd)!=0)
+                       {
+                               print "Mustardtime newpage "mpage" not downloaded."
+                               break
+                       }
+                       for(j=0;(getline temp < tempfile)>0;++j)
+                       {
+                               if(temp ~ regexp)
+                               {
+                                       print "Newpage "mpage" - already ONGed."
+                                       system(rm" -f "tempfile)
+                                       print page" "f > lasttime
+                                       close(lasttime)
+                                       
+                                       exit 1
+                               }
+                               gsub(/<[^<>]*>/,"",temp)
+                               gsub(/ +/," ",temp)
+                               temp2=tolower(temp)
+                               if((i=match(temp2,/page [0-9]+ of [0-9]+/))!=0)
+                               {
+                                       temp2=substr(temp2,i)
+                                       temp2=substr(temp2,index(temp2,"of")+3)
+                                       temp2=substr(temp2,1,index(temp2," ")-1)
+                                       mlastpage=int(temp2)
+                               }
+                               temp2=tolower(temp)
+                               if((i=match(temp2,/[0-9]+ posts/))!=0)
+                               {
+                                       temp2=substr(temp2,index(temp2,"")-1)
+                                       posts=int(temp2)
+                                       if(posts%40==0)
+                                               pope=1
+                                       else
+                                               pope=""
+                               }
+                       }
+                       close(tempfile)
+                       print "Mustradtime newpage "mpage" - nothing found."
+               }
+       }
+       
+       if(argtab["nomeme"]=="")
+       {
+               print "Ok, can ONG. Now generate ONGtext"
+               cmd = perl" "automome" -lc 150 -n 67 -d "memedef (pope!=""?" -t \"[decrall]\"":"")
+               while ((cmd | getline temp)>0)
+               {
+                       if(sub(/[AEIOUY]-N-G/,"[b]O-N-G[/b]",temp)>0)
+                       {
+                               ongtext= prepare(temp)
+                               break
+                       }
+                       if(sub(/O+N+G+/,"[b]&[/b]",temp)>0)
+                       {
+                               ongtext= prepare(temp)
+                               break
+                       }
+                       if(sub(/DON'T/,"D[b]ON'G[/b]T",temp)>0)
+                       {
+                               ongtext= prepare(temp)
+                               break
+                       }
+                       if(sub(/[AEIOUY]NG/,"[b]ONG[/b]",temp)>0)
+                       {
+                               if($0!~/TH\[b\]ONG/)
+                               {
+                                       ongtext= prepare(temp)
+                                       break
+                               }
+                       }
+                       if(sub(/ON G/,"[b]ON G[/b] ",temp)>0)
+                       {
+                               ongtext= prepare(temp)
+                               break
+                       }
+                       if(sub(/ON /,"[b]ONG[/b] ",temp)>0)
+                       {
+                               ongtext= prepare(temp)
+                               break
+                       }
+                       if(sub(/O\.?$/,"[b]ONG[/b] ",temp)>0)
+                       {
+                               ongtext= prepare(temp)
+                               break
+                       }
+               }
+               close(cmd)
+               
+               if(ongtext=="")
+                       ongtext="ONG"
+               print ongtext
+       }
+       else
+               ongtext="ONG"
+       
+       cmd= wget " -q -O "tempfile" -U "useragent" \""lastpost_address"\""
+       if(system(cmd)!=0)
+       {
+               print "Can't check last post"
+               # system(rm" -f "tempfile)
+               # exit 1
+       }
+       
+       else
+       {
+               while((getline temp < tempfile)>0)
+               {
+                       if ((i=match(temp, /id=\"p[0-9]+\"/))!=0) #"
+                       {
+                               temp2=substr(temp, i+5)
+                               lastpostid=substr(temp2, 1, index(temp2,"\"")-1)
+                       }
+                       
+                       if (temp ~ /class=\"postprofile\"/) #"
+                               postprofile = "1"
+               
+                       else if (postprofile=="")
+                               continue
+               
+                       if(temp ~ /memberlist\.php.*mode=viewprofile[^<>]*>[^<>]+<\/a/)
+                       {
+                               temp2=substr(temp, index(temp, ">")+1)
+                               lastusername=substr(temp2, 1, index(temp2,"<")-1)
+                               break
+                       }
+               }
+               close(tempfile)
+               if(lastusername=="" || lastpostid=="")
+               {
+                       print "Can't check last post"
+                       # system(rm" -f "tempfile)
+                       # exit 1
+               }
+       }
+       
+       srand(ID+lastpostid+f)
+
+       if(rand()<(argtab["npbprob"]+0))
+       {
+               print "Also, let's do some NewpixbOTTification!"
+               npbsel="npbframe"ext
+       }
+       else
+               npbsel="frame"ext
+
+       
+       
+       framedir= (argtab["framedir"]!="" ? argtab["framedir"] : "/aftertime/"argtab["story"]"/")
+       
+       print "username="urlencode(username) > tempfile
+       print "password="urlencode(password,1) >> tempfile
+       print "subject="urlencode(sprintf(argtab["subject"ext],f,"")) >> tempfile
+       print "message="urlencode(ongtext"\n[url="botcastleurl"/aftertime/viewer?story="argtab["story"]"&f="f((enh>0)?"&e="enh:"")"][img]"botcastleurl framedir sprintf(argtab[npbsel],f,"")"[/img][/url]"((argtab["text"]!="")?("\n"argtab["text"]):"")"[spoiler]"alt"[/spoiler]\n[right][size=80] -- posted by "botname"[/size][/right]") >> tempfile
+       print "Send post"
+       
+       cmd= mawk" -f "postawk" -v postfile="tempfile_p" -v cookiefile="tempfile_c" -v tempfile="tempfile_t((lastpostid!="" && lastusername!="")?" -v edit="lastpostid" -v user=\""lastusername"\"":"")" "tempfile
+       cmd2= mawk" -f "mpostawk" -v postfile="tempfile_p" -v cookiefile="tempfile_c" -v tempfile="tempfile_t" "tempfile
+       
+       if(system(cmd)!=0)
+       {
+               print "Can't post, try again from mirror"
+               if(system(cmd2)!=0)
+               {
+                       print "CAN'T POST EITHER!"
+                       system(rm" -f "tempfile)
+                       system(rm" -f "tempfile_t)
+                       system(rm" -f "tempfile_c)
+                       system(rm" -f "tempfile_p)
+                       exit 1
+               }
+       }
+       print "ONGed"
+       system(rm" -f "tempfile)
+       system(rm" -f "tempfile_t)
+       system(rm" -f "tempfile_c)
+       system(rm" -f "tempfile_p)
+       if(force=="")
+       {
+               print lastpage" "f > lasttime
+               close(lasttime)
+       }
+       
+       
+}
+function urlencode(name, all,  len,iii,escaped,ch)
+{
+       len=length(name)
+       escaped=""
+       for(iii=1;iii<=len;++iii)
+       {
+               ch=substr(name,iii,1);
+               if (ch ~ /[a-z]|[A-Z]|[0-9]/ && all=="")
+                       escaped = escaped ch
+               else
+                       escaped = escaped "%" ch2hex[ch]
+       }
+       return escaped
+};
+function prepare(rh)
+{
+       gsub(/\*\*/,"€",rh)
+       gsub(/\*[^\*]+\*/,"±&±",rh)
+       gsub(/±\*/,"[i]",rh)
+       gsub(/\*±/,"[/i]",rh)
+       gsub(/€/,"*",rh)
+       
+       gsub(/__/,"€",rh)
+       gsub(/_[^_]+_/,"±&±",rh)
+       gsub(/±_/,"[u]",rh)
+       gsub(/_±/,"[/u]",rh)
+       gsub(/€/,"_",rh)
+       
+       gsub(/\$\$/,"€",rh)
+       gsub(/\$[^\$]+\$/,"±&±",rh)
+       gsub(/±\$/,"[size=80]",rh)
+       gsub(/\$±/,"[/size]",rh)
+       gsub(/€/,"$",rh)
+       
+       return rh  " -- [url=http://1190.bicyclesonthemoon.info/ongtext?b=on][b]ong[/b]o[/url][url=http://mrob.com/time/automome/]mome[/url]"
+}
diff --git a/compare-t-1.awk b/compare-t-1.awk
new file mode 100644 (file)
index 0000000..2aab0e9
--- /dev/null
@@ -0,0 +1,33 @@
+BEGIN{
+       # for(i=1; i<=828; ++i)
+       # {
+               # f=sprintf("%04d",i)
+               # cmpcmd="/eizm/pro/aftertime/compare /eizm/www/time/aftertime/t-1/t-1_"f".png /eizm/data/aftertime/testaftertime/t-1/t-1_"f".png"
+               
+               # printf("%s","t-1_"f".png ")
+               
+               # # print cmpcmd
+               # system (cmpcmd)
+       # }
+       for(i=1; i<=828; ++i)
+       {
+               f=sprintf("%04d",i)
+               cmpcmd="/eizm/pro/aftertime/compare /eizm/www/time/aftertime/t-1/remapt-1_"f".png /eizm/data/aftertime/testaftertime/t-1/remapt-1_"f".png"
+               cpcmd="/bin/cp /eizm/data/aftertime/testaftertime/t-1/remapt-1_"f".png /eizm/www/time/aftertime/t-1/mustardremapt-1_"f".png"
+               
+               printf("%s","remapt-1_"f".png ")
+               
+               # print cmpcmd
+               # system (cmpcmd)
+               
+               cmpcmd | getline line
+               close(cmpcmd)
+               print line
+               if (line!="identical.")
+               {
+                       system(cpcmd)
+                       print "upload "f"."
+               }
+       }
+       
+}
diff --git a/convert1.awk b/convert1.awk
new file mode 100644 (file)
index 0000000..b9b4bf6
--- /dev/null
@@ -0,0 +1,16 @@
+BEGIN{\r
+       print "SilentTimer\n5TkxDBIL21OyEGwkdTR2EQYwdYC5F4\n"\r
+}\r
+{\r
+       y=substr($1, 1, 4)\r
+       m=substr($1, 5, 2)\r
+       d=substr($1, 7, 2)\r
+       h=substr($1, 9, 2)\r
+       \r
+       if($NF !~ /^t1i-[0-9]+$/)\r
+               next\r
+       \r
+       id= $NF "-1"\r
+       \r
+       print y"-"m"-"d" "h"\nq\n"\r
+}
\ No newline at end of file
diff --git a/convert2.awk b/convert2.awk
new file mode 100644 (file)
index 0000000..2bf3c69
--- /dev/null
@@ -0,0 +1,47 @@
+BEGIN{\r
+       FS=""\r
+       print "SilentTimer\n5TkxDBIL21OyEGwkdTR2EQYwdYC5F4\n"\r
+       i=0\r
+}\r
+{\r
+       ind=index($0, " ")\r
+       id=substr($0, 1, ind-1)\r
+       value=substr($0, ind+1)\r
+       ind=index(value," ")\r
+       name=substr(value, 1, ind-1)\r
+       value=substr(value, ind+1)\r
+       \r
+       if (tab[id]=="")\r
+       {\r
+               list[i]=id\r
+               tab[id]=id\r
+               ++i\r
+       }\r
+       tab[id"-"name]=value\r
+}\r
+END{\r
+       for(j=0;j<i;++j)\r
+       {\r
+               timenumber=list[j]\r
+               time=substr(timenumber,1,4)"-"substr(timenumber,5,2)"-"substr(timenumber,7,2)" "substr(timenumber,9,2)":00"\r
+               id=substr(tab[timenumber"-subject"],index(tab[timenumber"-subject"],"t1i-"))\r
+               \r
+               for(k=1; idtab[id"-"k]!=""; ++k)\r
+               {\r
+               }\r
+               fullid=id"-"k\r
+               idtab[fullid]=k;\r
+               \r
+               options=tab[timenumber"-options"]\r
+               subject="Did you notice â€Š"\r
+               content=tab[timenumber"-content"]\r
+               notice=substr(content,index(content,"[br]
")+4)\r
+               \r
+               print fullid\r
+               print options\r
+               print time\r
+               print subject\r
+               print notice\r
+               print ""\r
+       }\r
+}\r
index 257e7e4823ab1e74c9bc9cf97682a91bf0abc2a3..ab3d2273806df114fa476ac2b8aec2c6609d2d33 100644 (file)
--- a/frame.awk
+++ b/frame.awk
@@ -1,6 +1,6 @@
 #// frame.awk\r
 #// Dynamic frame for the viewer\r
-#//  7.01.2019\r
+#// 10.03.2019\r
 #// \r
 #// Copyright (C) 2015, 2018-2019  Balthasar SzczepaƄski\r
 #// \r
@@ -67,7 +67,9 @@ END{
        if (file=="")\r
                exit 1\r
        \r
-       if(this_sf=="")\r
+       if (sf=="")\r
+               s=""\r
+       else if(this_sf=="")\r
                s=""\r
        else if(s>this_sf && argtab["cfrt"]=="")\r
                s=this_sf\r
@@ -116,7 +118,7 @@ END{
        \r
        if(argtab["special"] != "")\r
        {\r
-               specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f)\r
+               specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,s)\r
                line=""\r
                undertext=""\r
                \r
@@ -146,19 +148,19 @@ END{
        }\r
        \r
        framedir= (argtab["framedir"]!="" ? argtab["framedir"] : "/aftertime/"argtab["story"]"/")\r
-       if(sf!="")\r
-       {\r
+       if(sf!="")\r
+       {\r
                frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f,s)\r
                if (system("[ -f " framepath frame" ]")!=0)\r
                        frame= framedir sprintf(argtab["frame"],f,s)\r
-       }\r
-       else\r
-       {\r
-               s=""\r
-               frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f)\r
-               if (system("[ -f " framepath frame" ]")!=0)\r
-                       frame=framedir sprintf(argtab["frame"],f)\r
-       }\r
+       }\r
+       else\r
+       {\r
+               s=""\r
+               frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f)\r
+               if (system("[ -f " framepath frame" ]")!=0)\r
+                       frame=framedir sprintf(argtab["frame"],f)\r
+       }\r
        \r
        if(f==last && state==1)\r
        {\r
index 47bd110a1068dbf6b7cbb74d80c1d3a0481a2854..949a124a15850506fcbca961ba9613f78de9fcb3 100644 (file)
--- a/info.awk
+++ b/info.awk
@@ -1,6 +1,6 @@
 #// info.awk
 #// Info about an aftertime story.
-#//  7.01.2019
+#// 10.03.2019
 #// 
 #// Copyright (C) 2015-2016, 2018-2019  Balthasar SzczepaƄski
 #// 
@@ -239,7 +239,7 @@ END{
                
                if(argtab["special"] != "")
                {
-                       specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f)
+                       specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,s)
                        line=""
                        undertext=""
                        
@@ -302,26 +302,26 @@ END{
                        numberformat=argtab["number"]
                else
                {
-                       if (sf!="")
+                       if (sf!="")
                                numberformat="%u%s"
-                       else
-                               numberformat="%u"
+                       else
+                               numberformat="%u"
                }
                
                framedir= "/aftertime/"argtab["story"]"/"
-               if(sf!="")
-               {
+               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"]))
-               }
+               }
+               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
@@ -342,10 +342,10 @@ END{
                {
                        for(i=0;i<=max_enhance;++i)
                        {
-                               if(sf!="")
+                               if(sf!="")
                                        enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f,s)
-                               else
-                                       enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f)
+                               else
+                                       enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f)
                                
                                if (system("[ -f " framepath enhancedframe" ]")==0)
                                        print "enhance-"i"="argtab["enhance-"i]
index b1fbfd68012d35999b702d3db4496017917719bf..0f3f01310976856fb893263897e8b91c8a656941 100644 (file)
--- a/mpview.c
+++ b/mpview.c
@@ -59,7 +59,7 @@ int main()
        sprintf(key,"key=%s",arg?arg:"???");\r
        \r
        // sprintf(filename,"%s",line);\r
-       sprintf(postpath,"%s%s",POST_PATH,line);\r
+       sprintf(postpath,"%s%s",POST_PATH,line);//UNSAFE! (2019)\r
 \r
        \r
        sprintf(path2,"%s%lu",TEMP_PATH,(unsigned long)getpid());\r
index 179f41ba1c5657c211c21e740aaf1d20581ab54e..487d0498916c399d457d226c8ce0bce461464263 100644 (file)
@@ -1,6 +1,6 @@
 #// ong-bsta.awk
 #// The bot to ketchup frames from the bsta viewer
-#//  6.01.2019
+#//  6.09.2019
 #// 
 #// Copyright (C) 2019  Balthasar SzczepaƄski
 #// 
@@ -333,8 +333,8 @@ function bb2bb (text)
        gsub(/\[(fq|tq)\]/, "[quote]", text)
        gsub(/\[\/(fq|tq)\]/, "[/quote]", text)
        gsub(/\[br\]/, "[color=#BB6622]", text)
-       gsub(/\[ni\]/, "[color=#FF8800]", text)
-       gsub(/\[po\]/, "[color=#0057AF]", text)
+       gsub(/\[ni\]/, "[color=#0057AF]", text)
+       gsub(/\[po\]/, "[color=#FF8800]", text)
        gsub(/\[\/(br|ni|po)\]/, "[/color]", text)
        
        return htmlescape(text,"","br")
index b8d13185d67ca19d3122ddbb79226ccb64a9c141..7f03aa3b17bed2929791080d9905655c801a8f90 100644 (file)
@@ -1,8 +1,8 @@
 #// ong-mscha-t-1.awk\r
 #// The bot to ketchup frames from the mschaviewer, and enhance by remapping\r
-#// 21.12.2015\r
+#// 12.02.2019\r
 #// \r
-#// Copyright (C) 2015  Balthasar SzczepaƄski\r
+#// Copyright (C) 2015, 2019  Balthasar SzczepaƄski\r
 #// \r
 #// This program is free software: you can redistribute it and/or modify\r
 #// it under the terms of the GNU Affero General Public License as\r
@@ -44,10 +44,16 @@ BEGIN{
 END{\r
        \r
        if (file=="")\r
+       {\r
+               print "No data."\r
                exit 1\r
+       }\r
        \r
        if(argtab["ongoing"]!="2")\r
+       {\r
+               print "Story is not externally onged."\r
                exit 1\r
+       }\r
        \r
        # timecmd | getline thistime\r
                # close(timecmd)\r
@@ -71,15 +77,19 @@ END{
        optionfile = datapath argtab["story"]"/settings"\r
        framedir = "aftertime/"argtab["story"]"/"\r
        \r
-       system("sleep 15")\r
+       system("sleep 15")\r
        while(1)\r
        {\r
+               \r
+               \r
                timecmd | getline thistime\r
                close(timecmd)\r
                \r
                timetext = substr(thistime,1,10);\r
                timenumber = substr(thistime,11);\r
                \r
+               print f" "timetext" "timenumber\r
+               \r
                newalt=""\r
                frameurl= sprintf(argtab["otherviewerframe"],f)\r
                viewerurl= sprintf(argtab["otherviewerurl"],f)\r
@@ -99,11 +109,17 @@ END{
                addhashcmd= mawk" -f "uploadawk" -v timenumber="timenumber" -v timetext="timetext" -v tempfile="tempfile" "tempfile2\r
                \r
                if(system(getfcmd)!=0)\r
+               {\r
+                       print "Frame download failed: "getfcmd\r
                        break\r
-               system("sleep 5")\r
+               }\r
+               system("sleep 2")\r
                \r
                if(system(getvcmd)!=0)\r
+               {\r
+                       print "Viewer download failed: "getvcmd\r
                        break\r
+               }\r
                system("sleep 1")\r
                \r
                foundalt=""\r
@@ -115,12 +131,14 @@ END{
                                newalt=substr(temp,index(temp,"title=\"")+7)\r
                                newalt=substr(newalt,1,index(newalt,"\"")-1)\r
                                foundalt=1\r
+                               print "alt: "newalt\r
                        }\r
                        if(index(temp,"class=\"hash\"")!=0 && foundpal=="" )\r
                        {\r
                                pal=substr(temp,index(temp,">")+1)\r
                                pal=substr(pal,1,index(pal,".")-1)\r
                                foundpal=1\r
+                               print "pal: "pal\r
                        }\r
                        if(foundalt!="" && foundpal!="")\r
                                break;\r
diff --git a/ong.awk b/ong.awk
index 9da5f24cf4f944c198d2912c59207f52261c0d8d..f6dc1abf5397944a343545c041f56bc525b6d261 100644 (file)
--- a/ong.awk
+++ b/ong.awk
@@ -1,8 +1,8 @@
 #// ong.awk\r
 #// The bot to ONG new frames to the viewer.\r
-#// 05.01.2019\r
+#// 28.08.2020\r
 #// \r
-#// Copyright (C) 2015, 2018-2019  Balthasar SzczepaƄski\r
+#// Copyright (C) 2015, 2018-2020  Balthasar SzczepaƄski\r
 #// \r
 #// This program is free software: you can redistribute it and/or modify\r
 #// it under the terms of the GNU Affero General Public License as\r
@@ -31,6 +31,7 @@ BEGIN{
        mawk="/usr/bin/mawk"\r
        bot4awk="/eizm/pro/aftertime/bot4.awk"\r
        chmod="/bin/chmod"\r
+       npb="/eizm/pro/ong1/npb"\r
        \r
        timecmd2 | getline thistime2\r
                close(timecmd2)\r
@@ -40,6 +41,15 @@ BEGIN{
                # close(timecmd)\r
                \r
        thistime3 -= thistime3%3600\r
+       \r
+       for(i=0;i<256;++i)\r
+       {\r
+               ch=sprintf("%c",i)\r
+               hex=sprintf("%02X",i)\r
+               dec=sprintf("%u",i)\r
+               ch2hex[ch]=hex\r
+               ch2dec[ch]=dec\r
+       }\r
 }\r
 {\r
        file=1\r
@@ -84,24 +94,51 @@ END{
        last=int(temptab[2])\r
        nextong=int(temptab[3])\r
        ongfailcount=int(temptab[4])\r
+       enhance=int(argtab["enhance"])\r
+       \r
+       specialtab[0]=""\r
+       effectivetab[0]=""\r
        \r
        # temp=""\r
        # updatefile= datapath argtab["story"]"/update"\r
        # getline temp < updatefile\r
        # close(updatefile)\r
        \r
+       timefile= datapath argtab["story"]"/ongtime"\r
+       \r
        if (state == 1 || state ==2)\r
        {\r
                updatefail=""\r
                temp=""\r
                updatefile= datapath argtab["story"]"/update"\r
+               # timefile= datapath argtab["story"]"/ongtime"\r
+               \r
+               updated=""\r
                \r
                while((getline temp < updatefile)>0)\r
                {\r
-                       if (temp !~ /^([0-9]+)|(c)$/)\r
+                       if (temp !~ /^([0-9]+[a-z]?)|(c)$/)\r
                                continue\r
                        \r
-                       i = int(temp)\r
+                       if(timeread=="")\r
+                       {\r
+                               while((getline line < timefile)>0)\r
+                               {\r
+                                       ongind=index(line," ")\r
+                                       ongft=substr(line,1,ongind-1)\r
+                                       ongt=substr(line,ongind+1)\r
+                                       \r
+                                       if(ongft ~ /^[0-9]+[a-z]$/)\r
+                                               ongf=int(substr(ongft,1,ongind-2)) substr(ongft,ongind-1,1)\r
+                                       else\r
+                                               ongf=int(ongft)\r
+                                       \r
+                                       timetab[ongft]=ongt\r
+                               }\r
+                               close(timefile)\r
+                               timeread=1\r
+                       }\r
+                       \r
                        if(temp=="c")\r
                        {\r
                                print "Update CFRT."\r
@@ -110,141 +147,132 @@ END{
                                        print "There is no cfrt frame."\r
                                        continue\r
                                }\r
-                               inframe= datapath argtab["story"]"/"argtab["cfrt"]\r
+                               inframe[0]= datapath argtab["story"]"/"argtab["cfrt"]\r
                                \r
-                               frame= framepath framedir argtab["cfrt"]\r
+                               frame[0]= framepath framedir argtab["cfrt"]\r
                                \r
-                               cpcmd = cp" "inframe" "frame\r
-                               chmodcmd = chmod" +r "frame\r
+                               cpcmd[0] = cp" "inframe[0]" "frame[0]\r
+                               chmodcmd[0] = chmod" +r "frame[0]\r
                        }\r
                        else\r
                        {\r
-                               print "Update frame "i"."\r
+                               if (temp ~ /[a-z]$/)\r
+                               {\r
+                                       i=int(substr(temp,1,length(temp)-1))\r
+                                       j=substr(temp, length(temp))\r
+                               }\r
+                               else\r
+                               {\r
+                                       i = int(temp)\r
+                                       j = ""\r
+                               }\r
+                               \r
+                               print "Update frame "i j"."\r
+                               \r
+                               if(argtab["special"] != "")\r
+                               {\r
+                                       specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],i,j)\r
+                                       readspecialfile(specialfile,argtab,specialtab,effectivetab)\r
+                               }\r
+                               else\r
+                               {\r
+                                       readspecialfile("",argtab,specialtab,effectivetab)\r
+                               }\r
                                if ((i < int(argtab["first"]))||(i > last)) \r
                                {\r
-                                       print (i" not onged yet.")\r
+                                       print (i j" not onged yet.")\r
                                        continue\r
                                }\r
-                               inframe= datapath argtab["story"]"/"sprintf(argtab["inframe"],i)\r
                                \r
-                               frame= framepath framedir sprintf(argtab["frame"],i)\r
-                               npbframe= framepath framedir sprintf(argtab["npbframe"],i)\r
-                               \r
-                               npbcmd= sprintf("/eizm/pro/ong1/npb %s %s q",inframe,npbframe)\r
-                               cpcmd = cp" "inframe" "frame\r
-                               chmodcmd = chmod" +r "frame\r
+                               if(j!="")\r
+                               {\r
+                                       if(argtab["sf-"i]=="")\r
+                                       {\r
+                                               print (i" doesn't have meteor frames.")\r
+                                               continue\r
+                                       }\r
+                                       else if(j > argtab["sf-"i])\r
+                                       {\r
+                                               print (j" is not a meteor frame of "i".")\r
+                                               continue\r
+                                       }\r
+                                       \r
+                               }\r
+                               for (k=0; k<=enhance; ++k)\r
+                               {\r
+                                       k2=(k>0)?("-"k):""\r
+                                       inframe[k]= datapath argtab["story"]"/"sprintf(effectivetab["inframe"k2],i,j)\r
+                                       \r
+                                       frame[k]= framepath framedir sprintf(effectivetab["frame"k2],i,j)\r
+                                       npbframe[k]= framepath framedir sprintf(effectivetab["npbframe"k2],i,j)\r
+                                       \r
+                                       npbcmd[k]= npb" "inframe[k]" "npbframe[k]" q"\r
+                                       cpcmd[k] = cp" "inframe[k]" "frame[k]\r
+                                       chmodcmd[k] = chmod" +r "frame[k]\r
+                               }\r
+                               if (specialtab["text"]!="")\r
+                               {\r
+                                       specialtab["HTML"]=bb2html(specialtab["text"])\r
+                                       writespecialfile(specialfile,specialtab)\r
+                                       # print debug\r
+                               }\r
+                       }\r
+                       \r
+                       if(temp!="c" && timetab[sprintf("%04u%s",i,j)]=="")\r
+                       {\r
+                               print sprintf("%04u%s",i,j)" "thistime2 >> timefile\r
+                               close(timefile)\r
+                               timetab[sprintf("%04u%s",i,j)]=thistime2\r
                        }\r
-                       if((argtab["npbframe"]!="") && (temp!="c"))\r
+                       \r
+                       for(k=0; k<=enhance; ++k)\r
                        {\r
-                               if(system(npbcmd)!=0)\r
+                               k2=(k>0)?("-"k):""\r
+                               \r
+                               if ((system("[ -f " inframe[k]" ]")!=0)&&(k>0))\r
+                                       continue\r
+                               \r
+                               if((argtab["npbframe"]!="") && (temp!="c"))\r
                                {\r
-                                       print i" NewpixbOTTification failed."\r
+                                       if(system(npbcmd[k])!=0)\r
+                                       {\r
+                                               print i j k2" NewpixbOTTification failed."\r
+                                               updatefail=1\r
+                                               break\r
+                                       }\r
+                               }\r
+                               if(system(cpcmd[k])!=0)\r
+                               {\r
+                                       print i j k2" Upload failed."\r
                                        updatefail=1\r
-                                       continue\r
+                                       break\r
+                               }\r
+                               if(system(chmodcmd[k])!=0)\r
+                               {\r
+                                       print "Chmod failed."\r
+                                       updatefail=1\r
+                                       break\r
+                               }\r
+                               if(temp=="c")\r
+                               {\r
+                                       break\r
                                }\r
                        }\r
-                       if(system(cpcmd)!=0)\r
-                       {\r
-                               print "Upload failed."\r
-                               updatefail=1\r
-                               continue\r
-                       }\r
-                       if(system(chmodcmd)!=0)\r
+                       if (updatefail)\r
                        {\r
-                               print "Chmod failed."\r
-                               updatefail=1\r
-                               continue\r
+                               break #come up with other aproach\r
                        }\r
+                       updated=1\r
                        print "Updated."\r
                }\r
                close(updatefile)\r
-               if (!updatefail)\r
+               if (!updatefail && updated)\r
                {\r
                        print "" > updatefile\r
                        close(updatefile)\r
                }\r
        }\r
        \r
-       # # temp ="remove this line!"\r
-       # if (temp != "")\r
-       # {\r
-               # print "Update requested."\r
-               # updatefail=""\r
-               \r
-               # if(state>2 || state <1)\r
-               # {\r
-                       # print "Can't update in this state"\r
-               # }\r
-               # else \r
-               # {\r
-                       # for(i=int(argtab["first"]);i<=last;++i)\r
-                       # {\r
-                               # if (i==int(argtab["first"])  && argtab["cfrt"]!="")\r
-                               # {\r
-                                       # inframe= datapath argtab["story"]"/"argtab["cfrt"]\r
-                                       # frame= framepath framedir argtab["cfrt"]\r
-                                       # cpcmd = cp" "inframe" "frame\r
-                                       # chmodcmd = chmod" +r "frame\r
-                                       \r
-                                       # # print cpcmd\r
-                                       # if(system(cpcmd)!=0)\r
-                                       # {\r
-                                               # print "CFRT upload failed."\r
-                                               # updatefail=1\r
-                                               # break\r
-                                       # }\r
-                                       # # print chmodcmd\r
-                                       # if(system(chmodcmd)!=0)\r
-                                       # {\r
-                                               # print "CFRT chmod failed."\r
-                                               # updatefail=1\r
-                                               # break\r
-                                       # }\r
-                                       # print "CFRT updated."\r
-                               # }\r
-                               \r
-                               # inframe= datapath argtab["story"]"/"sprintf(argtab["inframe"],i)\r
-                               \r
-                               # frame= framepath framedir sprintf(argtab["frame"],i)\r
-                               # npbframe= framepath framedir sprintf(argtab["npbframe"],i)\r
-                               \r
-                               # npbcmd= sprintf("/eizm/pro/ong1/npb %s %s q",inframe,npbframe)\r
-                               # cpcmd = cp" "inframe" "frame\r
-                               # chmodcmd = chmod" +r "frame\r
-                               # if(argtab["npbframe"]!="")\r
-                               # {\r
-                                       # # print npbcmd\r
-                                       # if(system(npbcmd)!=0)\r
-                                       # {\r
-                                               # print i" NewpixbOTTification failed."\r
-                                               # updatefail=1\r
-                                               # break\r
-                                       # }\r
-                               # }\r
-                               # # print cpcmd\r
-                               # if(system(cpcmd)!=0)\r
-                               # {\r
-                                       # print i" upload failed."\r
-                                       # updatefail=1\r
-                                       # break\r
-                               # }\r
-                               # # print chmodcmd\r
-                               # if(system(chmodcmd)!=0)\r
-                               # {\r
-                                       # print i" chmod failed."\r
-                                       # updatefail=1\r
-                                       # break\r
-                               # }\r
-                               # print i" updated."\r
-                       # }\r
-                       # if (!updatefail)\r
-                       # {\r
-                               # print "" > updatefile\r
-                               # close(updatefile)\r
-                       # }\r
-               # }\r
-       # }\r
-       \r
        firstong=""\r
        if (state==4) {\r
                print "Time to start onging."\r
@@ -295,18 +323,18 @@ END{
        \r
        if(firstong && argtab["cfrt"]!="")\r
        {\r
-               inframe= datapath argtab["story"]"/"argtab["cfrt"]\r
-               frame= framepath framedir argtab["cfrt"]\r
+               inframe[0]= datapath argtab["story"]"/"argtab["cfrt"]\r
+               frame[0]= framepath framedir argtab["cfrt"]\r
                \r
-               cpcmd = cp" "inframe" "frame\r
-               chmodcmd = chmod" +r "frame\r
+               cpcmd[0] = cp" "inframe[0]" "frame[0]\r
+               chmodcmd[0] = chmod" +r "frame[0]\r
                \r
-               if(system(cpcmd)!=0)\r
+               if(system(cpcmd[0])!=0)\r
                {\r
                        print "CFRT upload failed."\r
                        exit 1\r
                }\r
-               if(system(chmodcmd)!=0)\r
+               if(system(chmodcmd[0])!=0)\r
                {\r
                        print "CFRT chmod failed."\r
                        exit 1\r
@@ -316,72 +344,102 @@ END{
        \r
        print "ONG frame "f"."\r
        \r
-       inframe= datapath argtab["story"]"/"sprintf(argtab["inframe"],f)\r
+       if(argtab["special"] != "")\r
+       {\r
+               specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,"")\r
+               readspecialfile(specialfile,argtab,specialtab,effectivetab)\r
+       }\r
+       else\r
+       {\r
+               readspecialfile("",argtab,specialtab,effectivetab)\r
+       }\r
        \r
-       if (system("[ -f " inframe " ]")!=0)\r
+       for(k=0; k<=enhance; ++k)\r
        {\r
-               ++ongfailcount\r
-               print "Frame "f" doesnt't exist. (#"ongfailcount")"\r
+               k2=(k>0)?("-"k):""\r
                \r
-               print sprintf("%u %u %u %u",state,last,nextong,ongfailcount) > statefile\r
-               close(statefile)\r
+               inframe[k]= datapath argtab["story"]"/"sprintf(effectivetab["inframe"k2],f,"")\r
                \r
-               if((argtab["finalreplaceframe"]!="") && (argtab["finalreplacetime"]!=""))\r
+               if (system("[ -f " inframe[k] " ]")!=0)\r
                {\r
-                       if(((thistime3 - nextong) >= int(argtab["finalreplacetime"])*3600) && (ongfailcount>=int(argtab["finalreplacetime"])))\r
+                       if(k>0) #we only care about missing original frame\r
                        {\r
-                               print "Time to stop trying."\r
-                               print "ONG final replacement frame."\r
-                               inframe= datapath argtab["story"]"/"argtab["finalreplaceframe"]\r
-                               nextstate=3\r
+                               continue\r
+                       }\r
+                       ++ongfailcount\r
+                       print "Frame "f" doesnt't exist. (#"ongfailcount")"\r
+                       \r
+                       print sprintf("%u %u %u %u",state,last,nextong,ongfailcount) > statefile\r
+                       close(statefile)\r
+                       \r
+                       if((argtab["finalreplaceframe"]!="") && (argtab["finalreplacetime"]!=""))\r
+                       {\r
+                               if(((thistime3 - nextong) >= int(argtab["finalreplacetime"])*3600) && (ongfailcount>=int(argtab["finalreplacetime"])))\r
+                               {\r
+                                       print "Time to stop trying."\r
+                                       print "ONG final replacement frame."\r
+                                       inframe[0]= datapath argtab["story"]"/"argtab["finalreplaceframe"]\r
+                                       nextstate=3\r
+                               }\r
+                               else\r
+                                       exit 1\r
                        }\r
                        else\r
                                exit 1\r
                }\r
-               else\r
-                       exit 1\r
+               \r
+               frame[k]= framepath framedir sprintf(effectivetab["frame"k2],f,"")\r
+               npbframe[k]= framepath framedir sprintf(effectivetab["npbframe"k2],f,"")\r
+               \r
+               \r
+               npbcmd[k]= npb" "inframe[k]" "npbframe[k]" q"\r
+               cpcmd[k] = cp" "inframe[k]" "frame[k]\r
+               chmodcmd[k] = chmod" +r "frame[k]\r
        }\r
-       \r
-       \r
-       frame= framepath framedir sprintf(argtab["frame"],f)\r
-       npbframe= framepath framedir sprintf(argtab["npbframe"],f)\r
-       # nextong = thistime3 + int(argtab["ongtime"])*3600\r
-       nextong = getnextongtime()\r
-       \r
-       npbcmd= sprintf("/eizm/pro/ong1/npb %s %s q",inframe,npbframe)\r
-       cpcmd = cp" "inframe" "frame\r
        ongcmd = mawk" -f " bot4awk" -v story="argtab["story"]" -v frame="last" "datapath argtab["story"]"/settings"\r
-       chmodcmd = chmod" +r "frame\r
-       \r
+# nextong = thistime3 + int(argtab["ongtime"])*3600\r
+       nextong = getnextongtime()\r
        ### replace this with actual onging!!!\r
        # system("/eizm/pro/ong1/bot4")\r
        \r
+       if (specialtab["text"]!="")\r
+       {\r
+               specialtab["HTML"]=bb2html(specialtab["text"])\r
+               writespecialfile(specialfile,specialtab)\r
+       }\r
        \r
-       timefile= datapath argtab["story"]"/ongtime"\r
+       timefile= datapath argtab["story"]"/ongtime"\r
        print sprintf("%04u ",f)thistime2 >> timefile\r
        close(timefile)\r
        \r
-       if(argtab["npbframe"]!="")\r
+       for(k=0; k<=enhance; ++k)\r
        {\r
-                       if(system(npbcmd)!=0)\r
+               k2=(k>0)?("-"k):""\r
+               \r
+               if ((system("[ -f " inframe[k]" ]")!=0)&&(k>0))\r
+                       continue\r
+               \r
+               if(argtab["npbframe"]!="")\r
+               {\r
+                       if(system(npbcmd[k])!=0)\r
+                       {\r
+                               print "NewpixbOTTification"k2" failed."\r
+                               exit 1\r
+                       }\r
+               }\r
+               \r
+               if(system(cpcmd[k])!=0)\r
                {\r
-                       print "NewpixbOTTification failed."\r
+                       print "Frame"k2" upload failed."\r
+                       exit 1\r
+               }\r
+               \r
+               if(system(chmodcmd[k])!=0)\r
+               {\r
+                       print "Frame"k2" chmod failed."\r
                        exit 1\r
                }\r
        }\r
-       \r
-       if(system(cpcmd)!=0)\r
-       {\r
-               print "Frame upload failed."\r
-               exit 1\r
-       }\r
-       \r
-       if(system(chmodcmd)!=0)\r
-       {\r
-               print "Frame chmod failed."\r
-               exit 1\r
-       }\r
-       \r
        print sprintf("%u %u %u 0",nextstate,f,nextong) > statefile\r
        close(statefile)\r
        \r
@@ -419,4 +477,669 @@ function getnextongtime(   schedulefile,temp,i)
        }\r
        close(schedulefile)\r
        return thistime3 + int(argtab["ongtime"])*3600\r
-}
\ No newline at end of file
+}\r
+\r
+function readspecialfile (datafile, argtab, specialtab, effectivetab,   line,undertext,eq,i)\r
+{\r
+       for (i in specialtab)\r
+               delete specialtab[i]\r
+       \r
+       for (i in effectivetab)\r
+               delete effectivetab[i]\r
+       \r
+       if (datafile=="")\r
+               return\r
+       \r
+       line=""\r
+       while((getline line < datafile)>0)\r
+       {\r
+               gsub(/[\r\n]/, "", line)\r
+               \r
+               if (line == "" && !undertext)\r
+               {\r
+                       undertext=1\r
+                       specialtab["text"]=""\r
+               }\r
+               else if (undertext)\r
+               {\r
+                       specialtab["text"] = specialtab["text"] line "\n"\r
+               }\r
+               else\r
+               {\r
+                       eq=index(line, "=")\r
+                       specialtab[substr(line, 1, eq-1)]=substr(line, eq+1)\r
+               }\r
+       }\r
+       \r
+       for (i in argtab)\r
+               effectivetab[i]=argtab[i]\r
+       \r
+       for (i in specialtab)\r
+               effectivetab[i]=specialtab[i]\r
+       \r
+       \r
+       close (datafile)\r
+       \r
+}\r
+\r
+function writespecialfile (datafile, specialtab,   i)\r
+{\r
+       for (i in specialtab)\r
+       {\r
+               if (i!="text")\r
+                       print i"="specialtab[i] > specialfile\r
+       }\r
+       \r
+       print "" > specialfile\r
+       if (specialtab["text"]!="")\r
+               printf("%s",specialtab["text"]) > specialfile\r
+       close (specialfile)\r
+}\r
+\r
+#HTML STUFF FROM HERE\r
+function bb2html(text,   depth,count,bbtree,html,tag,tagstart,taglength,elm,tagv,tagname,tagvalue,matchname)\r
+{\r
+       depth=0\r
+       count[0]=1\r
+       bbtree["0"]=""\r
+       bbtree["0.n"]=0\r
+       bbtree["0.t"]="post"\r
+       bbtree["0.v"]=argtab["subject"]\r
+       html=""\r
+       # gsub(/&#61;/,"=",text)\r
+       debug = debug "\n\nBuild BBcode tree:"\r
+       while(length(text)!=0)\r
+       {\r
+               tag=match(text, /\[\/?[a-z0-9\*]+(=(([^\[<>\"\]]*)|(\"[^\"<>]*\")))?\]/)\r
+               #"#\""\r
+               if (tag==0)\r
+               {\r
+                       debug = debug "\ntext: " text\r
+                       bbtree[ind(count,depth)]=text\r
+                       bbtree[indt(count,depth)".n"]=count[depth]\r
+                       ++count[depth]\r
+                       text=""\r
+                       break;\r
+               }\r
+               tagstart=RSTART\r
+               taglength=RLENGTH\r
+               if(tagstart>1)\r
+               {\r
+                       elm=substr(text,1,tagstart-1)\r
+                       debug = debug "\ntext: " elm\r
+                       bbtree[ind(count,depth)]=elm\r
+                       bbtree[indt(count,depth)".n"]=count[depth]\r
+                       ++count[depth]\r
+               }\r
+               tag=substr(text,tagstart,taglength)\r
+               text=substr(text,tagstart+taglength)\r
+               debug = debug "\ntag: " tag\r
+               if(tag!~/^\[\//)\r
+               {\r
+                       tagv=index(tag,"=")\r
+                       if(tagv<2)\r
+                       {\r
+                               tagname=substr(tag,2,length(tag)-2)\r
+                               tagvalue=""\r
+                       }\r
+                       else\r
+                       {\r
+                               tagname=substr(tag,2,tagv-2)\r
+                               tagvalue=substr(tag,tagv+1,length(tag)-tagv-1)\r
+                       }\r
+                       if(tagname !~ /^((fq)|(tq)|(ni)|(po)|(quote)|b|i|u|(code)|(img)|(url)|(size)|(color)|(center)|(right)|(sub)|(sup)|(s)|(spoiler)|(list)|(br)|(\*))$/)\r
+                       {\r
+                               debug = debug "\nunknown tag"\r
+                               bbtree[ind(count,depth)]=tag\r
+                               bbtree[indt(count,depth)".n"]=count[depth]\r
+                               ++count[depth]\r
+                               continue\r
+                       }\r
+                       if((bbtree[indt(count,depth)".t"] == "code" && tagname!="code")||bbtree[indt(count,depth)".t"] == "img"||(bbtree[indt(count,depth)".t"] == "spoiler" && tagname=="spoiler")||(bbtree[indt(count,depth)".t"] == "size" && tagname=="size"))\r
+                       {\r
+                               debug = debug "\nthis tag forbidden here"\r
+                               bbtree[ind(count,depth)]=tag\r
+                               bbtree[indt(count,depth)".n"]=count[depth]\r
+                               ++count[depth]\r
+                               continue\r
+                       }\r
+                       if(tagname=="*")\r
+                       {\r
+                               if(bbtree[indt(count,depth)".t"]==tagname)\r
+                               {\r
+                                       debug = debug "\nimplied tag: [/"tagname"]"\r
+                                       debug = debug "\nmatched"\r
+                                       bbtree[ind(count,depth)]="[/"tagname"]"\r
+                                       bbtree[ind(count,depth)".k"]="e"\r
+                                       bbtree[ind(count,depth)".m"]=1\r
+                                       bbtree[ind(count,depth)".t"]=tagname\r
+                                       bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
+                                       bbtree[indt(count,depth)".n"]=count[depth]\r
+                                       bbtree[indt(count,depth)".m"]=1\r
+                                       count[depth]=""\r
+                                       --depth\r
+                                       ++count[depth]\r
+                               }\r
+                               else if(bbtree[indt(count,depth)".t"]!="list")\r
+                               {\r
+                                       debug = debug "\nthis tag forbidden here"\r
+                                       bbtree[ind(count,depth)]=tag\r
+                                       bbtree[indt(count,depth)".n"]=count[depth]\r
+                                       ++count[depth]\r
+                                       continue\r
+                               }\r
+                       }\r
+                       debug = debug "\nname: " tagname " value: " tagvalue\r
+                       bbtree[ind(count,depth)]=tagname" "tagvalue\r
+                       bbtree[ind(count,depth)".k"]="s"\r
+                       bbtree[indt(count,depth)".n"]=count[depth]\r
+                       ++depth\r
+                       count[depth]=1\r
+                       bbtree[indt(count,depth)]=tag\r
+                       bbtree[indt(count,depth)".n"]=0\r
+                       bbtree[indt(count,depth)".t"]=tagname\r
+                       bbtree[indt(count,depth)".v"]=tagvalue\r
+                       \r
+                       # if(tagname=="br") #or other single tags in the future\r
+                       # {\r
+                               # debug = debug "\nmatched"\r
+                               # bbtree[ind(count,depth)]=tag\r
+                               # bbtree[ind(count,depth)".k"]="e"\r
+                               # bbtree[ind(count,depth)".m"]=1\r
+                               # bbtree[ind(count,depth)".t"]=tagname\r
+                               # bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
+                               # bbtree[indt(count,depth)".n"]=count[depth]\r
+                               # bbtree[indt(count,depth)".m"]=1\r
+                               # count[depth]=""\r
+                               # --depth\r
+                               # ++count[depth]\r
+                       # }\r
+               }\r
+               else\r
+               {\r
+                       if(depth<=0)\r
+                       {\r
+                               debug = debug "\n""unmatched"\r
+                               bbtree[ind(count,depth)]=tag\r
+                               bbtree[indt(count,depth)".n"]=count[depth]\r
+                               ++count[depth]\r
+                               continue\r
+                       }\r
+                       tagname=substr(tag,3,length(tag)-3)\r
+                       if(tagname=="list"&&bbtree[indt(count,depth)".t"]=="*")\r
+                       {\r
+                               debug = debug "\nimplied tag: [/*]"\r
+                               debug = debug "\nmatched"\r
+                               bbtree[ind(count,depth)]="[/*]"\r
+                               bbtree[ind(count,depth)".k"]="e"\r
+                               bbtree[ind(count,depth)".m"]=1\r
+                               bbtree[ind(count,depth)".t"]="*"\r
+                               bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
+                               bbtree[indt(count,depth)".n"]=count[depth]\r
+                               bbtree[indt(count,depth)".m"]=1\r
+                               count[depth]=""\r
+                               --depth\r
+                               ++count[depth]\r
+                       }\r
+                       debug = debug "\nname: " tagname\r
+                       matchname=bbtree[indt(count,depth)".t"]\r
+                       if((bbtree[indt(count,depth)".t"] == "code" && tagname!="code")||(bbtree[indt(count,depth)".t"] == "img" && tagname != "img"))\r
+                       {\r
+                               debug = debug "\nthis tag forbidden here"\r
+                               bbtree[ind(count,depth)]=tag\r
+                               bbtree[indt(count,depth)".n"]=count[depth]\r
+                               ++count[depth]\r
+                               continue\r
+                       }\r
+                       if(tagname!=matchname)\r
+                       {\r
+                               debug = debug "\nmismatched: " matchname\r
+                               # bbtree[ind(count,depth)]=tag\r
+                               # bbtree[indt(count,depth)".n"]=count[depth]\r
+                               # ++count[depth]\r
+                               # continue\r
+                               bbtree[ind(count,depth)]=tag\r
+                               bbtree[ind(count,depth)".k"]="e"\r
+                               bbtree[ind(count,depth)".t"]=bbtree[indt(count,depth)".t"]\r
+                               bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
+                               bbtree[indt(count,depth)".n"]=count[depth]\r
+                               count[depth]=""\r
+                               --depth\r
+                               ++count[depth]\r
+                               continue\r
+                       }\r
+                       debug = debug "\nmatched"\r
+                       bbtree[ind(count,depth)]=tag\r
+                       bbtree[ind(count,depth)".k"]="e"\r
+                       bbtree[ind(count,depth)".m"]=1\r
+                       bbtree[ind(count,depth)".t"]=tagname\r
+                       bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
+                       bbtree[indt(count,depth)".n"]=count[depth]\r
+                       bbtree[indt(count,depth)".m"]=1\r
+                       count[depth]=""\r
+                       --depth\r
+                       ++count[depth]\r
+               }\r
+       }\r
+       if(depth>0)\r
+               debug = debug "\nunclosed tags: " depth\r
+       \r
+       debug = debug "\n\n""generate HTML:"\r
+       depth=0\r
+       count[0]=0\r
+       while(count[0]<=bbtree["0.n"]&&depth>=0)\r
+       {\r
+               if(count[depth]==0)\r
+               {\r
+                       tag=bbtree[indt(count,depth)]\r
+                       tagname=bbtree[indt(count,depth)".t"]\r
+                       tagvalue=bbtree[indt(count,depth)".v"]\r
+                       debug = debug "\nname: "tagname" value: "tagvalue" elements: "bbtree[indt(count,depth)".n"]\r
+                       if(tagname == "post")\r
+                       {\r
+                       }\r
+                       else if(bbtree[indt(count,depth)".m"]=="")\r
+                       {\r
+                               debug = debug "\nunmatched"\r
+                               html = html htmlescape(tag)\r
+                       }\r
+                       else if(tagname == "quote")\r
+                       {\r
+                               if (tagvalue=="")\r
+                               {\r
+                                       html = html "<blockquote class=\"pq\"><div>"\r
+                               }\r
+                               else\r
+                               {\r
+                                       if(tagvalue !~ /^\".*\"$/)\r
+                                       #"#\""\r
+                                               tagvalue="You forgot about the quote marks, "htmlescape(tagvalue)\r
+                                       else\r
+                                               tagvalue=bb2html(substr(tagvalue,2,length(tagvalue)-2))\r
+                                       html = html "<blockquote class=\"pq\"><div><cite class=\"pq\"><b class=\"br\">"tagvalue"</b> wrote:</cite><br>"\r
+                               }\r
+                       }\r
+                       else if (tagname == "fq")\r
+                       {\r
+                               html = html"<div class=\"fq\">"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. " \r
+                       }\r
+                       else if (tagname == "tq")\r
+                       {\r
+                               html = html"<div class=\"tq\">"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. " \r
+                       }\r
+                       else if (tagname == "br")\r
+                       {\r
+                               html = html"<span class=\"br\">"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. " \r
+                       }\r
+                       else if (tagname == "ni")\r
+                       {\r
+                               html = html"<span class=\"ni\">"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. " \r
+                       }\r
+                       else if (tagname == "po")\r
+                       {\r
+                               html = html"<span class=\"po\">"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. " \r
+                       }\r
+                       else if (tagname == "b")\r
+                       {\r
+                               html = html"<span style=\"font-weight: bold\">"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. " \r
+                       }\r
+                       else if (tagname == "i")\r
+                       {\r
+                               html = html"<span style=\"font-style: italic\">"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. " \r
+                       }\r
+                       else if (tagname == "u")\r
+                       {\r
+                               html = html"<span style=\"text-decoration: underline\">"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. " \r
+                       }\r
+                       else if (tagname == "code")\r
+                       {\r
+                               if(bbtree[indtu(count,depth)".t"] == "code")\r
+                               {\r
+                                       html=html htmlescape(tag)\r
+                                       debug = debug "\nnot a tag, actually"\r
+                               }\r
+                               else\r
+                               {\r
+                                       html=html"<dl class=\"pq\"><dt class=\"pq\">Code: <a href=\"#\" onclick=\"selectCode(this); return false;\">Select all</a></dt><dd><code class=\"pq\">"\r
+                                       if(tagvalue!="")\r
+                                               html=html"This tag shouldn't have any value. "\r
+                               }\r
+                       }\r
+                       else if (tagname == "img")\r
+                               html=html"<img src=\""\r
+                       else if (tagname == "url")\r
+                       {\r
+                               if(tagvalue=="")\r
+                               {\r
+                                       ++count[depth]\r
+                                       tagvalue=bbtree[ind(count,depth)]\r
+                                       --count[depth]\r
+                                       debug = debug "\nimplied value: " tagvalue\r
+                               }\r
+                               html=html"<a href=\""htmlescape(tagvalue)"\" class=\"postlink\">"\r
+                       }\r
+                       else if (tagname == "size")\r
+                       {\r
+                               if (tagvalue==""||(tagvalue !~ /^[0-9]+$/)||(tagvalue+0)>200)\r
+                                       html=html"<span style=\"font-size: 130%; line-height: 116%;\"> This tag should have a correct value. "\r
+                               else\r
+                                       html=html"<span style=\"font-size: "htmlescape(tagvalue)"%; line-height: 116%;\">"\r
+                       }\r
+                       else if (tagname == "color")\r
+                       {\r
+                               if (tagvalue==""||tagvalue !~ /^#[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]$/) #for some reason /^([0-9A-F]{6})$/ doesn't work.\r
+                                       html=html"<span style=\"color: #EE0000\"> This tag should have a correct value. "\r
+                               else\r
+                                       html=html"<span style=\"color: "htmlescape(tagvalue)"\">"\r
+                       }\r
+                       else if (tagname ~ /^((center)|(right))$/)\r
+                       {\r
+                               html=html"<div align=\""tagname"\">"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. "\r
+                       }\r
+                       else if (tagname =="s")\r
+                       {\r
+                               html=html"<strike>"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. "\r
+                       }\r
+                       else if (tagname =="sub")\r
+                       {\r
+                               html=html"<sub>"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. "\r
+                       }\r
+                       else if (tagname =="sup")\r
+                       {\r
+                               html=html"<sup>"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. "\r
+                       }\r
+                       else if (tagname=="spoiler")\r
+                       {\r
+                               html=html"<div style=\"margin:20px; margin-top:5px\"><div class=\"quotetitle\"><b>Spoiler:</b> <input type=\"button\" class=\"pk\" value=\"Show\" style=\"width:45px;font-size:10px;margin:0px;padding:0px;\" onclick=\"if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = '';        this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }\" /></div><div class=\"quotecontent\"><div style=\"display: none;\">"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. "\r
+                       }\r
+                       else if (tagname=="list")\r
+                       {\r
+                               if(tagvalue=="")\r
+                                       html=html"<ul>"\r
+                               else\r
+                               {\r
+                                       if (tagvalue=="1")\r
+                                               tagvalue="decimal"\r
+                                       else if (tagvalue=="i")\r
+                                               tagvalue="lower-roman"\r
+                                       else if (tagvalue=="I")\r
+                                               tagvalue="upper-roman"\r
+                                       else if (tagvalue=="a")\r
+                                               tagvalue="lower-alpha"\r
+                                       else if (tagvalue=="A")\r
+                                               tagvalue="upper-alpha"\r
+                                       else\r
+                                       {\r
+                                               html=html"This tag should have a correct value. "\r
+                                               tagvalue="decimal"\r
+                                       }\r
+                                       html=html"<ol style=\"list-style-type: "tagvalue"\">"\r
+                               }\r
+                       }\r
+                       else if (tagname=="*")\r
+                       {\r
+                               html=html"<li>"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. "\r
+                       }\r
+                       # else if (tagname == "br")\r
+                       # {\r
+                               # html = html"<br>"\r
+                               # if(tagvalue!="")\r
+                                       # html=html"This tag shouldn't have any value. " \r
+                       # }\r
+                       else\r
+                       {\r
+                               debug = debug "\nunknown tag"\r
+                               html = html htmlescape(tag)\r
+                       }\r
+                       ++count[depth]\r
+               }\r
+               else if(bbtree[ind(count,depth)".k"]=="s")\r
+               {\r
+                       debug = debug "\nentering tag:"\r
+                       ++depth\r
+                       count[depth]=0\r
+               }\r
+               else if(bbtree[ind(count,depth)".k"]=="e")\r
+               {\r
+                       debug = debug "\nleaving tag:"\r
+                       tag=bbtree[ind(count,depth)]\r
+                       tagname=bbtree[ind(count,depth)".t"]\r
+                       tagvalue=bbtree[ind(count,depth)".v"]\r
+                       debug = debug "\nname: "tagname" value: "tagvalue\r
+                       if (tagname == "post")\r
+                       {\r
+                       }\r
+                       else if(bbtree[ind(count,depth)".m"]=="")\r
+                       {\r
+                               debug = debug "\nunmatched"\r
+                               html = html htmlescape(tag)\r
+                       }\r
+                       else if(tagname == "quote")\r
+                               html = html "</div></blockquote>"\r
+                       else if (tagname ~/^(b|i|u|(size)|(color)|(br)|(ni)|(po))$/)\r
+                               html = html"</span>"\r
+                       else if (tagname == "code")\r
+                       {\r
+                               if(bbtree[indtu(count,depth)".t"] == "code")\r
+                               {\r
+                                       html=html htmlescape(tag)\r
+                                       debug = debug "\nnot a tag, actually"\r
+                               }\r
+                               else\r
+                                       html = html"</code></dd></dl>"\r
+                       }\r
+                       else if (tagname == "img")\r
+                       {\r
+                               html = html"\" alt=\"Image\" />"\r
+                               if(tagvalue!="")\r
+                                       html=html"This tag shouldn't have any value. "\r
+                       }\r
+                       else if(tagname=="url")\r
+                               html=html"</a>"\r
+                       else if (tagname ~ /^((center)|(right)|(fq)|(tq))$/)\r
+                               html=html"</div>"\r
+                       else if (tagname =="s")\r
+                               html=html"</strike>"\r
+                       else if (tagname =="sub")\r
+                               html=html"</sub>"\r
+                       else if (tagname =="sup")\r
+                               html=html"</sup>"\r
+                       else if (tagname=="spoiler")\r
+                               html=html"</div></div></div>"\r
+                       else if (tagname=="list")\r
+                       {\r
+                               if (tagvalue=="")\r
+                                       html=html"</ul>"\r
+                               else\r
+                                       html=html"</ol>"\r
+                       }\r
+                       else if (tagname=="*")\r
+                               html=html"</li>"\r
+                       # else if (tagname == "br") #\r
+                       # {\r
+                               # #\r
+                       # }\r
+                       else\r
+                       {\r
+                               debug = debug "\nunknown tag"\r
+                               html = html htmlescape(tag)\r
+                       }\r
+                       count[depth]=""\r
+                       --depth\r
+                       ++count[depth]\r
+               }\r
+               else if(count[depth]>bbtree[indt(count,depth)".n"])\r
+               {\r
+                       debug = debug "\nrun out of elements in this tag; leaving"\r
+                       count[depth]=""\r
+                       --depth\r
+                       ++count[depth]\r
+               }\r
+               else\r
+               {\r
+                       tag=bbtree[ind(count,depth)]\r
+                       debug = debug "\ntext: "tag\r
+                       \r
+                       tag=htmlescape(tag,"","br")\r
+                       \r
+                       if(bbtree[indt(count,depth)".t"] == "code")\r
+                       {\r
+                               gsub(/ /,"\\&nbsp;",tag)\r
+                               gsub(/\t/,"\\&nbsp;\\&nbsp;",tag)\r
+                       }\r
+                       else{\r
+                               gsub(/  /,"\\&nbsp; ",tag)\r
+                               gsub(/  /," \\&nbsp;",tag)\r
+                               # gsub(/<br> /,"<br>\\&nbsp;",tag)\r
+                       }\r
+                       \r
+                       \r
+                       if(nourl==""&& bbtree[indt(count,depth)".t"] !~ /^((code)|(img)|(url))$/)\r
+                               gsub(/https?:\/\/[^\n\r\t<> ]+/,"<a href=\"&\" class=\"postlink\">&</a>",tag)\r
+                       # if(nosmil=="" && bbtree[indt(count,depth)".t"] !~ /^((code)|(img))$/)\r
+                       # {\r
+                               # gsub(/(^|[\n\r\t ]):D($|[\n\r\t ])/," <img title=\"Very Happy\" alt=\":D\" src=\"http://forums.xkcd.com/images/smilies/icon_biggrin.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):\)($|[\n\r\t ])/," <img title=\"Smile\" alt=\":)\" src=\"http://forums.xkcd.com/images/smilies/icon_smile.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):\(($|[\n\r\t ])/," <img title=\"Sad\" alt=\":(\" src=\"http://forums.xkcd.com/images/smilies/icon_sad.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):o($|[\n\r\t ])/," <img title=\"Surprised\" alt=\":o\" src=\"http://forums.xkcd.com/images/smilies/icon_surprised.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):shock:($|[\n\r\t ])/," <img title=\"Shocked\" alt=\":shock:\" src=\"http://forums.xkcd.com/images/smilies/icon_eek.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):\?($|[\n\r\t ])/," <img title=\"Confused\" alt=\":?\" src=\"http://forums.xkcd.com/images/smilies/icon_confused.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ])8-\)($|[\n\r\t ])/," <img title=\"Cool\" alt=\"8-)\" src=\"http://forums.xkcd.com/images/smilies/icon_cool.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):lol:($|[\n\r\t ])/," <img title=\"Laughing\" alt=\":lol:\" src=\"http://forums.xkcd.com/images/smilies/icon_lol.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):x($|[\n\r\t ])/," <img title=\"Mad\" alt=\":x\" src=\"http://forums.xkcd.com/images/smilies/icon_mad.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):P($|[\n\r\t ])/," <img title=\"Razz\" alt=\":P\" src=\"http://forums.xkcd.com/images/smilies/icon_razz.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):oops:($|[\n\r\t ])/," <img title=\"Embarassed\" alt=\":oops:\" src=\"http://forums.xkcd.com/images/smilies/icon_redface.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):cry:($|[\n\r\t ])/," <img title=\"Crying or Very Sad\" alt=\":cry:\" src=\"http://forums.xkcd.com/images/smilies/icon_cry.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):evil:($|[\n\r\t ])/," <img title=\"Evil or Very Mad\" alt=\":evil:\" src=\"http://forums.xkcd.com/images/smilies/icon_evil.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):twisted:($|[\n\r\t ])/," <img title=\"Twisted Evil\" alt=\":twisted:\" src=\"http://forums.xkcd.com/images/smilies/icon_twisted.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):roll:($|[\n\r\t ])/," <img title=\"Rolling Eyes\" alt=\":roll:\" src=\"http://forums.xkcd.com/images/smilies/icon_rolleyes.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):wink:($|[\n\r\t ])/," <img title=\"Wink\" alt=\":wink:\" src=\"http://forums.xkcd.com/images/smilies/icon_wink.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]);\)($|[\n\r\t ])/," <img title=\"Wink\" alt=\":wink:\" src=\"http://forums.xkcd.com/images/smilies/icon_wink.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):!:($|[\n\r\t ])/," <img title=\"Exclamation\" alt=\":!:\" src=\"http://forums.xkcd.com/images/smilies/icon_exclaim.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):\?:($|[\n\r\t ])/," <img title=\"Question\" alt=\":?:\" src=\"http://forums.xkcd.com/images/smilies/icon_question.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):idea:($|[\n\r\t ])/," <img title=\"Idea\" alt=\":idea:\" src=\"http://forums.xkcd.com/images/smilies/icon_idea.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):arrow:($|[\n\r\t ])/," <img title=\"Arrow\" alt=\":arrow:\" src=\"http://forums.xkcd.com/images/smilies/icon_arrow.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):\|($|[\n\r\t ])/," <img title=\"Neutral\" alt=\":|\" src=\"http://forums.xkcd.com/images/smilies/icon_neutral.gif\" /> ",tag)\r
+                               # gsub(/(^|[\n\r\t ]):mrgreen:($|[\n\r\t ])/," <img title=\"Mr. Green\" alt=\":mrgreen:\" src=\"http://forums.xkcd.com/images/smilies/icon_mrgreen.gif\" /> ",tag)\r
+                       # }\r
+                       \r
+                       html = html tag\r
+                       ++count[depth]\r
+               }\r
+       }\r
+       debug = debug "\ndone\n"\r
+       return html\r
+}\r
+\r
+function ind(count,depth,   ii,iindex)\r
+{\r
+       iindex = ""\r
+       for(ii=0;ii<=depth;++ii)\r
+       {\r
+               if(ii!=0)\r
+                       iindex = iindex "."\r
+               iindex = iindex count[ii]\r
+       }\r
+       # debug = debug "\n" iindex\r
+       return iindex\r
+}\r
+function indt(count,depth,   ii,iindex)\r
+{\r
+       iindex = ""\r
+       for(ii=0;ii<depth;++ii)\r
+       {\r
+               if(ii!=0)\r
+                       iindex = iindex "."\r
+               iindex = iindex count[ii]\r
+       }\r
+       if(depth>0)\r
+               iindex=iindex"."\r
+       iindex = iindex "0"\r
+       # debug = debug "\n" iindex\r
+       return iindex\r
+}\r
+function indtu(count,depth,   ii,iindex)\r
+{\r
+       iindex = ""\r
+       for(ii=0;ii<depth-1;++ii)\r
+       {\r
+               if(ii!=0)\r
+                       iindex = iindex "."\r
+               iindex = iindex count[ii]\r
+       }\r
+       if(depth>0)\r
+               iindex=iindex"."\r
+       iindex = iindex "0"\r
+       # debug = debug "\n" iindex\r
+       return iindex\r
+}\r
+function htmlescape(name,less,br,   len,iii,escaped,ch)\r
+{\r
+       len=length(name)\r
+       escaped=""\r
+       for(iii=1;iii<=len;++iii)\r
+       {\r
+               ch=substr(name,iii,1);\r
+               if(ch == "\n")\r
+                       escaped = escaped ((br!="")?"<br>":"&#"ch2dec[ch]";")\r
+               else if(ch =="\r")\r
+                       escaped = escaped ((br!="")?"":"&#"ch2dec[ch]";")\r
+               else if(ch == "\"" && less=="")\r
+                       escaped = escaped "&#"ch2dec[ch]";"\r
+               else if(ch ~ /[=<>&]/)\r
+                       escaped = escaped "&#"ch2dec[ch]";"\r
+               else\r
+                       escaped = escaped ch\r
+       }\r
+       return escaped\r
+}\r
+function hexencode(name,   len,iii,escaped,ch)\r
+{\r
+       len=length(name)\r
+       escaped=""\r
+       for(iii=1;iii<=len;++iii)\r
+       {\r
+               ch=substr(name,iii,1)\r
+               escaped = escaped ch2hex[ch]\r
+       }\r
+       return escaped\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
index f5cc701fab7829ede1ac7b37603e9cf51d8ebb17..4ccac67119e29cd107aa10e95dd182fd2821d24d 100644 (file)
--- a/post.cpp
+++ b/post.cpp
@@ -1,8 +1,8 @@
 // post.cpp (1190.bicyclesonthemoon.info/aftertime/post)\r
 // The post edit interface\r
-// 05.04.2015\r
+// 15.04.2019\r
 // \r
-// Copyright (C) 2015  Balthasar SzczepaƄski\r
+// Copyright (C) 2015, 2019  Balthasar SzczepaƄski\r
 // \r
 // This program is free software: you can redistribute it and/or modify\r
 // it under the terms of the GNU Affero General Public License as\r
@@ -75,6 +75,7 @@ char *subject =&zero;
 char *key =&zero;\r
 char *forcekey =&zero;\r
 char *ID =&zero;\r
+bool special=false;\r
 \r
 char wrong[256];\r
 \r
@@ -86,7 +87,8 @@ void writeArgH(FILE *file,const char *name,const char *value, unsigned char br);
 void writeArgH(FILE *file,const char *value);\r
 // void writeArgBR(FILE *file,const char *name, const char *value);\r
 void end(int m);\r
-void id(char *timenumber,char *story, unsigned short frame, unsigned char round);\r
+void id(char *timenumber, char *story, unsigned short frame, char *subframe, unsigned char round);\r
+void specialid(char *timenumber, char *story, char frame);\r
 \r
 void end(int m)\r
 {\r
@@ -257,41 +259,86 @@ void submit()
        char mm[4];\r
        char dd[4];\r
        char hh[4];\r
+       char sf[2]={0,0};\r
        \r
        char arg1[256];\r
        char arg2[256];\r
        char arg3[256];\r
+       char arg4[256];\r
        \r
        char newkey[33];\r
        \r
        unsigned char tm, td, th, tr;\r
        unsigned short ty, tf;\r
+       \r
+       // dup2(fileno(stdout),fileno(stderr));\r
+       // printf("Content-type: text/plain\n\n");\r
+\r
 \r
        // posttime=time(NULL);\r
        // nowS=gmtime(&posttime);\r
        \r
        if(forcekey[0]=='\0')\r
-               sprintf(newkey,"%04X%04X%04X%04X%04X%04X%04X%04X",\r
+               snprintf(newkey,33,"%04X%04X%04X%04X%04X%04X%04X%04X",\r
                        (unsigned short)rand(),(unsigned short)rand(),(unsigned short)rand(),(unsigned short)rand(),\r
                        (unsigned short)rand(),(unsigned short)rand(),(unsigned short)rand(),(unsigned short)rand());\r
        else\r
-               sprintf(newkey,"%s",forcekey);\r
+               snprintf(newkey,33,"%s",forcekey);\r
        \r
-       if(y[0]!='\0'){sscanf(y,"%hu",&ty); sprintf(yy,"%04hu",ty); }\r
-       if(m[0]!='\0'){sscanf(m,"%hhu",&tm);sprintf(mm,"%02hhu",tm);}\r
-       if(d[0]!='\0'){sscanf(d,"%hhu",&td);sprintf(dd,"%02hhu",td);}\r
-       if(h[0]!='\0'){sscanf(h,"%hhu",&th);sprintf(hh,"%02hhu",th);}\r
-       if(frame[0]!='\0'){sscanf(frame,"%hu",&tf);sprintf(ff,"%04hu",tf);}\r
-       if(round[0]!='\0'){sscanf(round,"%hhu",&tr);sprintf(rr,"%02hhu",tr);}\r
+       if(y[0]!='\0')\r
+       {\r
+               sscanf(y,"%hu",&ty);\r
+               snprintf(yy,8,"%04hu",ty);\r
+       }\r
+       if(m[0]!='\0')\r
+       {\r
+               sscanf(m,"%hhu",&tm);\r
+               snprintf(mm,4,"%02hhu",tm);\r
+       }\r
+       if(d[0]!='\0')\r
+       {\r
+               sscanf(d,"%hhu",&td);\r
+               snprintf(dd,4,"%02hhu",td);\r
+       }\r
+       if(h[0]!='\0')\r
+       {\r
+               sscanf(h,"%hhu",&th);\r
+               snprintf(hh,4,"%02hhu",th);\r
+       }\r
+       if(frame[0]!='\0')\r
+       {\r
+               if(special)\r
+               {\r
+                       snprintf(ff,8,"%c",frame[0]);\r
+               }\r
+               else\r
+               {\r
+                       sscanf(frame,"%hu%c",&tf,sf);\r
+                       snprintf(ff,8,"%04hu%s",tf,sf);\r
+               }\r
+       }\r
+       if(round[0]!='\0')\r
+       {\r
+               if(special)\r
+                       snprintf(rr,4,"");\r
+               else\r
+               {\r
+                       sscanf(round,"%hhu",&tr);\r
+                       snprintf(rr,4,"%02hhu",tr);\r
+               }\r
+       }\r
        \r
        if((ty>0x0fff)||(tm>0x0f)||(td>0x1f)||(th>0x1f))\r
                preview("Time too long");\r
        // I accept invalid time as long as it's not too long\r
        \r
-       id(timenumber,story,tf,tr);\r
-       sprintf(postpath,"%s%s",MPOST_PATH,timenumber);\r
+       if (special)\r
+               specialid(timenumber,story,frame[0]);\r
+       else\r
+               id(timenumber,story,tf,sf,tr);\r
+       snprintf(postpath,512,"%s%s",MPOST_PATH,timenumber);\r
        if(forceID[0]!='\0')\r
-               sprintf(forcepath,"%s%s",MPOST_PATH,forceID);\r
+               snprintf(forcepath,512,"%s%s",MPOST_PATH,forceID);\r
        \r
        tempfile=fopen(temppath,"wt");\r
        if(tempfile==NULL)\r
@@ -321,8 +368,8 @@ void submit()
        fclose(tempfile);\r
        tf=false;\r
        \r
-       sprintf(arg1,"outfile=%s",temppath);\r
-       sprintf(arg2,"tempfile=%s",temppath2);\r
+       snprintf(arg1,256,"outfile=%s",temppath);\r
+       snprintf(arg2,256,"tempfile=%s",temppath2);\r
        fflush(stdout);\r
        sub=fork();\r
        if(sub==0)\r
@@ -334,19 +381,24 @@ void submit()
        }\r
        waitpid(sub,&r,0);\r
        \r
-       sprintf(arg1,"name=%s",username);\r
-       sprintf(arg2,"pass=%s",password);\r
-       sprintf(arg3,"story=%s",story);\r
+       snprintf(arg1,256,"name=%s",username);\r
+       snprintf(arg2,256,"pass=%s",password);\r
+       snprintf(arg3,256,"story=%s",story);\r
+       snprintf(arg4,256,"file=%s",(forceID[0]!='\0')?forcepath:postpath);\r
+       \r
        sub=fork();\r
        if(sub==0)\r
        {\r
-               r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_VERIFY,"-v",arg1,"-v",arg2,"-v",arg3,"-v","reversed=1",(forceID[0]!='\0')?forcepath:postpath,(char *)0);\r
+               r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_VERIFY,"-v",arg1,"-v",arg2,"-v",arg3,"-v",arg4,(char *)0);\r
                exit(r);\r
        }\r
        waitpid(sub,&r,0);\r
-       if(!r)\r
+       \r
+       // printf("r=%d\n",r);\r
+       \r
+       if(r)\r
                preview("Can't submit this post. Not yours or wrong password?");\r
-               \r
+       \r
        if(forceID[0]!='\0')\r
        {\r
                sub=fork();\r
@@ -370,7 +422,7 @@ void submit()
                preview(postpath);\r
        \r
        printf("Content-type: text/html\n\n");\r
-       sprintf(arg1,"info=<p>This message has been sent successfully.<br><br><a href=\"/aftertime/view?v=%s&amp;key=%s\">View your submitted message</a><br><br><a href=\"/aftertime/list/\">Return to the list</a></p>",timenumber,newkey);\r
+       snprintf(arg1,256,"info=<p>This message has been sent successfully.<br><br><a href=\"/aftertime/view?v=%s&amp;key=%s\">View your submitted message</a><br><br><a href=\"/aftertime/list/\">Return to the list</a></p>",timenumber,newkey);\r
        // printf("Content-type: text/html\n\n");\r
        fflush(stdout);\r
        sub=fork();\r
@@ -394,14 +446,54 @@ void preview (const char *text)
        char mm[4];\r
        char dd[4];\r
        char hh[4];\r
+       char sf[2]={0,0};\r
        unsigned short ty, tf;\r
        unsigned char tm,td,th, tr;\r
-       if(y[0]!='\0'){sscanf(y,"%hu",&ty); ty&=0x0fff;sprintf(yy,"%04hu",ty); }\r
-       if(m[0]!='\0'){sscanf(m,"%hhu",&tm);tm&=  0x0f;sprintf(mm,"%02hhu",tm);}\r
-       if(d[0]!='\0'){sscanf(d,"%hhu",&td);td&=  0x1f;sprintf(dd,"%02hhu",td);}\r
-       if(h[0]!='\0'){sscanf(h,"%hhu",&th);th&=  0x1f;sprintf(hh,"%02hhu",th);}\r
-       if(frame[0]!='\0'){sscanf(frame,"%hu",&tf);sprintf(ff,"%04hu",tf);}\r
-       if(round[0]!='\0'){sscanf(round,"%hhu",&tr);sprintf(rr,"%02hhu",tr);}\r
+       if(y[0]!='\0')\r
+       {\r
+               sscanf(y,"%hu",&ty);\r
+               ty&=0x0fff;\r
+               snprintf(yy,8,"%04hu",ty);\r
+       }\r
+       if(m[0]!='\0')\r
+       {\r
+               sscanf(m,"%hhu",&tm);\r
+               tm&=  0x0f;\r
+               snprintf(mm,4,"%02hhu",tm);\r
+       }\r
+       if(d[0]!='\0')\r
+       {\r
+               sscanf(d,"%hhu",&td);\r
+               td&=  0x1f;\r
+               snprintf(dd,4,"%02hhu",td);\r
+       }\r
+       if(h[0]!='\0')\r
+       {\r
+               sscanf(h,"%hhu",&th);\r
+               th&=  0x1f;snprintf(hh,4,"%02hhu",th);\r
+       }\r
+       if(frame[0]!='\0')\r
+       {\r
+               if(special)\r
+               {\r
+                       snprintf(ff,8,"%c",frame[0]);\r
+               }\r
+               else\r
+               {\r
+                       sscanf(frame,"%hu%c",&tf,sf);\r
+                       snprintf(ff,8,"%04hu%s",tf,sf);\r
+               }\r
+       }\r
+       if(round[0]!='\0')\r
+       {\r
+               if(special)\r
+                       snprintf(rr,4,"");\r
+               else\r
+               {\r
+                       sscanf(round,"%hhu",&tr);\r
+                       snprintf(rr,4,"%02hhu",tr);\r
+               }\r
+       }\r
        \r
        tempfile=fopen(temppath,"wt");\r
        if(tempfile==NULL)\r
@@ -434,8 +526,8 @@ void preview (const char *text)
        \r
        printf("Content-type: text/html\n\n");\r
        \r
-       sprintf(arg1,"outfile=%s",temppath);\r
-       sprintf(arg2,"tempfile=%s",temppath2);\r
+       snprintf(arg1,256,"outfile=%s",temppath);\r
+       snprintf(arg2,256,"tempfile=%s",temppath2);\r
        \r
        fflush(stdout);\r
        sub=fork();\r
@@ -449,8 +541,8 @@ void preview (const char *text)
        waitpid(sub,&r,0);\r
        \r
        // printf("Content-type: text/html\n\n");\r
-       sprintf(arg1,"argfile=%s",temppath);\r
-       sprintf(arg2,"key=%s",key[0]?key:"???");\r
+       snprintf(arg1,256,"argfile=%s",temppath);\r
+       snprintf(arg2,256,"key=%s",key[0]?key:"???");\r
        fflush(stdout);\r
        sub=fork();\r
        if(sub==0)\r
@@ -472,12 +564,14 @@ int main()
        \r
        char *arg;\r
        \r
+       // printf("Content-type: text/plain\n\n");\r
+       \r
        cgi=cgiInit();\r
        srand (time (NULL) + getpid());\r
        \r
        \r
-       sprintf(temppath,"%s%lu",TEMP_PATH,(unsigned long)getpid());\r
-       sprintf(temppath2,"%s_%lu",TEMP_PATH,(unsigned long)getpid());\r
+       snprintf(temppath,256,"%s%lu",TEMP_PATH,(unsigned long)getpid());\r
+       snprintf(temppath2,256,"%s_%lu",TEMP_PATH,(unsigned long)getpid());\r
        \r
        arg=cgiGetValue(cgi,"password");\r
        if(arg!=NULL)\r
@@ -501,9 +595,19 @@ int main()
        if(arg!=NULL)\r
        {\r
                story=arg;\r
-               if(!strcmp(story,"t1i"));\r
-               else if(!strcmp(story,"bftf"));
+               if(!strcmp(story,"time")); //really shouldn't be hardcoded!\r
+               else if(!strcmp(story,"prickly"));
+               else if(!strcmp(story,"potm"));\r
+               else if(!strcmp(story,"lucky"));\r
+               else if(!strcmp(story,"beany"));\r
+               else if(!strcmp(story,"bean2"));\r
+               else if(!strcmp(story,"t1i"));\r
                else if(!strcmp(story,"zodiac"));\r
+               else if(!strcmp(story,"bftf"));\r
+               else if(!strcmp(story,"t-1"));\r
+               else if(!strcmp(story,"bsta"));\r
+               else if(!strcmp(story,"advent"));\r
+               else if(!strcmp(story,"phys"));\r
                else\r
                {\r
                        missing=true;\r
@@ -518,7 +622,11 @@ int main()
        \r
        arg=cgiGetValue(cgi,"frame");\r
        if(arg!=NULL)\r
+       {\r
                frame=arg;\r
+               if((frame[0]>='a')&&(frame[0]<='z'))\r
+                       special=true;\r
+       }\r
        else\r
        {\r
                missing=true;\r
@@ -530,8 +638,11 @@ int main()
                round=arg;\r
        else\r
        {\r
-               missing=true;\r
-               strcpy(wrong,"Round number was missing. Replaced with default value.");\r
+               if(!special)\r
+               {\r
+                       missing=true;\r
+                       strcpy(wrong,"Round number was missing. Replaced with default value.");\r
+               }\r
        }\r
        arg=cgiGetValue(cgi,"subject");\r
        if(arg!=NULL)\r
@@ -646,7 +757,11 @@ int main()
        \r
 }\r
 \r
-void id(char *timenumber,char *story, unsigned short frame, unsigned char round)\r
+void id(char *timenumber, char *story, unsigned short frame, char *subframe, unsigned char round)\r
+{\r
+       snprintf(timenumber,256,"%s-%04hu%s-%02hhu",story,frame,subframe,round);\r
+}\r
+void specialid(char *timenumber, char *story, char frame)\r
 {\r
-       sprintf(timenumber,"%s-%04hu-%02hhu",story,frame,round);\r
-} 
\ No newline at end of file
+       snprintf(timenumber,256,"%s-%c",story,frame);\r
+} \r
index 20b4a61b4ad130dc67d03167fe84b0a57b50b0fd..01d7db5311c7367e87e262a7c9656dd96b54dd60 100644 (file)
@@ -1,8 +1,8 @@
 #// preview.awk\r
 #// Preview a post in the post edit interface\r
-#// 31.03.2015\r
+#// 25.05.2021\r
 #// \r
-#// Copyright (C) 2015  Balthasar SzczepaƄski\r
+#// Copyright (C) 2015, 2021  Balthasar SzczepaƄski\r
 #// \r
 #// This program is free software: you can redistribute it and/or modify\r
 #// it under the terms of the GNU Affero General Public License as\r
@@ -51,7 +51,7 @@ BEGIN{
        }\r
        # print "-->"\r
        close(argfile)\r
-       if(argtab["edit"] ~ /^[a-zA-Z0-9]+\-[0-9]+\-[0-9]+$/)\r
+       if(argtab["edit"] ~ /^[a-zA-Z0-9]+\-(([0-9]+[a-z]?\-[0-9]+)|([a-z]))$/)\r
        {\r
                argtab["forceID"]=argtab["edit"] ### reused from where it made more sense\r
                argfile= postpath argtab["forceID"]\r
@@ -83,7 +83,7 @@ BEGIN{
                }\r
                close(argfile)\r
        }\r
-       else if(argtab["addquote"] ~ /^[a-zA-Z0-9]+\-[0-9]+\-[0-9]+$/)\r
+       else if(argtab["addquote"] ~ /^[a-zA-Z0-9]+\-(([0-9]+[a-z]?\-[0-9]+)|([a-z]))$/)\r
        {\r
                argfile= postpath argtab["addquote"]\r
                while((getline argline < argfile)>0)\r
index 694be8d5a5c8bc663208312c70684d74d59f3cf7..670c4ffc1fcd38e980c67d4392163fd220ac5403 100644 (file)
--- a/remove.c
+++ b/remove.c
@@ -1,8 +1,8 @@
 // remove.c (1190.bicyclesonthemoon.info/aftertime/remove)\r
 // remove a post\r
-// 28.03.2015\r
+// 15.04.2019\r
 // \r
-// Copyright (C) 2015  Balthasar SzczepaƄski\r
+// Copyright (C) 2015, 2019  Balthasar SzczepaƄski\r
 // \r
 // This program is free software: you can redistribute it and/or modify\r
 // it under the terms of the GNU Affero General Public License as\r
@@ -45,9 +45,12 @@ int main(int argc, char **argv)
        char outpath[256];\r
        char argp1[256];\r
        char argp2[256];\r
+       char argp3[256];\r
        \r
        cgi=cgiInit();\r
        \r
+       // dup2(fileno(stdout),fileno(stderr));\r
+       // printf("Content-type: text/plain\n\n");\r
        \r
        rmov=((arg=cgiGetValue(cgi,"r"))?arg:&zero);\r
        \r
@@ -77,15 +80,16 @@ int main(int argc, char **argv)
                return 0;\r
        }\r
        \r
-       sprintf(inpath,"%s%s",POST_PATH,rmov);\r
+       snprintf(inpath,256,"%s%s",POST_PATH,rmov);\r
        \r
-       sprintf(argp1,"name=%s",username);\r
-       sprintf(argp2,"pass=%s",password);\r
+       snprintf(argp1,256,"name=%s",username);\r
+       snprintf(argp2,256,"pass=%s",password);\r
+       snprintf(argp3,256,"file=%s",inpath);\r
        \r
        sub=fork();\r
        if(sub==0)\r
        {\r
-               r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_VERIFY,"-v",argp1,"-v",argp2,inpath,(char *)0);\r
+               r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_VERIFY,"-v",argp1,"-v",argp2,"-v",argp3,(char *)0);\r
                exit(r);\r
        }\r
        waitpid(sub,&r,0);\r
@@ -94,7 +98,7 @@ int main(int argc, char **argv)
                cgiRedirect("/aftertime/list");\r
                return(0);\r
        }\r
-       sprintf(outpath,"%s%s",RMOV_PATH,rmov);\r
+       snprintf(outpath,256,"%s%s",RMOV_PATH,rmov);\r
        \r
        sub=fork();\r
        if(sub==0)\r
index 2bd73120f88eef5810f61a7e6ba05e6e22967581..728701dcb90d5ed1d2758b3d3fd420c62216d63b 100644 (file)
@@ -1,8 +1,8 @@
 #// upload.awk\r
 #// The post upload interface\r
-#// 21.12.2015\r
+#// 25.05.2021\r
 #// \r
-#// Copyright (C) 2015  Balthasar SzczepaƄski\r
+#// Copyright (C) 2015, 2019, 2021  Balthasar SzczepaƄski\r
 #// \r
 #// This program is free software: you can redistribute it and/or modify\r
 #// it under the terms of the GNU Affero General Public License as\r
@@ -20,7 +20,7 @@
 BEGIN{\r
        postpath="/eizm/mem/aftertime/mpost/"\r
        passpath="/eizm/mem/aftertime/pass/"\r
-       rmpath="/eizm/mem/aftertime/rm/"\r
+       rmpath="/eizm/mem/aftertime/mpost/rm/"\r
        bb2html="/eizm/pro/aftertime/bb2html.awk"\r
        automome="/eizm/pro/ong1/mome.pl"\r
        memepath="/eizm/mem/ong1/mome.txt"\r
@@ -108,7 +108,21 @@ BEGIN{
                else\r
                        split($0, idtab, "-")\r
                story=idtab[1]\r
-               frame=int(idtab[2])\r
+               if (idtab[2]~/^[a-z]/)\r
+               {\r
+                       frame=substr(idtab[2],1,1)\r
+                       subframe=""\r
+               }\r
+               else if(idtab[2]~/^[0-9]+[a-z]$/)\r
+               {\r
+                       frame=int(substr (idtab[2], 1, length(idtab[2])-1))\r
+                       subframe=substr (idtab[2], length(idtab[2]), 1)\r
+               }\r
+               else\r
+               {\r
+                       frame=int(idtab[2])\r
+                       subframe=""\r
+               }\r
                round=int(idtab[3])\r
        }\r
        else if(ln==2)\r
@@ -152,9 +166,23 @@ END{
        if(ln!=0)\r
                post()\r
 }\r
+\r
+\r
+function makeid(story,frame,subframe,round)\r
+{\r
+       if(frame ~ /^[a-z]/)\r
+       {\r
+               return sprintf("%s-%s",story,frame)\r
+       }\r
+       else\r
+       {\r
+               return sprintf("%s-%04u%s-%02u",story,frame,subframe,round)\r
+       }\r
+}\r
+\r
 function remove(   postid,postfile,rmfile,passfile,temp,f,tn,eq,tv,namef,passf)\r
 {\r
-       postid=sprintf("%s-%04u-%02u",story,frame,round)\r
+       postid=makeid(story,frame,subframe,round)\r
        postfile=postpath postid\r
        rmfile=rmpath postid\r
        passfile=passpath story\r
@@ -171,7 +199,7 @@ function remove(   postid,postfile,rmfile,passfile,temp,f,tn,eq,tv,namef,passf)
                print "Can't remove. Wrong username."\r
                return\r
        }\r
-       if(pass!=password)\r
+       if(pass!=passf)\r
        {\r
                print "Can't remove. Wrong password."\r
                return\r
@@ -187,7 +215,7 @@ function remove(   postid,postfile,rmfile,passfile,temp,f,tn,eq,tv,namef,passf)
 \r
 function quote(   postid,postfile,passfile,temp,f,opt,cont,ongt,subj,eq,tn,tv,id,namef,passf,yy,mm,dd,hh)\r
 {\r
-       postid=sprintf("%s-%04u-%02u",story,frame,round)\r
+       postid=makeid(story,frame,subframe,round)\r
        postfile=postpath postid\r
        passfile=passpath story\r
        \r
@@ -318,7 +346,7 @@ function post(   postid,replaceid,postfile,passfile,replacefile,temp,i,eq,tn,tv,
                return quote()\r
        if(rmov!="")\r
                return remove()\r
-       postid=sprintf("%s-%04u-%02u",story,frame,round)\r
+       postid=makeid(story,frame,subframe,round)\r
        printf("%s",postid" ")\r
        \r
        postfile=postpath postid\r
@@ -346,7 +374,7 @@ function post(   postid,replaceid,postfile,passfile,replacefile,temp,i,eq,tn,tv,
                print "Story name missing."\r
                return\r
        }\r
-       if(story !~ /^(t1i|bftf|t-1)$/)\r
+       if(story !~ /^(time|prickly|potm|lucky|beany|bean2|t1i|zodiac|bftf|t-1|bsta|advent|phys)$/) #this really shouldn't be hardcoded!\r
        {\r
                print "Unknown story."\r
                return\r
@@ -421,8 +449,13 @@ function post(   postid,replaceid,postfile,passfile,replacefile,temp,i,eq,tn,tv,
        print "username_h="htmlescape(name) >> postfile\r
        print "subject_h="htmlescape(subject) >> postfile\r
        print "story="story >> postfile\r
-       print "frame="sprintf("%04u",frame) >> postfile\r
-       print "round="sprintf("%02u",round) >> postfile\r
+       if (frame ~ /^[a-z]/)\r
+               print "frame="frame >> postfile\r
+       else\r
+       {\r
+               print "frame="sprintf("%04u",frame) >> postfile\r
+               print "round="sprintf("%02u",round) >> postfile\r
+       }\r
        \r
        print "h="htmlescape(h) >> postfile\r
        print "d="htmlescape(d) >> postfile\r
index a4ca33bf562ec5fe5a8e09dd8bb1cd071a3053c9..b94bffff5b2e0876f99097f043907d9427168601 100644 (file)
@@ -1,8 +1,8 @@
 #// verify.awk\r
 #// Check if post belongs to user\r
-#// 27.03.2015\r
+#// 15.04.2019\r
 #// \r
-#// Copyright (C) 2015  Balthasar SzczepaƄski\r
+#// Copyright (C) 2015, 2019  Balthasar SzczepaƄski\r
 #// \r
 #// This program is free software: you can redistribute it and/or modify\r
 #// it under the terms of the GNU Affero General Public License as\r
@@ -38,15 +38,24 @@ BEGIN{
                fail=1\r
        }\r
 }\r
-{\r
-       gsub(/[\r\n]/,"",$0)\r
-       eq=index($0,"=")\r
-       argtab[substr($0,1,eq-1)]=substr($0,eq+1)\r
-}\r
+{\r
+       gsub(/[\r\n]/,"",$0)\r
+       eq=index($0,"=")\r
+       argtab[substr($0,1,eq-1)]=substr($0,eq+1)\r
+}\r
 END{\r
+       while((getline line < file)>0)\r
+       {\r
+               gsub(/[\r\n]/,"",line)\r
+               eq=index(line,"=")\r
+               argtab[substr(line,1,eq-1)]=substr(line,eq+1)\r
+       }\r
+       close (file)\r
+       \r
        if(story=="")\r
                story=argtab["story"]\r
-       else if(story!=argtab["story"])\r
+       \r
+       else if(story!=argtab["story"] && argtab["story"]!="")\r
                exit fail\r
        \r
        passfile = passpath story\r
diff --git a/viewer.awk b/viewer.awk
new file mode 100644 (file)
index 0000000..50e2713
--- /dev/null
@@ -0,0 +1,687 @@
+#// viewer.awk
+#// The viewer
+#// 25.05.2021
+#// 
+#// Copyright (C) 2015-2021  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
+#// published by the Free Software Foundation, either version 3 of the
+#// License, or (at your option) any later version.
+#// 
+#// This program is distributed in the hope that it will be useful,
+#// but WITHOUT ANY WARRANTY; without even the implied warranty of
+#// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#// GNU Affero General Public License for more details.
+#// 
+#// You should have received a copy of the GNU Affero General Public License
+#// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+BEGIN{
+       FS=""
+       noticepath="/eizm/mem/aftertime/mpost/"
+       framepath="/eizm/www/time/"
+       datapath="/eizm/data/aftertime/"
+       timecmd="date -u +\"%Y%m%d%H\""
+       timecmd2="date +\"%H%M%S\""
+       timecmd3="date -u +\"%m%d%H%M\""
+       timecmd4="date -u +\"%s\""
+       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
+       }
+       
+       listfile = datapath "stories"
+       stories=0
+       line=""
+       while((getline line < listfile)>0)
+       {
+               gsub(/[\r\n]/,"",line)
+               eq=index(line,"=")
+               
+               storytab[stories]=htmlescape(substr(line, 1, eq-1),"","")
+               storyname[stories]=htmlescape(substr(line, eq+1),"","")
+               ++stories
+       }
+       close(listfile)
+       
+       if(frame ~ /[a-zA-Z]$/)
+       {
+               f=int(substr(frame,1,length(frame)-1))
+               s=substr(frame, length(frame))
+       }
+       else
+       {
+               f=int(frame)
+               s=""
+       }
+       e=int(enhance)
+       n=int(notice)
+       b=int(bbcode)
+       
+       timecmd | getline thistime
+               close(timecmd)
+       
+       timecmd2 | getline thistime2
+               close(timecmd2)
+       
+       timecmd3 | getline thistime3
+               close(timecmd3)
+       
+       timecmd4 | getline thistime4
+               close(timecmd4)
+               
+       thistime3=int(thistime3)
+       thistime4=int(thistime4)
+       
+       lastalt=0
+       
+       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
+       }
+       alttabsize=0
+}
+{
+       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
+               ++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)
+}
+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"
+               getline temp < statefile
+               close(statefile)
+               
+               split(temp, temptab, " ")
+               state=int(temptab[1])
+               last=int(temptab[2])
+               nextong=int(temptab[3])
+       }
+       else
+       {
+               last=int(argtab["last"])
+               state=3
+       }
+       first=int(argtab["first"])
+       
+       ongtimefile= datapath argtab["story"]"/ongtime"
+       
+       if(frame=="")
+       {
+               if(ongoing>0)
+               {
+                       if (int(argtab["onlyframe"])>0)
+                       {
+                               f=last
+                               onlyframe=1
+                       }
+                       else
+                       {
+                               onlyframe=""
+                               if (int(argtab["showlatest"])>0)
+                                       f=last
+                               else
+                                       f=first
+                       }
+               }
+               else
+               {
+                       f=first
+                       onlyframe=""
+                       if (replay != "")
+                       {
+                               # print "DEBUG:<br>"
+                               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<br>",ongt)
+                                       
+                                       if(!ongsy)
+                                       {
+                                               ongsy=1
+                                               ongyr=substr(line,ongind+1,4)
+                                               # printf("3.%d<br>",thistime3)
+                                               if(thistime3<ongt)
+                                               {
+                                                       thistime3 += 100000000
+                                                       # printf("3.%d<br>",thistime3)
+                                               }
+                                       }
+                                       
+                                       if(ongt>thistime3)
+                                       {
+                                               # if(ongsm)
+                                               # print"BREAK!<br>"
+                                                       break;
+                                       }
+                                       # else
+                                               # ongsm=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=""
+                                       }
+                                       # print"f."f"."s"<br>"
+                               }
+                               close(ongtimefile)
+                       }
+               }
+       }
+       
+       if (s!="")
+       {
+               if(argtab[s] != "")
+                       s2=argtab[s]
+               else
+                       s2=s
+               # n=-1
+       }
+       
+       if(f<first && argtab["cfrt"]=="")
+               f=first
+       
+       if(f>last && argtab["cfrt"]=="")
+               f=last
+       
+       if(argtab["special"] != "")
+       {
+               specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,s)
+               line=""
+               undertext=""
+               
+               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)
+                       }
+               }
+               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)
+               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] UTC$/)
+                       ongtimetext=ongt
+       }
+       close(ongtimefile)
+               
+       if ("alt" in argtab)
+               alt=htmlescape(argtab["alt"],"less","bb")
+       else
+       {
+               for(i=0; i<alttabsize; ++i)
+               {
+                       if(f>=alttabn[i] && alttabn[i]>=lastalt)
+                       {
+                               alt=htmlescape(alttab[i],"less","bb")
+                               lastalt=alttabn[i]
+                       }
+               }
+       }
+       
+       if(argtab["number"]!="")
+               numberformat=argtab["number"]
+       else
+       {
+               # if (sf!="")
+                       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?"&amp;e="e:"")"&amp;f="f s
+       
+       if((f>last || f<first || (this_sf!="" && s>this_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"])
+       
+       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!="")
+       {
+               prev_f = f
+               prev_s = num2ch[ch2num[s]-1]
+       }
+       else if(prev_sf!="")
+       {
+               prev_f = f-1
+               prev_s = prev_sf
+       }
+       else
+       {
+               prev_f = f-1
+               prev_s = ""
+       }
+       
+       if(prev_s!=""){
+               if(argtab[prev_s]!=""){
+                       prev_s2=argtab[prev_s]
+               }
+               else
+               {
+                       prev_s2=prev_s
+               }
+       }
+       else
+               prev_s2 = ""
+       if (next_s!="")
+       {
+               if(argtab[next_s]!=""){
+                       next_s2=argtab[next_s]
+               }
+               else
+               {
+                       next_s2=next_s
+               }
+       }
+       else
+               next_s2 = ""
+       
+       print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"\">"
+       print "<html lang=\"en\"><head>"
+       print "<title>"title" &bull; time after Time viewer &bull; Bicycles on the Moon</title>"
+       print "<meta http-equiv=\"Content-type\" content=\"text/html; charset=UTF-8\">"
+       print "<link rel=\"icon\" type=\"image/png\" href=\"/img/favicon.png\">"
+       print "<link rel=\"stylesheet\" href=\"/css/botm.css\">"
+       print "<link rel=\"index\" href=\"/aftertime/\">"
+       print "<link rel=\"start\" href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="first"\">"
+       if(f>first)
+       {
+               print "<link rel=\"prev\" href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="prev_f prev_s"\">"
+       }
+       if(f<last)
+       {
+               print "<link rel=\"next\" href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="next_f next_s"\">"
+               print "<link rel=\"prefetch\" href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="next_f next_s"\">"
+       }
+       print "</head><body><center>"
+       print "<a href=\"/\"><img src=\"/img/botmlogo2.png\" alt=\"1190.bicyclesonthemoon.info\" border=\"0\"></a><br>"
+       print "<H1>"title"</H1>"
+       print "<table cellspacing=\"0\" cellpadding=\"0\""(argtab["width"]!=""?" width=\""width"\"":"")">"
+       print "<tr width=\""width"\" align=\"center\"><td colspan=\"4\" width=\"100%\">"
+       if(onlyframe!="")
+               print "<a href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="f s"\">"
+       print "<img src=\""((ongoing>0 && state <2 && f==last)?dynamicframe:frame)"\" alt=\""title"\" title=\""alt"\" border=\""border"\">"
+       if(onlyframe!="")
+               print "</a>"
+       print "</td></tr>"
+       
+       if(ongoing==1)
+       {
+               # print "<tr width=\""width"\" align=\"right\"><td colspan=\"4\" width=\"100%\">"
+               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"
+                       }
+               }
+               else
+               {
+                       ss="EE"
+                       mm="EE"
+                       hh="EE"
+               }
+               # hh=nextong" "thistime4
+               timecolor=(state>1?"br":"ni")
+       
+               print "<tr width=\""width"\" align=\"right\"><td colspan=\"4\" width=\"100%\"><tt><b class=\""timecolor"\">"hh"</b>:<b class=\""timecolor"\">"mm"</b>:<b class=\""timecolor"\">"ss"</b></tt></td></tr>"
+       }
+       
+       if(onlyframe=="")
+       {
+               if(max_enhance>0)
+               {
+                       print "<tr width=\""width"\" align=\"center\"><td colspan=\"4\" width=\"100%\">["
+                       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)
+                                               print"<b>"argtab["enhance-"i]"</b>"
+                                       else
+                                               print"<a href=\"/aftertime/viewer?story="argtab["story"]"&amp;e="i"&amp;f="f s((b>0)?("&amp;b="b):"")"\">"argtab["enhance-"i]"</a>"
+                               }
+                               else
+                                       print argtab["enhance-"i]
+                       }
+                       print "]</td></tr>"
+               }
+                               
+               print "<tr width=\""width"\" align=\"center\">"
+               print "<td width=\"25%\"><a href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="first"\">|&lt; "sprintf(numberformat,first,"")"</a></td>"
+               print "<td width=\"25%\">"(f>first?"<a href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="prev_f prev_s"\">&lt; "sprintf(numberformat,prev_f,prev_s2)"</a>":"")"</td>"
+               print "<td width=\"25%\">"(f<last?"<a href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="next_f next_s"\">"sprintf(numberformat,next_f,next_s2)" &gt;</a>":"")"</td>"
+               print "<td width=\"25%\"><a href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="last"\">"sprintf(numberformat,last,"")" &gt;|</a></td>"
+               print "</tr>"
+               
+               if(ongtimetext!="")
+               {
+                       if(argtab["ID"]!="")
+                       {
+                               print "<tr width=\""width"\" align=\"right\"><td colspan=\"4\" width=\"100%\"><a href=\""postlink"&p="int(argtab["ID"])"#p"int(argtab["ID"])"\">"ongtimetext"</a></td></tr>"
+                       }
+                       # else if (argtab["otherviewerurl"]!="")
+                       # {
+                               # print "<tr width=\""width"\" align=\"right\"><td colspan=\"4\" width=\"100%\"><a href=\""otherviewerurl"\">"ongtimetext"</a></td></tr>"
+                       # }
+                       else
+                               print "<tr width=\""width"\" align=\"right\"><td colspan=\"4\" width=\"100%\">"ongtimetext"</td></tr>"
+               }
+               
+               if(argtab["HTML"]!="" && b==0)
+               {
+                       print "<tr width=\""width"\"><td colspan=\"4\" width=\"100%\">"argtab["HTML"]"</td></tr>"
+               }
+               
+               for(i=-1; i<=n; ++i)
+               {
+                       if(i<0)
+                               noticepost=noticepath argtab["story"]"-i"
+                       else
+                               noticepost=noticepath argtab["story"]"-"sprintf("%04u%s",f,s)"-"sprintf("%02u",i+1)
+                       # print "<!-- ######## "noticepost"######## -->" 
+                       split("", noticetab, ":")
+                       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)
+                       }
+                       close(noticepost)
+                       if(j==0)
+                       {
+                               if(i<0)
+                                       continue;
+                               else
+                                       break;
+                       }
+                       if(i>=0)
+                       {
+                               nposttime=noticetab["y"]noticetab["m"]noticetab["d"]noticetab["h"]
+                               if (thistime<nposttime)
+                                       break;
+                       }
+                       if(i<n)
+                       {
+                               if(i>=0)
+                                       print "<tr width=\""width"\"><td colspan=\"4\" width=\"100%\"><i>"noticetab["subject_h"]"</i> "(noticetab["ID"]!=""?"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<a href=\"/ott/view?p="noticetab["ID"]"#p"noticetab["ID"]"\">OTT time travel</a>)":"")"</td></tr>"
+                               print"<tr width=\""width"\"><td colspan=\"4\" width=\"100%\">"((noticetab["HTML"]!="")?noticetab["HTML"]:noticetab["BBHTML"])"</td></tr>"
+                       }
+                       else
+                       {
+                               print "<tr width=\""width"\" align=\"center\"><td colspan=\"4\" width=\"100%\"><a href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="f s"&amp;n="i+1"\">"noticetab["subject_h"]"</a></td></tr>"
+                       }
+               }
+               
+               if(b>0)
+               {
+                       if (argtab["BBHTML"]!="")
+                       {
+                               bbtext=argtab["BBHTML"]
+                       }
+                       else if (argtab["text"]!="")
+                       {
+                               bbtext=htmlescape(argtab["text"],"less","bb")
+                               gsub(/  /,"\\&nbsp; ",bbtext)
+                               gsub(/  /," \\&nbsp;",bbtext)
+                       }
+                       
+                       print "<tr width=\""width"\"><td colspan=\"4\" width=\"100%\">"
+                       print"<code>[url="botcastleurl"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="f s"][img]"botcastleurl frame"[/img][/url]"(bbtext!=""?"<br>"bbtext:"")(b>1 && alt!=""?"[spoiler]"alt"[/spoiler]":"")
+                       print"</code></td></tr>"
+                       
+                       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))
+                       {
+                               print "<tr width=\""width"\" align=\"center\"><td colspan=\"4\" width=\"100%\">"
+                               print "<form method=\"post\" action=\"/aftertime/pleaseongthis\">"
+                               print "[<input type=\"submit\" class=\"hl\" value=\"ONG this for me\">]"
+                               print "<input type=\"hidden\" name=\"story\" value=\""argtab["story"]"\">"
+                               if(e>0 && noenh=="")
+                                       print "<input type=\"hidden\" name=\"e\" value=\""e"\">"
+                               print "</form></td></tr>"
+                       }
+                       if(b==1 && alt!="")
+                               print "<tr width=\""width"\" align=\"center\"><td colspan=\"4\" width=\"100%\">[<a href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="f s"&amp;b=2\">spoiler</a>]</td></tr>"
+               }
+               else
+                       print "<tr width=\""width"\" align=\"center\"><td colspan=\"4\" width=\"100%\">[<a href=\"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&amp;e="e:"")"&amp;f="f s"&amp;b=1\">bbcode</a>]</td></tr>"
+               
+               if(argtab["otherviewerurl"]!="")
+                       print "<tr width=\""width"\" align=\"center\"><td colspan=\"4\" width=\"100%\">[<a href=\""otherviewerurl"\">"argtab["otherviewertext"]"</a>]</td></tr>"
+               
+               print "<tr width=\""width"\" align=\"center\"><td colspan=\"4\" width=\"100%\"><form method=\"get\" action=\"/aftertime/viewer\">Go to frame:"
+               print "<input type=\"hidden\" name=\"story\" value=\""argtab["story"]"\">"
+               if(max_enhance>0)
+                       print "<input type=\"hidden\" name=\"e\" value=\""e"\">"
+               print "<input class=\"pt\" type=\"text\" name=\"f\" size=\"4\">"
+               print "<input class=\"pk\" type=\"submit\" value=\"GO\">"
+               if(ongtimetext!="" && ongoing==0)
+               {
+                       # print ongoing
+                       # print"<form method=\"get\" action=\"/aftertime/viewer\">"
+                       # print "<input type=\"hidden\" name=\"story\" value=\""argtab["story"]"\">"
+                       # if(max_enhance>0)
+                               # print "<input type=\"hidden\" name=\"e\" value=\""e"\">"
+                       # print "<input type=\"hidden\" name=\"r\" value=\"1\">"
+                       print "<input class=\"pk\" name=\"r\" type=\"submit\" value=\"replay\">"
+                       # print "</form>"
+               }
+               
+               print"</form></td></tr>"
+               
+               print "<tr width=\""width"\" align=\"center\"><td colspan=\"4\" width=\"100%\"><form method=\"get\" action=\"/aftertime/viewer\">Go to story:<select class=\"pk\" name=\"story\">"
+               for(i=0; i<stories; ++i)
+                       print "<option value=\""storytab[i]"\""(storytab[i]==argtab["story"]?" selected":"")">"storyname[i]"</option>"
+               print "</select> <input class=\"pk\" type=\"submit\" value=\"GO\"></form></td></tr>"
+               
+               print "<tr width=\""width"\" align=\"center\"><td colspan=\"4\" width=\"100%\"><a href=\"http://1190.bicyclesonthemoon.info/aftertime\">Aftertime ONGsystem</a></td></tr>"
+       }
+       print "</table>"
+       
+       print "<br><a href=\"/\">1190.bicyclesonthemoon.info</a>"
+       print "</center></body></html>"
+       
+       
+}
+
+function htmlescape(name,less,br,   len,iii,escaped,ch)
+{
+       len=length(name)
+       escaped=""
+       for(iii=1;iii<=len;++iii)
+       {
+               ch=substr(name,iii,1);
+               if(ch == "\n")
+                       escaped = escaped ((br!="")?"<br>":"&#"ch2dec[ch]";")
+               else if(ch =="\r")
+                       escaped = escaped ((br!="")?"":"&#"ch2dec[ch]";")
+               else if(ch ~ /[\" ]/ && less=="")#"#"\""
+                       escaped = escaped "&#"ch2dec[ch]";"
+               else if(ch ~ /[=<>&]/)
+                       escaped = escaped "&#"ch2dec[ch]";"
+               else
+                       escaped = escaped ch
+       }
+       return escaped
+}