root/tags/5.4.pre05/mxaot.c

Revision 1, 135.5 kB (checked in by heitor.barbieri, 4 years ago)

Criação do svn para Cisis.

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