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

  1. /* This program parses a form that contains 3 input fields: a name 
  2. suggestion for 
  3.     my expected new baby, a sex which could be male/female/either, 
  4. and a comment 
  5.     the suggestions are added to a database that I╒m keeping until I 
  6. actually have to
  7.     name the kid. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "util.h"
  12. #define LF              10
  13. #define MAX_ENT         100        
  14. #define NAME            0
  15. #define SEX             1
  16. #define COMMENT         2
  17. #define NAMES           "/usr/pub/names"
  18. typedef struct {
  19.                char *name;
  20.                char *val;
  21.                } entry;
  22.  
  23. void main(int argc, char *argv[])
  24. {
  25.  
  26.        entry entries[MAX_ENT];
  27.        int cont_len,index,marker;
  28.        char address[256];
  29.        FILE *names;
  30.  
  31.        index=marker=0;
  32.  
  33.        cont_len = atoi(getenv("CONTENT_LENGTH"));
  34.    for(index=0;cont_len&& (!feof(stdin));index++)
  35.    {
  36.        marker=index;
  37.        entries[index].val = fmakeword(stdin,'&',&cont_len);
  38.                plustospace(entries[index].val);
  39.        unescape_url(entries[index].val);
  40.        entries[index].name = makeword(entries[index].val,'=');
  41.    }
  42.        printf("Content-type: text/html%c%c",LF,LF);
  43.        names = fopen(NAMES, "a");
  44.          
  45. fprintf(names,"%s\t\t%s\t%s\n",entries[NAME].val,entries[SEX].val,
  46.                entries[COMMENT].val);
  47.        fclose(names);
  48.        system("/usr/bin/sort /shaggy.a/downing/pub/names > 
  49. /shaggy.a/downing/pu
  50. b/tmp");
  51.        system("/usr/bin/mv /shaggy.a/downing/pub/tmp 
  52. /shaggy.a/downing/pub/names");
  53.        printf("<h1>Thanks for your suggestion!</h1> %c",LF);
  54.        printf("<h2>I will take the name \"%s\" into serious 
  55. consideration!<p>",entries[NAME].val);
  56.        printf("<a 
  57. href=\"http://found.cs.nyu.edu/shaggy.a/downing/pub/names\">"
  58. );
  59.        printf("List of names</a><p>");
  60.        printf("<a 
  61. href=\"http://found.cs.nyu.edu/downing\">return</a><p>");
  62.        exit(0);
  63. }
  64.  
  65.