root/tags/5.52/ciupdmarx.c

Revision 4, 56.7 kB (checked in by heitor.barbieri, 2 years ago)

Versão 5.52 do cisis (28/04/2010)

Line 
1
2
3/* Begin PROCXSOCKREC
4
5         Gload[/<tag>][/nolf][/xml][/socket][/head][={<url>|<file>}]
6         Gload[/<tag>][/nolf][/xml][/socket][/head][={<url>|dir=<file>}]
7
8         Gmarx [/<tag>] [/<elem>[,<elem>..]] [=<tag>[,<tag>..]]
9
10Gmarx/1       /documents               =2      |  1.1 2.1
11Gmarx/2       /fulltext                =21     |  1.1 2.1 21.1
12Gmarx/2       /receipt                 =22     |  1.1 2.1 22.1
13
14*/
15#if PROCXSOCKREC
16
17#define MAXXPATH 99
18
19#define bpmovemax(bp,max,len,xleft)   {                                   \
20                                    if (max >= 20 && len > max) {         \
21                                        int m2=max/3*2,m3=max-m2-3;         \
22                                        char *q=bp+m2,*p=bp+len-m3;       \
23                                        char *z=bp+max-1;                 \
24                                        int left=max;                     \
25                                        int lmin=(xleft)?m2:0;            \
26                                        while (left-- > lmin)             \
27                                          if (*z--==' ')                  \
28                                            if (*z=='.' || *z==';')       \
29                                              break;                      \
30                                        if (left >= lmin) {               \
31                                          len=left+3;                     \
32                                          memcpy(bp+left," ..",3);        \
33                                        } else {                          \
34                                          len=m2+3+m3;                    \
35                                          memcpy(q,"...",3); q+=3;        \
36                                          while (m3--) *q++= *p++;        \
37                                        }                                 \
38                                    }                                     \
39                                  }
40//end bpmovemax(bp,max,len,xleft)
41
42#define hpmovemax(hp,max,a,len)   {                                       \
43                                    if (max >= 20 && len > max) {         \
44                                        int m2=max/3*2,m3=max-m2-3;       \
45                                        memcpy(hp,a,m2);        hp+=m2;   \
46                                        memcpy(hp,"+++",3);     hp+=3;    \
47                                        memcpy(hp,a+len-m3,m3); hp+=m3;   \
48                                    }                                     \
49                                    else {                                \
50                                        memcpy(hp,a,len); hp+=len;        \
51                                    }                                     \
52                                  }
53//end hpmovemax(hp,max,a,len)
54
55
56             if (  strncmp(p,"load=",5) == 0 || strncmp(p,"load/",5) == 0 || strcmp(p,"load") == 0 ||
57
58                   strncmp(p,"marx=",5) == 0 || strncmp(p,"marx/",5) == 0 || strncmp(p,"marx ",5) == 0
59
60                                         /* &&  (strstr(p,"/socket=") || strstr(p,"/socket/")  */      ) {
61
62
63                int isload = ( strncmp(p,"load=",5) == 0 || strncmp(p,"load/",5) == 0 || strcmp(p,"load") == 0 ) ? 1 : 0;
64                int ismarx = ( strncmp(p,"marx=",5) == 0 || strncmp(p,"marx/",5) == 0 || strncmp(p,"marx ",5) == 0 ) ? 1 : 0;
65
66            LONGX xtag=1;
67            int xtagzero=0;
68            int parmsocket=0;
69            int parmcmd=0;
70            int parmhead=0;
71            char *filnamp=NULL;
72
73            int parm0=0; //1; // strip 0D
74            int parm1=0;      // strip 0A
75            //int parmprint=0;
76            //FILE *parmfp=stdout;
77
78            int parmparse=0;
79            char *vxpath[MAXXPATH+1];
80            int vxtag[MAXXPATH+1];
81            int xmlspec=1;
82            int colonspec=0;
83            char *colonspecp="";
84            char *colonspecq;
85            int parmxml=0;
86            int xmlopened=0;
87
88            int  parmfile=0;
89            char *filepath="";
90            char *filechar="";
91            char *filename="";
92            char *filedot="";
93            char *fileext="";
94
95            int parmindex=0;
96            char *iphbuff=NULL;
97            char *ihtbuff=NULL;
98            char *ihtptr[21];
99            int   ihtlen[21];
100            int   ihtocc[21];
101            char *ihtpta[21];
102            int   ihtpla[21];
103            char *ihtptc[21];
104            char *ihtptd[21];
105
106            char *xbuffer=NULL;
107
108            int parmtag=0; //allow 0
109            int parmmin=0;
110            int parmmax=0;
111            int parm1cc=0;
112            int parm1c2=0;
113            int parmocc=0;
114            int parmoc2=0;
115            int clean=0;
116            int parmxlen=0;
117            int parmx=0;
118            int chunch1=0;
119            int chunch2=0;
120            int chunch3=0;
121            int parmvin=0;
122
123            char selattr[BUFSIZ+BUFSIZ];
124            int selsize;
125            int selparm;
126            char selcode[BUFSIZ];
127            char selcodearea[BUFSIZ];
128
129
130            char *xarea=NULL;
131            LONGX nbytes;
132            char *urlp=NULL;
133            char *q;
134
135            char *haddp=NULL;
136            char *hlenp=NULL;
137            char *hdatap=NULL;
138            LONGX hlen=0;
139
140            char *protocol;
141            char *serverhost;
142            uint16_t port;
143            char *pathp;
144
145            int maxrds=INT_MAX;
146            int xport=0;
147
148            char *msgp;
149            int rc;
150
151            //char *dbname;
152            //LONGX mfn;
153            //char *key;
154
155#if VDBBNAM_SERVER_PORT
156            //int dbx;
157            //int ndbx=3;
158            char *vdbname[] = {
159                "lilacs",
160                "artigo",
161                "citacoes",
162            };
163            char *vdbserver[] = {
164                "bases.bireme.br",
165                "www.scielo.br",
166                "serverofi.bireme.br",
167            };
168            int vdbport[] = {
169                1417,
170                1417,
171                1417
172            };
173#endif
174            vxpath[0]=NULL; vxtag[0]=0; //eol
175
176            /* scan parms
177            */
178            if (ismarx) {  // Gmarx
179              char *q;
180              int ipath=0;
181              p+=4;  /* skip marx */
182              while (isspace(*p)) p++;
183              if (*p != '/') fatal("fldupdat/procx/Gmarx [/<tag>] /<elem> =<tag>");
184              p++;
185              while (isspace(*p)) p++;
186              parmtag=1; //default
187              if (isdigit(*p)) for (parmtag=0; isdigit(*p); p++ ) parmtag=parmtag*10+((int)(*p)-(int)'0');
188              if (parmtag < 1) fatal("fldupdat/procx/Gmarx/tag");
189              while (isspace(*p)) p++;
190              if (*p=='/') p++; else fatal("fldupdat/procx/Gmarx/elem dlm");
191              vxpath[ipath]=p; // /element
192              selattr[0]='\0'; selsize=0; selparm=0; selcode[0]='\0';
193              q=strstr(p,"@@");
194              if (q) {
195                  int n=0; *q='\0'; p=q+2; while (isdigit(*p) || *p=='.') { n++; p++; }
196                  if (n>sizeof(selcode)-1) n=sizeof(selcode)-1; memcpy(selcode,q+2,n); selcode[n]='\0'; selparm=n;
197              }
198              else {
199                q=strchr(p,'@');
200                if (q) {
201                  q=strstr(q+1,"=\""); if (q) q=strchr(q+2,'"');
202                  if (q) {
203                    char *qb;
204                    int n;
205                    p=strchr(p,'@'); *p++='\0'; q=p; for (; *p; p++) if (*p==' ') if (*(p+1)=='=') { qb=p-1; *p='\0'; p++; break; }
206                    n=strlen(q); for (; *qb != '"'; qb--) n--;
207                    if (n>sizeof(selattr)-1) n=sizeof(selattr)-1; memcpy(selattr,q,n); selattr[n]='\0'; selsize=n;
208                  }
209                }
210              }//end selection
211              if (!q) for (; *p; p++) if (*p==' ' || *p=='=') { *p='\0'; p++; break; } //no selattr selparm
212              while (isspace(*p) || *p=='=') p++;
213              if (!isdigit(*p)) fatal("fldupdat/procx/Gmarx/=tag non numeric");
214              for (xtag=0; isdigit(*p); p++ ) xtag=xtag*10+((int)(*p)-(int)'0');
215              if (xtag < 1) fatal("fldupdat/procx/Gmarx/=tag lt 1");
216              vxtag[ipath]=xtag; ipath++;
217              while (isspace(*p)) p++;
218              while (*p=='/') {
219                  if (*(p+1)=='/') { *p='\0'; break; }  //comment
220                  if (strncmp(p,"/file="  ,6)==0)                               { p+=6; filepath=p; while (*p) if (isspace(*p)) break; else p++; if (*p) *p++='\0';
221                                                                                  for (q=p-2; q!=filepath; q--) { if (*q=='/' || *q=='\\') break;
222                                                                                                                  if (*q=='.') { *q++='\0'; fileext=q; filedot="."; break; }
223                                                                                                                }
224                                                                                  filename=filepath;
225                                                                                  if (strchr(filename,'\\')) while ((q=strchr(filename,'\\')) != NULL) filename=q+1;
226                                                                                  if (strchr(filename,'/' )) while ((q=strchr(filename,'/' )) != NULL) filename=q+1;
227                                                                                  if (filename==filepath) filepath="";
228                                                                                  else { q=filename-1; filechar=(*q=='/')?"/":"\\"; *q='\0'; }
229                                                                                  parmfile=1;
230                                                                                }
231                  if (strncmp(p,"/1cc="   ,5)==0)                               { p+=5; for (n=0; isdigit(*p); p++ ) n=n*10+((int)(*p)-(int)'0'); parm1cc=n; }
232                  if (strncmp(p,"/1c2="   ,5)==0)                               { p+=5; for (n=0; isdigit(*p); p++ ) n=n*10+((int)(*p)-(int)'0'); parm1c2=n; }
233                  if (strncmp(p,"/occ="   ,5)==0)                               { p+=5; for (n=0; isdigit(*p); p++ ) n=n*10+((int)(*p)-(int)'0'); parmocc=n; }
234                  if (strncmp(p,"/oc2="   ,5)==0)                               { p+=5; for (n=0; isdigit(*p); p++ ) n=n*10+((int)(*p)-(int)'0'); parmoc2=n; }
235                  if (strncmp(p,"/tag="   ,5)==0)                               { p+=5; for (n=0; isdigit(*p); p++ ) n=n*10+((int)(*p)-(int)'0'); parmvin=n; }
236                  if (strncmp(p,"/clean " ,7)==0 || strncmp(p,"/clean/" ,7)==0) { p+=7; clean=1; }
237                  if (strcmp (p,"/clean"    )==0)                               { p+=6; clean=1; }
238                  if (strncmp(p,"/index " ,7)==0 || strncmp(p,"/index/" ,7)==0) { p+=7; parmindex=1; xmlspec=0; colonspec=1; }  // /.@level:header,text
239                  if (strcmp (p,"/index"    )==0)                               { p+=6; parmindex=1; xmlspec=0; colonspec=1; }
240                  if (strncmp(p,"/i "     ,3)==0 || strncmp(p,"/i/"     ,3)==0) { p+=3; parmindex=1; xmlspec=0; colonspec=1; }  // /.@level:header,text
241                  if (strcmp (p,"/i"        )==0)                               { p+=2; parmindex=1; xmlspec=0; colonspec=1; }
242                  if (strncmp(p,"/len "   ,5)==0 || strncmp(p,"/len/"   ,5)==0) { p+=5; parmxlen=1; }
243                  if (strcmp (p,"/len"      )==0)                               { p+=4; parmxlen=1; }
244                  if (strncmp(p,"/xml "   ,5)==0 || strncmp(p,"/xml/"   ,5)==0) { p+=5; parmxml=1; }
245                  if (strcmp (p,"/xml"      )==0)                               { p+=4; parmxml=1; }
246                  if (strncmp(p,"/chunch ",8)==0 || strncmp(p,"/chunch/",8)==0) { p+=8; parmx=1; chunch1=224; }
247                  if (strcmp (p,"/chunch"   )==0)                               { p+=7; parmx=1; chunch1=224; }
248                  if (strncmp(p,"/c "     ,3)==0 || strncmp(p,"/c/"     ,3)==0) { p+=3; parmx=1; chunch1=224; }
249                  if (strcmp (p,"/c"        )==0)                               { p+=2; parmx=1; chunch1=224; }
250                  if (strncmp(p,"/chunch=",8)==0 ||
251                      strncmp(p,"/c="     ,3)==0)                               { if (strncmp(p,"/c="     ,3)==0) p+=3; else p+=8;
252                                                                                  for (n=0; isdigit(*p); p++ ) n=n*10+((int)(*p)-(int)'0'); chunch1=n;
253                                                                                  if (chunch1 < 20) chunch1=20;
254                                                                                  chunch2=chunch3=0;
255                                                                                  while (isspace(*p)) p++;
256                                                                                  if (*p==',') {
257                                                                                    int n;
258                                                                                    p++; for (n=0; isdigit(*p); p++ ) n=n*10+((int)(*p)-(int)'0'); chunch2=n;
259                                                                                  }
260                                                                                  while (isspace(*p)) p++;
261                                                                                  if (*p==',') {
262                                                                                    int n;
263                                                                                    p++; for (n=0; isdigit(*p); p++ ) n=n*10+((int)(*p)-(int)'0'); chunch3=n;
264                                                                                  }
265                                                                                }
266                  while (isspace(*p)) p++;
267              }
268              if (*p==':') {
269                p++; while (isspace(*p)) p++;
270                if (*p=='/') if (*(p+1)=='/') *p='\0';   //comment
271                colonspecp=p;
272                colonspecq=p;
273                if (strlen(p)) {
274                  p=p+strlen(p)-1; while (isspace(*p)) p--; colonspecq=p;
275                }
276                xmlspec=0; colonspec=1;
277              }
278              vxpath[ipath]=NULL; vxtag[ipath]=0; //eol
279              parmparse=1; // !load
280            }
281
282            /* scan parms
283            */
284            if (isload) {  // Gload
285              p+=4;  /* skip load or marx */
286              if (*p) { /* proc='Gload' */
287               while (*p == '/') {      /* /<tag>/socket */
288                p++;
289                if (isdigit(*p)) {                                                   /* /<tag> */
290                  if (*p=='0') xtagzero=1;  // allow tag /0n
291                  for (xtag=0; isdigit(*p); p++ ) xtag=xtag*10+((int)(*p)-(int)'0');
292                  if (xtag < 1) fatal("fldupdat/procx/Gload/tag");
293                  if (*p=='/' || *p=='='); else fatal("fldupdat/procx/Gload/tag dlm");
294                } else
295                if (strncmp(p,"no0D=",5) == 0 || strncmp(p,"no0D/",5) == 0 ||        /* /no0D */
296                    strncmp(p,"noCR=",5) == 0 || strncmp(p,"noCR/",5) == 0) {        /* /noCR */
297                  p+=4;
298                  parm0=1;
299                } else
300                if (strncmp(p,"no0A=",5) == 0 || strncmp(p,"no0A/",5) == 0 ||        /* /no0A */
301                    strncmp(p,"noLF=",5) == 0 || strncmp(p,"noLF/",5) == 0) {        /* /noLF */
302                  p+=4;
303                  parm1=1;
304                } else
305                if (strncmp(p,"line=",5) == 0 || strncmp(p,"line/",5) == 0 ||        /* /line */
306                    strncmp(p,"nonl=",5) == 0 || strncmp(p,"nonl/",5) == 0) {        /* /nonl */
307                  p+=4;
308                  parm0=parm1=1;
309                } else
310                if (strncmp(p,"socket=",7) == 0 || strncmp(p,"socket/",7) == 0) {    /* /socket */
311                  p+=6;
312                  parmsocket=1;
313                } else
314                if (strncmp(p,"head=",5) == 0 || strncmp(p,"head/",5) == 0) {        /* /head */
315                  p+=4;
316                  parmhead=1;
317                } else
318                if (strncmp(p,"xml=",4) == 0 || strncmp(p,"xml/",4) == 0) {          /* /xml */
319                  p+=3;
320                  parmcmd=1;
321                } else
322                if (strncmp(p,"tell=",5) == 0 || strncmp(p,"tell/",5) == 0) {        /* /tell */
323                  p+=4;
324                  parmcmd=2;
325                } else
326                if (strncmp(p,"trace=",6) == 0 || strncmp(p,"trace/",6) == 0) {      /* /trace */
327                  p+=5;
328                  parmcmd=3;
329                } else
330                fatal("fldupdat/procx/Gload[/<tag>][/nolf][/xml][/socket][/head][={<url>|<file>}]");
331               } /* while /x */
332              } /* proc='Gload' */
333              if (*p == '=') {
334                p++; if (parmsocket) urlp=p; else filnamp=p; p+=strlen(p);    /* <file> | <url> */
335             
336              }
337            }
338
339
340            /* alloc working area
341            */
342            nbytes=(rec_maxmfrl>MAXMFRL)?rec_maxmfrl:MAXMFRL;
343            if (nbytes < MFRmfrl) nbytes=MFRmfrl;
344            nbytes+=BUFSIZ;     /* buffup */ /* nbytes=MFRmfrl+MFRmfrl+BUFSIZ; */
345#if CICPP
346            try { xarea = (char *) new char [nbytes]; }
347            catch (BAD_ALLOC) { xarea = (char *)ALLONULL; }
348#else /* CICPP */
349            xarea=(char *)ALLOC((ALLOPARM)nbytes);
350#endif /* CICPP */
351            if (xarea == (char *)ALLONULL) fatal("fldupdat/procx/Gload/socket/ALLOC");
352            *xarea='\0';
353
354            q=xarea; /* batchp */
355
356            /* del/add command
357            */
358            if (isload) {
359                if (!xtagzero) sprintf(q,"D%ld",xtag);
360                else      sprintf(q,"D*");                       q+=strlen(q);   // exec tag /0n
361
362                sprintf(haddp=q,"H%09ld ",(xtag)?(LONGX)xtag:1L); q+=strlen(q);
363                sprintf(hlenp=q,"123456789 ");                   q+=strlen(q);
364            }
365
366            hdatap=q;
367
368             if (parmparse) {            /* ./mx null "proc='Gsplit/marx /215 /Para =2151'" */
369
370            /* scan, xdata and parse
371            */
372            int min;//=parmmin;
373            int max;//=parmmax;
374            int occ=parm1cc;
375            int oc2=parm1c2;
376            int tag=parmtag;
377            char *bufp=NULL;
378            int xdir,loop;
379            int iocc=0,lastag=0;
380
381            haddp=hdatap; // fldupdat() ptr
382
383            //if (tag<0) tag=1;
384            //if (!tag)  tag=1; // Gload/1  Gmarx/1
385
386            if (occ<0) occ=0;
387            if (oc2<0) oc2=0;
388            if (oc2<occ) oc2=occ;
389
390            for (xdir=0, loop=MFRnvf; loop--; xdir++) {
391                int itag=DIRtag(xdir);
392                int ilen=DIRlen(xdir);
393                if (tag) if (itag != tag) continue;   // otherwise all tags
394                if (!tag) if (itag == 2000) continue; // exclude cicgi tag
395                if (itag == lastag) iocc++; else { lastag=itag; iocc=1; }
396                if (occ) if (iocc < occ) continue;
397                if (oc2) if (iocc > oc2) continue;
398                min=parmmin;
399                max=parmmax;
400                if (min<1) min=1;
401                if (max<1) max=nbytes-BUFSIZ;
402                if (ilen < min) continue;
403
404                if (!xbuffer) {
405#if CICPP
406                    try { xbuffer = (char *) new char [nbytes]; }
407                    catch (BAD_ALLOC) { xbuffer = (char *)ALLONULL; }
408#else /* CICPP */
409                    xbuffer=(char *)ALLOC((ALLOPARM)nbytes);
410#endif /* CICPP */
411                    if (xbuffer == (char *)ALLONULL) fatal("fldupdat/procx/Gsplit/marx/ALLOC");
412                }
413                *(bufp=xbuffer)='\0';
414
415                if (ilen) {
416                    char *fldp=FIELDP(xdir);
417                    bpmovemax(fldp,max,ilen,0);
418                }
419                if (ilen) {
420                    char *fldp=FIELDP(xdir);
421                    int left=(ilen<100)?ilen-1:100-1;
422                    int s=0;
423                    char *p,*q;
424                    char k=fldp[left];
425                    fldp[left]='\0'; q=strstr(fldp,"<x a=\""); fldp[left]=k;
426                    if (q) {
427                      for (p=fldp;       ; p++) { s++; if (*p=='>') break;          } // ancest
428                      for (p=q+6; *p!='"'; p++) { if (*p==',') break; *bufp++ = *p; } // ancest,*offset.lenght
429                      *bufp++='|'; *bufp++='|';
430                      memcpy(bufp,fldp+s,ilen-s);           bufp+=(ilen-s);
431                    }
432                    else {
433                      fldp[left]='\0'; q=strstr(fldp,"||"); fldp[left]=k;
434                      if (q) {
435                        for (p=fldp;  p!=; p++) { s++; } s+=2;                        // ancest
436                        for (p=fldp; *p!='|'; p++) { if (*p==',') break; *bufp++ = *p; } // ancest,*offset.lenght
437                        *bufp++='|'; *bufp++='|';
438                        memcpy(bufp,fldp+s,ilen-s);          bufp+=(ilen-s);
439                      }
440                      else {
441                        sprintf(bufp,"%d.%d||",itag,iocc);   bufp+=strlen(bufp);
442                        memcpy(bufp,fldp,ilen);              bufp+=ilen;
443                      }
444                    }
445                }
446                *bufp++='\n';
447                *bufp='\0';
448
449                if (*xbuffer) {
450
451                    // rc = mainparse ( parmcmd, xbuffer, vxpath, vxtag, hdatap, nbytes-strlen(xbuffer) );
452
453                    char *hp=haddp;
454                    //char *hpback=hp;
455                    char *x=xbuffer; // input data
456                    //int xbufaoff=strlen(xbuffer);
457                    int lft;
458                    char carea[BUFSIZ];
459                    char *name=carea+2;
460                    char *p;
461                    char *np;
462                    char *path;
463                    int ipath;
464                    int i;
465                    char *a;  //opening ptr
466
467                    int itag,iocc=0,lastag=0;
468
469                    carea[0]='<'; carea[1]='/';
470
471                    while ((a=strchr(x,'<')) != NULL) // while <element..>
472
473                      if (strchr(a,'>')) { // opening element // if
474
475                        char *b;  //opening end
476                        char *c=NULL;  //closing ptr
477                        char *d=NULL;  //closing end
478                        int xb;   //opening len
479                        int xn;   //element name len
480                        char *ba;
481                        int xx=0;
482                        int xen=0;
483                        int len=0;
484                        int hasattr=0;
485                        int closed=0;
486                        //
487                        char *ihtba=NULL;
488                        int ihtxen=0;
489                        int level=0;
490                        char *indattr=" level=\"";
491                        int   indsize=8,xlev;
492                        //
493
494                        for (xb=1, b=a; *b != '>'; b++) xb++;                 // <x ...>....</x>
495                        if (*(b-1) == '/') closed=1;                          // <x ../>
496
497                        for (np=name, xn=0, p=a+1, lft=xb; lft--; p++) {
498                            if (*p == ' ') hasattr=1;
499                            if (*p == ' ' || *p == '/' || *p == '>') break;
500                            xn++; *np++= *p;
501                        }
502                        *np='\0';
503
504                        for (ipath=EOF, i=0; ; i++) {
505                            path=vxpath[i]; if (!path) break;
506                            if (strcmp(path,name) == 0) { ipath=i; itag=vxtag[ipath]; break; }
507                        }
508
509                        x=b+1;                                                // contents
510                        if (ipath == EOF) continue;        // skip element
511
512
513                        if (itag == lastag) iocc++; else { lastag=itag; iocc=1; hlen=0; }
514#if 01
515                        if (parmocc) if (iocc < parmocc) continue;
516                        if (parmoc2) if (iocc > parmoc2) continue;
517#endif
518                        if (*colonspecp == '-') continue;  // skip element - void output
519
520                        if (selsize) if (hasattr) {
521                            int skip=1;
522                            char *p;
523                            for (p=a; p!=b; p++) {
524                                if (*p == ' ') {
525                                    p++; // space
526                                    if (strncmp(p,selattr,selsize)==0) {
527                                        char c=p[selsize];
528                                        if (c == ' ' || c == '/' || c == '>') { skip=0; break; }
529                                    }
530                                }
531                            }
532                            if (skip) continue;            // skip element
533                        }
534
535                        if (closed) {                                         // <x ../>
536                            for (p=a; ; p++) { len++; if (p==b) break; }
537                        }
538                        else {                                                // <x ..>....</x>
539                        //
540                            char *q,oarea[BUFSIZ];
541                            int oxn;
542                        //
543                            int empty=0; //(c==x)?1:0;
544                            //
545                            level=0;
546                            //
547                            strcat(carea,">"); c=strstr(x,carea);
548                            if (c) d=strchr(c,'>');
549                            //
550                            //
551                            if (parmindex) if (c) { //it's well formed
552                                char *op=NULL;
553                                char *q=b;       //hierarchal index stops at b instead of c
554                                oxn=1+xn; oarea[0]='<'; memcpy(oarea+1,name,xn); oarea[oxn]='\0';
555                                *c='\0'; q=strstr(q+1,oarea); *c='<';                                                  // <name
556                                if (q) if (q[oxn]==' ' || q[oxn]=='>') { op=q; for (; q!=c; q++) if (*q=='>') break; } // <name ..>
557                                if (op) {
558                                  c=op;   //dlm as if </index>
559                                  d=op-1; //set forward x=d+1
560                                }
561                            }
562
563                        //
564                        // <index level=1> <index level=2> </index><index level=2><index level=3></index></index><index level=2></index></index>
565                        //                 op
566                        // a             b                 c      d                                                                      c     d
567
568                        // <index level=1> <index level=2> 2A </index> <index level=2> 2B</index> <index level=2> 2C </index> </index>
569                        //                 op
570                        // a             b                    c      d                   c      d                    c      d C      D
571                        //
572                                                                              // a     b    c  d
573                                if (parmindex) {
574                                    if (!iphbuff) {
575#if CICPP
576                                        try { iphbuff = (char *) new char [nbytes]; }
577                                        catch (BAD_ALLOC) { iphbuff = (char *)ALLONULL; }
578#else /* CICPP */
579                                        iphbuff=(char *)ALLOC((ALLOPARM)nbytes);
580#endif /* CICPP */
581                                        if (iphbuff == (char *)ALLONULL) fatal("fldupdat/procx/Gsplit/marx/ALLOC");
582                                    }
583                                    if (!ihtbuff) {
584#if CICPP
585                                        try { ihtbuff = (char *) new char [nbytes]; }
586                                        catch (BAD_ALLOC) { ihtbuff = (char *)ALLONULL; }
587#else /* CICPP */
588                                        ihtbuff=(char *)ALLOC((ALLOPARM)nbytes);
589#endif /* CICPP */
590                                        if (ihtbuff == (char *)ALLONULL) fatal("fldupdat/procx/Gsplit/marx/ALLOC");
591                                        *ihtbuff='\0'; for (xlev=0; xlev<21; xlev++) { ihtptr[xlev]=ihtbuff; ihtlen[xlev]=0; ihtocc[xlev]=0; ihtpta[xlev]=NULL; ihtpla[xlev]=0; ihtptc[xlev]=NULL; ihtptd[xlev]=NULL; }
592                                    }
593                                    level=0; ihtxen=0; xen=0;
594                                    if (hasattr) for (p=a+1; p!=b; p++) if (*p == ' ') if (strncmp(p,indattr,indsize)==0) {                   //.level="
595                                      for (p+=indsize; isdigit(*p); p++ ) level=level*10+((int)(*p)-(int)'0'); break;
596                                    }
597                                    if (level>=1 && level<21) {
598                                      //header
599                                      char *a1,*b1=NULL,*c1=NULL;
600                                      char *a2,*b2=NULL,*c2=NULL;
601                                      char *oarea1="<header",*carea1="</header>";
602                                      char *oarea2="<text",*carea2="</text>";
603                                      int oxn1=7,oxn2=5;
604                                      //
605                                      //header
606                                      *c='\0'; a1=strstr(b+1,oarea1);  if (a1) if (a1[oxn1]==' ' || a1[oxn1]=='>') b1=strchr(a1,'>'); *c='<'; // <header..>
607                                      if (b1) { c1=strstr(b1+1,carea1); }                                                                     // </header>
608                                      if (c1) {
609                                        int n;
610                                        char *ihtp=ihtptr[level]+ihtlen[level]+1;
611                                        //copy header
612                                        if (level>1) *ihtp++=' ';
613                                        *c1='\0'; n=strlen(b1+1); *c1='<'; memcpy(ihtp,b1+1,n); ihtptr[level]=ihtp; ihtp+=n; ihtlen[level]=n; *ihtp='\0';
614                                        ihtocc[level]=iocc;
615                                        ihtpta[level]=a; ihtpla[level]=b-a+1; if (closed) ihtpla[level]--;
616                                        ihtptc[level]=c; ihtptd[level]=d;
617                                   /**/ for (xlev=level+1; xlev<21; xlev++) { ihtptr[xlev]=ihtp; ihtlen[xlev]=0; ihtocc[xlev]=0; ihtpta[xlev]=NULL; ihtpla[xlev]=0; ihtptc[xlev]=NULL; ihtptd[xlev]=NULL; }
618                                        //
619                                        //text
620                                        *c='\0'; a2=strstr(b+1,oarea2);  if (a2) if (a2[oxn2]==' ' || a2[oxn2]=='>') b2=strchr(a2,'>'); *c='<'; // <text..>
621                                        if (b2) { c2=strstr(b2+1,carea2); }                                                                     // </text>
622                                        if (c2) { *c2='\0';  ihtxen=strlen(b2+1); *c2='<'; ihtba=b2+1; }
623                                      }//c1
624                                    }//level
625                                    //ihtmove(p,max,len,xleft)
626                                }//end parmindex
627                            else // nested
628                            if (d) {
629                              q=b;       //nested elements in b+1..c-1
630                              oxn=1+xn; oarea[0]='<'; memcpy(oarea+1,name,xn); oarea[oxn]='\0';
631                              while (d) {  //while following closing and nested opening
632                                char *op=NULL;
633                                *c='\0'; q=strstr(q+1,oarea); *c='<';                                                  // <name
634                                if (q) if (q[oxn]==' ' || q[oxn]=='>') { op=q; for (; q!=c; q++) if (*q=='>') break; } // <name ..>
635                                if (op) {                       //nested opening
636                                  c=strstr(d+1,carea); d=NULL;  //following c                                          // </name>
637                                  if (c) d=strchr(c,'>');       //following d
638                                }
639                                else break;
640                              }//end while following closing and nested opening
641                            }//d
642
643                            if (selparm) {
644                              int skip=1;
645                              char *p;
646                              if (!parmindex) {
647                                level=0; ihtxen=0; xen=0;
648                                if (hasattr) for (p=a+1; p!=b; p++) if (*p == ' ') if (strncmp(p,indattr,indsize)==0) {                   //.level="
649                                  for (p+=indsize; isdigit(*p); p++ ) level=level*10+((int)(*p)-(int)'0'); break;
650                                }
651                                if (level>=1 && level<21) ihtocc[level]=iocc;
652                              }
653                              if (level>=1 && level<21) {
654                                for (p=selcodearea, xlev=1; xlev<=level; xlev++) { sprintf(p,"%d.",ihtocc[xlev]); p+=strlen(p); } *p++='\0';
655                                if (strcmp(selcodearea,selcode) == 0) skip=0;  // get this element - code
656                              }
657                              if (skip) continue;                              // skip element - code
658                            }//end selparm
659
660                            if (d) if (!parmindex) {
661                              char *bc=c;
662                              //remove CDATA marks
663                              int parmy=clean;
664                              if (parmy) {
665                                    char *p,*q;
666                                    char k= *c; *c='\0';
667                                    p=b+1; while ((q=strstr(p,"<![CDATA[")) !=NULL) { memset(q,(int)' ',9); p=q+9; }
668                                    p=b+1; while ((q=strstr(p,"]]>"      )) != NULL) { memset(q,(int)' ',3); p=q+3; }
669                                    p=b+1; while ((q=strchr(p,'<')) != NULL) if ((p=strchr(q,'>')) == NULL) { *q=' '; p=q+1; } else for (*p=' '; p!=q; ) *--p=' ';
670                                    *c=k;
671                              } // parmy
672                              for (p=a;  ; p++) { len++; if (p==d)  break; }
673                              for (ba=b+1; ba!=&& isspace(*ba); ) { ba++; xx++; }
674                              if (ba==c)  empty=1; else for (bc=c-1; bc!=ba && isspace(*bc); ) { bc--; xx++; }
675                              if (ba==bc) empty=1;
676                              if (!empty) {
677                                for (p=ba; ; p++) { xen++; if (p==bc) break; }
678                                if (clean) {
679                                    int left=xen,n=0;
680                                    char *p=ba,*q=ba,x='\0';
681                                    while (left--)
682                                      if (x==' ' && *p==' ') { p++; n++; }
683                                      else
684                                      if (x=='.' && *p=='.') { p++; n++; }
685                                      else
686                                      { x= *p; if (p == q) { p++; q++; } else *q++ = *p++; }
687                                    xen-=n;
688                                }//clean
689                                //
690                              }//!empty
691                            }//d
692                        }//!closed
693
694                        while (xmlspec || hasattr || xen || ihtxen) {
695#if 01
696                            if (xmlspec || hasattr || xen >= min || ihtxen >= min) {
697#endif
698                                char *hdatp;
699                                LONGX litag=(parmvin)?parmvin:itag;
700                                if (ihtxen) {
701                                    //int xlev;
702                                    int xe;
703                                    char *iphp,*c2,k;
704                                    char *pp;   //par1 a
705                                    int qpcase; //case
706//
707                                    //execute /index@level:header,text
708                                    ba=iphbuff;
709                                    //copy headers
710                                    for (iphp=iphbuff, xlev=1; xlev<=level; xlev++) {
711                                      if (ihtlen[xlev]) { memcpy(iphp,ihtptr[xlev],ihtlen[xlev]); iphp+=ihtlen[xlev]; } else *iphp++='-';
712                                    //*iphp++='.'; *iphp++=' ';
713                                      *iphp++='|';
714                                    }
715                                    *iphp++='|';
716                                    *iphp='\0'; xen=strlen(iphbuff);
717                                    //copy text
718                                    c2=ihtba+ihtxen; k= *c2; *c2='\0'; //skip headers, search for .space
719
720                                    p=strstr(pp=ihtba,". ");           // Par1.   Par2.
721                                    while (isspace(*pp)) pp++;         // Par1.   Par2.
722                                    qpcase=0;                          // Par1.   Par2.
723                                    while (p) {                        // pp  p   qq  pq
724                                                                       // Aetc.   Aetc.
725                                                                       // Aetc.   12. Aetc
726                                      char *q;
727                                      char *qq; //par2 a
728                                      char *pq; //par2 b
729                                      int n=0;  //par1 lenght excluding .
730                                      int s=0;  //spaces before par2
731                                      int m=0;  //par2 lenght excluding .
732                                      int v=0;  //par2 starts with digits
733                                      int w=0;  //par2 is all digits, period and upper case letter
734//
735                                      for (q=pp;  q!=p;        q++) n++;
736                                      for (q=p+1; isspace(*q); q++) s++;
737                                      pq=strstr(qq=q,". ");
738                                      qpcase=0;
739                                      if (pq) qpcase=2; else for (; *q; q++) if (*q=='.' && !*(q+1)) { pq=q; qpcase=1; }
740                                      if (pq) for (q=p+1+s; q!=pq;       q++) m++;
741                                      if (pq) for (q=p+1+s; isdigit(*q); q++) v++;
742                                      if (v) if (*q=='.' && *(q+1)==' ') { q+=2; while (isspace(*q)) q++; if (isupper(*q)) w=v; }
743//
744                                      if (n<=3) {                      //par1 is too short - 1.
745                                         pp=qq; p=pq;
746                                         continue;
747                                      }
748                                      if (w && w<=2) {                 //par2 is 12. Aetc
749                                         break;
750                                      }
751                                      if (m) if (!isupper(*qq)) {      //par2 not Aetc     - E. coli
752                                         pp=qq; p=pq;
753                                         continue;
754                                      }
755                                      if (m<=3) {                      //par2 is too short - Tard A. O.
756                                         pp=qq; p=pq;
757                                         continue;
758                                      }
759                                      break;           //otherwise
760                                    }
761                                    *c2=k;
762#if 1
763                                    if (p) { *(p+1)='\0'; xe=strlen(ihtba); *(p+1)=' '; memcpy(iphp,ihtba,xe);    ihtba+=(xe+1);  ihtxen-=(xe+1); }
764                                    else   {              xe=ihtxen;                    memcpy(iphp,ihtba,xe);    ihtba=NULL;     ihtxen=0;       }
765#else
766                                    if (p) {
767                                      if (qpcase == 2)
768                                           { *(p+1)='\0'; xe=strlen(ihtba); *(p+1)=' '; memcpy(iphp,ihtba,xe);    ihtba+=(xe+1);  ihtxen-=(xe+1); }
769                                      else
770                                      if (qpcase == 1)
771                                           {              xe=strlen(ihtba);             memcpy(iphp,ihtba,xe);    ihtba+=(xe  );  ihtxen-=(xe  ); }
772                                      else
773                                           {              xe=ihtxen;                    memcpy(iphp,ihtba,xe);    ihtba=NULL;     ihtxen=0;       }
774                                    }
775                                    else   {              xe=ihtxen;                    memcpy(iphp,ihtba,xe);    ihtba=NULL;     ihtxen=0;       }
776#endif
777                                    if (xe) { //
778                                      char *pa=iphp,*pc=iphp+xe;
779                                      for (; pa!=pc && isspace(*pa); ) { pa++; xe--; }
780                                      if (pa==pc) xe=0; else for (; pc!=pa && isspace(*pc); ) { pc--; xe--; }
781                                      if (pa==pc) xe=0;
782                                      if (xe) {
783                                            int left=xe,n=0;
784                                            char *p=pa,*q=iphbuff+xen,x='\0';
785                                            while (left--)
786                                              if (x==' ' && *p==' ') { p++; n++; }
787                                              else
788                                              if (x=='.' && *p=='.') { p++; n++; }
789                                              else
790                                              { x= *p; if (p == q) { p++; q++; } else *q++ = *p++; }
791                                            xe-=n;
792                                      }//!empty
793                                    }//xe
794                                    xen+=xe;
795                                    if (!xe) xen=0; // no text to display
796                                }//end if ihtxen
797                                if (parmindex) if (!xen) break;
798
799                                if (colonspec) {
800                                    if (parmx) {
801                                      if (chunch2 < 6 || chunch2>=chunch1) chunch2=chunch1/2;
802                                      if (chunch3 < 6 || chunch3>=chunch1) chunch3=chunch1/3;
803                                      max=chunch1+chunch2;
804                                      if (hlen) {
805                                        if (closed) { if (hasattr)              hlen=0; }
806                                        else {        int xe=0;
807                                                      char *xep=ba;
808                                                      while (isdigit(*xep) || *xep=='.') { xep++; xe++; }
809                                                      if (xe>1) if (*xep==' ')  hlen=0;   //    - / n.n.
810                                                      if (xen      >  max    )  hlen=0;   //336 - / 224...112
811                                                      if (xen      >  chunch1)  hlen=0;   //224 - / xen
812                                        }
813                                        if (hlen) {
814                                          *hp++=' '; *hp++=' ';
815                                        }
816                                      }
817                                      if (hlen==0) {
818                                        hlenp=hp+11; sprintf(hp,"H%09ld 123456789 ",litag); hp+=strlen(hp); hdatp=hp;
819                                        if (parmfile) { sprintf(hp,"%s ",filename);                         hp+=strlen(hp); }
820                                        sprintf(hp,"%d %d: ",itag,iocc);                                    hp+=strlen(hp);
821                                        if (level) { //headers ptrs/code
822                                            sprintf(hp,"%d",ihtocc[1]); hp+=strlen(hp); for (xlev=2; xlev<=level; xlev++) { sprintf(hp,".%d",ihtocc[xlev]); hp+=strlen(hp); }
823                                            sprintf(hp,"||");                                               hp+=strlen(hp);
824                                        }
825                                        bpmovemax(ba,max,xen,1);  //336  //224
826                                      }
827                                      max+=3;
828                                    }
829                                    else {  //parse/index !parmx
830                                      hlenp=hp+11; sprintf(hp,"H%09ld 123456789 ",litag); hp+=strlen(hp); hdatp=hp;
831                                      //if (parmfile) { sprintf(hp,"%s%s%s%s%s ",filepath,filechar,filename,filedot,fileext);  hp+=strlen(hp); }
832                                      if (parmfile) { sprintf(hp,"%s ",filename);                         hp+=strlen(hp); }
833                                      for (p=xbuffer; ; p++) { if (*p=='|') break; *hp++ = *p; }  // ancestor
834                                      if (parmxlen) { sprintf(hp," %d.%d, %d,%d,%d,%d||",itag,iocc,xn,xb,xen,len);          hp+=strlen(hp); }
835                                      else          { sprintf(hp," %d.%d||"             ,itag,iocc              );          hp+=strlen(hp); }
836                                      if (level) { //headers ptrs/code
837                                            sprintf(hp,"%d",ihtocc[1]); hp+=strlen(hp); for (xlev=2; xlev<=level; xlev++) { sprintf(hp,".%d",ihtocc[xlev]); hp+=strlen(hp); }
838                                            sprintf(hp,"||");                                               hp+=strlen(hp);
839                                      }
840                                    } //end parmx
841                                } else { //xmlspec/!colonspec
842                                    hlenp=hp+11; sprintf(hp,"H%09ld 123456789 ",litag); hp+=strlen(hp); hdatp=hp;
843                                    if (parmxml) if (!xmlopened) {
844                                      sprintf(hp,"<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");     hp+=strlen(hp);
845                                      sprintf(hp,"<marx file=\"%s\" type=\"%s%s\" path=\"%s%s\">\n",filename,filedot,fileext,filepath,filechar);  hp+=strlen(hp);
846                                      xmlopened=1;
847                                    }
848                                    sprintf(hp,"<x a=\"");                                                  hp+=strlen(hp);
849                                    for (p=xbuffer; ; p++) { if (*p=='|') break; *hp++ = *p; } // ancestor
850                                    sprintf(hp," %d.%d\"",itag,iocc);                                      hp+=strlen(hp);
851                                    if (parmxlen) { sprintf(hp," b=\"%d,%d,%d,%d\"",xn,xb,xen,len);         hp+=strlen(hp); }
852                                    if (level) { //headers ptrs/code
853                                          sprintf(hp," c=\"");                                              hp+=strlen(hp);
854                                          sprintf(hp,"%d",ihtocc[1]); hp+=strlen(hp); for (xlev=2; xlev<=level; xlev++) { sprintf(hp,".%d",ihtocc[xlev]); hp+=strlen(hp); }
855                                          sprintf(hp,"\"");                                                 hp+=strlen(hp);
856                                    }
857                                    sprintf(hp,"/>"); hp+=strlen(hp);
858                                }
859
860                                if (colonspec) {
861                                  if (*colonspecp) {
862                                    for (q=colonspecp; *q; q++) {
863                                      if (*q == '&') {
864                                        char *p=q+1;
865                                        char *m;
866                                        if (isalpha(*p) || isdigit(*p)) {   //&name - attr char1
867                                          char bb[BUFSIZ];
868                                          char *aap=NULL;
869                                          char *aaq=NULL;
870                                          char k;
871                                          for (m=bb, *m=' '; isalpha(*p) || isdigit(*p); p++) { *m++= *p; q++; } *m++='='; *m++='"'; *m='\0';  //.attrname="
872                                          k= *b; *b='\0'; aap=strstr(a+1,bb); if (aap) aaq=strchr(aap+=strlen(bb),'"'); *b=k;
873                                          if (aaq) while (aap != aaq) *hp++ = *aap++;           //output attr contents
874                                        }
875                                        else {                              //& - element name, attrs, contents
876                                          for (  p=a+1,      m=p+xn;          p != m; p++) *hp++= *p;             //output element name
877                                          if (hasattr) { *hp++=' ';                                               //output
878                                            if (closed) for (p=a+1+xn+1, m=b-1/*closed*/; p != m; p++) *hp++= *p; //output all attrs
879                                            else        for (p=a+1+xn+1, m=b-0/*      */; p != m; p++) *hp++= *p; //output all attrs
880                                          }
881                                          if (xen) {
882                                            *hp++=' ';                                                            //output
883                                            //for (p=ba; xen--; p++) *hp++= *p;                                   //output all contents //
884                                            hpmovemax(hp,max,ba,xen);                                             //output all contents //
885                                          }
886                                        }// end if char1
887                                      } else {                              //. - spec char
888                                        *hp++ = *q;                                                               //output spec char
889                                      }//& or .
890                                      if (q==colonspecq) break;
891                                    }//end for
892                                  } //colonspecp
893                                  else { //colonspecp                       //: - contents
894                                      if (closed) { xen=len-3; ba=a+1; }
895                                      hpmovemax(hp,max,ba,xen);                                                   //: - output contents
896                                  } //colonspec
897                                } else { //colonspec
898                                    hpmovemax(hp,max,a,len);                                                      //: - output xml
899                                } //colonspec
900
901                                if (xmlopened) {
902                                  sprintf(hp,"</marx>\n");  hp+=strlen(hp);
903                                }
904                                //null hp string
905                                *hp='\0'; haddp=hp;
906
907                                //actual len
908                                hlen=strlen(hdatp); sprintf(hlenp,"%9ld",(LONGX)hlen); hlenp[9]=' ';
909
910                                if (parmx) {
911                                        if (  hlen      >= chunch1         )    hlen=0;   //224 - /
912                                        if (!closed) if ( xen > chunch3 ) {               //75  - 75./
913                                                          if ( ba[xen-1]=='.' ) hlen=0;
914                                                          if ( ba[xen-1]==';' ) hlen=0;
915                                        }
916                                } // parmx
917
918                                //move forward ok
919                                if (d) x=d+1;
920
921                            } // end if xmlspec || hasattr || xen >= min || ihtxen >= min
922                            // else continues from x=b+1
923
924                            if (!ihtxen) break;
925
926                        } // end while xmlspec || hasattr ||xen || ihtxen
927
928
929                      } else { // else while <element..>
930
931                        x++;
932
933                      } // fi while <element..>
934
935                } // *xbuffer
936            } // xdir
937             } // parmparse
938
939         else  /* else parmparse */
940
941             if (parmsocket) {            /* ./mx null "proc='Gload/socket=http://www.bireme.br:80/'" */
942
943            /* scan <url>
944            */
945            protocol="HTTP";
946            q=strstr(p=urlp,"://"); /* http:// */
947            if (q) {
948                char *x;
949                int len;
950                *q='\0'; len=strlen(p);
951                if (len < 8) {
952                  protocol=p;                                                    /* http | x1417*/
953                  for (x=p; *x; x++) *x=toupper(*x);
954                  p=q+3;
955                }
956                else *q=':';
957            }
958
959            serverhost=p;                                                       /* www.bireme.br | serverofi.bireme.br */
960
961            pathp=strchr(p+1,'/');                                           /* /path | /dbname/parms */
962            if (pathp) *pathp='\0';
963            else pathp="/";
964
965            port=80;                          /* :80 */
966            q=strchr(p,':');
967            if (q) {
968                *q='\0';
969                if (sscanf(q+1,"%d",&xport) == 1) port=xport;                   /* :80 | :1417 */
970                else xport=0; /*fatal("fldupdat/procx/Gload/socket/port");*/
971            }
972
973            /* X1417://serverofi.bireme.br:1417/msg
974                                               /dbname/control/maxmfn
975                                               /dbname/text/mfn/mfn2/count/step
976                                               /dbname/dict/key/key2/contains/count
977                                               /dbname/bool/expression
978                                               /dbname/rank/text
979            */
980            if (strcmp(protocol,"X1417") == 0) {
981                maxrds=1;                                                        /* single read */
982                if (!xport) port=1417;     /* :1417 */
983            }
984
985            msgp=hdatap;
986            *msgp='\0';
987            if (strcmp(protocol,"X1417") == 0) {
988                sprintf(msgp,"%s\n",pathp+1);
989            }
990            else
991            if (strcmp(protocol,"HTTP") == 0) {
992                sprintf(msgp,"%s /%s HTTP/1.0\r\n\r\n",(parmhead)?"HEAD":"GET",pathp+1);
993            }
994
995            if (*msgp) rc = mainclient ( parmcmd, protocol, serverhost, port, msgp, hdatap, nbytes-strlen(xarea), maxrds);
996
997             }
998
999
1000//#define DIR_FILE 1                  /* list=directory */
1001//#if DIR_FILE
1002//#include <sys/types.h>
1003//#include <dirent.h>
1004//#endif
1005    /* ............................................... directory listing */
1006#if DIR_FILE
1007         else   /* else parmsocket: <file> */
1008             if (strncmp(filnamp,"dir=",4)==0) {
1009                DIR *direntdp=NULL;
1010                struct dirent *direntep;
1011                char *directory=filnamp+4;
1012                rc=0;
1013                direntdp = opendir (directory);
1014                if (direntdp != NULL) {
1015                    int n;
1016                    while ((direntep = readdir (direntdp)) != NULL) {
1017                        strcpy(hdatap,direntep->d_name); 
1018                        n=strlen(direntep->d_name); *(hdatap+=n)='\n'; *++hdatap='\0'; rc+=(n+1);
1019                    }
1020                    (void) closedir (direntdp);
1021                }
1022                //else fatal("Couldn't open the directory");
1023             }   
1024#endif
1025
1026         else { /* else parmsocket: <file> */
1027
1028             rc = mainfile ( parmcmd, filnamp, parm0, parm1, hdatap, nbytes-strlen(xarea) );
1029
1030             } /* end parmsocket */
1031
1032
1033
1034        if (isload) {
1035            if (rc < 0) {
1036                sprintf(hdatap,"Gload%s error %d",parmsocket?"/socket":"",(-rc));
1037                hlen=strlen(hdatap);
1038            }
1039            else hlen=rc;
1040
1041            if (hlen) {
1042                /* actual add lenght */
1043                sprintf(hlenp,"%9ld",(LONGX)hlen); hlenp[9]=' ';
1044                /* print */
1045                //if (parmprint) fprintf(parmfp,"%s",hdatap);
1046            }
1047            else if (haddp) *haddp='\0';
1048        }
1049
1050        //else printf("%s\n",xarea);
1051
1052#if CICPP
1053        if (recp->xfldupdat(xarea)) fatal(errp);
1054        delete xarea;
1055        delete xbuffer;
1056#else /* CICPP */
1057//printf("antes do fldupdat\n");
1058        if (fldupdat(irec,xarea)) fatal(errp);
1059//printf("depois do fldupdat\n");
1060        if (xarea) FREE(xarea);
1061        if (xbuffer) FREE(xbuffer);
1062#endif /* CICPP */
1063
1064        return NULL; //isgdump=1;
1065
1066        }  /* end Gload/socket */
1067        else
1068
1069#endif /* PROCXSOCKREC */
1070/* End PROCXSOCKREC
1071*/
1072
1073#if INDEXAT
1074                                            for (xlev=1; xlev<=level; xlev++) {
1075                                              char *p=ihtpta[xlev]+1;
1076                                              int n=ihtpla[xlev]-1;
1077                                              *hp++='/';
1078                                              while (n) if (*p==' ' || *p=='/' || *p=='>') break; else { *hp++ = *p++; n--; }
1079                                              if (*p==' ') { p++; n--; }
1080                                              *hp++='@';
1081                                              n--; if (closed) n--;
1082                                              memcpy(hp,p,n); hp+=n;
1083                                              *hp++='|';
1084                                            }
1085#endif
Note: See TracBrowser for help on using the browser.