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

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

Criação do svn para Cisis.

Line 
1#include <stdio.h>
2#include <string.h>
3#include <ctype.h>
4
5#include "cisis.h"
6#include "ciupi.h"
7#if TRACEhh
8void print_head(IFPSTRU *p,INFO off);
9#endif
10
11#if CICPP
12#include <cidbx.hpp>
13#include <citrm.hpp>
14#include <cirun.hpp>
15#endif /* CICPP */
16
17#define CONVERTE    0 /* <========== ver quando (e porque!) foi inserido */
18#define TRCTRACE    0
19#define TRNTRACE    0
20#define UNITRACE    0
21#define TRLTRACE    0
22#define TRPTRACE    0
23#define TRPTRAC2    0 /* sindo */
24#define TR0TRACE    0
25
26
27#if CICPP
28int cntwrit(DBXSTRU *dbxp)
29#else /*CICPP*/
30int cntwrit(dbxp)                           /*
31------------
32            grava .cnt;
33            retorna RCNORMAL ou abenda;
34                                    */
35DBXSTRU *dbxp;           /* ptr descritor da base de dados */
36#endif /*CICPP*/
37{
38    INVMAP *invp;
39    int fd,treecase;
40    char *unip;
41    int unin;
42
43#if CICPP
44    CISISX *cisisxp = dbxp->cisisxp;
45#endif /* CICPP */
46
47    if (!dbxp) fatal("cntwrit/dbxp");
48    invp=DBXifmap;
49    if (!invp) fatal("cntwrit/invp");
50    if ((fd=invp->cnopn) <= 0 || !invp->cnopw)
51        fd=dbxopenw(DBXname,DBXname,cx1extp,&invp->cnopn,&invp->cnopw,"cntwrit/cnopn/w");
52
53    if (fd <= 0) fatal("cntwrit/fd");
54    if (LSEEK64(fd,0L,SEEK_SET) != 0L)
55        fatal("cntwrit/seek");
56
57    for (treecase=0; treecase < 2; treecase++) {
58#if TRCTRACE
59printf("cntwrit - cnt[%d] \n",treecase);
60#endif
61#if CNV_PCFILES
62        unin=CNBSIZ-CNBUNI;
63#else
64        unin=CNBSIZ;
65#endif
66#if CNV_PCBINUM
67        memcpy(cnv_pcbuff,(char *)&invp->cn[treecase],CNBSIZ);
68        ConvertCNT_REC(cnv_pcbuff);
69        unip=cnv_pcbuff;
70#else
71        unip=(char *)&invp->cn[treecase];
72#endif
73        if (CIWRITE(fd,unip,unin) != unin) fatal("cntwrit/writ");
74    }
75#if TRCTRACE
76printf("cntwrit - ok \n");
77#endif
78    return(RCNORMAL);
79}
80
81
82#if CICPP
83int nodewrit(DBXSTRU *dbxp,
84             N0STRU  *n0p,
85             int      level,
86             int      isroot)
87#else /*CICPP*/
88int nodewrit(dbxp,n0p,level,isroot)                                   /*
89------------
90            grava No';
91            grava .cnt se necessario
92            retorna RCNORMAL ou abenda;
93                                                                      */
94DBXSTRU *dbxp;      /* ptr descritor da base de dados */
95N0STRU *n0p;        /* ptr No' a gravar */
96int level;          /* nivel da arvore a gravar */
97int isroot;         /* root node indicator */
98#endif /*CICPP*/
99{
100    INVMAP *invp;       /* ptr descritor do inverted file */
101    int treecase,n,nodesize,fd,upcnt;
102    off_t xbytes;
103    PUNT punt;
104#if CNV_PCFILES
105    N0STRU *unp;
106    N1STRU *n1p;
107    N2STRU *n2p;
108    char *up;
109#if UNITRACE
110    int i;
111#endif
112#endif
113
114#if CICPP
115    CISISX *cisisxp = dbxp->cisisxp;
116#endif /* CICPP */
117
118#if TRNTRACE
119printf("nodewrit - dbxp=%p (%s)  n0p=%p  level=%d  isroot=%d\n",
120 dbxp,DBXname,n0p,level,isroot);
121#endif
122    invp=DBXifmap;
123    treecase = n0p->it - 1;
124    punt = n0p->pos;
125    if (invp->nybasep[treecase]) fatal("nodewrit/CNLI/nybasep");
126    if (n0p->ock < 1 || n0p->ock > TWORDN) fatal("nodewrit/ock");
127    if (punt < 1 || punt > invp->cn[treecase].nmaxpos)
128        if (punt != invp->cn[treecase].nmaxpos + 1) fatal("nodewrit/pos");
129    if (level < 0 || level > invp->cn[treecase].liv + 1)
130        fatal("nodewrit/level");
131
132#if LINDLUX
133    if (invp->ltxthresh) {
134        /* alloc */
135        if (punt > invp->ltxpages[treecase]) {
136            if (punt != invp->ltxpages[treecase]+1) fatal("nodewrit/ltx/punt");
137            if (punt > LUXPAGES) fatal("nodewrit/ltx/overflow");
138            if (invp->ltxvpagp[treecase][punt]) fatal("nodewrit/ltx/again");
139            invp->ltxvpagp[treecase][punt]=
140                                (N0STRU *)ALLOC((ALLOPARM)nxbsiz[treecase]);
141            if (invp->ltxvpagp[treecase][punt] == (N0STRU *)ALLONULL)
142                                                fatal("nodewrit/ltx/ALLOC");
143            invp->ltxpages[treecase]++;
144        }
145        /* copy */
146        memcpy(invp->ltxvpagp[treecase][punt],(char *)n0p,nxbsiz[treecase]);
147    }
148    else { /* else if invp->ltxthresh */
149#endif /* LINDLUX */
150
151    if (treecase) {
152        nodesize=N2BSIZ;
153        if ((fd=invp->n2opn) <= 0 || !invp->n2opw) {
154            fd=dbxopenw(DBXname,DBXname,nx12extp[treecase],&invp->n2opn,&invp->n2opw,"nodewrit/n2opn/w");
155        }
156    }
157    else {
158        nodesize=N1BSIZ;
159        if ((fd=invp->n1opn) <= 0 || !invp->n1opw) {
160            fd=dbxopenw(DBXname,DBXname,nx12extp[treecase],&invp->n1opn,&invp->n1opw,"nodewrit/n1opn/w");
161        }
162    }
163    if (fd <= 0) fatal("nodewrit/fd");
164#if TRNTRACE
165printf("nodewrit - invp=%p  treecase=%d  punt=%ld  liv=%d\n",
166    invp,treecase,(LONGX)punt,invp->cn[treecase].liv);
167#endif
168
169    for (n=0; n <= invp->cn[treecase].liv; n++) {
170#if TRNTRACE
171printf("nodewrit - left=%d por pages=%d total=%d\n",
172    invp->nx[treecase][n].left,invp->nx[treecase][n].pages,
173    invp->nx[treecase][n].pages);
174#endif
175#if BEFORE950308
176        invp->nx[treecase][n].left = invp->nx[treecase][n].pages;
177#else
178        /* left=pages ==> 0 loaded */
179        invp->nx[treecase][n].left = invp->nx[treecase][n].pages;
180        /* but if level is ok, copy it to nx[] */
181#endif
182    }
183
184#if CNV_PCFILES
185    nodesize-=(treecase)?TWORDN*N2BUNI:TWORDN*N1BUNI;
186#endif
187    xbytes=((off_t)(punt-1L))*nodesize;
188#if CNLI
189    if (invp->cn_offset[treecase]) fatal("nodewrit/CNLI/cn_offset");
190#endif
191#if TRNTRACE
192printf("nodewrit - xbytes=%"P_OFF_T" nodesize=%d \n",(LONG_LONG)xbytes,nodesize);
193#endif
194    if (LSEEK64(fd,xbytes,SEEK_SET) != xbytes) fatal("nodewrit/seek");
195
196#if CNV_PCFILES
197#if UNITRACE
198 n1p=(N1STRU *)n0p;
199 n2p=(N2STRU *)n0p;
200 if (treecase) {
201 printf("pos=%4ld  ock=%2d  it=%d  '%.30s'\n",
202 n2p->pos,n2p->ock,n2p->it,n2p->idx[0].key);
203     getchar();
204 for (i=0;i<n2p->ock;i++)
205  printf("i=%2d  ock=%2d  '%.30s'  punt=%ld\n",
206    i+1,n2p->ock,n2p->idx[i].key,
207    n2p->idx[i].punt);
208 } else {
209  printf("pos=%4ld  ock=%2d  it=%d  '%.10s'\n",
210   n1p->pos,n1p->ock,n1p->it,n1p->idx[0].key);
211      getchar();
212  for (i=0;i<n1p->ock;i++)
213   printf("i=%2d  ock=%2d  '%.10s'  punt=%ld\n",
214    i+1,n1p->ock,n1p->idx[i].key,
215    n1p->idx[i].punt);
216 }
217#endif /* UNITRACE */
218    unp=(N0STRU *)nodeunibuff;
219    unp->pos=n0p->pos;
220    unp->ock=n0p->ock;
221    unp->it=n0p->it;
222    n1p=(N1STRU *)n0p;
223    n2p=(N2STRU *)n0p;
224    up=unp->idxchars;
225    for (n=0; n < TWORDN; n++, up+=sizeof(PUNT))
226        if (treecase) {
227            memcpy(up,n2p->idx[n].key,LE2); up+=LE2;
228            memcpy(up,&(n2p->idx[n].punt),sizeof(PUNT));
229        }
230        else {
231            memcpy(up,n1p->idx[n].key,LE1); up+=LE1;
232            memcpy(up,&(n1p->idx[n].punt),sizeof(PUNT));
233        }
234#if CNV_PCBINUM
235    if (treecase) ConvertN02_REC(nodeunibuff);
236             else ConvertN01_REC(nodeunibuff);
237#endif
238    if (CIWRITE(fd,nodeunibuff,nodesize) != nodesize)
239        fatal("nodewrit/writ");
240#else /* CNV_PCFILES */
241#if CNV_PCBINUM
242    memcpy(cnv_pcbuff,(char *)n0p,nodesize);
243    if (treecase) ConvertN02_REC(cnv_pcbuff);
244             else ConvertN01_REC(cnv_pcbuff);
245    if (CIWRITE(fd,cnv_pcbuff,nodesize) != nodesize)
246        fatal("nodewrit/writ");
247#else
248    if (CIWRITE(fd,(char *)n0p,nodesize) != nodesize)
249        fatal("nodewrit/writ");
250#endif
251#endif /* CNV_PCFILES */
252
253#if LINDLUX
254    } /* end if invp->ltxthresh */
255#endif /* LINDLUX */
256    /* Update .cnt in memory */
257    upcnt=0;
258    if (punt > invp->cn[treecase].nmaxpos) {
259        invp->cn[treecase].nmaxpos = punt;
260        upcnt=1;
261    }
262    if (level > invp->cn[treecase].liv) {
263        invp->cn[treecase].liv = level;
264        upcnt=1;
265    }
266    if (isroot) {
267        if (invp->cn[treecase].abnormal == ABNORMAL)
268#if BEFORE950627
269            if (punt > 1) {
270#else
271            /* gdb resets ABNORMAL when root has ORDN keys */
272            if (punt > 1 || (punt == 1 && n0p->ock >= ORDN)) {
273#endif
274                invp->cn[treecase].abnormal = ABNORMAL+1;   /* NORMAL */
275                upcnt=1;
276            }
277        if (invp->cn[treecase].posrx != punt) {
278            invp->cn[treecase].posrx = punt;
279            upcnt=1;
280        }
281    }
282    /* Update .cnt file */
283    if (upcnt)
284        if (trmifupd == IFUPDXUP) cntwrit(dbxp);
285#if TRNTRACE
286printf("nodewrit - ok \n");
287#endif
288    return(RCNORMAL);
289}
290
291
292#if CICPP
293int leafwrit(DBXSTRU *dbxp,
294             L0STRU  *l0p)
295#else /*CICPP*/
296int leafwrit(dbxp,l0p)                                                /*
297------------
298            grava Folha;
299            grava .cnt se necessario
300            retorna RCNORMAL ou abenda;
301                                                                      */
302DBXSTRU *dbxp;      /* ptr descritor da base de dados */
303L0STRU *l0p;        /* ptr folha a gravar */
304#endif /*CICPP*/
305{
306    INVMAP *invp;       /* ptr descritor do inverted file */
307    int treecase;
308    PUNT punt;
309    int lbufsiz,fd;
310    off_t xbytes;
311
312#if CICPP
313    CISISX *cisisxp = dbxp->cisisxp;
314#endif /* CICPP */
315
316#if TRLTRACE
317printf("leafwrit - dbxp=%p (%s)  l0p=%p \n",dbxp,DBXname,l0p);
318#endif
319    invp=DBXifmap;
320    treecase = l0p->it - 1;
321    punt = l0p->pos;
322    if (invp->lybasep[treecase]) fatal("leafwrit/CNLI");
323    if (l0p->ock < 1 || l0p->ock > TWORDF) fatal("leafwrit/ock");
324    if (punt < 1 || punt > invp->cn[treecase].fmaxpos)
325        if (punt != invp->cn[treecase].fmaxpos + 1) fatal("leafwrit/pos");
326#if LINDLUX
327    if (invp->luxthresh) {
328        /* alloc */
329        if (punt > invp->luxpages[treecase]) {
330            if (punt != invp->luxpages[treecase]+1) fatal("leafwrit/lux/punt");
331            if (punt > LUXPAGES) fatal("leafwrit/lux/overflow");
332            if (invp->luxvpagp[treecase][punt]) fatal("leafwrit/lux/again");
333            invp->luxvpagp[treecase][punt]=
334                                (L0STRU *)ALLOC((ALLOPARM)lxbsiz[treecase]);
335            if (invp->luxvpagp[treecase][punt] == (L0STRU *)ALLONULL)
336                                                fatal("leafwrit/lux/ALLOC");
337            invp->luxpages[treecase]++;
338        }
339        /* copy */
340        memcpy(invp->luxvpagp[treecase][punt],(char *)l0p,lxbsiz[treecase]);
341        /* Update .cnt */
342        if (punt > invp->cn[treecase].fmaxpos) {
343            invp->cn[treecase].fmaxpos = punt;
344            if (trmifupd == IFUPDXUP) cntwrit(dbxp);
345        }
346        return(RCNORMAL);
347    }
348#endif /* LINDLUX */
349    if (treecase) {
350        lbufsiz=L2BSIZ;
351        if ((fd=invp->l2opn) <= 0 || !invp->l2opw) {
352            fd=dbxopenw(DBXname,DBXname,lx12extp[treecase],&invp->l2opn,&invp->l2opw,"leafwrit/l2opn/w");
353        }
354    }
355    else {
356        lbufsiz=L1BSIZ;
357        if ((fd=invp->l1opn) <= 0 || !invp->l1opw) {
358            fd=dbxopenw(DBXname,DBXname,lx12extp[treecase],&invp->l1opn,&invp->l1opw,"leafwrit/l1opn/w");
359        }
360    }
361    if (fd <= 0) fatal("leafwrit/fd");
362#if TRLTRACE
363printf("leafwrit - invp=%p  treecase=%d  punt=%ld\n",
364    invp,treecase,(LONGX)punt);
365#endif
366    xbytes=((off_t)(punt-1L))*lbufsiz;
367#if CNLI
368    if (invp->cl_offset[treecase]) fatal("leafwrit/CNLI/cl_offset");
369#endif
370#if TRLTRACE
371printf("leafwrit - xbytes=%"P_OFF_T" lbufsiz=%d \n",(LONG_LONG)xbytes,lbufsiz);
372#endif
373
374    if (LSEEK64(fd,xbytes,SEEK_SET) != xbytes) {
375        printf("leafread - xbytes=%"P_OFF_T" punt=%ld lbufsiz=%d \n",(LONG_LONG)xbytes,(LONGX)punt, lbufsiz);           
376        printf("errno=%ld\n", (long)errno);
377        fatal("leafwrit/lseek");
378    }
379#if CNV_PCBINUM
380    memcpy(cnv_pcbuff,(char *)l0p,lbufsiz);
381    if (treecase) ConvertL02_REC(cnv_pcbuff);
382             else ConvertL01_REC(cnv_pcbuff);
383    if (CIWRITE(fd,cnv_pcbuff,lbufsiz) != lbufsiz) fatal("leafwrit/write");
384#else
385    if (CIWRITE(fd,(char *)l0p,lbufsiz) != lbufsiz) fatal("leafwrit/write");
386#endif
387    /* Update .cnt */
388    if (punt > invp->cn[treecase].fmaxpos) {
389        invp->cn[treecase].fmaxpos = punt;
390        if (trmifupd == IFUPDXUP) cntwrit(dbxp);
391    }
392#if TRLTRACE
393printf("leafwrit - ok \n");
394#endif
395    return(RCNORMAL);
396}
397
398
399#if CNV_PCBINUM
400#if CICPP
401int ifpwrit(DBXSTRU *dbxp,
402            char    *buffer,
403            LONGX     nbytes,
404            INFO     hdblk[],
405            INFO     hdoff[],
406            int      hdn)
407#else /*CICPP*/
408int ifpwrit(dbxp,buffer,nbytes,hdblk,hdoff,hdn)
409DBXSTRU *dbxp;           /* ptr descritor da base de dados */
410char *buffer;            /* ptr if post's a gravar */
411LONGX nbytes;             /* bytes contiguos a gravar  */
412INFO hdblk[];
413INFO hdoff[];
414int hdn;
415  /* hdblk,hdoff,hdn - armazenam as ocorrencias de headers de                */
416  /*                   chaves que estao em buff                              */
417  /* hdblk[i],hdoff[i] ->posicao do header i (blk,off)
418     hdn-> qtda de headers
419  */
420#endif /*CICPP*/
421#else /* CNV_PCBINUM */
422#if CICPP
423int ifpwrit(DBXSTRU *dbxp,
424            char    *buffer,
425            LONGX     nbytes)
426#else /*CICPP*/
427int ifpwrit(dbxp,buffer,nbytes)                                         /*
428------------
429            grava buffer de "nbytes/size(IFPSTRU)" blocos de postings;
430            retorna RCNORMAL ou abenda;
431                                                                        */
432DBXSTRU *dbxp;           /* ptr descritor da base de dados */
433char *buffer;            /* ptr if post's a gravar */
434LONGX nbytes;             /* bytes contiguos a gravar  */
435#endif /*CICPP*/
436#endif /* CNV_PCBINUM */
437{
438    INVMAP *invp;       /* ptr descritor do inverted file */
439    int fd;
440    unsigned int towrite;
441
442#if CICPP
443    CISISX *cisisxp = dbxp->cisisxp;
444#endif /* CICPP */
445
446#if !LIND
447    off_t xbytes;
448#endif
449#if CNV_PCBINUM
450    INFO thisblk;
451    int blk1;
452    int i;
453#endif /* CNV_PCBINUM */
454#if TRPTRACE || TRPTRAC2
455 int nn;
456 IFPSTRU *qq;
457 qq=(IFPSTRU *)buffer;
458 printf("\nifpwrit - dbxp=%p (%s)  buffer=%p  nbytes=%ld",
459 dbxp,DBXname,buffer,nbytes);
460 for (nn=nbytes;nn>0;nn=nn-IFBSIZ,qq++){
461   printf("\nifpwrit blocos existentes buffer: blk=%ld",qq->ifpblk);
462}
463#endif
464    invp=DBXifmap;
465    if ((fd=invp->ifopn) <= 0 || !invp->ifopw) {
466        fd=dbxopenw(DBXname,DBXname,ix1extp,&invp->ifopn,&invp->ifopw,"ifpwrit/ifopn/w");
467    }
468    if (fd <= 0) fatal("ifpwrit/fd");
469#if LIND
470    LSEEK64(fd,0L,SEEK_END); /* append */
471#else
472    xbytes=((off_t)(((IFPSTRU *)buffer)->ifpblk - 1L))*sizeof(IFPSTRU );
473    //if (LSEEK64(fd,xbytes,SEEK_SET) != xbytes) fatal("ifpwrit/seek");
474    if (LSEEK64(fd,xbytes,SEEK_SET) != xbytes) {
475      printf("xbytes=%"P_OFF_T" lseek=%"P_OFF_T"\n", (LONG_LONG)xbytes, (LONG_LONG)LSEEK64(fd,xbytes,SEEK_SET));
476      fatal("ifpwrit/seek");
477    }
478#endif
479    if (nbytes >= USHRT_MAX) fatal("ifpwrit/nbytes");
480    towrite=nbytes;
481#if LIND
482    if (CIWRITE(fd,buffer,towrite) != towrite)
483#else
484#if CNV_PCBINUM
485    memcpy(cnv_pcbuff,buffer,towrite);
486    blk1=0;
487    if (((IFPSTRU *)buffer)->ifpblk == 1) blk1=1;
488    for (xbytes=0; xbytes < towrite; xbytes+=IFBSIZ, blk1=0) {
489        thisblk=(INFO )((IFPSTRU *)(buffer+xbytes))->ifpblk;
490        /* extrai os headers do regitro atual */
491        for (i=0; i <= hdn; i++) { /* se 1 elem: hdn = 0 (init = -1) */
492#if TRACEhh
493      printf("this=%ld hdb[%d]=%ld hdo[%d]=%ld ", thisblk,i,hdblk[i],i,hdoff[i]);
494#endif
495            if (hdblk[i] == thisblk) {
496#if CONVERTE
497                ConvertIFP_PSTHDR(cnv_pcbuff+xbytes+hdoff[i]);
498#endif
499#if TRACEhh
500                print_head((IFPSTRU *)(cnv_pcbuff+xbytes),hdoff[i]);
501#endif
502                hdblk[i]=-hdblk[i]; /* Limpa */
503            }
504#if TRACEhh
505            else { printf("\n");}
506#endif
507        }
508#if CONVERTE
509        ConvertIFP_BLKCTL(cnv_pcbuff+xbytes,blk1);
510#endif /* CONVERTE */
511    }
512    if (CIWRITE(fd,cnv_pcbuff,towrite) != towrite)
513#else /* CNV_PCBINUM */
514    if (CIWRITE(fd,buffer,towrite) != towrite)
515#endif /* CNV_PCBINUM */
516#endif
517        fatal("ifpwrit/write");
518
519#if TRPTRACE
520printf("ifpwrit - ok \n");
521#endif
522    return(RCNORMAL);
523}
524
525
526#if CICPP
527int trmisis0(CISISX *cisisxp, char *dbnamp)
528#else /*CICPP*/
529int trmisis0(dbnamp)                                                  /*
530------------
531                    cria .cnt;
532                    cria .n0x e .l0x vazios;
533                    cria .ifp;
534                    retorna CREAT()
535                                                                      */
536char *dbnamp;       /* ptr nome bases de dados */
537#endif /*CICPP*/
538{
539    int fd;
540    char area[CIMPL+1],*p;
541    int treecase;
542    CNSTRU cntbuff[2];
543    int unin;
544#if !LIND
545    IFPSTRU ifpbuff;
546#endif
547#if MPE
548    char dcb[80];
549#endif
550
551#if TR0TRACE
552printf("trmisis0 - dbnamp=%s\n",dbnamp);
553#endif
554
555#if MULTI
556    if (dbxstorp(dbnamp)->dbxnetws != MONONETS)
557        fatal("trmisis0/MONONETS expected");
558#endif
559
560    /* .cnt */
561    strcpy(area,dbnamp);
562    strcat(area,cx1extp);
563    strcpy(area,dbxcipar(dbnamp,area,'='));
564#if TR0TRACE
565printf("trmisis0 - filename='%s'  len=%d\n",area,strlen(area));
566#endif
567#if MPE
568    sprintf(dcb,"b R%3d",sizeof(CNSTRU));
569    if ((fd=OPEN(area,
570                O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,dcb)) <= 0) {
571#else
572    if ((fd=CREAT(area,PERMIS)) <= 0) {
573#endif
574        fatal("trmisis0/cnt");
575    }
576    for (treecase=0; treecase < 2; treecase++) {
577        if (trmtrace) printf("+++ trmisis0 - %s=%d [id=%d]\n",area,fd,treecase+1);
578        cntbuff[treecase].idtype=treecase+1;
579        cntbuff[treecase].ordn=ORDN;
580        cntbuff[treecase].ordf=ORDF;
581        cntbuff[treecase].n=CNTN;
582        cntbuff[treecase].k=CNTK;
583        cntbuff[treecase].liv=NEGLIV;
584        cntbuff[treecase].posrx=0;
585        cntbuff[treecase].nmaxpos=0;
586        cntbuff[treecase].fmaxpos=0;
587        cntbuff[treecase].abnormal=ABNORMAL;
588        p=(char *)&cntbuff[treecase];
589#if CNV_PCFILES
590        unin=CNBSIZ-CNBUNI;
591#else
592        unin=CNBSIZ;
593#endif
594#if CNV_PCBINUM
595#if CONVERTE
596        ConvertCNT_REC(p); /* local */
597#endif
598#endif
599        if (CIWRITE(fd,p,unin) != unin) fatal("trmisis0/write/cnt");
600    }
601    CLOSE(fd);
602
603    /* .l01 */
604    strcpy(area,dbnamp);
605    strcat(area,lx12extp[0]);
606    strcpy(area,dbxcipar(dbnamp,area,'='));
607#if TR0TRACE
608printf("trmisis0 - filename='%s'  len=%d\n",area,strlen(area));
609#endif
610#if MPE
611    sprintf(dcb,"b R%3d",sizeof(L1STRU));
612    if ((fd=OPEN(area,
613                O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,dcb)) <= 0) {
614#else
615    if ((fd=CREAT(area,PERMIS)) <= 0) {
616#endif
617        fatal("trmisis0/.l01");
618    }
619    if (trmtrace) printf("+++ trmisis0 - %s=%d\n",area,fd);
620    CLOSE(fd);
621
622    /* .l02 */
623    strcpy(area,dbnamp);
624    strcat(area,lx12extp[1]);
625    strcpy(area,dbxcipar(dbnamp,area,'='));
626#if TR0TRACE
627printf("trmisis0 - filename='%s'  len=%d\n",area,strlen(area));
628#endif
629#if MPE
630    sprintf(dcb,"b R%3d",sizeof(L2STRU));
631    if ((fd=OPEN(area,
632                O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,dcb)) <= 0) {
633#else
634    if ((fd=CREAT(area,PERMIS)) <= 0) {
635#endif
636        fatal("trmisis0/.l02");
637    }
638    if (trmtrace) printf("+++ trmisis0 - %s=%d\n",area,fd);
639    CLOSE(fd);
640
641    /* .n01 */
642    strcpy(area,dbnamp);
643    strcat(area,nx12extp[0]);
644    strcpy(area,dbxcipar(dbnamp,area,'='));
645#if TR0TRACE
646printf("trmisis0 - filename='%s'  len=%d\n",area,strlen(area));
647#endif
648#if MPE
649    sprintf(dcb,"b R%3d",sizeof(N1STRU));
650    if ((fd=OPEN(area,
651                O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,dcb)) <= 0) {
652#else
653    if ((fd=CREAT(area,PERMIS)) <= 0) {
654#endif
655        fatal("trmisis0/.n01");
656    }
657    if (trmtrace) printf("+++ trmisis0 - %s=%d\n",area,fd);
658    CLOSE(fd);
659
660    /* .n02 */
661    strcpy(area,dbnamp);
662    strcat(area,nx12extp[1]);
663    strcpy(area,dbxcipar(dbnamp,area,'='));
664#if TR0TRACE
665printf("trmisis0 - filename='%s'  len=%d\n",area,strlen(area));
666#endif
667#if MPE
668    sprintf(dcb,"b R%3d",sizeof(N2STRU));
669    if ((fd=OPEN(area,
670                O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,dcb)) <= 0) {
671#else
672    if ((fd=CREAT(area,PERMIS)) <= 0) {
673#endif
674        fatal("trmisis0/.n02");
675    }
676    if (trmtrace) printf("+++ trmisis0 - %s=%d\n",area,fd);
677    CLOSE(fd);
678
679    /* .ifp */
680    strcpy(area,dbnamp);
681    strcat(area,ix1extp);
682    strcpy(area,dbxcipar(dbnamp,area,'='));
683#if TR0TRACE
684printf("trmisis0 - filename='%s'  len=%d\n",area,strlen(area));
685#endif
686#if MPE
687    sprintf(dcb,"b R%3d",sizeof(IFPSTRU));
688    if ((fd=OPEN(area,
689                O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,dcb)) <= 0) {
690#else
691    if ((fd=CREAT(area,PERMIS)) <= 0) {
692#endif
693        fatal("trmisis0/ifp");
694    }
695    if (trmtrace) printf("+++ trmisis0 - %s=%d\n",area,fd);
696#if !LIND
697    p=(char *)&ifpbuff;
698    memset(p,0xFF,sizeof(IFPSTRU));
699    ifpbuff.ifpblk=1L;
700    ifpbuff.ifprec[0]=1L;
701    ifpbuff.ifprec[1]=2L;
702#if CNV_PCBINUM
703#if CONVERTE
704    ConvertIFP_BLKCTL(p,1); /* local */
705#endif
706#endif
707    if (CIWRITE(fd,p,sizeof(IFPSTRU)) != sizeof(IFPSTRU)) {
708        fatal("trmisis0/write/ifp");
709    }
710#endif
711    CLOSE(fd);
712
713#if TR0TRACE
714printf("trmisis0 - ok \n");
715#endif
716    return(fd);
717}
718
719
720#if TRACEhh
721#if CICPP
722void print_head(IFPSTRU *p,
723                INFO     off)
724#else /* CICPP */
725void print_head(p,off)
726IFPSTRU *p;
727INFO off;
728#endif /* CICPP */
729{
730IFPHEAD  *ifhead;
731if (off >=0) {
732   ifhead = (IFPHEAD *) &(p->ifprec[off]);
733   printf("->Nxtb=%lu Nxtp=%lu totp=%lu segp=%lu segc=%lu\n",
734                  ifhead->ifpnxtb,ifhead->ifpnxtp,ifhead->ifptotp,
735                  ifhead->ifpsegp,ifhead->ifpsegc);
736}
737}
738#endif /*TRACEhh*/
739#if DEBIFUPD
740/*------------------------------------------------------------------------*/
741#if CICPP
742void lifp_print_cnt(INVMAP *invp)
743#else /*CICPP*/
744void lifp_print_cnt(invp)
745INVMAP *invp;
746#endif /*CICPP*/
747{ int treecase;
748printf(
749"\n-------------------------------------------------------------------------");
750printf(
751"\nTree|Type |Ordn |Ordf |N   |k   |Liv |Posrx |Nmaxpos |Fmaxpos |Abnormal|");
752printf(
753"\n----|-----|-----|-----|----|----|----|------|--------|--------|---------|");
754treecase=0;
755printf("\n%4d|%5d|%5d|%5d|%4d|%4d|%4d|%6ld|%8ld|%8ld|%9d|",
756treecase,
757invp->cn[treecase].idtype ,
758invp->cn[treecase].ordn ,
759invp->cn[treecase].ordf ,
760invp->cn[treecase].n ,
761invp->cn[treecase].k ,
762invp->cn[treecase].liv ,
763invp->cn[treecase].posrx ,
764invp->cn[treecase].nmaxpos ,
765invp->cn[treecase].fmaxpos ,
766invp->cn[treecase].abnormal);
767printf(
768"\n----|-----|-----|-----|----|----|----|------|--------|--------|---------|");
769treecase=1;
770printf("\n%4d|%5d|%5d|%5d|%4d|%4d|%4d|%6ld|%8ld|%8ld|%9d|",
771treecase,
772invp->cn[treecase].idtype ,
773invp->cn[treecase].ordn ,
774invp->cn[treecase].ordf ,
775invp->cn[treecase].n ,
776invp->cn[treecase].k ,
777invp->cn[treecase].liv ,
778invp->cn[treecase].posrx ,
779invp->cn[treecase].nmaxpos ,
780invp->cn[treecase].fmaxpos ,
781invp->cn[treecase].abnormal);
782printf(
783"\n-------------------------------------------------------------------------");
784}
785/* ------------------------------------------------------------------------*/
786#if CICPP
787void upif_chgtostr(UCHR *v,
788                   int   n,
789                   UCHR *tkey)
790#else /*CICPP*/
791void upif_chgtostr(v,n,tkey)
792UCHR *v;
793int n;
794UCHR *tkey;
795#endif /*CICPP*/
796{
797 memcpy((UCHR *)tkey,v,n);
798 tkey[n]='\0';
799}
800/* ------------------------------------------------------------------------*/
801#if CICPP
802void upif_print_node(N0STRU *n0p)
803#else /*CICPP*/
804void upif_print_node(n0p)
805N0STRU *n0p;
806#endif /*CICPP*/
807{
808  int ock,i,keysize;
809  int treecase;
810  PUNT punt;
811  N1STRU *n1p;
812  N2STRU *n2p;
813  UCHR  key[LE2+1];
814  ock=n0p->ock;
815  treecase=n0p->it-1;
816  n1p=(N1STRU *)n0p;
817  n2p=(N2STRU *)n0p;
818  keysize=vlex[treecase];
819  printf("\n  pos=%ld, ock=%d, treecase=%d",n0p->pos,ock,treecase);
820  printf("\n");
821  for (i=0;i<ock;i++){
822/*  if(i-i/4*4==0)printf("\n    "); */
823    printf("\n");
824    if (treecase == 0){
825       memcpy(key,n1p->idx[i].key,keysize);
826       punt= n1p->idx[i].punt;
827    }
828    else {
829       memcpy(key,n2p->idx[i].key,keysize);
830       punt= n2p->idx[i].punt;
831    }
832    key[keysize]='\0';
833    printf(" +++ >%s %ld ;",(char *)key,punt);
834  }
835}
836/*-------------------------------------------------------------------------*/
837#if CICPP
838void upif_print_leaf(L0STRU *l0p)
839#else /*CICPP*/
840void upif_print_leaf(l0p)
841L0STRU *l0p;
842#endif /*CICPP*/
843{ int ock,i,treecase,keysize;
844  UCHR  key[LE2+1];
845  L1STRU *l1p;
846  L2STRU *l2p;
847  INFO info1,info2;
848  ock=l0p->ock;
849  treecase=l0p->it-1;
850  keysize=vlex[treecase];
851  printf("\n pos=%ld,ock=%d,it=%d,ps=%ld",
852        l0p->pos,ock,treecase,l0p->ps );
853  ock=l0p->ock;
854  l1p=(L1STRU *)l0p;
855  l2p=(L2STRU *)l0p;
856  for (i=0;i<ock;i++){
857     if (i-i/4*4==0)printf("\n  ");
858     if (treecase == 0 ) {
859     memcpy((char *)key ,l1p->idx[i].key,keysize);
860     info1=l1p->idx[i].info1;
861     info2=l1p->idx[i].info2;
862     }
863     else {
864     memcpy((char *)key ,l2p->idx[i].key,keysize);
865     info1=l2p->idx[i].info1;
866     info2=l2p->idx[i].info2;
867     }
868     key[keysize]='\0';
869     printf("%s, %ld, %ld ;",
870        key,info1,info2);
871  }
872}
873
874/* -----------------------------------------------------------------------*/
875#if CICPP
876void upif_print_btree(INVMAP *invp,
877                      int     ident,
878                      int     level,
879                      PUNT    punt,
880                      int     treecase,
881                      FILE   *fout)
882#else /*CICPP*/
883void upif_print_btree(invp,ident,level,punt,treecase,fout)
884INVMAP *invp;
885int ident;
886int level;
887PUNT punt;
888int treecase;
889FILE *fout;
890#endif /*CICPP*/
891{
892  int ock,i;
893  UCHR  *np;
894  N2STRU *n2p, *keep_node2,area_node2;
895  N1STRU *n1p, *keep_node1,area_node1;
896  N0STRU *n0local;
897  L0STRU *l0p;
898  L1STRU *l1p;
899  L2STRU *l2p;
900  PUNT next_punt;
901  UCHR lbufp[sizeof(L2STRU)+1];
902  UCHR  key[LE2+1];
903  INFO info1, info2;
904  int keysize;
905  keep_node1=&area_node1;
906  keep_node2=&area_node2;
907  keysize=vlex[treecase];
908  if (punt==0) return;
909  if (punt<0) {
910        punt=-punt;
911    l0p=(L0STRU *)leafread(lbufp,invp,treecase,punt,0);
912    l1p=(L1STRU *)l0p;
913    l2p=(L2STRU *)l0p;
914    fprintf(fout,"\n     Leaf  punt=%ld ock=%d\n",-punt,l0p->ock);
915    for (i=0;i<l0p->ock;i++){
916      if(i-i/4*4==0) {
917        fprintf(fout,"\n");
918      }
919      if (treecase == 0 ) {
920         memcpy((char *)key ,l1p->idx[i].key,keysize);
921         info1=l1p->idx[i].info1;
922         info2=l1p->idx[i].info2;
923      }
924      else {
925          memcpy((char *)key ,l2p->idx[i].key,keysize);
926          info1=l2p->idx[i].info1;
927          info2=l2p->idx[i].info2;
928      }
929      key[keysize]='\0';
930      printf("%s, %ld, %ld ;",
931              key,info1,info2);
932    }
933        return;
934  }
935  if (punt<=0 ) return;
936  np=(UCHR *)noderead(invp,treecase,level,punt);
937  n1p=(N1STRU *)np;
938  n2p=(N2STRU *)np;
939  if (treecase == 0) {
940     memcpy((UCHR *)keep_node1,(UCHR *)np,sizeof(N1STRU));
941     n0local=(N0STRU *)keep_node1;
942     n1p=(N1STRU *)n0local;
943  }
944  else {
945     memcpy((UCHR *)keep_node2,(UCHR *)np,sizeof(N2STRU));
946     n0local=(N0STRU *)keep_node2;
947     n2p=(N2STRU *)n0local;
948  }
949  fprintf(fout,"\n");
950  for (i=0;i<ident;i++)fprintf(fout,"-");
951  fprintf(fout,"pos=%ld ock=%d type=%d",n0local->pos,
952        n0local->ock,n0local->it);
953  ock=n0local->ock;
954  upif_print_node(n0local);
955  for (i=0;i<ock;i++){
956      if (treecase == 0)
957     next_punt = n1p->idx[i].punt;
958      else
959     next_punt = n2p->idx[i].punt;
960         upif_print_btree(/* trmp,*/ invp,ident+2,level+1,
961               next_punt,treecase,fout);
962  }
963}
964/* -----------------------------------------------------------------------*/
965#if CICPP
966void upif_gera_keys(INVMAP *invp,
967                    int     ident,
968                    int     level,
969                    PUNT    punt,
970                    int     treecase,
971                    FILE   *fkeys)
972#else /*CICPP*/
973
974void upif_gera_keys(invp,ident,level,punt,treecase,fkeys)
975INVMAP *invp;
976int ident;
977int level;
978PUNT punt;
979int treecase;
980FILE *fkeys;
981#endif /*CICPP*/
982{
983  int ock,i,keysize;
984  UCHR  *np;
985  N2STRU *n2p, *keep_node2,area_node2;
986  N1STRU *n1p, *keep_node1,area_node1;
987  N0STRU *n0local;
988  L0STRU *l0p;
989  L1STRU *l1p;
990  L2STRU *l2p;
991  PUNT next_punt;
992  PUNT info1,info2;
993  UCHR lbufp[sizeof(L2STRU)+1];
994  UCHR  key[LE2+1];
995  keep_node1=&area_node1;
996  keep_node2=&area_node2;
997  keysize=vlex[treecase];
998  if (punt==0) return;
999  if (punt<0) {
1000        punt=-punt;
1001    l0p=(L0STRU *)leafread(lbufp,invp,treecase,punt,0);
1002    l1p=(L1STRU *)l0p;
1003    l2p=(L2STRU *)l0p;
1004    for (i=0;i<l0p->ock;i++){
1005      if (treecase == 0) {
1006         memcpy((char *)key,l1p->idx[i].key,keysize);
1007         info1=l1p->idx[i].info1;
1008         info2=l1p->idx[i].info2;
1009      }
1010      else{
1011         memcpy((char *)key,l2p->idx[i].key,keysize);
1012         info1=l2p->idx[i].info1;
1013         info2=l2p->idx[i].info2;
1014      }
1015      key[keysize]='\0';
1016      fprintf(fkeys,"%s , %ld * %ld \n",key,info1,info2);
1017    }/* FOR */
1018        return;
1019  } /* punt > 0 */
1020  np=(UCHR *)noderead(invp,treecase,level,punt);
1021  n1p=(N1STRU *)np;
1022  n2p=(N2STRU *)np;
1023  if (treecase == 0) {
1024     memcpy((UCHR *)keep_node1,(UCHR *)np,sizeof(N1STRU));
1025     n0local=(N0STRU *)keep_node1;
1026     n1p=(N1STRU *)n0local;
1027  }
1028  else {
1029     memcpy((UCHR *)keep_node2,(UCHR *)np,sizeof(N2STRU));
1030     n0local=(N0STRU *)keep_node2;
1031     n2p=(N2STRU *)n0local;
1032  }
1033  ock=n0local->ock;
1034  for (i=0;i<ock;i++){
1035      if (treecase == 0)
1036     next_punt = n1p->idx[i].punt;
1037      else
1038     next_punt = n2p->idx[i].punt;
1039         upif_gera_keys(/* trmp,*/ invp,ident+2,level+1,
1040               next_punt,treecase,fkeys);
1041  }
1042}
1043#endif /* DEBIFUPD */
1044
1045#if CNV_PCBINUM
1046/*--------------------------------------------------------------------------*/
1047/* Armazena o par bloco/offset se ainda nao estiver armazenado              */
1048/*   Verifica se ha espaco nos vetores.                                     */
1049/*--------------------------------------------------------------------------*/
1050#if CICPP
1051void ifp_ins_new_hd(INFO blk,
1052                    INFO off,
1053                    INFO hdblk[],
1054                    INFO hdoff[],
1055                    int  hdmax,
1056                    int *hdn)
1057#else /* CICPP */
1058void ifp_ins_new_hd(blk,off,hdblk,hdoff,hdmax,hdn)
1059 INFO blk;
1060 INFO off;
1061 INFO hdblk[];
1062 INFO hdoff[];
1063 int  hdmax;
1064 int *hdn;
1065#endif /* CICPP */
1066 {
1067   int i;
1068   /* Verifica se  se ja existe uma entrada no vetor para o par */
1069
1070   for (i=*hdn;i>=0;i--) {
1071     if (hdblk[i]==blk && hdoff[i]==off) break; /*existe */
1072   }
1073
1074  if (i<0){ /* Nao esta */
1075   *hdn=*hdn+1;
1076   if (*hdn<hdmax){
1077      hdblk[*hdn]=blk;
1078      hdoff[*hdn]=off;
1079   } else fatal ("ifp_ins_new_hd");
1080  }
1081#if TRACEhh
1082     printf("\n===Ins===\n");
1083   for (i=*hdn;i>=0;i--) {
1084     printf("\n[InsHd] hdblk[%d]=%d hdoff[%d]=%d",i,hdblk[i],hdoff[i]);
1085   }
1086
1087#endif
1088}
1089
1090/*--------------------------------------------------------------------------*/
1091/* Inicializa as estruturas que guardam os headers de um ifp                */
1092/*                                                                          */
1093/*--------------------------------------------------------------------------*/
1094#if CICPP
1095void ifp_init_hd(int  *hdn)
1096#else /* CICPP */
1097void ifp_init_hd(hdn)
1098 int  *hdn;
1099#endif /* CICPP */
1100{
1101 *hdn=-1; /* ISTO E' SUFICIENTE */
1102#if TRACEhh
1103  printf("  Inicializou hdn\n");
1104#endif
1105}
1106
1107#endif /* CNV_PCBINUM */
Note: See TracBrowser for help on using the browser.