root/tags/5.4.pre05/mxbol.c

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

Criação do svn para Cisis.

Line 
1/* ------------------------------ mxbol.c --------------------------------- */
2
3#include <stdio.h>
4#include <string.h>
5
6#if 1
7#if CIAPI
8#include "ciapi.h"   /* CISIS Interface API header file -
9                  includes cisis, implements cirun.h and ci*.c using ci*.?pp */
10
11#if !MXFUN
12extern void *ciapip;
13#endif /* MXFUN */
14
15#else /* CIAPI */
16#include "cisis.h"                  /* CISIS Interface */
17#endif /* CIAPI */
18#include "mx.h"                     /* MX Program header file */
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#if CIB71
26
27int mxbool(xmxp,parmp,dbnp)
28void *xmxp;
29char *parmp;
30char *dbnp;
31{
32    RECSTRU *recp;
33    char *p,*q;
34    LONGX mfn;
35    LONGX crec=0L; /* b5_exp usa crec condicionado a booldbnp */
36    int errno,xfd;
37#if !MXFUN
38    char mx_bup[512];
39#endif
40    LONGX asize;
41
42    cib7p=b7_cib7(cib7p, ciapip);
43
44    if (strncmp(parmp,"bool?",5) == 0 || strncmp(parmp,"bool=",5) == 0)
45        q=parmp+5;
46    else
47        q=parmp;
48
49    boolqryp=loadfile(dbnp,'@',q,boolqryp,MAXBOOL,'\0');
50    if (!boolqryp) fatal(q);
51
52    for (boolridx=nrecs, mfn=1; ; mfn++) { /* get actual maxmfn */
53        RECORD(boolridx,dbnp,mfn);
54        if (RECrc == RCEOF) fatal(dbnp);
55        if (RECrc == RCNORMAL) break;
56    }
57
58    if (booldbnp) {
59        dbxopt_fatal=0; xfd=dbxopen("",booldbnp,xx1extp);
60        if (xfd > 0) CLOSE(xfd); else recisis0(booldbnp);
61        RECORD(crec=nrecs,booldbnp,0L);
62        b7setno=MF0nxtmfn-1L;
63/*
64<R>
65        vrecp[boolridx]->recdbxp=RECdbxp;
66*/
67        VRECdbxp(boolridx)=RECdbxp;
68    }
69    else {
70        VRECdbxp(boolridx)=NULL; /* nao usa base de log */
71        VMFRmfn(boolridx)=0L;
72    }
73
74    /* allocate buffup
75    */
76    asize=     strlen(dbnp)     +                 /* field MFQTDBN0=11 (may be longer than CIMPL+1) */
77               strlen(boolqryp) +                 /* the expression */
78               2*strlen(boolqryp) +               /* the terms + pseudo operators _1termX+11X */
79               BUFSIZ+strlen(dbnp)     +          /* field MFQSWDBN=20 + a diferent db */
80               24*(strlen(B7DELADD)+3*B7UPLEN) +  /* 2 duzias de control fields */  /* DxxAxx|xxx| */ 
81               strlen(boolqryp)+4 +               /* tmpfile .%03x */
82               BUFSIZ;                            /* por si las moscas */
83
84    if (!mx_bup || mx_buplen < asize) {   
85        if (mx_bup) {
86#if CICPP
87                delete [] mx_bup;
88#else /* CICPP */
89            FREE(mx_bup);
90#endif /* CICPP */
91        }
92        mx_buplen=asize;
93        mx_bup=loadfile(NULL,'@',"",NULL,mx_buplen,'\0');
94    }
95   
96    p=b7_exp(cib7p,boolridx,dbnp,boolqryp,mx_bup,booldbnp,crec,&errno);
97    if (p || errno) printf("Expression syntax error %d: '%s'\n",errno,p);
98    else {
99        /* set hit file name to "null=don't write" or as provided by "b70x=" */
100        if (!booldbnp || booltmpnam[0]) {
101            char *hitfnamp="null";
102            if (booltmpnam[0]) hitfnamp=booltmpnam;
103            sprintf(mx_bup,"D%dA%d|%s|",MFQTHMEM,MFQTHMEM,hitfnamp);
104            if (fldupdat(boolridx,mx_bup) != NULL) fatal("mxbol/fldupdat");
105            if (b70trace) prtfields(vrecp[boolridx],VMFRmfn(boolridx));
106        }
107        /* b7_run faz "trirecp=vrep[tlirec]" */
108        if (!booltlir) record(booltlir=nrecs,"null",1L);
109
110        p=b7_run(cib7p,boolridx,dbnp,mx_bup,mx_buplen,booltell,isisuctab,"",booltlir,crec,&errno);
111        if (p || errno) printf("Execution error %d: '%s'\n",errno,p);
112        else {
113            boolhits=b7_hit(cib7p,boolridx,boolh=0L,b7setno);
114            if (booltell) printf("Hits=%ld\n",boolhits);
115        }
116    }
117    if (p || errno) return(1);
118    return(0);
119}
120
121#else /* CIB71 */
122
123#if LIND || CIB64
124
125int mxbool(xmxp,parmp,dbnp)
126void *xmxp;
127char *parmp;
128char *dbnp;
129{
130    RECSTRU *recp;
131    char *p,*q;
132    LONGX mfn;
133    LONGX crec=0L; /* b5_exp usa crec condicionado a booldbnp */
134    int errno,xfd;
135#if !MXFUN
136    char mx_bup[512];
137#endif
138    extern LONGX b5maxbyts0; /* <== mover para cisis.h (rever estrut. b7) */
139
140#if 0
141    if (argc < 5) {
142        /* fatal("b6 <dbn> <bytes1> <bufsiz> <expr> [<hits> [x] [y]]"); */
143        printf("%s",cicopyr("Utility B6"));
144        printf("\n");
145        printf("b6 <dbn> <bytes1> <bufsiz> <expr> [options]");
146        printf("\n");
147        printf("options: <hits>          -> max hits to show \n");
148        printf("         <x>             -> don't show hits \n");
149        printf("         <y>             -> max bitstring (in bytes) \n");
150        printf("\n");
151        exit(1);
152    }
153#endif
154   
155    if (strncmp(parmp,"bool?",5) == 0 || strncmp(parmp,"bool=",5) == 0)
156        q=parmp+5;
157    else
158        q=parmp;
159
160    boolqryp=loadfile(dbnp,'@',q,boolqryp,MAXBOOL,'\0');
161    if (!boolqryp) fatal(q);
162
163    if (parmtrace) {
164        showcore("+++ bool");
165        printf("+++ bool=%c",OPENFCHR); printf("%s",boolqryp);
166        printf("%c ..",CLOSFCHR); if (getchar() != '\n') return(1);
167    }
168
169    if (boolnby0) b5maxbyts0=boolnby0;
170
171    for (boolridx=nrecs, mfn=1; ; mfn++) { /* get actual maxmfn */
172        RECORD(boolridx,dbnp,mfn);
173        if (RECrc == RCEOF) fatal(dbnp);
174        if (RECrc == RCNORMAL) break;
175    }
176    if (!boolnby1) boolnby1=dbxstorp(dbnp)->dbxmsmfn/8+1;
177
178
179#if BIGREC
180#else
181    if (boolnbyb) b6_hballoc(boolnbyb,&b6bufferp);
182#endif
183
184    if (booldbnp) {
185        dbxopt_fatal=0; xfd=dbxopen("",booldbnp,xx1extp);
186        if (xfd > 0) CLOSE(xfd); else recisis0(booldbnp);
187        RECORD(crec=nrecs,booldbnp,0L);
188        b5setno=MF0nxtmfn-1L;
189        vrecp[boolridx]->recdbxp=RECdbxp;
190    }
191    else {
192        VRECdbxp(boolridx)=NULL; /* nao usa base de log */
193        VMFRmfn(boolridx)=0L;
194    }
195
196    p=b5_exp(boolridx,dbnp,boolqryp,mx_bup,booldbnp,crec,&errno);
197    if (p || errno) printf("Expression syntax error %d: '%s'\n",errno,p);
198    else {
199        if (!booldbnp) {
200            if (!booltmpnam[0]) 
201#if BEFORE991117 || 1
202                tmpnam(booltmpnam);
203#else
204/*strcpy(booltmpnam,"c:\\TMP1.$$$");
205*/
206                if (!dbxtmpnm("CI_TEMPDIR", 0, booltmpnam))
207                    fatal("mxbol/dbxtmpnm");
208#endif
209            sprintf(mx_bup,"D%dA%d|%s|",MFQTHMEM,MFQTHMEM,booltmpnam);
210            if (fldupdat(boolridx,mx_bup) != NULL) fatal("mxbol/fldupdat");
211            if (b50trace) prtfields(vrecp[boolridx],VMFRmfn(boolridx));
212        }
213#if BIGREC
214        p=b5_run(boolridx,dbnp,mx_bup,
215                boolnby1,booltell,isisuctab,"",booltlir,crec,&errno);
216#else
217        p=b6_run(boolridx,dbnp,mx_bup,mx_buplen,
218                boolnby1,booltell,isisuctab,"",booltlir,crec,&errno);
219#endif
220        if (p || errno) printf("Execution error %d: '%s'\n",errno,p);
221        else {
222#if BIGREC
223            boolhits=b5_hit(boolridx,boolh,mx_bup);
224#else /* BIGREC */
225            boolhits=b6_hit(boolridx,boolh,b5setno,b6bufferp);
226#endif /* BIGREC */
227            if (booltell) printf("Hits=%ld\n",boolhits);
228        }
229    }
230    if (p || errno) return(2);
231    return(0);
232}
233
234
235#else /* LIND || CIB64 */
236
237int mxbool(xmxp,parmp,dbnp)
238void *xmxp;
239char *parmp;
240char *dbnp;
241{
242#if !MXFUN
243    extern char *mx_bup;
244#endif
245
246    char *p,*q,*fldp;
247    int errno,xdir;
248    FFI fldl;
249    LONGX nby1,mfn,cc;
250    char area[B4UPLEN+1];
251
252
253    if (strncmp(parmp,"bool?",5) == 0 || strncmp(parmp,"bool=",5) == 0)
254        q=parmp+5;
255    else
256        q=parmp;
257
258    boolqryp=loadfile(dbnp,'@',q,boolqryp,MAXBOOL,'\0');
259    if (!boolqryp) fatal(q);
260
261    if (parmtrace) {
262        showcore("+++ bool");
263        printf("+++ bool=%c",OPENFCHR); printf("%s",boolqryp);
264        printf("%c ..",CLOSFCHR); if (getchar() != '\n') return(1);
265    }
266
267    nby1=dbxstorp(dbnp)->dbxmsmfn/8+1;
268    if (!boolridx) {
269        boolridx=nrecs;
270        recallok(boolridx,BUFSIZ+MAXBOOL+nby1);
271        if (!booltlir)
272            invsetup(dbnp,parmload,parmload,parmload);/* allocate areas */
273        else
274            for (xdir=0; xdir <= VMFRnvf(booltlir); xdir++)
275                if (VDIRtag(booltlir,xdir) == MFQTXTAG) {
276                    fldl=VDIRlen(booltlir,xdir);
277                    fldp=subfldp(VFIELDP(booltlir,xdir),'y',&fldl);
278                    fldl=subfldn(fldp,fldl);
279                    if (fldl) {
280                        memcpy(mx_bup,fldp,fldl);
281                        mx_bup[fldl]='\0';
282                        invsetup(mx_bup,parmload,parmload,parmload);
283                    }
284                }
285    }
286
287    if (strcmp(boolqryp,"#") == 0) {
288        if (booldbnp) {
289            if (b4setno > 0) {
290                for (mfn=1; mfn <= b4setno; mfn++) {
291                    record(boolridx,VRDBname(boolridx),mfn);
292                    if (VRECrc(boolridx) == RCNORMAL) {
293                        sprintf(mx_bup,"D%dD%dD%dD%d",
294                            MFQTHCUR,MFQTHMFN,MFQTHSIZ,MFQTHMEM);
295                        if (fldupdat(boolridx,mx_bup)) fatal("mxbool");
296                        sprintf(mx_bup,"D%dD%dD%dD%dD%d",
297                            MFQTDBN0,MFQTOBJ0,MFQTXCTS,MFQTASET,MFQTALCC);
298                        if (fldupdat(boolridx,mx_bup)) fatal("mxbool");
299                        prtfields(vrecp[boolridx],mfn);
300                    }
301                }
302                if (booltlir)
303                    prtfields(vrecp[booltlir],VMFRmfn(booltlir));
304                record(boolridx,VRDBname(boolridx),b4setno);
305                return(0);
306            }
307        }
308        if (booltlir) {
309            prtfields(vrecp[boolridx],b4setno);
310            prtfields(vrecp[booltlir],VMFRmfn(booltlir));
311            return(0);
312        }
313    }
314
315    p=b4_exp(boolridx,dbnp,boolqryp,booldbnp,&errno);
316    if (p || errno) {
317        printf("Expression syntax error %d: '%s'\n",errno,p);
318        if (b40trace)
319            if (vrecp[boolridx])
320                prtfields(vrecp[boolridx],VMFRmfn(boolridx));
321    }
322    else {
323        p=b4_run(boolridx,dbnp,nby1,boolnby2,booltell,
324                                        isisuctab,booltlir,&errno);
325        if (p || errno) {
326            printf("Execution error %d: '%s'\n",errno,p);
327            if (b40trace)
328                if (vrecp[boolridx])
329                    prtfields(vrecp[boolridx],VMFRmfn(boolridx));
330        }
331        else {
332            boolhits=b4_hit(boolridx,boolh=0L);
333            if (boolhits >= 0) {
334                recfield(area,boolridx,MFQTALCC,1,NULL);
335                if ((cc=atol(area)) != 0) sprintf(area," [cc=%ld]",cc);
336                else strcpy(area," ");
337                if (booltell) printf("Hits=%ld %s\n",boolhits,area);
338            }
339            else
340                if (vrecp[boolridx])
341                    prtfields(vrecp[boolridx],VMFRmfn(boolridx));
342        }
343    }
344    if (p || errno) return(2);
345    return(0);
346}
347
348#endif /* LIND || CIB64 */
349#endif /* CIB71 */
Note: See TracBrowser for help on using the browser.