]> bicyclesonthemoon.info Git - ott/enhance/blob - relink.c
Update from src directory as of 26.11.2016
[ott/enhance] / relink.c
1 // relink.c (1190.bicyclesonthemoon.info/ongoing.png (old))\r
2 // redirect to the latest frame\r
3 // 06.04.2015\r
4 // \r
5 // Copyright (C) 2015  Balthasar SzczepaƄski\r
6 // \r
7 // This program is free software: you can redistribute it and/or modify\r
8 // it under the terms of the GNU Affero General Public License as\r
9 // published by the Free Software Foundation, either version 3 of the\r
10 // License, or (at your option) any later version.\r
11 // \r
12 // This program is distributed in the hope that it will be useful,\r
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 // GNU Affero General Public License for more details.\r
16 // \r
17 // You should have received a copy of the GNU Affero General Public License\r
18 // along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
19 \r
20 #define ONG_STATE_PATH "/eizm/data/aftertime/bftf/ongstate"\r
21 #define RELINK_PATH    "/ongframe.png?f=%hu"\r
22 \r
23 #include <cgi.h>\r
24 #include <stdio.h>\r
25 \r
26 s_cgi *cgi;\r
27 \r
28 int main (int argc, char *argv[])\r
29 {\r
30         FILE *file;\r
31         char relinkPath[256];\r
32         unsigned short ongFrame;\r
33         unsigned char ongState;\r
34         \r
35         cgi=cgiInit();\r
36         \r
37         file=fopen(ONG_STATE_PATH,"rt");\r
38         if(file!=NULL)\r
39         {\r
40                 fscanf(file,"%hhu %hu",&ongState,&ongFrame);\r
41                 fclose(file);\r
42         }\r
43         else\r
44         {\r
45                 ongState=0;\r
46                 ongFrame=0;\r
47         }\r
48         \r
49         if(ongState==1)\r
50         {\r
51                 file=fopen(ONG_STATE_PATH,"wt");\r
52                 if(file!=NULL)\r
53                 {\r
54                         fprintf(file,"2 %hu",ongFrame);\r
55                         fclose(file);\r
56                 }\r
57         }\r
58         \r
59         sprintf(relinkPath,RELINK_PATH,(unsigned short)ongFrame);\r
60         cgiRedirect(relinkPath);\r
61         \r
62         return 0;\r
63 }