home *** CD-ROM | disk | FTP | other *** search
/ The HTML Web Publisher's Construction Kit / HTMLWPCK.ISO / unix / cgi / c_src / eightbal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-27  |  2.7 KB  |  81 lines

  1. #include <stdio.h>
  2. #include "util.h"
  3. #define CHOICES         20
  4. #define LOG             "/usr/httpd/logs/eightball_log.html"
  5. #define LF              10
  6.  
  7. int main(void)
  8. {
  9.  
  10.        int cont_len;     /* number of bytes to read from stdin*/
  11.        unsigned char rn; /* random number */
  12.        FILE *questions; /* pointer to the log file */
  13.        char *entry;     /* value of the data string */
  14.       /* 20 answers of the icosahedron */
  15.        static char *message[]={ 
  16.          "Yes",
  17.          "No",
  18.          "Maybe",
  19.          "My reply is YES",
  20.          "Reply Hazy try again",
  21.          "Concentrate and ask again",
  22.          "Definitely",
  23.          "Signs point to YES",
  24.          "Ask again later",
  25.          "Without a doubt",
  26.          "It is certain",
  27.          "Outlook not so good",
  28.          "My reply is NO!",
  29.          "Don't count on it",
  30.          "Outlook good",
  31.          "Most likely",
  32.          "VERY doubtful",
  33.          "My sources say no",
  34.          "You may rely on it",
  35.          "It is decidedly so"
  36.        };
  37.  
  38.       /* getstring length */
  39.        cont_len = atoi(getenv("CONTENT_LENGTH")); 
  40.       /* store data string in entry */   
  41.       entry = fmakeword(stdin, '&', &cont_len);
  42.       /* replace +s with spaces */
  43.        plustospace(entry);
  44.        /* unescape any special character
  45.        unescape_url(entry);
  46.       /* store value of name/value pair in entry */
  47.        makeword(entry,'=');
  48.       /* print standard MIME header */
  49.        printf("Content-type: text/html%c%c",LF,LF);
  50.  
  51.        if (!(questions=fopen(LOG,"a")))
  52.                printf(stderr,"unable to open log file");
  53.  
  54.       /* seed the random generator */
  55.        srand(getpid());
  56.  
  57.        rn = rand()%20; /* take a random number between 0..19*/
  58.  
  59.       /* add the question and answer to the log */
  60.        fprintf(questions, "<pre>%s </pre>",entry);
  61.        fprintf(questions, "<B> %s</B><hr>\n",message[rn]);
  62.  
  63.        fclose(questions);
  64.       /* return the answer page to the user */
  65.        printf("<title>Magic 8-ball reply</title>%c",LF);
  66.        printf("The Magic Eight Ball has thought long");
  67.        printf(" and hard about your question and has come");
  68.        printf(" to the following answer:<p>%c<hr>%c",LF,LF);
  69.        printf("<H1>%s</H1>%c<hr>",message[rn],LF);
  70.        printf("<a href=\"http://found.cs.nyu.edu/shaggy.a/downing/public-html/eightball.html\">Return to 8-ball</a><p>");
  71.        printf("<a href=\"http://found.cs.nyu.edu/shaggy.a/downing/public-html/index.html\">Troy's page</a><p><hr>%c",LF);
  72.        printf("If you find public/anonymous postings in a log format %c",LF);
  73.        printf("offensive, or embarrassing, ");
  74.        printf("then please do not read the 8-ball log <p>%c",LF);
  75.        printf("<a href=\"logs/eightball_log.html\"> Read 8-ball log</a><p>");
  76.        printf("%c<hr>",LF);
  77. }
  78.  
  79.  
  80.  
  81.