+++ /dev/null
-#! /usr/bin/mawk -f
-
-#// notice4.awk
-#// Add SilentBot's posts' ID to the viewer
-#// 31.03.2015
-#//
-#// Copyright (C) 2015 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{
- lasttime="/eizm/mem/t1i/notice/lasttime"
- list="/eizm/mem/t1i/mpost/sent/"
- list2="/eizm/mem/aftertime/mpost/"
-
- listcmd="/bin/ls -1 --color=never "list
-
-
- getline lastpost < lasttime
- close(lasttime)
-
- if(lastpost=="")
- lastpost="0000000000"
-
- while ((listcmd | getline postid)>0)
- {
- if (postid !~ /^[0-9A-F]+_53696C656E7454696D6572/)
- continue
-
- number=substr(postid,1,index(postid,"_")-1)
-
- if (number<=lasttime)
- continue
-
- postfile=list postid
-
- split("", argtab, ":")
- while((getline line < postfile)>0)
- {
- f=1
- gsub(/[\r\n]/,"",line)
- eq=index(line,"=")
- argtab[substr(line,1,eq-1)]=substr(line,eq+1)
- }
- close (postfile)
- if(argtab["ID"]=="")
- continue
-
- if(argtab["subject_h"]!~/t1i-[0-9][0-9][0-9][0-9]$/)
- continue
-
- ottid=argtab["ID"]
-
- frame=substr(argtab["subject_h"], length(argtab["subject_h"])-3)
-
- y=substr(number,1,4)
- m=substr(number,5,2)
- d=substr(number,7,2)
- h=substr(number,9,2)
-
-
- for(i=1;i<100;++i)
- {
- postfile=list2 "t1i-"frame"-"sprintf("%02u",i)
-
- split("", argtab, ":")
- while((getline line < postfile)>0)
- {
- f=1
- gsub(/[\r\n]/,"",line)
- eq=index(line,"=")
- argtab[substr(line,1,eq-1)]=substr(line,eq+1)
- }
- close (postfile)
-
- if(argtab["timenumber"]=="")
- break;
-
- if(argtab["y"]!=y || argtab["m"]!=m || argtab["d"]!=d || argtab["h"]!=h)
- continue
-
- if(argtab["ID"]!="")
- break;
-
- print "ID="ottid >> postfile
- close(postfile)
-
- #print argtab["timenumber"]
-
- print number > lasttime
- close(lasttime)
-
- }
- }
- close(listcmd)
-}
\ No newline at end of file
+++ /dev/null
-// viewer.c (1190.bicyclesonthemoon.info/bluet1i/viewer)
-// The viewer
-// 08.04.2015
-//
-// Copyright (C) 2015 Balthasar SzczepaĆ
-//
-// 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/>.
-
-#define MAX 1414
-#define NOTICE_PATH "/eizm/mem/aftertime/mpost/"
-#define OLD_NOTICE_PATH "/eizm/mem/t1i/notice/"
-#define AWK_NOTICE "/eizm/pro/t1i/notice.awk"
-#define MAWK_PATH "/usr/bin/mawk"
-#define REDIRECT "/aftertime/viewer?story=t1i"
-
-#include <cgi.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/wait.h>
-
-s_cgi *cgi;
-
-int main (int argc, char *argv[])
-{
- s_cgi *cgi;
- pid_t sub;
- int r;
-
- char *value;
- char *bb;
- char *spoiler;
- char *blue;
- char *nn;
-
- unsigned char round;
- unsigned short cgiFrame;
- unsigned char bl;
- char alttext[256];
- char notice[256];
- char arg1[256];
- char arg2[256];
- char redirect[256];
-
- FILE *file;
- unsigned char i;
-
- cgi=cgiInit();
-
- value=cgiGetValue(cgi,"f");
- if(value!=NULL)
- sscanf(value,"%hu",&cgiFrame);
- else
- cgiFrame=0;
-
- nn=cgiGetValue(cgi,"n");
- if(nn!=NULL)
- sscanf(nn,"%hhu",&round);
- else
- round=0;
-
- blue=cgiGetValue(cgi,"blue");
- if(blue!=NULL)
- sscanf(blue,"%hhu",&bl);
- else
- bl=1;
-
- bb=cgiGetValue(cgi,"b");
- spoiler=cgiGetValue(cgi,"s");
-
-#if defined REDIRECT
- strcpy(redirect,REDIRECT);
- if(value!=NULL)
- sprintf(redirect+strlen(redirect),"&f=%s",value);
- if(nn!=NULL)
- sprintf(redirect+strlen(redirect),"&n=%s",nn);
- if(blue!=NULL)
- sprintf(redirect+strlen(redirect),"&e=%s",blue);
- if(bb!=NULL)
- sprintf(redirect+strlen(redirect),"&b=%s",bb);
- cgiRedirect(redirect);
- return 0;
-#endif
-
- if(cgiFrame<0)
- cgiFrame=0;
- else if(cgiFrame>MAX)
- cgiFrame=MAX;
-
- if(cgiFrame>=1400)
- strcpy(alttext,"The end.");
- else if(cgiFrame>=1381)
- strcpy(alttext,"...");
- else if(cgiFrame>=1196)
- strcpy(alttext,"Wait for it.");
- else if(cgiFrame>=1192)
- strcpy(alttext,"...");
- else if(cgiFrame>=1185)
- strcpy(alttext,"Wait for it.");
- else if(cgiFrame>=1174)
- strcpy(alttext,"...");
- else if(cgiFrame>=1172)
- strcpy(alttext,"LOOK OUT!");
- else if(cgiFrame>=1158)
- strcpy(alttext,"...");
- else if(cgiFrame>=1046)
- strcpy(alttext,"LOOK OUT!");
- else if(cgiFrame>=1039)
- strcpy(alttext,"...");
- else if(cgiFrame>=1007)
- strcpy(alttext,"Wait for it.");
- else if(cgiFrame>=1002)
- strcpy(alttext,"...");
- else if(cgiFrame>=972)
- strcpy(alttext,"LOOK OUT!");
- else if(cgiFrame>=961)
- strcpy(alttext,"...");
- else if(cgiFrame>=715)
- strcpy(alttext,"Wait for it.");
- else if(cgiFrame>=687)
- strcpy(alttext,"...");
- else if(cgiFrame>=653)
- strcpy(alttext,"LOOK OUT!");
- else if(cgiFrame>=633)
- strcpy(alttext,"...");
- else
- strcpy(alttext,"Wait for it.");
-
- printf("Content-type: text/html\n\n");
-
- puts("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"\">\n");
- puts("<html lang=\"en\"><head>\n");
- printf("<title>%04hu • bluet1i viewer • Bicycles on the Moon</title>\n", cgiFrame);
- puts("<meta http-equiv=\"Content-type\" content=\"text/html; charset=UTF-8\">\n");
- puts("<link rel=\"icon\" type=\"image/png\" href=\"/img/favicon.png\">\n");
- puts("<link rel=\"stylesheet\" href=\"/css/botm.css\">\n");
- puts("</head><body><center>\n");
- puts("<a href=\"/\"><img src=\"/img/botmlogo2.png\" alt=\"1190.bicyclesonthemoon.info\" border=\"0\"></a><br>\n");
- printf("<H1>%st1i-%04hu</H1>\n",bl?((bl>1)?((bl>2)?"no fading ":"very blue "):"blue "):"",cgiFrame);
- puts("<table cellspacing=\"0\" cellpadding=\"0\"><tr><td colspan=\"4\" width=\"553\">\n");
-
- printf("<img src=\"/bluet1i/%s-%04hu.png\" alt=\"the frame, a png file\" title=\"%s\" border=\"0\"><br>\n",bl?((bl>1)?((bl>2)?"nofading":"hyperblue"):"bluet1i"):"t1i",cgiFrame,alttext);
-
- printf("<tr align=\"center\"><td width=\"138\"><a href=\"/bluet1i/viewer?f=0&blue=%hhu\">| < 0</a></td>\n",bl);
- if(cgiFrame>0)
- printf("<td width=\"138\"><a href=\"/bluet1i/viewer?f=%hu&blue=%hhu\">< %hu</a>\n",cgiFrame-1,bl,cgiFrame-1);
- else
- puts("<td width=\"138\"></td>\n");
- if(cgiFrame<MAX)
- printf("<td width=\"138\"><a href=\"/bluet1i/viewer?f=%hu&blue=%hhu\">%hu ></a>\n",cgiFrame+1,bl,cgiFrame+1);
- else
- puts("<td width=\"138\"></td>\n");
- printf("<td width=\"139\"><a href=\"/bluet1i/viewer?f=%hu&blue=%hhu\">%hu >|</a></tr>\n",MAX,bl,MAX);
-
- puts("<tr align=\"center\"><td colspan=\"4\">[ ");
- if(bl!=0)
- printf("<a href=\"/bluet1i/viewer?f=%hu&blue=0\">original</a>",cgiFrame);
- else
- puts("<b>original</b>");
- puts(" | ");
- if(bl!=1)
- printf("<a href=\"/bluet1i/viewer?f=%hu&blue=1\">blue</a>",cgiFrame);
- else
- puts("<b>blue</b>");
- puts(" | ");
- if(bl!=2)
- printf("<a href=\"/bluet1i/viewer?f=%hu&blue=2\">very blue</a>",cgiFrame);
- else
- puts("<b>very blue</b>");
- puts(" | ");
- if(bl!=3)
- printf("<a href=\"/bluet1i/viewer?f=%hu&blue=3\">no fading</a>",cgiFrame);
- else
- puts("<b>no fading</b>");
- puts(" ]</td></tr>\n");
-
- for(i=0;i<=round;++i)
- {
- sprintf(notice,"%st1i-%04hu-%02hhu",NOTICE_PATH,cgiFrame,i+1);
- sprintf(arg1,"url=/bluet1i/viewer?f=%hu&blue=%hhu&n=%hhu",cgiFrame,bl,i+1);
- sprintf(arg2,"round=%hhu",round);
-
- fflush(stdout);
- sub=fork();
- if(sub==0)
- {
- // setvbuf(stdout, NULL, _IONBF, 0);
- // dup2(fileno(stdout),fileno(stderr));
- r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_NOTICE,"-v",arg1,"-v",arg2,notice,(char *)0);
- exit(r);
- }
- waitpid(sub,&r,0);
- if(r)
- {
- if(!i)
- {
- sprintf(notice,"%s%04hu",OLD_NOTICE_PATH,cgiFrame);
- file=fopen(notice,"rt");
- if(file!=NULL)
- {
- fgets(notice,255,file);
- fclose(file);
- printf("<tr align=\"center\"><td colspan=\"4\"><a href=\"http://forums.xkcd.com/viewtopic.php?p=%s#p%s\">Did you notice . . . . </a></td></tr>\n",notice,notice);
- }
- }
- break;
- }
-
- }
-
- if(bb!=NULL)
- {
- printf("<tr><td colspan=\"4\"><code>[url=http://1190.bicyclesonthemoon.info/bluet1i/viewer?f=%hu&blue=%hhu][img]http://1190.bicyclesonthemoon.info/bluet1i/%s-%04hu.png[/img][/url]",cgiFrame,bl,bl?((bl>1)?((bl>2)?"nofading":"hyperblue"):"bluet1i"):"t1i",cgiFrame);
- if(spoiler!=NULL)
- printf("[spoiler]%s[/spoiler]",alttext);
- printf("</code></td></tr>\n");
- if(spoiler==NULL)
- printf("<tr align=\"center\"><td colspan=\"4\">[<a href=\"/bluet1i/viewer?f=%hu&blue=%hhu&b=1&s=1\">spoiler</a>]</td></tr>\n",cgiFrame,bl);
- }
- else
- printf("<tr align=\"center\"><td colspan=\"4\">[<a href=\"/bluet1i/viewer?f=%hu&blue=%hhu&b=1\">bbcode</a>]</td></tr>\n",cgiFrame,bl);
-
- printf("<tr align=\"center\"><td colspan=\"4\">[<a href=\"http://xkcd.mscha.org/vieweraftertime/t1i-%04hu\">this frame in mscha's viewer</a>]</td></tr>\n",cgiFrame);
-
- printf("<tr align=\"center\"><td colspan=\"4\"><form method=\"get\" action=\"/bluet1i/viewer\">go to frame:<input type=\"hidden\" name=\"blue\" value=\"%hhu\"><input class=\"pt\" type=\"text\" name=\"f\" size=\"4\"><input class=\"pk\" type=\"submit\" value=\"GO\"></form></td></tr>\n",bl);
-
- puts("</table><br>\n");
- puts("<a href=\"/\">1190.bicyclesonthemoon.info</a>\n");
- puts("<ul><li><a href=\"/pro/bluenh/bluenh.htm\">bluenhancement</a></li>\n");
- puts("<li><a href=\"/pro/nofading/nofading.htm\">no fading</a></li></ul>\n");
- puts("</center></body></html>\n");
-
- return 0;
-}
\ No newline at end of file