root/trunk/mxrun.c

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

essage first commit

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        if (parmpftoutfp && 0) fprintf(parmpftoutfp,"%s",mx_bup); else
256        printf("%s",mx_bup);
257    }
258    else if (cgixpok) printf("\n</body></html>\n");
259#else /* CICGI */
260    if (parmepilogp) if (irecepilog) {
261        if (recfmt(irecepilog,rec_maxmfrl,parmepilogp,mx_bup,mx_buplen) < 0) {
262            printf("Content-type: text/plain\n\nMX fatal: %s",parmepilogp);
263        }
264        if (parmpftoutfp && 0) fprintf(parmpftoutfp,"%s",mx_bup); else
265        printf("%s",mx_bup);
266    }
267#endif /* CICGI */
268
269#if FREEptabjdi
270#if CICPP
271     if (ptabjditrmp) {
272         delete ptabjditrmp;
273         ptabjditrmp=NULL;
274         ptabtable=NULL;
275     if (ptabjdirecp) {
276         delete ptabjdirecp;
277         ptabjdirecp=NULL;
278         ptabtable=NULL;
279     }
280#else /* CICPP */
281     if (ptabjditrm_prat != (-1L)) if (vtrmp[ptabjditrm_prat]!=NULL) {
282         FREE(vtrmp[ptabjditrm_prat]); vtrmp[ptabjditrm_prat]=NULL; ntrms--;
283         ptabjditrm_prat=(-1L);
284         ptabtable=NULL;
285     if (ptabjdirec_prat != (-1L)) if (vrecp[ptabjdirec_prat]!=NULL) {
286         FREE(vrecp[ptabjdirec_prat]); vrecp[ptabjdirec_prat]=NULL; nrecs--;
287         ptabjdirec_prat=(-1L);
288         ptabtable=NULL;
289     }
290#endif /* CICPP */
291#endif //FREEptabjdi
292
293    if (ptabtable) {
294        LONGX hidx=0;
295        char *h=ptabtable;
296        int hwidth=(ptabwidth+1);       
297        LONGX *n=ptabCOUNT;
298        LONGX rev;
299        for (; hidx < ptabmaxprim; hidx++, h+=hwidth, n++) {
300            if (!*h) continue;
301            if (!*n) continue;
302            rev=999999999L - *n;
303            printf("%09"_LD_"|%"_LD_"|%s\n",rev,*n,h); //table+hidx*hwidth
304            if (parmtrace) printf("[%9"_LD_"] %9"_LD_" %s\n",hidx,n,h); //table+hidx*hwidth
305        }
306    }
307   
308#if RECGIZM
309#if MXGIZP
310    if ((p=parmgizp) != NULL) {
311
312        if (!upcrec)
313            recallok((upcrec=nrecs),(LONGX)sizeof(M0STRU));
314        if (!upirec)
315            recallok((upirec=nrecs),MAXMFRL);
316
317        for (idbx=0L; idbx < ndbxs; idbx++) {
318            if (idbx > 0)
319                break;
320            for (gizmap=VDBXvgzrp(idbx), igiz=0; gizmap; igiz++,
321                                                gizmap=gizmap->nextp) {
322                sprintf(usedbn,"%s%d",parmgizp,igiz);
323                recisis0(usedbn); record(upcrec,usedbn,0L);
324                nused=0;
325                fprintf(stderr,"+++ %s/giz%d=%s\n",VDBXname(idbx),igiz,gizmap->gdbnp);
326                for (i=0; i <= 255; i++) {
327                    gizmp=gizmap->ghdrp[i];
328                    if (!gizmp)
329                        continue;
330                    for (; gizmp; gizmp=gizmp->nextp) {
331                        if (gizmp->nused == 0) continue;
332                        nused++;
333                        record(upirec,usedbn,VMF0nxtmfn(upcrec));
334                        VMFRstatus(upirec)=ACTIVE; q=line;
335                        sprintf(q,"A10 #%"_LD_"#",gizmp->nused);    q+=strlen(q);
336                        sprintf(q,"H1   %d ",gizmp->isize);     q+=strlen(q);
337                        memcpy(q,gizmp->ipatt,n=gizmp->isize);  q+=n;
338                        sprintf(q,"H2   %d ",gizmp->osize);     q+=strlen(q);
339                        memcpy(q,gizmp->opatt,n=gizmp->osize);  q+=n;
340                        sprintf(q,"A31 #%d#",gizmp->isize);     q+=strlen(q);
341                        sprintf(q,"A32 #%d#",gizmp->osize);     q+=strlen(q);
342#if MXGIZHP
343                        if (parmgizhp) {
344                        sprintf(q,"A102#");                     q+=strlen(q);
345                        for (p=gizmp->ipatt, n=gizmp->isize; n--; p++, q+=2)
346                            sprintf(q,"%02x",*p);
347                        *q++ = '#';
348                        sprintf(q,"A202#");                     q+=strlen(q);
349                        for (p=gizmp->opatt, n=gizmp->osize; n--; p++, q+=2)
350                            sprintf(q,"%02x",*p);
351                        *q++ = '#';
352                        sprintf(q,"A103#");                     q+=strlen(q);
353                        for (p=gizmp->ipatt, n=gizmp->isize; n--; p++, q+=3)
354                            sprintf(q,"%03d",(int)*p);
355                        *q++ = '#';
356                        sprintf(q,"A203#");                     q+=strlen(q);
357                        for (p=gizmp->opatt, n=gizmp->osize; n--; p++, q+=3)
358                            sprintf(q,"%03d",(int)*p);
359                        *q++ = '#';
360                        }
361#endif
362                        *q = '\0';
363                        if ((p=fldupdat(upirec,line)) != NULL) fatal(p);
364                        recupdat(upcrec,upirec);
365                    }
366                }
367                fprintf(stderr,"+++ %s = %"_LD_" entries\n",usedbn,nused);
368                dbxflush(usedbn);
369            }
370        }
371    }
372#endif
373#endif
374
375    if (parmiso2 == 1) iso_close();
376
377    if (tmpseq) {
378#if DELETETMPSEQ
379        mstflush("tmpseq");
380#if PC
381        remove("tmpseq.xrf");
382        remove("tmpseq.mst");
383#endif
384#if MPE
385        system("purge tmpseq.xrf");
386        system("purge tmpseq.mst");
387#endif
388#if VAX
389        system("delete/noconfirm tmpseq.xrf;*");
390        system("delete/noconfirm tmpseq.mst;*");
391#endif
392#if UNIX
393        remove("tmpseq.xrf");
394        remove("tmpseq.mst");
395#endif
396#endif /* DELETETMPSEQ */
397    }
398
399#if CIB71
400    cib7p=b7_cib7_delete(cib7p);
401#endif
402#if LIND || CIB64
403    if (booltmpnam[0])           /* b62 MFQTHMEM tmp file */
404        remove(booltmpnam);
405#endif
406
407#if MXIFUPD
408    if (ifnp) {
409        if (svdifupx == 2) {
410            if (!svdifupy) upif_end(ifnp,pstflag);
411        }
412        else {
413            if (endup == IFUPCORE)
414                ifupdat(VRDBname(mstcrec),0L,0L,
415                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,IFUPWRIT);
416        }
417        dbxp=dbxstorp(ifnp); /* inverted file ! */
418        if (parmtell && DBXirecs) {
419            fprintf(stderr,"+++ %"_LD_" records updated      \n",DBXirecs);
420            fprintf(stderr,"+++ %"_LD_"+%"_LD_" postings added   \n",DBXipadd[0],DBXipadd[1]);
421            fprintf(stderr,"+++ %"_LD_"+%"_LD_" postings deleted \n",DBXipdel[0],DBXipdel[1]);
422    }
423}
424#endif
425
426#if MXFST
427    if (fstpgmp) {
428        if (lnk1p) FREE(lnk1p);
429        if (lnk2p) FREE(lnk2p);
430        lnk1p=lnk2p=NULL;
431        fst_clos(0); fst_clos(1); fst_fd[0]=fst_fd[1]=0;
432        if (parmtell)
433             if (fst_fx[0]+fst_fx[1])
434            fprintf(stderr,"+++ %"_LD_"+%"_LD_" links \n",fst_fx[0],fst_fx[1]);
435        fst_free(fstpgmp);
436    }
437#endif
438
439#if MULTI
440    /* process Data Entry Lock and Exclusive Write Lock */
441    if (parmcopy && VRDBdelxx(upcrec)) {
442        if (parmtrace) printf("DEL - %"_LD_",%s\n",upcrec,VRDBname(upcrec));
443        VREClock(upcrec)=NOLOCK; record(upcrec,VRDBname(upcrec),0L);
444             recunlck(upcrec,DELOCK);
445             if (parmtrace) prtcontrol(vrecp[upcrec],VRDBname(upcrec));
446    }
447    if (parmcopy && VRDBewlxx(upcrec)) {
448        if (parmtrace) printf("EWL - %"_LD_",%s\n",upcrec,VRDBname(upcrec));
449             VREClock(upcrec)=NOLOCK; record(upcrec,VRDBname(upcrec),0L);
450             recunlck(upcrec,EWLOCK);
451             if (parmtrace) prtcontrol(vrecp[upcrec],VRDBname(upcrec));
452    }
453#endif /* MULTI */
454
455#if MXFUN
456
457#if MXFULLINV
458    if (fullinv_ifnp) {
459      char *errp=NULL;
460      while (!errp) {
461        /* ifupdat(VRDBname(mstcrec),0L,0L,
462                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,IFUPWRIT); */
463        char cmdline[CIMPL+CIMPL+BUFSIZ+1];
464        char nameln1[CIMPL+1],nameln2[CIMPL+1];  /* dbname + .ext + NULL */
465        char namelk1[CIMPL+1],namelk2[CIMPL+1];  /* dbname + .ext + NULL */
466        int link1len,link2len;
467        int rc;
468
469#if PC || MYSFUN
470#else /* PC || MYSFUN */
471        char *setposix="";
472        char *restposix="";
473        char *envp,*p;
474        char envarea[BUFSIZ];
475
476        envp=getenv("OSTYPE");
477        if (parmtrace) printf("+++ mxrun envp: '%s'\n",envp?envp:"");
478#if UNIX /* AOT, 03/12/2002 */
479        if (!envp) { 
480            envp="LINUX"; 
481            if (parmtrace) printf("+++ mxrun envp: '%s'\n",envp);
482        }
483#endif
484        if (envp) {
485            strcpy(envarea,envp);
486            /* for (p=envarea; *p; p++) if (isalpha(*p)) { *p = toupper(*p); p++; }/* AOT/HB 02/08/2002 */
487                        for (p=envarea; *p; p++) if (isalpha(*p)) { *p = toupper(*p); }/* AOT/HB 19/02/2003 */
488            if (parmtrace) printf("+++ mxrun envarea: '%s'\n",envarea);
489            if (strstr(envarea,"LINUX")) {                                               /* AOT/HB 02/08/2002 */
490                setposix="BAK_LC_ALL=$LC_ALL;export LC_ALL=POSIX;";
491                restposix=";export LC_ALL=$BAK_LC_ALL";
492                if (parmtrace) printf("+++ mxrun setposix: '%s'\n",setposix);
493                if (parmtrace) printf("+++ mxrun restposix: '%s'\n",restposix);
494            }
495        }
496#endif /* PC || MYSFUN */
497
498        strcpy(nameln1,fullinv_ifnp); strcat(nameln1,".ln1");
499        strcpy(nameln2,fullinv_ifnp); strcat(nameln2,".ln2");
500        strcpy(namelk1,fullinv_ifnp); strcat(namelk1,".lk1");
501        strcpy(namelk2,fullinv_ifnp); strcat(namelk2,".lk2");
502
503        link1len=LE1+1+8+(ciiflfim?0:1+5+1+4+1+4)+(CRLF?2:1); /* 27: key %8"_LD_" %5d %4d %4d */
504        link2len=LE2+1+8+(ciiflfim?0:1+5+1+4+1+4)+(CRLF?2:1); /* 57: key %8"_LD_" %5d %4d %4d */
505
506#if PC || MYSFUN
507        rc=cisis_mysfunc(fullinv_ifnp,link1len,nameln1,namelk1,parmtell|parmtrace);
508#else /* PC || MYSFUN */
509        sprintf(cmdline,"%ssort -o %s %s%s",setposix,namelk1,nameln1,restposix);
510        if (parmtrace) printf("+++ mxrun sort 1: '%s'\n",cmdline);
511        rc=system(cmdline);
512#endif /* PC || MYSFUN */
513        if (rc) { errp="fullinv/sort/1"; break; }
514        if (!fullinv_keep) remove(nameln1);
515
516#if PC || MYSFUN
517        rc=cisis_mysfunc(fullinv_ifnp,link2len,nameln2,namelk2,parmtell|parmtrace);
518#else /* PC || MYSFUN */
519        sprintf(cmdline,"%ssort -o %s %s%s",setposix,namelk2,nameln2,restposix);
520        if (parmtrace) printf("+++ mxrun sort 2: '%s'\n",cmdline);
521        rc=system(cmdline);
522#endif /* PC || MYSFUN */
523        if (rc) { errp="fullinv/sort/2"; break; }
524        if (!fullinv_keep) remove(nameln2);
525
526        p=cmdline;
527        sprintf(cmdline,"%s\n%s\n%s\n+fix%s\ntell=%"_LD_"\n",
528                fullinv_ifnp,namelk1,namelk2,ciiflfim ? "/m" : "",parmtell);
529        p+=strlen(p);
530#if LIND
531        if (fullinv_maxmfn) {
532            sprintf(p,"maxmfn=%"_LD_"\n",fullinv_maxmfn); p+=strlen(p);
533        }
534        else if (fullinv_master) {
535            sprintf(p,"master=%s\n",fullinv_master); p+=strlen(p);
536        }
537        else {errp="mxrun/fullinv/maxmfn"; break; }
538#else /* LIND */
539        if (fullinv_reset) {
540            if (fullinv_master) {
541                sprintf(p,"master=%s\n",fullinv_master); p+=strlen(p);
542            }
543        }
544        else strcat(p,"-reset\n");
545#endif /* LIND */
546        if (fullinv_pstflag == IFUPDICT) strcat(p,"-posts\n");
547        if (!fullinv_balan)              strcat(p,"-balan\n");
548        if (parmtrace) printf("+++ mxrun cisis_ifload: '%s'\n",cmdline);
549        rc=cisis_ifload(cmdline);
550        if (rc) errp="fullinv/ifload";
551        if (!fullinv_keep) remove(namelk1);
552        if (!fullinv_keep) remove(namelk2);
553        break;
554      }
555      if (parmtrace) printf("+++ mxrun \n");
556      if (errp) fatal(errp);
557    }
558#endif /* MXFULLINV */
559
560    if (mx_bup) FREE(mx_bup);
561#if MXIFUPD
562#if CIAPI
563    if (mstcrec) { FREE(vrecp[mstcrec]); vrecp[mstcrec]=NULL; nrecs-=1; }
564    if (mstirec) { FREE(vrecp[mstirec]); vrecp[mstirec]=NULL; nrecs-=1; }
565#else /* CIAPI */
566    if (mstcrec) { FREE(vrecp[mstcrec]); vrecp[mstcrec]=NULL; nrecs--; }
567    if (mstirec) { FREE(vrecp[mstirec]); vrecp[mstirec]=NULL; nrecs--; }
568#endif /* CIAPI */
569#endif /* MXIFUPD */
570
571    if (rc) if (parmtrace) fprintf(stderr,"*** mx: end of execution [%d]\n",rc);
572
573#if CIAPI
574    cisisApplicationDelete( ciapip );
575#endif /* CIAPI */
576
577    FREE(xmxp);
578    return(0);
579
580#else /* MXFUN */
581    exit(rc);
582#endif /* MXFUN */
583}
Note: See TracBrowser for help on using the browser.