#include #include #include #define LF 10 #define CR 13 void getword(word, line, stop) char *word; char *line; char stop; { int x = 0,y; for(x=0;((line[x]) && (line[x] != stop));x++) word[x] = line[x]; word[x] = '\0'; if(line[x]) ++x; y=0; while(line[y++] = line[x++]); } char *makeword(line, stop) char *line; char stop; { int x = 0,y; char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1)); for(x=0;((line[x]) && (line[x] != stop));x++) word[x] = line[x]; word[x] = '\0'; if(line[x]) ++x; y=0; while(line[y++] = line[x++]); return word; } char *fmakeword(f, stop, cl) FILE *f; char stop; int *cl; { int wsize; char *word; int ll; wsize = 102400; ll=0; word = (char *) malloc(sizeof(char) * (wsize + 1)); while(1) { word[ll] = (char)fgetc(f); if(ll==wsize) { word[ll+1] = '\0'; wsize+=102400; word = (char *)realloc(word,sizeof(char)*(wsize+1)); } --(*cl); if((word[ll] == stop) || (feof(f)) || (!(*cl))) { if(word[ll] != stop) ll++; word[ll] = '\0'; return word; } ++ll; } } char x2c(what) char *what; { register char digit; digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); digit *= 16; digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0')); return(digit); } void unescape_url(url) char *url; { register int x,y; for(x=0,y=0;url[y];++x,++y) { if((url[x] = url[y]) == '%') { url[x] = x2c(&url[y+1]); y+=2; } } url[x] = '\0'; } void plustospace(str) char *str; { register int x; for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' '; } #define MAX_ENTRIES 100 typedef struct { char *name; char *val; } entry; char *makeword(); char *fmakeword(); char x2c(); void unescape_url(); void plustospace(); main(argc,argv) int argc; char *argv[]; { int i,j,j1,ok; char lines[2025]; char *s,*t,*spb,*spe,*senv; char nam[255]; FILE *fil; entry entries[MAX_ENTRIES]; register int x,m=0; int cl; s=getenv("CONTENT_LENGTH"); if(s){ cl = atoi(s); 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,'='); }; } else m= -1; /* for (i=0;i<=m;i++)printf("%s = %s\n",entries[i].name,entries[i].val); printf("**********\n"); */ strcpy(lines,argv[1]); for(i=0;i<=m;i++){ if(strcmp("matfile",entries[i].name)==0){ strcat(lines,entries[i].val); break; }; }; if((fil=fopen(lines,"r")) == NULL)exit(1); while(fgets(lines,2024,fil) != NULL){ /* printf("<<%s\n",lines); */ s=lines; while(spb=strchr(s,'$')){ if(*(spb+1)=='{'){ spe=strchr(spb,'}'); *spb='\0'; printf("%s",s); *spe='\0'; spb += 2; /* printf("name: %s\n",spb); */ for(i=0;i<=m;i++){ if(strcmp(spb,entries[i].name)==0){ printf("%s",entries[i].val); break; }; }; if(i>m){ senv=getenv(spb); if(senv)printf("%s",senv); }; s=spe+1; } else { *spb='\0'; printf("%s$",s); s=spb+1; }; }; printf("%s",s); }; }