#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
//MyCGI is going to be a collection of common web page addons all available in one package
//Currently there is a counter. I intend to atleast add a guestbook to this aswell
//I kno there are better choices for cgi.....but i needed to brush up on C so this was a
//good way to start :)

//09/02/2000: 0.1 includes a working Counter, url parsing and some general error trapping
*/
extern int counter(const char *user);


int main(int argc, char **argv) {
        char *s;
	char *svptr;
        static const char delim[] = "\\&";
	char *parms[25];
	int  i;
	//check to make sure parms were given!
	if(argc > 1) {
		//parse web url parms
		
		s = strtok_r(argv[1],delim,&svptr);

		i = 0;
		while ( s != 0) {  // i kno i dont need the while loop but one day when i
			parms[i++] = s;   // add more then 2 parms it'll be useful :)
			s = strtok_r(NULL,delim,&svptr);
		} //done parsing
		
		printf("Content-type: text/html\n\n");  //I need this or the server gets real pissed
		//once again....why use an if statment...why even use modules? heh
		//well thats because i plan to add a guestbook an other stuff to this.
		//it's wise to be setup ahead of time :)
		if(strstr(parms[0],"counter"))    //If a counter is hit
		{	counter(parms[1]); }
		else
			{ printf("You never gave me a valid option\n<br>"); }
			
	} else {
	   	printf("Content-type: text/html\n\n");  //I need this or the server gets real pissed
		printf("Sorry You didn't give me the Information I need to work\n<br>");
	}
	printf("\n"); //this is for u goofs who run this in console 1st...and me cause i run it there to test it heh
	return 0;
	
}

