root/tags/5.4.pre05/cib72.c @ 1

Revision 1, 67.9 kB (checked in by heitor.barbieri, 2 years ago)

Criação do svn para Cisis.

Line 
1/*
2 * <R>
3 * cib72, b7_run(), b7_hit()
4 * basado en b6 usando algo de b4
5 * b4 - proximidad
6 * b6 - prefix, multiples I/F, log format
7 * </R>
8 */
9
10/* Alteracoes BIREME:
11
12   1. Arquivo temporario com lista de hits
13
14      nao gravar arquivo com lista de hits se nome do arquivo = "null"
15      (campo MFQTHMEM=35 do registro de b7_run - parametro irec)
16
17      ver #if CIB7TMPNULL
18      #define CIB7TMPNULL em cisis.h
19      AOT, 14/01/2002
20
21   2. B7BUFFER (lista de hits) com dois tipos de lista
22
23      grava bit string ou lista de LONGX integer com os mfn's recuperados
24      se for mais economico em termos de espaco
25
26      ver #if CIB7HITLIST
27      #define CIB7HITLIST em cisis.h
28      AOT, 15/01/2002
29
30   3. Correcao no processamento de '$'
31
32      Rosnier deixou passar warning incorrect assign em "if( mkp[len-1]='$' )"
33
34      ver #if BEFORE20020115
35      AOT, 15/01/2002
36
37   4. Correcao do tamanho maximo de CIWRITE
38
39      define tamanho maximo UINT_MAX apenas se for PC 16 bits
40
41      ver #if BEFORE20020115
42      AOT, 15/01/2002
43
44   5. Parametro btch0p
45
46      chama fldupdat() com parametro btch0p, como cib62.c
47
48      ver btch0p - AOT, 16/01/2002
49      AOT, 16/01/2002
50
51   6. Reprogracao de MFNSTRING na b7_hit()
52
53      nao toca no registro do qrydb
54
55      ver #if CIB7HITLIST
56      AOT, 28/01/2002
57
58   7. Correcao "chaves de 29 caracteres"
59
60      testa existencia de aspas antes de mover '\0'
61
62      ver AOT/RP 03/07/2002
63      AOT, 03/07/2002
64
65   8. Formato para mais hits nas msgs:
66            1    MACACA/SU
67           79  MACACA$
68          106  Operation +
69          106  Set #000000001
70      Hits=106
71      AOT, 22/12/2006
72
73   9. Alteracao B72SIZE_MAX para B72B72SIZE_MAX
74
75      ver: cib72.c:139:1: warning: "B72SIZE_MAX" redefined
76           In file included from /usr/include/netinet/in.h:23,
77                            from cisis.h:3526,
78                            from cib72.c:107:
79           /usr/include/stdint.h:268:1: warning: this is the location of the previous definition
80      AOT, 12/01/2007
81
82
83*/
84
85/*
86 * Alteraciones Rosnier
87 * Definir BITSTRING, MFNSTRING e CNTSTRING para !LIND.
88 * pasarlo para cisis.h o eliminar el uso en caso !LIND.
89 */
90
91#if !LIND
92#define BITSTRING  (-1)
93#define MFNSTRING  0
94#define CNTSTRING  1
95#endif
96
97/*
98 * Eliminar realloc.
99 * No se porque esta "reallocando" en memoria que ya esta en uso.
100 * ver #if BEFORE20020319
101 */
102
103
104#include <stdio.h>
105#include <ctype.h>
106#include <string.h>
107#include <time.h>
108
109#if CIAPI
110#include "ciapi.h"
111#if !TLS
112#define ciapip cib7p->ciapip
113#else
114DWORD extern ciapiTlsIndex;
115#endif
116#else /* CIAPI */
117#include "cisis.h"
118#endif /* CIAPI */
119
120#if !CICPP
121#include "cib70.h"
122#endif /* CICPP */
123
124#define MIDDLEMSG       01
125#define RUITRACE        0
126#define RUATRACE        0
127
128#define HITTRACE 0
129#define HITTRACx 0
130
131
132#if BEFORE20020115
133#if PC
134#define UINTIO          1
135#else
136#define UINTIO          0
137#endif
138#else /*BEFORE20020115 */
139#if PC && !DOS32BITS  /* AOT, 15/01/2002 */
140#define UINTIO          1
141#else
142#define UINTIO          0
143#endif
144#endif /*BEFORE20020115 */
145
146#if UINTIO
147#define B72SIZE_MAX     UINT_MAX
148#else
149#define B72SIZE_MAX     INT_MAX
150#endif /* UINTIO */
151
152/*
153Rosnier: falta implementar esta parte (ver comigo e com Ricardo)
154         como subcampo na tabela de prefixos (por exemplo, ^vTW^wMH)
155         de maneira a poder usar a feature em otras aplicacoes alem do
156         search em MedLine e, sobretudo, nao fazer a cagada de ir sempre
157         pesquisar numa arvore MH quando uma chave de uma arvore chamada TW
158         tem mais de uma palavra
159AOT, 18/05/2001
160*/
161#define SOING           1       /* CDMDL - text word TI and AB are I
162                                           text word MeSH are I/E/P
163
164                                            if dbn="TW"
165                                              if key has multiple words
166                                                dbn="MH"
167                                   (b6tw2mh)
168                                */
169
170/*
171        definiciones sobre la pila de ejecuaci�*/
172#define PDLlvel         pdlp->pdllvel
173#define PDLleft         pdlp->pdlleft
174#define PDLdocs         pdlp->pdldocs
175#define PDLlmfn                 pdlp->pdllmfn
176#define PDLsize         pdlp->pdlsize
177#define PDLisiz         pdlp->pdlisiz
178#define PDLplen         pdlp->pdlplen
179#define PDLnxtp         pdlp->pdlnxtp
180#define VPDLlvel(i)     vpdlp[i]->pdllvel
181#define VPDLleft(i)     vpdlp[i]->pdlleft
182#define VPDLdocs(i)     vpdlp[i]->pdldocs
183#define VPDLlmfn(i)     vpdlp[i]->pdllmfn
184#define VPDLsize(i)     vpdlp[i]->pdlsize
185#define VPDLisiz(i)     vpdlp[i]->pdlisiz
186#define VPDLplen(i)     vpdlp[i]->pdlplen
187#define VPDLnxtp(i)     vpdlp[i]->pdlnxtp
188#define PDL0            vpdlp[0]
189#define PDL0lvel        PDL0->pdllvel
190#define PDL0left        PDL0->pdlleft
191#define PDL0docs        PDL0->pdldocs
192#define PDL0lmfn        PDL0->pdllmfn
193#define PDL0size        PDL0->pdlsize
194#define PDL0isiz        PDL0->pdlisiz
195#define PDL0plen        PDL0->pdlplen
196#define PDL0nxtp        PDL0->pdlnxtp
197
198#define vpdltop                         npdls-1
199
200
201#if CICPP
202void CIB7::b7_runerr(int error, char *errp, int errl)
203#else /*CICPP*/
204void b7_runerr(cib7p,error,errp,errl)
205b7_CIB7 *cib7p;
206int error;
207char *errp;
208int errl;
209#endif /*CICPP*/
210{
211#if ERRTRACE
212    char *p;
213    int loop;
214#endif
215    if (b7fd) { CLOSE(b7fd); b7fd=0;}   /* 06/03/95 */
216
217    if (errl <= 0) errl=strlen(errp);
218    if (errl > MAXERRL) errl=MAXERRL;
219#if ERRTRACE
220    printf("b7_runerr - error=%d (",error);
221    for (p=errp,loop=errl;loop--;p++)
222      putchar(*p);
223    printf(")\n");
224#endif
225    memcpy(b7errxy,errp,errl); b7errxy[errl]='\0';
226#ifndef CICPP
227#if !WWWISIS
228    longjmp(b71jumper,error);
229    fatal("b7_run/b7_runerr");
230#endif /* !WWWISIS */
231#endif /* CICPP */
232    b7error = error?error:1;
233
234}
235
236/*
237        eliminar un nivel de la pila.
238*/
239
240#if CICPP
241int CIB7::b7_free(int ipdl)
242#else /*CICPP*/
243int b7_free(cib7p,ipdl)
244b7_CIB7 *cib7p;
245int ipdl;
246#endif
247{
248        PDLSTRU *pdlp;
249   pdlp = vpdlp[ipdl];
250
251   if( pdlp == (PDLSTRU*)ALLONULL )
252        return 0;
253
254#if CICPP
255   if( PDLlvel )
256        delete[] PDLlvel;
257
258   delete[] pdlp;
259#else /* CICPP */
260   if( PDLlvel )
261        FREE( PDLlvel );
262
263   FREE( pdlp );
264#endif /* CICPP */
265
266   npdls--;
267   return 0;
268}
269
270/*
271        intercambia 2 niveles de la pila.
272*/
273
274#if CICPP
275int CIB7::b7_xpdl(int ipdl1, int ipdl2 )
276#else /*CICPP*/
277int b7_xpdl( cib7p,ipdl1, ipdl2 )
278b7_CIB7 *cib7p;
279int ipdl1;
280int ipdl2;
281#endif
282{
283
284        PDLSTRU *tmp;
285
286   tmp = vpdlp[ ipdl1 ];
287   vpdlp[ ipdl1 ]=vpdlp[ ipdl2 ];
288   vpdlp[ ipdl2 ] = tmp;
289
290   return 1;
291
292}
293
294/*
295        Inicializa un PDLSTRU.
296*/
297
298#if CICPP
299char *CIB7::b7_initpdl(PDLSTRU *pdlp, char postlen, LONGX lastmfn)
300#else /*CICPP*/
301char *b7_initpdl(cib7p,pdlp, postlen, lastmfn)
302b7_CIB7 *cib7p;
303PDLSTRU *pdlp;
304char postlen;   /* tama�e los postings */
305LONGX lastmfn;  /* �o MFN de la base. */
306#endif /*CICPP*/
307{
308
309   switch( postlen ){
310           case '1': PDLplen=0; break;  /* one bit per mfn */
311           case '2': PDLplen=5; break;   /* MFN+TAG */
312       case '3': PDLplen=6; break;   /* MFN+TAG+OCC */
313       case '4': PDLplen=8; break;   /* MFN+TAG+OCC+CNT */
314       default : PDLplen=0;
315   }
316
317   if( !PDLplen )
318        PDLsize=lastmfn/8+1;    /*bitstring.*/
319   else
320        PDLsize=lastmfn*PDLplen;
321
322   PDLisiz = PDLsize;
323
324#if CICPP
325   if( PDLlvel ) delete[] PDLlvel;
326
327   try {PDLlvel= (UCHR *)new char[(ALLOPARM)PDLsize]; }
328   catch(BAD_ALLOC) { PDLlvel = (UCHR *)ALLONULL; }
329#else /* CICPP */
330   if( PDLlvel ) FREE(PDLlvel);
331
332   PDLlvel= (char*)ALLOC((ALLOPARM)(PDLsize));
333#endif /* CICPP */
334   if (PDLlvel == (UCHR *)ALLONULL)
335   {
336        b7_runerr(B7_THISP 3,"b7_ipdl/ALLOC/PDLlvel",0);
337      return (char *)ALLONULL;
338   }
339   memset(PDLlvel,0x00,PDLsize);
340
341   PDLleft=PDLsize;
342
343   PDLdocs=0;
344   PDLnxtp=(char *)PDLlvel;
345   PDLlmfn=lastmfn;
346
347   return (char *)PDLlvel;
348
349}
350
351/*
352        adicionar PDLSTRU a la pila en el nivel ipdl.
353*/
354
355#if CICPP
356PDLSTRU *CIB7::b7_ipdl(int ipdl)
357#else /*CICPP*/
358PDLSTRU *b7_ipdl(cib7p,ipdl)
359b7_CIB7 *cib7p;
360int ipdl;
361#endif /*CICPP*/
362{
363        PDLSTRU *pdlp;
364   if (ipdl >= npdls) {
365                if (ipdl > npdls)
366        fatal("b7_ipdl/ipdl");
367                if (npdls >= MAXPDLS)
368                {
369        b7_runerr(B7_THISP 2,"b7_ipdl/MAXPDLS",0);
370                return 0;
371      }
372
373#if CICPP
374      try { pdlp=(PDLSTRU *)new char[(ALLOPARM)(sizeof(PDLSTRU))]; }
375      catch(BAD_ALLOC) { pdlp=(PDLSTRU *)NULL; }
376#else /* CICPP */
377      pdlp=(PDLSTRU *)ALLOC((ALLOPARM)(sizeof(PDLSTRU)));
378#endif /* CICPP */
379
380      memset((char *)pdlp,0x00,sizeof(PDLSTRU));
381
382      if (pdlp == (PDLSTRU *)ALLONULL)
383                {
384        b7_runerr(B7_THISP 3,"b7_ipdl/ALLOC/pdlp",0);
385        return 0;
386                }
387#if RUATRACE
388printf("ALLOC - ipdl=%d  pdlp=%p\n",ipdl,pdlp);
389#endif
390      vpdlp[npdls++]=pdlp;
391        }
392   else
393        pdlp=vpdlp[ipdl];
394
395        return(pdlp);
396}
397
398/*
399        guess!!!
400*/
401#if CICPP
402PDLSTRU *CIB7::b7_push()
403#else
404PDLSTRU *b7_push(cib7p)
405b7_CIB7 *cib7p;
406#endif
407{
408        return b7_ipdl( B7_THISP npdls );
409}
410
411/*
412        guess!!!
413*/
414#if CICPP
415int CIB7::b7_pop()
416#else
417int b7_pop(cib7p)
418b7_CIB7 *cib7p;
419#endif
420{
421        b7_free( B7_THISP npdls-1);
422   return 1;
423}
424
425#if CICPP
426int CIB7 :: b7_pfx(RECSTRU *recp, UWORD invxtag, char *dp, char *op, int b7re_pfx)
427#else /* CICPP */
428int b7_pfx(cib7p,irec, invxtag, dp, op, b7re_pfx)
429b7_CIB7 *cib7p;
430LONGX irec;
431UWORD invxtag;
432char *dp;
433char *op;
434int b7re_pfx;
435#endif /* CICPP */
436{
437    int found=0;
438    unsigned char *fldp,*pfxp,*dbnp,*usep,*kp,*msgp;
439    int xdir;
440    FFI pfxl,dbnl,usel,deflen,opxlen,kl,n,msgl;
441    char *tmp;
442
443    int aspas;
444   
445#if !CICPP
446    RECSTRU *recp;
447    recp=vrecp[irec];
448#endif
449    if (!recp) fatal("b7_pfx/irec");
450
451#if CICPP
452    if (!recp->recmfp) fatal("b7_pfx/recmfp");
453#endif /* CICPP */
454
455    b7_pfxtwx[0]='\0';
456    b7_pfxlen=0;
457    *b7_pfxmsg='\0';
458    *b7_pfxdbn='\0';
459    strcpy(b7_pfxopx,op);
460    opxlen=kl=strlen((const char *)(kp=(unsigned char *)op));
461    deflen=strlen(dp);
462#if INVXTRAC
463printf("0. dbname=%s,opx=%s<== \n",b7_pfxdbn,b7_pfxopx);
464#endif
465#if CICPP
466    if (opxlen > 0) {
467#else /* CICPP */
468    if (irec && opxlen > 0) {
469#endif /* CICPP */
470        for (xdir=0; xdir < MFRnvf; xdir++) {
471#if INVXTRAC
472 printf("xdir,tag: %d,%d \n",xdir,DIRtag(xdir));
473#endif
474            if (DIRtag(xdir) == invxtag) {
475                fldp=(unsigned char *)FIELDP(xdir);
476                pfxl=DIRlen(xdir);
477                pfxp=subfldp(fldp,'p',&pfxl);
478                pfxl=subfldn(pfxp,pfxl);
479                if (!pfxl) fatal("b7_pfx/invxtag/^p");
480                if (pfxl == 1 && *pfxp == '*') continue;
481                dbnl=DIRlen(xdir);
482                dbnp=subfldp(fldp,'y',&dbnl);
483                dbnl=subfldn(dbnp,dbnl);
484                if (!dbnl) fatal("b7_pfx/invxtag/^y");
485                usel=DIRlen(xdir);
486                usep=subfldp(fldp,'u',&usel);
487                usel=subfldn(usep,usel);
488                if (usel > LE2) fatal("b7_pfx/invxtag/^u");
489                if (opxlen >= pfxl) {
490                        if (strncmp(b7_pfxopx,(const char *)pfxp,pfxl) == 0) {
491                        memcpy(b7_pfxdbn,dbnp,dbnl);
492                        b7_pfxdbn[dbnl]='\0';
493                        if (usel) memcpy(b7_pfxopx,usep,usel);
494
495/* <R>  */
496                        if( op[pfxl] == '"' ){
497                                aspas=1;
498                           tmp = strrchr((char *)op+pfxl+1, (int)'"' );
499                           if (tmp) /* AOT/RP 03/07/2002 */ *tmp = '\0';
500                        }else{
501                                aspas=0;
502                        }
503/* </R> */
504                                                                strcpy(b7_pfxopx+usel,op+pfxl+aspas);
505                                                                found=1;
506#if INVXTRAC
507 printf("1. dbname=%s,opx=%s<== \n",b7_pfxdbn,b7_pfxopx);
508#endif
509                        break;
510                    }
511                }
512            }
513        }
514    }
515#if INVXTRAC
516 printf("1. defpfx=%s(%d),op,opx: %s,%s[%s] (%d)\n",
517  dp,deflen,op,b7_pfxopx,b7_pfxdbn,found);
518#endif
519#if CICPP
520    if (found == 0) {
521#else /* CICPP */
522    if (irec && found == 0) {
523#endif /* CICPP */
524        if (strlen(dp)) {
525            for (xdir=0; xdir < MFRnvf; xdir++) {
526#if INVXTRAC
527 printf("1. xdir,tag: %d,%d \n",xdir,DIRtag(xdir));
528#endif
529                if (DIRtag(xdir) == invxtag) {
530                    fldp=(unsigned char *)FIELDP(xdir);
531                              pfxl=DIRlen(xdir);
532                    pfxp=subfldp(fldp,'p',&pfxl);
533                    pfxl=subfldn(pfxp,pfxl);
534                    if (pfxl == 1 && *pfxp == '*') continue;
535                    if (pfxl < deflen) continue;
536                    n=pfxl-deflen;
537                    if (strncmp((const char *)pfxp,dp,deflen) != 0) continue;
538                    if (strncmp((const char *)(pfxp+deflen),(const char *)kp,n) != 0) continue;
539                    dbnl=DIRlen(xdir);
540                    dbnp=subfldp(fldp,'y',&dbnl);
541                    dbnl=subfldn(dbnp,dbnl);
542                    usel=DIRlen(xdir);
543                    usep=subfldp(fldp,'u',&usel);
544                    usel=subfldn(usep,usel);
545                    memcpy(b7_pfxdbn,dbnp,dbnl); b7_pfxdbn[dbnl]='\0';
546                    if (usel) memcpy(b7_pfxopx,usep,usel);
547/* <R>  */
548                    if( kp[n] == '"' ){
549                                aspas=1;
550                        tmp = strrchr((char *)kp+n+1, (int)'"' );
551                        if (tmp) /* AOT/RP 03/07/2002 */ *tmp = '\0';
552                    }else{
553                                aspas=0;
554                    }
555/* </R> */
556                    memcpy(b7_pfxopx+usel,kp+n+aspas,kl-n);
557                    b7_pfxopx[usel+kl-n]='\0';
558                    found=2;
559#if INVXTRAC
560 printf("2. dbname=%s,opx=%s<== \n",b7_pfxdbn,b7_pfxopx);
561#endif
562                    break;
563                }
564            }
565            if (!found)
566            {
567                b7_runerr(B7_THISP b7re_pfx,dp,0);
568                return(0);
569                /*goto B7_RUNERROR;*/
570            }
571        }
572    }
573#if INVXTRAC
574 printf("2. defpfx=%s(%d),op,opx: %s,%s[%s] (%d)\n",
575  dp,deflen,op,opx,b7_pfxdbn,found);
576#endif
577#if !CICPP
578    if (irec) {
579#endif /* !CICPP */
580        if (found == 0) {
581            for (xdir=0; xdir < MFRnvf; xdir++) {
582#if INVXTRAC
583 printf("2. xdir,tag: %d,%d \n",xdir,DIRtag(xdir));
584#endif
585                if (DIRtag(xdir) == invxtag) {
586                    fldp=(unsigned char *)FIELDP(xdir);
587                    pfxl=DIRlen(xdir);
588                    pfxp=subfldp(fldp,'p',&pfxl);
589                    pfxl=subfldn(pfxp,pfxl);
590                    if (pfxl != 1) continue;
591                    if (*pfxp != '*') continue;
592                    dbnl=DIRlen(xdir);
593                    dbnp=subfldp(fldp,'y',&dbnl);
594                    dbnl=subfldn(dbnp,dbnl);
595                    usel=DIRlen(xdir);
596                    usep=subfldp(fldp,'u',&usel);
597                    usel=subfldn(usep,usel);
598                    memcpy(b7_pfxdbn,dbnp,dbnl);
599                    b7_pfxdbn[dbnl]='\0';
600                    if (usel) memcpy(b7_pfxopx,usep,usel);
601/* <R>  */
602          if( op[0] == '"' ){
603                        aspas=1;
604               tmp = strrchr((char *)op+1, (int)'"' );
605               if (tmp) /* AOT/RP 03/07/2002 */ *tmp = '\0';
606          }else{
607               aspas=0;
608          }
609/* </R> */
610
611                    strcpy(b7_pfxopx+usel,op+aspas);
612                    found=3;
613#if INVXTRAC
614 printf("3. dbname=%s,opx=%s<== \n",b7_pfxdbn,b7_pfxopx);
615#endif
616                    break;
617                }
618            }
619        }
620#if !CICPP
621    }
622#endif /* !CICPP */
623    if (found) {
624        b7_pfxlen=usel;
625        msgl=DIRlen(xdir);
626        msgp=subfldp((unsigned char *)FIELDP(xdir),'m',&msgl);
627        msgl=subfldn(msgp,msgl);
628        if (msgl >= sizeof(b7_pfxmsg)) fatal("b7_pfx/invxtag/^m");
629        memcpy(b7_pfxmsg,msgp,msgl); b7_pfxmsg[msgl]='\0';
630        msgl=DIRlen(xdir);
631        msgp=subfldp((unsigned char *)FIELDP(xdir),'w',&msgl);
632        msgl=subfldn(msgp,msgl);
633        if (msgl >= sizeof(b7_pfxtwx)) fatal("b7_pfx/invxtag/^w");
634        memcpy(b7_pfxtwx,msgp,msgl); b7_pfxtwx[msgl]='\0';
635        msgl=DIRlen(xdir);
636        msgp=subfldp((unsigned char *)FIELDP(xdir),'x',&msgl);
637        b7_pfxmdl = (msgp) ? 1 : 0;
638    }
639#if INVXTRAx
640 printf("3. defpfx=%s(%d),op,opx: %s,%s[%s] (%d)\n",
641  dp,deflen,op,b7_pfxopx,b7_pfxdbn,found);
642#endif
643
644        /*      27.Feb.2003 RP - begin */
645        if ( aspas )
646        {
647        char *auxString = strdup(b7_pfxopx);
648
649                sprintf(b7_pfxopx,"\"%s\"",auxString);
650#if CICPP
651      free(auxString);
652#else /* CICPP */
653      FREE(auxString);
654#endif /* CICPP */
655        }
656        /*      27.Feb.2003 RP - end */
657
658    return(found);
659}
660
661
662/*
663        b7_run()
664        ejecuta la b�da :-)
665 */
666#if CICPP
667char *CIB7::b7_run(RECSTRU *irecp, char *dbnamp,
668                char *buffup, int buffuplen, LONGX tell,
669                unsigned char uctab[], char *btch0p, RECSTRU *tlirecp,
670                RECSTRU *crecp, int *errnop)
671#else /* CICPP */
672char *b7_run(cib7p,irec,dbnamp,buffup,buffuplen,tell,uctab,
673                        btch0p,tlirec,crec,errnop)           /*
674
675------------
676                    executa query em dbnamp;
677                    retorna NULL ou ptr erro
678                                                                        */
679b7_CIB7 *cib7p;
680LONGX irec;                             /* recp, para store */
681char *dbnamp;                           /* ptr nome base de dados a ler */
682char *buffup;                           /* area addr for fldupdat */
683int buffuplen;                          /* buffup length */
684LONGX tell;                     /* b7_msg call */
685unsigned char uctab[];          /* uctab */
686char *btch0p;                   /* initial fldupdat */
687LONGX tlirec;                   /* invx definition */
688LONGX crec;                             /* registro de controle de qrydbnp */
689int *errnop;                    /* addr para codigo de erro */
690#endif /* CICPP */
691{
692   RECSTRU *recp;
693   TRMSTRU *trmp;
694   PDLSTRU *pdlp;                                               /* pilha de execucao */
695
696   unsigned char *b7p;
697
698   unsigned char *q, *p, *op1, *res, *batchp, *p0p, *mtp, *mkp;
699
700   char postlen;
701
702   int b7opxlen;
703
704/* <R>
705        Pasadas a b7_CIB7.
706   short unsigned int nqualts,vqualt[MAXQUAL],*qualtp;
707 </R>
708 */
709
710   int b7rootf;
711   LONGX b7rootloop;
712
713   unsigned char b7opr;
714   unsigned char b7qty;
715   unsigned char b7pst;
716   unsigned char b7acc;
717   unsigned char b7opx[2+LE2+1];
718   LONGX lastmfn;
719   LONGX offset, loop;
720
721   int xdir_obj0,xdir_dbn0;
722
723   int xdir_hmem;
724   int xdir_xcts,n;
725   FFI nffi;
726
727   LONGX nord,mfn,left;
728   LONGX hits,hsiz,lastcc,bytes;
729
730   time_t wtime;
731
732   int b7fd1;
733
734   LONGX npdlsb;
735
736   char buffup1[1024];
737
738#if INVXBOOL
739    unsigned char /*tl_dbname[CIMPL+1],*/tl_opx[LE2+LE2+1];
740#endif
741
742   int tl_deflen;
743   unsigned char tl_defpfx[LE2+1];
744
745   DBXSTRU *dbxp;
746
747#if MIDDLEMSG
748   LONGX count;
749#endif
750
751#if CDMDL
752    int dctlen,qlflen;
753#endif
754
755//#if CIB7HITLIST  /* AOT, 15/01/2002 */
756//    LONGX bytsneed=LONGX_MAX;
757//    int hcase=BITSTRING;
758//#endif
759
760#if !CICPP
761   RECSTRU *tlirecp;
762#endif /* CICPP */
763
764   *errnop=0;
765
766   if (!ndbxs) dbxinit();  /* init vdbxp/vrecp/vtrmp if not yet init - AOT, 28/10/2005 */
767               
768   tl_defpfx[0] = '\0';
769   nqualts=0;
770
771#if CICPP
772   recp = irecp;
773#else /* CICPP */
774   recp=vrecp[irec];
775#endif /* CICPP */
776   if (!recp)
777                fatal("b7_run/irec");
778
779#if !CICPP
780   tlirecp=vrecp[tlirec];
781#endif /* CICPP */
782   if (!tlirecp)
783                fatal("b7_run/tlirec");
784
785   npdls=0;
786   b7itrm=0;
787   lastcc=0;
788
789#if CICPP
790   trmp = new TRMSTRU(cisisxp);
791   trmp->xtrmalloc(IFBSIZ);
792#else /* CICPP */
793   for (b7itrm=maxntrm; --b7itrm > 0; )
794        if (!vtrmp[b7itrm]) {
795        trmalloc(b7itrm,IFBSIZ);
796         break;
797      }
798   if (b7itrm == 0)
799        b7_runerr(B7_THISP 8,"b7_run/itrm",0);
800#endif /* CICPP */
801
802B7_RUNERROR:
803        if (b7error != 0) {
804#if ERRTRACE
805                printf("setjmp - error=%d (%s)\n",b7error,b7errxy);
806#endif
807                sprintf(buffup,B7DELADD,MFQTALCC,MFQTALCC,(LONGX)b7error);
808#if CICPP
809                recp->xfldupdat(buffup); /* try it */
810#else /* CICPP */
811                fldupdat(irec,buffup); /* try it */
812#endif /* CICPP */
813
814                if (RECdbxp) {
815        RECtype=TYPEMFR;
816
817#if CICPP
818        recp->xrecupdat();   /* put it on disk */
819#else /* CICPP */
820        recupdat(crec,irec);   /* put it on disk */
821#endif /* CICPP */
822
823        RECtype=TYPEMFQ;
824                }
825                if (b7error == 222) {
826        b7error=0;
827                }
828
829                *errnop=b7error;
830
831                return(b7errxy);
832        }
833
834
835#if CICPP
836   recp = irecp;
837#else /* CICPP */
838        recp = vrecp[irec];
839#endif /* CICPP */
840   b7tell = tell;
841   b7setno=MFRmfn;
842
843   /* setup MFQTXCTS and MFQTAxxx and MFQTHxxx */
844   RECtype=TYPEMFR;
845   batchp=(unsigned char *)buffup;
846   sprintf((char *)batchp,"A%d|^%c%ld",MFQTXCTS,MFQSWTIM,time(&wtime));
847   batchp+=strlen((const char *)batchp);
848
849#if CICPP
850   if ((xdir_dbn0=recp->xfieldx(MFQTDBN0,1)) < 0){
851#else /* CICPP */
852   if ((xdir_dbn0=fieldx(irec,MFQTDBN0,1)) < 0){
853#endif /* CICPP */
854                b7_runerr(B7_THISP B7RE_1,"b7_run/xdir_dbn0",0);
855                goto B7_RUNERROR;
856   }
857
858   if (strlen(dbnamp) != DIRlen(xdir_dbn0) || strncmp(dbnamp,FIELDP(xdir_dbn0),DIRlen(xdir_dbn0))) {
859                sprintf((char *)batchp,"^%c%s",MFQSWDBN,dbnamp);
860                batchp+=strlen((const char *)batchp);
861   }
862
863   sprintf((char *)batchp,"^%c",MFQSWQTY);
864   batchp+=strlen((const char *)batchp);
865   sprintf((char *)batchp,B7EDIT1,0L);
866   batchp+=strlen((const char *)batchp);
867   *batchp++ = '|';
868   sprintf((char *)batchp,B7DELADD,MFQTASET,MFQTASET,0L);
869   batchp+=strlen((const char *)batchp);
870   sprintf((char *)batchp,B7DELADD,MFQTALCC,MFQTALCC,lastcc);
871   batchp+=strlen((const char *)batchp);
872   sprintf((char *)batchp,B7DELADD,MFQTHITS,MFQTHITS,0L);
873   batchp+=strlen((const char *)batchp);
874   sprintf((char *)batchp,B7DELADD,MFQTHCUR,MFQTHCUR,0L);
875   batchp+=strlen((const char *)batchp);
876   sprintf((char *)batchp,B7DELADD,MFQTHMFN,MFQTHMFN,0L);
877   batchp+=strlen((const char *)batchp);
878   sprintf((char *)batchp,B7DELADD,MFQTHSIZ,MFQTHSIZ,0L);
879 /*  batchp+=strlen((const char *)batchp); */
880
881#if CICPP
882   if ((p=(unsigned char *)recp->xfldupdat(buffup)) != NULL)
883        b7_runerr(B7_THISP B7RE_2,(char *)p,0);
884   if (btch0p)
885   if ((p=(unsigned char *)recp->xfldupdat(btch0p)) != NULL)         /* btch0p - AOT, 16/01/2002 */
886        b7_runerr(B7_THISP B7RE_2,(char *)p,0);
887
888   if ((xdir_hmem=recp->xfieldx(MFQTHMEM,1)) < 0) {
889        if (!RECdbxp)
890        fatal("b7_run/RECdbxp");
891        sprintf(buffup,"A%d|%s.%03x|",MFQTHMEM,RDBname,(int)b7setno);
892        if ((p=(unsigned char *)recp->xfldupdat(buffup)) != NULL)
893        b7_runerr(B7_THISP B7RE_2,(char *)p,0);
894        sprintf(buffup,"%s.%03x",RDBname,(int)b7setno);
895#else /* CICPP */
896   if ((p=fldupdat(irec,buffup)) != NULL)
897        b7_runerr(B7_THISP B7RE_2,(char *)p,0);
898   if (btch0p)
899   if ((p=fldupdat(irec,btch0p)) != NULL)                            /* btch0p - AOT, 16/01/2002 */
900        b7_runerr(B7_THISP B7RE_2,(char *)p,0);
901
902   if ((xdir_hmem=fieldx(irec,MFQTHMEM,1)) < 0) {
903        if (!RECdbxp)
904        fatal("b7_run/RECdbxp");
905        sprintf(buffup,"A%d|%s.%03x|",MFQTHMEM,RDBname,(int)b7setno);
906        if ((p=fldupdat(irec,buffup)) != NULL)
907        b7_runerr(B7_THISP B7RE_2,(char *)p,0);
908        sprintf(buffup,"%s.%03x",RDBname,(int)b7setno);         /* build file name for results in buffup */
909#endif /* CICPP */
910   }else {
911        memcpy(buffup,FIELDP(xdir_hmem),DIRlen(xdir_hmem));     /* or get it from irec into buffup */
912        buffup[DIRlen(xdir_hmem)]='\0';
913   }
914
915   
916#if CIB7TMPNULL
917   if (strcmp(buffup,"null")) {   /* do not write hits (bit string) to disk
918                                     note: b7_run() alloc b7buffer if needed and
919                                           stores hits in b7buffer at end of execution
920                                           therefore, b7buffer still can be used by b7_hit()
921                                           (or used directly by the caller..)
922                                     AOT - 14/01/2002
923                                  */
924#endif /* CIB7TMPNULL */
925
926       b7fd=CREAT(dbxcipar(b7_gidbnp,buffup,'='),PERMIS);
927       if (b7fd > 0)
928            CLOSE(b7fd);
929
930       n=dbxopt_ordwr; dbxopt_ordwr=O_RDWR;
931       b7fd=dbxopen(b7_gidbnp,buffup,"");
932       dbxopt_ordwr=n;
933
934#if CIB7TMPNULL
935   }                              /* AOT - 14/01/2002 */
936#endif /* CIB7TMPNULL */
937
938
939#if CICPP
940   if ((xdir_obj0=recp->xfieldx(MFQTOBJ0,1)) < 0){
941#else /* CICPP */
942   if ((xdir_obj0=fieldx(irec,MFQTOBJ0,1)) < 0){
943#endif /* CICPP */
944            b7_runerr(B7_THISP B7RE_3,"b7_run/xdir_obj0",0);
945                goto B7_RUNERROR;
946   }
947
948        dbxp = dbxstorp(dbnamp);
949    lastmfn = DBXmsmfn;
950
951#if CICPP
952   if ((xdir_obj0=recp->xfieldx(MFQTOBJ0,1)) < 0)
953#else /* CICPP */
954   if ((xdir_obj0=fieldx(irec,MFQTOBJ0,1)) < 0)
955#endif /* CICPP */
956        fatal("b7_run/fieldx");
957
958   b7p=(unsigned char *)FIELDP(xdir_obj0);
959
960   while (*b7p != OPRXEND) {
961#if RUITRACE
962        b7_showpdl( B7_THIS );
963#endif
964        b7opr = *b7p++;
965      postlen = *b7p;
966      switch (b7opr) {
967        case ZQUA:
968            for (nqualts=0; *b7p; ) {
969                if (*b7p == OPRNULL)
970                    break;
971                for( ;isspace(*b7p); b7p++) ;
972                for (n=0; isdigit(*b7p); b7p++)         /* convert tag */
973                    n = 10 * n + (*b7p - '0');
974                if (nqualts >= MAXQUAL)
975                    fatal("b7_run/MAXQUAL");
976                vqualt[nqualts++]=n;
977                if (*b7p == ',')
978                    b7p++;
979            }
980            vqualt[nqualts]=0;                          /* end */
981            b7pst = '0';
982            b7qty = '0';
983            b7acc = '0';
984                break;
985                        case ZPFX:
986                        for (tl_deflen=0; *b7p != OPRNULL; )
987                                        tl_defpfx[tl_deflen++] = uctab[*b7p++];
988            if (tl_deflen)
989                if (isalpha(tl_defpfx[tl_deflen-1]))
990                tl_defpfx[tl_deflen++] = ' ';
991            tl_defpfx[tl_deflen]='\0';
992            b7pst = '0';
993                        b7qty = '0';
994                        b7acc = '0';
995                        break;
996
997        case ZLDV:
998                b7pst = *b7p++;
999            b7qty = '0';
1000            b7acc = '0';
1001            break;
1002        default:
1003            b7pst = '0';
1004            b7qty = *b7p++;
1005            b7acc = *b7p++;
1006      }
1007
1008
1009      q=(unsigned char *)buffup; /* buffup is available */
1010      for (b7opxlen=0; *b7p; ) {
1011        if (*b7p == OPRNULL)
1012                break;
1013         *q++ = *b7p++;
1014         b7opxlen++;
1015      }
1016      *q='\0';
1017      b7rootf=OFF;
1018      b7rootloop=0;
1019        *b7opx='\0';
1020
1021      if (b7opxlen) {
1022        if (buffup[strlen(buffup)-1] == '$') {
1023                b7rootf=ON;
1024            b7opxlen--;
1025         }
1026         if (b7_xlkey(B7_THISP (char *)b7opx,buffup,uctab,NULL,&b7opxlen) == NULL)
1027                b7_runerr(B7_THISP 10,"b7_xlkey",0);
1028      }
1029
1030      if (*b7p != OPRNULL)
1031        fatal("b7_run/OPRNULL");
1032      b7p++;
1033
1034      switch (b7opr) {
1035        case ZQUA:
1036#if RUXTRACE
1037                                if (b70trace) {
1038                                        printf("->");
1039                                        for (qualtp=vqualt; *qualtp; qualtp++)
1040                                                printf("%d,",*qualtp);
1041                                        printf("nq=%d\n",nqualts);
1042                                }
1043#endif
1044            break;
1045                        case ZPFX:
1046#if RUXTRACE
1047                                if (b70trace) {
1048                                        printf("->");
1049                                }
1050#endif
1051                        break;
1052
1053/*
1054        <R>
1055                Aca empiezan los cambios :-)
1056        </R>
1057 */
1058        case ZLDV:
1059                /* oper _ */
1060
1061                npdlsb = npdls;
1062
1063                        /*Cargar resultado de b�da anterior almacenado en HD */
1064                if (RECdbxp && *b7opx == '#' && b7opxlen > 1) {
1065                mfn=atol((const char *)b7opx+1);
1066               for (p=b7opx+1; *p; p++)
1067                                if (!isdigit(*p)) {
1068                mfn= -1;
1069                  break;
1070               }
1071               if( mfn<0 )
1072                break;
1073
1074               pdlp=b7_push(B7_THIS);
1075               b7_initpdl(B7_THISP pdlp, 0, lastmfn);
1076
1077               if( mfn == 0 ){ /* Marcar todos los registros ... */
1078                  /* 1er bit=0 */
1079                  *PDLlvel=0x7F;
1080                  /* resto de los bits a 1 */
1081                  memset( PDLlvel+1, 0xFF, PDLsize-1);
1082                  /* 0s a partir de lmfn */
1083                  p0p=PDLlvel+PDLsize-1; /*last byte. */
1084                  for( mfn=PDLsize*8-1;mfn>PDLlmfn;mfn--)
1085                        *p0p &= ~bitmask[mfn&BY8RMASK];
1086               }else{
1087
1088                  /* should be read from qrydbnp, field MFQTHMEM - AOT, 28/01/2002 */
1089                  sprintf(buffup1,"%s.%03x",RDBname,(int)mfn);
1090                                        b7fd1=dbxopen(b7_gidbnp,buffup1,""); /* result log */
1091
1092                  if( ( CIREAD( b7fd1, PDLlvel, PDLsize ) )!= PDLsize )
1093                        break;
1094
1095                  if (b7fd1 > 0) CLOSE(b7fd1);
1096
1097               }
1098               PDLdocs = b7_hsizh( B7_THISP pdlp, &hsiz );
1099            }else{
1100
1101#if CICPP
1102               int AuxError = b7_pfx(tlirecp,MFQTXTAG,(char *)tl_defpfx,(char *)b7opx,B7RE_PFX);
1103               if (b7error) goto B7_RUNERROR;
1104               if (AuxError) {
1105#else /* CICPP */
1106               if (b7_pfx(B7_THISP tlirec,MFQTXTAG,(char *)tl_defpfx,(char *)b7opx,B7RE_PFX)) {
1107#endif /* CICPP */
1108                  mtp = (unsigned char *)b7_pfxdbn;
1109                  mkp = (unsigned char *)b7_pfxopx;
1110#if CDMDL
1111                /* MDL Medical Subject Heading is [.]mesh[/[xx]] */
1112                        if (b7_pfxmdl && b7opxlen > LE2) {
1113                        dctlen=LE2-1-3;
1114                        if (tl_opx[0] == '.') dctlen++;
1115                        qlflen=0;
1116                        if (tl_opx[b7opxlen-1] == '/') qlflen=1;
1117                        if (tl_opx[b7opxlen-3] == '/') qlflen=3;
1118                        memcpy(buffup,tl_opx,dctlen);
1119                        memcpy(buffup+dctlen,tl_opx+b7opxlen-qlflen,qlflen);
1120                        b7opxlen=dctlen+qlflen;
1121                        memcpy(tl_opx,buffup,b7opxlen);
1122                        tl_opx[b7opxlen]='\0';
1123                        }
1124#endif
1125               }else{
1126                  mtp = (unsigned char *)dbnamp;
1127                  mkp = (unsigned char *)b7opx;
1128               }
1129
1130               if( (mkp[0] == '"') && (mkp[strlen((const char *)mkp)-1] == '"' ) ){
1131                  int len;
1132                mkp++;
1133                  len = strlen((const char *)mkp)-1;
1134#if BEFORE20020115 /* BC5: Possibly incorrect assignment... */
1135                  if( mkp[len-1]='$' ){
1136#else
1137                  if( mkp[len-1]=='$' ){ /* AOT 15/01/2002 */
1138#endif
1139                        mkp[len-1] = '\0';
1140                     b7rootf=ON;
1141                  }else{
1142                        mkp[len] = '\0';
1143                  }
1144               }
1145
1146#if CDMDL /* D-Day */
1147#if SOING /* if ^y == TW and key has multiple words then search on MH */
1148                if (b7tw2mh) {
1149                if (strcmp(mtp,"TW") == 0) {                      /* tree */
1150                        for (n=0, p=mkp; *p; p++)                       /* key */
1151                        if (!isiswctab[*p]) { n++; break; }
1152                                if (n) mtp="MH";
1153                        }
1154                }
1155#endif /* SOING */
1156#endif /* CDMDL */
1157
1158#if CICPP
1159               trmp->xterm(mtp,mkp);
1160#else /* CICPP */
1161               TERM( b7itrm, mtp,mkp);
1162#endif /* CICPP */
1163
1164               pdlp=b7_push(B7_THIS);
1165               b7_initpdl(B7_THISP pdlp, postlen, lastmfn);
1166
1167               hits=0; hsiz=0;
1168               for(;;){
1169                                        if( b7rootf ){ /* right truncate ... */
1170                        if (TRMrc == RCEOF) break;
1171#if BEFORE20010827
1172                        if( strncmp((const char *) TRMkey, b7_pfxopx, strlen( b7_pfxopx ) ) ){
1173#endif
1174                        if( strncmp((const char *) TRMkey, (const char *)mkp, strlen( (const char *)mkp ) ) ){
1175                                break;
1176                     }
1177                        if (b7tell >= 2 ) {
1178                                count=TRMxytotp;
1179#if !CICPP
1180                                                                b7_msg(B7_THISP 1,TRMkey,0,count,b7rootmsg ? 1 : 4); /* 1st_msg */
1181#endif /* CICPP */
1182                                                        }
1183
1184                                                        if( PDLdocs && PDLplen ){
1185                        pdlp=b7_push(B7_THIS);
1186                        b7_initpdl(B7_THISP pdlp, postlen, lastmfn);
1187                                                        }
1188
1189                  }else if (TRMrc != RCNORMAL){
1190                     break;
1191                  }
1192
1193                  for( nord=0;; ){
1194#if CICPP
1195                     mfn=trmp->xposting(++nord);
1196#else /* CICPP */
1197                     mfn=posting(b7itrm,++nord);
1198#endif /* CICPP */
1199                     if( mfn <= 0 )
1200                        break;
1201
1202                     if (nqualts) {
1203                        for (n=0, qualtp=vqualt; *qualtp; qualtp++)
1204                           if (TRMptag == *qualtp) {
1205                              n=1; break;
1206                           }
1207                        if (n)
1208                            ;           /* qualifiers list */
1209                        else
1210                            continue;   /* goto next posting */
1211                     }
1212#if !LIND
1213                     if( !PDLplen ){
1214#endif /* !LIND */
1215                        mask =bitmask[mfn&BY8RMASK];
1216                        offset = (mfn/8);
1217                        if( !( PDLlvel[offset] & mask ) ){
1218                                PDLdocs++;
1219                           PDLlvel[offset] |= mask;
1220                        }
1221#if!LIND
1222                     }else{
1223                        if( mfn != hsiz ){
1224                                hsiz = mfn;
1225                           PDLdocs++;
1226//                           b7_addk( B7_THISP pdlp, trmp );
1227                        }
1228                        b7_addk( B7_THISP pdlp, trmp );
1229                     }
1230#endif /* !LIND */
1231                  }
1232
1233                  if( b7rootf ){
1234#if CICPP
1235                     trmp->xnxterm();
1236#else /* CICPP */
1237                     NXTERM(b7itrm);
1238#endif /* CICPP */
1239                  }else
1240                     break;
1241
1242                  if( b7rootloop ){ /* hacer or entre los resultados. */
1243#if !LIND
1244                                                        if( PDLplen ){
1245                        if( npdls > 1 ){
1246                           pdlp = b7_push(B7_THIS); /*donde dejar el resultado. */
1247                           b7_initpdl( B7_THISP pdlp, postlen, lastmfn );
1248                                b7_zorx(B7_THIS);
1249                        }
1250                     }
1251#else
1252                                                        ;
1253#endif /* !LIND */
1254                  }else
1255                     b7rootloop++;
1256               }
1257
1258            }
1259
1260/*GOT_ZLDV:*/
1261
1262                        if( npdls == npdlsb ){
1263               pdlp = b7_push(B7_THIS);
1264               b7_initpdl( B7_THISP pdlp, postlen, lastmfn );
1265            }
1266
1267                if (b7tell) {
1268               sprintf(buffup,"%s%c",mkp,(b7rootf)? '$' : '\0');
1269                b7_msg(B7_THISP 0,buffup,0,PDLdocs,1);
1270            }
1271            nqualts=0;
1272                break;
1273
1274            default:
1275#if !LIND
1276                if( !VPDLplen( vpdltop ) ){     /* top tiene nivel 1 */
1277#endif /* !LIND */
1278                  pdlp = vpdlp[ vpdltop ];
1279                  res = VPDLlvel( vpdltop - 1 );
1280                  op1 = PDLlvel;
1281#if !LIND
1282               }else{
1283                pdlp=b7_push(B7_THIS);
1284                  b7_initpdl( B7_THISP pdlp, b7acc, lastmfn );
1285               }
1286#endif /* !LIND */
1287               loop=PDLsize;
1288               switch( b7opr ){
1289                case ZORX:
1290                                /* oper + */
1291#if !LIND
1292                        if( b7acc == '1' ){
1293#endif /* !LIND */
1294                                for( ;loop--; )
1295                                        *res++ |= *op1++;
1296                        b7_pop(B7_THIS);
1297#if !LIND
1298                     }else
1299                        b7_zorx(B7_THIS);
1300#endif /* !LIND */
1301                     break;
1302                case ZAND:
1303                                /* oper * */
1304#if !LIND
1305                        if( b7acc == '1' ){
1306#endif /* !LIND */
1307                                for( ;loop--; )
1308                                        *res++ &= *op1++;
1309                        b7_pop(B7_THIS);
1310#if !LIND
1311                     }else
1312                        b7_zand( B7_THISP 1 );
1313#endif /* !LIND */
1314                     break;
1315                case ZANN:
1316                                /* oper ^ */
1317#if !LIND
1318                        if( b7acc == '1' ){
1319#endif /* !LIND */
1320                                for( ;loop--; )
1321                                        *res++ &= ~(*op1++);
1322                        b7_pop(B7_THIS);
1323#if !LIND
1324                     }else
1325                        b7_zann(B7_THIS);
1326#endif /* !LIND */
1327                     break;
1328#if !LIND
1329                case ZANG:
1330                                /* oper (G) */
1331                        b7_zand( B7_THISP 2 );
1332                     break;
1333                case ZANF:
1334                                /* oper (F) */
1335                        b7_zand( B7_THISP 3 );
1336                     break;
1337                case ZANP:
1338                                /* oper . */
1339                        b7_zanp( B7_THISP 4, b7qty );
1340                     break;
1341                case ZANE:
1342                                /* oper $ */
1343                        b7_zanp( B7_THISP 5, b7qty );
1344                     break;
1345#endif /* !LIND */
1346               }
1347               pdlp = vpdlp[vpdltop];
1348               if( !PDLplen )
1349                PDLdocs = b7_hsizh( B7_THISP pdlp, &hsiz );
1350
1351               if (b7tell) {
1352                sprintf(buffup,"%c",b7opr);
1353                b7_msg(B7_THISP 0,buffup,0,PDLdocs,2);
1354               }
1355      }
1356   }
1357
1358   PDLdocs = b7_hsizh( B7_THISP pdlp, &hsiz );
1359
1360        sprintf(buffup,B7EDIT1,b7setno);
1361   if (b7tell)
1362        b7_msg(B7_THISP 1,buffup,0,PDLdocs,3);                            /* end_msg */
1363
1364#if RUITRACE
1365   b7_showpdl( B7_THIS );
1366#endif
1367
1368        pdlp = vpdlp[vpdltop];
1369
1370    /* store actual MFQTASET */
1371    sprintf(buffup,B7EDIT1,b7setno);
1372#if CICPP
1373    memcpy(FIELDP(irecp->xfieldx(MFQTASET,1)),buffup,B7UPLEN);
1374#else /* CICPP */
1375    memcpy(FIELDP(fieldx(irec,MFQTASET,1)),buffup,B7UPLEN);
1376#endif /* CICPP */
1377
1378    /* store actual MFQTALCC */
1379    sprintf(buffup,B7EDIT1,lastcc);
1380#if CICPP
1381    memcpy(FIELDP(irecp->xfieldx(MFQTALCC,1)),buffup,B7UPLEN);
1382#else /* CICPP */
1383    memcpy(FIELDP(fieldx(irec,MFQTALCC,1)),buffup,B7UPLEN);
1384#endif /* CICPP */
1385
1386    /* store actual MFQTHITS */
1387    sprintf(buffup,B7EDIT1,PDLdocs);
1388#if CICPP
1389    memcpy(FIELDP(irecp->xfieldx(MFQTHITS,1)),buffup,B7UPLEN);
1390#else /* CICPP */
1391    memcpy(FIELDP(fieldx(irec,MFQTHITS,1)),buffup,B7UPLEN);
1392#endif /* CICPP */
1393
1394/*..*/
1395        /* actual #bytes of hit list */
1396   hsiz = hsiz/8+1;
1397
1398    /* store actual MFQTHSIZ */
1399    sprintf(buffup,B7EDIT1,hsiz);
1400#if CICPP
1401    memcpy(FIELDP(irecp->xfieldx(MFQTHSIZ,1)),buffup,B7UPLEN);
1402#else /* CICPP */
1403    memcpy(FIELDP(fieldx(irec,MFQTHSIZ,1)),buffup,B7UPLEN);
1404#endif /* CICPP */
1405
1406/*..*/
1407    /* update stored MFQTHMEM */
1408    if (b7fd) {
1409
1410        for (p0p=PDLlvel, left=hsiz/*, bytes=0*/; left; left-=bytes ) {
1411                        bytes=hsiz;
1412                        if (bytes > B72SIZE_MAX)
1413                bytes=B72SIZE_MAX;      /* < U */
1414                        if (bytes > left)
1415                bytes=left;
1416                        if ((unsigned)CIWRITE(b7fd,p0p,(unsigned)bytes) != bytes){
1417                                fatal("b73_run/write/6");
1418                        }
1419
1420         p0p+=bytes;
1421      }
1422      CLOSE(b7fd);
1423      b7fd=0; /* 06/03/95 */
1424        }
1425
1426
1427    /* update MFQTXCTS^MFQSWQTY */
1428    sprintf(buffup,B7EDIT1,PDLdocs);
1429#if CICPP
1430    if ((xdir_xcts=irecp->xfieldx(MFQTXCTS,irecp->xnocc(MFQTXCTS))) < 0)
1431#else /* CICPP */
1432    if ((xdir_xcts=fieldx(irec,MFQTXCTS,nocc(irec,MFQTXCTS))) < 0)
1433#endif /* CICPP */
1434        fatal("b7_run/xdir_xcts");
1435    n=DIRlen(xdir_xcts); p=(unsigned char *)FIELDP(xdir_xcts);
1436    nffi=n;
1437    p=subfldp(p,MFQSWQTY,&nffi);
1438    memcpy(p,buffup,B7UPLEN);
1439
1440    /* put it on disk */
1441    if (RECdbxp) {
1442#if CICPP
1443        recp->xrecupdat();
1444#else /* CICPP */
1445        recupdat(crec,irec);
1446#endif /* CICPP */
1447    }
1448    RECtype=TYPEMFQ;
1449
1450
1451#if CIB7HITLIST
1452    /* alloc b7bufferp if needed */
1453    if (!b7error) {
1454
1455        LONGX bytsneed;         //
1456        int hcase;             //
1457        LONGX mfnvar;
1458        LONGX xbytes=PDLdocs*sizeof(mfnvar);
1459
1460        if (xbytes < hsiz) {
1461            bytsneed=xbytes;
1462            hcase=MFNSTRING; /* a binary 4-byte integer list ready to use */
1463        }
1464        else {
1465            bytsneed=hsiz;     //
1466            hcase=BITSTRING;   //
1467        }
1468
1469        if (b7bufferp) if (b7bufferp->bufsiz < bytsneed) b7_hbfree(B7_THISP &b7bufferp);
1470        if (!b7bufferp) b7_hballoc(B7_THISP (bytsneed),&b7bufferp);
1471        b7bufferp->setno = b7setno;
1472
1473        b7bufferp->hcase = hcase;
1474        b7bufferp->ndocs = PDLdocs;
1475
1476        if (hcase == MFNSTRING) {
1477
1478    unsigned char *hp=PDLlvel;
1479        LONGX hsizleft=hsiz;
1480    LONGX hitsleft=PDLdocs;
1481
1482    LONGX hcur=0;
1483    LONGX hmfn=0;
1484    int bitloop,by8masked;
1485
1486    B7HITLIST *hitlistp=(B7HITLIST *)b7bufferp->area;
1487    LONGX *mfnlistp=hitlistp->mfnlist;
1488
1489          for (; hitsleft; ) {
1490            /* check bytes left */ if (!hsizleft) fatal("b7_run/aotmsa1/hsizleft");
1491            /* skip null bytes */
1492            while (!*hp) {
1493              hp++; hmfn+=8; hsizleft--;
1494            }
1495            /* scan max 8 bits */
1496            bitloop=8-(hmfn&BY8RMASK);
1497            for (; bitloop--; hmfn++) {
1498                if (*hp&bitmask[by8masked=hmfn&BY8RMASK]) {
1499                    hcur++; hitsleft--;
1500                                        /* store hit hcur/hmfn and count it */
1501                    *mfnlistp++ = hmfn;
1502                } /* end if (*hp & bitmask[by8masked]) */
1503            } /* end for (; bitloop--; hmfn++) */
1504                        /* increment byte ptr every 8 bits */
1505            if (by8masked == BY8RMASK) {
1506                hp++; hsizleft--;
1507            }
1508          } /* end for (; hitsleft; ) */
1509      } /* end if (hcase == MFNSTRING) */
1510      else { /* else if (hcase == MFNSTRING) */
1511        memcpy(b7bufferp->area,PDLlvel,hsiz);
1512        memset(b7bufferp->area+hsiz,0x00,b7bufferp->bufsiz-hsiz);
1513      } /* end if (hcase == MFNSTRING) */
1514    } /* end if (!b7error) */
1515
1516//B7HITLISTLONG   1
1517//B7HITLISTSHORT  2
1518
1519#else /* CIB7HITLIST */
1520
1521    /* alloc b7bufferp if needed */
1522    if (!b7error) {
1523        if (b7bufferp) if (b7bufferp->bufsiz < (lastmfn/8+1)) b7_hbfree(B7_THISP &b7bufferp);
1524        if (!b7bufferp) b7_hballoc(B7_THISP (lastmfn/8+1),&b7bufferp);
1525        b7bufferp->setno = b7setno;
1526
1527        memcpy(b7bufferp->area,PDLlvel,hsiz);
1528        memset(b7bufferp->area+hsiz,0x00,b7bufferp->bufsiz-hsiz);
1529    }
1530#endif /* CIB7HITLIST */
1531
1532    /* release tmp area */
1533         b7_pop(B7_THIS);
1534
1535#if CICPP
1536    delete trmp;
1537#else
1538    free(vtrmp[b7itrm]);    /* Chico 03/07/2007 */
1539    vtrmp[b7itrm] = NULL;
1540    ntrms--;   
1541#endif /* CICPP */
1542
1543   *errnop=b7error;
1544 return 0;
1545
1546}
1547                                 
1548#if CICPP
1549int CIB7::b7_hballoc(LONGX bufsiz, B7HITBUF **bufferpp)
1550#else /*CICPP*/
1551int b7_hballoc(cib7p,bufsiz,bufferpp)                                           /*
1552------------
1553                                allocate b7_hit() processing buffer
1554                                                                        */
1555b7_CIB7 *cib7p;
1556LONGX bufsiz;           /* buffer size */
1557B7HITBUF **bufferpp;    /* buffer addr */
1558#endif /*CICPP*/
1559{
1560    if (!*bufferpp) {
1561#if CICPP
1562        try { *bufferpp=(B7HITBUF *)new char [sizeof(B7HITBUF)+bufsiz]; }
1563        catch (BAD_ALLOC) { *bufferpp = (B7HITBUF *)ALLONULL; }
1564#else /* CICPP */
1565        *bufferpp=(B7HITBUF *)ALLOC((ALLOPARM)(sizeof(B7HITBUF)+bufsiz));
1566#endif /* CICPP */
1567        if (*bufferpp == (B7HITBUF *)ALLONULL) fatal("b7_hballoc/ALLOC");
1568        (*bufferpp)->bufsiz=bufsiz;
1569    }
1570    else
1571        if ((*bufferpp)->bufsiz != bufsiz) fatal("b7_hballoc/bufsiz");
1572/*    (*bufferpp)->block=(-1L);*/
1573    (*bufferpp)->setno=(-1L);
1574    return(0);
1575}
1576
1577
1578#if CICPP
1579int CIB7::b7_hbinit(LONGX setno, B7HITBUF *bufferp)
1580#else /*CICPP*/
1581int b7_hbinit(cib7p,setno,bufferp)                                              /*
1582------------
1583                                initialize b7_hit() processing buffer
1584                                                                        */
1585b7_CIB7 *cib7p;
1586LONGX setno;            /* query number */
1587B7HITBUF *bufferp;      /* buffer */
1588#endif /*CICPP*/
1589{
1590    if (!bufferp) fatal("b7_hbinit/NULL");
1591/*    bufferp->block=(-1L);*/
1592    bufferp->setno=setno;
1593    return(0);
1594}
1595
1596#if CICPP
1597int CIB7::b7_hbfree(B7HITBUF **bufferpp)
1598#else /*CICPP*/
1599int b7_hbfree(cib7p,bufferpp)                                                   /*
1600------------
1601                                release b7_hit() processing buffer
1602                                                                        */
1603b7_CIB7 *cib7p;
1604B7HITBUF **bufferpp;    /* buffer addr */
1605#endif /*CICPP*/
1606{
1607    if (*bufferpp) {
1608#if CICPP
1609        delete [] (char *)*bufferpp;
1610#else /* CICPP */
1611        FREE(*bufferpp);
1612#endif /* CICPP */
1613        *bufferpp=NULL;
1614    }
1615    return(0);
1616}
1617
1618#if CICPP
1619LONGX CIB7::b7_hit(RECSTRU *irecp, LONGX nord, LONGX setno)
1620#else /* CICPP */
1621LONGX b7_hit(cib7p,irec,nord,setno)                                   /*
1622-----------
1623                    abenda se vrecp nao inicializado;
1624                    abenda se registro irec nao alocado;
1625                    abenda se registro irec invalido;
1626                    retorna total de hits se nord = 0;
1627                    se nord > total de hits
1628                        zera hit e mfn correntes e retorna -1;
1629                    mantem controles para chamadas subsequentes;
1630                    retorna o mfn correspondente ao hit nord
1631                    (retorna -2 .. -n se algum erro)
1632                                                                      */
1633b7_CIB7 *cib7p;
1634LONGX irec;             /* indice de vrecp, para info/store */
1635LONGX nord;             /* numero de ordem do hit a analisar */
1636LONGX setno;            /* query number */
1637#endif /* CICPP */
1638{
1639    char buffup[B7UPLEN+1];       /* area for fldupdat */
1640    RECSTRU *recp;
1641    LONGX hits,hcur,hsiz,hmfn;
1642    int xdir_hits,xdir_hcur,xdir_hsiz,xdir_hmfn,xdir_hmem;
1643    unsigned char *p;
1644    LONGX offset,mfn;
1645    LONGX loop;
1646    int loop2,n,delta8,delta1;
1647#if CHKFOUND
1648    int found;
1649#endif
1650/* Leer de disco */
1651    int fd;
1652    char filname[CIMPL+1];
1653    LONGX rslen;
1654#if HITTRACE
1655 printf("b7_hit - irec,nord: %ld,%ld \n",irec,nord);
1656#endif
1657#if SHOWCORE
1658 if (b70trace) showcore("b7_hit");
1659#endif
1660
1661    /* Process hit MFNSTRING/LONGX
1662    */
1663#if CIB7HITLIST                     /* AOT, 28/01/2002 */
1664    if (!b7bufferp) fatal("b7_hit/MFNSTRING/b7bufferp");
1665    if (b7bufferp->setno != setno) fatal("b7_hit/MFNSTRING/setno");
1666    if (b7bufferp->hcase == MFNSTRING) {
1667        hits=b7bufferp->ndocs;
1668        if (nord == 0 || nord > hits) {
1669            if (nord == 0)
1670                mfn=hits;           /* returning value */
1671            else
1672                mfn=(-1L);
1673        }
1674        else { /* 1 >= nord <= hits */
1675            B7HITLIST *hitlistp;            /* hit processing */
1676            LONGX *mfnlistp;                 /* hit processing */
1677            hitlistp=(B7HITLIST *)b7bufferp->area;
1678            mfnlistp=hitlistp->mfnlist;
1679            mfnlistp+=(nord-1);
1680            mfn = *mfnlistp;
1681        } /* end if (nord == 0 || nord > hits) */
1682       
1683        return(mfn);
1684           
1685    } /* if (b7bufferp->hcase == MFNSTRING) */
1686#endif /* CIB7HITLIST */
1687   
1688   
1689    /* BTW, b7errxy nao deveria ser resetado antes de return??? - AOT, 28/01/2002 */
1690    strcpy(b7errxy,"b7_hit");          /* b7_hiterr() */
1691
1692#if !CICPP
1693    if (!nrecs)
1694#if CDROM
1695        return(-2L);
1696#else
1697        fatal("b7_hit/nrecs");
1698#endif
1699    recp=vrecp[irec];
1700
1701#else /* CICPP */
1702    recp=irecp;
1703#endif /* CICPP */
1704
1705    if (!recp)
1706#if CDROM
1707        return(-3L);
1708#else
1709        fatal("b7_hit/irec");
1710#endif
1711    if (RECtype != TYPEMFQ || RECrc != RCNORMAL)
1712#if CDROM
1713        return(-4L);
1714#else
1715        fatal("b7_hit/check");
1716#endif
1717#if CICPP
1718    if ((xdir_hits=recp->xfieldx(MFQTHITS,1)) < 0)
1719#else /* CICPP */
1720    if ((xdir_hits=fieldx(irec,MFQTHITS,1)) < 0)
1721#endif /* CICPP */
1722
1723#if CDROM
1724        return(-5L);
1725#else
1726        fatal("b7_hit/xdir_hits");
1727#endif
1728
1729                for (hits=0, p=(unsigned char *)FIELDP(xdir_hits), loop=DIRlen(xdir_hits); loop--; p++)
1730        hits = hits * 10 + (*p - '0');
1731    if (nord < 0 || nord > (hits+1))
1732#if CDROM
1733        return(-6L);
1734#else
1735        fatal("b7_hit/nord");
1736#endif
1737#if CICPP
1738    if ((xdir_hcur=recp->xfieldx(MFQTHCUR,1)) < 0)
1739#else /* CICPP */
1740    if ((xdir_hcur=fieldx(irec,MFQTHCUR,1)) < 0)
1741#endif /* CICPP */
1742#if CDROM
1743        return(-7L);
1744#else
1745        fatal("b7_hit/xdir_hcur");
1746#endif
1747#if CICPP
1748    if ((xdir_hmfn=recp->xfieldx(MFQTHMFN,1)) < 0)
1749#else /* CICPP */
1750    if ((xdir_hmfn=fieldx(irec,MFQTHMFN,1)) < 0)
1751#endif /* CICPP */
1752#if CDROM
1753        return(-8L);
1754#else
1755        fatal("b7_hit/xdir_hmfn");
1756#endif
1757#if CICPP
1758    if ((xdir_hsiz=recp->xfieldx(MFQTHSIZ,1)) < 0)
1759#else /* CICPP */
1760    if ((xdir_hsiz=fieldx(irec,MFQTHSIZ,1)) < 0)
1761#endif /* CICPP */
1762#if CDROM
1763        return(-9L);
1764#else
1765        fatal("b7_hit/xdir_hsiz");
1766#endif
1767    if (nord == 0 || nord > hits) {
1768        hcur=hmfn=0;
1769        if (nord == 0)
1770            mfn=hits;           /* returning value */
1771        else
1772            mfn=(-1L);
1773    }
1774    else {
1775        for (hcur=0, p=(unsigned char *)FIELDP(xdir_hcur), loop=DIRlen(xdir_hcur); loop--; p++)
1776            hcur = hcur * 10 + (*p - '0');
1777        for (hmfn=0, p=(unsigned char *)FIELDP(xdir_hmfn), loop=DIRlen(xdir_hmfn); loop--; p++)
1778            hmfn = hmfn * 10 + (*p - '0');
1779        for (hsiz=0, p=(unsigned char *)FIELDP(xdir_hsiz), loop=DIRlen(xdir_hsiz); loop--; p++)
1780            hsiz = hsiz * 10 + (*p - '0');
1781#if HITTRACx
1782 printf("b7_hit - rec - hits=%ld hcur=%ld hsiz=%ld hmfn=%ld\n",
1783  hits,hcur,hsiz,hmfn);
1784#endif
1785        if (hcur == nord)
1786            mfn=hmfn;
1787        else {
1788#if CICPP
1789            if ((xdir_hmem=recp->xfieldx(MFQTHMEM,1)) < 0)
1790#else /* CICPP */
1791            if ((xdir_hmem=fieldx(irec,MFQTHMEM,1)) < 0)
1792#endif /* CICPP */
1793#if CDROM
1794                return(-10L);
1795#else
1796                fatal("b7_hit/xdir_hmen");
1797#endif
1798            if (nord > hcur) {
1799#if UNIX
1800                delta8 =  8; delta1 =  1;
1801#else
1802                delta8 = +8; delta1 = +1;
1803#endif
1804            }
1805            else {
1806                delta8 = -8; delta1 = -1;
1807            }
1808#if CDUSP
1809            mfn = (hcur == 0) ? 0 : hmfn+delta1;
1810#else
1811            mfn = (hmfn == 0) ? 0 : hmfn+delta1;
1812#endif
1813            offset=(mfn/8);
1814/* Leer de disco */
1815            if (!b7bufferp) fatal("b7_hit/buffer");
1816            if (b7bufferp->bufsiz < hsiz) fatal("b7_hit/bufsiz");
1817            if (b7bufferp->setno != setno) {
1818                                    memcpy(filname,FIELDP(xdir_hmem),n=DIRlen(xdir_hmem));
1819                                    filname[n]='\0';
1820                dbxopt_fatal=0; fd=dbxopen(b7_gidbnp,filname,"");
1821                                    if (fd <= 0) fatal("b7_hit/open/1");
1822                                    rslen=(unsigned)CIREAD(fd,b7bufferp->area,hsiz);
1823                                    if (rslen != hsiz) fatal("b7_hit/read/1");
1824                CLOSE(fd);
1825                b7bufferp->setno = setno;
1826            }
1827
1828/*            for (p=FIELDP(xdir_hmem)+offset; hcur != nord; ) {*/
1829            for (p=b7bufferp->area+offset; hcur != nord; ) {
1830                loop=(nord > hcur) ? hsiz-(mfn/8) : (mfn/8);
1831#if CHKFOUND
1832                found=0;
1833#endif
1834#if HITTRACx
1835 printf("b7_hit - hcur=%ld nord=%ld mfn=%ld *p=%02x loop=%ld - hmfn=%ld\n",
1836  hcur,nord,mfn,*p,loop,hmfn);
1837#endif
1838                do {
1839                    if (!*p) {
1840                        p+=delta1; mfn+=delta8;
1841#if HITTRACx
1842 printf("b7_hit - hcur=%ld nord=%ld mfn=%ld *p=%02x loop=%ld - continue\n",
1843  hcur,nord,mfn,*p,loop);
1844#endif
1845                        continue;
1846                    }
1847                    if (nord > hcur)
1848                        loop2 = 8 - (mfn&BY8RMASK);
1849                    else
1850                        loop2 = (mfn&BY8RMASK) + 1;
1851                    for (; loop2--; mfn+=delta1) {
1852                        n=mfn&BY8RMASK;
1853#if HITTRACx
1854 printf("b7_hit - hcur=%ld nord=%ld mfn=%ld *p=%02x loop=%ld loop2=%d n=%d\n",
1855  hcur,nord,mfn,*p,loop,loop2,n);
1856#endif
1857                        if (*p & bitmask[n]) {
1858#if CHKFOUND
1859                            found=1;
1860#endif
1861                            hmfn=mfn; hcur+=delta1;
1862                            if (nord == hcur)
1863                                break;
1864                        }
1865                    }
1866#if CHKFOUND
1867                    if (found) {
1868#endif
1869                        if (nord > hcur) {
1870                            if (n == BY8RMASK)
1871                                p++;
1872                        }
1873                        else
1874                            if (n == 0)
1875                                p--;
1876                        break;
1877#if CHKFOUND
1878                    }
1879                    else
1880                        fatal("b7_hit/bug1");
1881#endif
1882                } while (--loop > 0);
1883#if CHKFOUND
1884                if (!found)
1885                     fatal("b7_hit/bug2");
1886#endif
1887            } /* end for hcur != nord */
1888        } /* end else hcur == nord */
1889    } /* end else nord == 0 || nord > hits */
1890    /* store */
1891    sprintf(buffup,B7EDIT1,hcur);
1892    memcpy(FIELDP(xdir_hcur),buffup,B7UPLEN);
1893    sprintf(buffup,B7EDIT1,hmfn);
1894    memcpy(FIELDP(xdir_hmfn),buffup,B7UPLEN);
1895#if HITTRACE
1896 printf("b7_hit - mfn: %ld\n",mfn);
1897#endif
1898#if SHOWCORE
1899 if (b70trace) showcore("b7_hit - exit");
1900#endif
1901    return(mfn);
1902}
1903
1904#if !WWWISIS
1905#if CICPP
1906int CIB7::b7_msg(int tline,char *msg,LONGX psts,LONGX docs,int tmsg)
1907#else
1908int b7_msg(cib7p,tline,msg,psts,docs,tmsg)
1909b7_CIB7 *cib7p;
1910int tline;
1911char *msg;
1912LONGX psts;
1913LONGX docs;
1914int tmsg;
1915#endif
1916{
1917        char *q;
1918
1919   q = msg+strlen( msg );
1920   if (nqualts) {
1921      *q++ = '/';  *q++ = '(';
1922      for (qualtp=vqualt; *qualtp; qualtp++) {
1923          if (*(qualtp+1))
1924              sprintf(q,"%d,",*qualtp);
1925          else
1926              sprintf(q,"%d",*qualtp);
1927          while (*q) q++;
1928      }
1929      *q++ = ')';  *q = '\0';
1930   }
1931
1932
1933    if (docs) {
1934        printf("%8ld ",docs); //AOT, 22/12/2006
1935    }
1936    else {    /*12345678 */
1937        printf("         ");  //AOT, 22/12/2006
1938    }
1939    if (msg)
1940        switch (tmsg) {
1941        case 1:
1942            printf(" %s",msg);
1943            break;
1944        case 2:
1945            printf(" Operation %s",msg);
1946            break;
1947        case 3:
1948            printf(" Set #%s",msg);
1949            break;
1950        case 4:
1951            printf("   %s",msg);
1952            break;
1953        default:
1954            fatal("b7_msg/tmsg");
1955        }
1956#if TOSEETLINE
1957    if (tline)
1958        printf(" [%d]\n",tline);
1959    else
1960#else
1961    if (tline == 0 || tline == 1)       /* no wrn */
1962#endif
1963        printf("\n");
1964
1965
1966    return(0);
1967}
1968#endif /* WWWISIS */
1969
1970#if CICPP
1971char * CIB7 :: b7_xlkey(char *opx,char *bufp,unsigned char uctab[],char *xlfilp,int *opxlp)
1972#else
1973char *b7_xlkey(cib7p,opx,bufp,uctab,xlfilp,opxlp)
1974b7_CIB7 *cib7p;
1975char *opx;
1976char *bufp;
1977unsigned char uctab[];
1978char *xlfilp;
1979int *opxlp;
1980#endif
1981{
1982    unsigned char *p;
1983    int loop,newlen;
1984#if TRACEXK
1985printf("b7_xlkey - buf=%s (%d)\n",bufp,*opxlp);
1986#endif
1987    if (xlfilp) fatal("b7_xlkey/xlfilp");
1988    for (p=(unsigned char *)bufp, loop= *opxlp; loop--; p++)
1989        *p = uctab[*p];
1990    newlen= *opxlp;
1991    if (newlen > LE2) if (newlen != LE2+2 || (*bufp != '\"' && bufp[newlen-1] != '\"'))
1992        newlen=LE2;
1993    memcpy(opx,bufp,newlen);
1994    opx[newlen]='\0';
1995    *opxlp = newlen;
1996    return(opx);
1997}
1998
1999#if CICPP
2000LONGX CIB7::b7_hsizh(PDLSTRU *pdlp,LONGX *hsizp)
2001#else
2002LONGX b7_hsizh(cib7p,pdlp,hsizp)
2003b7_CIB7 *cib7p;
2004PDLSTRU *pdlp;
2005LONGX *hsizp;
2006#endif
2007{
2008    LONGX hits,hsiz,loop,mfn,offset;
2009    int loop2;
2010    unsigned char *p1p;
2011    hits=0; hsiz=0;
2012    p1p=PDLlvel;
2013    for (mfn=0, loop=PDLsize; loop--; ) {
2014        offset=(mfn/8);
2015        if (!*(PDLlvel+offset)) {
2016            mfn+=8;
2017            continue;
2018        }
2019        for (loop2=8; loop2--; mfn++){
2020                        if( mfn > PDLlmfn )
2021                break;
2022            if (*(p1p+offset) & bitmask[mfn&BY8RMASK]) {
2023                hits++;
2024                hsiz=mfn;
2025#if MFNTRACE
2026 printf("%ld ",mfn);
2027#endif
2028            }
2029                  }
2030    }
2031#if MFNTRACE
2032 printf("\n");
2033#endif
2034    *hsizp = hsiz;
2035    return(hits);
2036}
2037
2038
2039/*
2040 * <R>
2041 * funciones utilizadas desde _run()
2042 * </R>
2043 */
2044
2045#if !LIND
2046
2047#if CICPP
2048int CIB7::b7_cmp( char *op1, char *op2, int oplen )
2049#else
2050int b7_cmp( cib7p,op1,op2,oplen )
2051b7_CIB7 *cib7p;
2052char *op1;              /* posting 1 */
2053char *op2;              /* posting 2 */
2054int oplen;              /* tama�e los posting */
2055#endif
2056{
2057/*
2058        Return value
2059        >0      => op1 > op2
2060        <0      => op1 < op2
2061         0      => op1 = op2
2062 */
2063        int res;
2064        int i;
2065
2066   oplen = (oplen>3)?oplen:3;
2067
2068   if (!op1 || !op2) fatal("cib72/b7_cmp/op1Xop2");
2069
2070   for( i = 0; i < oplen; i++ ){
2071        res = ((int)(unsigned char)*(op1+i) - (unsigned char)*(op2+i));
2072      if( res != 0 )    return res;
2073   }
2074    return 0;
2075}
2076
2077#if CICPP
2078int CIB7::b7_prox( char *op1, char* op2, short andl, LONGX dist )
2079#else
2080int b7_prox( cib7p,op1,op2,andl,dist )
2081b7_CIB7 *cib7p;
2082char *op1;
2083char *op2;
2084short andl;             /* 4: oper . ;  5:oper $ */
2085LONGX dist;             /* cant. de operadores. */
2086#endif
2087{
2088
2089/*
2090        retorna 0 si no cumple la condicion de proximidad,
2091        dist de 0 en caso contrario.
2092 */
2093
2094        int res;
2095   short int cnt1, cnt2;
2096
2097        if( b7_cmp( B7_THISP op1, op2, 6 ) )
2098        return 0;
2099
2100   cnt1 = (unsigned)*(op1+6);
2101   cnt1 = (cnt1<<8) + ((unsigned)*(op1+7));
2102
2103   cnt2 = (unsigned)*(op2+6);
2104   cnt2 = (cnt2<<8) + ((unsigned)*(op2+7));
2105
2106   switch( andl ){
2107        case 4:
2108        res = ( abs( cnt1 - cnt2 ) <= dist );
2109         break;
2110        case 5:
2111        res = ( abs( cnt1 - cnt2 ) == dist );
2112         break;
2113      default:
2114        res = 0;
2115   }
2116
2117   return res;
2118
2119}
2120
2121#if CICPP
2122LONGX CIB7::b7_gmfn( char *str )
2123#else
2124LONGX b7_gmfn( cib7p,str )
2125b7_CIB7 *cib7p;
2126char *str;              /*posting */
2127#endif
2128{
2129/*
2130        Calcula el MFN del posting almacenado.
2131 */
2132        LONGX res;
2133        unsigned char mfn1, mfn2, mfn3;
2134
2135        mfn1 = *str;
2136        mfn2 = *(str+1);
2137        mfn3 = *(str+2);
2138
2139        res = (LONGX)(mfn1<<16) + (LONGX)(mfn2<<8) + (LONGX) mfn3;
2140
2141   return res;
2142}
2143
2144/*
2145        Funciones sobre la pila de ejecuci�trabajan sobre las listas
2146        del tope y subtope de la pila
2147*/
2148
2149
2150/* logical or. */
2151#if CICPP
2152void CIB7 :: b7_zorx()
2153#else
2154void b7_zorx(cib7p)
2155b7_CIB7 *cib7p;
2156#endif
2157{
2158/*
2159        recorrer las 2 listas de posting y crear una nueva
2160        almacenando ordenadamente los postings distintos entre si
2161        comparandolos en el nivel del resultado.
2162 */
2163        char *op1, *op2, *cur, *lp;
2164   int reslen, oplen;
2165   int iop1, iop2;
2166   int cmpf;
2167   PDLSTRU *pdlp;
2168   LONGX offset;
2169
2170   LONGX mfnx, lmfn;
2171
2172   iop1 = vpdltop - 2;
2173   iop2 = vpdltop - 1;
2174
2175   pdlp = vpdlp[ vpdltop ];
2176
2177   op1 = (char *)VPDLlvel( iop1 );
2178   op2 = (char *)VPDLlvel( iop2 );
2179
2180   reslen = PDLplen;
2181   oplen = VPDLplen( iop1 );
2182
2183   lmfn = 0;
2184
2185   lp=NULL;
2186   while( op1 != VPDLnxtp( iop1 ) || op2 != VPDLnxtp( iop2 ) ){
2187
2188        if( op1 == VPDLnxtp( iop1 ) ){
2189        cur = op2;
2190         op2 += oplen;
2191      }else if( op2 == VPDLnxtp( iop2 ) ){
2192        cur = op1;
2193         op1 += oplen;
2194      }else{
2195         cmpf = b7_cmp( B7_THISP op1, op2, oplen );
2196
2197         if( cmpf <= 0 ){
2198            cur = op1;
2199            op1 += oplen;
2200            if( !cmpf ){
2201               op2 += oplen;
2202            }
2203         }else{
2204            cur = op2;
2205            op2 += oplen;
2206         }
2207      }
2208
2209          /*cur esta en el menor de los posting restantes. */
2210      mfnx = b7_gmfn( B7_THISP cur );
2211
2212      if( ( !PDLdocs || ( b7_cmp( B7_THISP cur, lp, reslen ) ) != 0  ) ){
2213                  /*no hemos almacenado ninguno o cur apunta a un posting */
2214                  /*distinto del �o almacenado. */
2215
2216         if( PDLplen ){
2217            b7_copy( B7_THISP pdlp, cur );
2218         }else{
2219            offset = (mfnx/8);
2220            mask=bitmask[mfnx&BY8RMASK];
2221            PDLlvel[offset] |= mask;
2222         }
2223         lp = cur;
2224      }
2225
2226      if( !lmfn || lmfn != mfnx ){
2227                  /*es el primer posting o */
2228                  /*tiene mfn distinta del �o almacenado. */
2229
2230         PDLdocs++;
2231         lmfn = mfnx;
2232      }
2233   }
2234
2235   /*cambiar el tope de la pila con el 3er nivel. */
2236   b7_xpdl( B7_THISP npdls-1, npdls-3);
2237   b7_pop(B7_THIS);
2238   b7_pop(B7_THIS);
2239
2240}
2241
2242/*logical and, oper (G) and oper (F) */
2243#if CICPP
2244void CIB7::b7_zand( short andl )
2245#else
2246void b7_zand( cib7p, andl )
2247b7_CIB7 *cib7p;
2248short andl;     /* 1: *; 2: (G); 3: (F) */
2249#endif
2250{
2251/*
2252        recorrer las 2 listas hasta qeu una de ellas termine,
2253        creanndo una nueva con los posting qeu se encuentran en ambas.
2254 */
2255        char *op1, *op2, *cur, *lp;
2256   int reslen, oplen, andlen;
2257   int iop1, iop2;
2258   int cmpf;
2259   PDLSTRU *pdlp;
2260   LONGX offset;
2261
2262   LONGX mfnx, lmfn;
2263
2264   iop1 = vpdltop - 2;
2265   iop2 = vpdltop - 1;
2266
2267   pdlp = vpdlp[ vpdltop ];
2268
2269   op1 = (char *)VPDLlvel( iop1 );
2270   op2 = (char *)VPDLlvel( iop2 );
2271
2272   reslen = PDLplen;
2273   oplen = VPDLplen( iop1 );
2274
2275   switch( andl ){
2276        case 2: andlen = 5; break;
2277        case 3: andlen = 6; break;
2278      default: andlen = 3;
2279   }
2280
2281   lmfn = 0;
2282   lp = 0;
2283
2284
2285   while( op1 != VPDLnxtp( iop1 ) && op2 != VPDLnxtp( iop2 ) ){
2286
2287        cur = 0;
2288        cmpf = b7_cmp( B7_THISP op1, op2, andlen );
2289      if( cmpf < 0 ){
2290        if( lp && !b7_cmp( B7_THISP op1, lp, andlen ) ){
2291                cur = op1;
2292         }
2293        op1 += oplen;
2294      }else if( cmpf > 0 ){
2295        if( lp && !b7_cmp( B7_THISP op2, lp, andlen ) ){
2296                cur = op2;
2297         }
2298        op2 += oplen;
2299      }else{
2300         cmpf = b7_cmp( B7_THISP op1, op2, oplen );
2301         if( cmpf <= 0 ){
2302                cur = op1;
2303            op1 += oplen;
2304            if( !cmpf )
2305                op2 += oplen;
2306         }else{
2307                cur = op2;
2308            op2 += oplen;
2309         }
2310      }
2311
2312      if( cur ){
2313         mfnx = b7_gmfn( B7_THISP cur );
2314
2315         if( !PDLdocs || ( b7_cmp( B7_THISP cur, lp, reslen ) ) != 0 ){
2316
2317            if( PDLplen ){
2318               b7_copy( B7_THISP pdlp, cur );
2319            }else{
2320               offset = (mfnx/8);
2321               mask=bitmask[mfnx&BY8RMASK];
2322               PDLlvel[offset] |= mask;
2323            }
2324            lp = cur;
2325         }
2326
2327         if( !lmfn || lmfn != mfnx ){
2328            PDLdocs++;
2329            lmfn = mfnx;
2330         }
2331      }
2332   }
2333
2334   b7_xpdl( B7_THISP npdls-1, npdls-3);
2335   b7_pop(B7_THIS);
2336   b7_pop(B7_THIS);
2337
2338
2339}
2340
2341/*logical not. */
2342#if CICPP
2343void CIB7::b7_zann()
2344#else
2345void b7_zann( cib7p )
2346b7_CIB7 *cib7p;
2347#endif
2348{
2349
2350/*
2351        Por cada elemento de la lista 1, incluirlo en la lista de resultados
2352        sino se encuentra en la lista 2.
2353 */
2354
2355        char *op1, *op2, *cur, *lp, *tmp;
2356   int reslen, oplen;
2357   int iop1, iop2;
2358   int cmpf;
2359   PDLSTRU *pdlp;
2360   LONGX offset;
2361
2362   LONGX mfnx, lmfn;
2363
2364   iop1 = vpdltop - 2;
2365   iop2 = vpdltop - 1;
2366
2367   pdlp = vpdlp[ vpdltop ];
2368
2369   op1 = (char *)VPDLlvel( iop1 );
2370   op2 = (char *)VPDLlvel( iop2 );
2371
2372   reslen = PDLplen;
2373   oplen = VPDLplen( iop1 );
2374
2375
2376   lp=NULL; lmfn=0;
2377   while( op1 != VPDLnxtp( iop1 ) ){
2378        cur = 0;
2379        cmpf = b7_cmp( B7_THISP op1, op2, 3 );
2380      if( cmpf < 0 ){
2381        cur = op1;
2382         op1 += oplen;
2383      }else if( cmpf > 0 ){
2384        op2 += oplen;
2385      }else{
2386        tmp = op1;
2387         while( !b7_cmp( B7_THISP tmp, op1, 3 ) )
2388                op1 += oplen;
2389
2390         tmp = op2;
2391         while( !b7_cmp( B7_THISP tmp, op2, 3 ) )
2392                op2 += oplen;
2393      }
2394
2395      if( cur ){
2396         mfnx = b7_gmfn( B7_THISP cur );
2397
2398         if( !PDLdocs || ( b7_cmp( B7_THISP cur, lp, reslen ) ) != 0 ){
2399
2400            if( PDLplen ){
2401               b7_copy( B7_THISP pdlp, cur );
2402            }else{
2403               offset = (mfnx/8);
2404               mask=bitmask[mfnx&BY8RMASK];
2405               PDLlvel[offset] |= mask;
2406            }
2407            lp = cur;
2408         }
2409
2410         if( !lmfn || lmfn != mfnx ){
2411            PDLdocs++;
2412            lmfn = mfnx;
2413         }
2414      }
2415
2416   }
2417
2418
2419   b7_xpdl( B7_THISP npdls-1, npdls-3);
2420   b7_pop(B7_THIS);
2421   b7_pop(B7_THIS);
2422
2423
2424}
2425
2426/*proximidad. */
2427#if CICPP
2428void CIB7::b7_zanp( short andl, unsigned char b7qty )
2429#else
2430void b7_zanp( cib7p,andl,b7qty )
2431b7_CIB7 *cib7p;
2432short andl;     /*4: .; 5: $ */ 
2433unsigned char b7qty;
2434#endif
2435{
2436/*
2437        Por cada elemento de la lista 1
2438                si existe elemento en la lista 2 que cumpla condicion de proximidad
2439                        adicionarlos a ambos en el resultado ( si son distintos en el nivel del resultado )
2440 */
2441        char *op1, *op2, *lp;
2442   int oplen;
2443   int iop1, iop2;
2444   int cmpf;
2445   PDLSTRU *pdlp;
2446   LONGX offset;
2447
2448   LONGX mfnx, lmfn;
2449   short dist;
2450
2451//HB   dist = atoi((const char *) &b7qty );
2452   dist = (short)b7qty;
2453
2454   iop1 = vpdltop - 2;
2455   iop2 = vpdltop - 1;
2456
2457   pdlp = vpdlp[ vpdltop ];
2458
2459   op1 = (char *)VPDLlvel( iop1 );
2460   op2 = (char *)VPDLlvel( iop2 );
2461
2462   oplen = VPDLplen( iop1 );
2463
2464   lmfn = 0;
2465   lp = 0;
2466
2467   while( op1 != VPDLnxtp( iop1 ) ){
2468        cmpf = b7_cmp( B7_THISP op1, op2, 6 );
2469      if( cmpf < 0 ){
2470        op1 += oplen;
2471        op2 = (char *)VPDLlvel( iop2 );
2472      }else if( cmpf > 0 ){
2473        op2 += oplen;
2474      }else{
2475         if( b7_prox( B7_THISP op1, op2, andl, dist) ){
2476                mfnx = b7_gmfn( B7_THISP op1 );
2477                if( !PDLplen ){
2478               offset = (mfnx/8);
2479               mask=bitmask[mfnx&BY8RMASK];
2480               PDLlvel[offset] |= mask;
2481            }else if( PDLplen < 7 ){
2482               if( !lp || b7_cmp( B7_THISP op1, lp, PDLplen ) ){
2483                  b7_copy( B7_THISP pdlp, op1 );
2484                  lp = op1;
2485               }
2486            }else{
2487                        cmpf = b7_cmp( B7_THISP op1, op2, PDLplen );
2488               if( cmpf <= 0 ){
2489                  b7_inst( B7_THISP pdlp, op1 );
2490                  b7_inst( B7_THISP pdlp, op2 );
2491                  if( !lp || b7_cmp( B7_THISP op2, lp, PDLplen ) > 0 )
2492                        lp = op2;
2493               }else{
2494                  b7_inst( B7_THISP pdlp, op2 );
2495                  b7_inst( B7_THISP pdlp, op1 );
2496                  if( !lp || b7_cmp( B7_THISP op1, lp, PDLplen ) > 0 )
2497                        lp = op1;
2498               }
2499            }
2500            if( !lmfn || lmfn != mfnx ){
2501               PDLdocs++;
2502               lmfn = mfnx;
2503            }
2504         }
2505                        op2 += oplen;
2506      }
2507   }
2508   b7_xpdl( B7_THISP npdls-1, npdls-3);
2509   b7_pop(B7_THIS);
2510   b7_pop(B7_THIS);
2511
2512}
2513
2514
2515#if CICPP
2516void CIB7::b7_copy( PDLSTRU *pdlp, char *src )
2517#else
2518void b7_copy(cib7p,pdlp,src )
2519b7_CIB7 *cib7p;
2520PDLSTRU *pdlp;
2521char *src;
2522#endif
2523{
2524/*
2525        adicionar un posting en el pdllvel del pdlp, siempre al final.
2526 */
2527
2528        LONGX offset;
2529   if( !PDLleft ){
2530#if BEFORE20020319         
2531          offset = (UCHR *)PDLnxtp - PDLlvel;
2532      PDLlvel = (unsigned char *)realloc( PDLlvel, PDLsize+PDLisiz );
2533      if( !PDLlvel )
2534         fatal( "cib72/b7_copy/realloc" );
2535
2536      PDLsize += PDLisiz;
2537      PDLnxtp = (char *)(PDLlvel+offset);
2538      memset( PDLnxtp, 0x00, PDLisiz );
2539#else
2540        UCHR *newlvel;
2541
2542/*
2543        offset = (UCHR *)PDLnxtp - PDLlvel;
2544*/
2545        offset = PDLsize;
2546
2547#if CICPP
2548        newlvel = (UCHR*)new char[(ALLOPARM)(PDLsize+PDLisiz)];
2549#else /* CICPP */
2550        newlvel = (UCHR*)ALLOC((ALLOPARM)(PDLsize+PDLisiz));
2551#endif /* CICPP */
2552        if( !newlvel )
2553                fatal( "cib72/b7_addk/realloc" );
2554        memset( newlvel, 0x00, PDLsize+PDLisiz );
2555        memcpy( newlvel, PDLlvel, PDLsize );
2556#if CICPP
2557    delete[] PDLlvel;
2558#else /* CICPP */
2559        FREE( PDLlvel );
2560#endif /* CICPP */
2561        PDLlvel = newlvel;
2562        PDLsize += PDLisiz;
2563        PDLnxtp = (char *)(PDLlvel+offset);
2564        PDLleft = PDLisiz;
2565#endif
2566   }
2567
2568   memcpy( PDLnxtp, src, PDLplen );
2569
2570   PDLleft-= PDLplen;
2571   PDLnxtp += PDLplen;
2572}
2573
2574#if CICPP
2575void CIB7::b7_inst( PDLSTRU *pdlp, char *src )
2576#else
2577void b7_inst( cib7p,pdlp,src )
2578b7_CIB7 *cib7p;
2579PDLSTRU *pdlp;
2580char *src;
2581#endif
2582{
2583/*
2584        Adicionar un posting en el pdllvel del pdlp, pero ordenado.
2585 */
2586
2587        LONGX offset;
2588   char *cur;
2589
2590   if( PDLlvel == (unsigned char *)PDLnxtp ){
2591        b7_copy( B7_THISP pdlp, src );
2592      return;
2593   }
2594
2595   if( !PDLleft ){
2596#if BEFORE20020319
2597          offset = (UCHR *)PDLnxtp - PDLlvel;
2598      PDLlvel = (unsigned char *)realloc( PDLlvel, PDLsize+PDLisiz );
2599      if( !PDLlvel )
2600         fatal( "cib72/b7_copy/realloc" );
2601
2602      PDLsize += PDLisiz;
2603      PDLnxtp = (char *)(PDLlvel+offset);
2604      memset( PDLnxtp, 0x00, PDLisiz );
2605#else
2606        UCHR *newlvel;
2607
2608/*
2609        offset = (UCHR *)PDLnxtp - PDLlvel;
2610*/
2611        offset = PDLsize;
2612
2613#if CICPP
2614        newlvel = (UCHR*)new char[(ALLOPARM)(PDLsize+PDLisiz)];
2615#else /* CICPP */
2616        newlvel = (UCHR*)ALLOC((ALLOPARM)(PDLsize+PDLisiz));
2617#endif /* CICPP */
2618        if( !newlvel )
2619                fatal( "cib72/b7_addk/realloc" );
2620        memset( newlvel, 0x00, PDLsize+PDLisiz );
2621        memcpy( newlvel, PDLlvel, PDLsize );
2622#if CICPP
2623    delete[] PDLlvel;
2624#else /* CICPP */
2625        FREE( PDLlvel );
2626#endif /* CICPP */
2627        PDLlvel = newlvel;
2628        PDLsize += PDLisiz;
2629        PDLnxtp = (char *)(PDLlvel+offset);
2630        PDLleft = PDLisiz;
2631#endif
2632   }
2633
2634   cur = PDLnxtp;
2635
2636   while( cur-PDLplen != (char *)PDLlvel && b7_cmp( B7_THISP cur-PDLplen, src, PDLplen ) > 0 ){
2637      cur -= PDLplen;
2638   }
2639
2640   if( !b7_cmp( B7_THISP cur-PDLplen, src, PDLplen ) )
2641      return;
2642
2643   if( cur != PDLnxtp )
2644        memmove( cur, cur+PDLplen, PDLnxtp-cur );
2645
2646   memcpy( cur, src, PDLplen );
2647
2648   PDLleft-=PDLplen;
2649   PDLnxtp += PDLplen;
2650}
2651
2652#if CICPP
2653void CIB7::b7_addk( PDLSTRU *pdlp, TRMSTRU *trmp )
2654#else
2655void b7_addk( cib7p,pdlp,trmp )
2656b7_CIB7 *cib7p;
2657PDLSTRU *pdlp;
2658TRMSTRU *trmp;
2659#endif
2660{
2661/*
2662        Adicionar un posting al final del pdllvel del pdlp,
2663        partiendo de la informaci�el trmp.
2664 */
2665
2666        LONGX offset;
2667   char *p;
2668   LONGX pmfn;
2669   UWORD ptag, pocc, pcnt;
2670
2671   if( !PDLplen ) return;
2672
2673   if( !PDLleft ){
2674#if BEFORE20020319
2675          offset = (UCHR *)PDLnxtp - PDLlvel;
2676      PDLlvel = (unsigned char *)realloc( PDLlvel, PDLsize+PDLisiz );
2677      if( !PDLlvel )
2678         fatal( "cib72/b7_copy/realloc" );
2679
2680      PDLsize += PDLisiz;
2681      PDLnxtp = (char *)(PDLlvel+offset);
2682      memset( PDLnxtp, 0x00, PDLisiz );
2683#else
2684        UCHR *newlvel;
2685
2686/*
2687        offset = (UCHR *)PDLnxtp - PDLlvel;
2688*/
2689        offset = PDLsize;
2690
2691#if CICPP
2692        newlvel = (UCHR*)new char[(ALLOPARM)(PDLsize+PDLisiz)];
2693#else /* CICPP */
2694        newlvel = (UCHR*)ALLOC((ALLOPARM)(PDLsize+PDLisiz));
2695#endif /* CICPP */
2696        if( !newlvel )
2697                fatal( "cib72/b7_addk/realloc" );
2698        memset( newlvel, 0x00, PDLsize+PDLisiz );
2699        memcpy( newlvel, PDLlvel, PDLsize );
2700#if CICPP
2701    delete[] PDLlvel;
2702#else /* CICPP */
2703        FREE( PDLlvel );
2704#endif /* CICPP */
2705        PDLlvel = newlvel;
2706        PDLsize += PDLisiz;
2707        PDLnxtp = (char *)(PDLlvel+offset);
2708        PDLleft = PDLisiz;
2709#endif
2710   }
2711
2712   p = PDLnxtp;
2713
2714   pmfn = TRMpmfn;
2715
2716   *p= (pmfn>>16)&0xFF;
2717   *(p+1)=(pmfn>>8)&0xFF;
2718   *(p+2)= (pmfn)&0xFF;
2719
2720
2721   ptag = TRMptag;
2722
2723   p += 3;
2724   *p = (ptag>>8)&0xFF;
2725   *(p+1)=ptag & 0xFF;
2726
2727
2728   if( PDLplen > 5 ){
2729           pocc = TRMpocc;
2730           p+=2;
2731      *p = pocc;
2732   }
2733
2734   if( PDLplen > 6 ){
2735           pcnt = TRMpcnt;
2736      p+=1;
2737      *p = (pcnt>>8)&0xFF;
2738      *(p+1) = pcnt & 0xFF;
2739   }
2740
2741   PDLleft-=PDLplen;
2742   PDLnxtp += PDLplen;
2743
2744}
2745
2746#endif /* !LIND */
2747
2748/*utilidades para mostrar el contenido de la pila de ejecuci�/
2749#if CICPP
2750void CIB7::b7_print( char *str, short int len )
2751#else
2752void b7_print( cib7p,str, len )
2753b7_CIB7 *cib7p;
2754char *str;
2755short int len;
2756#endif
2757{
2758   LONGX val;
2759
2760   val=(unsigned char)*str;
2761   val=(val<<16)+(*(str+1)<<8)+(unsigned char)(*(str+2));
2762
2763   printf( "mfn: %u", val );
2764
2765   val=(unsigned char)*(str+3);
2766   val=(val<<8)+(unsigned char)(*(str+4));
2767   printf( ", tag: %u", val );
2768
2769   if( len > 5 ){
2770        val = (unsigned char)*(str+5);
2771        printf( ", occ: %u", val );
2772   }
2773
2774   if( len > 6 ){
2775      val=(unsigned char)*(str+6);
2776      val=(val<<8)+(unsigned char)(*(str+7));
2777      printf( ", cnt: %u", val );
2778   }
2779
2780}
2781
2782#if CICPP
2783void CIB7::b7_showpdl()
2784#else
2785void b7_showpdl( cib7p )
2786b7_CIB7 *cib7p;
2787#endif
2788{
2789        LONGX i;
2790   PDLSTRU *pdlp;
2791   char *str;
2792   LONGX mfn, offset, hits;
2793
2794   printf( "%d levels\n", npdls );
2795
2796   for( i = 0; i < npdls; i++ ){
2797        pdlp = vpdlp[i];
2798        printf( "\tlevel:%i\n", i );
2799      printf( "lvel: %d, nxtp: %d\n", (int)PDLlvel, PDLnxtp );
2800      printf( "size: %d, plen: %d,docs: %d, lvel:\n", PDLsize, PDLplen, PDLdocs );
2801      if( PDLplen ){
2802         str = (char *)PDLlvel;
2803         while( str != PDLnxtp ){
2804            b7_print( B7_THISP str, PDLplen );
2805            str += PDLplen;
2806            printf( "\n" );
2807         }
2808      }else{
2809        for( mfn=1, hits=0; mfn<=PDLlmfn && hits < PDLdocs; mfn++ ){
2810            offset = (mfn/8);
2811            mask=bitmask[mfn&BY8RMASK];
2812            if( PDLlvel[offset] & mask ){
2813               printf( "%d | ", mfn );
2814               hits++;
2815            }
2816         }
2817      }
2818      printf( "\n" );
2819   }
2820   fflush( stdout );
2821
2822}
2823
2824#if CICPP
2825CIB7::CIB7(CISISX *parm_cisisxp) {
2826   cisisxp = parm_cisisxp;
2827
2828   b70trace=0;        /* ja' esta' inicializada em cidbx/cisisx */
2829   and2gf=0;          /* AOT&RP 28/05/98 */
2830   subst_and=NULL; /* RP 29/05/98 */
2831   b7_gidbnp=NULL;   /* dbn.par */
2832   b7fd=0;        /* open() - 06/03/95 */
2833   b7bufferp = NULL;    /* b7_run() processing buffer */
2834   b7_pfxmdl=0;
2835   b7error=0;
2836   b7rootmsg=OFF;
2837}
2838#endif
Note: See TracBrowser for help on using the browser.