#include #include #include #define MAX_ENTRIES 10000 struct entry { char *name; char *val; }; #include "util1.c" /* extern char *makeword(char *line, char stop); extern char *fmakeword(FILE *f, char stop, int *len); extern char x2c(char *what); extern void unescape_url(char *url); extern void plustospace(char *str); */ main(argc,argv) int argc; char *argv[]; { struct entry entries[MAX_ENTRIES]; register int x,m=0; int cl,keyval; FILE *basefile,*logfile,*outfile,*scrfile,*keyfile; char c1,filen[80],filec[80],filegif[80],fileout[80],cmdnew[120]; printf("Content-type: text/html%c%c",10,10); if(strcmp(getenv("REQUEST_METHOD"),"POST")) { printf("This script should be referenced with a METHOD of POST.\n"); printf("If you don't understand this, see this "); printf("forms overview.%c",10); exit(1); } if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) { printf("This script can only be used to decode form results. \n"); exit(1); } cl = atoi(getenv("CONTENT_LENGTH")); for(x=0;cl && (!feof(stdin));x++) { m=x; entries[x].val = fmakeword(stdin,'&',&cl); plustospace(entries[x].val); unescape_url(entries[x].val); entries[x].name = makeword(entries[x].val,'='); } strcpy(cmdnew,entries[0].val); /* Check the key file to see if dataplot is already busy */ keyfile=fopen("base.key","r"); fscanf(keyfile,"%d",&keyval); fclose(keyfile); if(keyval==1){ printf("Dataplot files are busy--- please try again later \n"); printf("If consistently unavailable --- please contact system administrator \n"); fflush(stdout); } else{ /* Lock out the key file for dataplot usage */ keyfile=fopen("base.key","w"); fprintf(keyfile,"%d",1); fclose(keyfile); basefile=fopen("base.tex","w"); fprintf(basefile,"This is file base.tex\n"); fprintf(basefile,"Contents = base name for all files\n"); fprintf(basefile,"-----------\n"); fprintf(basefile,"%s\n",entries[0].val); fprintf(basefile,"-----------\n"); fclose(basefile); /* process form */ sprintf(filegif,"%sstep1.gif",entries[0].val); system("/usr/local/bin/dataplot step1.tmp"); system("cp dppl2f.dat dpstep1.ps"); sprintf(cmdnew,"/usr/local/bin/convert -rotate 90 /var/www/cgi-bin/dpstep1.ps /usr/people/bentz/public/fhwa/%s",filegif); system(cmdnew); printf("\n%c",10); printf("

Results

"); printf("%c",filegif,10); printf("
Above plot generated by DATAPLOT

%c",10); printf("\n%c",10); /* Update the key file again */ keyfile=fopen("base.key","w"); fprintf(keyfile,"%d",0); fclose(keyfile); } /* printf("You submitted the following name/value pairs:

%c",10); printf("

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