| 1 | /* ------------------------------ cicgi.c ---------------------------------- */ |
|---|
| 2 | |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <string.h> |
|---|
| 5 | #include <ctype.h> |
|---|
| 6 | |
|---|
| 7 | #include "cisis.h" |
|---|
| 8 | |
|---|
| 9 | #if CICPP |
|---|
| 10 | #include "cicgi.hpp" |
|---|
| 11 | #endif |
|---|
| 12 | |
|---|
| 13 | #if CICGI |
|---|
| 14 | |
|---|
| 15 | #define CICG1 0 /* for COREDATA/mxcgi.c */ |
|---|
| 16 | |
|---|
| 17 | #if RECGIZM |
|---|
| 18 | #define CICGXGIZ 1 |
|---|
| 19 | #endif |
|---|
| 20 | |
|---|
| 21 | #define PARMTAG5 ((FFI) 5/*U*/) |
|---|
| 22 | #define PARMTAG6 ((FFI) 6/*U*/) |
|---|
| 23 | #define PARMTAG701 ((FFI) 701/*U*/) |
|---|
| 24 | |
|---|
| 25 | #define TAGMXTGS ((FFI) 900/*U*/) |
|---|
| 26 | #define TAGMXCTS ((FFI) 901/*U*/) |
|---|
| 27 | #define TAGMXPFT ((FFI) 902/*U*/) |
|---|
| 28 | |
|---|
| 29 | #define NAMHXSUB 'n' |
|---|
| 30 | #define VALHXSUB 'v' |
|---|
| 31 | #define TAGHXSUB ((FFI) 100/*U*/) |
|---|
| 32 | #define TAGHXNAM ((FFI) 101/*U*/) |
|---|
| 33 | #define TAGHXVAL ((FFI) 102/*U*/) |
|---|
| 34 | |
|---|
| 35 | #if PC |
|---|
| 36 | #define ALTEQUAL '~' |
|---|
| 37 | #else |
|---|
| 38 | #define ALTEQUAL '=' |
|---|
| 39 | #endif |
|---|
| 40 | |
|---|
| 41 | #if ANSI |
|---|
| 42 | static char *getword(char *line, char stop, char stop2); |
|---|
| 43 | static char x2c(char *what); |
|---|
| 44 | static void unescape_url(char *url); |
|---|
| 45 | static void plustospace(char *str); |
|---|
| 46 | static char *makeword(char *line, char stop, char stop2); |
|---|
| 47 | static char *fmakeword(FILE *f, char stop, char stop2, int *len); |
|---|
| 48 | static char *getenvx(char *namep); |
|---|
| 49 | #if CICG1 |
|---|
| 50 | static void cgierr(int error, char *p); |
|---|
| 51 | static void b5_keepdbx(int option); |
|---|
| 52 | static LONGX getridx(int n, char *msgp); |
|---|
| 53 | #endif |
|---|
| 54 | #if !CICPP |
|---|
| 55 | static char *gettmpnam(char *namp); |
|---|
| 56 | #endif /* CICPP */ |
|---|
| 57 | #else |
|---|
| 58 | static char *getword(); |
|---|
| 59 | static char x2c(); |
|---|
| 60 | static void unescape_url(); |
|---|
| 61 | static void plustospace(); |
|---|
| 62 | static char *makeword(); |
|---|
| 63 | static char *fmakeword(); |
|---|
| 64 | static char *getenvx(); |
|---|
| 65 | #if CICG1 |
|---|
| 66 | static void cgierr(); |
|---|
| 67 | static void b5_keepdbx(); |
|---|
| 68 | static LONGX getridx(); |
|---|
| 69 | #endif |
|---|
| 70 | static char *gettmpnam(); |
|---|
| 71 | #endif |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | #if CICPP |
|---|
| 75 | char * CGIClass :: gettmpnam(char *namp) |
|---|
| 76 | #else /* CICPP */ |
|---|
| 77 | static char *gettmpnam(namp) |
|---|
| 78 | char *namp; |
|---|
| 79 | #endif /* CICPP */ |
|---|
| 80 | { |
|---|
| 81 | #if BEFORE20000729 |
|---|
| 82 | char *p,*q; |
|---|
| 83 | FILE *fp; |
|---|
| 84 | p=tmpnam(namp); |
|---|
| 85 | if (!namp) p=strdup(p); |
|---|
| 86 | fp=fopen(p,"w"); if (fp) fclose(fp); |
|---|
| 87 | #if PC |
|---|
| 88 | if (strcmp((q=p+strlen(p)-4),".$$$") == 0) *q='\0'; |
|---|
| 89 | #endif |
|---|
| 90 | return(p); |
|---|
| 91 | #else |
|---|
| 92 | return (dbxtmpnm("CI_TEMPDIR", 0, namp /*NULL*/)); |
|---|
| 93 | #endif |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | #if CICG1 |
|---|
| 97 | |
|---|
| 98 | #define CICGSRCH 1 |
|---|
| 99 | #define CGCGMXMX 0 |
|---|
| 100 | |
|---|
| 101 | static LONGX getridx(n,msgp) |
|---|
| 102 | int n; |
|---|
| 103 | char *msgp; |
|---|
| 104 | { |
|---|
| 105 | LONGX i,j; |
|---|
| 106 | for (j=i=0; i < maxnrec; i++) if (!vrecp[i]) { j=1; break; } |
|---|
| 107 | if (!j) if (msgp) cgierr(n,msgp); |
|---|
| 108 | return(i); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | static void b5_keepdbx(option) |
|---|
| 112 | int option; |
|---|
| 113 | { |
|---|
| 114 | static LONGX keepndbx=0; |
|---|
| 115 | LONGX idbx; |
|---|
| 116 | |
|---|
| 117 | if (option == 0) keepndbx=ndbxs; |
|---|
| 118 | else |
|---|
| 119 | for (idbx=ndbxs-1; idbx>=keepndbx; idbx--) |
|---|
| 120 | dbxflush(vdbxp[idbx]->dbxname); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | static void cgierr(error,p) |
|---|
| 124 | int error; |
|---|
| 125 | char *p; |
|---|
| 126 | { |
|---|
| 127 | static char line[5+40+1+1]; |
|---|
| 128 | int len; |
|---|
| 129 | char *lp; |
|---|
| 130 | |
|---|
| 131 | sprintf(line,"%03d [",error); lp=line+5; |
|---|
| 132 | len=strlen(p); if (len > 40) len=40; |
|---|
| 133 | memcpy(lp,p,len); |
|---|
| 134 | sprintf(lp+len,"]"); |
|---|
| 135 | |
|---|
| 136 | fatal(line); |
|---|
| 137 | } |
|---|
| 138 | #endif /* CICG1 */ |
|---|
| 139 | |
|---|
| 140 | #if CICPP |
|---|
| 141 | static char *getenvx(char *namep) |
|---|
| 142 | #else /* CICPP */ |
|---|
| 143 | static char *getenvx(namep) |
|---|
| 144 | char *namep; |
|---|
| 145 | #endif /* CICPP */ |
|---|
| 146 | { |
|---|
| 147 | static char *none = ""; |
|---|
| 148 | char *envp; |
|---|
| 149 | |
|---|
| 150 | envp=getenv(namep); |
|---|
| 151 | if (!envp) envp=none; |
|---|
| 152 | |
|---|
| 153 | return(envp); |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | #if CICPP |
|---|
| 158 | static char *getword(char *line, |
|---|
| 159 | char stop, |
|---|
| 160 | char stop2) |
|---|
| 161 | #else /* CICPP */ |
|---|
| 162 | static char *getword(line, stop, stop2) |
|---|
| 163 | char *line; |
|---|
| 164 | char stop; |
|---|
| 165 | char stop2; |
|---|
| 166 | #endif /* CICPP */ |
|---|
| 167 | { |
|---|
| 168 | char *word; |
|---|
| 169 | int x = 0,y; |
|---|
| 170 | |
|---|
| 171 | for(x=0;((line[x]) && (line[x] != stop) && (line[x] != stop2));x++) |
|---|
| 172 | /*word[x] = line[x]*/; |
|---|
| 173 | |
|---|
| 174 | word=(char *) malloc(sizeof(char) * (x + 1)); |
|---|
| 175 | memcpy(word,line,x); word[x] = '\0'; |
|---|
| 176 | |
|---|
| 177 | if(line[x]) ++x; |
|---|
| 178 | y=0; |
|---|
| 179 | |
|---|
| 180 | while((line[y++] = line[x++]) != '\0'); |
|---|
| 181 | return word; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | #if CICPP |
|---|
| 185 | static char *makeword(char *line, |
|---|
| 186 | char stop, |
|---|
| 187 | char stop2) |
|---|
| 188 | #else /* CICPP */ |
|---|
| 189 | static char *makeword(line, stop, stop2) |
|---|
| 190 | char *line; |
|---|
| 191 | char stop; |
|---|
| 192 | char stop2; |
|---|
| 193 | #endif /* CICPP */ |
|---|
| 194 | { |
|---|
| 195 | int x = 0,y; |
|---|
| 196 | char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1)); |
|---|
| 197 | |
|---|
| 198 | for(x=0;((line[x]) && (line[x] != stop) && (line[x] != stop2));x++) |
|---|
| 199 | word[x] = line[x]; |
|---|
| 200 | |
|---|
| 201 | word[x] = '\0'; |
|---|
| 202 | if(line[x]) ++x; |
|---|
| 203 | #if 0 |
|---|
| 204 | fprintf(stderr,"%s=%s,,,\n",word,line+x); |
|---|
| 205 | #endif |
|---|
| 206 | y=0; |
|---|
| 207 | |
|---|
| 208 | while((line[y++] = line[x++]) != '\0'); |
|---|
| 209 | return word; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | #if CICPP |
|---|
| 213 | static char *fmakeword(FILE *f, |
|---|
| 214 | char stop, |
|---|
| 215 | char stop2, |
|---|
| 216 | int *cl) |
|---|
| 217 | #else /* CICPP */ |
|---|
| 218 | static char *fmakeword(f, stop, stop2, cl) |
|---|
| 219 | FILE *f; |
|---|
| 220 | char stop; |
|---|
| 221 | char stop2; |
|---|
| 222 | int *cl; |
|---|
| 223 | #endif /* CICPP */ |
|---|
| 224 | { |
|---|
| 225 | int wsize; |
|---|
| 226 | char *word; |
|---|
| 227 | int ll; |
|---|
| 228 | |
|---|
| 229 | wsize = CICGI_WORDSIZE; |
|---|
| 230 | ll=0; |
|---|
| 231 | word = (char *) malloc(sizeof(char) * (wsize + 1)); |
|---|
| 232 | |
|---|
| 233 | while(1) { |
|---|
| 234 | word[ll] = (char)fgetc(f); |
|---|
| 235 | if(ll==wsize) { |
|---|
| 236 | word[ll+1] = '\0'; |
|---|
| 237 | wsize+=CICGI_WORDSIZE; |
|---|
| 238 | word = (char *)realloc(word,sizeof(char)*(wsize+1)); |
|---|
| 239 | } |
|---|
| 240 | --(*cl); |
|---|
| 241 | if((word[ll] == stop || word[ll] == stop2) || (feof(f)) || (!(*cl))) { |
|---|
| 242 | if(word[ll] != stop && word[ll] != stop2) ll++; |
|---|
| 243 | word[ll] = '\0'; |
|---|
| 244 | #if 0 |
|---|
| 245 | fprintf(stderr,"\n%s..\n",word); |
|---|
| 246 | #endif |
|---|
| 247 | break; |
|---|
| 248 | } |
|---|
| 249 | ++ll; |
|---|
| 250 | } |
|---|
| 251 | return word; |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | #if CICPP |
|---|
| 255 | static char x2c(char *what) |
|---|
| 256 | #else /* CICPP */ |
|---|
| 257 | static char x2c(what) |
|---|
| 258 | char *what; |
|---|
| 259 | #endif /* CICPP */ |
|---|
| 260 | { |
|---|
| 261 | register char digit; |
|---|
| 262 | |
|---|
| 263 | digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); |
|---|
| 264 | digit *= 16; |
|---|
| 265 | digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0')); |
|---|
| 266 | return(digit); |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | #if CICPP |
|---|
| 270 | static void unescape_url(char *url) |
|---|
| 271 | #else /* CICPP */ |
|---|
| 272 | static void unescape_url(url) |
|---|
| 273 | char *url; |
|---|
| 274 | #endif /* CICPP */ |
|---|
| 275 | { |
|---|
| 276 | register int x,y; |
|---|
| 277 | |
|---|
| 278 | for(x=0,y=0;url[y];++x,++y) { |
|---|
| 279 | if((url[x] = url[y]) == '%') { |
|---|
| 280 | url[x] = x2c(&url[y+1]); |
|---|
| 281 | y+=2; |
|---|
| 282 | } |
|---|
| 283 | } |
|---|
| 284 | url[x] = '\0'; |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | #if CICPP |
|---|
| 288 | static void plustospace(char *str) |
|---|
| 289 | #else /* CICPP */ |
|---|
| 290 | static void plustospace(str) |
|---|
| 291 | char *str; |
|---|
| 292 | #endif /* CICPP */ |
|---|
| 293 | { |
|---|
| 294 | register int x; |
|---|
| 295 | |
|---|
| 296 | for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' '; |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | #if USEIT |
|---|
| 300 | static int rind(s, c) |
|---|
| 301 | char *s; |
|---|
| 302 | char c; |
|---|
| 303 | { |
|---|
| 304 | register int x; |
|---|
| 305 | for(x=strlen(s) - 1;x != -1; x--) |
|---|
| 306 | if(s[x] == c) return x; |
|---|
| 307 | return -1; |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | static int getline(s, n, f) |
|---|
| 311 | char *s; |
|---|
| 312 | int n; |
|---|
| 313 | FILE *f; |
|---|
| 314 | { |
|---|
| 315 | register int i=0; |
|---|
| 316 | |
|---|
| 317 | while(1) { |
|---|
| 318 | s[i] = (char)fgetc(f); |
|---|
| 319 | |
|---|
| 320 | if(s[i] == '\r') |
|---|
| 321 | s[i] = fgetc(f); |
|---|
| 322 | |
|---|
| 323 | if((s[i] == 0x4) || (s[i] == '\n') || (i == (n-1))) { |
|---|
| 324 | s[i] = '\0'; |
|---|
| 325 | return (feof(f) ? 1 : 0); |
|---|
| 326 | } |
|---|
| 327 | ++i; |
|---|
| 328 | } |
|---|
| 329 | return 0; /* no wrn */ |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | static void send_fd(f, fd) |
|---|
| 333 | FILE *f; |
|---|
| 334 | FILE *fd; |
|---|
| 335 | { |
|---|
| 336 | /* int num_chars=0; */ |
|---|
| 337 | char c; |
|---|
| 338 | |
|---|
| 339 | while (1) { |
|---|
| 340 | c = fgetc(f); |
|---|
| 341 | if(feof(f)) |
|---|
| 342 | return; |
|---|
| 343 | fputc(c,fd); |
|---|
| 344 | } |
|---|
| 345 | } |
|---|
| 346 | #endif /* ISUSED */ |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | /* |
|---|
| 350 | ***************************************************** |
|---|
| 351 | cicgi.c |
|---|
| 352 | ***************************************************** |
|---|
| 353 | */ |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | #if CICPP |
|---|
| 357 | int CGIClass::cicgi0(int *argc, |
|---|
| 358 | char *argv[], |
|---|
| 359 | char **wwwp, |
|---|
| 360 | UWORD taghxsub, |
|---|
| 361 | char *taghpfxp) |
|---|
| 362 | #else /* CICPP */ |
|---|
| 363 | int cicgi0(argc,argv,wwwp,taghxsub,taghpfxp) |
|---|
| 364 | int *argc; |
|---|
| 365 | char *argv[]; |
|---|
| 366 | char **wwwp; |
|---|
| 367 | UWORD taghxsub; |
|---|
| 368 | char *taghpfxp; |
|---|
| 369 | #endif /* CICPP */ |
|---|
| 370 | { |
|---|
| 371 | CICGI_ENTRY entries[CICGI_MAXENTRIES]; |
|---|
| 372 | int nentries=0; |
|---|
| 373 | int method=0; |
|---|
| 374 | char *cicgi_p=NULL; |
|---|
| 375 | |
|---|
| 376 | char *entryval; |
|---|
| 377 | char *entryname; |
|---|
| 378 | register int x,m=0; |
|---|
| 379 | char *cl,*p,*p1,*p2,*clp; |
|---|
| 380 | int cli,argnext; |
|---|
| 381 | int un,uv,ut; |
|---|
| 382 | LONGX bytes; |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | if(strcmp(getenvx("REQUEST_METHOD"),"GET") == 0) { |
|---|
| 386 | |
|---|
| 387 | method=1; |
|---|
| 388 | clp = getenv("QUERY_STRING"); |
|---|
| 389 | if(clp == NULL) { |
|---|
| 390 | return(0); |
|---|
| 391 | } |
|---|
| 392 | cl=strdup(clp); |
|---|
| 393 | #if 0 |
|---|
| 394 | printf("cl=%s",cl); getchar(); |
|---|
| 395 | #endif |
|---|
| 396 | for(m=x=0;cl[0] != '\0';x++) { |
|---|
| 397 | if (x >= CICGI_MAXENTRIES) fatal("cicgi/CICGI_MAXENTRIES/GET"); |
|---|
| 398 | entryval=getword(cl,'&','&'); |
|---|
| 399 | #if 0 |
|---|
| 400 | printf("entryval=%s",entryval); getchar(); |
|---|
| 401 | #endif |
|---|
| 402 | plustospace(entryval); |
|---|
| 403 | unescape_url(entryval); |
|---|
| 404 | entryname=getword(entryval,'=',ALTEQUAL); |
|---|
| 405 | entries[x].namp = entryname; |
|---|
| 406 | entries[x].valp = entryval; |
|---|
| 407 | #if 0 |
|---|
| 408 | printf("entry#%d: %s=%s",x,entries[x].namp,entries[x].valp); getchar(); |
|---|
| 409 | #endif |
|---|
| 410 | if (entries[x].namp[0]) m++; |
|---|
| 411 | } |
|---|
| 412 | free(cl); |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | else |
|---|
| 416 | if(strcmp(getenvx("REQUEST_METHOD"),"POST") == 0) { |
|---|
| 417 | |
|---|
| 418 | method=2; |
|---|
| 419 | if(strcmp(getenvx("CONTENT_TYPE"),"application/x-www-form-urlencoded")) { |
|---|
| 420 | return(0); |
|---|
| 421 | } |
|---|
| 422 | cli = atoi(getenvx("CONTENT_LENGTH")); |
|---|
| 423 | for(m=x=0;cli && (!feof(stdin));x++) { |
|---|
| 424 | if (x >= CICGI_MAXENTRIES) fatal("cicgi/CICGI_MAXENTRIES/POST"); |
|---|
| 425 | entries[x].valp = fmakeword(stdin,'&','&',&cli); |
|---|
| 426 | plustospace(entries[x].valp); |
|---|
| 427 | unescape_url(entries[x].valp); |
|---|
| 428 | entries[x].namp = makeword(entries[x].valp,'=',ALTEQUAL); |
|---|
| 429 | if (entries[x].namp[0]) m++; |
|---|
| 430 | } |
|---|
| 431 | } |
|---|
| 432 | |
|---|
| 433 | else |
|---|
| 434 | if (!wwwp) if (taghxsub) if (*argc > 1) { |
|---|
| 435 | |
|---|
| 436 | method=3; |
|---|
| 437 | for(m=0, x=1; x < *argc; x++) { |
|---|
| 438 | cl=strdup(argv[x]); |
|---|
| 439 | entryval=getword(cl,'&','&'); |
|---|
| 440 | #if 0 |
|---|
| 441 | printf("entryval=%s",entryval); getchar(); |
|---|
| 442 | #endif |
|---|
| 443 | plustospace(entryval); |
|---|
| 444 | unescape_url(entryval); |
|---|
| 445 | entryname=getword(entryval,'=',ALTEQUAL); |
|---|
| 446 | entries[m].namp = entryname; |
|---|
| 447 | entries[m].valp = entryval; |
|---|
| 448 | #if 0 |
|---|
| 449 | printf("entry#%d: %s=%s",m,entries[m].namp,entries[m].valp); getchar(); |
|---|
| 450 | #endif |
|---|
| 451 | if (entries[m].namp[0]) m++; else { free(entryval); free(entryname); } |
|---|
| 452 | if (m >= CICGI_MAXENTRIES) fatal("cicgi/CICGI_MAXENTRIES/argv"); |
|---|
| 453 | free(cl); |
|---|
| 454 | } |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | if (!method) return(0); |
|---|
| 458 | |
|---|
| 459 | nentries=m; |
|---|
| 460 | |
|---|
| 461 | for (x=0; x < m; x++) |
|---|
| 462 | if (strcmp(entries[x].namp,"trace") == 0) if (!entries[x].valp[0]) cgitrace=1; |
|---|
| 463 | |
|---|
| 464 | if (wwwp) { |
|---|
| 465 | /* store input pairs */ |
|---|
| 466 | for (bytes=0, x=0; x < nentries; x++) { |
|---|
| 467 | bytes+=1+5+1+5+1; |
|---|
| 468 | bytes+=2+strlen(entries[x].namp)+2+strlen(entries[x].valp); |
|---|
| 469 | } |
|---|
| 470 | *wwwp = (char *) malloc(sizeof(char)*bytes + 1); |
|---|
| 471 | if (*wwwp == NULL) return(0); |
|---|
| 472 | *(p= *wwwp)='\0'; |
|---|
| 473 | if (!taghxsub) taghxsub=TAGHXSUB; |
|---|
| 474 | for (x=0; x < nentries; x++) { |
|---|
| 475 | un=strlen(entries[x].namp); |
|---|
| 476 | uv=strlen(entries[x].valp); |
|---|
| 477 | if (taghpfxp) { |
|---|
| 478 | p1=strstr(entries[x].namp,"^t"); |
|---|
| 479 | if (p1) p1+=2; |
|---|
| 480 | else { |
|---|
| 481 | ut=strlen(taghpfxp); |
|---|
| 482 | if (strncmp(p1=entries[x].namp,taghpfxp,ut) == 0) p1+=ut; |
|---|
| 483 | else p1=""; |
|---|
| 484 | } |
|---|
| 485 | ut=atoi(p1); |
|---|
| 486 | if (ut > 0) { |
|---|
| 487 | sprintf(p,"H%ld %ld ",(LONGX)ut,(LONGX)uv); p+=strlen(p); |
|---|
| 488 | memcpy(p,entries[x].valp,uv); p+=uv; |
|---|
| 489 | *p='\0'; |
|---|
| 490 | continue; |
|---|
| 491 | } |
|---|
| 492 | } |
|---|
| 493 | sprintf(p,"H%ld %ld ",(LONGX)taghxsub,(LONGX)2+un+2+uv); p+=strlen(p); |
|---|
| 494 | *p++=SFLDCHR; *p++=NAMHXSUB; |
|---|
| 495 | memcpy(p,entries[x].namp,un); p+=un; |
|---|
| 496 | *p++=SFLDCHR; *p++=VALHXSUB; |
|---|
| 497 | memcpy(p,entries[x].valp,uv); p+=uv; |
|---|
| 498 | *p='\0'; |
|---|
| 499 | } |
|---|
| 500 | for (x=0; x < nentries; x++) { |
|---|
| 501 | free(entries[x].namp); |
|---|
| 502 | free(entries[x].valp); |
|---|
| 503 | } |
|---|
| 504 | return(0); |
|---|
| 505 | } /* end if wwwp */ |
|---|
| 506 | |
|---|
| 507 | for (x=0; x < m; x++) { |
|---|
| 508 | if (strcmp(entries[x].namp,"CICGI") == 0 || |
|---|
| 509 | strcmp(entries[x].namp,"cicgi") == 0) { |
|---|
| 510 | cicgi_p=entries[x].valp; |
|---|
| 511 | for (; ++x < m; ) { |
|---|
| 512 | /* alloc -> free */ |
|---|
| 513 | entries[x-1].namp=entries[x].namp; |
|---|
| 514 | entries[x-1].valp=entries[x].valp; |
|---|
| 515 | } |
|---|
| 516 | m--; |
|---|
| 517 | break; |
|---|
| 518 | } |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | if (!cicgi_p) { |
|---|
| 522 | p=getenv("CICGI"); |
|---|
| 523 | if (!p) cicgi_p=getenv("cicgi"); |
|---|
| 524 | if (p) cicgi_p=strdup(p); |
|---|
| 525 | } |
|---|
| 526 | |
|---|
| 527 | if (!cicgi_p) { |
|---|
| 528 | for (x=0; x < nentries; x++) { |
|---|
| 529 | free(entries[x].namp); |
|---|
| 530 | free(entries[x].valp); |
|---|
| 531 | } |
|---|
| 532 | return(0); |
|---|
| 533 | } |
|---|
| 534 | |
|---|
| 535 | nentries=m; |
|---|
| 536 | argnext= *argc; |
|---|
| 537 | |
|---|
| 538 | #define VALUEMX 0 |
|---|
| 539 | #if VALUEMX |
|---|
| 540 | if (strcmp(cicgi_p,"mx") == 0) { |
|---|
| 541 | for (x=0; x < m; x++) { |
|---|
| 542 | if (strcmp(entries[x].namp,"files") == 0 || |
|---|
| 543 | strcmp(entries[x].namp,"cipar") == 0 || |
|---|
| 544 | strcmp(entries[x].namp,"mfrl") == 0) { |
|---|
| 545 | p1=entries[x].namp; |
|---|
| 546 | p2=entries[x].valp; |
|---|
| 547 | p= (char *) malloc(sizeof(char) * (strlen(p1)+1+strlen(p2) + 1)); |
|---|
| 548 | sprintf(p,"%s=%s",p1,p2); |
|---|
| 549 | argv[argnext++]=p; |
|---|
| 550 | } |
|---|
| 551 | } |
|---|
| 552 | for (x=0; x < m; x++) { |
|---|
| 553 | if (strcmp(entries[x].namp,"db") == 0 || strcmp(entries[x].namp,"dbn") == 0) { |
|---|
| 554 | p2=entries[x].valp; |
|---|
| 555 | p= (char *) malloc(sizeof(char) * (strlen(p2) + 1)); |
|---|
| 556 | sprintf(p,"%s",p2); |
|---|
| 557 | argv[argnext++]=p; |
|---|
| 558 | break; |
|---|
| 559 | } |
|---|
| 560 | } |
|---|
| 561 | for (x=0; x < m; x++) { |
|---|
| 562 | if (strcmp(entries[x].namp,"files") != 0 && |
|---|
| 563 | strcmp(entries[x].namp,"cipar") != 0 && |
|---|
| 564 | strcmp(entries[x].namp,"mfrl") != 0 && |
|---|
| 565 | strcmp(entries[x].namp,"dbn") != 0) { |
|---|
| 566 | p1=entries[x].namp; |
|---|
| 567 | p2=entries[x].valp; |
|---|
| 568 | p= (char *) malloc(sizeof(char) * (strlen(p1)+1+strlen(p2) + 1)); |
|---|
| 569 | #if BEFORE20000629 |
|---|
| 570 | sprintf(p,"%s=%s",p1,p2); |
|---|
| 571 | #else |
|---|
| 572 | if (*p2) sprintf(p,"%s=%s",p1,p2); else sprintf(p,"%s",p1); |
|---|
| 573 | #endif |
|---|
| 574 | argv[argnext++]=p; |
|---|
| 575 | } |
|---|
| 576 | } |
|---|
| 577 | cicgi_p=NULL; |
|---|
| 578 | } |
|---|
| 579 | #endif /* VALUEMX */ |
|---|
| 580 | |
|---|
| 581 | #if CICG1 |
|---|
| 582 | if (cicgi_p) cicgi1(&argnext,argv,entries,nentries,cicgi_p); |
|---|
| 583 | #endif /* CICG1 */ |
|---|
| 584 | |
|---|
| 585 | for (x=0; x < nentries; x++) { |
|---|
| 586 | free(entries[x].namp); |
|---|
| 587 | free(entries[x].valp); |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | argv[argnext]=NULL; |
|---|
| 591 | *argc=argnext; |
|---|
| 592 | |
|---|
| 593 | return(*argc-1); |
|---|
| 594 | } |
|---|
| 595 | |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | /* cicg2 - creates a MF record MF from cgi-bin parsing |
|---|
| 599 | */ |
|---|
| 600 | |
|---|
| 601 | #if CICG1 |
|---|
| 602 | #if ANSI |
|---|
| 603 | static char *getxcgi(char *cicgi_p, char *namp); |
|---|
| 604 | static UWORD getxtag(LONGX irec, char *namp, char *wkap); |
|---|
| 605 | #else |
|---|
| 606 | static char *getxcgi(); |
|---|
| 607 | static UWORD getxtag(); |
|---|
| 608 | #endif |
|---|
| 609 | |
|---|
| 610 | static char *getxcgi(cicgi_p,namp) |
|---|
| 611 | char *cicgi_p; |
|---|
| 612 | char *namp; |
|---|
| 613 | { |
|---|
| 614 | static char retarea[80+1]; |
|---|
| 615 | char *p,*q; |
|---|
| 616 | |
|---|
| 617 | strcpy(retarea,"cicgi"); |
|---|
| 618 | |
|---|
| 619 | p=cicgi_p; q=retarea; |
|---|
| 620 | if (strcmp(namp,"dbn") == 0) { |
|---|
| 621 | while (*p && *p != ',') *q++ = *p++; |
|---|
| 622 | *q='\0'; |
|---|
| 623 | } |
|---|
| 624 | else |
|---|
| 625 | if (strcmp(namp,"701") == 0) { |
|---|
| 626 | while (*p && *p != ',') p++; |
|---|
| 627 | if (*p) p++; |
|---|
| 628 | while (*p && *p != ',') *q++ = *p++; |
|---|
| 629 | *q='\0'; |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | return retarea; |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | |
|---|
| 636 | static UWORD getxtag(irec,namp,wkap) |
|---|
| 637 | LONGX irec; |
|---|
| 638 | char *namp; |
|---|
| 639 | char *wkap; |
|---|
| 640 | { |
|---|
| 641 | UWORD xtag; |
|---|
| 642 | int iocc,len; |
|---|
| 643 | LONGX lv; |
|---|
| 644 | |
|---|
| 645 | for (xtag=0, len=strlen(namp), iocc=1; !xtag; iocc++) { |
|---|
| 646 | recfield(wkap,irec,TAGMXTGS,iocc,""); |
|---|
| 647 | if (!*wkap) break; |
|---|
| 648 | if (strncmp(wkap,namp,len) == 0) { |
|---|
| 649 | /* nam=tag */ |
|---|
| 650 | if (sscanf(wkap+len+1,"%ld",&lv) == 1) xtag=(UWORD)lv; |
|---|
| 651 | break; |
|---|
| 652 | } |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | if (!xtag) |
|---|
| 656 | if (strncmp(namp,"tag",3) == 0) |
|---|
| 657 | /* tag999 */ |
|---|
| 658 | if (sscanf(namp+3,"%ld",&lv) == 1) xtag=(UWORD)lv; |
|---|
| 659 | |
|---|
| 660 | return xtag; |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | #if CICPP |
|---|
| 665 | #if CICG1 |
|---|
| 666 | int CGIClass::cicgi1(int *argc, |
|---|
| 667 | char *argv[], |
|---|
| 668 | CICGI_ENTRY entries[], |
|---|
| 669 | int nentries, |
|---|
| 670 | char *cicgi_p) |
|---|
| 671 | #endif /* CICG1 */ |
|---|
| 672 | #else /* CICPP */ |
|---|
| 673 | int cicgi1(argc,argv,entries,nentries,cicgi_p) |
|---|
| 674 | int *argc; |
|---|
| 675 | char *argv[]; |
|---|
| 676 | CICGI_ENTRY entries[]; |
|---|
| 677 | int nentries; |
|---|
| 678 | char *cicgi_p; |
|---|
| 679 | #endif /* CICPP */ |
|---|
| 680 | { |
|---|
| 681 | |
|---|
| 682 | LONGX buffridx,workridx,parmridx; |
|---|
| 683 | LONGX irec; |
|---|
| 684 | UWORD xtags[CICGI_MAXENTRIES],xtag; |
|---|
| 685 | int tagged=0; |
|---|
| 686 | |
|---|
| 687 | char *cicgi_dbnp=NULL; |
|---|
| 688 | int retc=0; |
|---|
| 689 | |
|---|
| 690 | char *wka=NULL; |
|---|
| 691 | char *buffup,*parmp; |
|---|
| 692 | |
|---|
| 693 | RECSTRU *recp; |
|---|
| 694 | LONGX upirec=0L; |
|---|
| 695 | LONGX upcrec=0L; |
|---|
| 696 | |
|---|
| 697 | LONGX mfn; |
|---|
| 698 | int iex; |
|---|
| 699 | UWORD nexttag,thistag; |
|---|
| 700 | char *lastnamp=""; |
|---|
| 701 | unsigned int uv,un; |
|---|
| 702 | LONGX lv; |
|---|
| 703 | char *x701p; |
|---|
| 704 | |
|---|
| 705 | int rc; |
|---|
| 706 | char *p,*q,*xbp,*xwp,xchr,*q2; |
|---|
| 707 | LONGX xnby,xlv; |
|---|
| 708 | char *fmtp; |
|---|
| 709 | int n; |
|---|
| 710 | #if CICGXGIZ |
|---|
| 711 | VGIZPSTRU *gizmap; |
|---|
| 712 | GIZMSTRU *gizmp; |
|---|
| 713 | int ngizmos=0; |
|---|
| 714 | int gizminfo; |
|---|
| 715 | #endif |
|---|
| 716 | |
|---|
| 717 | FILE *fp; |
|---|
| 718 | int fd,left; |
|---|
| 719 | |
|---|
| 720 | int nexec; |
|---|
| 721 | UWORD tagexec[32]; |
|---|
| 722 | int occexec[32]; |
|---|
| 723 | |
|---|
| 724 | char *outfilnp=NULL; |
|---|
| 725 | int outfiltt=0; |
|---|
| 726 | FILE *ofp=stdout; |
|---|
| 727 | |
|---|
| 728 | #if CICGSRCH |
|---|
| 729 | #define MAXSRCH 8 |
|---|
| 730 | int vsrchoff[MAXSRCH]; |
|---|
| 731 | int vsrchmfn1[MAXSRCH]; |
|---|
| 732 | int vsrchmfn2[MAXSRCH]; |
|---|
| 733 | LONGX vsrchirec[MAXSRCH]; |
|---|
| 734 | LONGX vsrchitrm[MAXSRCH]; |
|---|
| 735 | int vsrchoccex[MAXSRCH]; |
|---|
| 736 | int vsrchoccexx[MAXSRCH]; |
|---|
| 737 | LONGX vsrchbastag[MAXSRCH]; |
|---|
| 738 | int vsrchmaster[MAXSRCH]; |
|---|
| 739 | char *vsrchdbxname[MAXSRCH]; |
|---|
| 740 | char *vsrchdictk1p[MAXSRCH]; |
|---|
| 741 | char *vsrchdictk2p[MAXSRCH]; |
|---|
| 742 | LONGX vsrchdicth[MAXSRCH]; |
|---|
| 743 | LONGX vsrchdicths[MAXSRCH]; |
|---|
| 744 | char *srchqrydbnp=NULL; |
|---|
| 745 | int srchsrch=0; |
|---|
| 746 | |
|---|
| 747 | char *srchdbnp; |
|---|
| 748 | char *srchqryp; |
|---|
| 749 | LONGX srchirec,srchitrm,srchbastag; |
|---|
| 750 | LONGX srchnbytes1; |
|---|
| 751 | LONGX srchh,srchhits,mfn1,mfn2,mfn0,lvh; |
|---|
| 752 | int srchi,srcherrno; |
|---|
| 753 | char buffedit[B4UPLEN+1]; |
|---|
| 754 | char *b,*up,*tp,*ep; |
|---|
| 755 | char *bufsizbuff; |
|---|
| 756 | LONGX bufsizbridx=0; |
|---|
| 757 | |
|---|
| 758 | int f2_xerrno; |
|---|
| 759 | int f2_errcod; |
|---|
| 760 | char f2_iomsg[MAXFATML+1]; |
|---|
| 761 | jmp_buf f2_jumper; |
|---|
| 762 | |
|---|
| 763 | #endif /* CISISRCH */ |
|---|
| 764 | extern int errno; |
|---|
| 765 | |
|---|
| 766 | /* init rec_maxmfrl */ |
|---|
| 767 | //dbxinit(); |
|---|
| 768 | if (!ndbxs) dbxinit(); /* init vdbxp/vrecp/vtrmp if not yet init - AOT, 28/10/2005 */ |
|---|
| 769 | |
|---|
| 770 | /* trap cisis fatal() */ |
|---|
| 771 | dbxopt_errno=0; /* dbxopen/errno */ |
|---|
| 772 | strcpy(fatal_iomsg,"trap"); |
|---|
| 773 | rc = setjmp(fatal_jumper); |
|---|
| 774 | if (rc != 0) { |
|---|
| 775 | printf("Content-type: text/html%c%c",10,10); |
|---|
| 776 | printf("CISIS/CGI detected an error: %s [%d]\n",fatal_iomsg,errno); |
|---|
| 777 | strcpy(fatal_iomsg,""); /* notrap fatal() */ |
|---|
| 778 | return(fatal_errcod); |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | |
|---|
| 782 | /* allocate fdlupdat() buffer */ |
|---|
| 783 | RECALLOC(buffridx=nrecs,rec_maxmfrl); |
|---|
| 784 | buffup=VMFX(buffridx); /* ds */ |
|---|
| 785 | |
|---|
| 786 | /* allocate another fdlupdat() buffer - small */ |
|---|
| 787 | #if CICGSRCH |
|---|
| 788 | RECALLOC(bufsizbridx=nrecs,BUFSIZ+1); |
|---|
| 789 | bufsizbuff=VMFX(bufsizbridx); /* ds */ |
|---|
| 790 | #endif /* CISISRCH */ |
|---|
| 791 | |
|---|
| 792 | /* allocate working buffer */ |
|---|
| 793 | RECALLOC(workridx=nrecs,rec_maxmfrl); |
|---|
| 794 | wka=VMFX(workridx); /* ds */ |
|---|
| 795 | |
|---|
| 796 | /* allocate parameter area */ |
|---|
| 797 | RECALLOC(parmridx=nrecs,rec_maxmfrl/*BUFSIZ+BUFSIZ*/); |
|---|
| 798 | parmp=VMFX(parmridx); /* ds */ |
|---|
| 799 | |
|---|
| 800 | /* load parameter record */ |
|---|
| 801 | RECALLOC(irec=nrecs,rec_maxmfrl/*+rec_maxmfrl*/); |
|---|
| 802 | RECtype=TYPEMFR; |
|---|
| 803 | RECrc=RCNORMAL; |
|---|
| 804 | MFRmfn=1; |
|---|
| 805 | MFRmfrl=MFRbase=LEADER; MFRnvf=0; |
|---|
| 806 | MFRstatus=ACTIVE; |
|---|
| 807 | |
|---|
| 808 | for (mfn=1L; RECrc != RCEOF; mfn++) { |
|---|
| 809 | RECORD(irec,(cicgi_dbnp=strdup(getxcgi(cicgi_p,"dbn"))),mfn); |
|---|
| 810 | if (RECrc != RCNORMAL) continue; |
|---|
| 811 | if (cgitrace) prtfields(recp,MFRmfn); |
|---|
| 812 | x701p=getxcgi(cicgi_p,"701"); |
|---|
| 813 | if (!*x701p) break; |
|---|
| 814 | #if 0 |
|---|
| 815 | if (strcmp(recfield(wka,irec,PARMTAG5,1,"W"),"W") == 0 && |
|---|
| 816 | strcmp(recfield(wka,irec,PARMTAG6,1,"cicgi"),"cicgi") == 0 && |
|---|
| 817 | strcmp(recfield(wka,irec,PARMTAG701,1,x701p),x701p) == 0) { /* if "cicgi" */ |
|---|
| 818 | #else |
|---|
| 819 | if ( |
|---|
| 820 | #endif |
|---|
| 821 | strcmp(recfield(wka,irec,PARMTAG701,1,""),x701p) == 0) { /* if "cicgi" */ |
|---|
| 822 | break; |
|---|
| 823 | } /* end if "cicgi" */ |
|---|
| 824 | } /* end for mfn */ |
|---|
| 825 | |
|---|
| 826 | if (MFRnvf == 0) fatal("CISIS/CGI record not found"); |
|---|
| 827 | |
|---|
| 828 | |
|---|
| 829 | /* |
|---|
| 830 | Process <name>=<val> parameters |
|---|
| 831 | */ |
|---|
| 832 | /* store input pairs */ |
|---|
| 833 | *(p=buffup)='\0'; |
|---|
| 834 | for (iex=0; iex < nentries; iex++) { |
|---|
| 835 | un=strlen(entries[iex].namp); |
|---|
| 836 | uv=strlen(entries[iex].valp); |
|---|
| 837 | sprintf(p,"H%ld %ld ",(LONGX)TAGHXSUB,(LONGX)2+un+2+uv); p+=strlen(p); |
|---|
| 838 | *p++=SFLDCHR; *p++=NAMHXSUB; |
|---|
| 839 | memcpy(p,entries[iex].namp,un); p+=un; |
|---|
| 840 | *p++=SFLDCHR; *p++=VALHXSUB; |
|---|
| 841 | memcpy(p,entries[iex].valp,uv); p+=uv; |
|---|
| 842 | *p='\0'; |
|---|
| 843 | } |
|---|
| 844 | if (*buffup) fldupdat(irec,buffup); |
|---|
| 845 | |
|---|
| 846 | /* assign tags */ |
|---|
| 847 | for (nexttag=1, lastnamp="", iex=0; iex < nentries; iex++) { |
|---|
| 848 | if (strcmp(entries[iex].namp,lastnamp) == 0) { |
|---|
| 849 | thistag=xtags[iex-1]; |
|---|
| 850 | } |
|---|
| 851 | else { |
|---|
| 852 | thistag=nexttag; |
|---|
| 853 | xtag=getxtag(irec,entries[iex].namp,wka); |
|---|
| 854 | if (xtag) { |
|---|
| 855 | thistag=xtag; |
|---|
| 856 | nexttag=thistag+1; |
|---|
| 857 | tagged++; |
|---|
| 858 | } |
|---|
| 859 | else nexttag++; |
|---|
| 860 | lastnamp=entries[iex].namp; |
|---|
| 861 | } |
|---|
| 862 | xtags[iex]=thistag; |
|---|
| 863 | } |
|---|
| 864 | |
|---|
| 865 | /* store input data names */ |
|---|
| 866 | *(p=buffup)='\0'; |
|---|
| 867 | for (iex=0; iex < nentries; iex++) { |
|---|
| 868 | un=strlen(entries[iex].namp); |
|---|
| 869 | sprintf(p,"H%ld %ld ",(LONGX)TAGHXNAM,(LONGX)un); p+=strlen(p); |
|---|
| 870 | memcpy(p,entries[iex].namp,un); p+=un; |
|---|
| 871 | *p='\0'; |
|---|
| 872 | } |
|---|
| 873 | if (*buffup) fldupdat(irec,buffup); |
|---|
| 874 | |
|---|
| 875 | /* store input data values */ |
|---|
| 876 | *(p=buffup)='\0'; |
|---|
| 877 | for (iex=0; iex < nentries; iex++) { |
|---|
| 878 | uv=strlen(entries[iex].valp); |
|---|
| 879 | xtag = (tagged) ? xtags[iex] : TAGHXVAL; |
|---|
| 880 | sprintf(p,"H%ld %ld ",(LONGX)xtag,(LONGX)uv); p+=strlen(p); |
|---|
| 881 | memcpy(p,entries[iex].valp,uv); p+=uv; |
|---|
| 882 | *p='\0'; |
|---|
| 883 | } |
|---|
| 884 | if (*buffup) fldupdat(irec,buffup); |
|---|
| 885 | |
|---|
| 886 | |
|---|
| 887 | /* |
|---|
| 888 | Process "mx" commands |
|---|
| 889 | */ |
|---|
| 890 | tagexec[0]=TAGMXCTS; |
|---|
| 891 | occexec[0]=0; |
|---|
| 892 | for (nexec=1; nexec > 0; ) { /* for iocc */ |
|---|
| 893 | |
|---|
| 894 | occexec[nexec-1]++; |
|---|
| 895 | p=recfield(parmp,irec,tagexec[nexec-1],occexec[nexec-1],""); |
|---|
| 896 | |
|---|
| 897 | if (cgitrace) { |
|---|
| 898 | printf("+++ %s:\n",p); |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | while (*p == ' ') p++; |
|---|
| 902 | |
|---|
| 903 | if (*p == '*') continue; /* comment */ |
|---|
| 904 | |
|---|
| 905 | if (*p == '\0') { |
|---|
| 906 | nexec--; |
|---|
| 907 | continue; |
|---|
| 908 | } |
|---|
| 909 | |
|---|
| 910 | if (strncmp(p,"exec=",5) == 0) { |
|---|
| 911 | if (sscanf(p+5,"%ld",&lv) != 1) continue; |
|---|
| 912 | if (lv <= 0 || lv > (LONGX)USHRT_MAX) continue; |
|---|
| 913 | tagexec[nexec]=(UWORD)lv; |
|---|
| 914 | occexec[nexec]=0; |
|---|
| 915 | nexec++; |
|---|
| 916 | continue; |
|---|
| 917 | } |
|---|
| 918 | |
|---|
| 919 | if (strcmp(p,"trace") == 0) { |
|---|
| 920 | cgitrace=1; |
|---|
| 921 | continue; |
|---|
| 922 | } |
|---|
| 923 | if (strcmp(p,"prtfields") == 0) { |
|---|
| 924 | prtfields(vrecp[irec],VMFRmfn(irec)); |
|---|
| 925 | continue; |
|---|
| 926 | } |
|---|
| 927 | |
|---|
| 928 | if (strcmp(p,"setdbx") == 0) { |
|---|
| 929 | b5_keepdbx(0); |
|---|
| 930 | continue; |
|---|
| 931 | } |
|---|
| 932 | if (strcmp(p,"resetdbx") == 0) { |
|---|
| 933 | b5_keepdbx(1); |
|---|
| 934 | continue; |
|---|
| 935 | } |
|---|
| 936 | if (strncmp(p,"flush=",6) == 0) { |
|---|
| 937 | dbxflush(p+6); |
|---|
| 938 | continue; |
|---|
| 939 | } |
|---|
| 940 | |
|---|
| 941 | #if CICGSRCH |
|---|
| 942 | if (strncmp(p,"search/",7) == 0 || |
|---|
| 943 | strncmp(p,"master/",7) == 0 || |
|---|
| 944 | strncmp(p,"dict/" ,5) == 0) { |
|---|
| 945 | if (strncmp(p,"dict/" ,5) == 0) srchbastag=atol(q=p+5); |
|---|
| 946 | else srchbastag=atol(q=p+7); while (isdigit(*q)) q++; |
|---|
| 947 | if (srchbastag <= 0) cgierr(1,p); |
|---|
| 948 | if (cgitrace) for (srchi=0; srchi < srchsrch; srchi++) printf("--- 1. %d/%ld irec=%ld\n",srchi,vsrchbastag[srchi],vsrchirec[srchi]); |
|---|
| 949 | for (n=srchi=0; srchi < srchsrch; srchi++) |
|---|
| 950 | if (vsrchbastag[srchi] == srchbastag) { n=1; break; } |
|---|
| 951 | if (!n) { |
|---|
| 952 | if (srchsrch >= MAXSRCH) break; |
|---|
| 953 | srchi=srchsrch; srchsrch++; |
|---|
| 954 | } |
|---|
| 955 | if (srchi != srchsrch-1) { |
|---|
| 956 | printf("*** search/master/%ld: %d/%d\n",srchbastag,srchi,srchsrch-1); |
|---|
| 957 | break; |
|---|
| 958 | } |
|---|
| 959 | vsrchirec[srchi]=0; |
|---|
| 960 | vsrchitrm[srchi]=0; |
|---|
| 961 | vsrchoccex[srchi]=0; |
|---|
| 962 | vsrchoccexx[srchi]=0; |
|---|
| 963 | vsrchmaster[srchi]=0; |
|---|
| 964 | vsrchbastag[srchi]=srchbastag; |
|---|
| 965 | vsrchdbxname[srchi]=NULL; |
|---|
| 966 | vsrchdictk1p[srchi]=NULL; |
|---|
| 967 | vsrchdictk2p[srchi]=NULL; |
|---|
| 968 | vsrchdicth[srchi]=0; |
|---|
| 969 | vsrchdicths[srchi]=0; |
|---|
| 970 | b=buffup; |
|---|
| 971 | sprintf(b,"D%ld",srchbastag); b+=strlen(b); |
|---|
| 972 | sprintf(b,"D%ld",srchbastag+1); b+=strlen(b); |
|---|
| 973 | sprintf(b,"D%ld",srchbastag+2); b+=strlen(b); |
|---|
| 974 | sprintf(b,"D%ld",srchbastag+9); b+=strlen(b); |
|---|
| 975 | sprintf(b,"D%ld",srchbastag+11); b+=strlen(b); |
|---|
| 976 | sprintf(b,"D%ld",srchbastag+99); |
|---|
| 977 | fldupdat(irec,buffup); |
|---|
| 978 | if (*q != '=') cgierr(2,p); |
|---|
| 979 | srchdbnp = ++q; |
|---|
| 980 | if (strncmp(p,"dict/" ,5) == 0) { |
|---|
| 981 | vsrchmaster[srchi]=2; |
|---|
| 982 | q=strchr(q,' '); |
|---|
| 983 | if (q) { |
|---|
| 984 | *q++='\0'; tp=strstr(q," to="); if (tp) *tp='\0'; |
|---|
| 985 | vsrchdictk1p[srchi]=strdup(q); |
|---|
| 986 | for (up=vsrchdictk1p[srchi]; *up; up++) *up = isisuctab[*up]; |
|---|
| 987 | if (cgitrace) printf("+++ dict k1=%s\n",vsrchdictk1p[srchi]); |
|---|
| 988 | if (tp) { |
|---|
| 989 | q=tp+4; n=strlen(q); |
|---|
| 990 | if (n < LE2) { memset(q+n,*highv,LE2-n); q[LE2]='\0'; } |
|---|
| 991 | vsrchdictk2p[srchi]=strdup(q); |
|---|
| 992 | for (up=vsrchdictk2p[srchi]; *up; up++) *up = isisuctab[*up]; |
|---|
| 993 | if (cgitrace) printf("+++ dict k2=%s\n",vsrchdictk2p[srchi]); |
|---|
| 994 | } |
|---|
| 995 | } else vsrchdictk1p[srchi]=strdup("!"); |
|---|
| 996 | vsrchdbxname[srchi]=strdup(srchdbnp);; |
|---|
| 997 | } |
|---|
| 998 | else |
|---|
| 999 | if (strncmp(p,"master/",7) == 0) { |
|---|
| 1000 | vsrchmaster[srchi]=1; |
|---|
| 1001 | q=strchr(q,','); if (!q) cgierr(3,p); |
|---|
| 1002 | *q++='\0'; |
|---|
| 1003 | if (sscanf(q,"%ld,%ld",&mfn1,&mfn2) != 2) cgierr(4,p); |
|---|
| 1004 | if (mfn1 <= 0L) cgierr(5,p); |
|---|
| 1005 | if (mfn2 <= 0L) cgierr(6,p); |
|---|
| 1006 | vsrchdbxname[srchi]=strdup(srchdbnp);; |
|---|
| 1007 | } |
|---|
| 1008 | else { |
|---|
| 1009 | if ((q=strchr(q,'=')) == NULL) cgierr(7,p); |
|---|
| 1010 | *q++='\0'; |
|---|
| 1011 | if (!*q) cgierr(8,p); /* points to srchqryp */ |
|---|
| 1012 | if (!loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0')) cgierr(9,p); |
|---|
| 1013 | if (!*wka) cgierr(10,p); |
|---|
| 1014 | if (recfmt(irec,rec_maxmfrl,wka,buffup,rec_maxmfrl-1L) < 0) cgierr(11,p); |
|---|
| 1015 | if (!*buffup) cgierr(12,p); |
|---|
| 1016 | srchqryp=buffup; |
|---|
| 1017 | } |
|---|
| 1018 | if (!*srchdbnp) srchdbnp=RDBname; |
|---|
| 1019 | |
|---|
| 1020 | srchirec=vsrchirec[srchi]; |
|---|
| 1021 | if (!srchirec) { |
|---|
| 1022 | for (srchirec=0; srchirec < maxnrec; srchirec++) |
|---|
| 1023 | if (!vrecp[srchirec]) { |
|---|
| 1024 | if (cgitrace) printf("+++ srchirec/%ld=%ld\n",srchbastag,(LONGX)srchirec); |
|---|
| 1025 | vsrchirec[srchi]=srchirec; break; |
|---|
| 1026 | } |
|---|
| 1027 | if (!vsrchirec[srchi]) cgierr(13,p); |
|---|
| 1028 | recallok(srchirec,(VRECnbytes(irec) > rec_maxmfrl) ? VRECnbytes(irec) : rec_maxmfrl ); |
|---|
| 1029 | } |
|---|
| 1030 | if (vsrchmaster[srchi] == 2) { |
|---|
| 1031 | srchitrm=vsrchitrm[srchi]; |
|---|
| 1032 | if (!srchitrm) { |
|---|
| 1033 | for (srchitrm=1; srchitrm < maxntrm; srchitrm++) |
|---|
| 1034 | if (!vtrmp[srchitrm]) { |
|---|
| 1035 | if (cgitrace) printf("+++ srchitrm/%ld=%ld\n",srchbastag,(LONGX)srchitrm); |
|---|
| 1036 | vsrchitrm[srchi]=srchitrm; break; |
|---|
| 1037 | } |
|---|
| 1038 | if (!vsrchitrm[srchi]) cgierr(14,p); |
|---|
| 1039 | /* if (!vsrchdicps[srchi]) trmalloc(srchirec,0L); */ |
|---|
| 1040 | } |
|---|
| 1041 | } |
|---|
| 1042 | |
|---|
| 1043 | /* trap cisis fatal() */ |
|---|
| 1044 | f2_xerrno=dbxopt_errno; /* dbxopen/errno */ |
|---|
| 1045 | strcpy(f2_iomsg,fatal_iomsg); |
|---|
| 1046 | memcpy(f2_jumper,fatal_jumper,sizeof(fatal_jumper)); |
|---|
| 1047 | f2_errcod=fatal_errcod; |
|---|
| 1048 | strcpy(fatal_iomsg,"trap"); |
|---|
| 1049 | rc = setjmp(fatal_jumper); |
|---|
| 1050 | if (rc != 0) { |
|---|
| 1051 | retc=fatal_errcod; |
|---|
| 1052 | memcpy(fatal_jumper,f2_jumper,sizeof(fatal_jumper)); |
|---|
| 1053 | strcpy(fatal_iomsg,f2_iomsg); |
|---|
| 1054 | fatal_errcod=f2_errcod; |
|---|
| 1055 | dbxopt_errno=f2_xerrno; |
|---|
| 1056 | break; /* continue! */ |
|---|
| 1057 | } |
|---|
| 1058 | |
|---|
| 1059 | if (vsrchmaster[srchi] == 2) { |
|---|
| 1060 | term(srchitrm,vsrchdbxname[srchi],vsrchdictk1p[srchi]); |
|---|
| 1061 | for (lv=0; VTRMrc(srchitrm) != RCEOF; ) { |
|---|
| 1062 | if (vsrchdictk2p[srchi]) |
|---|
| 1063 | if (strcmp(VTRMkey(srchitrm),vsrchdictk2p[srchi]) > 0) break; |
|---|
| 1064 | if (VTRMxytotp(srchitrm)) lv++; |
|---|
| 1065 | nxterm(srchitrm); |
|---|
| 1066 | } |
|---|
| 1067 | vsrchdicths[srchi]=lv; |
|---|
| 1068 | } |
|---|
| 1069 | else { |
|---|
| 1070 | record(srchirec,srchdbnp,0L); |
|---|
| 1071 | lv=VMF0nxtmfn(srchirec)-1; |
|---|
| 1072 | } |
|---|
| 1073 | b=bufsizbuff; /* srchqryp is using buffup */ |
|---|
| 1074 | sprintf(b,"A%ld#%s#",srchbastag+9,srchdbnp); b+=strlen(b); |
|---|
| 1075 | sprintf(b,"A%ld#%ld#",srchbastag+11,0L); b+=strlen(b); |
|---|
| 1076 | fldupdat(irec,bufsizbuff); |
|---|
| 1077 | if (vsrchmaster[srchi] == 1) { |
|---|
| 1078 | mfn=VMF0nxtmfn(srchirec)-1; |
|---|
| 1079 | if (mfn1 > mfn) mfn1=mfn; |
|---|
| 1080 | if (mfn2 > mfn) mfn2=mfn; |
|---|
| 1081 | vsrchmfn1[srchi]=mfn1; |
|---|
| 1082 | vsrchmfn2[srchi]=mfn2; |
|---|
| 1083 | } |
|---|
| 1084 | if (vsrchmaster[srchi] == 0) { |
|---|
| 1085 | srchnbytes1=VMF0nxtmfn(srchirec)/8+1; |
|---|
| 1086 | for (mfn=1; ; mfn++) { |
|---|
| 1087 | record(srchirec,srchdbnp,mfn); |
|---|
| 1088 | if (VRECrc(srchirec) == RCEOF) break; |
|---|
| 1089 | if (VRECrc(srchirec) == RCNORMAL) break; |
|---|
| 1090 | } |
|---|
| 1091 | lv=BUFSIZ+strlen(srchqryp)+srchnbytes1; |
|---|
| 1092 | if (lv > VRECnbytes(srchirec)) { |
|---|
| 1093 | FREE(vrecp[srchirec]); vrecp[srchirec]=NULL; nrecs--; |
|---|
| 1094 | recallok(srchirec,lv); |
|---|
| 1095 | } |
|---|
| 1096 | if (!srchqrydbnp) { |
|---|
| 1097 | srchqrydbnp=gettmpnam(NULL); /* wka*/ |
|---|
| 1098 | } |
|---|
| 1099 | /* b4_exp assigns MFRmfn=RDBmsmfn */ |
|---|
| 1100 | VRECdbxp(srchirec)=dbxstorp(srchqrydbnp); |
|---|
| 1101 | if (VRDBmsmfn(srchirec) > 0) { |
|---|
| 1102 | for (b4setno=1, n=0; n < srchi; n++) |
|---|
| 1103 | if (vsrchmaster[srchi] == 0) b4setno++; |
|---|
| 1104 | VRDBmsmfn(srchirec) = b4setno; |
|---|
| 1105 | } |
|---|
| 1106 | ep=b4_exp(srchirec,srchdbnp,srchqryp,srchqrydbnp,&srcherrno); /* buffup */ |
|---|
| 1107 | if (srcherrno) fatal(ep); |
|---|
| 1108 | ep=b4_run(srchirec,srchdbnp,srchnbytes1,rec_maxmfrl,(LONGX)cgitrace, |
|---|
| 1109 | isisuctab,0L,&srcherrno); |
|---|
| 1110 | if (srcherrno) fatal(ep); |
|---|
| 1111 | sprintf(buffup,"A%ld#%s^m%ld#",srchbastag+99,srchqrydbnp,VMFRmfn(srchirec)); |
|---|
| 1112 | fldupdat(irec,buffup); |
|---|
| 1113 | } /* end else vsrchmaster[srchi] */ |
|---|
| 1114 | continue; |
|---|
| 1115 | } |
|---|
| 1116 | |
|---|
| 1117 | if (strncmp(p,"gethit/",7) == 0) { |
|---|
| 1118 | srchbastag=atol(q=p+7); while (isdigit(*q)) q++; |
|---|
| 1119 | if (srchbastag <= 0) cgierr(15,p); |
|---|
| 1120 | if (cgitrace) for (srchi=0; srchi < srchsrch; srchi++) printf("--- 2. %d/%ld irec=%ld/%ld\n",srchi,vsrchbastag[srchi],irec,vsrchirec[srchi]); |
|---|
| 1121 | for (n=srchi=0; srchi < srchsrch; srchi++) |
|---|
| 1122 | if (vsrchbastag[srchi] == srchbastag) { n=1; break; } |
|---|
| 1123 | if (!n) cgierr(16,p); |
|---|
| 1124 | if (srchi != srchsrch-1) { |
|---|
| 1125 | printf("*** gethit/%ld: %d/%d\n",srchbastag,srchi,srchsrch-1); |
|---|
| 1126 | break; |
|---|
| 1127 | } |
|---|
| 1128 | |
|---|
| 1129 | srchirec=vsrchirec[srchi]; |
|---|
| 1130 | srchitrm=vsrchitrm[srchi]; |
|---|
| 1131 | |
|---|
| 1132 | if (vsrchmaster[srchi] == 2) {; |
|---|
| 1133 | srchh=vsrchdicth[srchi]; |
|---|
| 1134 | srchhits=vsrchdicths[srchi]; |
|---|
| 1135 | } |
|---|
| 1136 | else |
|---|
| 1137 | if (vsrchmaster[srchi] == 1) { |
|---|
| 1138 | srchh=VMFRmfn(srchirec); |
|---|
| 1139 | mfn1=vsrchmfn1[srchi]; |
|---|
| 1140 | mfn2=vsrchmfn2[srchi]; |
|---|
| 1141 | srchhits=mfn2-mfn1+1; if (srchhits < 0) srchhits=(-srchhits); |
|---|
| 1142 | } |
|---|
| 1143 | else { |
|---|
| 1144 | recfield(buffedit,srchirec,MFQTHCUR,1,""); |
|---|
| 1145 | if (!*buffedit) cgierr(17,p); |
|---|
| 1146 | sscanf(buffedit,B4EDIT1,&srchh); |
|---|
| 1147 | srchhits=b4_hit(srchirec,0L); |
|---|
| 1148 | } |
|---|
| 1149 | mfn0=0; |
|---|
| 1150 | if (srchh == 0) { /* 1st time */ |
|---|
| 1151 | if (cgitrace) printf("+++ gethit/%ld=%ld hits\n",srchbastag,srchhits); |
|---|
| 1152 | srchh=1L; vsrchoff[srchi] = 1; |
|---|
| 1153 | if (vsrchmaster[srchi] == 1) { |
|---|
| 1154 | if (mfn1 > mfn2) vsrchoff[srchi] = -1; |
|---|
| 1155 | VMFRmfn(srchirec)=mfn1; |
|---|
| 1156 | } |
|---|
| 1157 | else |
|---|
| 1158 | if (vsrchmaster[srchi] == 0) if (strcmp(q,"/rev") == 0) { |
|---|
| 1159 | srchh=srchhits; vsrchoff[srchi] = -1; |
|---|
| 1160 | } |
|---|
| 1161 | vsrchoccex[srchi]=occexec[nexec-1]; /* save gethit occ (tag) */ |
|---|
| 1162 | for (n=occexec[nexec-1]; ++n; ) { |
|---|
| 1163 | q=recfield(buffup,irec,tagexec[nexec-1],n,""); |
|---|
| 1164 | if (!*q) break; |
|---|
| 1165 | if (strncmp(q,"endhit/",7) != 0) continue; |
|---|
| 1166 | if (atol(q+7) != srchbastag) continue; |
|---|
| 1167 | vsrchoccexx[srchi]=n+1; /* save endhit occ+1 (tag) */ |
|---|
| 1168 | break; |
|---|
| 1169 | } |
|---|
| 1170 | if (!vsrchoccexx[srchi]) cgierr(18,p); |
|---|
| 1171 | } |
|---|
| 1172 | else { |
|---|
| 1173 | if (vsrchmaster[srchi] == 1) { |
|---|
| 1174 | mfn0=VMFRmfn(srchirec); |
|---|
| 1175 | VMFRmfn(srchirec)+=vsrchoff[srchi]; |
|---|
| 1176 | } |
|---|
| 1177 | else if (vsrchmaster[srchi] == 0) { |
|---|
| 1178 | mfn0=b4_hit(srchirec,srchh); |
|---|
| 1179 | srchh+=vsrchoff[srchi]; |
|---|
| 1180 | } |
|---|
| 1181 | } |
|---|
| 1182 | |
|---|
| 1183 | if (vsrchmaster[srchi] == 2) { |
|---|
| 1184 | mfn=0; |
|---|
| 1185 | if (!vsrchdicth[srchi]) *VTRMkey(srchitrm)='\0'; |
|---|
| 1186 | while (mfn == 0) { |
|---|
| 1187 | if (!*VTRMkey(srchitrm)) |
|---|
| 1188 | term(srchitrm,VTDBname(srchitrm),vsrchdictk1p[srchi]); /* rewind */ |
|---|
| 1189 | else |
|---|
| 1190 | nxterm(srchitrm); |
|---|
| 1191 | if (VTRMrc(srchitrm) == RCEOF) break; |
|---|
| 1192 | if (vsrchdictk2p[srchi]) |
|---|
| 1193 | if (strcmp(VTRMkey(srchitrm),vsrchdictk2p[srchi]) > 0) break; |
|---|
| 1194 | mfn=posting(srchitrm,VTRMpost(srchitrm)+1); |
|---|
| 1195 | if (mfn <= 0) {mfn=0; break;} |
|---|
| 1196 | } |
|---|
| 1197 | lvh= ++vsrchdicth[srchi]; |
|---|
| 1198 | } |
|---|
| 1199 | else |
|---|
| 1200 | if (vsrchmaster[srchi] == 1) { |
|---|
| 1201 | for (mfn=VMFRmfn(srchirec); ; ) { |
|---|
| 1202 | if (mfn == mfn2+vsrchoff[srchi]) { mfn=0; break; } |
|---|
| 1203 | else { |
|---|
| 1204 | record(srchirec,vsrchdbxname[srchi],mfn); |
|---|
| 1205 | if (VRECrc(srchirec) == RCEOF) { mfn=0; break; } |
|---|
| 1206 | if (VMFRstatus(srchirec) == ACTIVE) break; |
|---|
| 1207 | mfn+=vsrchoff[srchi]; |
|---|
| 1208 | } |
|---|
| 1209 | } |
|---|
| 1210 | lvh=(vsrchoff[srchi] == 1)?mfn-mfn1+1:mfn1-mfn+1; |
|---|
| 1211 | } |
|---|
| 1212 | else { |
|---|
| 1213 | if (srchh/*its*/) mfn=b4_hit(srchirec,srchh); else mfn=0; |
|---|
| 1214 | lvh=(vsrchoff[srchi] == 1)?srchh:srchhits-srchh+1; |
|---|
| 1215 | } |
|---|
| 1216 | |
|---|
| 1217 | if (mfn > 0) { |
|---|
| 1218 | if (vsrchmaster[srchi] == 2) { |
|---|
| 1219 | b=buffup; |
|---|
| 1220 | sprintf(b,"D%ldA%ld\n",srchbastag+51,srchbastag+51); b+=strlen(b); |
|---|
| 1221 | strcpy(b,VTRMkey(srchitrm)); |
|---|
| 1222 | for (b+=strlen(b); ; b--) if (*(b-1) != ' ') break; |
|---|
| 1223 | sprintf(b,"\n"); |
|---|
| 1224 | fldupdat(irec,buffup); |
|---|
| 1225 | } |
|---|
| 1226 | b=buffup; |
|---|
| 1227 | sprintf(b,"D%ldD%ldD%ldD%ld",srchbastag,srchbastag+1,srchbastag+2,srchbastag+11); |
|---|
| 1228 | b+=strlen(b); |
|---|
| 1229 | sprintf(b,"A%ld#%ld#",srchbastag,mfn); b+=strlen(b); |
|---|
| 1230 | sprintf(b,"A%ld#%ld#",srchbastag+1,lvh); b+=strlen(b); |
|---|
| 1231 | sprintf(b,"A%ld#%ld#",srchbastag+2,srchhits); b+=strlen(b); |
|---|
| 1232 | sprintf(b,"A%ld#%ld#",srchbastag+11,mfn0); |
|---|
| 1233 | fldupdat(irec,buffup); |
|---|
| 1234 | } |
|---|
| 1235 | else { |
|---|
| 1236 | if (srchitrm) if (vtrmp[srchitrm]) { |
|---|
| 1237 | FREE(vtrmp[srchitrm]); vtrmp[srchitrm]=NULL; ntrms--; |
|---|
| 1238 | } |
|---|
| 1239 | if (srchirec) if (vrecp[srchirec]) { |
|---|
| 1240 | FREE(vrecp[srchirec]); vrecp[srchirec]=NULL; nrecs--; |
|---|
| 1241 | } |
|---|
| 1242 | if (vsrchdictk1p[srchi]) FREE(vsrchdictk1p[srchi]); |
|---|
| 1243 | if (vsrchdictk2p[srchi]) FREE(vsrchdictk2p[srchi]); |
|---|
| 1244 | if (vsrchdbxname[srchi]) FREE(vsrchdbxname[srchi]); |
|---|
| 1245 | if (srchsrch) srchsrch--; |
|---|
| 1246 | if (srchsrch == 0) |
|---|
| 1247 | if (srchqrydbnp) { |
|---|
| 1248 | dbxflush(srchqrydbnp); |
|---|
| 1249 | FREE(srchqrydbnp); srchqrydbnp=NULL; |
|---|
| 1250 | } |
|---|
| 1251 | occexec[nexec-1]=vsrchoccexx[srchi]; /* set endhit occ+1 (tag) */ |
|---|
| 1252 | occexec[nexec-1]--; /* occexec[nexec-1]++; */ |
|---|
| 1253 | } |
|---|
| 1254 | continue; |
|---|
| 1255 | } |
|---|
| 1256 | |
|---|
| 1257 | if (strncmp(p,"endhit/",7) == 0) { |
|---|
| 1258 | srchbastag=atol(q=p+7); while (isdigit(*q)) q++; |
|---|
| 1259 | if (srchbastag <= 0) cgierr(22,p); |
|---|
| 1260 | if (cgitrace) for (srchi=0; srchi < srchsrch; srchi++) printf("--- 3. %d/%ld irec=%ld/%ld\n",srchi,vsrchbastag[srchi],irec,vsrchirec[srchi]); |
|---|
| 1261 | for (n=srchi=0; srchi < srchsrch; srchi++) |
|---|
| 1262 | if (vsrchbastag[srchi] == srchbastag) { n=1; break; } |
|---|
| 1263 | if (!n) cgierr(23,p); |
|---|
| 1264 | if (srchi != srchsrch-1) { |
|---|
| 1265 | printf("*** endhit/%ld: %d/%d\n",srchbastag,srchi,srchsrch-1); |
|---|
| 1266 | break; |
|---|
| 1267 | } |
|---|
| 1268 | if (vsrchoccex[srchi]) { |
|---|
| 1269 | occexec[nexec-1]=vsrchoccex[srchi]; /* set gethit occ (tag) */ |
|---|
| 1270 | occexec[nexec-1]--; /* occexec[nexec-1]++; */ |
|---|
| 1271 | } |
|---|
| 1272 | continue; |
|---|
| 1273 | } |
|---|
| 1274 | #if 00 |
|---|
| 1275 | #define MFQTDBN0 11 |
|---|
| 1276 | #define MFQTQRY0 12 |
|---|
| 1277 | #define MFQTOBJ0 13 |
|---|
| 1278 | #define MFQTXCTS 20 |
|---|
| 1279 | #define MFQSWTIM 't' |
|---|
| 1280 | #define MFQSWDBN 'd' |
|---|
| 1281 | #define MFQSWQTY 'q' |
|---|
| 1282 | #define MFQTASET 21 |
|---|
| 1283 | #define MFQTALCC 22 |
|---|
| 1284 | #define MFQTHITS 31 |
|---|
| 1285 | #define MFQTHCUR 32 |
|---|
| 1286 | #define MFQTHMFN 33 |
|---|
| 1287 | #define MFQTHSIZ 34 |
|---|
| 1288 | #define MFQTHMEM 35 |
|---|
| 1289 | #define B4EDIT1 "%06ld" /* sprintf format for field edit */ |
|---|
| 1290 | #endif |
|---|
| 1291 | #endif /* CICGSRCH */ |
|---|
| 1292 | |
|---|
| 1293 | if (strncmp(p,"goto=",5) == 0) { |
|---|
| 1294 | q=p+5; if (!*q) continue; |
|---|
| 1295 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1296 | if (recfmt(irec,rec_maxmfrl,wka,buffup,rec_maxmfrl-1L) < 0) fatal(wka); |
|---|
| 1297 | if (!*buffup) continue; /* accepts no label */ |
|---|
| 1298 | for (n=1; ++n; ) { |
|---|
| 1299 | q=recfield(wka,irec,tagexec[nexec-1],n,""); |
|---|
| 1300 | if (!*q) break; |
|---|
| 1301 | if (strncmp(q,"label=",6)) continue; |
|---|
| 1302 | if (strcmp(q+6,buffup)) continue; |
|---|
| 1303 | occexec[nexec-1]=n; /* occexec[nexec-1]++; */ |
|---|
| 1304 | n=0; |
|---|
| 1305 | break; |
|---|
| 1306 | } |
|---|
| 1307 | if (n) cgierr(24,p); |
|---|
| 1308 | continue; |
|---|
| 1309 | } |
|---|
| 1310 | |
|---|
| 1311 | if (strncmp(p,"sys=",4) == 0) { |
|---|
| 1312 | q=p+4; if (!*q) continue; |
|---|
| 1313 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1314 | if (cgitrace) printf("+++ sys=%s\n",wka); |
|---|
| 1315 | system(wka); |
|---|
| 1316 | continue; |
|---|
| 1317 | } |
|---|
| 1318 | |
|---|
| 1319 | if (strncmp(p,"set_of=",7) == 0) { |
|---|
| 1320 | q=p+7; if (!*q) continue; |
|---|
| 1321 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1322 | if (recfmt(irec,rec_maxmfrl,wka,buffup,rec_maxmfrl-1L) < 0) fatal(wka); |
|---|
| 1323 | outfiltt=1; |
|---|
| 1324 | if (outfilnp) FREE(outfilnp); outfilnp=strdup(buffup); |
|---|
| 1325 | if (cgitrace) printf("+++ set_of=%s\n",outfilnp); |
|---|
| 1326 | fp=fopen(outfilnp,"w"); |
|---|
| 1327 | if (fp != (FILE *)NULL) ofp=fp; |
|---|
| 1328 | continue; |
|---|
| 1329 | } |
|---|
| 1330 | if (strcmp(p,"get_of") == 0) { |
|---|
| 1331 | #if 0 |
|---|
| 1332 | q=getenv("GET_OF"); |
|---|
| 1333 | if (!q) continue; |
|---|
| 1334 | if (*q != 'Y') continue; |
|---|
| 1335 | #endif |
|---|
| 1336 | q=getenv("OUTPUT_FILE"); |
|---|
| 1337 | if (!q) { q=gettmpnam(wka); outfiltt=1; } |
|---|
| 1338 | if (outfilnp) FREE(outfilnp); outfilnp=strdup(q); |
|---|
| 1339 | if (cgitrace) printf("+++ getof=%s\n",outfilnp); |
|---|
| 1340 | fp=fopen(outfilnp,"w"); |
|---|
| 1341 | if (fp != (FILE *)NULL) ofp=fp; |
|---|
| 1342 | continue; |
|---|
| 1343 | } |
|---|
| 1344 | if (strcmp(p,"type_of") == 0) { |
|---|
| 1345 | if (!outfilnp) continue; |
|---|
| 1346 | if (!ofp) continue; |
|---|
| 1347 | if (ofp == stdout) continue; |
|---|
| 1348 | fclose(ofp); ofp=stdout; /*(FILE *)NULL;*/ |
|---|
| 1349 | #if PC |
|---|
| 1350 | sprintf(wka,"type %s",outfilnp); |
|---|
| 1351 | #else |
|---|
| 1352 | sprintf(wka,"cat %s",outfilnp); |
|---|
| 1353 | #endif |
|---|
| 1354 | system(wka); |
|---|
| 1355 | continue; |
|---|
| 1356 | } |
|---|
| 1357 | if (strcmp(p,"del_of") == 0) { |
|---|
| 1358 | if (!outfilnp) continue; |
|---|
| 1359 | if (!outfiltt) continue; |
|---|
| 1360 | if (ofp) if (ofp != stdout) { fclose(ofp); ofp=stdout; /*(FILE *)NULL;*/ } |
|---|
| 1361 | outfiltt=0; |
|---|
| 1362 | #if PC |
|---|
| 1363 | sprintf(wka,"del %s",outfilnp); |
|---|
| 1364 | #else |
|---|
| 1365 | sprintf(wka,"rm %s",outfilnp); |
|---|
| 1366 | #endif |
|---|
| 1367 | system(wka); |
|---|
| 1368 | continue; |
|---|
| 1369 | } |
|---|
| 1370 | if (strcmp(p,"close_of") == 0) { |
|---|
| 1371 | if (!outfilnp) continue; |
|---|
| 1372 | if (ofp) if (ofp != stdout) { fclose(ofp); ofp=stdout; /*(FILE *)NULL;*/ } |
|---|
| 1373 | outfiltt=0; |
|---|
| 1374 | continue; |
|---|
| 1375 | } |
|---|
| 1376 | |
|---|
| 1377 | if (strncmp(p,"cat=",4) == 0) { |
|---|
| 1378 | q=p+4; if (!*q) continue; |
|---|
| 1379 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1380 | if (cgitrace) printf("+++ cat=%s\n",wka); |
|---|
| 1381 | fd=dbxopen(RDBname,wka,""); |
|---|
| 1382 | if (fd <= 0) continue; |
|---|
| 1383 | while ((left=CIREAD(fd,wka,BUFSIZ)) > 0) { |
|---|
| 1384 | if (wka[left-1] == 0x1A) left--; |
|---|
| 1385 | for (q=wka; left--; q++) if (*q != '\r') fprintf(ofp,"%c",*q); |
|---|
| 1386 | } |
|---|
| 1387 | CLOSE(fd); |
|---|
| 1388 | continue; |
|---|
| 1389 | } |
|---|
| 1390 | |
|---|
| 1391 | #if CICGMXMX |
|---|
| 1392 | #endif /* CICGMXMX */ |
|---|
| 1393 | |
|---|
| 1394 | |
|---|
| 1395 | if (strncmp(p,"rec=",4) == 0) { |
|---|
| 1396 | q=p+4; |
|---|
| 1397 | q2=strchr(q,'='); if (!q2) fatal(p); *q2='\0'; q2++; |
|---|
| 1398 | if (!*q) q=gettmpnam(wka); |
|---|
| 1399 | |
|---|
| 1400 | if (cgitrace) printf("+++ rec=%s/%s\n",q,q2); |
|---|
| 1401 | |
|---|
| 1402 | recallok((upcrec=getridx(31,p)),(LONGX)sizeof(M0STRU)); |
|---|
| 1403 | #if 0 |
|---|
| 1404 | VRECtype(upcrec)=TYPEMF0; |
|---|
| 1405 | VRECdbxp(upcrec)=dbxstorp(q); /* wka */ |
|---|
| 1406 | VRECrc(upcrec)=RCNORMAL; |
|---|
| 1407 | memset(VMFX(upcrec),0x00,sizeof(M0STRU)); |
|---|
| 1408 | VMF0nxtmfn(upcrec)=1L; |
|---|
| 1409 | #endif |
|---|
| 1410 | record(upcrec,q,0L); |
|---|
| 1411 | |
|---|
| 1412 | recallok((upirec=getridx(32,p)), |
|---|
| 1413 | (VRECnbytes(irec) > rec_maxmfrl) ? VRECnbytes(irec) : rec_maxmfrl); |
|---|
| 1414 | |
|---|
| 1415 | VRECtype(upirec)=TYPEMFR; |
|---|
| 1416 | VRECdbxp(upirec)=VRECdbxp(upcrec); |
|---|
| 1417 | VRECrc(upirec)=RCNORMAL; |
|---|
| 1418 | #if 0 |
|---|
| 1419 | memset(VMFX(upirec),0x00,LEADER); |
|---|
| 1420 | VMFRmfn(upirec)=1L; VMFRmfrl(upirec)=VMFRbase(upirec)=LEADER; |
|---|
| 1421 | #endif |
|---|
| 1422 | memcpy(VMFX(upirec),VMFX(irec),VMFRmfrl(irec)); |
|---|
| 1423 | VMFRmfn(upirec)=VMF0nxtmfn(upcrec); |
|---|
| 1424 | |
|---|
| 1425 | if (q2) if (fldupdat(upirec,q2)) fatal(p); |
|---|
| 1426 | |
|---|
| 1427 | recupdat(upcrec,upirec); |
|---|
| 1428 | |
|---|
| 1429 | FREE(vrecp[upcrec]); vrecp[upcrec]=NULL; nrecs--; |
|---|
| 1430 | FREE(vrecp[upirec]); vrecp[upirec]=NULL; nrecs--; |
|---|
| 1431 | |
|---|
| 1432 | continue; |
|---|
| 1433 | } |
|---|
| 1434 | |
|---|
| 1435 | if (strncmp(p,"log=",4) == 0) { |
|---|
| 1436 | q=p+4; if (!*q) continue; |
|---|
| 1437 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1438 | if (cgitrace) printf("+++ log=%s\n",wka); |
|---|
| 1439 | recisis0(wka); record(buffridx,wka,0L); |
|---|
| 1440 | mfn=VMFRmfn(irec); |
|---|
| 1441 | VMFRmfn(irec)=1; recupdat(buffridx,irec); |
|---|
| 1442 | VMFRmfn(irec)=mfn; |
|---|
| 1443 | continue; |
|---|
| 1444 | } |
|---|
| 1445 | |
|---|
| 1446 | if (strncmp(p,"app=",4) == 0) { |
|---|
| 1447 | q=p+4; if (!*q) continue; |
|---|
| 1448 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1449 | if (cgitrace) printf("+++ app=%s\n",wka); |
|---|
| 1450 | record(buffridx,wka,0L); |
|---|
| 1451 | mfn=VMFRmfn(irec); |
|---|
| 1452 | VMFRmfn(irec)=VMF0nxtmfn(buffridx); recupdat(buffridx,irec); |
|---|
| 1453 | VMFRmfn(irec)=mfn; |
|---|
| 1454 | continue; |
|---|
| 1455 | } |
|---|
| 1456 | |
|---|
| 1457 | if (strncmp(p,"zer=",4) == 0) { |
|---|
| 1458 | q=p+4; if (!*q) continue; |
|---|
| 1459 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1460 | if (cgitrace) printf("+++ zer=%s\n",wka); |
|---|
| 1461 | recisis0(wka); |
|---|
| 1462 | continue; |
|---|
| 1463 | } |
|---|
| 1464 | |
|---|
| 1465 | if (strncmp(p,"tmpnam=",7) == 0) { |
|---|
| 1466 | if (sscanf(p+7,"%ld",&lv) != 1) continue; |
|---|
| 1467 | if (lv <= 0 || lv > (LONGX)USHRT_MAX) continue; |
|---|
| 1468 | q=gettmpnam(wka); |
|---|
| 1469 | sprintf(buffup,"D%ld H%ld %d %s",lv,lv,strlen(q),q); |
|---|
| 1470 | fldupdat(irec,buffup); |
|---|
| 1471 | continue; |
|---|
| 1472 | } |
|---|
| 1473 | |
|---|
| 1474 | if (strncmp(p,"cipar=",6) == 0) { |
|---|
| 1475 | q=p+6; if (!*q) continue; |
|---|
| 1476 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1477 | if (recfmt(irec,rec_maxmfrl,wka,buffup,rec_maxmfrl-1L) < 0) fatal(wka); |
|---|
| 1478 | dbxcdcip=loadfile(NULL,'\0',buffup,NULL,0L,'\n'); |
|---|
| 1479 | continue; |
|---|
| 1480 | } |
|---|
| 1481 | |
|---|
| 1482 | if (strncmp(p,"write=",6) == 0) { |
|---|
| 1483 | q=p+6; if (!*q) continue; |
|---|
| 1484 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1485 | if (recfmt(irec,rec_maxmfrl,wka,buffup,rec_maxmfrl-1L) < 0) fatal(wka); |
|---|
| 1486 | for (q=buffup; *q; q++) |
|---|
| 1487 | if (*q != '\r') |
|---|
| 1488 | fprintf(ofp,"%c",*q); |
|---|
| 1489 | continue; |
|---|
| 1490 | } |
|---|
| 1491 | |
|---|
| 1492 | if (strncmp(p,"echo=",5) == 0) { |
|---|
| 1493 | q=p+5; |
|---|
| 1494 | for (; *q; q++) fprintf(ofp,"%c",*q); fprintf(ofp,"\n"); |
|---|
| 1495 | continue; |
|---|
| 1496 | } |
|---|
| 1497 | |
|---|
| 1498 | if (strncmp(p,"fwrite/",7) == 0) { |
|---|
| 1499 | if (sscanf(p+7,"%ld",&lv) != 1) continue; |
|---|
| 1500 | if (lv <= 0 || lv > (LONGX)USHRT_MAX) continue; |
|---|
| 1501 | xtag=(UWORD)lv; |
|---|
| 1502 | q=recfield(wka,irec,xtag,1,""); |
|---|
| 1503 | if (!*q) continue; |
|---|
| 1504 | fp=fopen(wka,"w"); |
|---|
| 1505 | if (fp == (FILE *)NULL) continue; |
|---|
| 1506 | q=strchr(p+7+1,'='); if (!*q) continue; |
|---|
| 1507 | q++; if (!*q) continue; |
|---|
| 1508 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1509 | if (recfmt(irec,rec_maxmfrl,wka,buffup,rec_maxmfrl-1L) < 0) fatal(wka); |
|---|
| 1510 | for (q=buffup; *q; q++) if (*q != '\r') fprintf(fp,"%c",*q); |
|---|
| 1511 | fclose(fp); |
|---|
| 1512 | continue; |
|---|
| 1513 | } |
|---|
| 1514 | |
|---|
| 1515 | if (strncmp(p,"fldupdat=",9) == 0) { |
|---|
| 1516 | q=p+9; if (!*q) continue; |
|---|
| 1517 | loadfile(RDBname,'@',q,buffup,rec_maxmfrl,'\0'); |
|---|
| 1518 | if (fldupdat(irec,buffup)) fatal(buffup); |
|---|
| 1519 | continue; |
|---|
| 1520 | } |
|---|
| 1521 | if (strncmp(p,"proc=",5) == 0) { |
|---|
| 1522 | q=p+5; if (!*q) continue; |
|---|
| 1523 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1524 | if (recfmt(irec,rec_maxmfrl,wka,buffup,rec_maxmfrl-1L) < 0) fatal(wka); |
|---|
| 1525 | if (fldupdat(irec,buffup)) fatal(buffup); |
|---|
| 1526 | continue; |
|---|
| 1527 | } |
|---|
| 1528 | |
|---|
| 1529 | if (isdigit(*p)) { /* number= */ |
|---|
| 1530 | if (sscanf(p,"%ld%c",&xlv,&xchr) == 2) { |
|---|
| 1531 | for (q=p; isdigit(*q); ) q++; |
|---|
| 1532 | if (*q == '=' || (*q == '+' && *(q+1) == '=')) { |
|---|
| 1533 | if (*q == '+') q++; q++; |
|---|
| 1534 | *bufsizbuff='\0'; |
|---|
| 1535 | if (xchr == '=') sprintf(bufsizbuff,"D%ld",xlv); |
|---|
| 1536 | *wka='\0'; |
|---|
| 1537 | if (*q) { |
|---|
| 1538 | loadfile(RDBname,'@',q,wka,rec_maxmfrl,'\0'); |
|---|
| 1539 | if (recfmt(irec,rec_maxmfrl,wka,buffup,rec_maxmfrl-1L) < 0) { |
|---|
| 1540 | strcpy(buffup,wka+fmt_errof); |
|---|
| 1541 | } |
|---|
| 1542 | for (*(xwp=wka)='\0', xbp=buffup; *xbp; ) { |
|---|
| 1543 | for (xnby=0, q=xbp; *q; q++) |
|---|
| 1544 | if (*q == '\n' || *q == '\r') { |
|---|
| 1545 | *q++ = '\0'; |
|---|
| 1546 | while (*q == '\n' || *q == '\r') *q++ = '\0'; |
|---|
| 1547 | break; |
|---|
| 1548 | } else xnby++; |
|---|
| 1549 | if (xnby) { |
|---|
| 1550 | sprintf(xwp,"H%ld %ld ",xlv,xnby); xwp+=strlen(xwp); |
|---|
| 1551 | memcpy(xwp,xbp,(size_t)xnby); xwp+=xnby; *xwp='\0'; |
|---|
| 1552 | } |
|---|
| 1553 | xbp = q; |
|---|
| 1554 | } |
|---|
| 1555 | } |
|---|
| 1556 | if (*bufsizbuff) if (fldupdat(irec,bufsizbuff)) fatal(bufsizbuff); |
|---|
| 1557 | if (*wka) if (fldupdat(irec,wka)) fatal(wka); |
|---|
| 1558 | continue; |
|---|
| 1559 | } |
|---|
| 1560 | } |
|---|
| 1561 | } |
|---|
| 1562 | |
|---|
| 1563 | #if CICGXGIZ |
|---|
| 1564 | if (strncmp(p,"gizmo=",6) == 0 || strncmp(p,"gizmo/?=",8) == 0) { |
|---|
| 1565 | if (strncmp(p,"gizmo/?=",8) == 0) gizminfo=1; else gizminfo=0; |
|---|
| 1566 | gizmread(p+6,&gizmap,buffridx); |
|---|
| 1567 | recgizmo(irec,gizmap); |
|---|
| 1568 | ngizmos++; |
|---|
| 1569 | if (gizminfo) { |
|---|
| 1570 | q=buffup; lv=10000/*U*/+ngizmos*100; |
|---|
| 1571 | sprintf(q,"A%ld\n%s\n",lv,gizmap->gdbnp); q+=strlen(q); |
|---|
| 1572 | for (n=0; n <= 255; n++) { /* header list */ |
|---|
| 1573 | gizmp=gizmap->ghdrp[n]; |
|---|
| 1574 | if (!gizmp) continue; |
|---|
| 1575 | for (; gizmp; gizmp=gizmp->nextp) { /* list */ |
|---|
| 1576 | if (gizmp->nused == 0) continue; |
|---|
| 1577 | sprintf(q,"A%ld#%ld#",(lv+10),gizmp->nused); q+=strlen(q); |
|---|
| 1578 | sprintf(q,"H%ld %d ",(lv+1),gizmp->isize); q+=strlen(q); |
|---|
| 1579 | memcpy(q,gizmp->ipatt,n=gizmp->isize); q+=n; |
|---|
| 1580 | sprintf(q,"H%ld %d ",(lv+2),gizmp->osize); q+=strlen(q); |
|---|
| 1581 | memcpy(q,gizmp->opatt,n=gizmp->osize); q+=n; |
|---|
| 1582 | sprintf(q,"A%ld#%d#",(lv+31),gizmp->isize); q+=strlen(q); |
|---|
| 1583 | sprintf(q,"A%ld#%d#",(lv+32),gizmp->osize); |
|---|
| 1584 | fldupdat(irec,buffup); |
|---|
| 1585 | } /* end list */ |
|---|
| 1586 | } /* end header */ |
|---|
| 1587 | } |
|---|
| 1588 | gizflush(gizmap); |
|---|
| 1589 | continue; |
|---|
| 1590 | } |
|---|
| 1591 | #endif /* CICGXGIZ */ |
|---|
| 1592 | |
|---|
| 1593 | if (strncmp(p,"label=",6) == 0) continue; |
|---|
| 1594 | |
|---|
| 1595 | if (strcmp(p,"exit") == 0) break; |
|---|
| 1596 | |
|---|
| 1597 | fatal(p); |
|---|
| 1598 | |
|---|
| 1599 | } /* end for iocc */ |
|---|
| 1600 | |
|---|
| 1601 | |
|---|
| 1602 | |
|---|
| 1603 | /* |
|---|
| 1604 | Process format lines |
|---|
| 1605 | */ |
|---|
| 1606 | fmtp=recfield(buffup,irec,TAGMXPFT,1,""); |
|---|
| 1607 | if (*fmtp) { |
|---|
| 1608 | if (recfmt(irec,rec_maxmfrl,fmtp,wka,rec_maxmfrl-1L) < 0) fatal(fmtp); |
|---|
| 1609 | if (cgitrace) printf("recfmt:\n%s\n",wka); |
|---|
| 1610 | for (p=fmtp=wka; *fmtp; ) { |
|---|
| 1611 | if (*p != '\r') if (*p != '\n') if (*p) {p++; continue;} |
|---|
| 1612 | while (*p == '\r' || *p == '\n') *p++='\0'; |
|---|
| 1613 | if (*fmtp) { |
|---|
| 1614 | argv[*argc]=(char *) malloc(sizeof(char) * (strlen(fmtp) + 1)); |
|---|
| 1615 | strcpy(argv[*argc],fmtp); |
|---|
| 1616 | *argc= *argc+1; |
|---|
| 1617 | } |
|---|
| 1618 | fmtp=p; |
|---|
| 1619 | } /* end of for fmtp */ |
|---|
| 1620 | } |
|---|
| 1621 | if (cgitrace) if (*argc-1) { |
|---|
| 1622 | printf("Content-type: text/html%c%c",10,10); |
|---|
| 1623 | printf("CISIS/CGI %s produced the following %d parameters:<p>%c",cicgi_p,*argc-1,10); |
|---|
| 1624 | printf("<ul>%c",10); |
|---|
| 1625 | for(n=1; n < *argc; n++) printf("<li> <code>%s</code>%c",argv[n],10); |
|---|
| 1626 | printf("</ul>%c",10); |
|---|
| 1627 | } |
|---|
| 1628 | |
|---|
| 1629 | |
|---|
| 1630 | /* |
|---|
| 1631 | Release all CISIS runtime data |
|---|
| 1632 | */ |
|---|
| 1633 | for (lv=0; lv < maxnrec; lv++) |
|---|
| 1634 | if (vrecp[lv]) { |
|---|
| 1635 | FREE(vrecp[lv]); vrecp[lv]=(RECSTRU *)NULL; nrecs--; |
|---|
| 1636 | } |
|---|
| 1637 | for (lv=0; lv < maxntrm; lv++) |
|---|
| 1638 | if (vtrmp[lv]) { |
|---|
| 1639 | FREE(vtrmp[lv]); vtrmp[lv]=(TRMSTRU *)NULL; ntrms--; |
|---|
| 1640 | } |
|---|
| 1641 | for (lv=0; lv < maxndbx; lv++) |
|---|
| 1642 | if (vdbxp[lv]) |
|---|
| 1643 | dbxflush(VDBXname(lv)); |
|---|
| 1644 | |
|---|
| 1645 | if (cicgi_dbnp) FREE(cicgi_dbnp); |
|---|
| 1646 | |
|---|
| 1647 | strcpy(fatal_iomsg,""); /* notrap fatal() */ |
|---|
| 1648 | |
|---|
| 1649 | return(retc); |
|---|
| 1650 | } |
|---|
| 1651 | |
|---|
| 1652 | #endif /* CICG1 */ |
|---|
| 1653 | |
|---|
| 1654 | |
|---|
| 1655 | #if CICPP |
|---|
| 1656 | int CGIClass :: cigt_function(char *varp, |
|---|
| 1657 | char *action) |
|---|
| 1658 | #else /* CICPP */ |
|---|
| 1659 | #if ANSI |
|---|
| 1660 | int cigt_function(char *varp, char *action); |
|---|
| 1661 | #else |
|---|
| 1662 | int cigt_function(); |
|---|
| 1663 | #endif |
|---|
| 1664 | |
|---|
| 1665 | int cigt_function(varp, action) |
|---|
| 1666 | char *varp; |
|---|
| 1667 | char *action; |
|---|
| 1668 | #endif /* CICPP */ |
|---|
| 1669 | { |
|---|
| 1670 | char *def_pfxtmp="tmp"; |
|---|
| 1671 | int def_tmps=1; |
|---|
| 1672 | |
|---|
| 1673 | char *pip,*p,*op,*cp; |
|---|
| 1674 | char area[200]; |
|---|
| 1675 | int loop; |
|---|
| 1676 | |
|---|
| 1677 | pip=getenv(varp); |
|---|
| 1678 | if (!pip) return(0); |
|---|
| 1679 | pip=strdup(pip); |
|---|
| 1680 | |
|---|
| 1681 | for (p=pip; *p; p=cp+1) { |
|---|
| 1682 | op=strchr(p,'['); |
|---|
| 1683 | if (!op) break; |
|---|
| 1684 | op++; |
|---|
| 1685 | cp=strchr(op,']'); |
|---|
| 1686 | if (!cp) break; |
|---|
| 1687 | *cp='\0'; |
|---|
| 1688 | if (strncmp(op,"pfxtmp=",7) == 0 || strncmp(op,"pfxtmp~",7) == 0) { |
|---|
| 1689 | def_pfxtmp=op+7; |
|---|
| 1690 | continue; |
|---|
| 1691 | } |
|---|
| 1692 | if (strncmp(op,"tmps=",5) == 0 || strncmp(op,"tmps~",5) == 0) { |
|---|
| 1693 | def_tmps=atoi(op+5); |
|---|
| 1694 | continue; |
|---|
| 1695 | } |
|---|
| 1696 | } |
|---|
| 1697 | |
|---|
| 1698 | if (strcmp(action,"del") == 0) |
|---|
| 1699 | for (loop=1; loop <= def_tmps; loop++) { |
|---|
| 1700 | sprintf(area,"%s%d",def_pfxtmp,loop); |
|---|
| 1701 | p=getenv(area); |
|---|
| 1702 | if (p) { |
|---|
| 1703 | /* unset */ |
|---|
| 1704 | strcat(area,"="); |
|---|
| 1705 | putenv(area); |
|---|
| 1706 | /* delete */ |
|---|
| 1707 | #if PC |
|---|
| 1708 | sprintf(area,"del %s.$$$",p); |
|---|
| 1709 | #else |
|---|
| 1710 | sprintf(area,"rm %s",p); |
|---|
| 1711 | #endif |
|---|
| 1712 | system(area); |
|---|
| 1713 | } |
|---|
| 1714 | } |
|---|
| 1715 | |
|---|
| 1716 | if (strcmp(action,"set") == 0) |
|---|
| 1717 | for (loop=1; loop <= def_tmps; loop++) { |
|---|
| 1718 | p=gettmpnam(NULL); |
|---|
| 1719 | sprintf(area,"%s%d=%s",def_pfxtmp,loop,p); |
|---|
| 1720 | putenv(strdup(area)); |
|---|
| 1721 | } |
|---|
| 1722 | |
|---|
| 1723 | free(pip); |
|---|
| 1724 | |
|---|
| 1725 | return(def_tmps); |
|---|
| 1726 | } |
|---|
| 1727 | |
|---|
| 1728 | #endif /* CICGI */ |
|---|