home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "util.h"
- #define CHOICES 20
- #define LOG "/usr/httpd/logs/eightball_log.html"
- #define LF 10
-
- int main(void)
- {
-
- int cont_len; /* number of bytes to read from stdin*/
- unsigned char rn; /* random number */
- FILE *questions; /* pointer to the log file */
- char *entry; /* value of the data string */
- /* 20 answers of the icosahedron */
- static char *message[]={
- "Yes",
- "No",
- "Maybe",
- "My reply is YES",
- "Reply Hazy try again",
- "Concentrate and ask again",
- "Definitely",
- "Signs point to YES",
- "Ask again later",
- "Without a doubt",
- "It is certain",
- "Outlook not so good",
- "My reply is NO!",
- "Don't count on it",
- "Outlook good",
- "Most likely",
- "VERY doubtful",
- "My sources say no",
- "You may rely on it",
- "It is decidedly so"
- };
-
- /* getstring length */
- cont_len = atoi(getenv("CONTENT_LENGTH"));
- /* store data string in entry */
- entry = fmakeword(stdin, '&', &cont_len);
- /* replace +s with spaces */
- plustospace(entry);
- /* unescape any special character
- unescape_url(entry);
- /* store value of name/value pair in entry */
- makeword(entry,'=');
- /* print standard MIME header */
- printf("Content-type: text/html%c%c",LF,LF);
-
- if (!(questions=fopen(LOG,"a")))
- printf(stderr,"unable to open log file");
-
- /* seed the random generator */
- srand(getpid());
-
- rn = rand()%20; /* take a random number between 0..19*/
-
- /* add the question and answer to the log */
- fprintf(questions, "<pre>%s </pre>",entry);
- fprintf(questions, "<B> %s</B><hr>\n",message[rn]);
-
- fclose(questions);
- /* return the answer page to the user */
- printf("<title>Magic 8-ball reply</title>%c",LF);
- printf("The Magic Eight Ball has thought long");
- printf(" and hard about your question and has come");
- printf(" to the following answer:<p>%c<hr>%c",LF,LF);
- printf("<H1>%s</H1>%c<hr>",message[rn],LF);
- printf("<a href=\"http://found.cs.nyu.edu/shaggy.a/downing/public-html/eightball.html\">Return to 8-ball</a><p>");
- printf("<a href=\"http://found.cs.nyu.edu/shaggy.a/downing/public-html/index.html\">Troy's page</a><p><hr>%c",LF);
- printf("If you find public/anonymous postings in a log format %c",LF);
- printf("offensive, or embarrassing, ");
- printf("then please do not read the 8-ball log <p>%c",LF);
- printf("<a href=\"logs/eightball_log.html\"> Read 8-ball log</a><p>");
- printf("%c<hr>",LF);
- }
-
-
-
-