/* * cgifnd.c -- CGI Test example for the GoAhead WebServer * * Copyright J. SaKong and JJ. Woo * cgifnd.c,v 0.1 2007/6/22 06:28:24 */ /******************************** Description *********************************/ /* * Tests the CGI environment with GoAhead Webserver, Hybus PXA270-TKU */ /********************************* Includes ***********************************/ #include #include #include #include #include #define MAXFND 8 /******************************************************************************/ static char fndDev[] = "/dev/FND"; static int fndFd = (-1); asc2fnd(char *s, long n) { char c; int l; while (n > 0) { l = n % 10; switch (l) { case 0: c = 0x3f; break; case 1: c = 0x06; break; case 2: c = 0x5b; break; case 3: c = 0x4f; break; case 4: c = 0x66; break; case 5: c = 0x6d; break; case 6: c = 0x7d; break; case 7: c = 0x07; break; case 8: c = 0x7f; break; case 9: c = 0x67; break; default: c = 0x00; break; } *s++ = c; n = n/10; } } int send_number_FND(long av) { int n; char buf[MAXFND+1]; fndFd = open( fndDev, O_RDWR); if (fndFd < 0) { fprintf(stderr, "cannot open FND (%d)", fndFd); exit(2); } memset(buf, 0, sizeof(buf)); asc2fnd(buf, av); write(fndFd, buf, MAXFND); return 0; } /* * Test program entry point */ int main(int argc, char *argv[]) { char *cgiinput ; long send_number; /* * Print the CGI response header, required for all HTML output. * Note the extra \n, to send the blank line. */ printf("Content-type:text/html;charset=iso-8859-1%c%c\n\n",13,10) ; /* * Print the HTML header to STDOUT. */ printf("\n"); printf("Web Server Application\n"); printf("\n"); printf("

Web Server Application

\n"); cgiinput= getenv("QUERY_STRING"); if(cgiinput == NULL) printf("

Error in passing data from form to script."); else if(sscanf(cgiinput, "send_number=%ld", &send_number)!=1) printf("

Invalid data. Data must be numeric."); else send_number_FND(send_number); printf("

Check the FND, [%ld] is displayed
\n", send_number); printf("\n"); printf("\n"); return 0; }