| 1 | |
|---|
| 2 | |
|---|
| 3 | /* Begin PROCXDUMPREC |
|---|
| 4 | */ |
|---|
| 5 | #if PROCXDUMPREC |
|---|
| 6 | if (strncmp(batchp2,"dump=",5) == 0 || /* mx null "proc='Gdump/1=dor1.txt'" */ |
|---|
| 7 | strncmp(batchp2,"dump/",5) == 0 || |
|---|
| 8 | strcmp( batchp2,"dump" ) == 0) { |
|---|
| 9 | |
|---|
| 10 | LONGX xtag=1; //default tag |
|---|
| 11 | int parmsocket=0; |
|---|
| 12 | int parmcmd=0; |
|---|
| 13 | int rc; |
|---|
| 14 | char *filnamp=NULL; |
|---|
| 15 | |
|---|
| 16 | int parm1=0; |
|---|
| 17 | |
|---|
| 18 | char *p,*localbatchp=NULL; |
|---|
| 19 | |
|---|
| 20 | char *xarea=NULL; |
|---|
| 21 | LONGX nbytes,nbytes2; |
|---|
| 22 | |
|---|
| 23 | int fd=0; |
|---|
| 24 | |
|---|
| 25 | char *fldp=NULL; |
|---|
| 26 | FFI len=0; /* output zero chars */ |
|---|
| 27 | |
|---|
| 28 | /* alloc working area |
|---|
| 29 | */ |
|---|
| 30 | nbytes=MFRmfrl+BUFSIZ; /* working */ |
|---|
| 31 | nbytes2=(strlen(batchp2)+1); /* batchp2 */ |
|---|
| 32 | #if CICPP |
|---|
| 33 | try { xarea = (char *) new char [nbytes]; } |
|---|
| 34 | catch (BAD_ALLOC) { xarea = (char *)ALLONULL; } |
|---|
| 35 | try { localbatchp = (char *) new char [nbytes2]; } |
|---|
| 36 | catch (BAD_ALLOC) { localbatchp = (char *)ALLONULL; } |
|---|
| 37 | #else /* CICPP */ |
|---|
| 38 | xarea=(char *)ALLOC((ALLOPARM)nbytes); |
|---|
| 39 | localbatchp=(char *)ALLOC((ALLOPARM)nbytes2); |
|---|
| 40 | #endif /* CICPP */ |
|---|
| 41 | if (xarea == (char *)ALLONULL) fatal("fldupdat/procx/Gdump/ALLOC"); |
|---|
| 42 | *xarea='\0'; /* output */ |
|---|
| 43 | |
|---|
| 44 | strcpy(p=localbatchp,batchp2); /* duplicate batchp2 */ |
|---|
| 45 | |
|---|
| 46 | /* scan parms |
|---|
| 47 | */ |
|---|
| 48 | p+=4; /* skip dump */ |
|---|
| 49 | |
|---|
| 50 | if (*p) { |
|---|
| 51 | while (isspace(*p)) p++; |
|---|
| 52 | while (*p == '/') { /* /<tag>/socket */ |
|---|
| 53 | p++; |
|---|
| 54 | if (isdigit(*p)) { /* /<tag> */ |
|---|
| 55 | //if (*p=='0') xtagzero=1; // allow tag /0n |
|---|
| 56 | for (xtag=0; isdigit(*p); p++ ) xtag=xtag*10+((int)(*p)-(int)'0'); |
|---|
| 57 | if (xtag < 1) fatal("fldupdat/procx/Gload/tag"); |
|---|
| 58 | if (*p=='/' || *p=='='); else fatal("fldupdat/procx/Gload/tag dlm"); |
|---|
| 59 | } else |
|---|
| 60 | if (strncmp(p,"line=",5) == 0 || strncmp(p,"line/",5) == 0) { /* /line */ |
|---|
| 61 | p+=4; |
|---|
| 62 | parm1=1; |
|---|
| 63 | } else |
|---|
| 64 | #if PROCXSERVREC |
|---|
| 65 | if (strncmp(p,"socket=",7) == 0 || strncmp(p,"socket/",7) == 0) { /* /socket */ |
|---|
| 66 | p+=6; |
|---|
| 67 | parmsocket=1; |
|---|
| 68 | } else |
|---|
| 69 | if (strncmp(p,"xml=",4) == 0 || strncmp(p,"xml/",4) == 0) { /* /xml */ |
|---|
| 70 | p+=3; |
|---|
| 71 | parmcmd=1; |
|---|
| 72 | } else |
|---|
| 73 | if (strncmp(p,"tell=",5) == 0 || strncmp(p,"tell/",5) == 0) { /* /tell */ |
|---|
| 74 | p+=4; |
|---|
| 75 | parmcmd=2; |
|---|
| 76 | } else |
|---|
| 77 | if (strncmp(p,"trace=",6) == 0 || strncmp(p,"trace/",6) == 0) { /* /trace */ |
|---|
| 78 | p+=5; |
|---|
| 79 | parmcmd=3; |
|---|
| 80 | } else |
|---|
| 81 | #endif /* PROCXSERVREC */ |
|---|
| 82 | fatal("fldupdat/procx/Gdump/option"); |
|---|
| 83 | } /* while /x */ |
|---|
| 84 | if (*p == '=') { p++; filnamp=p; p+=strlen(p); } /* <file> | <url> */ |
|---|
| 85 | } |
|---|
| 86 | else { // proc='Gdump' |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | if (parmsocket) { /* ./mx null "proc='Gdump/socket/:1417'" */ |
|---|
| 91 | #if PROCXSERVREC_spawn |
|---|
| 92 | uint16_t port=1417; |
|---|
| 93 | int maxconnqueued=1; |
|---|
| 94 | rc = mainserver( parmcmd, port, xarea , nbytes, maxconnqueued); |
|---|
| 95 | #endif /* PROCXSERVREC */ |
|---|
| 96 | } |
|---|
| 97 | else { /* else parmsocket: <file> */ |
|---|
| 98 | |
|---|
| 99 | /* get contents */ |
|---|
| 100 | xdir=fieldx(irec,(UWORD)xtag,1); |
|---|
| 101 | if (xdir >= 0) { /* data */ |
|---|
| 102 | fldp=FIELDP(xdir); |
|---|
| 103 | len=DIRlen(xdir); |
|---|
| 104 | |
|---|
| 105 | if (len) { |
|---|
| 106 | if (parm1) { |
|---|
| 107 | LONGX left=len; |
|---|
| 108 | char *x=fldp; |
|---|
| 109 | char *y=xarea; |
|---|
| 110 | for (; left; left--, x++) |
|---|
| 111 | if (*x=='\r' || *x=='\n') len--; |
|---|
| 112 | else *y++= *x; |
|---|
| 113 | } |
|---|
| 114 | else memcpy(xarea,fldp,len); |
|---|
| 115 | } |
|---|
| 116 | xarea[len]='\0'; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | /* rc = maindump ( parmcmd, filnamp, parm1, buffer, buffersize ); */ |
|---|
| 120 | if (filnamp) { |
|---|
| 121 | dbxopenc(NULL,filnamp,&fd,NULL,"fldupdat/procx/Gdump/create",1,0); /* create=1, append=0 */ |
|---|
| 122 | if (fd >= 0) { |
|---|
| 123 | if ((FFI)CIWRITE(fd,xarea,len) != len) fatal("fldupdat/procx/Gdump/write"); |
|---|
| 124 | CLOSE(fd); |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | else { |
|---|
| 128 | #if USEFPUTS /* fputs */ |
|---|
| 129 | if (fputs(xarea,stdout) == EOF) fatal("fldupdat/procx/Gdump/write"); |
|---|
| 130 | #else /* putchar */ |
|---|
| 131 | char *y; |
|---|
| 132 | for (y=xarea; *y; y++) if (*y != '\r') putchar((int)*y); |
|---|
| 133 | #endif |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | } /* end parmsocket */ |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | #if CICPP |
|---|
| 140 | delete xarea; |
|---|
| 141 | delete localbatchp; |
|---|
| 142 | #else /* CICPP */ |
|---|
| 143 | if (xarea) FREE(xarea); |
|---|
| 144 | if (localbatchp) FREE(localbatchp); |
|---|
| 145 | #endif /* CICPP */ |
|---|
| 146 | |
|---|
| 147 | return NULL; //isgdump=1; |
|---|
| 148 | |
|---|
| 149 | } /* end Gdump */ |
|---|
| 150 | else |
|---|
| 151 | |
|---|
| 152 | #endif /* PROCXDUMPREC */ |
|---|
| 153 | /* End PROCXDUMPREC |
|---|
| 154 | */ |
|---|
| 155 | |
|---|