root/tags/5.4.pre05/mxrun.c

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

Criação do svn para Cisis.

Line 
1/* ------------------------------ mxrun.c --------------------------------- */
2
3#include <stdio.h>
4#include <string.h>
5/* #include <ctype.h> */
6
7#if 1
8#if CIAPI
9#include "ciapi.h"   /* CISIS Interface API header file -
10                  includes cisis, implements cirun.h and ci*.c using ci*.?pp */
11#if !MXFUN
12extern void *ciapip;
13#endif /* MXFUN */
14
15#else /* CIAPI */
16#include "cisis.h"   /* CISIS Interface header file */
17#endif /* CIAPI */
18#include "mx.h"   /* CISIS Interface runtime declarations */
19#else
20#include "\cisis\include\cisis.h"   /* CISIS Interface header file */
21#include "\cisis\mx\mx.h"           /* MX Program header file */
22#endif
23
24
25/* ------------------------------ mx.c ------------------------------------- */
26
27#if MXFUN
28int mxinit(xmxpp)
29void **xmxpp;
30{
31    MXFUN_XMX *xmxp;
32    *xmxpp=NULL;
33    xmxp=(MXFUN_XMX *)ALLOC((ALLOPARM)sizeof(MXFUN_XMX));
34    if (xmxp == (MXFUN_XMX *)ALLONULL) return(1);
35    memset((char *)xmxp,sizeof(MXFUN_XMX),0x00);
36    *xmxpp=(void *)xmxp;
37#include "mxfun.c"
38    return(0);
39}
40#else /* MXFUN */
41
42#if OPEN30
43union REGS      d33_regs;
44struct SREGS    d33_sregs;
45unsigned short  newax;
46#endif
47
48char *parmprologp=NULL;
49char *parmepilogp=NULL;
50LONGX  irecepilog=0L;
51#if CICGI
52LONGX wwrec1=0L,wwrec2=0L;
53char *cgixpok=NULL;
54#endif /* CICGI */
55
56FMT_CODE *pgmp;
57char *fmtarea=NULL;
58LONGX fmtlw=79;
59LONGX fmtlines;
60LONGX fmtasize=MAXMFRL;
61FILE *fp;
62
63char *ptabtable=NULL;
64int   ptabwidth=100; //LE2+LE2;
65LONGX  ptabcategories=300000;
66LONGX  ptabmaxprim;
67LONGX *ptabCOUNT=NULL;  /* n(t) */
68
69LONGX parmtell = 0;
70LONGX parmload = 0;
71int parmtrace = 0;
72int parmcopy  = 0;
73
74char *parmdupp = NULL;
75int parmdupx = 0;
76
77LONGX *tagfreq;
78
79int parmiso1  = 0;
80int parmiso2  = 0;
81FILE *fpfix = NULL;    /*parmiso2=2 */
82
83#if RECXPND
84int parmxpn01 = 0;
85int parmxpn02 = 0;
86#endif
87#if MXGIZP
88char *parmgizp = NULL;
89int parmgizhp = 0;
90#endif
91
92char *prompt1p = "..";
93char *prompt2p = "->";
94
95char promptxx[2];
96
97char line[LINSIZE];              /* recfgets() + working */
98char prmbuff[PRMSIZE];           /* in= */
99
100FILE *fpseq = NULL;
101FILE *fpprm = NULL;
102
103FILE *vfpprm[MAXNFPRM];
104int nfpprms=0;
105
106int tmpseq=0;                   /* mxexit() */
107char *mx_bup=NULL;/*free*/                   /* global */
108LONGX mx_buplen=0L;              /* global */
109
110LONGX upcrec=0L;                 /* global */
111LONGX upirec=0L;                 /* global */
112
113#if MXFULLINV
114char *fullinv_ifnp=NULL;
115char *fullinv_ln1p=NULL;
116char *fullinv_ln2p=NULL;
117char *fullinv_lk1p=NULL;
118char *fullinv_lk2p=NULL;
119int fullinv_pstflag=IFUPISIS;
120int fullinv_reset=1;
121int fullinv_balan=1;
122int fullinv_keep=0;
123#if LIND
124LONGX fullinv_maxmfn=0L;
125#endif
126char *fullinv_master=NULL;
127#endif
128
129#if MXIFUPD
130LONGX mstcrec=0L;/*free*/
131LONGX mstirec=0L;/*free*/
132char *ifnp=NULL;
133int svdifupx=0;
134int svdifupy=0;
135#endif
136
137#if MXIFUPD
138int pstflag=IFUPISIS;
139int endup=IFUPCORE;
140#endif
141
142#if MXIFUPD || MXFST
143char *stwp=NULL;
144FST_CODE *fstpgmp=NULL;
145char *lnk1p=NULL;
146char *lnk2p=NULL;
147LONGX maxlk1=1000;
148LONGX maxlk2=500;
149#endif
150
151PRMSTRU *vprmp[MAXNPRM];        /* pointers to the entries      */
152LONGX nprms=0;                   /* actual #entries              */
153LONGX maxnprm=MAXNPRM;           /* runtime value                */
154
155
156/* ------------------------------ mx.h ------------------------------------- */
157
158#if RECXPND
159#endif
160
161#if RECGIZM
162#endif
163
164
165
166
167/* ------------------------------ mxbol.c --------------------------------- */
168
169
170char *boolqryp=NULL;
171LONGX boolridx=0;
172LONGX boolhits=0;
173LONGX boolh=0;
174
175char *booldbnp = NULL;          /* b4x query dbn */
176LONGX booltell=1L;               /* 0L = no msg */
177LONGX booltlir=0L;               /* b40 invx */
178
179#if CIB71
180b7_CIB7 *cib7p=NULL;
181char booltmpnam[CIMPL+1]={'\0'};    /* b72 MFQTHMEM tmp file */
182#else /* CIB71 */
183#if LIND || CIB64
184LONGX boolnby1=0L;               /* b62 nbytes1 */
185LONGX boolnbyb=0L;               /* b62 b6bufsiz */
186LONGX boolnby0=0L;               /* b62 b5irxbyts0 */
187char booltmpnam[CIMPL+1]={'\0'};    /* b62 MFQTHMEM tmp file */
188int boolerrno=0;                /* b62 errno */
189#else
190LONGX boolnby2=MAXMFRL;          /* b42 nbytes2 */
191#endif
192#endif /* CIB71 */
193
194/* ------------------------------ mxrel.c --------------------------------- */
195
196/* ========================== mp_scan/mp_edit ============================= */
197
198FMT_CODE *mp_pgmp[MAXNPPP];
199int mp_n = 0;
200char *mp_areap=NULL;
201
202/* ====================== mj_scan/mj_edit/mj_join ========================= */
203
204MJ_TAGS *mj_vtagp[MAXNJJJ];
205MJ_STWS *mj_vstwp[MAXNJJJ];
206FMT_CODE *mj_pgmp[MAXNJJJ];
207LONGX mj_plustag[MAXNJJJ]; /* AOT 23/04/2005 */
208LONGX mj_ridx[MAXNJJJ];
209LONGX mj_tidx=0;
210char *mj_areap=NULL;
211char *mj_buffup=NULL;
212int mj_pjchk[MAXNJJJ];
213int mj_n=0;
214LONGX mj_jmax=LONGX_MAX;
215UWORD mj_jtag=32000;
216
217/* ------------------------------ mxtxt.c --------------------------------- */
218
219int  mxtext_found=0;
220int  mxtext_fdir;
221int  mxtext_foff;
222int  mxtext_pshow=0;
223
224#endif /* MXFUN */
225
226
227
228
229/* ============================== mxexit ================================== */
230
231int mxexit(xmxp,rc)
232void *xmxp;
233int rc;
234{
235#if MXIFUPD
236    DBXSTRU *dbxp;
237#endif
238#if RECGIZM
239#if MXGIZP
240    int i,n,igiz;
241    LONGX idbx,nused;
242    char *p,*q,usedbn[CIMPL+1];
243    VGIZPSTRU *gizmap;
244    GIZMSTRU *gizmp;
245#endif
246#endif
247
248#if CICGI
249//    if (parmepilogp && wwrec2) /* then wwrec1 was alloced */ {
250//        if (recfmt(wwrec1,rec_maxmfrl,parmepilogp,mx_bup,mx_buplen) < 0) {
251    if (parmepilogp && irecepilog) /* then wwrec1 was alloced */ {
252        if (recfmt(irecepilog,rec_maxmfrl,parmepilogp,mx_bup,mx_buplen) < 0) {
253            printf("Content-type: text/plain\n\nMX fatal: %s",parmepilogp);
254        }
255        printf("%s",mx_bup);
256    }
257    else if (cgixpok) printf("\n</body></html>\n");
258#else /* CICGI */
259    if (parmepilogp) if (irecepilog) {
260        if (recfmt(irecepilog,rec_maxmfrl,parmepilogp,mx_bup,mx_buplen) < 0) {
261            printf("Content-type: text/plain\n\nMX fatal: %s",parmepilogp);
262        }
263        printf("%s",mx_bup);
264    }
265#endif /* CICGI */
266
267    if (ptabtable) {
268        LONGX hidx=0;
269        char *h=ptabtable;
270        int hwidth=(ptabwidth+1);       
271        LONGX *n=ptabCOUNT;
272        LONGX rev;
273        for (; hidx < ptabmaxprim; hidx++, h+=hwidth, n++) {
274            if (!*h) continue;
275            if (!*n) continue;
276            rev=999999999L - *n;
277            printf("%09ld|%ld|%s\n",rev,*n,h); //table+hidx*hwidth
278            if (parmtrace) printf("[%9ld] %9ld %s\n",hidx,n,h); //table+hidx*hwidth
279        }
280    }
281   
282#if RECGIZM
283#if MXGIZP
284    if ((p=parmgizp) != NULL) {
285
286        if (!upcrec)
287            recallok((upcrec=nrecs),(LONGX)sizeof(M0STRU));
288        if (!upirec)
289            recallok((upirec=nrecs),MAXMFRL);
290
291        for (idbx=0L; idbx < ndbxs; idbx++) {
292            if (idbx > 0)
293                break;
294            for (gizmap=VDBXvgzrp(idbx), igiz=0; gizmap; igiz++,
295                                                gizmap=gizmap->nextp) {
296                sprintf(usedbn,"%s%d",parmgizp,igiz);
297                recisis0(usedbn); record(upcrec,usedbn,0L);
298                nused=0;
299                fprintf(stderr,"+++ %s/giz%d=%s\n",VDBXname(idbx),igiz,gizmap->gdbnp);
300                for (i=0; i <= 255; i++) {
301                    gizmp=gizmap->ghdrp[i];
302                    if (!gizmp)
303                        continue;
304                    for (; gizmp; gizmp=gizmp->nextp) {
305                        if (gizmp->nused == 0) continue;
306                        nused++;
307                        record(upirec,usedbn,VMF0nxtmfn(upcrec));
308                        VMFRstatus(upirec)=ACTIVE; q=line;
309                        sprintf(q,"A10 #%ld#",gizmp->nused);    q+=strlen(q);
310                        sprintf(q,"H1   %d ",gizmp->isize);     q+=strlen(q);
311                        memcpy(q,gizmp->ipatt,n=gizmp->isize);  q+=n;
312                        sprintf(q,"H2   %d ",gizmp->osize);     q+=strlen(q);
313                        memcpy(q,gizmp->opatt,n=gizmp->osize);  q+=n;
314                        sprintf(q,"A31 #%d#",gizmp->isize);     q+=strlen(q);
315                        sprintf(q,"A32 #%d#",gizmp->osize);     q+=strlen(q);
316#if MXGIZHP
317                        if (parmgizhp) {
318                        sprintf(q,"A102#");                     q+=strlen(q);
319                        for (p=gizmp->ipatt, n=gizmp->isize; n--; p++, q+=2)
320                            sprintf(q,"%02x",*p);
321                        *q++ = '#';
322                        sprintf(q,"A202#");                     q+=strlen(q);
323                        for (p=gizmp->opatt, n=gizmp->osize; n--; p++, q+=2)
324                            sprintf(q,"%02x",*p);
325                        *q++ = '#';
326                        sprintf(q,"A103#");                     q+=strlen(q);
327                        for (p=gizmp->ipatt, n=gizmp->isize; n--; p++, q+=3)
328                            sprintf(q,"%03d",(int)*p);
329                        *q++ = '#';
330                        sprintf(q,"A203#");                     q+=strlen(q);
331                        for (p=gizmp->opatt, n=gizmp->osize; n--; p++, q+=3)
332                            sprintf(q,"%03d",(int)*p);
333                        *q++ = '#';
334                        }
335#endif
336                        *q = '\0';
337                        if ((p=fldupdat(upirec,line)) != NULL) fatal(p);
338                        recupdat(upcrec,upirec);
339                    }
340                }
341                fprintf(stderr,"+++ %s = %ld entries\n",usedbn,nused);
342                dbxflush(usedbn);
343            }
344        }
345    }
346#endif
347#endif
348
349    if (parmiso2 == 1) iso_close();
350
351    if (tmpseq) {
352#if DELETETMPSEQ
353        mstflush("tmpseq");
354#if PC
355        remove("tmpseq.xrf");
356        remove("tmpseq.mst");
357#endif
358#if MPE
359        system("purge tmpseq.xrf");
360        system("purge tmpseq.mst");
361#endif
362#if VAX
363        system("delete/noconfirm tmpseq.xrf;*");
364        system("delete/noconfirm tmpseq.mst;*");
365#endif
366#if UNIX
367        remove("tmpseq.xrf");
368        remove("tmpseq.mst");
369#endif
370#endif /* DELETETMPSEQ */
371    }
372
373#if CIB71
374    cib7p=b7_cib7_delete(cib7p);
375#endif
376#if LIND || CIB64
377    if (booltmpnam[0])           /* b62 MFQTHMEM tmp file */
378        remove(booltmpnam);
379#endif
380
381#if MXIFUPD
382    if (ifnp) {
383        if (svdifupx == 2) {
384            if (!svdifupy) upif_end(ifnp,pstflag);
385        }
386        else {
387            if (endup == IFUPCORE)
388                ifupdat(VRDBname(mstcrec),0L,0L,
389                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,IFUPWRIT);
390        }
391        dbxp=dbxstorp(ifnp); /* inverted file ! */
392        if (parmtell && DBXirecs) {
393            fprintf(stderr,"+++ %ld records updated      \n",DBXirecs);
394            fprintf(stderr,"+++ %ld+%ld postings added   \n",DBXipadd[0],DBXipadd[1]);
395            fprintf(stderr,"+++ %ld+%ld postings deleted \n",DBXipdel[0],DBXipdel[1]);
396    }
397}
398#endif
399
400#if MXFST
401    if (fstpgmp) {
402        if (lnk1p) FREE(lnk1p);
403        if (lnk2p) FREE(lnk2p);
404        lnk1p=lnk2p=NULL;
405        fst_clos(0); fst_clos(1); fst_fd[0]=fst_fd[1]=0;
406        if (parmtell)
407             if (fst_fx[0]+fst_fx[1])
408            fprintf(stderr,"+++ %ld+%ld links \n",fst_fx[0],fst_fx[1]);
409        fst_free(fstpgmp);
410    }
411#endif
412
413#if MULTI
414    /* process Data Entry Lock and Exclusive Write Lock */
415    if (parmcopy && VRDBdelxx(upcrec)) {
416        if (parmtrace) printf("DEL - %ld,%s\n",upcrec,VRDBname(upcrec));
417        VREClock(upcrec)=NOLOCK; record(upcrec,VRDBname(upcrec),0L);
418             recunlck(upcrec,DELOCK);
419             if (parmtrace) prtcontrol(vrecp[upcrec],VRDBname(upcrec));
420    }
421    if (parmcopy && VRDBewlxx(upcrec)) {
422        if (parmtrace) printf("EWL - %ld,%s\n",upcrec,VRDBname(upcrec));
423             VREClock(upcrec)=NOLOCK; record(upcrec,VRDBname(upcrec),0L);
424             recunlck(upcrec,EWLOCK);
425             if (parmtrace) prtcontrol(vrecp[upcrec],VRDBname(upcrec));
426    }
427#endif /* MULTI */
428
429#if MXFUN
430
431#if MXFULLINV
432    if (fullinv_ifnp) {
433      char *errp=NULL;
434      while (!errp) {
435        /* ifupdat(VRDBname(mstcrec),0L,0L,
436                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,IFUPWRIT); */
437        char cmdline[CIMPL+CIMPL+BUFSIZ+1];
438        char nameln1[CIMPL+1],nameln2[CIMPL+1];  /* dbname + .ext + NULL */
439        char namelk1[CIMPL+1],namelk2[CIMPL+1];  /* dbname + .ext + NULL */
440        int link1len,link2len;
441        int rc;
442
443#if PC || MYSFUN
444#else /* PC || MYSFUN */
445        char *setposix="";
446        char *restposix="";
447        char *envp,*p;
448        char envarea[BUFSIZ];
449
450        envp=getenv("OSTYPE");
451        if (parmtrace) printf("+++ mxrun envp: '%s'\n",envp?envp:"");
452#if UNIX /* AOT, 03/12/2002 */
453        if (!envp) { 
454            envp="LINUX"; 
455            if (parmtrace) printf("+++ mxrun envp: '%s'\n",envp);
456        }
457#endif
458        if (envp) {
459            strcpy(envarea,envp);
460            /* for (p=envarea; *p; p++) if (isalpha(*p)) { *p = toupper(*p); p++; }/* AOT/HB 02/08/2002 */
461                        for (p=envarea; *p; p++) if (isalpha(*p)) { *p = toupper(*p); }/* AOT/HB 19/02/2003 */
462            if (parmtrace) printf("+++ mxrun envarea: '%s'\n",envarea);
463            if (strstr(envarea,"LINUX")) {                                               /* AOT/HB 02/08/2002 */
464                setposix="BAK_LC_ALL=$LC_ALL;export LC_ALL=POSIX;";
465                restposix=";export LC_ALL=$BAK_LC_ALL";
466                if (parmtrace) printf("+++ mxrun setposix: '%s'\n",setposix);
467                if (parmtrace) printf("+++ mxrun restposix: '%s'\n",restposix);
468            }
469        }
470#endif /* PC || MYSFUN */
471
472        strcpy(nameln1,fullinv_ifnp); strcat(nameln1,".ln1");
473        strcpy(nameln2,fullinv_ifnp); strcat(nameln2,".ln2");
474        strcpy(namelk1,fullinv_ifnp); strcat(namelk1,".lk1");
475        strcpy(namelk2,fullinv_ifnp); strcat(namelk2,".lk2");
476
477        link1len=LE1+1+8+(ciiflfim?0:1+5+1+4+1+4)+(CRLF?2:1); /* 27: key %8ld %5d %4d %4d */
478        link2len=LE2+1+8+(ciiflfim?0:1+5+1+4+1+4)+(CRLF?2:1); /* 57: key %8ld %5d %4d %4d */
479
480#if PC || MYSFUN
481        rc=cisis_mysfunc(fullinv_ifnp,link1len,nameln1,namelk1,parmtell|parmtrace);
482#else /* PC || MYSFUN */
483        sprintf(cmdline,"%ssort -o %s %s%s",setposix,namelk1,nameln1,restposix);
484        if (parmtrace) printf("+++ mxrun sort 1: '%s'\n",cmdline);
485        rc=system(cmdline);
486#endif /* PC || MYSFUN */
487        if (rc) { errp="fullinv/sort/1"; break; }
488        if (!fullinv_keep) remove(nameln1);
489
490#if PC || MYSFUN
491        rc=cisis_mysfunc(fullinv_ifnp,link2len,nameln2,namelk2,parmtell|parmtrace);
492#else /* PC || MYSFUN */
493        sprintf(cmdline,"%ssort -o %s %s%s",setposix,namelk2,nameln2,restposix);
494        if (parmtrace) printf("+++ mxrun sort 2: '%s'\n",cmdline);
495        rc=system(cmdline);
496#endif /* PC || MYSFUN */
497        if (rc) { errp="fullinv/sort/2"; break; }
498        if (!fullinv_keep) remove(nameln2);
499
500        p=cmdline;
501        sprintf(cmdline,"%s\n%s\n%s\n+fix%s\ntell=%ld\n",
502                fullinv_ifnp,namelk1,namelk2,ciiflfim ? "/m" : "",parmtell);
503        p+=strlen(p);
504#if LIND
505        if (fullinv_maxmfn) {
506            sprintf(p,"maxmfn=%ld\n",fullinv_maxmfn); p+=strlen(p);
507        }
508        else if (fullinv_master) {
509            sprintf(p,"master=%s\n",fullinv_master); p+=strlen(p);
510        }
511        else {errp="mxrun/fullinv/maxmfn"; break; }
512#else /* LIND */
513        if (fullinv_reset) {
514            if (fullinv_master) {
515                sprintf(p,"master=%s\n",fullinv_master); p+=strlen(p);
516            }
517        }
518        else strcat(p,"-reset\n");
519#endif /* LIND */
520        if (fullinv_pstflag == IFUPDICT) strcat(p,"-posts\n");
521        if (!fullinv_balan)              strcat(p,"-balan\n");
522        if (parmtrace) printf("+++ mxrun cisis_ifload: '%s'\n",cmdline);
523        rc=cisis_ifload(cmdline);
524        if (rc) errp="fullinv/ifload";
525        if (!fullinv_keep) remove(namelk1);
526        if (!fullinv_keep) remove(namelk2);
527        break;
528      }
529      if (parmtrace) printf("+++ mxrun \n");
530      if (errp) fatal(errp);
531    }
532#endif /* MXFULLINV */
533
534    if (mx_bup) FREE(mx_bup);
535#if MXIFUPD
536#if CIAPI
537    if (mstcrec) { FREE(vrecp[mstcrec]); vrecp[mstcrec]=NULL; nrecs-=1; }
538    if (mstirec) { FREE(vrecp[mstirec]); vrecp[mstirec]=NULL; nrecs-=1; }
539#else /* CIAPI */
540    if (mstcrec) { FREE(vrecp[mstcrec]); vrecp[mstcrec]=NULL; nrecs--; }
541    if (mstirec) { FREE(vrecp[mstirec]); vrecp[mstirec]=NULL; nrecs--; }
542#endif /* CIAPI */
543#endif /* MXIFUPD */
544
545    if (rc) if (parmtrace) fprintf(stderr,"*** mx: end of execution [%d]\n",rc);
546
547#if CIAPI
548    cisisApplicationDelete( ciapip );
549#endif /* CIAPI */
550
551    FREE(xmxp);
552    return(0);
553
554#else /* MXFUN */
555    exit(rc);
556#endif /* MXFUN */
557}
Note: See TracBrowser for help on using the browser.