| 1 | |
|---|
| 2 | |
|---|
| 3 | /* Begin PROCXLOADREC |
|---|
| 4 | */ |
|---|
| 5 | #if PROCXLOADREC |
|---|
| 6 | |
|---|
| 7 | if (strncmp(p,"load=",5) == 0 || /* mx null "proc='Gload=dor1.txt=1'" */ |
|---|
| 8 | strncmp(p,"load/",5) == 0) { |
|---|
| 9 | |
|---|
| 10 | int parm0=1; |
|---|
| 11 | int parm1=0; |
|---|
| 12 | int parmprint=0; |
|---|
| 13 | FILE *parmfp=stdout; |
|---|
| 14 | |
|---|
| 15 | char *xarea=NULL; |
|---|
| 16 | LONGX nbytes,nbytes0,nread; |
|---|
| 17 | char *filnamp; |
|---|
| 18 | int fd=0; |
|---|
| 19 | |
|---|
| 20 | char *q; |
|---|
| 21 | LONGX xtag=1; |
|---|
| 22 | |
|---|
| 23 | char *haddp=NULL; |
|---|
| 24 | char *hlenp=NULL; |
|---|
| 25 | char *hdatap=NULL; |
|---|
| 26 | LONGX hlen=0; |
|---|
| 27 | |
|---|
| 28 | /* scan parms |
|---|
| 29 | */ |
|---|
| 30 | if (strncmp(p,"load/",5) == 0) { |
|---|
| 31 | p+=4; /* load/ */ |
|---|
| 32 | while (*p == '/') { |
|---|
| 33 | |
|---|
| 34 | p++; |
|---|
| 35 | if (isdigit(*p)) { |
|---|
| 36 | for (xtag=0; isdigit(*p); p++ ) xtag=xtag*10+((int)(*p)-(int)'0'); |
|---|
| 37 | if (xtag < 0) fatal("fldupdat/procx/Gload/tag"); // allow tag /0 |
|---|
| 38 | if (*p=='/' || *p=='='); else fatal("fldupdat/procx/Gload/tag dlm"); |
|---|
| 39 | } |
|---|
| 40 | if (strncmp(p,"nonl/",5) == 0 || strncmp(p,"nonl=",5) == 0) { |
|---|
| 41 | p+=4; |
|---|
| 42 | parm1=1; |
|---|
| 43 | } |
|---|
| 44 | if (*p=='=') { p++; break; } |
|---|
| 45 | if (*p=='/') ; else fatal("fldupdat/procx/Gload[/tag][/<option>][=<file>]"); // Gload[/<tag>][/nolf][/xml][/socket][/head][={<url>|<file>}] + Gmark[/<tag>] |
|---|
| 46 | //fatal("fldupdat/procx/Gload/option"); |
|---|
| 47 | |
|---|
| 48 | } /* while /x */ |
|---|
| 49 | } |
|---|
| 50 | else p+=5; /* load= */ |
|---|
| 51 | |
|---|
| 52 | filnamp=p; |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | /* alloc working area |
|---|
| 56 | */ |
|---|
| 57 | nbytes=(rec_maxmfrl>MAXMFRL)?rec_maxmfrl:MAXMFRL; |
|---|
| 58 | if (nbytes < MFRmfrl) nbytes=MFRmfrl; |
|---|
| 59 | nbytes=(nbytes0=nbytes)+BUFSIZ; /* buffup */ /* nbytes=MFRmfrl+MFRmfrl+BUFSIZ; */ |
|---|
| 60 | #if CICPP |
|---|
| 61 | try { xarea = (char *) new char [nbytes]; } |
|---|
| 62 | catch (BAD_ALLOC) { xarea = (char *)ALLONULL; } |
|---|
| 63 | #else /* CICPP */ |
|---|
| 64 | xarea=(char *)ALLOC((ALLOPARM)nbytes); |
|---|
| 65 | #endif /* CICPP */ |
|---|
| 66 | if (xarea == (char *)ALLONULL) fatal("fldupdat/procx/Gload/ALLOC"); |
|---|
| 67 | *xarea='\0'; |
|---|
| 68 | |
|---|
| 69 | q=xarea; /* batchp */ |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | /* del/add command |
|---|
| 73 | */ |
|---|
| 74 | if (xtag) sprintf(q,"D%ld",xtag); |
|---|
| 75 | else sprintf(q,"D*"); q+=strlen(q); |
|---|
| 76 | |
|---|
| 77 | sprintf(haddp=q,"H%09ld ",(xtag)?(LONGX)xtag:1L); q+=strlen(q); |
|---|
| 78 | sprintf(hlenp=q,"123456789 "); q+=strlen(q); |
|---|
| 79 | |
|---|
| 80 | hdatap=q; |
|---|
| 81 | |
|---|
| 82 | if (*filnamp) { |
|---|
| 83 | fd=dbxopen(NULL/*gidbnp*/,filnamp,""); |
|---|
| 84 | if (fd <= 0) fatal("fldupdat/procx/Gload/open"); |
|---|
| 85 | else { |
|---|
| 86 | nread=CIREAD(fd,hdatap,nbytes0); |
|---|
| 87 | CLOSE(fd); |
|---|
| 88 | if (nread > 0L) { |
|---|
| 89 | q+=nread; hlen+=nread; |
|---|
| 90 | } |
|---|
| 91 | if (parm0) if (nread > 0L) { |
|---|
| 92 | LONGX left=nread; |
|---|
| 93 | int found=0; |
|---|
| 94 | char *x,*y; |
|---|
| 95 | for (x=y=hdatap; left; left--, x++) |
|---|
| 96 | if (*x=='\r') { found=1; hlen--; q--; } |
|---|
| 97 | else { if (found) *y= *x; y++; } |
|---|
| 98 | } |
|---|
| 99 | if (parm1) if (nread > 0L) { |
|---|
| 100 | LONGX left=nread; |
|---|
| 101 | int found=0; |
|---|
| 102 | char *x,*y; |
|---|
| 103 | for (x=y=hdatap; left; left--, x++) |
|---|
| 104 | if (*x=='\n') { found=1; hlen--; q--; } |
|---|
| 105 | else { if (found) *y= *x; y++; } |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | else { |
|---|
| 110 | LONGX left=nbytes0; |
|---|
| 111 | #if USEFGETS /* fgets looses last char if LF is missing in last line */ |
|---|
| 112 | int nread=(left>INT_MAX)?INT_MAX:left; |
|---|
| 113 | char *linep; |
|---|
| 114 | while ((linep=fgets(q,nread,stdin)) != NULL) { |
|---|
| 115 | int nread=strlen(linep); |
|---|
| 116 | if (parm1) if (nread) if (linep[nread-1]=='\n') nread--; |
|---|
| 117 | q+=nread; hlen+=nread; left-=nread; |
|---|
| 118 | } |
|---|
| 119 | #else /* getchar() */ |
|---|
| 120 | int c; |
|---|
| 121 | int nread; |
|---|
| 122 | while (left && (c=getchar()) != EOF) { |
|---|
| 123 | nread=1; |
|---|
| 124 | if (parm1) if ((char)c=='\n') nread=0; |
|---|
| 125 | if (nread) { *q++=(unsigned char)c; hlen++; left--; } |
|---|
| 126 | } |
|---|
| 127 | #endif |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | *q='\0'; |
|---|
| 131 | if (hlen) { |
|---|
| 132 | /* actual add lenght */ |
|---|
| 133 | sprintf(hlenp,"%9ld",(LONGX)hlen); hlenp[9]=' '; |
|---|
| 134 | /* print */ |
|---|
| 135 | if (parmprint) fprintf(parmfp,"%s",hdatap); |
|---|
| 136 | } |
|---|
| 137 | else if (haddp) *haddp='\0'; |
|---|
| 138 | |
|---|
| 139 | #if CICPP |
|---|
| 140 | if (recp->xfldupdat(xarea)) fatal(errp); |
|---|
| 141 | delete xarea; |
|---|
| 142 | #else /* CICPP */ |
|---|
| 143 | if (fldupdat(irec,xarea)) fatal(errp); |
|---|
| 144 | if (xarea) FREE(xarea); |
|---|
| 145 | #endif /* CICPP */ |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | return NULL; //isgdump=1; |
|---|
| 149 | |
|---|
| 150 | } /* end Gload */ |
|---|
| 151 | else |
|---|
| 152 | |
|---|
| 153 | #endif /* PROCXLOADREC */ |
|---|
| 154 | /* End PROCXLOADREC |
|---|
| 155 | */ |
|---|