


#include <stdio.h>

typedef struct {
    char name[128];
    char val[128];
} entry;

void getword(char *word, char *line, char stop);
char x2c(char *what);
void unescape_url(char *url);
void plustospace(char *str);



main(int argc, char *argv[]) {
    entry entries[10000];
    register int x,m=0;
    char cl[128000];

    printf("Content-type: text/html%c%c",10,10);
    if(argc==1) {
        printf("No query information sent. Sorry.%c",10);
        exit(1);
    }

    cl[0] = '\0';
    strcpy(cl,argv[1]);
    /* Re-assemble possibly separated string */
    for(x=2;x<=argc-1;++x) {
        strcat(cl," ");
        strcat(cl,argv[x]);
    }   

    for(x=0;cl[0] != '\0';x++) {
        m=x;
        getword(entries[x].val,cl,'&');
        plustospace(entries[x].val);
        unescape_url(entries[x].val);
        getword(entries[x].name,entries[x].val,'=');
    }

    printf("<H1>Query Results</H1>");
    printf("You submitted the following name/value pairs:<p>%c",10);
    printf("<ul>%c",10);

    for(x=0; x <= m; x++)
        printf("<li> <code>%s = %s</code>%c",entries[x].name,
               entries[x].val,10);
    printf("</ul>%c",10);
}
