root/tags/5.52/mxaot.c

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

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

Line 
1/* ------------------------------ mxaot.c ---------------------------------- */
2
3#include <stdio.h>
4#include <ctype.h>
5#include <string.h>
6
7#if CIAPI
8#include "ciapi.h"
9#else /* CIAPI */
10#include "cisis.h"                  /* CISIS Interface header file */
11#endif /* CIAPI */
12
13#include "mx.h"                     /* MX Program header file */
14
15#define DIR_FILE 1                  /* list=directory */
16#if DIR_FILE
17#include <sys/types.h>
18#include <dirent.h>
19#endif
20
21#define XML_FILE 1                  /* xml=file,tag */
22#if XML_FILE
23    char tagName[64];
24
25    char * findTag(char     *in,       /* input string */
26                   char     *tagName,  /* tag name */
27                   int      *type,     /* -1-unknown 0-open 1-close 2-openclose */
28                   unsigned *len) {    /* tag length including < and > */
29
30        char *initPos = NULL;
31        char *curPos = in;
32        int tagLen;
33
34        *type = -1; /* unknown */
35        *len = 0;
36
37        if (tagName != NULL) {
38            tagLen = strlen(tagName);
39            while (curPos != NULL) {
40                curPos = strchr(curPos, '<');
41                if (curPos != NULL) {
42                    initPos = curPos;
43                    curPos++;
44                    if (*curPos == '/') {
45                        *type = 1; /* close */
46                        curPos++;
47                    }
48                    if (strncmp(curPos, tagName, tagLen) == 0) {
49                        curPos += tagLen;
50                        if ((*curPos == ' ') || (*curPos == '/') || (*curPos == '>')) {
51                            while ((*curPos != '\0') && (*curPos == ' ')) {
52                                curPos++;
53                            }
54                            while ((*curPos != '\0') && (*curPos != '/') && (*curPos != '>')) {
55                                curPos++;
56                            }
57                            if (*curPos == '/') {
58                                *type = 2; /* openclose */
59                                curPos++;
60                            }
61                            if (*curPos == '>') {
62                                if (*type == -1) {
63                                    *type = 0; /* open */
64                                }
65                                break;
66                            }
67                        }
68                    }
69                    initPos = NULL;
70                    *type = -1;
71                }
72            }
73            if (curPos != NULL) {
74                 *len = curPos - initPos + 1;
75            }
76        }
77
78        return initPos;
79    }
80
81int recfgetxml(char *xmlfile, char *ibuf, unsigned ibufsiz, char *obuf, unsigned obufsiz, char *ubuf, unsigned ubufsiz, int *fdp, unsigned *n1p, char **iptrp, LONGX *countp);
82
83int recfgetxml(char *xmlfile, char *ibuf, unsigned ibufsiz, char *obuf, unsigned obufsiz, char *ubuf, unsigned ubufsiz, int *fdp, unsigned *n1p, char **iptrp, LONGX *countp)
84{
85    int fd=fdp[0];
86    unsigned n1=n1p[0];
87    char *iptr=iptrp[0];
88    LONGX count=countp[0];
89    char *batchp = ubuf;
90    unsigned ubu=ubufsiz-20;
91    unsigned j=0;  /* indice em obuf */
92    int eol=0;
93    int rc=0;
94    int insideTag = 0;
95    int newInstance = 0;
96    int closeFound = 0;
97    int type;
98#if PC
99    int nlSize = 2;
100#else
101    int nlSize = 1;
102#endif
103
104    *ubuf='\0';                                            // null update comand
105
106    if (!iptr) {                                           // close/open file
107        if (fd) CLOSE(fd);
108        dbxopt_fatal=0; fd=dbxopen(NULL,xmlfile,NULL);
109        if (fd < 0) return(fd);
110        n1=0; iptr=""; //force read
111        rc=fd;
112    }
113
114    /* read lines
115    */
116    if (obufsiz) {
117        while (1) {
118            char *jptr;
119            unsigned jn=0;
120            if (n1 == 0) {                                 // le buffer
121                n1=read(fd,ibuf,ibufsiz-1);
122                if (n1 <= 0) {  // if (j) ;
123                    rc=EOF; break;                         // EOF
124                }
125                ibuf[n1]='\0';
126                iptr=ibuf;
127            }
128            jptr=iptr;
129#if PC
130            while (n1 && *iptr != '\r') { jn++; iptr++; n1--; }
131            if (*iptr == '\r') { iptr++; n1--; }
132#else
133            while (n1 && *iptr != '\n') { jn++; iptr++; n1--; }
134#endif
135            if (*iptr == '\n') { iptr++; n1--; eol=1; }
136            if (jn) {
137                if (j+jn >= obufsiz) jn=(obufsiz-1)-j;
138                memcpy(obuf+j,jptr,jn); j+=jn;
139            }
140            if (eol) {
141                char *p,*p0;
142                unsigned len,bk;
143                count++;
144
145                obuf[j]='\0';
146                p0=p=obuf;
147                p = findTag(p, tagName, &type, &len);
148                if (insideTag) {
149                    if (p == NULL) {
150                        len = strlen(p0);
151                    } else {
152                        if (type != 1) { /* close */
153                            fatal("nested tag not supported");
154                        }
155                        p += len;
156                        insideTag = 0;
157                        closeFound = 1;
158                        len = p - p0;
159                        if (*p != '\0') {
160                            bk = (unsigned)((obuf + j) - p + nlSize);
161                              if (bk > nlSize) {
162                                iptr -= bk;
163                                n1 += bk;
164                            }
165                        }
166                    }
167                } else {
168                    if (p == NULL) {
169                        len = 0;
170                    } else {
171                        if (type == 0) { /* open */
172                            p0 = p;
173                            p += len;
174                            insideTag = 1;
175                            newInstance = 1;
176
177                            p = findTag(p, tagName, &type, &len);
178                            if (p == NULL) {
179                                len = strlen(p0);
180                            } else {
181                                if (type != 1) { /* close */
182                                    fatal("nested tag not supported");
183                                }
184                                p += len;
185                                insideTag = 0;
186                                closeFound = 1;
187                                len = p - p0;
188                                if (*p != '\0') {
189                                    bk = (unsigned)((obuf + j) - p + nlSize);
190                                    if (bk > nlSize) {
191                                        iptr -= bk;
192                                        n1 += bk;
193                                    }
194                                }
195                            }
196                        } else if (type == 2) { /* openclose */
197                            p0 = p;
198                            p += len;
199                            insideTag = 0;
200                            newInstance = 1;
201                            closeFound = 1;
202                            if (*p != '\0') {
203                                bk = (unsigned)((obuf + j) - p + nlSize);
204                                if (bk > nlSize) {
205                                    iptr -= bk;
206                                    n1 += bk;
207                                }
208                            }
209                        } else {
210                            fatal("invalid tag");
211                        }
212                    }
213                }
214                if (len) {
215                    if (newInstance) {
216                        if (ubu <= 7) fatal("ubu <= 7");
217                        sprintf(batchp,"d1<1 0>"); batchp+=7;
218                        ubu-=7;
219                        newInstance = 0;
220                    }
221
222                    if (len >= ubu) fatal("len >= ubu");
223                    memcpy(batchp,p0,len); batchp+=len;
224                    ubu-=len;
225
226                    if (closeFound) {
227                        if (ubu <= 4) fatal("ubu <= 4");
228                        sprintf(batchp,"</1>");
229                        batchp+=4;
230                        ubu-=4;
231                    } else {
232#if PC
233                        if (ubu < 1) fatal("ubu < 1");
234                        sprintf(batchp,"\r"); batchp+=1;
235                        ubu-=1;
236#endif
237                        if (ubu < 1) fatal("ubu < 1");
238                        sprintf(batchp,"\n"); batchp+=1;
239                        ubu-=1;
240                    }
241                } else if (insideTag) {
242#if PC
243                    if (ubu < 1) fatal("ubu < 1");
244                    sprintf(batchp,"\r"); batchp+=1;
245                    ubu-=1;
246#endif
247                    if (ubu < 1) fatal("ubu < 1");
248                    sprintf(batchp,"\n"); batchp+=1;
249                    ubu-=1;
250                }
251                if (closeFound) {
252                    rc=1; break;
253                } else {
254                    j=0;
255                }
256            } //end if eol
257        } // end while
258    } // end if obufsiz
259
260    /* save
261    */
262    fdp[0]=fd;
263    n1p[0]=n1;
264    iptrp[0]=iptr;
265    countp[0]=count;
266
267    return rc;
268}
269#endif /* XML_FILE */
270
271/* ------------------------------ fxl0.c ---------------------------------- */
272//int read(int handle, void *buf, unsigned len);
273//The maximum number of bytes that read can read is UINT_MAX -1, because UINT_MAX is the same as -1, the error return indicator.
274//On successful completion, read returns an integer indicating the number of bytes placed in the buffer.
275//On end-of-file, read returns 0. On error, read returns -1 and sets the global variable errno to one of the following values:
276
277int recfgetseq(char *seqfile, char c, int parmseqlog, char *ibuf, unsigned ibufsiz, char *obuf, unsigned obufsiz, char *ubuf, unsigned ubufsiz, int *fdp, unsigned *n1p, char **iptrp, LONGX *countp);
278
279int recfgetseq(char *seqfile, char c, int parmseqlog, char *ibuf, unsigned ibufsiz, char *obuf, unsigned obufsiz, char *ubuf, unsigned ubufsiz, int *fdp, unsigned *n1p, char **iptrp, LONGX *countp)
280{
281    int fd=fdp[0];
282    unsigned n1=n1p[0];
283    char *iptr=iptrp[0];
284    LONGX count=countp[0];
285
286    unsigned j=0;  /* indice em obuf */
287    int eol=0;
288    int rc=0;
289
290    if (!c) c='|';                                         // default dlm
291    *ubuf='\0';                                            // null update comand
292
293    if (!iptr) {                                           // close/open file
294        if (fd) CLOSE(fd);
295        dbxopt_fatal=0; fd=dbxopen(NULL,seqfile,NULL);
296        if (fd < 0) return(fd);
297        n1=0; iptr=""; //force read
298        rc=fd;
299    }
300
301    /* read lines
302    */
303    if (obufsiz) {
304        while (n1 >= 0) {
305            char *jptr;
306            unsigned jn=0;
307            if (n1 == 0) {                                 // le buffer
308                n1=read(fd,ibuf,ibufsiz-1);
309                if (n1 <= 0) {  // if (j) ;
310                    rc=EOF; break;                         // EOF
311                }
312                ibuf[n1]='\0';
313                iptr=ibuf;
314            }
315            jptr=iptr;
316    #if PC
317            while (n1 && *iptr != '\r') { jn++; iptr++; n1--; }
318            if (*iptr == '\r') { iptr++; n1--; }
319    #else
320            while (n1 && *iptr != '\n') { jn++; iptr++; n1--; }
321    #endif
322            if (*iptr == '\n') { iptr++; n1--; eol=1; }
323            if (jn) {
324                if (j+jn >= obufsiz) jn=(obufsiz-1)-j;
325                memcpy(obuf+j,jptr,jn); j+=jn;
326            }
327            if (eol) {
328                int tag=1;
329                char *p,*p0,*batchp;
330                unsigned len,u,ubu=ubufsiz-20;
331                count++;
332                obuf[j]=c; obuf[j+1]='\0';
333                for (batchp=ubuf, p=obuf; *p; p++, tag++) {
334                    p0=p; p=strchr(p0,c); if (p) *p='\0'; len=strlen(p0);
335                    if (len) {
336                        if (len >= ubu) len=0;
337                        sprintf(batchp,"H%d %d ",tag,len); batchp+=(u=strlen(batchp));
338                        memcpy(batchp,p0,len+1); batchp+=len;
339                        ubu-=(u+len);
340                    }
341                }
342                rc=1; break;
343            } //end if eol
344        } // end while
345    } // end if obufsiz
346
347    /* save
348    */
349    fdp[0]=fd;
350    n1p[0]=n1;
351    iptrp[0]=iptr;
352    countp[0]=count;
353
354    return rc;
355
356    //if (j != 0) erro("ultimo registro nao tem LF em ",seqfile);
357    //exit(0);
358}
359
360#if 0
361erro(s1,s2)     /* imprime mensagem de erro e morre */
362char *s1,*s2;
363{
364    fprintf(stderr,
365        "mx: %s%s\n",s1,s2);
366    breakout();
367    exit(1);
368}
369
370writbsiz()                                                          /*
371---------                                                           */
372{
373    int n2;
374    unsigned char *p,*q;
375    int loop;
376
377    if (n2free >= obufsize) {
378        memcpy(bufout+i2free,obuf,obufsize);
379        n2free-=obufsize;
380        i2free+=obufsize;
381    }
382    else {
383        memcpy(bufout+i2free+,obuf,n2free);
384        n2=write(f2,bufout,MBUFSIZ);
385        if (n2 < MBUFSIZ) erro("writbsiz - ","erro na gravacao");
386        i2free=obufsize-n2free;
387        memcpy(bufout,obuf+n2free,i2free);
388        n2free=MBUFSIZ-i2free;
389    }
390}
391
392breakout()                                                      /*
393---------                                                       */
394{
395    int n2;
396    if (i2free) if (f2) {
397        n2=write(f2,bufout,i2free);
398        if (n2 < i2free) {
399            fprintf(stderr,"breakout - erro na gravacao\n");
400        exit(1);
401    }
402    }
403}
404
405                                                                /*
406---------                                                       */
407#endif //0
408
409
410
411
412
413void mxsyntax(char *x, unsigned xibufsiz, LONGX xptabcategories, int xptabwidth);
414void mxsyntax(x, xibufsiz, xptabcategories, xptabwidth)
415char *x;
416unsigned xibufsiz;
417LONGX xptabcategories;
418int xptabwidth;
419{
420        printf("%s",cicopyr("Utility MX"));
421        printf("\n");
422        printf("mx ");
423#if CIPAR
424        printf("[cipar=<file>] ");
425#endif
426        printf("[{");
427#if OPEN30
428        printf("files|");
429#endif
430#if BEFORE20060120
431        printf("mfrl|fmtl|load}=<n>] [cgi={mx|<v2000_fmt>}] \n");
432#else
433        printf("mfrl|load}=<n>] [cgi={mx|<v2000_fmt>}] [in=<file>] \n");
434#endif
435        printf(" %s{[db=]<db>| \n",x);
436/*
437        printf(" %s seq[/blk:%ld/fi:<x>]=<file>| \n",x,(LONGX)xibufsiz);
438*/
439        printf(" %s seq[/%ldm]=<file>[<fldDelim>]| \n",x,(LONGX)xibufsiz);
440#if DIR_FILE
441        printf(" %s list={./|<dir>}| \n",x);
442#endif
443#if XML_FILE
444        printf(" %s xml[/%ldm]=<file>,<element>| \n",x,(LONGX)xibufsiz);
445#endif
446        printf(" %s iso[={marc|<n>}]=<isofile> [isotag1=<tag>]| \n",x);
447        printf(" %s dict=<if>[,<keytag>[,<posttag>[/<postsperrec>]]] [k{1|2}=<key>]} \n",x);
448        printf(" \n");
449        printf("options: \n");
450        printf(" %sfrom|to|loop|count|tell|btell=<n> \n",x);
451        printf(" %stext[/show]=<text> \n",x);
452        printf(" %s[bool=]{<bool_expr>|@<file>}  ",x);
453#if INVXBOOL
454        printf("[invx=<tag%d_mf>] ",MFQTXTAG);
455#endif
456#if CIB71
457        printf("[tmpx=<tmp_mf>] ");
458#else /* CIB71 */
459#if LIND || CIB64
460        printf("[tmpx=<tmp_mf>] ");
461#else
462        printf("[tmpx=<tmp_mf>] ");
463#endif
464#endif /* CIB71 */
465        printf(" \n");
466        printf(" \n");
467#if RECXPND
468        printf(" %sgetdir=<tag>,<dlm> \n",x);
469#endif
470#if RECGIZM
471        printf(" %sgizmo=<gizmo_mf>[,<taglist>]  ",x);
472#if MXGIZP
473        printf("[gizp[/h]=<out_mfx>] ");
474#endif
475#if RECDECO
476        printf("[decod=<mf>]");
477#endif
478#else /* RECGIZM */
479#if RECDECO
480        printf(" decod=<mf>");
481#endif
482#endif /* RECGIZM */
483        printf(" \n");
484        printf(" \n");
485        printf(" %sjoin=<mf>[:<offset>][,<taglist>]=<mfn=_fmt>\n",x);
486        printf(" %sjoin=<db>[:<offset>][,<taglist>]=<upkey_fmt>",x);
487        printf(" [jmax=<n>]\n");
488        printf(" %sjchk=<if>[+<stwfile>]=<upkey_fmt>",x);
489        printf(" \n");
490#if SHOWJDICMD || 0
491        printf(" %sjdi[/<options>]=<db>=<jdi_fmt>\n",x);
492        printf(" %s    /lines:1000/width:60\n",x);
493        printf(" %s    /tab:2/occ:30\n",x);
494        printf(" %s    /wmin:0.05/vmin:0.05/nmin:2\n",x);
495        printf(" %s    /sort:{w|v|n}{1|2|3}\n",x);
496        printf(" %s    /top:10\n",x);
497        printf(" %s    /55\n",x);
498        printf(" %s    /show\n",x);
499        printf(" \n");
500#endif
501        printf(" %sproc=[<proc_fmt>|@<file>] \n",x);
502/*
503        case 'X': ok
504        case 'F':
505        case 'Z':
506        case 'Y':
507        case 'T':
508        case 'C':
509*/
510        printf(" \n");
511        printf(" %s      D{<tag>[/<occ>]|*} \n",x);
512        printf(" %s      A<tag><delim><data><delim> \n",x);
513        printf(" %s      H<tag> <length> <data> \n",x);
514        printf(" %s      <TAG[ <stripmarklen>[ <minlen>]]><data></TAG> \n",x);
515        printf(" \n");
516        printf(" %s      S[<tag>] \n",x);
517        printf(" %s      R<mf>,<mfn> \n",x);
518        printf(" %s      G<gizmo_mf>[,<taglist>] \n",x);
519        printf(" %s      Gsplit[/clean]=<tag>[={<char>|words|letters|numbers|trigrams}] \n",x);
520//        printf(" %s      Gsplit[/clean]=<tag>[={<char>|words|letters|numbers}] \n",x);
521//        printf(" %s      Gsplit=<tag> \n",x);
522//        printf(" %s      Gsplit=<tag>={trigrams|wtrig} \n",x);
523        printf(" %s      Gsplit=<tag>=6words[/if=<if>] \n",x);
524#if GCC
525        printf(" %s      Gload[/<tag>][/nonl][/xml][/socket][/head][={<url>|<file>|dir=<dir>}]\n",x);
526#else
527        printf(" %s      Gload[/<tag>][/nonl][=<file>] \n",x);
528#endif
529        printf(" %s      Gmark[/<tag>]{/<elem>|/keys|/decs|/<mf>,<otag>[,<ctag>]}=<if> \n",x);
530        printf(" %s      Gmarx[/<tag>]/<elem>[@<att>=\"x\"] =<tag>[:&[<att>]|/c[=224]|/i]\n",x);
531        printf(" %s      Gdump[/<tag>][/nonl][/xml][=<file>] \n",x);
532#if PROCXSLT
533        printf(" %s      Gxsl[#<rec_mode>][/<tag>|:<file>]=[[@]<xsl_spec>] \n",x);
534#endif /* PROCXSLT */
535        printf(" %s      =<mfn> \n",x);
536        printf(" %s      X[append=]<mf> \n",x);
537/*
538        printf(" %s      Gport[/<tag>][=<port>] \n",x);
539        printf(" %s      Gdump[/<tag>][/x]{/socket=<url>|=<file>} \n",x);
540*/
541        printf(" \n");
542#if MXFST
543        printf(" %sconvert=ansi [uctab={<file>|ansi}]         [actab={<file>|ansi}] \n",x);
544        printf(" %sfst[/h]={<fst>|@[<file>]}                  [stw=@[<file>]] \n",x);
545#endif
546#if RECXPND
547        printf(" %sputdir=<tag>,<dlm> \n",x);
548#endif
549        printf(" \n");
550        printf(" %s",x);
551#if MULTI
552        printf("[mono|mast|full] ");
553#endif
554        printf("{create|copy|append|merge|updatf}=<out_mf> \n");
555        printf(" %s[out]iso[={marc|<n>}]=<out_isofile>        [outisotag1=<tag>] \n",x);
556#if LIND
557#if MXFULLINV
558        printf(" %sfullinv[/dict][/keep][/ansi]=<out_if>      [maxmfn=<n>|master=<mf>] \n",x);
559#endif
560#else /* LIND */
561#if BEFORE20060711
562#if MXIFUPD
563#if MXFULLINV
564        printf(" %s{ifupd[/create][/dict]|fullinv[/dict][/m][/ansi]}=<out_if> [-reset] \n",x);
565#else
566        printf(" %sifupd[/create][/dict]=<out_if> \n",x);
567#endif
568#endif //BEFORE20060711
569#else /* MXIFUPD */
570#if MXFULLINV
571        printf(" %sfullinv[/dict][/m][/ansi]=<out_if> [-reset] \n",x);
572#endif
573#endif /* MXIFUPD */
574#endif /* LIND */
575        printf(" %sln{1|2}=<out_file>                         [+fix[/m]] \n",x);
576        printf(" %sfix=<out_file> tbin=<tag> \n",x);
577#if SHOWTABCMD || 1
578        printf(" %stab[/lines:%ld/width:%ld/tab:<tag>]=<tab_fmt> \n",x,(LONGX)xptabcategories,(LONGX)xptabwidth);
579#endif
580        printf(" %sprolog|pft|epilog={<diplay_fmt>|@<file>}   [lw={<n>|0}] [pftout=<file>]\n",x);
581        printf(" \n");
582        printf(" %s{+|-}control|leader|xref|dir|fields|all    [now] [mfrl] \n",x);
583        printf(" \n");
584}
585
586
587#if MXFUN
588int cisis_mx(stringp)
589char *stringp;
590{
591#define MAXARGS1 512
592    int argc=0;
593    char *argv[MAXARGS1+1];
594    char *p,*q,c1,c2;
595    int strip;
596    int rc;
597    for (argv[argc++]="mx", p=stringp; *p; ) {
598        while (isspace(*p)) p++;
599        c1='\r'; c2='\n'; if (*p == '"') { p++; c1=c2='"'; }
600        argv[argc++]=p;
601        for (strip=0, q=p; *p; ) {
602            if (*p == c1) { *p++='\0'; if (*p == c2) p++; break; }
603            if (*p == c2) { *p++='\0'; if (*p == c1) p++; break; }
604            /* if (*p == '\\') p++; dbn... */
605            if (*p) { *q++ = *p++; strip++; }
606        }
607#if BEFORE401R2 /* because (still) need keep trailing space in "seq=x " */
608        if (c1 != '"') while (strip--) if (isspace(*(q-1))) q--; else break;
609#endif
610        *q='\0';
611    }
612    argv[argc]=NULL;
613    rc=mxexec(argc,argv);
614    return(rc);
615}
616#endif /* MXFUN */
617
618
619#if MXFUN
620#define FATLOCK {                           \
621        fprintf(stderr,                     \
622        "*** record %s#%ld is been update by another user!\n",  \
623        VRDBname(upcrec),MFRmfn);               \
624        mxexit(xmxp,1); /* DELOCK/EWLOCK */             \
625       return(1);                                     \
626    }
627#else /* MXFUN */
628#define FATLOCK {                           \
629        fprintf(stderr,                     \
630        "*** record %s#%ld is been update by another user!\n",  \
631        VRDBname(upcrec),MFRmfn);               \
632        mxexit(xmxp,1); /* DELOCK/EWLOCK */             \
633    }
634#endif /* MXFUN */
635
636#if MXFUN
637#define MXEXIT(rc) { mxexit(xmxp,rc); /* DELOCK/EWLOCK */ return(rc); }
638#else /* MXFUN */
639#define MXEXIT(rc)   mxexit(xmxp,rc); /* DELOCK/EWLOCK */
640#endif /* MXFUN */
641
642#if BEFORE20000323           /* because some BRM's GCC - ask rpiva */
643extern FILE *cistderr;  /* 20/05/98 (Asael!) */
644#else
645#define cistderr stderr
646#endif
647
648/* function mxexec(argc,argv) derived from the original mx.c source code
649
650   - declares xmxp and mxinit it
651   - uses xmxp as 1st parm of call all mx functions
652   - #if MXFUN then uses MXFUN_XMX struct and mxrun.h #defines
653
654   AOT, 21/02/2001
655*/
656
657int mxexec(argc,argv_1)
658int argc;
659char *argv_1[];
660
661{
662#if CIAPI
663#if !MXFUN
664    void *ciapip = NULL;
665#endif /* !MXFUN */
666#endif /* CIAPI */
667
668    void *xmxp; /* mandatory for #defines in mxrun.h (#if !MXFUN) */
669
670    RECSTRU *recp; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */
671
672
673    //char *seqfile;     // seq= using recfgetseq()
674    int parmseqlog=0;    // recfgetseq
675    char *ibuf;          // input buffer
676    unsigned ibufsiz=1*1024*1024;    // dedicated 1Mbyte-buffer
677    char *obuf;          // line buffer
678    unsigned obufsiz;
679    char *ubuf;          // fldupdat buffer
680    unsigned ubufsiz;
681    int n1fdseq=0;       // file descriptor
682    int n1fdxml=0;       // file descriptor
683    unsigned n1left=0;   // bytes left
684    char *n1iptr=NULL;   // next char
685    LONGX n1count=0;      // lines read
686
687    int parmtabtg=0;     // parmtabula
688
689#define TB        1
690#define TBISNEW   0
691
692#if TB
693    int ntagbin=0;
694    UWORD vtagbin[MAXTBIN];
695    UWORD tagbin;
696    int itagbin;
697    int fdtagbin;
698#endif /* TB */
699
700    char *dbnp=NULL;
701    LONGX crec,irec,mfn;
702
703    char *p,*q,parmxseq,*isxp=NULL;
704    int i,n,xfd;
705    int level,jchk;
706    int isfix,lrfix,isfox,lrfox;
707    unsigned int parmisildrtag=0;
708    unsigned int parmisoldrtag=0;
709
710#define MXCOMMENT 1
711#if MXCOMMENT
712    int incomment=0;
713#endif
714
715    int argnext=1;
716    LONGX nbytes,maxmfrl=MAXMFRL;
717    char *parmtextp=NULL;
718    char *parmsysp=NULL;
719    char *parmsysa=NULL;
720    int parmsyss=0;
721    char *shp;
722
723    UWORD utag;
724    int xdir;
725    UCHR *batchp;
726
727    int parmcontrol=0,parmleader=0,parmxref=0,parmdir=0,parmfields=1;
728    LONGX parmfrom=0,parmto=0,parmloop=1,parmcount=LONGX_MAX,count=0;
729    LONGX countdict1002=LONGX_MAX;
730    int parmwait=1;
731    int parmhits=0;
732    LONGX /*UWORD*/ parmmfrl=0;
733    int minus1=0,plus1=0;
734    LONGX ld;
735
736#if INVXBOOL
737    int loop;
738    LONGX irecx;
739#endif
740
741#if RECGIZM
742    VGIZPSTRU *gizmap;
743#endif
744
745#if MXIFUPD
746    int ifcreate=0;
747    DBXSTRU *ifndbxp;
748#endif
749
750#if MXIFUPD || MXFULLINV
751    char *parmmaster=NULL;
752    int parmmenosreset=0;
753#endif
754
755#if MXFST
756    int parmfstup=1;
757    LONGX qtylk1,qtylk2;
758#endif
759
760#if IFUPDATE
761    LONGX brec=0L;
762    int parmmfbw=0;
763#endif
764
765    char *mi_gidbnp=NULL;               /* dbn.par */
766
767    int parmoutmfntag=0;                /* multiple output records, accorging pft= */
768
769    char *parmkdbnp=NULL;
770    char *parmk1p=NULL;
771    char *parmk2p=NULL;
772    char  parmk2a[LE2+1];
773    UWORD parmktag1=1;
774    UWORD parmktag2=2;
775    int parmkpostings=0;
776    LONGX parmkkeep2=LONGX_MAX;
777    LONGX parmkcount=0L;
778    int xgo;
779
780/* iso=mark= */
781    int ismarc=0;
782    unsigned char parmisoxfs=ISOXFS;
783    unsigned char parmisoxgs=ISOXGS;
784
785/* convert= */
786    unsigned char *tabconvp=NULL;
787
788    LONGX itrm;
789    LONGX itrm2;
790    TRMSTRU *trmp=NULL;
791    TRMSTRU *trmp1=NULL;
792    TRMSTRU *trmp2=NULL;
793    int xti;
794    char *xtp;
795    LONGX xtl1,xtl2;
796
797//AOT, 09/12/2008
798/* tab/ jdi:<tempesos_db>= */
799#define JDISORTW1 1
800#define JDISORTW2 2
801#define JDISORTW3 3
802#define JDISORTV1 4
803#define JDISORTV2 5
804#define JDISORTV3 6
805#define JDISORTN1 7
806#define JDISORTN2 8
807#define JDISORTN3 9
808
809    char    *parmtabjdip=NULL;
810    long     jdiclass=1000;   /*xptabcategories/3;*/
811    int      jdiwidth=LE2;    /*xptabwidth;*/ 
812    long     jditabtg=2;
813    long     jditaboc=30;
814    int      jdisort=JDISORTW1;
815    int      jdisstop=10;
816    int      jdipshow=0;
817    int      jdiadd55=55;
818    int      jdiaddfm=2;
819    float    jdisminw=0.05;
820    float    jdisminv=0.05;
821    long     jdisminn=2;
822
823    char    *jditable=NULL;
824    LONGX    jdicategories;
825    LONGX    jdimaxprim;
826
827    float    jditotalw=0.0;
828    float    jditotalv=0.0;
829    long     jditotaln=0;
830    long     jdintabs=0;
831    float   *jdiSUM0w=NULL;  /* n(t) */
832    float   *jdiSUM0v=NULL;  /* n(t) */
833    long    *jdiSUM0n=NULL;  /* n(t) */
834    long    *jdiFREQ1=NULL;  /* n(t) */
835
836    char    *jdiSBUF=NULL;   /* sort keys area */
837    long    *jdiSBUH=NULL;   /* sort hidx area */
838    char    *jdiSBUFx=NULL;  /* sort tmp key  */
839    int      jdislen=0;   /* 9+jdiwidth+1  */
840
841    RECSTRU *jdirecp=NULL;
842    TRMSTRU *jditrmp=NULL;
843#if CICPP
844#else /* CICPP */
845    long     jdirec_prat=(-1L);
846    long     jditrm_prat=(-1L);
847#endif /* CICPP */
848
849    FMT_CODE *jdipgmp=NULL;
850    char     *jdifmtarea=NULL;
851    LONGX     jdifmtlw=0;
852    LONGX     jdifmtasize=MAXMFRL;
853
854
855    /* ............................................... directory listing */
856#if DIR_FILE
857    DIR *direntdp=NULL;
858    struct dirent *direntep;
859#endif
860
861
862    /* ............................................... get cgi parameters */
863#define MAXARGS 512
864    char *argv[MAXARGS+1];
865    char *argv_0[MAXARGS+1];
866
867/* mxaotx.c
868*/
869//CICGI
870#if CICGI
871    int ii,ix;
872    char *xp;
873    LONGX rc;
874#if !CIAPI
875    int cgitrace=0;
876#endif /* !CIAPI */
877
878    char *cgispecp=NULL;
879    char *cgipfxp="tag";
880    UWORD cgitag=2000;
881
882    /* int cicgi0(int *argc, char *argv[], char **wwwp, UWORD taghxsub, char *taghpfxp); */
883    char *wwwp=NULL;
884    char *infop;
885
886#endif
887
888
889//CICGI
890#if MXFUN
891    if (mxinit(&xmxp)) return(1);
892    if (xmxp == NULL) return(2);
893#if CIAPI
894    ciapip = cisisApplication( MAXNREC,MAXNTRM );/* mandatory for CIAPI definitions */
895#endif /* CIAPI */
896#else /* MXFUN */
897    xmxp=NULL;
898#endif /* MXFUN */
899
900
901#if CICGI
902#if CIAPI
903    cgitrace=0;
904#endif /* CIAPI */
905    argv_0[ix=0]=argv_1[0];
906#define TRACX 0
907#if TRACX
908cgitrace=1;
909printf("Content-type: text/plain\n\n");
910printf("PATH_INFO=%s\n",getenv("PATH_INFO"));
911printf("PATH_TRANSLATED=%s\n",getenv("PATH_TRANSLATED"));
912printf("SCRIPT_NAME=%s\n",getenv("SCRIPT_NAME"));
913printf("argv_0[0]=%s\n",argv_0[0]);
914#endif
915
916    infop=getenv("PATH_INFO"); /* PATH_INFO=/cgi=mx */
917    if (infop) {
918        xp=strstr(infop,"cgi="); if (!xp) xp=strstr(infop,"cgi~");
919        if (xp) if (*xp) {
920            cgixpok=argv_0[++ix]=strdup(xp);
921            xp=cgixpok+strlen(xp)-1; if (*xp == '/') *xp='\0';
922#if TRACX
923printf("argv_0[1]=%s\n",argv_0[1]);
924#endif
925        }
926    }
927
928    /* disable PATH_INFO=/cgi= */
929    if (cgixpok)
930        for (i=1; i < argc; i++)
931            if (strcmp(argv_1[i],"cgi=null") == 0) { ix--; cgixpok=NULL; break; }
932
933    argc+=ix; for (ii=1; ii < argc; ) argv_0[++ix]=argv_1[ii++]; argv_0[++ix]=NULL;
934    for (ii=0, i=1; i < argc; i++) if (strncmp(argv_0[i],"cgi",3) == 0) { ii=1; break; }
935    if (ii) { //some cgii
936        /*putenv("REQUEST_METHOD=GET");*/
937        /*putenv("QUERY_STRING=db~cds&pft~mfn,x1,v24/&count~2&now&btell~0&bool~plants*water");*/
938        for (i=0; i < argc; i++) if (strcmp(argv_0[i],"cgitrace") == 0) cgitrace=1;
939        RECORD(wwrec1=nrecs,"null",1L); RECrc=RCNORMAL; MFRstatus=ACTIVE;
940        RECORD(wwrec2=nrecs,"null",1L); xp=(char *)MFX; /* current */
941        for (ii=0, i=0; i < argc; i++) {
942            if (strncmp(argv_0[i],"cgi",3) != 0) argv[ii++]=argv_0[i];
943            else {
944                if (strncmp(argv_0[i],"cgitag=",7) == 0 || strncmp(argv_0[i],"cgitag~",7) == 0) {
945                    cgitag=(UWORD)atol(argv_0[i]+7); continue;
946                }
947                if (strncmp(argv_0[i],"cgipfx=",7) == 0 || strncmp(argv_0[i],"cgipfx~",7) == 0) {
948                    cgipfxp=argv_0[i]+7; continue;
949                }
950                if (strncmp(argv_0[i],"cgi=",4) == 0 || strncmp(argv_0[i],"cgi~",4) == 0) {
951                    cgispecp=argv_0[i]+4;
952                    if (cgitrace) printf("+++ cgispecp=%s.\n",cgispecp);
953                    if (strcmp(cgispecp,"null") == 0) continue;
954                    if (strcmp(cgispecp,"mx") == 0) {
955                        p=NULL;
956                        if (!p) {
957                            sprintf(xp,"@%s",argv_0[0]);
958                            if (strcmp((q=xp+strlen(xp)-4),".EXE") == 0) *q='\0';
959                            if (strcmp((q=xp+strlen(xp)-4),".exe") == 0) *q='\0';
960                        }
961                        cgispecp=strdup(strcat(xp,".pft"));
962                        if (cgitrace) printf("+++ cgispecp=mx=(%s)\n",cgispecp);
963                    }
964                    if (cgitrace) printf("+++ REQUEST_METHOD=%s.\n",getenv("REQUEST_METHOD"));
965                    if (cgitrace) printf("+++ QUERY_STRING=%s.\n",getenv("QUERY_STRING"));
966                    wwwp=NULL; cicgi0(&ii, argv, &wwwp, cgitag, cgipfxp);
967                    if (!wwwp) wwwp="";
968                    if (cgitrace) printf("+++ wwwp=%s.\n",wwwp);
969                    sprintf(xp,"D%ld",(LONGX)cgitag); fldupdat(wwrec1,xp);
970                    p=fldupdat(wwrec1,wwwp); if (p) fatal(p);
971                    rc=recfmt(wwrec1,RECnbytes,cgispecp,p=xp,RECnbytes);
972                    if (rc < 0) fatal(argv_0[i]/*cgispecp*/);
973                    while (*p) {
974                        for (ix=0, q=p; *p; p++)
975                           if (*p == '\r' || *p == '\n') {
976                               *p++='\0'; if (*p == '\n') *p++='\0'; break;
977                           } else ix++;
978                        if (ix) argv[ii++] = strdup(q);
979                    }
980                    continue;
981                } /* end if */
982            } /* end if else */
983        } /* end for */
984        argc=ii; argv[argc]=NULL;
985        if (cgitrace) {
986         printf("Content-type: text/html\n\n");
987         printf("%s/cgi produced %d parameters:<br>\n",argv[0],argc-1);
988         printf("<ul>\n");
989         for(ix=1; ix < argc; ix++) printf("<li><pre>%s</pre>\n",argv[ix]);
990         printf("</ul>\n");
991        }
992    }
993    else { //some cgii
994/*
995REQUEST_METHOD=GET
996QUERY_STRING=cicgi~mx&db~cds&pft~mfn,x1,v24/&count~2&now&btell~0&bool~plants*water
997*/
998        for (i=0; i < argc; i++) if (strcmp(argv_0[i],"trace=cgi") == 0) cgitrace=1;
999        for (ii=0, i=0; i < argc; i++) if (strcmp(argv_0[i],"trace=cgi")) argv[ii++]=argv_0[i];
1000        argc=ii;
1001        if (cicgi0(&argc, argv, NULL, 0, NULL)) {
1002if (cgitrace) {
1003 printf("Content-type: text/html%c%c",10,10);
1004 printf("%s/CICGI produced the following %d parameters:<p>%c",argv[0],argc-1,10);
1005 printf("<ul>%c",10);
1006 for(ix=1; ix < argc; ix++) printf("<li> <code>%s</code>%c",argv[ix],10);
1007 printf("</ul>%c",10);
1008}
1009        }
1010    } //some cgii
1011#endif /* CICGI */
1012//CICGI
1013
1014    argnext=1;
1015    if (argc > 1)
1016        if (*argv[1] == '?' || *argv[1] == '=') {
1017            for (i=0; i < argc; i++)
1018                printf("argv[%d]: %c%s%c\n",i,OPENFCHR,argv[i],CLOSFCHR);
1019            MXEXIT(0);
1020        }
1021
1022#define WHATISNEW 00
1023#if WHATISNEW
1024    if (argc > 1)
1025        if (strcmp(argv[1],"whatisnew") == 0) {
1026            printf("summary \n\n");
1027//CICGI
1028#if CICGI
1029            printf("    CGI data        get mx parameter from cgi environment \n\n");
1030            printf(" set REQUEST_METHOD=GET \n");
1031            printf(" set QUERY_STRING=db~cds&count~2&now&btell~0&bool~plants*water&pft~mfn/ \n");
1032            printf(" mx cgi=mx \n");
1033            printf(" 000004 \n");
1034            printf(" 000011 \n\n");
1035#endif /* CICGI */
1036            printf("    I/F keys        read I/F keys as mx input records \n\n");
1037            printf(" mx dict=cds k1=africa \"k2=african languages\" now  \n");
1038            printf(" mfn=     1  \n");
1039            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1040            printf(" mfn=     2  \n");
1041            printf("   1  �AFRICAN LANGUAGES^l2^s17^t1^k2� \n");
1042            printf(" \n");
1043            printf("    I/F postings    read I/F keys and postings as mx input records \n\n");
1044            printf(" mx dict=cds,1,2/3 k1=africa count=2 now  \n");
1045            printf(" mfn=     1  \n");
1046            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1047            printf("   2  �^m97^t69^o1^c9^p1^k1� \n");
1048            printf("   2  �^m115^t24^o1^c3^p2^k1� \n");
1049            printf("   2  �^m115^t69^o1^c3^p3^k1� \n");
1050            printf(" mfn=     2  \n");
1051            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1052            printf("   2  �^m119^t69^o1^c7^p4^k1� \n");
1053            printf("   2  �^m125^t69^o1^c4^p5^k1� \n");
1054            printf(" \n");
1055            printf("    field add       field add w/ markup strip \n\n");
1056            printf(" mx null \"proc='<10>x<mark>y</mark>z</10>'\" \n");
1057/*          printf(" mfn=     1 \n"); */
1058            printf("  10  �xyz� \n\n");
1059            printf("    procedures      up to %d proc= parameters, including fst, read, write, I/F update \n\n",MAXNPPP);
1060            printf(" mx cds \"proc='T99 2 (v69/)'\" \n");
1061/*          printf(" mfn=     1 \n"); */
1062            printf("  69  �Paper on: <plant physiology><plant transpiration><measurement and instruments>� \n");
1063            printf("  99  �PLANT PHYSIOLOGY^m1^o1^c1^l2� \n");
1064            printf("  99  �PLANT TRANSPIRATION^m1^o1^c2^l2� \n");
1065            printf("  99  �MEASUREMENT AND INSTRUMENTS^m1^o1^c3^l2� \n\n");
1066            printf(" mx null proc='Rcds,1' \n");
1067            printf(" mfn=     1 \n");
1068            printf("  44  �Methodology of plant eco-physiology: proceedings of the Montpellier Sympoium� \n");
1069            printf("  50  �Incl. bibl.� \n");
1070            printf("  69  �Paper on: <plant physiology><plant transpiration><measurement and instrumnts>� \n");
1071            printf("  24  �Techniques for the measurement of transpiration of individual plants� \n");
1072            printf("  26  �^aParis^bUnesco^c-1965� \n");
1073            printf("  30  �^ap. 211-224^billus.� \n");
1074            printf("  70  �Magalhaes, A.C.� \n");
1075            printf("  70  �Franco, C.M.� \n\n");
1076            printf(" mx null proc='a10/1/' proc='Xdbn1' \n");
1077            printf(" mx dbn1 \n");
1078            printf(" mfn= 1 \n");
1079            printf(" 10 �1� \n\n");
1080            printf(" del lilacs_year_*.mst \n");
1081            printf(" del lilacs_year_*.xrf \n");
1082            printf(" mx lilacs proc='Xappend=lilacs_year_',v64.4 \n\n");
1083            printf(" mx null proc='a1/x/' to=3 \"proc='Yy,,,1 0 v1'\" \"pft='npost='f(npost(['y']'x'),1,0)/\" \n");
1084            printf(" npost=1 \n");
1085            printf(" npost=2 \n");
1086            printf(" npost=3 \n\n");
1087            printf(" mx cds -all now proc='Xx' proc='Zx' \n");
1088            printf(" ifupd x fst=@cds.fst tell=1 \n");
1089            printf(" 0 records updated \n");
1090            printf(" 0+0=0 postings added \n");
1091            printf(" 0+0=0 postings deleted \n\n");
1092            printf(" del lilacs_year_*.12 \n");
1093            printf(" mx lilacs proc='Fappend=lilacs_year_',v64.4,'.12',v1'-'v2/ \n\n");
1094#if MORE1
1095            printf(" mx null proc='a10/1/' create=x \n");
1096            printf(" mfn=     1 \n");
1097            printf("  10  �1� \n");
1098            printf(" mx null proc='a20/2/' append=x \n");
1099/*            printf(" mfn=     1 \n"); */
1100            printf("  20  �2� \n");
1101            printf(" mx null proc='Rx,1' proc='Rx,2' \n");
1102/*            printf(" mfn=     1 \n"); */
1103            printf("  10  �1� \n");
1104            printf("  20  �2� \n\n");
1105
1106            printf(" mx null proc='a10/1/' proc='Xdbn1' proc='a20/2/' proc='Xdbn2' \n");
1107            printf(" mx dbn1 \n");
1108            printf(" mfn=     1 \n");
1109            printf("  10  �1� \n");
1110            printf(" mx dbn2 \n");
1111            printf(" mfn=     1 \n");
1112            printf("  10  �1� \n");
1113            printf("  20  �2� \n\n");
1114            printf(" @echo 'd*a32701~',,mstname,,'^m',,f(mfn,8,0),,'~',, >p0 \n");
1115            printf(" @echo '=',,ref(['mstxrf']1,f(maxmfn,1,0)) >p1 \n");
1116            printf(" @echo if l(['mstxrf']v32701)=0 then 'Xmstxrf' fi >p2 \n");
1117            printf(" @echo if l(['mstxrf']v32701)=0 then 'Ymstxrf,mstxrf,32701 0 v32701' fi >p3 \n");
1118            printf(" mx full x -all now proc=@p0 proc=@p1 proc=@p2 proc=@p3 \n\n");
1119#endif /* MORE1 */
1120            /* printf("    cipar           ci_tempdir, maxmfrl, ci_fststrip \n\n"); */
1121            printf("    cipar           set directory for temporary files \n\n");
1122            printf(" echo ci_tempdir=c:\\work >xcip \n");
1123            printf(" mx cipar=xcip cdromdb \n\n");
1124            printf("    cipar           set max master file record length \n\n");
1125            printf(" @echo maxmfrl=32000 >xcip \n");
1126            printf(" mx cipar=xcip bigrecs \n\n");
1127#define CIFS 1
1128#if CIFS
1129            printf("    cipar           strip <markup> marks during fst \n\n");
1130            printf(" set echo ci_fststrip=32000 >xcip \n");
1131            printf(" mx cds \n");
1132            printf("  69  �Paper on: <plant physiology><plant transpiration><measurement and instruments>� \n");
1133            printf(" mx cipar=xcip cds \"fst=690 4 v69\" \n");
1134            printf("  69  �Paper on:                                                                     � \n");
1135            printf(" 690  �PAPER^m1^o1^c1^l1� \n");
1136            printf(" 690  �ON^m1^o1^c2^l1� \n\n");
1137#endif /* CIFS */
1138            printf("    fst             indexing technique to extract text within <mark> and </mark> \n\n");
1139            printf(" mx null \"fst=1 2000 '#<B>#','text <B>text1</B> text <B>text2</B> text'\" \n");
1140            printf("   1  �TEXT1TEXT2^m1^o1^c1^l1� \n\n");
1141            printf("    format          read a stdin input line as a new field occurrence \n\n");
1142            printf(" mx null to=2 \"pft=if mfn=1 then _10,putenv('TAG10='v10) fi,,mfn,x1,getenv('TAG10'),/ \n");
1143            printf(" input line \n");
1144            printf(" 000001 input line \n");
1145            printf(" 000002 input line \n\n");
1146            printf("    format          get the contents of a specified cgi variable \n\n");
1147            printf(" set REQUEST_METHOD=GET \n");
1148            printf(" set QUERY_STRING=db~cds&bool~plants*water \n");
1149            printf(" mx null pft=getenv('cgi=db') \n");
1150            printf(" cds \n\n");
1151            printf("    format          get a temporary empty file name \n\n");
1152            printf(" mx null pft=getenv('tmp=') \n");
1153            printf(" TMP1.$$$ \n\n");
1154#if DOS32BITS
1155            printf("    platform        32-bit memory support \n\n");
1156            printf(" mx null count=1 sys='mx what' \n");
1157            printf(" CISIS Interface v4.01/fmtold/PC32/M/30000/10/30/I - Utility MX \n");
1158            printf(" CISIS Interface v4.01/fmtold/.iy0/Z/4GB/GIZ/DEC/ISI/UTL/FAT/CIP/CGI \n");
1159            printf(" Copyright (c)BIREME/PAHO 2000. All rights reserved. \n\n");
1160#endif /* DOS32BITS */
1161#if CICGI
1162            printf("[cgitag=<tag>] [cgipfx=<pfx>] cgi={<fmt>|mx}^uy^hget mx calling parameters from CGI^xx \n\n");
1163            printf("    cgitag=<tag>    tag for ^n^v pairs [%ld]\n",cgitag);
1164            printf("    cgipfx=<pfx>    tag naming prefix [%s] \n",cgipfxp);
1165            printf("    cgi=<fmt>       specify mx parameters via <fmt> \n");
1166#if 0
1167            printf("    cgi=mx          specify mx parameters via "); /* built-in specification */
1168for (xp=argv_0[0], ix=(strcmp(xp+strlen(xp)-4,".EXE") == 0)?strlen(xp)-4:strlen(xp); ix--; xp++) printf("%c",*xp);
1169printf(".pft \n\n");
1170#else
1171            printf("    cgi=mx          specify mx parameters by corresponding names \n\n"); /* built-in specification */
1172#endif
1173            printf("    store CGI name/value pairs as repeatable field %ld \n",cgitag);
1174            printf("    and take each line produced by format <fmt> (or mx.pft) as an additional mx parameter \n\n");
1175            printf(" set REQUEST_METHOD=GET \n");
1176            printf(" set QUERY_STRING=db~cds&count~2&now&btell~0&bool~plants*water&pft~mfn/ \n");
1177            printf(" mx cgi=mx \n");
1178            printf(" 000004 \n");
1179            printf(" 000011 \n\n");
1180            printf(" <html> \n");
1181            printf(" <body> \n");
1182            printf(" <form action=\"/cgi-bin/mx.exe/cgi=mx\" method=\"post\"> \n");
1183            printf(" Run MX with 'bool=' and 'count=' parameters assigned to the following values:<hr> \n");
1184            printf(" Search expression:    <input type=\"text\" name=\"bool\"  value=\"$\"><br> \n");
1185            printf(" Max #records to show: <input type=\"text\" name=\"count\" value=\"10\"><br> \n");
1186            printf(" <input type=\"submit\" value=\"search & display\"> \n");
1187            printf(" <input type=\"hidden\" name=\"db\" value=\"D:\\Users\\www\\isis\\data\\cds\"> \n");
1188            printf(" <input type=\"hidden\" name=\"pft\" value=\"lw(8000),newline('<br>'),@D:\\Users\\www\\isis\\data\\cds.pft\"> \n");
1189            printf(" <input type=\"hidden\" name=\"now\"> \n");
1190            printf(" <input type=\"hidden\" name=\"btell\" value=\"0\"> \n");
1191            printf(" </form> \n");
1192            printf(" </body> \n");
1193            printf(" </html> \n\n");
1194#endif /* CICGI */
1195            printf("dict=<ifn>[,<ktag>[,<ptag>[/<pmax>]]] [k{1|2}=<key>]^hread I/F keys as mx input records^xx \n\n");
1196            printf("    <ifn>           I/F dictionary \n");
1197            printf("    <ktag>          tag for I/F key [1] \n");
1198            printf("    <ptag>          tag for I/F posting \n");
1199            printf("    <pmax>          max postings per record [all] \n");
1200            printf("    k1=<key>        initial key \n");
1201            printf("    k2=<key>        final key \n\n");
1202            printf("    read I/F keys from <ifn> as mx input records with field <ktag> \n");
1203            printf("    with key and ^l=lex ^s=keylength ^t=totalpostings ^k=keyorder \n\n");
1204            printf("    if <ptag> is specified, combine I/F keys and corresponding postings \n");
1205            printf("    as mx input records having up to <pmax> postings each; \n");
1206            printf("    <ptag> has the form ^m=mfn ^t=tag ^o=occ ^c=cnt ^ppstorder ^kkeyorder \n\n");
1207            printf(" mx dict=cds k1=africa \"k2=african languages\" now  \n");
1208            printf(" mfn=     1  \n");
1209            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1210            printf(" mfn=     2  \n");
1211            printf("   1  �AFRICAN LANGUAGES^l2^s17^t1^k2� \n\n");
1212            printf(" mx dict=cds,1,2 k1=africa count=1 now  \n");
1213            printf(" mfn=     1  \n");
1214            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1215            printf("   2  �^m97^t69^o1^c9^p1^k1� \n");
1216            printf("   2  �^m115^t24^o1^c3^p2^k1� \n");
1217            printf("   2  �^m115^t69^o1^c3^p3^k1� \n");
1218            printf("   2  �^m119^t69^o1^c7^p4^k1� \n");
1219            printf("   2  �^m125^t69^o1^c4^p5^k1� \n\n");
1220            printf(" mx dict=cds,1,2/3 k1=africa count=2 now  \n");
1221            printf(" mfn=     1  \n");
1222            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1223            printf("   2  �^m97^t69^o1^c9^p1^k1� \n");
1224            printf("   2  �^m115^t24^o1^c3^p2^k1� \n");
1225            printf("   2  �^m115^t69^o1^c3^p3^k1� \n");
1226            printf(" mfn=     2  \n");
1227            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1228            printf("   2  �^m119^t69^o1^c7^p4^k1� \n");
1229            printf("   2  �^m125^t69^o1^c4^p5^k1� \n\n");
1230            printf(" mx dict=cds,1,2/1 k1=africa count=5 now  \n");
1231            printf(" mfn=     1  \n");
1232            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1233            printf("   2  �^m97^t69^o1^c9^p1^k1� \n");
1234            printf(" mfn=     2  \n");
1235            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1236            printf("   2  �^m115^t24^o1^c3^p2^k1� \n");
1237            printf(" mfn=     3  \n");
1238            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1239            printf("   2  �^m115^t69^o1^c3^p3^k1� \n");
1240            printf(" mfn=     4  \n");
1241            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1242            printf("   2  �^m119^t69^o1^c7^p4^k1� \n");
1243            printf(" mfn=     5  \n");
1244            printf("   1  �AFRICA^l1^s6^t5^k1� \n");
1245            printf("   2  �^m125^t69^o1^c4^p5^k1� \n\n");
1246#if TBISNEW
1247            printf("tb=<tag>^hsave data fields as individual files^xx \n\n");
1248            printf("    <tag>           field tag \n\n");
1249            printf("    save the contents of field <tag> into binary file MFRmfn.<tag> \n");
1250            printf("    if <tag> is zero save whole data segment into file MFRmfn.dat \n\n");
1251            printf(" mx cds tb=30 tb=70 \"pft=mfn,x2,v30,x2,v70+|; |/\" \n");
1252            printf(" 000001  ^ap. 211-224^billus.  Magalhaes, A.C.; Franco, C.M. \n");
1253            printf(" /****************************************************** \n");
1254            printf(" 1.30 \n");
1255            printf(" ******************************************************/ \n");
1256            printf(" ^ap. 211-224^billus. \n");
1257            printf(" /****************************************************** \n");
1258            printf(" 1.70 \n");
1259            printf(" ******************************************************/ \n");
1260            printf(" Magalhaes, A.C.Franco, C.M. \n");
1261#endif /* TB */
1262            printf("proc=<<tag>[ <marklen>[ <fldlen>]]><text></<tag>>^uy^hproc=< to add text between <marks>^xx \n\n");
1263            printf("    <tag>           field tag \n");
1264            printf("    <marklen>       max mark length [<text> length] \n");
1265            printf("    <fldlen>        min resulting field length to add a new occ of field <tag> [0] \n\n");
1266            printf("    add <text> as a new occurrence of field <tag> \n");
1267            printf("    <marks> up to <marklen> chars are stripped from <text> \n");
1268            printf("    do not add a new occurrence of field <tag> if the resulting text is shorter than <fldlen> chars \n\n");
1269#if MELHOR
1270ver se altercao acima nao estorou linha do browser
1271C:\cid>mx null count=1 "proc='<10>x<mark>y</mark>z</10>'"
1272mfn=     1
1273 10  xyz
1274
1275C:\cid>mx null count=1 "proc='<10 0>x<mark>y</mark>z</10>'"
1276mfn=     1
1277 10  x<mark>y</mark>z
1278
1279C:\cid>mx null count=1 "proc='<10 5>x<mark>y</mark>z</10>'"
1280mfn=     1
1281 10  x<mark>y</mark>z
1282
1283C:\cid>mx null count=1 "proc='<10 6>x<mark>y</mark>z</10>'"
1284mfn=     1
1285 10  xy</mark>z
1286
1287C:\cid>mx null count=1 "proc='<10 7>x<mark>y</mark>z</10>'"
1288mfn=     1
1289 10  xyz
1290#endif
1291            printf(" mx null \"proc='<10>text</10>'\" \n");
1292            printf(" mfn=     1 \n");
1293            printf("  10  �text� \n\n");
1294            printf(" mx null \"proc='<10>x<mark>y</mark>z</10>'\" \n");
1295            printf(" mfn=     1 \n");
1296            printf("  10  �xyz� \n\n");
1297            printf(" mx null \"proc='<10 99 3>x<mark>y</mark>z</10>'\" \n");
1298            printf(" mfn=     1 \n");
1299            printf("  10  �xyz� \n");
1300            printf(" mx null \"proc='<10 99 4>x<mark>y</mark>z</10>'\" \n");
1301            printf(" mfn=     1 \n\n");
1302#if GENPROCT
1303            printf("proc=T[/h=]<fst>^hproc=T to add fst results^xx \n\n");
1304            printf("    <fst>           field select table specification \n\n");
1305            printf("    apply <fst> to MFR adding generated links as data fields \n");
1306            printf("    command T/h=<fst> stands for full-length key extraction \n\n");
1307            printf(" mx cds \"proc='T99 0 (v70/)'\" \n");
1308            printf(" mfn=     1 \n");
1309            printf("  70  �Magalhaes, A.C.� \n");
1310            printf("  70  �Franco, C.M.� \n");
1311            printf("  99  �MAGALHAES, A.C.^m1^o1^c1^l2� \n");
1312            printf("  99  �FRANCO, C.M.^m1^o1^c2^l2� \n\n");
1313            printf(" mx cds \"proc='T/h=0 0 (v70/)'\" \n");
1314            printf(" mfn=     1 \n");
1315            printf(" 32767  �Magalhaes, A.C. \n");
1316            printf(" Franco, C.M. \n");
1317            printf(" � \n\n");
1318            printf(" echo PLANT PHYSIOLOGY>x \n");
1319            printf(" echo PLANT TRANSPIRATION>>x \n");
1320            printf(" mx seq=x -all now \"fst=1 0 v1\" ifupd/create=thes \n");
1321/*            printf(" mx cds \"proc='T99 2 (v69/)'\" \"proc=(if l(['thes']v99^*)=0 then 'a999|'v99^*'|' fi)\" \"pft=(if p(v999) then 'not in thes: 'v999/ fi)\" \n");
1322*/
1323            printf(" mx cds \"proc='T99 2 (v69/)'\" \"pft=(if l(['thes']v99^*)=0 then 'not in thes: 'v99^*/ fi)\" \n");
1324            printf(" mfn=     1 \n");
1325            printf("  69  �Paper on: <plant physiology><plant transpiration><measurement and instruments>� \n");
1326            printf("  99  �PLANT PHYSIOLOGY^m1^o1^c1^l2� \n");
1327            printf("  99  �PLANT TRANSPIRATION^m1^o1^c2^l2� \n");
1328            printf("  99  �MEASUREMENT AND INSTRUMENTS^m1^o1^c3^l2� \n");
1329            printf(" not it thes: MEASUREMENT AND INSTRUMENTS \n\n");
1330#endif /* GENPROCT */
1331            printf("proc=R<dbn>,<mfn>^hproc=R to add data of another record^xx \n\n");
1332            printf("    <dbn>           input master file name \n");
1333            printf("    <mfn>           master file record number \n\n");
1334            printf("    add to MFR all data fields of active record <dbn>,<mfn> \n\n");
1335            printf(" mx null proc='a10/1/a20/1/' create=x \n");
1336/*            printf(" mfn=     1 \n"); */
1337            printf("  10  �1� \n");
1338            printf("  20  �1� \n");
1339            printf(" mx null proc='a20/2/' append=x \n");
1340/*            printf(" mfn=     1 \n"); */
1341            printf("  20  �2� \n");
1342            printf(" mx null proc='Rx,1' proc='Rx,2' \n");
1343            printf(" mfn=     1 \n");
1344            printf("  10  �1� \n");
1345            printf("  20  �1� \n");
1346            printf("  20  �2� \n\n");
1347            printf("proc=X[{create|copy|append|merge}=]<out_dbn>^hproc=X to write an output record^xx \n\n");
1348            printf("    <out_dbn>       output master file name \n\n");
1349            printf("    create <out_dbn> if does not exist \n");
1350            printf("    write MFR to <out_dbn> as record MFRmfn or \n");
1351            printf("    append MFR to <out_dbn> or \n");
1352            printf("    merge MFR to <out_dbn> \n\n");
1353            printf(" mx null proc='a10/1/' proc='Xdbn1' proc='a20/2/' proc='=3' proc='Xdbn2' \n");
1354            printf(" mx dbn1 \n");
1355            printf(" mfn=     1 \n");
1356            printf("  10  �1� \n");
1357            printf(" mx dbn2 \n");
1358            printf(" mfn=     3 \n");
1359            printf("  10  �1� \n");
1360            printf("  20  �2� \n\n");
1361            printf(" echo replace(replace(s(v70[1].8),',','-'),' ','+') >xfile.pft \n");
1362            printf(" mx cds proc='Xappend='@xfile.pft, pft=mfn,x1,v70[1]/ \n");
1363            printf(" 000001 Magalhaes, A.C. \n");
1364            printf(" 000002 Bosian, G. \n");
1365            printf(" 000003 Bosian, G. \n");
1366            printf(" mx Magalhae pft=mfn,x1,v70[1]/ \n");
1367            printf(" 000001 Magalhaes, A.C. \n");
1368            printf(" mx Bosian-+ pft=mfn,x1,v70[1]/ \n");
1369            printf(" 000002 Bosian, G. \n");
1370            printf(" 000003 Bosian, G. \n\n");
1371            printf("proc=Y[create=]<out_ifn>,[<dbn>],[<mfn>],<fst>^hproc=Y to update an I/F^xx \n\n");
1372            printf("    <out_ifn>       output inverted file name \n");
1373            printf("    <dbn>           master file name, or 'null' \n");
1374            printf("    <mfn>           master file record number \n");
1375            printf("    <fst>           field select table specification \n\n");
1376            printf("    if <dbn> is 'null' or omitted update <out_ifn> applying <fst> to MFR \n");
1377            printf("    assign <mfn> [MFRmfn] to components TRMpmfn of generated postings \n");
1378            printf("    otherwise update <out_ifn> applying <fst> to record <mfn> [MFRmfn] of <dbn> \n");
1379            printf("    does not reset any IFupdPending flag \n\n");
1380/*          printf("    reset corresponding flag IFupdPending if exist <out_ifn>.mst \n\n"); */
1381            printf(" @echo Procedure to create a centralized index for a set of data bases \n");
1382            printf(" @echo Setup sample data base MF1, MF1.fst and MF1.pft.. \n");
1383            printf(" @echo 100 0 v1/,v2/,v1'/'v2/ >MF1.fst \n");
1384            printf(" @echo '[MF1] 'mfn/,' 1='v1/,' 2='v2/ >MF1.pft \n");
1385            printf(" @mx null count=1 \"proc='a1~master 1~a2~registro 1~'\" create=MF1 pft=@MF1.pft \n");
1386            printf(" @mx null count=1 \"proc='a1~master 1~a2~registro 2~'\" append=MF1 pft=@MF1.pft \n");
1387            printf(" @echo Setup sample data base MF2, MF2.fst and MF2.pft.. \n");
1388            printf(" @echo 200 0 v10/,v20/,v10'/'v20/ >MF2.fst \n");
1389            printf(" @echo '[MF2] 'mfn/,' 10='v10/,' 20='v20/ >MF2.pft \n");
1390            printf(" @mx null count=1 \"proc='a10~master 2~a20~registro 1~'\" create=MF2 pft=@MF2.pft \n");
1391            printf(" @echo And init centralized record number M/F and all indexes I/F.. \n");
1392            printf(" mx null count=0 create=mstxrf ifupd/create=mstxrf \n");
1393            printf(" @pause \n");
1394            printf(" @echo Load MF1 and MF2 into same mstxrf and index them.. \n");
1395            printf(" @rem setup centralized record numbering procs \n");
1396            printf(" @echo 'd*a32701~',mstname'^m'f(mfn,8,0)'~' >p1 \n");
1397            printf(" @echo if l(['mstxrf']v32701)=0 then '='ref(['mstxrf']1,f(maxmfn,1,0)),,'X','mstxrf' fi >p2a \n");
1398            printf(" @echo if l(['mstxrf']v32701)=0 then 'Y','mstxrf,null,,32701 0 v32701' fi >p2b \n");
1399            printf(" @echo 'Z',v32701^*','f(val(v32701^m),1,0) >p2c \n");
1400            printf(" @rem setup centralized index update procs \n");
1401            printf(" @echo 'R',v32701^*','f(val(v32701^m),1,0) >p3a \n");
1402            printf(" @echo 'Y','mstxrf,null,'f(l(['mstxrf']v32701),1,0)',@'v32701^*'.fst' >p3b \n");
1403            printf(" @echo 'Z',v32701^*','f(val(v32701^m),1,0) >p3c \n");
1404            printf(" @rem fldupdat() commands 'R', 'X', 'Y' and 'Z' may occur just once per 'proc=' or 'proc()'^iy^xx \n");
1405            printf(" @rem otherwise two or more of these procs could be put together in a single 'proc=' file^iy^xx \n");
1406            printf(" @rem p1 \n");
1407            printf(" @rem 'd*a32701~',mstname'^m'f(mfn,8,0)'~' \n");
1408            printf(" @rem p2a \n");
1409            printf(" @rem if l(['mstxrf']v32701)=0 then '='ref(['mstxrf']1,f(maxmfn,1,0)),,'X','mstxrf' fi \n");
1410            printf(" @rem p2b \n");
1411            printf(" @rem if l(['mstxrf']v32701)=0 then 'Y','mstxrf,null,,32701 0 v32701' fi \n");
1412            printf(" @rem p2c \n");
1413            printf(" @rem 'Z',v32701^*','f(val(v32701^m),1,0) \n");
1414            printf(" @rem p3a \n");
1415            printf(" @rem 'R',v32701^*','f(val(v32701^m),1,0) \n");
1416            printf(" @rem p3b \n");
1417            printf(" @rem 'Y','mstxrf,null,'f(l(['mstxrf']v32701),1,0)',@'v32701^*'.fst' \n");
1418            printf(" @rem p3c \n");
1419            printf(" @rem 'Z',v32701^*','f(val(v32701^m),1,0) \n");
1420            printf(" @rem \n");
1421            printf(" mx %1 MF1 now proc=@p1 proc=@p2a proc=@p2b proc=@p2c proc=@p3a proc=@p3b proc=@p3c \n");
1422            printf(" @rem mfn=     1 \n");
1423            printf(" @rem 32701  �MF1^m       1� \n");
1424            printf(" @rem   1  �master 1� \n");
1425            printf(" @rem   2  �registro 1� \n");
1426            printf(" @rem mfn=     2 \n");
1427            printf(" @rem 32701  �MF1^m       1� \n");
1428            printf(" @rem   1  �master 1� \n");
1429            printf(" @rem   2  �registro 2� \n");
1430            printf(" @rem \n");
1431            printf(" mx %1 MF2 now proc=@p1 proc=@p2a proc=@p2b proc=@p2c proc=@p3a proc=@p3b proc=@p3c \n");
1432            printf(" @rem mfn=     3 \n");
1433            printf(" @rem 32701  �MF2^m       1� \n");
1434            printf(" @rem  10  �master 2� \n");
1435            printf(" @rem  20  �registro 1� \n");
1436            printf(" @rem \n");
1437            printf(" @pause \n");
1438            printf(" @echo Create default display format for centralized record number M/F.. \n");
1439            printf(" @rem setup header and read original record \n");
1440            printf(" @echo '[mstxrf 'mfn'] ',v32701/, >mstxrf.pft \n");
1441            printf(" @echo proc('R'v32701^*,',',v32701^m), >>mstxrf.pft \n");
1442            printf(" @echo proc('='f(val(v32701^m),1,0)), >>mstxrf.pft \n");
1443            printf(" @rem setup original display format selection \n");
1444            printf(" @echo if v32701^*='MF1' then @MF1.pft, fi, >>mstxrf.pft \n");
1445            printf(" @echo if v32701^*='MF2' then @MF2.pft, fi, >>mstxrf.pft \n");
1446            printf(" @echo And test it.. \n");
1447            printf(" mx mstxrf \"bool=registro 1\" pft=@ now \n");
1448            printf(" @rem \n");
1449            printf(" @rem mx mstxrf \"bool=registro 1\" pft=@ now \n");
1450            printf(" @rem       2       2  REGISTRO 1 \n");
1451            printf(" @rem       2       2  Set #000001 \n");
1452            printf(" @rem Hits=2 \n");
1453            printf(" @rem [mstxrf 000001] MF1^m       1 \n");
1454            printf(" @rem [MF1] 000001 \n");
1455            printf(" @rem  1=master 1 \n");
1456            printf(" @rem  2=registro 1 \n");
1457            printf(" @rem 100= \n");
1458            printf(" @rem [mstxrf 000003] MF2^m       1 \n");
1459            printf(" @rem [MF2] 000001 \n");
1460            printf(" @rem  10=master 2 \n");
1461            printf(" @rem  20=registro 1 \n");
1462            printf(" @rem 200= \n");
1463            printf(" @rem \n");
1464            printf(" type mstxrf.pft \n");
1465            printf(" @rem '[mstxrf 'mfn'] ',v32701/, \n");
1466            printf(" @rem proc('R'v32701^*,',',v32701^m), \n");
1467            printf(" @rem proc('='f(val(v32701^m),1,0)), \n");
1468            printf(" @rem if v32701^*='MF1' then @MF1.pft, fi, \n");
1469            printf(" @rem if v32701^*='MF2' then @MF2.pft, fi, \n");
1470            printf(" @rem \n");
1471            printf(" @rem mz mstxrf -control now \n");
1472            printf(" @rem  + MASTER 1  : 1/9/0 \n");
1473            printf(" @rem    #1/2: mfn=1 tag=100 occ=1 cnt=1 \n");
1474            printf(" @rem    #2/2: mfn=2 tag=100 occ=1 cnt=1 \n");
1475            printf(" @rem  + MASTER 1/REGISTRO 1           : 1/23/0 \n");
1476            printf(" @rem    #1/1: mfn=1 tag=100 occ=1 cnt=3 \n");
1477            printf(" @rem  + MASTER 1/REGISTRO 2           : 1/51/0 \n");
1478            printf(" @rem    #1/1: mfn=2 tag=100 occ=1 cnt=3 \n");
1479            printf(" @rem  + MASTER 2  : 1/65/0 \n");
1480            printf(" @rem    #1/1: mfn=3 tag=200 occ=1 cnt=1 \n");
1481            printf(" @rem  + MASTER 2/REGISTRO 1           : 1/79/0 \n");
1482            printf(" @rem    #1/1: mfn=3 tag=200 occ=1 cnt=3 \n");
1483            printf(" @rem  + MF1^M       1                 : 1/2/0 \n");
1484            printf(" @rem    #1/1: mfn=1 tag=32701 occ=1 cnt=1 \n");
1485            printf(" @rem  + MF1^M       2                 : 1/30/0 \n");
1486            printf(" @rem    #1/1: mfn=2 tag=32701 occ=1 cnt=1 \n");
1487            printf(" @rem  + MF2^M       1                 : 1/58/0 \n");
1488            printf(" @rem    #1/1: mfn=3 tag=32701 occ=1 cnt=1 \n");
1489            printf(" @rem  + REGISTRO 1: 1/16/0 \n");
1490            printf(" @rem    #1/2: mfn=1 tag=100 occ=1 cnt=2 \n");
1491            printf(" @rem    #2/2: mfn=3 tag=200 occ=1 cnt=2 \n");
1492            printf(" @rem  + REGISTRO 2: 1/44/0 \n");
1493            printf(" @rem    #1/1: mfn=2 tag=100 occ=1 cnt=2 \n");
1494            printf(" @rem \n\n");
1495            printf("proc=Z<out_dbn>[,<mfn>]^hproc=Z to reset IFupdPending^xx \n\n");
1496            printf("    <out_dbn>       master file name \n");
1497            printf("    <mfn>           master file record number \n\n");
1498            printf("    reset flag IFupdPending corresponding to <mfn> [MFRmfn] from <out_dbn> \n\n");
1499            printf(" mx cds -all now proc='Xx' proc='Zx' \n");
1500            printf(" ifupd x fst=@cds.fst tell=1 \n");
1501            printf(" 0 records updated \n");
1502            printf(" 0+0=0 postings added \n");
1503            printf(" 0+0=0 postings deleted \n\n");
1504            printf("proc=F[{create|append}=]<out_file>,<text>^hproc=F to write a text to a file^xx \n\n");
1505            printf("    <out_file>      output file name \n");
1506            printf("    <text>          null terminated text \n\n");
1507            printf("    create <out_file> if does not exist \n");
1508            printf("    append <text> to <out_file> \n\n");
1509            printf(" echo replace(replace(s(v70[1].8),',','-'),' ','+') >xfile.pft \n");
1510            printf(" mx cds proc='Fappend='@xfile.pft,',',v24.68,'.' pft=mfn,x1,v70[1]/ \n");
1511            printf(" 000001 Magalhaes, A.C. \n");
1512            printf(" 000002 Bosian, G. \n");
1513            printf(" /****************************************************** \n");
1514            printf(" Magalhae \n");
1515            printf(" ******************************************************/ \n");
1516            printf(" Techniques for the measurement of transpiration of individual plants. \n");
1517            printf(" /****************************************************** \n");
1518            printf(" Bosian-+ \n");
1519            printf(" ******************************************************/ \n");
1520            printf(" <The> Controlled climate in the plant chamber and its influence upon. \n\n");
1521            printf("cipar: ci_tempdir=<path>^uy^cy^hcipar/ci_tempdir: set directory for temporary files^xx \n\n");
1522            printf("    <path>          drive and/or directory name \n\n");
1523            printf("    defined in cipar or environment \n");
1524            printf("    create temporary files in directory <path> \n");
1525            printf("    (if ci_tempdir is not set temporary files are created in directory \n");
1526            printf("    defined by the environment variable TEMP or by TMP) \n\n");
1527            printf(" echo ci_tempdir=c:\\work >xcip \n");
1528            printf(" mx cipar=xcip cdromdb \n\n");
1529            printf(" @set ci_tempdir=c:\\work \n");
1530            printf(" mx cdromdb \n\n");
1531            printf("cipar: maxmfrl=<nbytes>^hcipar/maxmfrl: set max master file record length^xx \n\n");
1532            printf("    <nbytes>        number of bytes \n\n");
1533            printf("    defined in cipar \n");
1534            printf("    specify the default MFRmfrl (master file record length) [%ld]\n",rec_maxmfrl);
1535#if CICPP
1536            printf("    (the maximum MFRmfrl is %ld, however the configured maximum value for <nbytes> is %ld) \n\n",(LONGX)MFRL_MAX,(LONGX)(ALLOMAXV-RECHSIZE));
1537#else
1538            printf("    (the maximum MFRmfrl is %ld, however the configured maximum value for <nbytes> is %ld) \n\n",(LONGX)MFRL_MAX,(LONGX)ALLOMAXV);
1539#endif
1540            printf(" echo maxmfrl=32767 >xcip \n");
1541            printf(" mx cipar=xcip bigrecsdb \n\n");
1542#if CIFS
1543            printf("cipar: ci_fststrip=<maxlen>^hcipar/ci_fststrip: strip <markup> marks during fst^xx \n\n");
1544/*          printf("cipar: ci_fststrip=<maxlen>[,<tags>] \n\n"); */
1545            printf("    <maxlen>        max mark length \n\n");
1546/*          printf("    <tags>          tag or comma separated tag list \n\n"); */
1547            printf("    defined in cipar or environment \n");
1548            printf("    strip any marks as <text> or </text> up to <maxlen> chars from all data fields \n");
1549            printf("    at the beggining of a FST execution (data fields are padded with blanks) \n\n");
1550            printf(" echo ci_fststrip=21 >xcip\n");
1551            printf(" mx cds \n");
1552            printf(" mfn=     1 \n");
1553            printf("  69  �Paper on: <plant physiology><plant transpiration><measurement and instruments>� \n");
1554            printf(" mx cipar=xcip cds \"fst=690 4 v69\" \n");
1555            printf(" mfn=     1 \n");
1556            printf("  69  �Paper on: <measurement and instruments>                                       � \n");
1557            printf(" 690  �PAPER^m1^o1^c1^l1� \n");
1558            printf(" 690  �ON^m1^o1^c2^l1� \n");
1559            printf(" 690  �MEASUREMENT^m1^o1^c3^l2� \n");
1560            printf(" 690  �AND^m1^o1^c4^l1� \n");
1561            printf(" 690  �INSTRUMENTS^m1^o1^c5^l2� \n");
1562#endif /* CIFS */
1563            printf("fst=<id> 2000+<it> <fmt>^uy^hfst/IT 2000 to extract text within <mark> and </mark>^xx \n\n");
1564            printf("    <id>            tag component \n");
1565            printf("    <it>            indexing technique 2000+IT (IT=0..8, 1000..1008) \n");
1566            printf("    <fmt>           format specification generating <dlm><mark><dlm><mark><text></mark> \n\n");
1567            printf("    apply indexing technique IT to text embedded in marks <mark> and </mark> \n\n");
1568            printf(" mx null \"fst=2 2004 '#<B>#','xxx <B>word1 word2</B> xxx'\" \n");
1569            printf(" mfn=     1 \n");
1570            printf("   2  �WORD^m1^o1^c1^l1� \n");
1571            printf("   2  �WORD^m1^o1^c2^l1� \n\n");
1572            printf("pft=_<tag>^uy^hpft=_ to input data from stdin^xx \n\n");
1573            printf("    <tag>           field tag \n\n");
1574            printf("    read a stdin input line and add the input data as a new occurrence of field <tag> \n\n");
1575            printf(" mx null \"proc=if mfn=1 then _10,putenv('TAG10='v10) fi\" pft=mfn,x1,getenv('TAG10'),/ to=2 \n");
1576            printf(" input line \n");
1577            printf(" 000001 input line \n");
1578            printf(" 000002 input line \n\n");
1579            printf("pft=getenv('cgi=',<varfmt>)^hpft=getenv('cgi='var) to get CGI data^xx \n\n");
1580            printf("    <varfmt>        format specification generating a cgi variable name \n\n");
1581            printf("    output the contents of the specified cgi variable \n");
1582            printf("    multiple occurrences are separeted by a %c char \n\n",'%');
1583            printf(" set REQUEST_METHOD=GET \n");
1584            printf(" set QUERY_STRING=db~cds&bool~plants*water&bool~another \n");
1585            printf(" mx null pft=getenv('cgi=db')/getenv('cgi=bool')/ \n");
1586            printf(" cds \n");
1587            printf(" plants*water%another \n\n");
1588            printf("pft=getenv('tmp=',[<pathfmt>])^hpft=getenv('tmp=') to get a temporary file name^xx \n\n");
1589            printf("    <pathfmt>       format specification generating a path name \n\n");
1590            printf("    get a temporary empty file name in the current working directory or in the specified path \n");
1591            printf("    if 'ci_tempdir' is specified then path is obtained from the following environment variables: ci_tempdir, temp, tmp \n\n");
1592            printf(" mx null pft=getenv('tmp=') \n");
1593            printf(" TMP1.$$$ \n\n");
1594            printf(" mx null pft=getenv('tmp=','ci_tempdir') \n");
1595            printf(" C:\\windows\\TEMP\\TMP1.$$$ \n\n");
1596            printf(" set ci_tempdir=C:\\work \n");
1597            printf(" mx null pft=getenv('tmp=','ci_tempdir') \n");
1598            printf(" C:\\work\\TMP1.$$$ \n\n");
1599            printf(" echo ci_tempdir=C:\\work2 >xcip \n");
1600            printf(" mx cipar=xcip null pft=getenv('tmp=','ci_tempdir') \n");
1601            printf(" C:\\work2\\TMP1.$$$ \n\n");
1602/*          printf("fst={<fst_spec>|@[<file>]} \n\n");
1603            printf("    <fst_spec>      fstspec or semicolon separated fstspec list \n");
1604            printf("    @               fstspec from standard file <dbn>.fst \n");
1605            printf("    @<file>         fstspec from file <file> \n\n");
1606            printf("    add extracted key+posting elements to data fields \n");
1607            printf("    tagged according fstspec specification \n\n");
1608*/
1609            printf("syntax^uy^hsyntax^xx \n\n");
1610            printf(" mx \n");
1611            mxsyntax("", ibufsiz/(1024*1024), ptabcategories/3, ptabwidth);
1612            MXEXIT(0);
1613        }
1614#endif /* WHATISNEW */
1615
1616    if (argc == 2 && strcmp(argv[1],"what") == 0) {
1617        printf("%s",cicopyr("?Utility MX"));
1618#if BEFORE20010109
1619        printf("\n");
1620        printf("MFRL=%ld FMT=%ld ",maxmfrl,fmtasize);
1621#endif
1622        printf("\n");
1623        MXEXIT(0);
1624    }
1625
1626    if (argc == 1) {
1627        mxsyntax("  ", ibufsiz/(1024*1024), ptabcategories/3, ptabwidth);
1628        MXEXIT(0);
1629    }
1630
1631
1632    p=argv[argnext];
1633    if (sscanf(p,"files=%2d",&n) == 1) {
1634#if OPEN30
1635    d33_regs.h.ah = 0x67;   /* Set handle count */
1636        d33_regs.x.bx = n;      /* no of handles */
1637#if 1 /* DOS32BITS */
1638        newax=intdosx(&d33_regs,&d33_regs,&d33_sregs);
1639#else
1640    newax=intdos(&d33_regs,&d33_regs);
1641#endif
1642        if (d33_regs.x.cflag)
1643            fprintf(stderr,"AX = %04x [%02d]\n",newax,n);
1644#endif
1645    argnext++;
1646    }
1647
1648#if DBXMSTXL
1649    p=NULL;
1650    for (i=argnext; i < argc; i++) if (strncmp(argv[i],"mstxl?",6) == 0 || strncmp(argv[i],"mstxl=",6) == 0) { p=argv[i]; break; }
1651    if (p) {
1652    }
1653#endif
1654
1655#if CIWTF                                /* WTFUN support */
1656    p=NULL;
1657    for (i=argnext; i < argc; i++) if (strncmp(argv[i],"cipar?",6) == 0 || strncmp(argv[i],"cipar=",6) == 0) { p=argv[i]; break; }
1658    /* setup wtfnew
1659    */
1660    if (!ciawtfp) if (p) if (*(p+6)) if (dbxciset(p+6)) fatal(p);
1661    if (!ciawtfp) if (dbxciset("mx.cip")) dbxciset(NULL); // optional mx.cip
1662    if (!ciawtfp) fatal("mx/ciawtfp");
1663    if (ciawtfp) maxmfrl=rec_maxmfrl; //maxmfrl local //fmt_fsiz set by dbxinit
1664#else //CIWTF
1665    /* forca carga de rec_maxmfrl */
1666    p=dbxcipar(NULL,"maxmfrl",'=');
1667    if (dbxcipok) { sscanf(p,"%ld",&rec_maxmfrl); maxmfrl=rec_maxmfrl; }
1668    fmt_fsiz=maxmfrl;
1669/* printf("+++maxmfrl=%ld\n",maxmfrl); */
1670#endif //CIWTF
1671
1672    /*
1673        Parsing
1674    */
1675    for (i=argnext; (i < argc) || fpprm; ) {
1676
1677        /* get parameter */
1678
1679        if (fpprm) {
1680            p=fgets(prmbuff,PRMSIZE-1,fpprm);
1681            if (p) p[strlen(p)-1]='\0';  /* strip \n */
1682            else {
1683                fclose(fpprm);
1684                fpprm = (nfpprms-- > 0) ? vfpprm[nfpprms] : NULL;
1685                if (parmtrace) if (fpprm) printf("+++ in/pop= %p\n",fpprm);
1686                continue;
1687            }
1688        }
1689        else {
1690            if (i >= argc) fatal("i >= argc");
1691            p=argv[i++];
1692        }
1693
1694        n=strlen(p);
1695        q=p+n-1;
1696        for (; n; n--, p++) if (!isspace(*p)) break;                    /* leading */
1697        if (strncmp(p,"seq?",4) == 0 || strncmp(p,"seq=",4) == 0 || strncmp(p,"seq/",4) == 0) ;      /* "seq=x " */
1698        else for (; n; n--, q--) if (isspace(*q)) *q='\0'; else break;  /* trailing */
1699        if (n < 0) fatal("bug/parm");
1700        if (n == 0) continue;
1701#if MXCOMMENT
1702        if (*p == '/')   if (*(p+1) == '*')       { p+=2;  incomment=1; }
1703        if (incomment) {
1704            n=0;
1705            q=strstr(p,"*/");
1706            if (q) { p=q+2; incomment=0; n=strlen(p); }
1707            if (n == 0) continue;
1708        }
1709#endif /* MXCOMMENT */
1710        if (parmtrace) printf("+++ parm=%s !\n",p);
1711
1712
1713        if (nprms >= MAXNPRM) fatal("MAXNPRM overflow");
1714        if ((vprmp[nprms]=(PRMSTRU *)ALLOC((ALLOPARM)sizeof(PRMSTRU)))
1715                        == (PRMSTRU *)ALLONULL) fatal("ALLOC/prm/stru");
1716        vprmp[nprms]->plen=strlen(p);
1717        if ((vprmp[nprms]->p=(char *)ALLOC((ALLOPARM)(vprmp[nprms]->plen+1)))
1718                                == (char *)ALLONULL) fatal("ALLOC/prm/p");
1719        memcpy(vprmp[nprms]->p,p,vprmp[nprms]->plen+1); /* '\0' */
1720
1721        p=vprmp[nprms++]->p;
1722
1723
1724        /* in= parameter */
1725
1726        if (strncmp(p,"in?",3) == 0 || strncmp(p,"in=",3) == 0) {
1727            q=p+3;
1728            if (fpprm) {
1729                if (parmtrace) printf("+++ in/push=%p\n",fpprm);
1730                if (nfpprms >= MAXNFPRM) fatal(p);
1731                vfpprm[nfpprms++]=fpprm;
1732            }
1733            if (parmtrace) printf("+++ in/open=%s\n",q);
1734            if ((fpprm=fopen(dbxcipar(NULL,q,'='),"r")) == NULL)
1735                fatal(p);
1736            continue;
1737        }
1738
1739
1740        /* setup parameters */
1741
1742#if MXFULLINV || MXIFUPD
1743        if (strcmp(p,"-reset") == 0) {
1744            parmmenosreset=1;
1745            continue;
1746        }
1747#endif
1748#if MXFULLINV
1749        if (strcmp(p,"-balan") == 0) {
1750            fullinv_balan=0;
1751            continue;
1752        }
1753#endif
1754
1755        if (*p == '-') {
1756            minus1++;
1757            if (minus1 == 1) {
1758                parmcontrol=parmleader=parmxref=parmdir=parmfields=1;
1759            }
1760        }
1761        if (strcmp(p,"-all") == 0) {
1762            parmcontrol=parmleader=parmxref=parmdir=parmfields=0;
1763            continue;
1764        }
1765        if (strcmp(p,"-control") == 0) {
1766            parmcontrol=0;
1767            continue;
1768        }
1769        if (strcmp(p,"-leader") == 0) {
1770            parmleader=0;
1771            continue;
1772        }
1773        if (strcmp(p,"-xref") == 0) {
1774            parmxref=0;
1775            continue;
1776        }
1777        if (strcmp(p,"-dir") == 0) {
1778            parmdir=0;
1779            continue;
1780        }
1781        if (strcmp(p,"-fields") == 0) {
1782            parmfields=0;
1783            continue;
1784        }
1785
1786        if (strcmp(p,"+hits") == 0) {
1787            parmhits=1;
1788            continue;
1789        }
1790#if MXFST
1791        if (strcmp(p,"+fix") == 0) {
1792            cifstfix=1;
1793            continue;
1794        }
1795        if (strcmp(p,"+fix/m") == 0) {
1796            cifstfix=cifstfim=1;
1797            continue;
1798        }
1799#endif
1800        if (*p == '+') {
1801            plus1++;
1802            if (plus1 == 1)
1803                parmcontrol=parmleader=parmxref=parmdir=parmfields=0;
1804        }
1805        if (strcmp(p,"+all") == 0) {
1806            parmcontrol=parmleader=parmxref=parmdir=parmfields=1;
1807            continue;
1808        }
1809        if (strcmp(p,"+control") == 0) {
1810            parmcontrol=1;
1811            continue;
1812        }
1813        if (strcmp(p,"+leader") == 0) {
1814            parmleader=1;
1815            continue;
1816        }
1817        if (strcmp(p,"+xref") == 0) {
1818            parmxref=1;
1819            continue;
1820        }
1821        if (strcmp(p,"+dir") == 0) {
1822            parmdir=1;
1823            continue;
1824        }
1825        if (strcmp(p,"+fields") == 0) {
1826            parmfields=1;
1827            continue;
1828        }
1829        if (strncmp(p,"from?",5) == 0 || strncmp(p,"from=",5) == 0) {
1830            if (sscanf(p+5,"%ld",&parmfrom) != 1)
1831                fatal(p);
1832            continue;
1833        }
1834        if (strncmp(p,"to?",3) == 0 || strncmp(p,"to=",3) == 0) {
1835            if (sscanf(p+3,"%ld",&parmto) != 1)
1836                fatal(p);
1837            continue;
1838        }
1839        if (strncmp(p,"loop?",5) == 0 || strncmp(p,"loop=",5) == 0) {
1840            if (sscanf(p+5,"%ld",&parmloop) != 1)
1841                fatal(p);
1842            continue;
1843        }
1844        if (strncmp(p,"count?",6) == 0 || strncmp(p,"count=",6) == 0) {
1845            if (sscanf(p+6,"%ld",&parmcount) != 1)
1846                fatal(p);
1847            continue;
1848        }
1849        if (strncmp(p,"tell?",5) == 0 || strncmp(p,"tell=",5) == 0) {
1850            if (sscanf(p+5,"%ld",&parmtell) != 1)
1851                fatal(p);
1852            continue;
1853        }
1854
1855        if (strcmp(p,"trace") == 0) {
1856            parmtrace=1;
1857            continue;
1858        }
1859        if (strcmp(p,"trace=dbx") == 0) {
1860            dbxtrace=1;
1861            continue;
1862        }
1863        if (strcmp(p,"trace=rec") == 0) {
1864            rectrace=dectrace=1;
1865            continue;
1866        }
1867        if (strcmp(p,"trace=dec") == 0) {
1868            dectrace=1;
1869            continue;
1870        }
1871        if (strcmp(p,"trace=trm") == 0) {
1872            trmtrace=1;
1873            continue;
1874        }
1875#if CIB71
1876        if (strcmp(p,"trace=b70") == 0) {
1877            b70trace=1;
1878            continue;
1879        }
1880#else /* CIB71 */
1881#if LIND || CIB64
1882        if (strcmp(p,"trace=b50") == 0) {
1883            b50trace=1;
1884            continue;
1885        }
1886#else
1887        if (strcmp(p,"trace=b40") == 0) {
1888
1889            b40trace=1;
1890            continue;
1891        }
1892#endif
1893#endif /* CIB71 */
1894        if (strcmp(p,"trace=fmt") == 0) {
1895            fmttrace=1;
1896            continue;
1897        }
1898        if (strcmp(p,"trace=fst") == 0) {
1899            fsttrace=1;
1900            continue;
1901        }
1902        if (strcmp(p,"trace=all") == 0) {
1903            parmtrace=dbxtrace=rectrace=trmtrace=
1904#if CIB71
1905        b70trace=
1906#else /* CIB71 */
1907#if LIND || CIB64
1908            b50trace=
1909#else
1910            b40trace=
1911#endif
1912#endif /* CIB71 */
1913        fmttrace=fsttrace=1;
1914            continue;
1915        }
1916
1917        if (strncmp(p,"cipar?",6) == 0 || strncmp(p,"cipar=",6) == 0) {
1918#if CIWTF                                /* WTFUN support */
1919#else //CIWTF
1920            if ((dbxcipfp=fopen(p+6,"r")) == NULL) fatal(p);
1921            /* forca carga de rec_maxmfrl */
1922            p=dbxcipar(NULL,"maxmfrl",'=');
1923            if (dbxcipok) { sscanf(p,"%ld",&rec_maxmfrl); maxmfrl=rec_maxmfrl; }
1924            fmt_fsiz=maxmfrl;
1925#endif //CIWTF
1926            continue;
1927        }
1928
1929        if (strcmp(p,"mfrl") == 0) {
1930            parmmfrl=LEADER-1;
1931            continue;
1932        }
1933        if (strncmp(p,"mfrl?",5) == 0 || strncmp(p,"mfrl=",5) == 0) {
1934            if (sscanf(p+5,"%ld",&maxmfrl) != 1)
1935                fatal(p);
1936#if CIWTF                                /* WTFUN support */
1937            if (maxmfrl < (LONGX)MSNVSPLT || (RECHSIZE+maxmfrl) > ALLOMAXV) maxmfrl=MAXMFRL;
1938            rec_maxmfrl=maxmfrl; // mx only
1939            fmt_fsiz=maxmfrl;    // mx only
1940#else //CIWTF
1941            if (maxmfrl > rec_maxmfrl) rec_maxmfrl=maxmfrl;
1942            fmt_fsiz=maxmfrl;
1943#endif //CIWTF
1944            continue;
1945        }
1946
1947#if BEFORE20060120 || 1  // tem que aceitar
1948        if (strncmp(p,"fmtl?",5) == 0 || strncmp(p,"fmtl=",5) == 0) {
1949            if (sscanf(p+5,"%ld",&fmtasize) != 1)
1950                fatal(p);
1951            continue;
1952        }
1953#endif //BEFORE20060120
1954
1955        if (strncmp(p,"load?",5) == 0 || strncmp(p,"load=",5) == 0) {
1956            if (sscanf(p+5,"%ld",&parmload) != 1)
1957                fatal(p);
1958            if (parmload > ALLOMAXV) {
1959                parmload = ALLOMAXV;
1960                fprintf(stderr,"+++ load=%ld\n",parmload);
1961            }
1962            continue;
1963        }
1964
1965        if (strncmp(p,"pages?",6) == 0 || strncmp(p,"pages=",6) == 0) {
1966            /* NXPAGES */
1967            p=p+6;
1968            for (level=0; level < MAXLIV; level++)
1969                if (*p)
1970                    if (atoi(p)) {
1971                        NXPAGES[level]=atoi(p);
1972                        if (parmtrace)
1973                            printf("+++ level %d = %d pages\n",
1974                                level,NXPAGES[level]);
1975                        while (isdigit(*p)) p++;
1976                        if (*p == ',') p++;
1977                    }
1978            continue;
1979        }
1980
1981#if CIB71
1982        if (strncmp(p,"b70?",4) == 0 || strncmp(p,"b70=",4) == 0 ||
1983            strncmp(p,"b50?",4) == 0 || strncmp(p,"b50=",4) == 0 ||
1984            strncmp(p,"b40?",4) == 0 || strncmp(p,"b40=",4) == 0 ||
1985            strncmp(p,"tmpx?",5) == 0 || strncmp(p,"tmpx=",5) == 0) {
1986#endif /* CIB71 */
1987            /* mxbool/b40 query data base */
1988            if (strncmp(p,"tmpx?",5) == 0 || strncmp(p,"tmpx=",5) == 0) booldbnp=p+5; else booldbnp=p+4;
1989            if (strncmp(booldbnp,"create=",7) == 0) {
1990                booldbnp+=7;
1991                recisis0(booldbnp);
1992            }
1993            continue;
1994        }
1995#if CIB71
1996#else /* CIB71 */
1997#if LIND || CIB64
1998        if (strncmp(p,"nb1?",4) == 0 || strncmp(p,"nb1=",4) == 0) {
1999            /* mxbool/b62 nbytes1 parm [b5irxbytes=nbytes1;] */
2000            if (sscanf(p+4,"%ld",&boolnby1) != 1)
2001                fatal(p);
2002            continue;
2003        }
2004        if (strncmp(p,"nbb?",4) == 0 || strncmp(p,"nbb=",4) == 0) {
2005            /* mxbool/b62 b6bufferp->bufsiz parm [b6_hballoc(bufsiz,&b6bufferp);] */
2006            if (sscanf(p+4,"%ld",&boolnbyb) != 1)
2007                fatal(p);
2008            continue;
2009        }
2010        if (strncmp(p,"nb0?",4) == 0 || strncmp(p,"nb0=",4) == 0) {
2011            /* mxbool/b62 b5maxbyts0 parm [if (b5maxbyts0) b5maxbyts=b5maxbyts0;] */
2012            if (sscanf(p+4,"%ld",&boolnby0) != 1)
2013                fatal(p);
2014            continue;
2015        }
2016#else
2017        if (strncmp(p,"nb2?",4) == 0 || strncmp(p,"nb2=",4) == 0) {
2018            /* mxbool/b40 nbytes2 parm */
2019            if (sscanf(p+4,"%ld",&boolnby2) != 1)
2020                fatal(p);
2021            continue;
2022        }
2023#endif
2024#endif /* CIB71 */
2025        if (strncmp(p,"btell?",6) == 0 || strncmp(p,"btell=",6) == 0) {
2026            /* mxbool/b40 tell parm */
2027            if (sscanf(p+6,"%ld",&booltell) != 1)
2028                fatal(p);
2029            continue;
2030        }
2031#if CIB71
2032#else /* CIB71 */
2033#if LIND || CIB64
2034#if 000
2035        if (strncmp(p,"b50t?",5) == 0 || strncmp(p,"b50t=",5) == 0) {
2036            /* mxbool/b5_run() tmp file name */
2037            strcpy(b5_tmpnam,p+5);
2038            continue;
2039        }
2040#endif
2041#else
2042        if (strncmp(p,"b40t?",5) == 0 || strncmp(p,"b40t=",5) == 0) {
2043            /* mxbool/b4_run() tmp file name */
2044            strcpy(b4_tmpnam,p+5);
2045            continue;
2046        }
2047#endif
2048#endif /* CIB71 */
2049        if (strncmp(p,"b40u?",5) == 0 || strncmp(p,"b40u=",5) == 0) {
2050            /* loaductb(mi_gidbnp,isisuctab,p+5); */
2051            if (!loaductb(mi_gidbnp,isisuctab,p+5)) fatal(p); /* AOT, 02/04/2001 */
2052            continue;
2053        }
2054
2055        if (strncmp(p,"uctab?",6) == 0 || strncmp(p,"uctab=",6) == 0) {
2056            if (strcmp(p+6,"ansi") == 0) {
2057                memcpy(isisuctab,ansiuctab,256/*sizeof(ansiuctab)*/);
2058            } else {
2059                /* loaductb(mi_gidbnp,isisuctab,p+6); */
2060                if (!loaductb(mi_gidbnp,isisuctab,p+6)) fatal(p); /* AOT, 02/04/2001 */
2061            }
2062            continue;
2063        }
2064        if (strncmp(p,"actab?",6) == 0 || strncmp(p,"actab=",6) == 0) {
2065            memset(isiswctab,0x00,256);
2066            if (strcmp(p+6,"ansi") == 0) {
2067                for (isiswctot=0; ansiactab[isiswctot]; isiswctot=isiswctot+1)
2068                    isiswctab[ansiactab[isiswctot]]=1;
2069            } else {
2070                unsigned char ubuffup[256];
2071                /* loadactb(mi_gidbnp,ubuffup,p+6); */
2072                if (!loadactb(mi_gidbnp,ubuffup,p+6)) fatal(p); /* AOT, 02/04/2001 */
2073                for (isiswctot=0; ubuffup[isiswctot]; isiswctot=isiswctot+1)
2074                    isiswctab[ubuffup[isiswctot]]=1;
2075            }
2076            continue;
2077        }
2078
2079        if (strncmp(p,"dupr?",5) == 0 || strncmp(p,"dupr=",5) == 0 ||
2080            strncmp(p,"dupl?",5) == 0 || strncmp(p,"dupl=",5) == 0) {
2081            parmdupp=p+5;
2082            parmdupx=DUPPRIGHT;
2083            if (strncmp(p,"dupl",5-1) == 0)
2084                parmdupx=DUPPLEFT;
2085            continue;
2086        }
2087
2088        if (strncmp(p,"p1?",3) == 0 || strncmp(p,"p1=",3) == 0) {
2089            prompt1p=p+3;
2090            continue;
2091        }
2092        if (strncmp(p,"p2?",3) == 0 || strncmp(p,"p2=",3) == 0) {
2093            prompt2p=p+3;
2094            continue;
2095        }
2096
2097        if (strcmp(p,"nowait") == 0 || strcmp(p,"now") == 0) {
2098            parmwait=0;
2099            continue;
2100        }
2101
2102#if BEFORE20000323           /* because some BRM's GCC - ask rpiva */
2103        if (strcmp(p,"stderr=off") == 0) {
2104            cistderr=stdout;
2105            continue;
2106        }
2107#endif
2108
2109#if MULTI
2110        if (strcmp(p,"mono") == 0) {
2111            cipnetws=MONONETS;
2112            continue;
2113        }
2114        if (strcmp(p,"mast") == 0) {
2115            cipnetws=MASTNETS;
2116            continue;
2117        }
2118        if (strcmp(p,"full") == 0) {
2119            cipnetws=FULLNETS;
2120            continue;
2121        }
2122#endif
2123        if (strncmp(p,"k1=",3) == 0) {
2124            parmk1p=p+3;
2125            continue;
2126        }
2127        if (strncmp(p,"k2=",3) == 0) {
2128            parmk2p=p+3;
2129            continue;
2130        }
2131
2132
2133#if CIWTF
2134#else //CIWTF
2135        /* setup alloc
2136        */
2137        q=dbxcipar(NULL,"maxmfrl",'='); if (dbxcipok) sscanf(q,"%ld",&maxmfrl);
2138        if (maxmfrl < (LONGX)MSNVSPLT || (RECHSIZE+maxmfrl) > ALLOMAXV) maxmfrl=MAXMFRL;
2139        rec_maxmfrl=maxmfrl;
2140        fmt_fsiz=maxmfrl;
2141#endif //CIWTF
2142
2143
2144        /* positional parameters */
2145
2146        if (!dbnp) {
2147
2148            /* allocate global buffer (former buffup, which is defined by mxrun.h) */
2149            nbytes = (mx_buplen) ? mx_buplen: maxmfrl+maxmfrl;
2150            if (nbytes > ALLOMAXV) nbytes=ALLOMAXV;
2151            mx_buplen=nbytes;
2152            if (parmtrace) printf("+++ mx_bup=%ld bytes\n",mx_buplen);
2153            if ((mx_bup=(char *)ALLOC((ALLOPARM)nbytes)) == (char *)ALLONULL)
2154                fatal("ALLOC/mx_bup");
2155
2156            recallok((crec=nrecs),(LONGX)sizeof(M0STRU));
2157            recallok((irec=nrecs),maxmfrl); /* b40 */
2158
2159            if (strncmp(p,"db=",3) == 0) p+=3;
2160            if (strncmp(p,"dbn=",4) == 0) p+=4;
2161
2162            /* allow mx <dbn>.mst */
2163            if (strlen(p)>strlen(mx1extp)) {
2164                int len=strlen(p);
2165                int n=strlen(mx1extp);
2166                if (memicmp(p+len-n,mx1extp,n) == 0) p[len-n]='\0';
2167            }
2168
2169#if DIR_FILE
2170            if (strncmp(p,"list=",5) == 0) {
2171                char *directory=p+5;
2172              //char *pattern=NULL,*q,c='\0';
2173              //for (q=directory; *q; q++) if (*q='/') pattern=q+1;
2174              //if (pattern) if (!*pattern) pattern=NULL; 
2175              //if (pattern) { c=(*pattern); *pattern='\0'; }
2176                direntdp = opendir (directory);
2177              //if (pattern) *pattern=c;
2178                if (direntdp != NULL)
2179                {
2180                    //char *q; int n,x;
2181                  //while ((direntep = readdir (direntdp)) != NULL)
2182                  //{
2183                //    int x=1;
2184                //    if (pattern) {
2185                //      char *q=(char *)direntep->d_name;
2186                //      int n=strlen(q);
2187                //      if (strcmp(q+n-strlen(".mak"),".mak")) x=0;
2188                //    }
2189                //    if (x)
2190                  //  puts (direntep->d_name);
2191                  //}
2192                  //(void) closedir (direntdp);
2193                }
2194                else
2195                //fatal("Couldn't open the directory");
2196                  fatal(p);
2197                tmpseq=1;
2198            }
2199#endif
2200
2201            if (strncmp(p,"dict=",5) == 0) {
2202                xtp=p; p+=5;
2203                parmkdbnp=p; p="null";
2204                if ((q=strchr(parmkdbnp,',')) != NULL) {
2205                    *q++='\0';
2206                    if (sscanf(q,"%ld",&xtl1) != 1) fatal(xtp);
2207                    parmktag1=(UWORD)xtl1;
2208                    while (isdigit(*q)) q++;
2209                    if (*q) {
2210                        if (*q++ != ',') fatal(xtp);
2211                        if (sscanf(q,"%ld",&xtl2) != 1) fatal(xtp);
2212                        parmktag2=(UWORD)xtl2;
2213                        while (isdigit(*q)) q++;
2214                        if (*q == '/') { q++;
2215                            if (sscanf(q,"%ld",&parmkkeep2) != 1) fatal(xtp);
2216                            if (parmkkeep2 < 1) fatal(xtp);
2217                            /*while (isdigit(*q)) q++; */
2218                        }
2219                        parmkpostings=1;
2220                    }
2221                }
2222            }
2223
2224            if (strcmp(p,"tmp") == 0) {
2225                tmpseq=1;
2226            }
2227            else {
2228                if (strncmp(p,"seq?",4) == 0 || strncmp(p,"seq=",4) == 0 || strncmp(p,"seq/",4) == 0) {
2229                    unsigned blass=0;
2230                    unsigned blas2=0;
2231                    q=p+4;
2232                    if (strncmp(p,"seq/",4) == 0) {
2233                        p+=3; //skip seq
2234                        while (*p == '/') {
2235                            if (strncmp(p,"/fi:"   ,4) == 0) { for (p+=4; isdigit(*p); p++) blas2=blas2*10+((int)(*p)-(int)'0'); continue; }
2236                            for (p++; isdigit(*p); p++) blass=blass*10+((int)(*p)-(int)'0');
2237                            if (*p=='k')   p++;
2238                            if (*p=='m') { p++; blass*=1024; }
2239                        } /* while /option */
2240                        if (*p == '?' || *p == '=') p++; else fatal(q-4);
2241                        if (parmtrace) printf("+++ ibufsiz=%ld Kbytes log=%ld\n",(LONGX)blass,(LONGX)blas2);
2242                        if (blass>=1) ibufsiz=blass*1024;
2243                        if (blas2>=1) parmseqlog=blas2;
2244                        q=p;
2245                    }
2246                    strcpy(line,q);
2247                    q=line+strlen(line)-1; parmxseq='\0';
2248                    if (strlen(line) > 1) {
2249                        if (*(q-1) == '\\') { parmxseq= *q; if (*q == 'n') parmxseq='\n'; *(q-1)='\0'; }
2250                    }
2251                    if (!parmxseq) if (!isalnum(*q)) {parmxseq= *q; *q='\0';}
2252                    if (parmtrace) printf("+++ %s|=%02x=%c\n",line,parmxseq,parmxseq);
2253                    tmpseq=1;
2254                    if (strcmp(line,"con") == 0) fpseq=stdin; else
2255#if BEFORE20060308
2256                    if ((fpseq=fopen(dbxcipar(NULL,line,'='),"r")) == NULL) fatal(p);
2257#else
2258                    {
2259                        n1fdseq=0;
2260                        n1left=0;
2261                        n1iptr=NULL;
2262                        n1count=0;
2263                        /* allocate input buffer */
2264                        obufsiz=(mx_buplen-4-BUFSIZ)/2;  ubufsiz=obufsiz+BUFSIZ;
2265                        obuf=mx_bup; ubuf=obuf+obufsiz+2;
2266                        if (parmtrace) printf("+++ ibuf=%ld bytes\n",(LONGX)ibufsiz);
2267                        if ((ibuf=(char *)ALLOC((ALLOPARM)ibufsiz+1)) == (char *)ALLONULL) fatal("ALLOC/ibuf");
2268                        if (recfgetseq(line, parmxseq, parmseqlog, ibuf, ibufsiz, obuf,       0, ubuf, ubufsiz, &n1fdseq, &n1left, &n1iptr, &n1count) <= 0) fatal(p);
2269                    }
2270#endif
2271                }
2272#if XML_FILE
2273                else {
2274                    if (strncmp(p,"xml?",4) == 0 || strncmp(p,"xml=",4) == 0 || strncmp(p,"xml/",4) == 0) {
2275                        unsigned blass=0;
2276                        unsigned blas2=0;
2277                        q=p+4;
2278                        if (strncmp(p,"xml/",4) == 0) {
2279                            p+=3; //skip seq
2280                            while (*p == '/') {
2281                                if (strncmp(p,"/fi:"   ,4) == 0) { for (p+=4; isdigit(*p); p++) blas2=blas2*10+((int)(*p)-(int)'0'); continue; }
2282                                for (p++; isdigit(*p); p++) blass=blass*10+((int)(*p)-(int)'0');
2283                                if (*p=='k')   p++;
2284                                if (*p=='m') { p++; blass*=1024; }
2285                            } /* while /option */
2286                            if (*p == '?' || *p == '=') p++; else fatal(q-4);
2287                            if (parmtrace) printf("+++ ibufsiz=%ld Kbytes log=%ld\n",(LONGX)blass,(LONGX)blas2);
2288                            if (blass>=1) ibufsiz=blass*1024;
2289                            if (blas2>=1) parmseqlog=blas2;
2290                            q=p;
2291                        }
2292                        p = strchr(p, ',');
2293                        if (!p) fatal("missing ,");
2294                        *p = '\0'; p++;
2295                        strcpy(tagName, p);
2296                        strcpy(line,q);
2297                        q=line+strlen(line)-1; parmxseq='\0';
2298                        if (strlen(line) > 1) {
2299                            if (*(q-1) == '\\') { parmxseq= *q; if (*q == 'n') parmxseq='\n'; *(q-1)='\0'; }
2300                        }
2301                        if (!parmxseq) if (!isalnum(*q)) {parmxseq= *q; *q='\0';}
2302                        if (parmtrace) printf("+++ %s|=%02x=%c\n",line,parmxseq,parmxseq);
2303                        tmpseq=1;
2304                        n1fdxml=0;
2305                        n1left=0;
2306                        n1iptr=NULL;
2307                        n1count=0;
2308                        /* allocate input buffer */
2309                        obufsiz=(mx_buplen-4-BUFSIZ)/2;  ubufsiz=obufsiz+BUFSIZ;
2310                        obuf=mx_bup; ubuf=obuf+obufsiz+2;
2311                        if (parmtrace) printf("+++ ibuf=%ld bytes\n",(LONGX)ibufsiz);
2312                        if ((ibuf=(char *)ALLOC((ALLOPARM)ibufsiz+1)) == (char *)ALLONULL) fatal("ALLOC/ibuf");
2313                        if (recfgetxml(line, ibuf, ibufsiz, obuf,       0, ubuf, ubufsiz, &n1fdxml, &n1left, &n1iptr, &n1count) <= 0) fatal(p);
2314                    }
2315#endif /* XML_FILE */
2316                else {
2317                    if (strncmp(p,"iso?",4) == 0 || strncmp(p,"iso=",4) == 0) {
2318                        q=p+4;
2319                        if (strchr(q,'=')) {
2320                            if (strncmp(q,"marc=",5) == 0) {  /* AOT, 06/06/2005 */
2321                                q+=5;
2322                                isfix=(-1);    /*  no CRLF */
2323                                lrfix=ISOBSIZ; /* set to max line len */
2324                                iso_ismarc=1;
2325                            }
2326                            else
2327                            if (strncmp(q,"0=",2) == 0) {    /* AOT, 06/06/2005 */
2328                                q+=2;
2329                                isfix=0;      /*  single line */
2330                                lrfix=ISOBSIZ;
2331                            }
2332                            else {
2333                                if (sscanf(q,"%d=%s",&lrfix,line) != 2) fatal(p);
2334                                q=strchr(q,'=')+1;
2335                                isfix=1;
2336                            }
2337                        }
2338                        else
2339#if MPE
2340                            { isfix=1; lrfix=80; }
2341#else
2342                            { isfix=0; lrfix=80; }
2343#endif
2344                        if (iso_open(NULL,q,0,lrfix,isfix) <= 0) fatal(p);
2345                        parmiso1=1;
2346                        tmpseq=1;
2347                    }
2348                    else if (parmkdbnp) {
2349                             mi_gidbnp=parmkdbnp; dbnp="null";
2350                         }
2351                         else mi_gidbnp=dbnp=p;
2352                }
2353#if XML_FILE
2354                }
2355#endif /* XML_FILE */
2356            }
2357
2358#if DELETETMPSEQ
2359            if (tmpseq) recisis0(dbnp="tmpseq");
2360#else
2361            if (tmpseq) dbnp="null";
2362#endif
2363
2364            if (parmload) mstsetup(dbnp,parmload,parmload);        /* invsetup is called in mxbol()/mj_join() */
2365
2366            if (parmtrace) printf("+++ RECORD %ld = %s#%ld \n",crec,dbnp,0L);
2367            RECORD(crec,dbnp,0L);
2368
2369            if (parmtrace) printf("+++ RECORD %ld = %s#%ld \n",irec,dbnp,1L);
2370            RECORD(irec,dbnp,1L);
2371
2372            continue;
2373
2374        } /* end okdbnp */
2375
2376
2377
2378        /* processing parameters */
2379
2380        if (!dbnp) fatal(p);
2381
2382#if IFUPDATE
2383        if (strcmp(p,"mfbw") == 0) { parmmfbw=1; continue; }
2384#endif
2385
2386#if TB
2387        if (strncmp(p,"tb?",3) == 0 || strncmp(p,"tb=",3) == 0 ||
2388            strncmp(p,"tbin?",5) == 0 || strncmp(p,"tbin=",5) == 0) {
2389            if (strncmp(p,"tb?",3) == 0 || strncmp(p,"tb=",3) == 0) q=p+3; else q=p+5;
2390            if (sscanf(q,"%ld",&ld) != 1) fatal(p);
2391             if (ntagbin >= MAXTBIN) fatal(p);
2392            tagbin=(UWORD)ld; vtagbin[ntagbin++]=tagbin;
2393            continue;
2394        }
2395#endif /* TB */
2396
2397        if (strncmp(p,"join?",5) == 0 || strncmp(p,"join=",5) == 0 ||
2398            strncmp(p,"jchk?",5) == 0 || strncmp(p,"jchk=",5) == 0 ||
2399            strncmp(p,"jch0?",5) == 0 || strncmp(p,"jch0=",5) == 0 ||
2400            strncmp(p,"jch1?",5) == 0 || strncmp(p,"jch1=",5) == 0) {
2401
2402            jchk=0;
2403            if (strncmp(p,"jchk",5-1) == 0)
2404                jchk=1;
2405            if (strncmp(p,"jch0",5-1) == 0)
2406                jchk= -1;
2407            if (strncmp(p,"jch1",5-1) == 0)
2408                jchk= -2;
2409
2410            *line='\0';
2411            for (q=p+5, n=0; *q; q++, n++)
2412                if (*q == '?' || *q == '=') {
2413                    memcpy(line,p+5,n); line[n]='\0';
2414                    break;
2415                }
2416            if (!*line || !*(q+1))
2417                fatal(p);
2418            if (mj_scan(xmxp,dbnp,line,q+1,jchk)) MXEXIT(1);
2419            continue;
2420        }
2421        if (strncmp(p,"jmax?",5) == 0 || strncmp(p,"jmax=",5) == 0) {
2422            /* mj_join() */
2423            if (sscanf(p+5,"%ld",&mj_jmax) != 1)
2424                fatal(p);
2425            continue;
2426        }
2427        if (strncmp(p,"jtag?",5) == 0 || strncmp(p,"jtag=",5) == 0) {
2428            /* mj_join() */
2429            if (sscanf(p+5,"%ld",&ld) != 1)
2430                fatal(p);
2431            mj_jtag=(UWORD)ld;
2432            continue;
2433        }
2434
2435        if (strncmp(p,"xxxx?",5) == 0 || strncmp(p,"xxxx=",5) == 0 ||
2436            strncmp(p,"proc?",5) == 0 || strncmp(p,"proc=",5) == 0) {
2437            q=p+5;
2438            if (!*q)
2439                fatal(p);
2440            if (mp_scan(xmxp,dbnp,q)) MXEXIT(1);
2441            continue;
2442        }
2443
2444        if (strncmp(p,"convert?",8) == 0 || strncmp(p,"convert=",8) == 0) {
2445            if (strcmp(p+8,"ansi") == 0) {
2446                tabconvp=ansimctab; /* asc2ansi */
2447                memcpy(isisuctab,ansiuctab,256/*sizeof(ansiuctab)*/);
2448                for (isiswctot=0; ansiactab[isiswctot]; isiswctot=isiswctot+1)
2449                    isiswctab[ansiactab[isiswctot]]=1;
2450                continue;
2451            }
2452            if (strcmp(p+8,"arab") == 0) {
2453                tabconvp=arabmctab; /* 708_1256 */
2454                continue;
2455            }
2456            fatal(p);
2457        }
2458
2459#if RECDECO
2460        if (strncmp(p,"decod?",6) == 0 || strncmp(p,"decod=",6) == 0) {
2461            recdecod(irec,p+6,(upirec)?upirec:(upirec=nrecs));
2462            continue;
2463        }
2464#endif
2465
2466#if RECGIZM
2467#if MXGIZP
2468        if (strncmp(p,"gizp?",5) == 0 || strncmp(p,"gizp=",5) == 0) {
2469            parmgizp=p+5;
2470            continue;
2471        }
2472        if (strncmp(p,"gizp/h?",7) == 0 || strncmp(p,"gizp/h=",7) == 0) {
2473            parmgizp=p+7;
2474            parmgizhp=1;
2475            continue;
2476        }
2477#endif
2478        if (strncmp(p,"gizmo?",6) == 0 || strncmp(p,"gizmo=",6) == 0 ||
2479            strncmp(p,"giz1?",5) == 0 || strncmp(p,"giz1=",5) == 0 ||
2480            strncmp(p,"giz2?",5) == 0 || strncmp(p,"giz2=",5) == 0) {
2481            if (strncmp(p,"gizmo?",6) == 0 || strncmp(p,"gizmo=",6) == 0)
2482                q=p+6;
2483            else
2484                q=p+5;
2485            if (!*q) fatal(p);
2486
2487            if (RDBvgzrp) {     /* gizmo already defined */
2488                for (gizmap=RDBvgzrp; gizmap->nextp; )
2489                    gizmap=gizmap->nextp;
2490                gizmread(q,&gizmap->nextp,(upirec)?upirec:(upirec=nrecs));
2491                gizmap=gizmap->nextp;
2492            }
2493            else {              /* first gizmo definition */
2494                gizmread(q,&RDBvgzrp,(upirec)?upirec:(upirec=nrecs));
2495            }
2496
2497            if (parmtrace) {
2498                for (gizmap=RDBvgzrp; gizmap; gizmap=gizmap->nextp)
2499                    printf("+++ gizmo=%s \n",gizmap->gdbnp);
2500            }
2501            continue;
2502        }
2503#endif /* RECGIZM */
2504
2505#if RECXPND
2506        if (strncmp(p,"putdir?",7) == 0 || strncmp(p,"putdir=",7) == 0) {
2507            if (sscanf(p+7,"%d,%d",&parmxpn01,&parmxpn02) != 2)
2508                fatal(p);                       /* recxpn00() tag,dlm */
2509            continue;
2510        }
2511        if (strncmp(p,"getdir?",7) == 0 || strncmp(p,"getdir=",7) == 0) {
2512            if (sscanf(p+7,"%d,%d",&RDBxpn01,&RDBxpn02) != 2)
2513                fatal(p);                       /* recxpnmo() */
2514            continue;
2515        }
2516#endif
2517
2518        if (strncmp(p,"sys?",4) == 0 || strncmp(p,"sys=",4) == 0 ||
2519            strncmp(p,"sys/show?",9) == 0 ||
2520            strncmp(p,"sys/show=",9) == 0) {
2521            p+=4;
2522            if (strncmp(p,"show",5-1) == 0) {
2523                p+=5; parmsyss=1;
2524            }
2525            parmsysp=loadfile(dbnp,'@',p,NULL,fmtasize+1,'\0');
2526        if (!parmsysp) fatal(p);
2527            parmfields=0;
2528            continue;
2529        }
2530
2531        if (strncmp(p,"text?",5) == 0 || strncmp(p,"text=",5) == 0 ||
2532            strncmp(p,"text/show?",10) == 0 ||
2533            strncmp(p,"text/show=",10) == 0) {
2534            p+=5;
2535            if (strncmp(p,"show",5-1) == 0) {
2536                p+=5;
2537                mxtext_pshow=1; parmfields=0;
2538            }
2539            parmtextp=p;
2540            continue;
2541        }
2542
2543        if (strncmp(p,"outmfntag?",10) == 0 || strncmp(p,"outmfntag=",10) == 0) {
2544            if (sscanf(p+10,"%d",&parmoutmfntag) != 1)
2545                fatal(p);
2546            continue;
2547        }
2548        if (strncmp(p,"lw?",3) == 0 || strncmp(p,"lw=",3) == 0) {
2549            if (sscanf(p+3,"%ld",&fmtlw) != 1)
2550                fatal(p);
2551            continue;
2552        }
2553
2554        if (strncmp(p,"pft?",4) == 0 || strncmp(p,"pft=",4) == 0 ||
2555            strncmp(p,"tab?",4) == 0 || strncmp(p,"tab=",4) == 0 || strncmp(p,"tab/",4) == 0) {
2556            int parmtabula=0;
2557            q=p+4;
2558            if (strncmp(p,"tab?",4) == 0 || strncmp(p,"tab=",4) == 0 || strncmp(p,"tab/",4) == 0) {
2559                parmtabula=1; fmtlw=0; //5.2
2560                if (strncmp(p,"tab/",4) == 0) {
2561                    unsigned class=0;
2562                    unsigned width=0;
2563                    unsigned tabtg=0;
2564                    p+=3; //skip tab
2565                    while (*p == '/') {
2566                        if (strncmp(p,"/lines:",7) == 0) { for (p+=7; isdigit(*p); p++) class=class*10+((int)(*p)-(int)'0'); if (class<1) fatal(p); }
2567                        else
2568                        if (strncmp(p,"/width:",7) == 0) { for (p+=7; isdigit(*p); p++) width=width*10+((int)(*p)-(int)'0'); if (width<1) fatal(p); }
2569                        else
2570                        if (strncmp(p,"/tab:"  ,5) == 0) { for (p+=5; isdigit(*p); p++) tabtg=tabtg*10+((int)(*p)-(int)'0'); if (tabtg<1) fatal(p); }
2571                        else fatal(q-4);
2572                    } /* while /option */
2573                    if (*p == '?' || *p == '=') p++; else fatal(q-4);
2574                    if (parmtrace) printf("+++ tab class=%ld width=%ld\n",(LONGX)class,(LONGX)width);
2575                    if (class > 0) ptabcategories=(LONGX)class*3; // hashing;
2576                    if (width > 0) ptabwidth=(int)width;
2577                    if (tabtg > 0) parmtabtg=tabtg;
2578                    q=p;
2579                }
2580                if (parmtrace) printf("+++ tab class=%ld width=%ld tabtg=%ld\n",(LONGX)ptabcategories,(LONGX)ptabwidth,(LONGX)parmtabtg);
2581            }
2582            if (strcmp(q,"@") == 0) sprintf(q=mx_bup,"@%s.pft",dbnp);
2583            fmtarea=loadfile(dbnp,'@',q,fmtarea,fmtasize+1,'\0');
2584            if (!fmtarea) fatal(q);
2585            q=fmtarea;
2586            if (parmtrace) {
2587                printf("+++ fmt=%c",OPENFCHR); printf("%s",q);
2588                printf("%c ..",CLOSFCHR); if (getchar() != '\n') MXEXIT(0);
2589            }
2590            if (!*q) fatal(p);
2591            if (fmt_gener(&pgmp,q)) {
2592                fprintf(stderr,"*** fmt_error=%ld\n",fmt_error);
2593                fatal(q+fmt_errof);
2594            }
2595            parmfields=0;
2596            if (parmtabula) {
2597                /* calculate maxprim and allocate/zero hash table */
2598                LONGX maxprim;
2599                ptabtable=hashalloc(ptabcategories,ptabwidth,&maxprim);
2600                ptabmaxprim=maxprim;
2601                if (parmtrace) printf("+++ hash=%ld\n",ptabmaxprim);
2602                /* allocate/zero frequencies */
2603                ptabCOUNT=     (LONGX *) loadfile(NULL,'@',"",NULL, ptabmaxprim*sizeof(LONGX),   '\0');
2604            }
2605            continue;
2606        }
2607
2608
2609        if (strncmp(p,"jdi?",4) == 0 || strncmp(p,"jdi=",4) == 0 || strncmp(p,"jdi/",4) == 0) {
2610            p+=3; //skip jdi
2611            while (*p == '/') {
2612                q=p;
2613                if (isdigit(*(p+1))            ) { for (p+=1, jdiadd55=0; isdigit(*p); p++) jdiadd55=jdiadd55*10+((int)(*p)-(int)'0'); if (jdiadd55<0) fatal(p); }
2614                else
2615                if (strncmp(p,"/lines:",7) == 0) { for (p+=7, jdiclass=0; isdigit(*p); p++) jdiclass=jdiclass*10+((int)(*p)-(int)'0'); if (jdiclass<1) fatal(p); }
2616                else
2617                if (strncmp(p,"/width:",7) == 0) { for (p+=7, jdiwidth=0; isdigit(*p); p++) jdiwidth=jdiwidth*10+((int)(*p)-(int)'0'); if (jdiwidth<1) fatal(p); }
2618                else
2619                if (strncmp(p,"/tab:"  ,5) == 0) { for (p+=5, jditabtg=0; isdigit(*p); p++) jditabtg=jditabtg*10+((int)(*p)-(int)'0'); if (jditabtg<1) fatal(p); }
2620                else
2621                if (strncmp(p,"/occ:"  ,5) == 0) { for (p+=5, jditaboc=0; isdigit(*p); p++) jditaboc=jditaboc*10+((int)(*p)-(int)'0'); if (jditaboc<1) fatal(p); }
2622                else
2623                if (strncmp(p,"/top:"  ,5) == 0) { for (p+=5, jdisstop=0; isdigit(*p); p++) jdisstop=jdisstop*10+((int)(*p)-(int)'0'); if (jdisstop<1) fatal(p); }
2624                else
2625                if (strncmp(p,"/nmin:" ,6) == 0) { for (p+=6, jdisminn=0; isdigit(*p); p++) jdisminn=jdisminn*10+((int)(*p)-(int)'0'); if (jdisminn<1) fatal(p); }
2626                else
2627                if (strncmp(p,"/wmin:"    ,6) == 0) { p+=6; if (sscanf(p,"%f",&jdisminw) != 1) fatal(p); while (isdigit(*p) || *p=='.') p++; }
2628                else
2629                if (strncmp(p,"/vmin:"    ,6) == 0) { p+=6; if (sscanf(p,"%f",&jdisminv) != 1) fatal(p); while (isdigit(*p) || *p=='.') p++; }
2630                else
2631                if (strncmp(p,"/show"     ,5) == 0) { p+=5; jdipshow=1; parmfields=0; }
2632                else
2633                if (strncmp(p,"/sort:w1"  ,8) == 0) { p+=8; jdisort=JDISORTW1; }
2634                else
2635                if (strncmp(p,"/sort:w2"  ,8) == 0) { p+=8; jdisort=JDISORTW2; }
2636                else
2637                if (strncmp(p,"/sort:w3"  ,8) == 0) { p+=8; jdisort=JDISORTW3; }
2638                else
2639                if (strncmp(p,"/sort:v1"  ,8) == 0) { p+=8; jdisort=JDISORTV1; }
2640                else
2641                if (strncmp(p,"/sort:v2"  ,8) == 0) { p+=8; jdisort=JDISORTV2; }
2642                else
2643                if (strncmp(p,"/sort:v3"  ,8) == 0) { p+=8; jdisort=JDISORTV3; }
2644                else
2645                if (strncmp(p,"/sort:n1"  ,8) == 0) { p+=8; jdisort=JDISORTN1; }
2646                else
2647                if (strncmp(p,"/sort:n2"  ,8) == 0) { p+=8; jdisort=JDISORTN2; }
2648                else
2649                if (strncmp(p,"/sort:n3"  ,8) == 0) { p+=8; jdisort=JDISORTN3; }
2650                else fatal(q);
2651            } /* while /option */
2652            if (*p == '?' || *p == '=') p++; else fatal(p); parmtabjdip=p; 
2653            q=p+1; p=strchr(q,'?'); if (!p) p=strchr(q,'='); if (!p) fatal(parmtabjdip); *p++='\0';
2654            if (parmtrace) printf("+++ jdi parmtabjdip=%s\n",parmtabjdip);
2655            q=p; if (strcmp(q,"@") == 0) sprintf(q=mx_bup,"@%s.pft",parmtabjdip);
2656            jdifmtarea=loadfile(parmtabjdip,'@',q,jdifmtarea,jdifmtasize+1,'\0');
2657            if (!jdifmtarea) fatal(q); q=jdifmtarea;
2658            if (!*q) fatal(p);
2659            if (parmtrace) {
2660                printf("+++ fmt=%c",OPENFCHR); printf("%s",q);
2661                printf("%c ..",CLOSFCHR); if (getchar() != '\n') MXEXIT(0);
2662            }
2663            if (fmt_gener(&jdipgmp,q)) {
2664                fprintf(stderr,"*** fmt_error=%ld\n",fmt_error);
2665                fatal(q+fmt_errof);
2666            }
2667            //parmfields=0;
2668            if (parmtabjdip) {
2669                jdislen=(9+jdiwidth+1);
2670                /* calculate maxprim and allocate/zero hash table */
2671                jdicategories=(LONGX)jdiclass*3; // hashing;
2672                if (parmtrace) printf("+++ jdi width=%d categories=%ld\n",jdiwidth,(long)jdicategories);
2673                jditable=hashalloc(jdicategories,jdiwidth,&jdimaxprim);
2674                if (parmtrace) printf("+++ jdi hash=%ld\n",jdimaxprim);
2675                /* allocate/zero frequencies */
2676                jdiSUM0w=     (float *) loadfile(NULL,'@',"",NULL, jdimaxprim           *sizeof(float), '\0');
2677                jdiSUM0v=     (float *) loadfile(NULL,'@',"",NULL, jdimaxprim           *sizeof(float), '\0');
2678                jdiSUM0n=     (long  *) loadfile(NULL,'@',"",NULL, jdimaxprim           *sizeof(long ), '\0');
2679                jdiFREQ1=     (long  *) loadfile(NULL,'@',"",NULL, jdimaxprim           *sizeof(long ), '\0');
2680                /* allocate/zero sort area - jdiclass */
2681                jdiSBUF=      (char  *) loadfile(NULL,'@',"",NULL, jdimaxprim*jdislen*sizeof(char ), '\0');
2682                jdiSBUH=      (long  *) loadfile(NULL,'@',"",NULL, jdimaxprim           *sizeof(long ), '\0');
2683                jdiSBUFx=     (char  *) loadfile(NULL,'@',"",NULL,            jdislen*sizeof(char ), '\0');
2684            }
2685            //alloc jdi term
2686#if CICPP
2687            try { jditrmp=new TRMSTRU(cisisxp); }
2688            catch (BAD_ALLOC) { fatal("mx/jdi/reftrm/next"); }
2689#else /* CICPP */
2690            for (jditrm_prat=maxntrm; jditrm_prat--; ){
2691                if (!vtrmp[jditrm_prat]) /* ja' decrementado */
2692                    break;
2693            }
2694            if (!jditrm_prat) fatal("mx/jdi/reftrm/next");
2695#endif /* CICPP */
2696            //alloc jdi record
2697#if CICPP
2698            try { jdirecp=new RECSTRU(cisisxp); }
2699            catch (BAD_ALLOC) { fatal("mx/jdi/refrec/next"); }
2700#else /* CICPP */
2701            for (jdirec_prat=maxnrec; jdirec_prat--; ){
2702                if (!vrecp[jdirec_prat]) /* ja' decrementado */
2703                    break;
2704            }
2705            if (!jdirec_prat) fatal("mx/jdi/refrec/next");
2706#endif /* CICPP */
2707            //open
2708#if CICPP
2709            jditrmp->term(parmtabjdip,"A");
2710#else
2711            jditrmp=vtrmp[term(jditrm_prat,parmtabjdip,"A")];
2712#endif
2713#if CICPP
2714            jdirecp->record(parmtabjdip,1L);
2715#else
2716            jdirecp=vrecp[record(jdirec_prat,parmtabjdip,1L)];
2717#endif
2718            continue;
2719        }
2720
2721
2722#if INVXBOOL
2723        if (strncmp(p,"invx?",5) == 0 || strncmp(p,"invx=",5) == 0) {
2724            /* mxbool/b40 tl_irec */
2725            if (booltlir == 0) {
2726#if BEFORE20020128
2727                record(booltlir=nrecs,dbnp,VMF0nxtmfn(crec)); /* alloc/init */
2728                VMFRstatus(booltlir)=ACTIVE;                  /* fmt */
2729                VMFRmfn(booltlir)=1L;                         /* good */
2730#else
2731            /* b7_run faz "trirecp=vrep[tlirec]" */
2732            if (!booltlir) record(booltlir=nrecs,"null",1L);
2733#endif
2734            }
2735            record(irecx=nrecs,p+5,1L);
2736            *(batchp=mx_bup)='\0';
2737            while (VRECrc(irecx) != RCEOF) {
2738                if (VRECrc(irecx) == RCNORMAL)
2739                    for (xdir=0, loop=VMFRnvf(irecx); loop--; xdir++)
2740                        if (VDIRtag(irecx,xdir) == MFQTXTAG) {
2741                            sprintf(batchp,"H%d %d ",
2742                                        MFQTXTAG,VDIRlen(irecx,xdir));
2743                            batchp+=strlen(batchp);
2744                            memcpy(batchp,
2745                                VFIELDP(irecx,xdir),VDIRlen(irecx,xdir));
2746                            batchp+=VDIRlen(irecx,xdir);
2747                            *batchp='\0';
2748                        }
2749                record(irecx,VRDBname(irecx),VMFRmfn(irecx)+1);
2750            }
2751#if BEFORE20020128
2752#else
2753            dbxflush(VRDBname(irecx)); /* libera x101 */
2754#endif
2755            if (fldupdat(booltlir,mx_bup)) fatal(mx_bup);
2756#if CIAPI
2757            FREE(vrecp[irecx]); vrecp[irecx]=NULL; nrecs-=1;
2758#else /* CIAPI */
2759            FREE(vrecp[irecx]); vrecp[irecx]=NULL; nrecs--;
2760#endif /* CIAPI */
2761
2762            if (parmtrace) prtfields(vrecp[booltlir],VMFRmfn(booltlir));
2763            continue;
2764        }
2765#endif
2766
2767
2768//#if CICGI
2769        if (strncmp(p,"pftout?",7) == 0 || strncmp(p,"pftout=",7) == 0) {
2770            parmpftoutp=p+7;
2771            if ((parmpftoutfp=fopen(dbxcipar(NULL,parmpftoutp,'='),"w")) == NULL)
2772                fatal(p);
2773            continue;
2774        }
2775        if (strncmp(p,"prolog?",7) == 0 || strncmp(p,"prolog=",7) == 0) {
2776            parmprologp=p+7;
2777            continue;
2778        }
2779        if (strncmp(p,"epilog?",7) == 0 || strncmp(p,"epilog=",7) == 0) {
2780            parmepilogp=p+7;
2781            irecepilog=irec;
2782            continue;
2783        }
2784//#endif /* CICGI */
2785
2786        /* output parameters */
2787
2788        if (strncmp(p,"iso?",4) == 0 || strncmp(p,"iso=",4) == 0 ||
2789            strncmp(p,"outiso?",7) == 0 || strncmp(p,"outiso=",7) == 0) {
2790            if (strncmp(p,"iso?",4) == 0 || strncmp(p,"iso=",4) == 0) q=p+4; else q=p+7;
2791                if (strchr(q,'=')) {
2792                    if (strncmp(q,"marc=",5) == 0) {  /* AOT, 06/06/2005 */
2793                        q+=5;
2794                        lrfox=ISOBSIZ; /* set to max line len */
2795                        isfox=(-1);    /*  no CRLF */
2796                        parmisoxfs=ISOXFSMARC;
2797                        parmisoxgs=ISOXGSMARC;
2798                        iso_ismarc=ismarc=1;
2799                    }
2800                    else
2801                    if (strncmp(q,"0=",2) == 0) {    /* AOT, 06/06/2005 */
2802                        q+=2;
2803                        lrfox=ISOBSIZ; /* set to max line len */
2804                        isfox=0;       /*  with [CR]LF */
2805                        parmisoxfs=ISOXFSMARC;
2806                        parmisoxgs=ISOXGSMARC;
2807                    }
2808                    else {
2809                        if (sscanf(q,"%d=%s",&lrfox,line) != 2) fatal(p);
2810                        if (lrfox > ISOBSIZ) fatal(p);
2811                        q=strchr(q,'=')+1;
2812                        isfox=1;    /* test ok */
2813                    }
2814                }
2815                else {
2816#if MPE
2817                    isfox=1;
2818#else
2819                    isfox=0;
2820#endif
2821                    lrfox=80;
2822                }
2823            if (iso_creat(NULL,q,0,lrfox,isfox) <= 0) fatal(p);
2824            parmiso2=1;
2825            continue;
2826        }
2827
2828        if (strncmp(p,"isotag1?",8) == 0 || strncmp(p,"isotag1=",8) == 0) {
2829            if (sscanf(p+8,"%u",&parmisildrtag) != 1)
2830                fatal(p);
2831            continue;
2832        }
2833        if (strncmp(p,"outisotag1?",11) == 0 || strncmp(p,"outisotag1=",11) == 0) {
2834            if (sscanf(p+11,"%u",&parmisoldrtag) != 1)
2835                fatal(p);
2836            continue;
2837        }
2838
2839        if (strncmp(p,"fix?",4) == 0 || strncmp(p,"fix=",4) == 0) {
2840            q=p+4;
2841            if ((fpfix=fopen(dbxcipar(NULL,q,'='),"w")) == NULL) fatal(p);
2842            parmiso2=2;
2843            continue;
2844        }
2845
2846#if MXFST
2847        if (strncmp(p,"ln1?",4) == 0 || strncmp(p,"ln1=",4) == 0) {
2848#if MXIFUPD
2849            if (ifnp) fatal(p);
2850#endif
2851             if (strcmp(p+4,"void") == 0) {
2852                parmfstup=0;
2853            }
2854            else    /* 21/05/98 */
2855                if (fst_open(NULL,p+4,0) <= 0) fatal(p);
2856            continue;
2857        }
2858        if (strncmp(p,"ln2?",4) == 0 || strncmp(p,"ln2=",4) == 0) {
2859#if MXIFUPD
2860            if (ifnp) fatal(p);
2861#endif
2862             if (strcmp(p+4,"void") == 0) {
2863                parmfstup=0;
2864            }
2865            else    /* 21/05/98 */
2866                if (fst_open(NULL,p+4,1) <= 0) fatal(p);
2867            continue;
2868        }
2869
2870        if (strncmp(p,"fst?",4) == 0 || strncmp(p,"fst=",4) == 0 ||
2871            strncmp(p,"fst/h?",6) == 0 || strncmp(p,"fst/h=",6) == 0) {
2872            if (strncmp(p,"fst/h",5) == 0) {
2873                q=p+6;
2874                fst_hdrp=(char *)ALLOC((ALLOPARM)(fst_hdrx=1000));
2875                if (fst_hdrp == ALLONULL) fatal("ALLOC/fst_hdrp");
2876            }
2877            else q=p+4;
2878            if (strcmp(q,"@") == 0) sprintf(q=line,"@%s.fst",dbnp);
2879            if (!loadfile(mi_gidbnp,'@',q,mx_bup,mx_buplen,'\n')) fatal(q);
2880            fst_gener(&fstpgmp,mx_bup);
2881            if (parmtrace) printf("%s.\n",mx_bup); 
2882            if (fst_error) {
2883                printf("\n*** FST error#%ld at line %ld\n",fst_error,fst_errl);
2884                if (fst_error == FSTERRF)
2885                    printf("\n*** FMT error#%ld at offset %ld\n",
2886                                                fmt_error,fmt_errof);
2887                fatal(fst_errp);
2888            }
2889            continue;
2890        }
2891
2892        if (strncmp(p,"stw?",4) == 0 || strncmp(p,"stw=",4) == 0) {
2893            q=p+4;
2894            if (*q++ != '@') fatal(p);
2895            if (!*q) sprintf(q=line,"%s.stw",dbnp);
2896        stwp=loadstw(mi_gidbnp,q,stwp=NULL,0L,&n);
2897        if (!stwp) fatal(p);
2898            if (parmtrace) {
2899                for (q=stwp; *q; q+=LE1+1) printf("%s/",q);
2900                printf("=%d\n",n);
2901            }
2902            continue;
2903        }
2904#endif
2905
2906#if MXFULLINV
2907        if (strncmp(p,"fullinv",7) == 0) {
2908            if (!fstpgmp) fatal(p);
2909#if MXIFUPD
2910            if (ifnp) fatal(p);
2911#endif
2912            q=p+7;
2913            /* fullinv[/dict][/keep][/m][/ansi]=<ifn> */
2914            if (strncmp(q,"/dict",5) == 0) {q+=5; fullinv_pstflag=IFUPDICT;
2915                                                  ciiflfim=1;
2916                                                  cifstfix=cifstfim=1;
2917                                           }
2918            if (strncmp(q,"/keep",5) == 0) {q+=5; fullinv_keep=1;}
2919#if LIND
2920            ciiflfim=1;
2921            cifstfix=cifstfim=1;
2922#endif
2923            if (strncmp(q,"/m" ,2)   == 0) {q+=2; ciiflfim=1;
2924                                                  cifstfix=cifstfim=1;
2925                                           }
2926            if (strncmp(q,"/ansi",5) == 0) {q+=5;
2927                memcpy(isisuctab,ansiuctab,256/*sizeof(ansiuctab)*/);
2928                for (isiswctot=0; ansiactab[isiswctot]; isiswctot=isiswctot+1)
2929                    isiswctab[ansiactab[isiswctot]]=1;
2930            }
2931            if (strncmp(q,"?",1) == 0 || strncmp(q,"=",1) == 0) q+=1; else fatal(p);
2932            if (!*q) fatal(p);
2933            fullinv_ifnp=q;
2934            parmfstup=0;
2935            cifstfix=1;                                           /* +fix */
2936            parmcontrol=parmleader=parmxref=parmdir=parmfields=0; /* -all */
2937            parmwait=0;                                           /* now */
2938            if (!fst_fd[0]) {
2939                sprintf(mx_bup,"%s.ln1",fullinv_ifnp);
2940                if (fst_open(NULL,mx_bup,0) <= 0) fatal(p);
2941            }
2942            if (!fst_fd[1]) {
2943                sprintf(mx_bup,"%s.ln2",fullinv_ifnp);
2944                if (fst_open(NULL,mx_bup,1) <= 0) fatal(p);
2945            }
2946            continue;
2947        }
2948#if LIND
2949        if (strncmp(p,"maxmfn?",7) == 0 || strncmp(p,"maxmfn=",7) == 0) {
2950            if (sscanf(p+7,"%ld",&fullinv_maxmfn) != 1) fatal(p);
2951            continue;
2952        }
2953#endif
2954#endif /* MXFULLINV */
2955
2956
2957#if MXFULLINV || MXIFUPD
2958        if (strncmp(p,"master?",7) == 0 || strncmp(p,"master=",7) == 0) {
2959            parmmaster=p+7; if (!*parmmaster) fatal(p);
2960            continue;
2961        }
2962#endif /* MXFULLINV || MXIFUPD */
2963
2964#if MXIFUPD
2965        if (strncmp(p,"ifupd",5) == 0) {
2966            if (ifnp) fatal(p);
2967            if (fst_fd[0] || fst_fd[1]) fatal(p);
2968            q=p+5;
2969            /* ifupd[/create][/dict]=<ifn> */
2970            if (strncmp(q,"/create",7) == 0) {q+=7; ifcreate=1;}
2971            if (strncmp(q,"/dict",5) == 0) {q+=5; pstflag=IFUPDICT;}
2972            if (strncmp(q,"?",1) == 0 || strncmp(q,"=",1) == 0) q+=1;
2973            else fatal(p);
2974            ifnp=q;
2975            if (!*ifnp) fatal(p);
2976            continue;
2977        }
2978        if (strncmp(p,"maxlk1?",7) == 0 || strncmp(p,"maxlk1=",7) == 0) {
2979            if (sscanf(p+7,"%d",&maxlk1) != 1)
2980                fatal(p);
2981            continue;
2982        }
2983        if (strncmp(p,"maxlk2?",7) == 0 || strncmp(p,"maxlk2=",7) == 0) {
2984            if (sscanf(p+7,"%d",&maxlk2) != 1)
2985                fatal(p);
2986            continue;
2987        }
2988#endif
2989
2990        if (strncmp(p,"copy?",5) == 0 || strncmp(p,"copy=",5) == 0 ||
2991            strncmp(p,"append?",7) == 0 || strncmp(p,"append=",7) == 0 ||
2992            strncmp(p,"updatf?",7) == 0 || strncmp(p,"updatf=",7) == 0 ||
2993            strncmp(p,"create?",7) == 0 || strncmp(p,"create=",7) == 0 ||
2994            strncmp(p,"merge?",6) == 0 || strncmp(p,"merge=",6) == 0) {
2995
2996            parmcopy=COPY;
2997            if (strncmp(p,"create",7-1) == 0) {                 /* create */
2998                p+=7;
2999                recisis0(p);
3000            }
3001            else {
3002                if (strncmp(p,"copy",5-1) == 0)                 /* copy */
3003                    p+=5;
3004                else
3005                    if (strncmp(p,"updatf",7-1) == 0)           /* update */
3006                    {
3007                        p+=7;
3008                        parmcopy=UPDATF;
3009                    }
3010                    else
3011                        if (strncmp(p,"append",7-1) == 0)       /* append */
3012                            {p+=7; parmcopy=APPEND;}
3013                        else
3014                            {p+=6; parmcopy=MERGE;}             /* merge */
3015                dbxopt_fatal=0; xfd=dbxopen(p,p,mx1extp);
3016                if (xfd <= 0) recisis0(p); else CLOSE(xfd);
3017            }
3018            recallok((upcrec=nrecs),(LONGX)sizeof(M0STRU));
3019            recallok((upirec=nrecs),maxmfrl); /* 18/11/91 */
3020#if MULTI
3021        if (strcmp(p,dbnp) == 0) /* dbxstorp has already set dbxnetws */
3022#if CIAPI
3023            dbnp_dbxnetws(p)=dbxcinet(p);
3024            if (dbnp_dbxnetws(p) != MONONETS) {
3025#else /* CIAPI */
3026            dbxstorp(p)->dbxnetws=dbxcinet(p);
3027            if (dbxstorp(p)->dbxnetws != MONONETS) {
3028#endif /* CIAPI */
3029                VREClock(upirec)=RLOCK;
3030                VREClock(upcrec)=DELOCK;
3031        }
3032#endif
3033            record(upcrec,p,0L);        /* append */    /* RLOCK */
3034#if MULTI
3035            if (VRECrc(upcrec) == RCLOCK) FATLOCK;
3036#endif
3037            continue;
3038        }
3039
3040        if (parmtextp) {
3041            if (tmpseq) fatal("text x tmpseq");
3042            fatal("text x bool");
3043        }
3044
3045        if (mxbool(xmxp,p,dbnp)) MXEXIT(1);
3046
3047    } /* end of argv[] */
3048
3049
3050    if (!dbnp) fatal("input missing");
3051
3052
3053#if MXFULLINV
3054    if (fullinv_ifnp) {
3055        if (parmmaster) fullinv_master=parmmaster;
3056        else {
3057            fullinv_master=dbnp;
3058            if (parmcopy) fullinv_master=VRDBname(upcrec);
3059        }
3060#if LIND
3061        fullinv_reset=0;  /* init=1 */
3062#else
3063        if (parmmenosreset) fullinv_reset=0;
3064        else
3065            if (!parmmaster)
3066                if (strcmp(fullinv_master,fullinv_ifnp)) fullinv_reset=0;
3067#endif
3068
3069#if 0
3070        if (!fst_fd[0]) fatal("fullinv/missing ln1=");
3071        if (!fst_fd[1]) fatal("fullinv/missing ln2=");
3072#endif
3073        trmisis0(fullinv_ifnp);
3074    }
3075#endif /* MXFULLINV */
3076
3077#if MXIFUPD
3078    if (ifnp) {
3079        if (parmmenosreset) ifupd_reset=0;
3080        parmfstup=0;
3081        if (ifcreate) trmisis0(ifnp);
3082        if (parmcopy) {
3083            mstcrec=upcrec; mstirec=upirec;
3084        }
3085        else {
3086            mstcrec=crec; mstirec=irec;
3087#if BEFORE20000831
3088            svdifupx++;
3089            upif_init(ifnp);
3090#else
3091            svdifupx=1;
3092#endif
3093        }
3094#if CIAPI
3095        ifndbxp=dbxstorp(ifnp);
3096        dbnp_dbxitrac(ifnp)=parmtrace;
3097#else /* CIAPI */
3098        (ifndbxp=dbxstorp(ifnp))->dbxitrac=parmtrace;
3099#endif /* CIAPI */
3100        endup = IFUPCORE;
3101#if MULTI
3102
3103#if CIAPI
3104        if (dbnp_dbxnetws(VRDBname(mstcrec)) != MONONETS) endup = IFUPWRIT;
3105#else /* CIAPI */
3106        if (dbxstorp(VRDBname(mstcrec))->dbxnetws != MONONETS) endup = IFUPWRIT;
3107#endif /* CIAPI */
3108
3109#endif
3110    }
3111#endif
3112
3113
3114
3115    /*
3116        Execution
3117    */
3118
3119    if (parmloop < 0) {  /* AOT, 26/07/2005 */
3120        if (!parmfrom) parmfrom = VMF0nxtmfn(crec) - 1;
3121        if (!parmto)   parmto=1;
3122    }
3123
3124    if (tmpseq)
3125        if (!parmfrom)
3126            parmfrom = (parmcopy) ? VMF0nxtmfn(upcrec) : 1L;
3127
3128    if (!parmfrom)
3129        parmfrom=1L;
3130
3131    if (!parmto)
3132        parmto=LONGX_MAX;
3133
3134    if (parmcontrol)
3135        prtcontrol(vrecp[crec],dbnp);
3136
3137    if (parmkdbnp) {
3138        if (parmk1p) {
3139            for (xtp=parmk1p, xti=LE2; *xtp && xti; xtp++, xti--) *xtp = isisuctab[(int)*xtp];
3140            *xtp='\0';
3141        }
3142        else parmk1p="!";
3143        memset(parmk2a,highv[0],LE2); parmk2a[LE2]='\0';
3144        if (parmk2p) {
3145            for (xtp=parmk2p, xti=LE2; *xtp && xti; xtp++, xti--) *xtp = isisuctab[(int)*xtp];
3146            *xtp='\0';
3147            memcpy(parmk2a,parmk2p,strlen(parmk2p));
3148        }
3149        itrm=ntrms;
3150        if (parmtrace) printf("+++ TERM %ld = %s,%s,%s \n",itrm,parmkdbnp,parmk1p,parmk2p);
3151#if LIND
3152        if (!parmkpostings) trmalloc(itrm,0L);  /* avoid opening .iyp */
3153        if (!parmkpostings) if (parmtrace) printf("+++ trmalloc(%ld,0)\n",itrm);
3154#endif
3155        TERM(itrm,parmkdbnp,parmk1p); parmkcount=1;
3156        itrm2=ntrms; trmp1=trmp;
3157        if (parmtrace) printf("+++ TERM %ld = %s,%s,%s \n",itrm2,parmkdbnp,TRMkey,parmk2p);
3158#if LIND
3159        if (!parmkpostings) trmalloc(itrm2,0L);  /* avoid opening .iyp */
3160        if (!parmkpostings) if (parmtrace) printf("+++ trmalloc(%ld,0)\n",itrm2);
3161#endif
3162        TERM(itrm2,parmkdbnp,TRMkey); trmp2=trmp;
3163        trmp=trmp1;
3164    }
3165
3166    if (parmprologp) {
3167#if CICGI
3168#if CIWTF
3169        if (ciahcgi) {
3170            if (fldupdat(irec,ciahcgi)) fatal(ciahcgi);
3171        }
3172#endif //CIWTF
3173#endif /* CICGI */
3174#define PROL1 1 // AOT 27/06/2009
3175#if PROL1
3176        if (1) {
3177            long v31009=VMF0nxtmfn(crec);
3178            long v31409=boolhits;
3179            sprintf(mx_bup,"a31009|%ld|a31409|%ld|",v31009,v31409);
3180            if (fldupdat(irec,mx_bup)) fatal(mx_bup);
3181        }
3182#endif //PROL1
3183        if (recfmt(irec,rec_maxmfrl,parmprologp,mx_bup,mx_buplen) < 0) {
3184            printf("Content-type: text/plain\n\nMX fatal: %s",parmprologp);
3185        }
3186        if (parmpftoutfp && 0) fprintf(parmpftoutfp,"%s",mx_bup); else
3187        printf("%s",mx_bup);
3188    }
3189#if CICGI
3190    else if (cgixpok) { printf("Content-type: text/html\n\n");
3191                        printf("<html><body>\n"); }
3192#endif /* CICGI */
3193
3194
3195    /*
3196        Loops throught...
3197    */
3198
3199LOOP:
3200
3201    for (mfn=parmfrom, boolh=0; ; mfn+=parmloop) {
3202
3203        LONGX xboolmfn;
3204
3205        if (boolqryp) { /* mxbool/boolh */
3206            if (boolh) {
3207                boolh+=parmloop;
3208                if (parmloop < 0) {                                                /* AOT, 26/07/2005 */
3209                    if (boolh < 1)        boolh=boolhits+1; /* end of hits */
3210                }
3211                else {
3212                    if (boolh > boolhits) boolh=boolhits+1; /* end of hits */
3213                }
3214            }
3215            else {
3216                if (parmloop < 0)                                                  /* AOT, 26/07/2005 */
3217                    boolh=boolhits;
3218                else
3219                    boolh=1;
3220            }
3221#if CIB71
3222            xboolmfn=b7_hit(cib7p,boolridx,boolh,b7setno);
3223#else /* CIB71 */
3224#if LIND || CIB64
3225#if BIGREC
3226            xboolmfn=b5_hit(boolridx,boolh,mx_bup);
3227#else
3228            xboolmfn=b6_hit(boolridx,boolh,b5setno,b6bufferp);
3229#endif
3230#else
3231            xboolmfn=b4_hit(boolridx,boolh);
3232#endif
3233#endif /* CIB71 */
3234            if (parmtrace) printf("+++ xboolmfn=%ld\n",xboolmfn);
3235            if (xboolmfn <= 0L) break;
3236
3237            if (parmloop < 0) {  /* AOT, 26/07/2005 */
3238                if (xboolmfn > parmfrom) continue;
3239                if (xboolmfn < parmto)   continue;
3240            }
3241            else {
3242                if (xboolmfn < parmfrom) continue;
3243                if (xboolmfn > parmto)   continue;
3244            }
3245            mfn=xboolmfn;
3246        } /* end if boolqryp */
3247
3248        if (parmloop < 0) {  /* AOT, 26/07/2005 */
3249            if (mfn < parmto) break;
3250        }
3251        else {
3252            if (mfn > parmto) break;
3253        }
3254
3255        if (count >= parmcount) break;
3256
3257        if (parmwait)
3258            if (count) {
3259                n=1;
3260                if (parmtextp && !mxtext_found) n=0;
3261                if (n) {
3262                    printf(prompt1p); isxp=gets(line); p=isxp;
3263                    if (ISX(p)) break;
3264                    if (p) if (*p) { if (mxbool(xmxp,p,dbnp)) MXEXIT(1); count=0; goto LOOP; }
3265                }
3266            }
3267
3268        ++count; /* in advance */
3269
3270        /* Sequential RECORD */
3271
3272        if (tmpseq) {
3273#if DIR_FILE
3274            if (direntdp) {
3275                if (direntep = readdir (direntdp))
3276                {
3277                    //puts (direntep->d_name);
3278                    RECORD(irec,dbnp,mfn);
3279                    RECrc=RCNORMAL; MFRmfn=mfn; MFRstatus=ACTIVE;
3280                    sprintf(mx_bup,"a1|%s|",direntep->d_name); 
3281                    if (fldupdat(irec,mx_bup)) fatal(mx_bup);
3282                    MFRmfn=mfn;
3283                }
3284                else {
3285                    (void) closedir (direntdp);
3286                    break; // end of directory listing
3287                }
3288            }
3289            else
3290#endif
3291            if (fpseq) {
3292            /* uses global mx_bup as input buffer */
3293                mx_bup[0]=parmxseq;
3294                if (recfgets(crec,irec,mx_bup,mx_buplen,fpseq) == EOF)
3295                    break;
3296                MFRmfn=mfn;
3297            }
3298            else
3299            if (n1fdseq) {
3300                if (recfgetseq(NULL, parmxseq, parmseqlog, ibuf, ibufsiz, obuf, obufsiz, ubuf, ubufsiz, &n1fdseq, &n1left, &n1iptr, &n1count) == EOF) break;
3301                RECORD(irec,dbnp,mfn);
3302                RECrc=RCNORMAL; MFRmfn=mfn; MFRstatus=ACTIVE;
3303                if (fldupdat(irec,ubuf)) fatal(ubuf);
3304                MFRmfn=mfn;
3305            }
3306#if XML_FILE
3307            else
3308            if (n1fdxml) {
3309                if (recfgetxml(NULL, ibuf, ibufsiz, obuf, obufsiz, ubuf, ubufsiz, &n1fdxml, &n1left, &n1iptr, &n1count) == EOF) break;
3310                RECORD(irec,dbnp,mfn);
3311                RECrc=RCNORMAL; MFRmfn=mfn; MFRstatus=ACTIVE;
3312                if (fldupdat(irec,ubuf)) fatal(ubuf);
3313                MFRmfn=mfn;
3314            }
3315#endif /* XML_FILE */
3316            else
3317                if (parmiso1) {
3318                    if (iso_read(crec,irec,parmisildrtag) == EOF) break;
3319                    MFRmfn=mfn;
3320                }
3321                else {                                          /* "tmp" */
3322                    RECORD(irec,dbnp,mfn);
3323                    RECrc=RCNORMAL; MFRmfn=mfn; MFRstatus=ACTIVE;
3324                }
3325#if RECXPND
3326            if (RDBxpn01) recxpnmo(irec);
3327#endif
3328#if RECGIZM
3329            for (gizmap=RDBvgzrp; gizmap; gizmap=gizmap->nextp)
3330                recgizmo(irec,gizmap);
3331#endif
3332#if RECDECO
3333            if (RDBvderp) recdecex(irec);
3334#endif
3335        }
3336
3337        else
3338        if (parmkdbnp) {
3339          sprintf(mx_bup,"D*"); if (fldupdat(irec,mx_bup)) fatal(mx_bup);
3340          sprintf(mx_bup,"=%ld",mfn); if (fldupdat(irec,mx_bup)) fatal(mx_bup);
3341KLOOP:
3342          trmp=trmp2;
3343          if (TRMrc != RCEOF) {
3344            NXTERM(itrm2);
3345            if (TRMrc == RCEOF) {
3346              countdict1002=count;
3347              sprintf(mx_bup,"D1001D1002A1001/%ld/A1002/%ld/",count,countdict1002);
3348              if (fldupdat(irec,mx_bup)) fatal(mx_bup);
3349            } else {
3350              if (strcmp(TRMkey,parmk2a) > 0) {
3351                countdict1002=count;
3352                sprintf(mx_bup,"D1001D1002A1001/%ld/A1002/%ld/",count,countdict1002);
3353                if (fldupdat(irec,mx_bup)) fatal(mx_bup);
3354              }
3355            }
3356          }
3357          trmp=trmp1;
3358
3359          if (parmkpostings) TRMpmfn=posting(itrm,TRMpost+1);
3360#if 0
3361          if (count==1 || !parmkpostings || (parmkpostings && TRMpmfn <= 0)) { /* */
3362#endif
3363          xgo=0;
3364          if (count==1) xgo=1;
3365          if (!parmkpostings) xgo=1;
3366          if (parmkpostings) if (TRMpmfn <= 0) xgo=1;
3367          if (xgo) { /* */
3368            if (TRMrc == RCEOF) break;
3369            if (strcmp(TRMkey,parmk2a) > 0) break;
3370             if (count > 1L) {
3371                NXTERM(itrm);
3372                if (TRMrc == RCEOF) break;
3373                if (strcmp(TRMkey,parmk2a) > 0) break;
3374                if (parmkpostings) TRMpmfn=posting(itrm,TRMpost+1);
3375                parmkcount++;
3376            }
3377            for (xtp=TRMkey+(xti=(TRMlcase)?LE2:LE1)-1; xti--; ) if (*xtp == ' ') *xtp--='\0'; else break;
3378          } /* */
3379          if (parmtrace) { printf("+++ TRMkey:\n"); for (xtp=TRMkey, xti=LE2; xti--; xtp++) printf("%c=%02x ",*xtp,*xtp); printf("\n"); }
3380          if (!parmkpostings || TRMpost%parmkkeep2 == 1 || parmkkeep2 == 1) {
3381            sprintf(mx_bup,"H%9ld %9ld %s^l%d^s%ld^t%ld^k%ld",(LONGX)parmktag1,0L,TRMkey,TRMlcase+1,(long)strlen(TRMkey),TRMxytotp,parmkcount);
3382            sprintf(mx_bup+1+10,"%9ld",(LONGX)strlen(mx_bup)-(1+10+10)); mx_bup[10+10]=' ';
3383            if (fldupdat(irec,mx_bup)) fatal(mx_bup);
3384          }
3385          if (parmkpostings && TRMpmfn > 0) { /* */
3386            sprintf(mx_bup,"A%ld/^m%ld^t%ld^o%ld^c%ld^p%ld^k%ld/",(LONGX)parmktag2,TRMpmfn,(LONGX)TRMptag,(LONGX)TRMpocc,(LONGX)TRMpcnt,TRMpost,parmkcount);
3387            if (fldupdat(irec,mx_bup)) fatal(mx_bup);
3388          } /* */
3389if ((parmkpostings && TRMpost < TRMxytotp) && (TRMpost%parmkkeep2 != 0)) goto KLOOP;
3390        }
3391
3392        else {
3393            RECORD(irec,dbnp,mfn);
3394            if (RECrc == RCEOF) break;
3395        }
3396
3397        if (parmhits) {
3398            if (boolqryp) /* mxbool/boolh */
3399                sprintf(mx_bup,"A1001/%ld/A1002/%ld/",boolh,boolhits);
3400            else
3401              if (parmkdbnp)
3402                sprintf(mx_bup,"A1001/%ld/A1002/%ld/",count,countdict1002);
3403              else
3404/*
3405                sprintf(mx_bup,"A1001/%ld/A1002/%ld/",MFRmfn,VMF0nxtmfn(crec)-1);
3406*/
3407                {
3408                    sprintf(mx_bup,"A1001/%ld/",MFRmfn-parmfrom+1);
3409                    if (MFRmfn == VMF0nxtmfn(crec)-1 ||
3410                        MFRmfn == parmto ||
3411                        count == parmcount)
3412                      sprintf(mx_bup+strlen(mx_bup),"A1002/%ld/",MFRmfn-parmfrom+1);
3413                }
3414            if (fldupdat(irec,mx_bup) != NULL) fatal(mx_bup);
3415        }
3416
3417        if (parmtextp) {
3418            if (mxtext(xmxp,irec,parmtextp)) MXEXIT(1);
3419            if (!mxtext_found)
3420                continue;
3421        }
3422
3423#if IFUPDATE
3424    if (parmmfbw) {
3425        if (MFRmfbwb == 0) continue;
3426        else {
3427          if (!brec) { brec=nrecs; record(brec,dbnp,mfn); }
3428          recreadb=MFRmfbwb; recreadp=MFRmfbwp;
3429          recread(vrecp[brec],MFRmfn);
3430          memcpy(MFX,VMFX(brec),VMFRmfrl(brec)); /* in trust.. */
3431        }
3432    }
3433#endif
3434
3435        if (parmtell)
3436            if ((count % parmtell) == 0)
3437                fprintf(stderr,"+++ %ld \n",count);
3438
3439        if (parmxref)   prtxref(recp,mfn);
3440
3441        if (parmleader) prtleader(recp,0L);
3442
3443        if (RECrc != RCNORMAL) {
3444
3445            if (parmdir)        prtdir(recp,mfn);
3446
3447            if (parmfields)     prtfields(recp,mfn);
3448
3449            if (parmcopy == COPY) if (!parmoutmfntag) {
3450
3451                record(upirec,VRDBname(upcrec),MFRmfn); /* RLOCK */
3452                if (VRECrc(upirec) == RCLOCK) FATLOCK;
3453                if (VRECrc(upirec) == RCNORMAL) {
3454#if MULTI
3455                    memcpy(VMFX(upirec),MFX,MFRmfrl);
3456#else
3457                    reccopy(upirec,upcrec,recp,MFRmfn);
3458#endif
3459                    recupdat(upcrec,upirec);
3460#if MXIFUPD
3461                    if (ifnp)
3462                        ifupdat(VRDBname(upcrec),MFRmfn,MFRmfn,
3463                           ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,endup);
3464#endif
3465
3466
3467                } /* end recupdat() */
3468#if MULTI
3469#if CIAPI
3470                if (dbnp_dbxnetws(p) != MONONETS) recunlck(upirec,RLOCK);
3471#else /* CIAPI */
3472                if (dbxstorp(p)->dbxnetws != MONONETS) recunlck(upirec,RLOCK);
3473#endif /* CIAPI */
3474#endif
3475            }
3476
3477            continue;
3478        }
3479
3480
3481        /* ACTIVE records */
3482
3483        if (MFRstatus != ACTIVE) fatal("mx/ACTIVE");
3484
3485        /* join */
3486        if (mj_n) if (mj_edit(xmxp,irec,0,mj_n-1,mj_jtag,NULL)) MXEXIT(1);
3487
3488        /* jdi */
3489        if (parmtabjdip) {
3490            /* tabulate generated lines */
3491            char delim=0x01; //'|';
3492            FFI len;
3493            char *p0=jdifmtarea;
3494            if (fmt_inter(jdipgmp,irec,(LONGX)jdifmtlw,jdifmtarea,(LONGX)fmtasize) < 0)
3495                fatal("mx/jdi/format execution error");
3496            for (len=0, p=p0; ; ) {
3497                /* next line */
3498                if (!*p || *p == '\r' || *p == '\n' || *p == delim) {
3499                    if (len) {
3500                        /* tabulate line */
3501                        long jdimfn=0L;
3502                        char c=(*p);//save
3503                        *p='\0';
3504#if CICPP
3505                        jditrmp->term(parmtabjdip,p0);
3506                        if (jditrmp->trmrc == RCNORMAL) jdimfn=trmp->posting(1L);
3507#else
3508                        term(jditrm_prat,parmtabjdip,p0);
3509                        if (jditrmp->trmrc == RCNORMAL) jdimfn=posting(jditrm_prat,1L);
3510#endif
3511                        if (jdimfn > 0) {
3512#if CICPP
3513                          jdirecp->record(parmtabjdip,jdimfn);
3514#else
3515                          record(jdirec_prat,parmtabjdip,jdimfn);
3516#endif
3517                          if (jdirecp->recrc == RCNORMAL) {
3518                            RECSTRU *recp=jdirecp;//local
3519                            DIRSTRU *dirp=MFRdir;
3520                            int loop=MFRnvf;
3521                            int xocc=jditaboc;
3522                            int xdir=0;
3523                            unsigned char c,*cp;
3524                            for (; loop--; dirp++, xdir++) {
3525                                char *jp,*p;//local
3526                                int jlen=0,len;
3527                                float jdiw=0.0;
3528                                float jdiv=0.0;
3529                                long  jdin=0;
3530                                if (dirp->tag != jditabtg) continue;
3531                                if (!xocc--) break;
3532                                jp=p=FIELDP(xdir);
3533                                len=dirp->len; cp=p+len; c=(*cp); p[len]='\0';
3534                                for (; len--; p++, jlen++) if (*p=='^') break; 
3535                                if (jlen) for (; len-->2; p++) if (*p=='^') {
3536                                    if (*(p+1)=='w') { if (sscanf(p+2,"%f" ,&jdiw) != 1) jdiw=0.0; len-=2; p+=2; continue; } else
3537                                    if (*(p+1)=='v') { if (sscanf(p+2,"%f" ,&jdiv) != 1) jdiv=0.0; len-=2; p+=2; continue; } else
3538                                    if (*(p+1)=='n') { if (sscanf(p+2,"%ld",&jdin) != 1) jdin=0;   len-=2; p+=2; continue; }
3539                                }
3540                                *cp=c;
3541                                //tabulate jd
3542                                if (jdiw>0) {
3543                                    /* tabulate line */
3544                                    long  hidx;
3545                                    int hwidth=(jdiwidth+1);
3546                                    int hfound;
3547                                    hidx=hashindex(jditable,jdimaxprim,jdiwidth,jp,jlen,&hfound,1);
3548                                    //if (hfound) if (!hfound) fatal("");
3549                                    jdiSUM0w[hidx]+=jdiw;
3550                                    jdiSUM0v[hidx]+=jdiv;
3551                                    jdiSUM0n[hidx]+=jdin;
3552                                    jdiFREQ1[hidx]++;
3553                                    jditotalw+=jdiw;
3554                                    jditotalv+=jdiv;
3555                                    jditotaln+=jdin;
3556                                    jdintabs++;
3557                                    if (parmtrace) {
3558                                        char *h=jditable+hidx*hwidth;
3559                                        printf("[%9ld] %f,%f,%ld/%6ld %d,%s %d,",hidx,jdiSUM0w[hidx],jdiSUM0v[hidx],jdiSUM0n[hidx],jdiFREQ1[hidx],strlen(h),h,jlen);
3560                                        for (; jlen--; jp++) printf("%c",*jp); //getchar();
3561                                        printf("\n");
3562                                    }
3563                                }
3564                            }//end for dirp
3565                          }//end if RECORD
3566                        }//end if jdimfn
3567                        *p=c;//restore
3568                    }//end if len
3569                    /* move line ptr */
3570                    while (*p == '\r' || *p == '\n' || *p == delim) p++;
3571                    p0=p; len=0;
3572                    if (!*p0) break;
3573                }//if !*p || *p == '\r' || *p == '\n' || *p == delim
3574                else {
3575                    p++; len++;
3576                }//end if !*p || *p == '\r' || *p == '\n' || *p == delim
3577            } /* end for */
3578            //list and reinit
3579            if (jditotalw) {
3580                long  hidx=0;
3581                char *h=jditable;
3582                int hwidth=(jdiwidth+1);
3583                float *w=jdiSUM0w;
3584                float *v=jdiSUM0v;
3585                long  *n=jdiSUM0n;
3586                long  *f=jdiFREQ1;
3587                long  rev;
3588                int   sbufs=0;
3589                char *sbufp=jdiSBUF;
3590                int   s1u,s1,s2;
3591                char *p1,*p2;
3592                *(batchp=mx_bup)='\0';
3593                for (; hidx < jdimaxprim; hidx++, h+=hwidth, w++, v++, n++, f++) {
3594                    if (!*h) continue;
3595                    if (!*w) continue;
3596                    if (jdisminw) if (*w / *f < jdisminw) continue;
3597                    if (jdisminw) if (*w / *f < jdisminw) continue;
3598                    if (jdisminn) if (     *f < jdisminn) continue;
3599                    rev=999999999L;
3600                    if (jdisort == JDISORTW1) /* w1 */   rev-=(long)( 100000*         *w / *f        );
3601                    if (jdisort == JDISORTW2) /* w2 */   rev-=(long)( 100000*         *w / jdintabs  );
3602                    if (jdisort == JDISORTW3) /* w3 */   rev-=(long)( 100000*         *w / jditotalw );
3603                    if (jdisort == JDISORTV1) /* v1 */   rev-=(long)( 100000*         *v / *f        );
3604                    if (jdisort == JDISORTV2) /* v2 */   rev-=(long)( 100000*         *v / jdintabs  );
3605                    if (jdisort == JDISORTV3) /* v3 */   rev-=(long)( 100000*         *v / jditotalv );
3606                    if (jdisort == JDISORTN1) /* n1 */   rev-=(long)(         (float) *n / *f        );
3607                    if (jdisort == JDISORTN2) /* n2 */   rev-=(long)( 100000* (float) *n / jdintabs  );
3608                    if (jdisort == JDISORTN3) /* n3 */   rev-=(long)( 100000* (float) *n / jditotaln );
3609                    sprintf(sbufp,"%09ld%s",rev,h); sbufp+=jdislen; jdiSBUH[sbufs++]=hidx;
3610                } /* end hidx */
3611                if (sbufs>jdisstop) sbufs=jdisstop;
3612                for (s1=0, p1=jdiSBUF, s1u=sbufs-1; s1<s1u; s1++, p1+=jdislen) {
3613                    for (s2=s1+1, p2=jdiSBUF+jdislen*s2; s2<sbufs; s2++, p2+=jdislen) {
3614                        if (memcmp(p1,p2,jdislen) <= 0) continue;
3615                        memcpy(jdiSBUFx,p1  ,jdislen); 
3616                        memcpy(p1  ,p2  ,jdislen); 
3617                        memcpy(p2  ,jdiSBUFx,jdislen); 
3618                        hidx=jdiSBUH[s1]; jdiSBUH[s1]=jdiSBUH[s2]; jdiSBUH[s2]=hidx;
3619                    } /* end s2 */
3620                } /* end s1 */
3621                for (sbufp=jdiSBUF, s1=0; s1<sbufs; s1++, sbufp+=jdislen) {
3622                    sscanf(sbufp,"%09ld",&rev); hidx=jdiSBUH[s1];
3623                    h=jditable+hidx*hwidth;;
3624                    w=jdiSUM0w+hidx;
3625                    v=jdiSUM0v+hidx;
3626                    n=jdiSUM0n+hidx;
3627                    f=jdiFREQ1+hidx;
3628                  //if (jdiadd55) { sprintf(batchp,"A%ld\001",(long)jdiadd55); batchp+=strlen(batchp); }
3629                    if (jdiadd55) { sprintf(batchp,"<%ld 0>" ,(long)jdiadd55); batchp+=strlen(batchp); }
3630                    if (jdiaddfm == 2) 
3631                    sprintf(batchp,"%s|w|%8.6f|%8.6f|%8.6f|v|%8.6f|%8.6f|%8.6f|n|%4.2f|%4.2f|%8.6f|t|%6.4f|%6.4f|%ld|%ld|T|%4.2f|%4.2f|%ld|%ld"
3632                           ,         h
3633                           ,        *w / *f
3634                           ,        *w / jdintabs
3635                           ,        *w / jditotalw
3636                           ,        *v / *f
3637                           ,        *v / jdintabs
3638                           ,        *v / jditotalv
3639                           ,(float) *n / *f
3640                           ,(float) *n / jdintabs
3641                           ,(float) *n / jditotaln
3642                           ,        *w
3643                           ,        *v
3644                           ,        *n
3645                           ,        *f
3646                           ,         jditotalw
3647                           ,         jditotalv
3648                           ,         jditotaln
3649                           ,         jdintabs
3650                    );
3651                    else
3652                    sprintf(batchp,"%s|T|%4.2f|%4.2f|%ld|%ld|t|%f|%f|%ld|%ld|w|%8.6f|%8.6f|%8.6f|v|%8.6f|%8.6f|%8.6f|n|%4.2f|%4.2f|%8.6f"
3653                           ,         h
3654                           ,         jditotalw
3655                           ,         jditotalv
3656                           ,         jditotaln
3657                           ,         jdintabs
3658                           ,        *w
3659                           ,        *v
3660                           ,        *n
3661                           ,        *f
3662                           ,        *w / *f
3663                           ,        *w / jdintabs
3664                           ,        *w / jditotalw
3665                           ,        *v / *f
3666                           ,        *v / jdintabs
3667                           ,        *v / jditotalv
3668                           ,(float) *n / *f
3669                           ,(float) *n / jdintabs
3670                           ,(float) *n / jditotaln
3671                    );
3672                    if (parmtrace || jdipshow) printf("%ld|%d|%s\n",mfn,s1+1,batchp);
3673                    batchp+=strlen(batchp); 
3674                  //if (jdiadd55) { sprintf(batchp,"\001"); batchp+=strlen(batchp); }
3675                    if (jdiadd55) { sprintf(batchp,"</%ld>",(long)jdiadd55); batchp+=strlen(batchp); }
3676                    *w=0.0; *v=0.0; *n=0.0; *f=0; *h='\0'; //reinit
3677                } /* end hidx */
3678                jditotalw=0.0; jditotalv=0.00; jditotaln=0; jdintabs=0;
3679            } /* end jditotalw */
3680            if (jdiadd55) if (mx_bup[0]) { char *p=fldupdat(irec,mx_bup); if (p) { if (parmtrace) fatal(p); else fatal("mx/jdi/fldupdat"); } }
3681        } /* end parmtabjdip */
3682
3683        /* proc */
3684        if (mp_n) if (mp_edit(xmxp,irec,0,mp_n-1)) MXEXIT(1);
3685
3686        /* convert */
3687        if (tabconvp) {
3688            unsigned char *p,c;
3689            unsigned int n,i,pi;
3690            for (p=FIELDP(0), n=MFRmfrl-MFRbase; n--; p++) {
3691                pi=(int)(*p);
3692                i=(int)tabconvp[pi];
3693                c = (unsigned char )i;
3694                *p=c;
3695            }
3696        }
3697
3698#if MXFST
3699        if (fstpgmp) {
3700            *mx_bup='\0'; if (parmfstup) fst_batchup=mx_bup; /* fst_batchp=mx_bup; */
3701            fst_inter(fstpgmp,irec,stwp,
3702                        &lnk1p,maxlk1,&lnk2p,maxlk2,&qtylk1,&qtylk2);
3703            fst_fx[0]+=qtylk1; /* lnk1p */
3704            fst_fx[1]+=qtylk2; /* lnk2p */
3705            if (*mx_bup) if (fldupdat(irec,mx_bup)) fatal(mx_bup);
3706            if (fst_hdrp) if (*fst_hdrp) {
3707                sprintf(mx_bup,"H 33000 %d ",fst_hdru);
3708                batchp=mx_bup+strlen(mx_bup);
3709                memcpy(batchp,fst_hdrp,fst_hdru); *(batchp+fst_hdru)='\0';
3710                if (fldupdat(irec,mx_bup)) fatal(mx_bup);
3711            }
3712        }
3713#endif /* MXFST */
3714
3715
3716        if (parmdir)        prtdir(recp,MFRmfn);
3717
3718        if (parmfields)     prtfields(recp,MFRmfn);
3719
3720        if (fmtarea) {
3721#if BEFORE20010213
3722            fmt_inter(pgmp,irec,(LONGX)fmtlw,fmtarea,(LONGX)fmtasize);
3723#else
3724            if (fmt_inter(pgmp,irec,(LONGX)fmtlw,fmtarea,(LONGX)fmtasize) < 0)
3725                fatal("mx/pft/format execution error");
3726#endif
3727            if (parmoutmfntag) {
3728              char delim='|';
3729              int tag=parmoutmfntag+1;
3730              FFI len;
3731              char *p0=fmtarea;
3732              batchp=mx_bup; *batchp='\0';
3733              for (len=0, p=p0; ; ) {
3734                if (!*p || *p == '\r' || *p == '\n' || *p == delim) {
3735                    if (len) {
3736                        sprintf(batchp,"H%ld %ld ",(LONGX)tag,(LONGX)len); batchp+=strlen(batchp);
3737                        memcpy(batchp,p0,len); *(batchp+=len)='\0';
3738                    }
3739                    if (mx_bup[0]) {
3740                        /* out rec */
3741                        RECSTRU *recp;
3742                        RECORD(upirec,VRDBname(upcrec),VMF0nxtmfn(upcrec)); MFRstatus=ACTIVE;
3743                        sprintf(batchp+1,"A%ld/%ld/",(LONGX)parmoutmfntag,VMFRmfn(irec));
3744                        if (fldupdat(upirec,batchp+1)) fatal("mx/outpft/fldupdat/1");
3745                        if (fldupdat(upirec,mx_bup)) fatal("mx/outpft/fldupdat/2");
3746                        recupdat(upcrec,upirec);
3747                        /* re-init */
3748                        batchp=mx_bup; *batchp='\0'; tag=parmoutmfntag+1;
3749                    }
3750                    else tag++;
3751                    /* move line ptr */
3752                    while (*p == '\r' || *p == '\n' || *p == delim) p++;
3753                    p0=p; len=0;
3754                    if (!*p0) break;
3755                }
3756                else {
3757                    p++; len++;
3758                }
3759              } /* end for */
3760            } /* end parmoutpft */
3761            else
3762            if (ptabtable) {
3763              /* tabulate generated lines */
3764              char delim=0x01; //'|';
3765              FFI len;
3766              char *p0=fmtarea;
3767              for (len=0, p=p0; ; ) {
3768                /* next line */
3769                if (!*p || *p == '\r' || *p == '\n' || *p == delim) {
3770                    if (len) {
3771                        /* tabulate line */
3772                        LONGX hidx;
3773                        int hwidth=(ptabwidth+1);
3774                        int hfound;
3775                        int tabv=1;
3776                        if (parmtabtg) {
3777                            FFI loop;
3778                            DIRSTRU *dirp;
3779                            int xdir;
3780                            for (dirp=MFRdir, xdir=0, loop=MFRnvf; loop--; dirp++, xdir++) {
3781                                int len;
3782                                char *p;
3783                                if (dirp->tag != parmtabtg) continue;
3784                                p=FIELDP(xdir);
3785                                for (tabv=0, len=dirp->len; len--; p++) if (isdigit(*p)) tabv=tabv*10+((int)*p - (int)'0'); else break;
3786                            }
3787                        }
3788                        hidx=hashindex(ptabtable,ptabmaxprim,ptabwidth,p0,len,&hfound,1);
3789                        //if (hfound) if (!hfound) fatal("");
3790                        ptabCOUNT[hidx]+=tabv;
3791                        if (parmtrace) { char *h=ptabtable+hidx*hwidth; printf("[%9ld] %9ld %s\n",hidx,jdiFREQ1[hidx],h); }
3792                    }//end if len
3793                    /* move line ptr */
3794                    while (*p == '\r' || *p == '\n' || *p == delim) p++;
3795                    p0=p; len=0;
3796                    if (!*p0) break;
3797                }//if !*p || *p == '\r' || *p == '\n' || *p == delim
3798                else {
3799                    p++; len++;
3800                }//end if !*p || *p == '\r' || *p == '\n' || *p == delim
3801              } /* end for */
3802            } /* end ptabtable */
3803            else
3804            if (parmpftoutfp) { char *q=mx_bup;
3805              for (p=fmtarea; *p; p++)
3806                if (*p != '\r') *q++=(*p);
3807              *q='\0'; if (*mx_bup) fprintf(parmpftoutfp,"%s",mx_bup);
3808            }   
3809            else
3810              for (p=fmtarea; *p; p++)
3811                if (*p != '\r')
3812                    putchar(*p);
3813        }
3814
3815        if (parmsysp) {
3816            if (!parmsysa) {
3817                parmsysa=loadfile(NULL,'@',"",NULL,fmtasize+1,'\0');
3818        if (!parmsysa) fatal("ALLOC/parmsysa");
3819        }
3820#if BEFORE20010213
3821            recfmt(irec,MAXMFRL,parmsysp,parmsysa,fmtasize);
3822#else
3823            if (recfmt(irec,MAXMFRL,parmsysp,parmsysa,fmtasize) < 0)
3824                fatal("mx/sys/format execution error");
3825#endif
3826            for (shp=parmsysa; *shp; ) {
3827                for (p=shp; *p; p++)
3828                    if (*p == '\n' || *p == '\r') {
3829                        *p++ = '\0';
3830                        if (*p == '\n' || *p == '\r') *p++ = '\0';
3831                        break;
3832                    }
3833                if (*shp) {
3834                    n=1;
3835                    if (parmsyss) {
3836                        printf("%s\n",shp);
3837                        printf(prompt1p); isxp=gets(line); q=isxp;
3838                        if (ISX(q)) n=0;
3839                    }
3840                    if (n) system(shp);
3841                }
3842                shp = p;
3843            }
3844        }
3845
3846        if (parmmfrl)
3847            if (MFRmfrl > parmmfrl) {
3848                printf("MFN=%ld -> MFRmfrl=%d\n",MFRmfn,MFRmfrl);
3849                parmmfrl=MFRmfrl;
3850            }
3851
3852#if TB
3853    for (itagbin=0; itagbin < ntagbin; itagbin++) {
3854        tagbin=vtagbin[itagbin];
3855#if 1
3856#if BEFORE20000913
3857        if (tagbin > 999) {
3858#else
3859        if (tagbin == 0) {
3860#endif
3861          sprintf(line,"create=%ld.dat",MFRmfn);
3862          dbxopenc(NULL,line,&fdtagbin,NULL,line,0,0);
3863          if (parmtrace) printf("+++ %s fd=%d\n",line,fdtagbin);
3864          for (xdir=0; xdir < MFRnvf; xdir++)
3865                if ((unsigned)CIWRITE(fdtagbin,FIELDP(xdir),DIRlen(xdir))
3866                != DIRlen(xdir)) fatal("mx/tbin/write");
3867          CLOSE(fdtagbin);
3868        } else
3869#endif
3870        if ((xdir=fieldx(irec,tagbin,1)) >= 0) {
3871          sprintf(line,"create=%ld%c%d",MFRmfn,'.',tagbin);
3872          dbxopenc(NULL,line,&fdtagbin,NULL,line,0,0);
3873          if (parmtrace) printf("+++ %s fd=%d\n",line,fdtagbin);
3874          for (xdir=0; xdir < MFRnvf; xdir++)
3875           if (DIRtag(xdir) == tagbin)
3876              if ((unsigned)CIWRITE(fdtagbin,FIELDP(xdir),DIRlen(xdir))
3877              != DIRlen(xdir)) fatal("mx/tbin/write");
3878          CLOSE(fdtagbin);
3879        }
3880    }
3881#endif /* TB */
3882
3883        if (parmcopy || parmiso2) {
3884#if RECXPND
3885            if (parmxpn01) recxpn00(irec,parmxpn01,parmxpn02); /* tag,dlm */
3886#endif
3887            if (parmiso2 && MFRnvf > 0) {
3888                if (parmiso2 == 1) iso_write(recp,parmisoxfs,parmisoxgs,parmisoldrtag);
3889                        else {
3890                            p=mx_bup; *p='\0';
3891                            for (xdir=0; xdir < MFRnvf; xdir++) {
3892                                memcpy(p,FIELDP(xdir),n=DIRlen(xdir));
3893                                p+=n;
3894                                *p++='|';
3895                            }
3896                            *(p-1)='\n'; *p='\0';
3897                            fprintf(fpfix,"%s",mx_bup);
3898                        }
3899            }
3900            if (parmcopy) if (!parmoutmfntag) {
3901                if (parmdupp) {
3902                    if (MFRnvf == 0) {
3903                        if (fldupdat(irec,"A1//")) fatal("A1//");
3904                    }
3905                    for (p=parmdupp; *p; p++) {
3906                        record(upirec,VRDBname(upcrec),VMF0nxtmfn(upcrec));
3907                        VMFRstatus(upirec)=ACTIVE;
3908                        q=mx_bup; n=DIRlen(0); n++;
3909                        sprintf(q,"H%d %d ",DIRtag(0),n); q+=strlen(q);
3910                        if (parmdupx == DUPPLEFT) *q++ = *p;
3911                        memcpy(q,FIELDP(0),DIRlen(0)); q+=DIRlen(0);
3912                        if (parmdupx == DUPPRIGHT) *q++ = *p;
3913                        *q = '\0';
3914                        if (fldupdat(upirec,mx_bup)) fatal(mx_bup);
3915                        recupdat(upcrec,upirec);
3916                    }
3917                }
3918                else {
3919                    n=1;
3920                    if (parmcopy == UPDATF) if (MFRnvf <= 0) n=0;
3921                    if (parmcopy == UPDATF && n) {
3922                        nbytes=sizeof(LONGX)*MAXUPFTAG;
3923                        if (!tagfreq) {
3924                            tagfreq=(LONGX *)ALLOC((ALLOPARM)nbytes);
3925                            if (tagfreq == (LONGX *)ALLONULL)
3926                                fatal("ALLOC/tagfreq");
3927                        }
3928                        memset(tagfreq,0x00,nbytes);
3929                        record(upirec,VRDBname(upcrec),MFRmfn); /* RLOCK */
3930                        if (VRECrc(upirec) == RCLOCK) FATLOCK;
3931                        for (xdir=0; xdir < MFRnvf; xdir++)
3932                            if (DIRtag(xdir) >= MAXUPFTAG) fatal("MAXUPFTAG");
3933                            else tagfreq[DIRtag(xdir)]++;
3934                        batchp=mx_bup;
3935                        for (utag=0; utag < MAXUPFTAG; utag++)
3936                            if (tagfreq[utag]) {
3937                                sprintf(batchp,"D%ld",(LONGX)utag);
3938                                batchp+=strlen(batchp);
3939                            }
3940                        *batchp='\0';
3941                        if ((p=fldupdat(upirec,mx_bup)) != NULL) fatal(p);
3942                        batchp=mx_bup;
3943                        for (xdir=0; xdir < MFRnvf; xdir++) {
3944                            sprintf(batchp,"H%6ld %6ld ",
3945                                (LONGX)DIRtag(xdir),(LONGX)DIRlen(xdir));
3946                            batchp+=strlen(batchp);
3947                            memcpy(batchp,FIELDP(xdir),DIRlen(xdir));
3948                            batchp+=DIRlen(xdir);
3949                        }
3950                        *batchp='\0';
3951                        if ((p=fldupdat(upirec,mx_bup)) != NULL) fatal(p);
3952                    }
3953
3954                    if (parmcopy == MERGE) {
3955                        record(upirec,VRDBname(upcrec),MFRmfn); /* RLOCK */
3956                    if (VRECrc(upirec) == RCLOCK) FATLOCK;
3957                        if (VRECrc(upirec) == RCNORMAL) n=0;
3958                    }
3959
3960                    if (parmcopy == APPEND) if (MFRnvf <= 0) n=0;
3961
3962                    if (n) {
3963#if MULTI
3964                        if (VRDBnetws(upcrec) != MONONETS) {
3965                            if (parmcopy == APPEND) {
3966                                memcpy(VMFX(upirec),MFX,MFRmfrl);
3967                                VMFRmfn(upirec)=0L;
3968                                VRECwlock(upirec)|=NEWREC;
3969                            }
3970                            else {
3971                                if (parmcopy != UPDATF) {
3972                                    record(upirec,VRDBname(upcrec),MFRmfn); /* RLOCK */
3973                            if (VRECrc(upirec) == RCLOCK) FATLOCK;
3974                                    memcpy(VMFX(upirec),MFX,MFRmfrl);
3975                                }
3976                                VRECwlock(upirec)|=NEWREC|FORCE;
3977                            }
3978                        }
3979                        else {
3980                            if (parmcopy != UPDATF)
3981                            reccopy(upirec,upcrec,recp,MFRmfn);
3982                            if (parmcopy == APPEND)
3983                                VMFRmfn(upirec)=VMF0nxtmfn(upcrec);
3984                        }
3985                        recupdat(upcrec,upirec);
3986#else
3987                        if (parmcopy != UPDATF)
3988                            reccopy(upirec,upcrec,recp,MFRmfn);
3989                        if (parmcopy == APPEND)
3990                            VMFRmfn(upirec)=VMF0nxtmfn(upcrec);
3991                        recupdat(upcrec,upirec);
3992#endif
3993                    }
3994                }
3995            }
3996        }
3997
3998#if MXIFUPD
3999        if (ifnp) {
4000            if (svdifupx) {
4001#if BEFORE20000831
4002#else
4003                if (svdifupx == 1) {
4004                    upif_init(ifnp); svdifupx=2;
4005#if MULTI
4006#if CIAPI
4007                    if (dbnp_dbxnetws(ifnp) == FULLNETS) svdifupy=1;
4008#else /* CIAPI */
4009                    if (dbxstorp(ifnp)->dbxnetws == FULLNETS) svdifupy=1;
4010#endif /* CIAPI */
4011#endif /* MULTI */
4012                }
4013                else if (svdifupy) upif_init(ifnp);
4014#endif
4015                svdifupd(lnk1p,qtylk1,lnk2p,qtylk2,             /* add new */
4016                         NULL,0,NULL,0,                         /*         */
4017                         pstflag,0L);
4018#if CIAPI
4019                     dbnp_dbxirecs(ifnp)+=1;
4020                     dbnp_dbxipadd(ifnp)[0]+=qtylk1;
4021                     dbnp_dbxipadd(ifnp)[1]+=qtylk2;
4022#else /* CIAPI*/
4023                ifndbxp->dbxirecs++;
4024                ifndbxp->dbxipadd[0]+=qtylk1;
4025                ifndbxp->dbxipadd[1]+=qtylk2;
4026#endif /* CIAPI*/
4027#if BEFORE20000831
4028#else
4029                if (svdifupy) { upif_end(ifnp,pstflag); invflush(ifnp); }
4030#endif
4031            }
4032            else
4033                ifupdat(VRDBname(mstcrec),VMFRmfn(mstirec),VMFRmfn(mstirec),
4034                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,endup);
4035        }
4036#endif
4037
4038    }  /* end of record */
4039
4040
4041    if (ISX(isxp)) MXEXIT(0);
4042
4043    if (parmwait && boolqryp != NULL) {
4044        do {
4045            printf(prompt2p); isxp=gets(line); p=isxp;
4046            if (!p) break;
4047        } while (!*p);
4048        if (ISX(p) || !p)
4049            MXEXIT(0);
4050        if (mxbool(xmxp,p,dbnp)) MXEXIT(1); count=0;
4051        goto LOOP;
4052    }
4053
4054    MXEXIT(0);
4055}
Note: See TracBrowser for help on using the browser.