#include 
#ifndef NO_STDLIB_H
#include 
#else
char *getenv();
#endif

#define MAX_ENTRIES 1000

typedef struct {
    char *name;
    char *val;
} entry;

char *makeword(char *line, char stop);
char *fmakeword(FILE *f, char stop, int *len);
char x2c(char *what);
void unescape_url(char *url);
void plustospace(char *str);
static    entry entries[MAX_ENTRIES];
static    int numOfVarFromPost;

/************************************************************************/
/*      								*/
/************************************************************************/

buildVars(int argc, char *argv[]) {
    register int x;
    int cl;

    printf("Content-type: text/html%c%c",10,10);

    if(strcmp(getenv("REQUEST_METHOD"),"POST")) {
        return(1);
    }
    if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) {
        return(1);
    }
    cl = atoi(getenv("CONTENT_LENGTH"));

    for(x=0;cl && (!feof(stdin));x++) {
        numOfVarFromPost=x;
        entries[x].val = fmakeword(stdin,'&',&cl);
        plustospace(entries[x].val);
        unescape_url(entries[x].val);
        entries[x].name = makeword(entries[x].val,'=');
    }
}
/************************************************************************/
/*      								*/
/************************************************************************/
char *getCharValueFromPost(char * theValue)
{
    int x;
    for(x=0; x <= numOfVarFromPost; x++)
    {
	if (!strcmp(entries[x].name,theValue))
	{
		return( (char*) entries[x].val);
	}
    }
    return(NULL);
}
/************************************************************************/
/*      								*/
/************************************************************************/

float getFloatValueFromPost(char * theValue)
{
    int x;
    for(x=0; x <= numOfVarFromPost; x++)
    {
	if (!strcmp(entries[x].name,theValue))
	{
		return(atof( entries[x].val));
	}
    }
   return(-99999.0);
}
/************************************************************************/
/*      								*/
/************************************************************************/

int getIntValueFromPost(char * theValue)
{
    int x;
    for(x=0; x <=  numOfVarFromPost; x++)
    {
	if (!strcmp(entries[x].name,theValue))
	{
		return(atoi( entries[x].val));
	}
    }
   return(-99999);
}