root/trunk/ciupdmarx.c

Revision 389, 56.8 kB (checked in by heitor.barbieri, 3 weeks ago)

essage first commit

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%09"_LD_" ",(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/* bug: pega todas as ocorrencias do elemento que nao tenham atributos
521                        if (selsize) if (hasattr) {
522*/
523                        if (selsize) {
524                            int skip=1;
525                            char *p;
526                            for (p=a; p!=b; p++) {
527                                if (*p == ' ') {
528                                    p++; // space
529                                    if (strncmp(p,selattr,selsize)==0) {
530                                        char c=p[selsize];
531                                        if (c == ' ' || c == '/' || c == '>') { skip=0; break; }
532                                    }
533                                }
534                            }
535                            if (skip) continue;            // skip element
536                        }
537
538                        if (closed) {                                         // <x ../>
539                            for (p=a; ; p++) { len++; if (p==b) break; }
540                        }
541                        else {                                                // <x ..>....</x>
542                        //
543                            char *q,oarea[BUFSIZ];
544                            int oxn;
545                        //
546                            int empty=0; //(c==x)?1:0;
547                            //
548                            level=0;
549                            //
550                            strcat(carea,">"); c=strstr(x,carea);
551                            if (c) d=strchr(c,'>');
552                            //
553                            //
554                            if (parmindex) if (c) { //it's well formed
555                                char *op=NULL;
556                                char *q=b;       //hierarchal index stops at b instead of c
557                                oxn=1+xn; oarea[0]='<'; memcpy(oarea+1,name,xn); oarea[oxn]='\0';
558                                *c='\0'; q=strstr(q+1,oarea); *c='<';                                                  // <name
559                                if (q) if (q[oxn]==' ' || q[oxn]=='>') { op=q; for (; q!=c; q++) if (*q=='>') break; } // <name ..>
560                                if (op) {
561                                  c=op;   //dlm as if </index>
562                                  d=op-1; //set forward x=d+1
563                                }
564                            }
565
566                        //
567                        // <index level=1> <index level=2> </index><index level=2><index level=3></index></index><index level=2></index></index>
568                        //                 op
569                        // a             b                 c      d                                                                      c     d
570
571                        // <index level=1> <index level=2> 2A </index> <index level=2> 2B</index> <index level=2> 2C </index> </index>
572                        //                 op
573                        // a             b                    c      d                   c      d                    c      d C      D
574                        //
575                                                                              // a     b    c  d
576                                if (parmindex) {
577                                    if (!iphbuff) {
578#if CICPP
579                                        try { iphbuff = (char *) new char [nbytes]; }
580                                        catch (BAD_ALLOC) { iphbuff = (char *)ALLONULL; }
581#else /* CICPP */
582                                        iphbuff=(char *)ALLOC((ALLOPARM)nbytes);
583#endif /* CICPP */
584                                        if (iphbuff == (char *)ALLONULL) fatal("fldupdat/procx/Gsplit/marx/ALLOC");
585                                    }
586                                    if (!ihtbuff) {
587#if CICPP
588                                        try { ihtbuff = (char *) new char [nbytes]; }
589                                        catch (BAD_ALLOC) { ihtbuff = (char *)ALLONULL; }
590#else /* CICPP */
591                                        ihtbuff=(char *)ALLOC((ALLOPARM)nbytes);
592#endif /* CICPP */
593                                        if (ihtbuff == (char *)ALLONULL) fatal("fldupdat/procx/Gsplit/marx/ALLOC");
594                                        *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; }
595                                    }
596                                    level=0; ihtxen=0; xen=0;
597                                    if (hasattr) for (p=a+1; p!=b; p++) if (*p == ' ') if (strncmp(p,indattr,indsize)==0) {                   //.level="
598                                      for (p+=indsize; isdigit(*p); p++ ) level=level*10+((int)(*p)-(int)'0'); break;
599                                    }
600                                    if (level>=1 && level<21) {
601                                      //header
602                                      char *a1,*b1=NULL,*c1=NULL;
603                                      char *a2,*b2=NULL,*c2=NULL;
604                                      char *oarea1="<header",*carea1="</header>";
605                                      char *oarea2="<text",*carea2="</text>";
606                                      int oxn1=7,oxn2=5;
607                                      //
608                                      //header
609                                      *c='\0'; a1=strstr(b+1,oarea1);  if (a1) if (a1[oxn1]==' ' || a1[oxn1]=='>') b1=strchr(a1,'>'); *c='<'; // <header..>
610                                      if (b1) { c1=strstr(b1+1,carea1); }                                                                     // </header>
611                                      if (c1) {
612                                        int n;
613                                        char *ihtp=ihtptr[level]+ihtlen[level]+1;
614                                        //copy header
615                                        if (level>1) *ihtp++=' ';
616                                        *c1='\0'; n=strlen(b1+1); *c1='<'; memcpy(ihtp,b1+1,n); ihtptr[level]=ihtp; ihtp+=n; ihtlen[level]=n; *ihtp='\0';
617                                        ihtocc[level]=iocc;
618                                        ihtpta[level]=a; ihtpla[level]=b-a+1; if (closed) ihtpla[level]--;
619                                        ihtptc[level]=c; ihtptd[level]=d;
620                                   /**/ 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; }
621                                        //
622                                        //text
623                                        *c='\0'; a2=strstr(b+1,oarea2);  if (a2) if (a2[oxn2]==' ' || a2[oxn2]=='>') b2=strchr(a2,'>'); *c='<'; // <text..>
624                                        if (b2) { c2=strstr(b2+1,carea2); }                                                                     // </text>
625                                        if (c2) { *c2='\0';  ihtxen=strlen(b2+1); *c2='<'; ihtba=b2+1; }
626                                      }//c1
627                                    }//level
628                                    //ihtmove(p,max,len,xleft)
629                                }//end parmindex
630                            else // nested
631                            if (d) {
632                              q=b;       //nested elements in b+1..c-1
633                              oxn=1+xn; oarea[0]='<'; memcpy(oarea+1,name,xn); oarea[oxn]='\0';
634                              while (d) {  //while following closing and nested opening
635                                char *op=NULL;
636                                *c='\0'; q=strstr(q+1,oarea); *c='<';                                                  // <name
637                                if (q) if (q[oxn]==' ' || q[oxn]=='>') { op=q; for (; q!=c; q++) if (*q=='>') break; } // <name ..>
638                                if (op) {                       //nested opening
639                                  c=strstr(d+1,carea); d=NULL;  //following c                                          // </name>
640                                  if (c) d=strchr(c,'>');       //following d
641                                }
642                                else break;
643                              }//end while following closing and nested opening
644                            }//d
645
646                            if (selparm) {
647                              int skip=1;
648                              char *p;
649                              if (!parmindex) {
650                                level=0; ihtxen=0; xen=0;
651                                if (hasattr) for (p=a+1; p!=b; p++) if (*p == ' ') if (strncmp(p,indattr,indsize)==0) {                   //.level="
652                                  for (p+=indsize; isdigit(*p); p++ ) level=level*10+((int)(*p)-(int)'0'); break;
653                                }
654                                if (level>=1 && level<21) ihtocc[level]=iocc;
655                              }
656                              if (level>=1 && level<21) {
657                                for (p=selcodearea, xlev=1; xlev<=level; xlev++) { sprintf(p,"%d.",ihtocc[xlev]); p+=strlen(p); } *p++='\0';
658                                if (strcmp(selcodearea,selcode) == 0) skip=0;  // get this element - code
659                              }
660                              if (skip) continue;                              // skip element - code
661                            }//end selparm
662
663                            if (d) if (!parmindex) {
664                              char *bc=c;
665                              //remove CDATA marks
666                              int parmy=clean;
667                              if (parmy) {
668                                    char *p,*q;
669                                    char k= *c; *c='\0';
670                                    p=b+1; while ((q=strstr(p,"<![CDATA[")) !=NULL) { memset(q,(int)' ',9); p=q+9; }
671                                    p=b+1; while ((q=strstr(p,"]]>"      )) != NULL) { memset(q,(int)' ',3); p=q+3; }
672                                    p=b+1; while ((q=strchr(p,'<')) != NULL) if ((p=strchr(q,'>')) == NULL) { *q=' '; p=q+1; } else for (*p=' '; p!=q; ) *--p=' ';
673                                    *c=k;
674                              } // parmy
675                              for (p=a;  ; p++) { len++; if (p==d)  break; }
676                              for (ba=b+1; ba!=&& isspace(*ba); ) { ba++; xx++; }
677                              if (ba==c)  empty=1; else for (bc=c-1; bc!=ba && isspace(*bc); ) { bc--; xx++; }
678                              if (ba==bc) empty=1;
679                              if (!empty) {
680                                for (p=ba; ; p++) { xen++; if (p==bc) break; }
681                                if (clean) {
682                                    int left=xen,n=0;
683                                    char *p=ba,*q=ba,x='\0';
684                                    while (left--)
685                                      if (x==' ' && *p==' ') { p++; n++; }
686                                      else
687                                      if (x=='.' && *p=='.') { p++; n++; }
688                                      else
689                                      { x= *p; if (p == q) { p++; q++; } else *q++ = *p++; }
690                                    xen-=n;
691                                }//clean
692                                //
693                              }//!empty
694                            }//d
695                        }//!closed
696
697                        while (xmlspec || hasattr || xen || ihtxen) {
698#if 01
699                            if (xmlspec || hasattr || xen >= min || ihtxen >= min) {
700#endif
701                                char *hdatp;
702                                LONGX litag=(parmvin)?parmvin:itag;
703                                if (ihtxen) {
704                                    //int xlev;
705                                    int xe;
706                                    char *iphp,*c2,k;
707                                    char *pp;   //par1 a
708                                    int qpcase; //case
709//
710                                    //execute /index@level:header,text
711                                    ba=iphbuff;
712                                    //copy headers
713                                    for (iphp=iphbuff, xlev=1; xlev<=level; xlev++) {
714                                      if (ihtlen[xlev]) { memcpy(iphp,ihtptr[xlev],ihtlen[xlev]); iphp+=ihtlen[xlev]; } else *iphp++='-';
715                                    //*iphp++='.'; *iphp++=' ';
716                                      *iphp++='|';
717                                    }
718                                    *iphp++='|';
719                                    *iphp='\0'; xen=strlen(iphbuff);
720                                    //copy text
721                                    c2=ihtba+ihtxen; k= *c2; *c2='\0'; //skip headers, search for .space
722
723                                    p=strstr(pp=ihtba,". ");           // Par1.   Par2.
724                                    while (isspace(*pp)) pp++;         // Par1.   Par2.
725                                    qpcase=0;                          // Par1.   Par2.
726                                    while (p) {                        // pp  p   qq  pq
727                                                                       // Aetc.   Aetc.
728                                                                       // Aetc.   12. Aetc
729                                      char *q;
730                                      char *qq; //par2 a
731                                      char *pq; //par2 b
732                                      int n=0;  //par1 lenght excluding .
733                                      int s=0;  //spaces before par2
734                                      int m=0;  //par2 lenght excluding .
735                                      int v=0;  //par2 starts with digits
736                                      int w=0;  //par2 is all digits, period and upper case letter
737//
738                                      for (q=pp;  q!=p;        q++) n++;
739                                      for (q=p+1; isspace(*q); q++) s++;
740                                      pq=strstr(qq=q,". ");
741                                      qpcase=0;
742                                      if (pq) qpcase=2; else for (; *q; q++) if (*q=='.' && !*(q+1)) { pq=q; qpcase=1; }
743                                      if (pq) for (q=p+1+s; q!=pq;       q++) m++;
744                                      if (pq) for (q=p+1+s; isdigit(*q); q++) v++;
745                                      if (v) if (*q=='.' && *(q+1)==' ') { q+=2; while (isspace(*q)) q++; if (isupper(*q)) w=v; }
746//
747                                      if (n<=3) {                      //par1 is too short - 1.
748                                         pp=qq; p=pq;
749                                         continue;
750                                      }
751                                      if (w && w<=2) {                 //par2 is 12. Aetc
752                                         break;
753                                      }
754                                      if (m) if (!isupper(*qq)) {      //par2 not Aetc     - E. coli
755                                         pp=qq; p=pq;
756                                         continue;
757                                      }
758                                      if (m<=3) {                      //par2 is too short - Tard A. O.
759                                         pp=qq; p=pq;
760                                         continue;
761                                      }
762                                      break;           //otherwise
763                                    }
764                                    *c2=k;
765#if 1
766                                    if (p) { *(p+1)='\0'; xe=strlen(ihtba); *(p+1)=' '; memcpy(iphp,ihtba,xe);    ihtba+=(xe+1);  ihtxen-=(xe+1); }
767                                    else   {              xe=ihtxen;                    memcpy(iphp,ihtba,xe);    ihtba=NULL;     ihtxen=0;       }
768#else
769                                    if (p) {
770                                      if (qpcase == 2)
771                                           { *(p+1)='\0'; xe=strlen(ihtba); *(p+1)=' '; memcpy(iphp,ihtba,xe);    ihtba+=(xe+1);  ihtxen-=(xe+1); }
772                                      else
773                                      if (qpcase == 1)
774                                           {              xe=strlen(ihtba);             memcpy(iphp,ihtba,xe);    ihtba+=(xe  );  ihtxen-=(xe  ); }
775                                      else
776                                           {              xe=ihtxen;                    memcpy(iphp,ihtba,xe);    ihtba=NULL;     ihtxen=0;       }
777                                    }
778                                    else   {              xe=ihtxen;                    memcpy(iphp,ihtba,xe);    ihtba=NULL;     ihtxen=0;       }
779#endif
780                                    if (xe) { //
781                                      char *pa=iphp,*pc=iphp+xe;
782                                      for (; pa!=pc && isspace(*pa); ) { pa++; xe--; }
783                                      if (pa==pc) xe=0; else for (; pc!=pa && isspace(*pc); ) { pc--; xe--; }
784                                      if (pa==pc) xe=0;
785                                      if (xe) {
786                                            int left=xe,n=0;
787                                            char *p=pa,*q=iphbuff+xen,x='\0';
788                                            while (left--)
789                                              if (x==' ' && *p==' ') { p++; n++; }
790                                              else
791                                              if (x=='.' && *p=='.') { p++; n++; }
792                                              else
793                                              { x= *p; if (p == q) { p++; q++; } else *q++ = *p++; }
794                                            xe-=n;
795                                      }//!empty
796                                    }//xe
797                                    xen+=xe;
798                                    if (!xe) xen=0; // no text to display
799                                }//end if ihtxen
800                                if (parmindex) if (!xen) break;
801
802                                if (colonspec) {
803                                    if (parmx) {
804                                      if (chunch2 < 6 || chunch2>=chunch1) chunch2=chunch1/2;
805                                      if (chunch3 < 6 || chunch3>=chunch1) chunch3=chunch1/3;
806                                      max=chunch1+chunch2;
807                                      if (hlen) {
808                                        if (closed) { if (hasattr)              hlen=0; }
809                                        else {        int xe=0;
810                                                      char *xep=ba;
811                                                      while (isdigit(*xep) || *xep=='.') { xep++; xe++; }
812                                                      if (xe>1) if (*xep==' ')  hlen=0;   //    - / n.n.
813                                                      if (xen      >  max    )  hlen=0;   //336 - / 224...112
814                                                      if (xen      >  chunch1)  hlen=0;   //224 - / xen
815                                        }
816                                        if (hlen) {
817                                          *hp++=' '; *hp++=' ';
818                                        }
819                                      }
820                                      if (hlen==0) {
821                                        hlenp=hp+11; sprintf(hp,"H%09"_LD_" 123456789 ",litag); hp+=strlen(hp); hdatp=hp;
822                                        if (parmfile) { sprintf(hp,"%s ",filename);                         hp+=strlen(hp); }
823                                        sprintf(hp,"%d %d: ",itag,iocc);                                    hp+=strlen(hp);
824                                        if (level) { //headers ptrs/code
825                                            sprintf(hp,"%d",ihtocc[1]); hp+=strlen(hp); for (xlev=2; xlev<=level; xlev++) { sprintf(hp,".%d",ihtocc[xlev]); hp+=strlen(hp); }
826                                            sprintf(hp,"||");                                               hp+=strlen(hp);
827                                        }
828                                        bpmovemax(ba,max,xen,1);  //336  //224
829                                      }
830                                      max+=3;
831                                    }
832                                    else {  //parse/index !parmx
833                                      hlenp=hp+11; sprintf(hp,"H%09"_LD_" 123456789 ",litag); hp+=strlen(hp); hdatp=hp;
834                                      //if (parmfile) { sprintf(hp,"%s%s%s%s%s ",filepath,filechar,filename,filedot,fileext);  hp+=strlen(hp); }
835                                      if (parmfile) { sprintf(hp,"%s ",filename);                         hp+=strlen(hp); }
836                                      for (p=xbuffer; ; p++) { if (*p=='|') break; *hp++ = *p; }  // ancestor
837                                      if (parmxlen) { sprintf(hp," %d.%d, %d,%d,%d,%d||",itag,iocc,xn,xb,xen,len);          hp+=strlen(hp); }
838                                      else          { sprintf(hp," %d.%d||"             ,itag,iocc              );          hp+=strlen(hp); }
839                                      if (level) { //headers ptrs/code
840                                            sprintf(hp,"%d",ihtocc[1]); hp+=strlen(hp); for (xlev=2; xlev<=level; xlev++) { sprintf(hp,".%d",ihtocc[xlev]); hp+=strlen(hp); }
841                                            sprintf(hp,"||");                                               hp+=strlen(hp);
842                                      }
843                                    } //end parmx
844                                } else { //xmlspec/!colonspec
845                                    hlenp=hp+11; sprintf(hp,"H%09"_LD_" 123456789 ",litag); hp+=strlen(hp); hdatp=hp;
846                                    if (parmxml) if (!xmlopened) {
847                                      sprintf(hp,"<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");     hp+=strlen(hp);
848                                      sprintf(hp,"<marx file=\"%s\" type=\"%s%s\" path=\"%s%s\">\n",filename,filedot,fileext,filepath,filechar);  hp+=strlen(hp);
849                                      xmlopened=1;
850                                    }
851                                    sprintf(hp,"<x a=\"");                                                  hp+=strlen(hp);
852                                    for (p=xbuffer; ; p++) { if (*p=='|') break; *hp++ = *p; } // ancestor
853                                    sprintf(hp," %d.%d\"",itag,iocc);                                      hp+=strlen(hp);
854                                    if (parmxlen) { sprintf(hp," b=\"%d,%d,%d,%d\"",xn,xb,xen,len);         hp+=strlen(hp); }
855                                    if (level) { //headers ptrs/code
856                                          sprintf(hp," c=\"");                                              hp+=strlen(hp);
857                                          sprintf(hp,"%d",ihtocc[1]); hp+=strlen(hp); for (xlev=2; xlev<=level; xlev++) { sprintf(hp,".%d",ihtocc[xlev]); hp+=strlen(hp); }
858                                          sprintf(hp,"\"");                                                 hp+=strlen(hp);
859                                    }
860                                    sprintf(hp,"/>"); hp+=strlen(hp);
861                                }
862
863                                if (colonspec) {
864                                  if (*colonspecp) {
865                                    for (q=colonspecp; *q; q++) {
866                                      if (*q == '&') {
867                                        char *p=q+1;
868                                        char *m;
869                                        if (isalpha(*p) || isdigit(*p)) {   //&name - attr char1
870                                          char bb[BUFSIZ];
871                                          char *aap=NULL;
872                                          char *aaq=NULL;
873                                          char k;
874                                          for (m=bb, *m=' '; isalpha(*p) || isdigit(*p); p++) { *m++= *p; q++; } *m++='='; *m++='"'; *m='\0';  //.attrname="
875                                          k= *b; *b='\0'; aap=strstr(a+1,bb); if (aap) aaq=strchr(aap+=strlen(bb),'"'); *b=k;
876                                          if (aaq) while (aap != aaq) *hp++ = *aap++;           //output attr contents
877                                        }
878                                        else {                              //& - element name, attrs, contents
879                                          for (  p=a+1,      m=p+xn;          p != m; p++) *hp++= *p;             //output element name
880                                          if (hasattr) { *hp++=' ';                                               //output
881                                            if (closed) for (p=a+1+xn+1, m=b-1/*closed*/; p != m; p++) *hp++= *p; //output all attrs
882                                            else        for (p=a+1+xn+1, m=b-0/*      */; p != m; p++) *hp++= *p; //output all attrs
883                                          }
884                                          if (xen) {
885                                            *hp++=' ';                                                            //output
886                                            //for (p=ba; xen--; p++) *hp++= *p;                                   //output all contents //
887                                            hpmovemax(hp,max,ba,xen);                                             //output all contents //
888                                          }
889                                        }// end if char1
890                                      } else {                              //. - spec char
891                                        *hp++ = *q;                                                               //output spec char
892                                      }//& or .
893                                      if (q==colonspecq) break;
894                                    }//end for
895                                  } //colonspecp
896                                  else { //colonspecp                       //: - contents
897                                      if (closed) { xen=len-3; ba=a+1; }
898                                      hpmovemax(hp,max,ba,xen);                                                   //: - output contents
899                                  } //colonspec
900                                } else { //colonspec
901                                    hpmovemax(hp,max,a,len);                                                      //: - output xml
902                                } //colonspec
903
904                                if (xmlopened) {
905                                  sprintf(hp,"</marx>\n");  hp+=strlen(hp);
906                                }
907                                //null hp string
908                                *hp='\0'; haddp=hp;
909
910                                //actual len
911                                hlen=strlen(hdatp); sprintf(hlenp,"%9"_LD_,(LONGX)hlen); hlenp[9]=' ';
912
913                                if (parmx) {
914                                        if (  hlen      >= chunch1         )    hlen=0;   //224 - /
915                                        if (!closed) if ( xen > chunch3 ) {               //75  - 75./
916                                                          if ( ba[xen-1]=='.' ) hlen=0;
917                                                          if ( ba[xen-1]==';' ) hlen=0;
918                                        }
919                                } // parmx
920
921                                //move forward ok
922                                if (d) x=d+1;
923
924                            } // end if xmlspec || hasattr || xen >= min || ihtxen >= min
925                            // else continues from x=b+1
926
927                            if (!ihtxen) break;
928
929                        } // end while xmlspec || hasattr ||xen || ihtxen
930
931
932                      } else { // else while <element..>
933
934                        x++;
935
936                      } // fi while <element..>
937
938                } // *xbuffer
939            } // xdir
940             } // parmparse
941
942         else  /* else parmparse */
943
944             if (parmsocket) {            /* ./mx null "proc='Gload/socket=http://www.bireme.br:80/'" */
945
946            /* scan <url>
947            */
948            protocol="HTTP";
949            q=strstr(p=urlp,"://"); /* http:// */
950            if (q) {
951                char *x;
952                int len;
953                *q='\0'; len=strlen(p);
954                if (len < 8) {
955                  protocol=p;                                                    /* http | x1417*/
956                  for (x=p; *x; x++) *x=toupper(*x);
957                  p=q+3;
958                }
959                else *q=':';
960            }
961
962            serverhost=p;                                                       /* www.bireme.br | serverofi.bireme.br */
963
964            pathp=strchr(p+1,'/');                                           /* /path | /dbname/parms */
965            if (pathp) *pathp='\0';
966            else pathp="/";
967
968            port=80;                          /* :80 */
969            q=strchr(p,':');
970            if (q) {
971                *q='\0';
972                if (sscanf(q+1,"%d",&xport) == 1) port=xport;                   /* :80 | :1417 */
973                else xport=0; /*fatal("fldupdat/procx/Gload/socket/port");*/
974            }
975
976            /* X1417://serverofi.bireme.br:1417/msg
977                                               /dbname/control/maxmfn
978                                               /dbname/text/mfn/mfn2/count/step
979                                               /dbname/dict/key/key2/contains/count
980                                               /dbname/bool/expression
981                                               /dbname/rank/text
982            */
983            if (strcmp(protocol,"X1417") == 0) {
984                maxrds=1;                                                        /* single read */
985                if (!xport) port=1417;     /* :1417 */
986            }
987
988            msgp=hdatap;
989            *msgp='\0';
990            if (strcmp(protocol,"X1417") == 0) {
991                sprintf(msgp,"%s\n",pathp+1);
992            }
993            else
994            if (strcmp(protocol,"HTTP") == 0) {
995                sprintf(msgp,"%s /%s HTTP/1.0\r\n\r\n",(parmhead)?"HEAD":"GET",pathp+1);
996            }
997
998            if (*msgp) rc = mainclient ( parmcmd, protocol, serverhost, port, msgp, hdatap, nbytes-strlen(xarea), maxrds);
999
1000             }
1001
1002
1003//#define DIR_FILE 1                  /* list=directory */
1004//#if DIR_FILE
1005//#include <sys/types.h>
1006//#include <dirent.h>
1007//#endif
1008    /* ............................................... directory listing */
1009#if DIR_FILE
1010         else   /* else parmsocket: <file> */
1011             if (strncmp(filnamp,"dir=",4)==0) {
1012                DIR *direntdp=NULL;
1013                struct dirent *direntep;
1014                char *directory=filnamp+4;
1015                rc=0;
1016                direntdp = opendir (directory);
1017                if (direntdp != NULL) {
1018                    int n;
1019                    while ((direntep = readdir (direntdp)) != NULL) {
1020                        strcpy(hdatap,direntep->d_name); 
1021                        n=strlen(direntep->d_name); *(hdatap+=n)='\n'; *++hdatap='\0'; rc+=(n+1);
1022                    }
1023                    (void) closedir (direntdp);
1024                }
1025                //else fatal("Couldn't open the directory");
1026             }   
1027#endif
1028
1029         else { /* else parmsocket: <file> */
1030
1031             rc = mainfile ( parmcmd, filnamp, parm0, parm1, hdatap, nbytes-strlen(xarea) );
1032
1033             } /* end parmsocket */
1034
1035
1036
1037        if (isload) {
1038            if (rc < 0) {
1039                sprintf(hdatap,"Gload%s error %d",parmsocket?"/socket":"",(-rc));
1040                hlen=strlen(hdatap);
1041            }
1042            else hlen=rc;
1043
1044            if (hlen) {
1045                /* actual add lenght */
1046                sprintf(hlenp,"%9"_LD_,(LONGX)hlen); hlenp[9]=' ';
1047                /* print */
1048                //if (parmprint) fprintf(parmfp,"%s",hdatap);
1049            }
1050            else if (haddp) *haddp='\0';
1051        }
1052
1053        //else printf("%s\n",xarea);
1054
1055#if CICPP
1056        if (recp->xfldupdat(xarea)) fatal(errp);
1057        delete xarea;
1058        delete xbuffer;
1059#else /* CICPP */
1060//printf("antes do fldupdat\n");
1061        if (fldupdat(irec,xarea)) fatal(errp);
1062//printf("depois do fldupdat\n");
1063        if (xarea) FREE(xarea);
1064        if (xbuffer) FREE(xbuffer);
1065#endif /* CICPP */
1066
1067        return NULL; //isgdump=1;
1068
1069        }  /* end Gload/socket */
1070        else
1071
1072#endif /* PROCXSOCKREC */
1073/* End PROCXSOCKREC
1074*/
1075
1076#if INDEXAT
1077                                            for (xlev=1; xlev<=level; xlev++) {
1078                                              char *p=ihtpta[xlev]+1;
1079                                              int n=ihtpla[xlev]-1;
1080                                              *hp++='/';
1081                                              while (n) if (*p==' ' || *p=='/' || *p=='>') break; else { *hp++ = *p++; n--; }
1082                                              if (*p==' ') { p++; n--; }
1083                                              *hp++='@';
1084                                              n--; if (closed) n--;
1085                                              memcpy(hp,p,n); hp+=n;
1086                                              *hp++='|';
1087                                            }
1088#endif
Note: See TracBrowser for help on using the browser.