root/trunk/ciifu.c

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

essage first commit

Line 
1 /*-------------------------------------------------------------------------
2ciifu.c
3SVD 10-03-93
4        Rotinas para Inserir/remover postings no arquivo .IFP
5
6        AOT 08-03-95
7        Operacao Multiusuario
8---------------------------------------------------------------------------*/
9
10#include <stdio.h>
11#include <string.h>
12#include "cisis.h"
13#include "ciupi.h"
14
15#if CICPP
16#include <ciifu.hpp>
17#include <cidbx.hpp>
18#include <citrm.hpp>
19#include <cirec.hpp>
20#include <cifst.hpp>
21#include <cirun.hpp>
22#ifdef USE_ERROR_SYS
23#include <ui_win.hpp>
24#include <errorsys.hpp>
25extern MY_ERROR_SYSTEM * errsys;
26extern UIW_WINDOW * wprogress;
27extern UIW_WINDOW *mainwindow;
28extern MESS_SYSTEM *mess;
29extern int DS_OperationStopped; // must be implemented in another way
30#define USE_INFO_SYS
31#include <textdb.hpp>
32#endif
33#endif /* CICPP */
34
35
36#if !CICPP
37int ifupd_reset=2;
38
39int ifupd_wrnmsg=1;
40#endif /* CICPP */
41
42#define lnk_not_found_msg  "Warning! Link not found. Cannot delete"
43#define lnk_dup_msg        "Warning! Duplicate link"
44
45/*-----------------------------------------------------------------------*/
46#define AOT            1
47
48#define MULTI_IF         MULTI
49
50#define SHTEST           0
51
52#if !CICPP
53#if SHTEST
54static char shtest[CIMPL+1];
55#endif /* SHTEST */
56#endif /* CICPP */
57
58#define TRACEOPT         0
59#define TRACEUPIF        DEBIFUPD
60#define TRACEUPIF2       0
61#define MODIFIED         TRUE
62#define NOT_MODIFIED     FALSE
63#define PSTADDR(blk,idx) (POSTSTRU *)&blk->ifprec[idx]
64#define HEAD(blk,off)    (IFPHEAD *)&blk->ifprec[off]
65#define HEADSIZE         sizeof(IFPHEAD)
66#define POSTSIZE         sizeof(POSTSTRU)
67#define BLK(x)           x->ifpblk
68
69#if !CICPP
70static UCHR key[LE2+1],*keyp;
71static INVMAP *invp;
72static  DBXSTRU *dbxp;
73
74#if LINDLUX /* 2 */
75static int luxtree,luxn;
76static LONGX luxpunt,luxpos,luxx,luxaddr;
77static L0STRU *luxpagp;
78static L1STRU *luxp1;
79static L2STRU *luxp2;
80static char *luxp;
81/* <============================ */
82#else /* LINDLUX 2 */
83#if !LIND /* 8x2 */
84typedef struct ifpkeydata {
85        BOOLEAN  st;            /* record modified */
86        IFPSTRU  reg;
87} IFPKEYDATA;
88
89#define  UNDEFINED   -1
90#define  CURR_INP    0
91#define  SEGH        1
92#define  FIRST       2
93#define  CURR_OUT    3
94#define  PREG(x)     (IFPSTRU *)&(v[x].reg)
95#define  BLKX(x)     BLK( (PREG(x)) )
96#define  STATUS(x)   v[x].st
97
98static IFPKEYDATA v[4];
99static int idx_curr_inp,idx_segh,idx_first,idx_curr_out;
100static BOOLEAN dupl_msg,ja_inseriu;
101static POSTSTRU *pinitpst,initpst;
102static UCHR buf[IFBSIZ],*pbuf;
103static IFPAVAILPOS pn;
104static INFO totp_inp,nxtb_inp,nxtp_inp,segp_inp,segc_inp,
105            accurate_totp,nxtb_out,nxtp_out,npst_read_in_seg,
106            off_fh_inp,off_ch_inp,blk_inp,off_inp,
107            idxpst_inp,idxpst_out;
108static IFPSTRU *pcur_blk,*pcur_blk_out;
109#endif /* !LIND 8x2 */
110#endif /* LINDLUX 2 */
111static LONGX nlidos;
112#endif /* CICPP */
113
114/*-------------------------------------------------------------------------*/
115#if CNV_PCBINUM
116/*25/07/97*/
117/* Variaveis para guardar a localizacao ds headers de um segmento */
118/* 128/(5+2) */
119#define IFLmaxhd  IFPmaxhd*MAXIFPMEM + 1   /* headers em memoria */
120#if ! CICPP
121static int hdn=-1;       /* numero headers de um ifp */
122static INFO hdblk[IFLmaxhd];
123static INFO hdoff[IFLmaxhd];
124#endif /* CICPP */
125#endif /*CNV_PCBINUM */
126/*-------------------------------------------------------------------------*/
127
128#if ! CICPP
129#if ANSI
130void optlnk1(char *lnk1p,LONGX qtylk1,char *olnk1p,LONGX oqtylk1);
131void optlnk2(char *lnk2p,LONGX qtylk2,char *olnk2p,LONGX oqtylk2);
132void trace_records(LONGX tell);
133void posiciona_inicio_seg(void);
134void verif_grava_rec(DBXSTRU *dbxp,int idx );
135PUNT upif_init_index(DBXSTRU *dbxp, int treecase, UCHR *key,INFO TSTblk,
136                                         INFO TSToff);
137PUNT  upif_create_root(DBXSTRU *dbxp,PUNT esq,UCHR *key,
138        PUNT dir,int treecase,BOOLEAN first);
139BOOLEAN upif_find_key_leaf(L0STRU *lp, UCHR *key, int treecase,
140                           int *pos);
141BOOLEAN upif_find_key_node(N0STRU *np,UCHR *key, int treecase,
142               int *pos);
143void upif_fnd_pifp(DBXSTRU  *dbxp,UCHR *key,int treecase,
144                                        POSTSTRU *pst,UCHR oper,int PSTFLAG);
145void upif_branqueia(UCHR *str, int size);
146BOOLEAN upif_insert_index (DBXSTRU *dbxp,
147        PUNT punt,int treecase,int level,int isroot,
148        UCHR *b_key,PUNT b_punt,
149        UCHR *p_key,PUNT *p_punt);
150PUNT upif_search_btree(INVMAP *invp,int treecase, UCHR *key);
151BOOLEAN upif_insert_leaf(DBXSTRU *dbxp,L0STRU *lp,UCHR *key,int treecase,
152                                 UCHR *p_b_key,PUNT *p_b_punt,int pos,
153                                 INFO blk,INFO off );
154void upif_print_msg(POSTSTRU *ppst,UCHR *msg);
155void upif_print_lfitem(int treecase,UCHR *lfitem);
156void next_output_element(void);
157#else
158void optlnk1();
159void optlnk2();
160void trace_records();
161void posiciona_inicio_seg();
162PUNT upif_init_index();
163PUNT upif_create_root();
164BOOLEAN upif_find_key_leaf();
165BOOLEAN upif_find_key_node();
166void upif_fnd_pifp();
167void upif_branqueia();
168BOOLEAN upif_insert_index ();
169PUNT upif_search_btree();
170BOOLEAN upif_insert_leaf();
171void upif_print_msg();
172void upif_print_lfitem();
173void next_output_element();
174#endif
175#if ANSI
176void read_ifpcntrl(void);
177void upif_delete_posting(POSTSTRU *ppst);
178void upif_delete_elem(void);
179void print_post(POSTSTRU *pst);
180/* void verif_headers_x_current(IFPSTRU *pcurrent,BOOLEAN *update_flag); */
181void update_frst_curr_headers(INFO nelem);
182void update_ifpcntrl(INFO nxtb,INFO nxtp);
183void next_output_blk(void );
184void next_input_blk(void);
185void next_input_seg(void);
186void next_input_element(void );
187void copia_posting(POSTSTRU *ppst,BOOLEAN  *ja_inseriu);
188void insere_posting( int idx_ifprec, int idx, POSTSTRU *ppst);
189void gethead_counters(IFPSTRU *p,INFO off,
190                          INFO  *nxtb , INFO *nxtp,INFO *totp ,
191                          INFO  *segp, INFO *segc);
192void update_header(IFPSTRU *pifp,INFO off,
193                   INFO  nxtb , INFO nxtp,INFO totp ,
194                   INFO segp, INFO segc);
195void create_new_segment(INFO segp,INFO segc);
196void upif_split_segment(POSTSTRU *ppst);
197void upif_find_segment(POSTSTRU *ppst);
198void upif_insert_into_seg(POSTSTRU *ppst);
199#if !LIND /* 11 */
200void upif_process_new_key(POSTSTRU *ppst,INFO *blk,INFO *off);
201void upif_process_posting(POSTSTRU *ppst,INFO blk, INFO off, UCHR operation);
202#endif /* !LIND 11 */
203#else
204void read_ifpcntrl();
205void upif_delete_posting();
206void upif_delete_elem();
207void print_post();
208/* void verif_headers_x_current();*/
209void update_frst_curr_headers();
210void update_ifpcntrl();
211void next_output_blk();
212void next_input_blk();
213void next_input_seg();
214void next_input_element();
215void copia_posting();
216void insere_posting();
217void gethead_counters();
218void update_header();
219void create_new_segment();
220void upif_split_segment();
221void upif_find_segment();
222void upif_insert_into_seg();
223#if !LIND /* 11 */
224void upif_process_new_key();
225void upif_process_posting();
226#endif /* !LIND 11 */
227#endif
228#endif /* CICPP */
229
230#include "ciifuh.c"
231/*------------------------------------------------------------------------*/
232
233#if CICPP
234CIIFU :: CIIFU(CISISX *parm_cisisp)
235{
236 cisisxp = parm_cisisp;
237
238 ifupd_reset=2; 
239 ifupd_wrnmsg=0;
240#if CNV_PCBINUM
241 hdn=-1;       /* numero headers de um ifp */
242#endif /*CNV_PCBINUM */
243
244 idx_curr_inp=0;
245
246}
247#endif /* CICPP */
248
249#if TRACEUPIF
250#if CICPP
251void CIIFU :: upif_print_lfitem(int   treecase,
252                                UCHR *lfitem)
253#else /*CICPP*/
254void upif_print_lfitem(treecase , lfitem)
255int treecase;
256UCHR *lfitem;
257#endif /*CICPP*/
258{
259  UCHR str [LE2+1];
260  int keysize;
261  L1IDXE  *lfi1;
262  L2IDXE  *lfi2;
263  INFO info1,info2;
264  keysize = vlex[treecase];
265  memcpy (str, lfitem, keysize );
266  str[keysize]='\0';
267  if (treecase == 0) {
268     lfi1 = (L1IDXE *)lfitem;
269     info1=lfi1->info1;
270     info2=lfi1->info2;
271   }
272   else {
273     lfi2 = (L2IDXE *)lfitem;
274     info1 = lfi2->info1;
275     info2 = lfi2->info2;
276   }
277    printf(" (%s %"_LD_" %"_LD_")",str, info1, info2);
278#if LIND /* x */
279  if (treecase == 0) printf(" (%"_LD_")",lfi1->info3info4.info3);
280  else               printf(" (%"_LD_")",lfi2->info3info4.info3);
281#endif /* LIND x */
282}
283#endif
284/*-----------------------------------------------------------------------*/
285#if CICPP
286void CIIFU :: upif_print_msg(POSTSTRU *pst,
287                             UCHR     *msg)
288#else /*CICPP*/
289void upif_print_msg(pst,msg)
290POSTSTRU *pst;
291UCHR *msg;
292#endif /*CICPP*/
293{
294  if (ifupd_wrnmsg) {
295   print_post(pst);
296   printf(" %s\n",msg);
297  }
298}
299/*------------------------------------------------------------------------*/
300#if !LIND /* 3 */
301#if CICPP
302void CIIFU :: verif_grava_rec(DBXSTRU *dbxp,
303                              int      idx)
304#else /*CICPP*/
305void verif_grava_rec(dbxp,idx)
306DBXSTRU *dbxp;
307int idx ;
308#endif /*CICPP*/
309{
310#if 1
311  IFPSTRU *tmp;
312  tmp=PREG(idx);
313#endif
314  if (STATUS(idx)==MODIFIED) {
315#if 0  /* Nao tirar!!!*/
316         printf("\n Gravando blk=%"_LD_,BLK(tmp));
317#endif
318#if CNV_PCBINUM
319         ifpwrit(dbxp,(char *)tmp,(LONGX)IFBSIZ,hdblk,hdoff,hdn);
320#else /* CNV_PCBINUM */
321         ifpwrit(dbxp,(char *)tmp,(LONGX)IFBSIZ);
322#endif /* CNV_PCBINUM */
323         STATUS(idx)=NOT_MODIFIED;
324  }
325}
326/*-----------------------------------------------------------------------*/
327#if CICPP
328void CIIFU :: update_frst_curr_headers(INFO nelem)
329#else /*CICPP*/
330void update_frst_curr_headers(nelem)
331INFO nelem;
332#endif /*CICPP*/
333{  IFPHEAD *h,*fh;
334#if CNV_PCBINUM
335 ifp_ins_new_hd(BLKX(idx_segh),off_ch_inp,hdblk,hdoff,IFLmaxhd,&hdn);
336#endif /*CNV_PCBINUM */
337
338
339 h=HEAD( (PREG(idx_segh)),off_ch_inp);
340 /* 25-08-95: Conclui que: O ifptot so tem valor correto no primeiro
341              header do  posting. Nos outros fica sempre com o mesmo valor
342              da capacidade do segmento. Desta forma nao se incrementa o
343              ifptot dos segmentos 2,3,..n .
344              Esta alteracao deve ser feita junto com as outras de 25-08-95
345 */
346
347/* 25-08-95
348 h->ifptotp+=nelem;
349*/
350 h->ifpsegp+=nelem;
351 STATUS(idx_segh)=MODIFIED;
352
353#if CNV_PCBINUM
354/*hh*/  ifp_ins_new_hd(BLKX(idx_first),off_fh_inp,hdblk,hdoff,IFLmaxhd,&hdn);
355#endif /*CNV_PCBINUM */
356
357
358 fh=HEAD( (PREG(idx_first)),(int) off_fh_inp);
359 /* 25-08-95
360              Nas linhas a seguir, o teste que era feito para saber se
361              deveria ou nao alterar no primeiro segmento perde o efeito.
362              Sempre devera ser feito. Esse teste tinha sentido para
363              nao incrementar 2 vezes quando estavamos trabalhando com
364              o primeiro segmento.
365              Deixei entre #if .. #endif para nao perder o historico
366
367 */
368#if 0
369 /* Se first coincide com current nao atualiza first */
370  if (fh!=h) {
371   fh->ifptotp+=nelem;
372   STATUS(idx_first)=MODIFIED;
373 }
374#else
375/* 25-08-95 */
376   fh->ifptotp+=nelem;
377   STATUS(idx_first)=MODIFIED;
378#endif
379}
380/*------------------------------------------------------------------------*/
381#if CICPP
382void CIIFU :: read_ifpcntrl()
383#else /*CICPP*/
384void read_ifpcntrl()
385#endif /*CICPP*/
386{
387  IFPSTRU *tmp;
388  tmp=postread(pbuf,invp,1L,0); /* Ler registro de controle */
389  pn.ifpblk=1L;
390  pn.nxtb=tmp->ifprec[0];
391  pn.nxtp=tmp->ifprec[1];
392}
393#endif /* !LIND 3 */
394/*------------------------------------------------------------------------*/
395#if BEFORE20000926
396#if CICPP
397int CIIFU :: upif_end(int pstflag)
398#else /*CICPP*/
399int upif_end(pstflag)
400int pstflag;
401#endif /*CICPP*/
402#else /* BEFORE20000926 */
403#if CICPP
404int CIIFU :: upif_end(char *dbnp, int pstflag)
405#else /*CICPP*/
406int upif_end(dbnp,pstflag)
407char *dbnp;
408int pstflag;
409#endif /*CICPP*/
410#endif /* BEFORE20000926 */
411{
412  int rc=0;
413#if !LIND /* 4.0 */
414  IFPHEAD *h;
415  IFPSTRU *t;
416#endif /* !LIND 4.0 */
417#if BEFORE20000927
418#else /* BEFORE20000926 */
419  trmifupd=IFUPDXUP; /* trm IFUPDATE operation + cntwrit */
420#endif /* BEFORE20000926 */
421
422#if BEFORE20000926
423#else /* BEFORE20000926 */
424  dbxp=dbxstorp(dbnp);
425#endif /* BEFORE20000926 */
426  if (!DBXiinit) fatal("ciifu/upif_end/DBXiinit");
427#if !LIND /* 4 */
428  if (pstflag == IFUPDICT) {    /* .ifp was not processed */
429        idx_curr_inp=CURR_INP;
430        off_inp=2L;
431        t=PREG(idx_curr_inp);
432        BLK(t)=1L;
433        update_ifpcntrl(1L,IDXHEADSIZE+PSTSIZE+off_inp);
434        h=HEAD(t,(int)off_inp);
435        h->ifptotp=0;
436        h->ifpsegp=0;
437        h->ifpsegc=1;
438        h->ifpnxtp=0;
439        h->ifpnxtb=0;
440        STATUS(idx_curr_inp)=MODIFIED;
441        verif_grava_rec(dbxp,idx_curr_inp);
442  }
443#if CNV_PCBINUM
444  /* Nao tem nada para converter */
445  ifpwrit(dbxp,(char *)&pn,(LONGX)sizeof(IFPAVAILPOS),hdblk,hdoff,(-1));
446#else /* CNV_PCBINUM */
447  ifpwrit(dbxp,(char *)&pn,(LONGX)sizeof(IFPAVAILPOS));
448#endif /* CNV_PCBINUM */
449#else /* !LIND 4 */
450  if (pstflag == IFUPDICT) {;}  /* no wrn */
451#endif /* !LIND 4 */
452
453#if BEFORE950308
454  cntwrit(dbxp); /* acho que nao precisa por causa de nodewrit/leafwrit */
455#endif
456
457  DBXiinit=0;
458
459#if BEFORE20000927
460#else /* BEFORE20000926 */
461  trmifupd=0; /* reset IFUPDXUP */
462#endif /* BEFORE20000926 */
463
464#if 0
465   printf("\n ----------------------------------------------------------");
466   printf("\n =>Total de registros Processados:%"_LD_,nlidos);
467   printf("\n ----------------------------------------------------------");
468#endif
469  return(rc);
470}
471/*------------------------------------------------------------------------*/
472#if CICPP
473void CIIFU :: upif_init(char *dbnp)
474#else /*CICPP*/
475void upif_init(dbnp)
476char *dbnp;
477#endif /*CICPP*/
478{
479#if BEFORE20000927
480#else /* BEFORE20000926 */
481  trmifupd=IFUPDXUP; /* trm IFUPDATE operation + cntwrit */
482#endif /* BEFORE20000926 */
483
484  keyp=(UCHR *)&key[0];
485  strcpy((char *)keyp,"!012345678");
486
487  if ((dbxp=dbxsrchp(dbnp)) == (DBXSTRU *)NULL) {
488        dbxp=dbxstorp(dbnp);
489        DBXitrac=0; DBXitell=0; DBXirang=1L;
490  }
491
492#if !LIND /* 5 */
493  invsetup((UCHR *)dbnp,0L,0L,0L);
494#else /* !LIND 5 */
495  invsetup((UCHR *)dbnp,0L,0L,-1L);
496#endif /* !LIND 5 */
497  invp=DBXifmap;
498
499  DBXiinit=1;
500#if !MULTI_IF
501  DBXirecs=0L;
502  DBXipadd[0]=DBXipadd[1]=0L;
503  DBXipdel[0]=DBXipdel[1]=0L;
504#endif
505#if !LIND /* 6 */
506  pbuf=(UCHR *)buf;
507  pinitpst= &initpst; /* falta inicializar com -1 */
508  read_ifpcntrl();
509#endif /* !LIND 6 */
510
511#if BEFORE20000927
512#else /* BEFORE20000926 */
513  trmifupd=0; /* reset IFUPDXUP */
514#endif /* BEFORE20000926 */
515
516}
517/*------------------------------------------------------------------------*/
518#if !LIND /* 7 */
519#if CICPP
520void CIIFU :: update_ifpcntrl(INFO nxtb,
521                              INFO nxtp)
522#else /*CICPP*/
523void update_ifpcntrl(nxtb,nxtp)
524 INFO nxtb;
525 INFO nxtp;
526#endif /*CICPP*/
527 {
528        pn.nxtb=nxtb;
529        pn.nxtp=nxtp;
530 }
531#endif /* !LIND 7 */
532/*-----------------------------------------------------------------------*/
533#if CICPP
534void CIIFU :: print_post(POSTSTRU *pstp)
535#else /*CICPP*/
536void print_post(pstp)
537POSTSTRU *pstp;
538#endif /*CICPP*/
539{
540 LONGX mfn;
541 unsigned short tag,occ,cnt;
542 decodepst(pstp,&mfn,&tag,&occ,&cnt);
543#if AOT
544 printf("%s %"_LD_"/%d/%d/%d  ",keyp,mfn,tag,occ,cnt);
545#else
546 printf("\n%s %"_LD_"/%d/%d/%d       ",keyp,mfn,tag,occ,cnt);
547#endif
548}
549/*------------------------------------------------------------------------*/
550#if !LIND /* 8 */
551#if CICPP
552void CIIFU :: next_output_blk()
553#else /*CICPP*/
554void next_output_blk()
555#endif /*CICPP*/
556{
557        verif_grava_rec(dbxp,idx_curr_out);
558    nxtb_out++;
559        idx_curr_out=CURR_OUT;
560        BLK( (PREG(idx_curr_out)) )=nxtb_out;
561        STATUS(idx_curr_out)=MODIFIED;
562    idxpst_out=0;
563}
564/*------------------------------------------------------------------------*/
565#if CICPP
566void CIIFU :: next_input_blk()
567#else /*CICPP*/
568void next_input_blk()
569#endif /*CICPP*/
570{
571if (idx_curr_inp==UNDEFINED ){
572  idx_curr_inp=CURR_INP;
573  idx_first=CURR_INP;
574  idx_segh=CURR_INP;
575  STATUS(CURR_INP)=NOT_MODIFIED;
576  off_fh_inp=nxtp_inp;
577  off_ch_inp=nxtp_inp;
578}else {
579  if ((idx_curr_inp==idx_segh) && (idx_segh!=idx_first)) {
580        idx_segh=SEGH;
581        v[idx_segh]=v[idx_curr_inp];
582        STATUS(idx_curr_inp)=NOT_MODIFIED;
583  }else {
584        if ((idx_curr_inp==idx_segh)&&(idx_first==idx_segh)) {
585          idx_segh=FIRST;
586          idx_first=FIRST;
587          v[idx_first]=v[idx_curr_inp];
588          STATUS(idx_curr_inp)=NOT_MODIFIED;
589        }
590  }
591}
592verif_grava_rec(dbxp,idx_curr_inp);
593blk_inp++;
594memcpy(PREG(idx_curr_inp),postread(pbuf,invp,blk_inp,0),IFBSIZ);
595idxpst_inp=0;
596}
597/*-----------------------------------------------------------------*/
598#if CICPP
599void CIIFU :: next_input_seg()
600#else /*CICPP*/
601void next_input_seg()
602#endif /*CICPP*/
603{
604 if (idx_curr_inp==UNDEFINED ){
605   idx_curr_inp=CURR_INP;
606   idx_first=CURR_INP;
607   idx_segh=CURR_INP;
608   STATUS(CURR_INP)=NOT_MODIFIED;
609   off_fh_inp=nxtp_inp;
610   off_ch_inp=nxtp_inp;
611 }else {
612   pcur_blk=PREG(idx_curr_inp);
613   if (BLK(pcur_blk)==nxtb_inp) {
614         verif_grava_rec(dbxp,idx_segh);
615         idx_segh=CURR_INP;
616         off_ch_inp=nxtp_inp;
617         goto get_counters;
618   } else {
619         if ((idx_curr_inp==idx_segh)&&(idx_segh==idx_first)){
620           idx_first=FIRST;
621           v[idx_first]=v[idx_curr_inp];
622           STATUS(idx_curr_inp)=NOT_MODIFIED;
623         }else {
624           if ((idx_curr_inp==idx_segh)&&(idx_segh != idx_first)) {
625                 verif_grava_rec(dbxp,idx_segh);
626           }else {
627                 verif_grava_rec(dbxp,idx_segh);
628                 idx_segh=CURR_INP;
629           }
630         }
631   }
632 }
633verif_grava_rec(dbxp,idx_curr_inp);
634memcpy(PREG(idx_curr_inp),postread(pbuf,invp,nxtb_inp,0),IFBSIZ);
635/* Verifica se apos a leitura o first e segh voltaram a apontar para
636   o mesmo bloco e estao apontando para posicoes diferentes na memoria
637*/
638if (  ( BLKX(idx_first) ==BLKX( idx_segh) )  &&
639   (idx_first!=idx_segh)) {
640        if (memcmp(PREG(idx_first),PREG(idx_segh),IFBSIZ) !=0)
641                fatal("ciifu/first/segh");
642        idx_first=idx_segh;
643}
644off_ch_inp=nxtp_inp;
645get_counters:
646 blk_inp=nxtb_inp;
647 off_inp=nxtp_inp;
648 gethead_counters(PREG(idx_segh),off_inp,
649                          &nxtb_inp,&nxtp_inp,&totp_inp,&segp_inp,&segc_inp);
650 npst_read_in_seg=0;
651 idxpst_inp=off_inp+IDXHEADSIZE;
652}
653/*-----------------------------------------------------------------*/
654#if CICPP
655void CIIFU :: next_input_element()
656#else /*CICPP*/
657void next_input_element()
658#endif /*CICPP*/
659{
660 if (npst_read_in_seg <= segp_inp) {
661    if (idxpst_inp+PSTSIZE <= MAXIDXPST){
662       idxpst_inp+=PSTSIZE;
663       }else {
664      next_input_blk();
665    }
666 }else {
667    next_input_seg();
668 }
669 npst_read_in_seg+=1;
670}
671/*-----------------------------------------------------------------*/
672#if CICPP
673void CIIFU :: next_output_element()
674#else /*CICPP*/
675void next_output_element()
676#endif /*CICPP*/
677{
678    if (idxpst_out+PSTSIZE <= MAXIDXPST){
679       idxpst_out+=PSTSIZE;
680       }else {
681      next_output_blk();
682    }
683}
684/*-----------------------------------------------------------------*/
685#if CICPP
686void CIIFU :: copia_posting(POSTSTRU *ppst,
687                            int      *ja_inseriu)
688#else /*CICPP*/
689void copia_posting(ppst,ja_inseriu)
690POSTSTRU *ppst;
691int *ja_inseriu;
692#endif /*CICPP*/
693{
694 int x;
695 POSTSTRU *source,*dest;
696 dest   = PSTADDR( (PREG(idx_curr_out)) ,(int)idxpst_out);
697 if (npst_read_in_seg <segp_inp) {
698   source = PSTADDR( (PREG(idx_curr_inp)) ,(int)idxpst_inp);
699   x=memcmp(source,ppst,sizeof(POSTSTRU));
700 }else x=1;
701 if (*ja_inseriu==TRUE || x<0){
702         memcpy(dest,source,sizeof(POSTSTRU));
703         STATUS(idx_curr_out)=MODIFIED;
704     next_output_element();
705     next_input_element();
706 }else {
707     memcpy(dest,ppst,sizeof(POSTSTRU));
708         STATUS(idx_curr_out)=MODIFIED;
709     *ja_inseriu=TRUE;
710     if (x==0)
711       upif_print_msg(ppst,(UCHR *)lnk_dup_msg);
712     next_output_element();
713 }
714}
715/*-----------------------------------------------------------------*/
716#if CICPP
717void CIIFU :: insere_posting(int idx_ifprec,
718                             int idx,
719                             POSTSTRU *ppst)
720#else /*CICPP*/
721void insere_posting(idx_ifprec,idx,ppst)
722 int idx_ifprec;
723 int idx;
724 POSTSTRU *ppst;
725/* Insere um elemento no lugar correto e passa o valor do vetor adiante
726   para ser inserido na posicao seguinte
727*/
728#endif /*CICPP*/
729{
730   IFPSTRU *pifp;
731   int  x;
732   POSTSTRU *p,tmp;
733   pifp=PREG(idx_ifprec);
734   p=PSTADDR(pifp,idx);
735   x= memcmp(p,ppst,sizeof(POSTSTRU));
736   if (x>0) {
737     memcpy(&tmp,p,sizeof(POSTSTRU));
738     memcpy(p,ppst,sizeof(POSTSTRU));
739     memcpy(ppst,&tmp,sizeof(POSTSTRU));
740         STATUS(idx_ifprec)=MODIFIED;
741   }else
742    if (x==0 && dupl_msg==FALSE){
743       upif_print_msg(ppst,(UCHR *)lnk_dup_msg);
744       dupl_msg=TRUE;
745    }
746}
747/*-----------------------------------------------------------------------*/
748#if CICPP
749void CIIFU :: gethead_counters(IFPSTRU *p,
750                               INFO   off,
751                               INFO  *nxtb,
752                               INFO  *nxtp,
753                               INFO  *totp,
754                               INFO  *segp,
755                               INFO  *segc)
756#else /*CICPP*/
757void gethead_counters(p,off,nxtb,nxtp,totp,segp,segc)
758IFPSTRU *p;
759INFO off;
760INFO  *nxtb , *nxtp,*totp ,*segp, *segc;
761#endif /*CICPP*/
762{
763  IFPHEAD *h;
764  h = HEAD(p,(int)off);
765  *nxtb = h->ifpnxtb;
766  *nxtp = h->ifpnxtp;
767  *totp = h->ifptotp;
768  *segp = h->ifpsegp;
769  *segc = h->ifpsegc;
770}
771/*-----------------------------------------------------------------------*/
772#if CICPP
773void CIIFU :: update_header(IFPSTRU *pifp,
774                            INFO off,
775                            INFO  nxtb,
776                            INFO  nxtp,
777                            INFO  totp,
778                            INFO  segp,
779                            INFO  segc)
780#else /*CICPP*/
781void update_header(pifp,off,nxtb,nxtp,totp,segp,segc)
782IFPSTRU *pifp;
783INFO off;
784INFO  nxtb , nxtp,totp , segp, segc;
785#endif /*CICPP*/
786 {
787  IFPHEAD *h;
788  h = HEAD(pifp,(int)off);
789  h->ifpnxtb=nxtb;
790  h->ifpnxtp=nxtp;
791  h->ifptotp=totp;
792  h->ifpsegp=segp;
793  h->ifpsegc=segc;
794#if CNV_PCBINUM
795/*hh*/  ifp_ins_new_hd(pifp->ifpblk,off,hdblk,hdoff,IFLmaxhd,&hdn);
796#endif /*CNV_PCBINUM */ 
797}
798/*----------------------------------------------------------------------*/
799#if CICPP
800void CIIFU :: create_new_segment(INFO segp,
801                                 INFO segc)
802#else /*CICPP*/
803void create_new_segment(segp,segc)
804INFO segp;
805INFO segc;
806#endif /*CICPP*/
807{
808 IFPSTRU *x;
809 nxtb_out=pn.nxtb;
810 nxtp_out=pn.nxtp;
811 if (segc > MAXPSTSSEG) segc=MAXPSTSSEG;
812/* Verifica se e possivel criar um header e um posting na proxima posicao
813   disponivel. Se nao tiver espaco, cria um novo bloco.
814   Se o bloco onde sera feita a insercao e o mesmo bloco  que esta na me
815   moria, modifica o apontador. Caso contrario le o blk onde sera feita
816   a insercao.
817*/
818/* 27/10/95 - Foi feita uma alteracao para que quando estejamos inserindo
819              uma nova chave, seja forcada a leitura do ifp do disco e
820              reinicializadas as variaveis, em vez de usarmos o blk que
821              esta na memoria.
822*/
823 idx_curr_out=CURR_OUT;
824 pcur_blk_out=PREG(idx_curr_out);
825 pcur_blk=PREG(idx_curr_inp);
826 if (BLK(pcur_blk)==nxtb_out) {
827   idx_curr_out=idx_curr_inp;
828   pcur_blk_out=PREG(idx_curr_out);
829 }else {
830        x=postread(pbuf,invp,nxtb_out,0);
831        memcpy(pcur_blk_out,x,IFBSIZ);
832        STATUS(idx_curr_out)=NOT_MODIFIED;
833    }
834 if (nxtp_out+IDXHEADSIZE+PSTSIZE > MAXIDXPST) {
835    next_output_blk();
836    nxtp_out=idxpst_out;
837 }
838 /* 25-08-93 totp: nao e 'accurate' nos segmentos que sao
839                   criados. O MicroIsis utiliza o valor do
840                   segc
841
842 update_header(PREG(idx_curr_out),nxtp_out,
843                  nxtb_inp,nxtp_inp,segp,segp,segc);
844*/
845 update_header(PREG(idx_curr_out),nxtp_out,
846                  nxtb_inp,nxtp_inp,segc,segp,segc);
847
848 idxpst_out=nxtp_out+IDXHEADSIZE;
849}
850/*------------------------------------------------------------------------*/
851#if CICPP
852void CIIFU :: posiciona_inicio_seg()
853#else /*CICPP*/
854void posiciona_inicio_seg()
855#endif /*CICPP*/
856{
857  if (idx_curr_inp != idx_segh)  {
858         verif_grava_rec(dbxp,idx_curr_inp);
859         v[idx_curr_inp]=v[idx_segh];
860         /* O segh deve apontar para o novo bloco.
861                Se o segh e  igual ao first , muda tambem o first
862         */
863         if (idx_segh==idx_first) {
864           idx_first=idx_curr_inp;
865         }
866         idx_segh=idx_curr_inp;
867         blk_inp=BLK( (PREG(idx_curr_inp) ) );
868         gethead_counters(PREG(idx_segh),off_ch_inp,
869                           &nxtb_inp,&nxtp_inp,&totp_inp,&segp_inp,&segc_inp);
870         npst_read_in_seg=0;
871         idxpst_inp=off_ch_inp+IDXHEADSIZE;
872  }
873}
874/*------------------------------------------------------------------------*/
875#if CICPP
876void CIIFU :: upif_split_segment(POSTSTRU *ppst)
877#else /*CICPP*/
878void upif_split_segment(ppst)
879POSTSTRU *ppst;
880#endif /*CICPP*/
881{
882 INFO segc_out;
883 POSTSTRU *out;
884 IFPHEAD *h,*fh,*hnew;
885 int meio,antes,depois;
886 LONGX np,dep;
887 meio=(int)(segc_inp/2);
888#if 1
889  antes=meio+1;
890#endif
891  depois=(int)(segc_inp-antes)+1; /* O que vai ser inserido */
892/*
893Aqui deveria ser feito outro algoritmo para que nao
894fiquem segmentos com poucos psotings
895#if 0
896   if (segc_inp + 1 <= 2*accurate_totp/3){
897     antes=0;
898     depois=segc_inp +1;
899  }
900#endif
901*/
902  /* Se o bloco onde esta o head do segmento e igual ao segmento corrente
903         nao precisa ler  o bloco do disco.
904     Basta copiar do bloco onde esta o head .
905         inicio do Post para fazer a quebra
906     O idxpst de qualquer maneira deve ser apontado para o inicio
907  */
908  npst_read_in_seg=0;
909  idxpst_inp = off_ch_inp+IDXHEADSIZE;/*precisa ser setado */
910  np=1;
911#if CNV_PCBINUM
912  /*hh*/ /*Marca local do header onde sera feito o split */
913  /*hh*/  ifp_ins_new_hd(BLKX(idx_curr_inp),off_ch_inp,hdblk,hdoff,IFLmaxhd,&hdn);
914#endif /*CNV_PCBINUM */
915
916  while (np<=antes && np<=segp_inp){
917         insere_posting(idx_curr_inp,(int)idxpst_inp,ppst);
918         next_input_element();
919     np++;
920  }
921    create_new_segment(depois,accurate_totp);
922    hnew=HEAD( (PREG(idx_curr_out) ),(int)nxtp_out); /*yyy*/
923    segc_out=hnew->ifpsegc;
924    h=HEAD( (PREG(idx_segh)),(int)off_ch_inp);
925    h->ifpnxtb=nxtb_out;
926    h->ifpnxtp=nxtp_out;
927    h->ifptotp-=(depois-1);
928    h->ifpsegc=segc_inp;
929    h->ifpsegp=antes;
930    STATUS(idx_segh)=MODIFIED;
931    fh=HEAD( (PREG(idx_first)),(int)off_fh_inp);
932   /*        fh->ifptotp+=1; */       /*25-08-1995*/
933    fh->ifptotp=accurate_totp+1; /*25-08-1995*/
934    STATUS(idx_first)=MODIFIED;
935
936#if CNV_PCBINUM
937    /*hh*/ /*Marca local do header do primerio segmento  */
938    /*hh*/  ifp_ins_new_hd(BLKX(idx_first),off_fh_inp,hdblk,hdoff,IFLmaxhd,&hdn);
939#endif /*CNV_PCBINUM */ 
940
941    ja_inseriu=FALSE;
942    dep=0;
943    while (np <= depois+antes && np<=segp_inp+1) {
944      copia_posting(ppst,&ja_inseriu);
945      np++;
946      dep++;
947    }
948/* Considera que ja foram lidos (processados) "depois" elementos do
949   segmento corrente
950*/
951   npst_read_in_seg=depois;
952/* limpa resto do vetor de saida */
953    while (dep < segc_out) {
954      out=PSTADDR( (PREG(idx_curr_out)),(int)idxpst_out);
955      memcpy(out,pinitpst,sizeof(POSTSTRU));
956      STATUS(idx_curr_out)=MODIFIED;
957      np++;
958      dep++;
959      next_output_element();
960    }
961    verif_grava_rec(dbxp,idx_curr_out);
962    update_ifpcntrl(nxtb_out,idxpst_out);
963 }
964/*------------------------------------------------------------------------*/
965#if CICPP
966void CIIFU :: upif_find_segment(POSTSTRU *ppst)
967#else /*CICPP*/
968void upif_find_segment(ppst)
969POSTSTRU *ppst;
970#endif /*CICPP*/
971{
972 int pst_in_blk,
973     /*last_elem, *hh*/  x;
974 INFO last_elem;/*hh*/
975 BOOLEAN found;
976 LONGX segp_tmp;
977 found=FALSE;
978 segp_tmp=segp_inp;
979 for (; segp_tmp >= 0 && found==FALSE ;) {
980  if (nxtb_inp == 0) { found=TRUE;
981  }else
982  if (segp_tmp == 0) {
983      next_input_seg();
984      segp_tmp=segp_inp;
985  }else {
986 /*hh*    last_elem=(int)idxpst_inp+((int)segp_tmp-1)*PSTSIZE; */
987 /*hh*/   last_elem=(INFO)idxpst_inp+((INFO)segp_tmp-1)*PSTSIZE;
988    if (last_elem > MAXIDXPST)last_elem=MAXIDXPST;
989    pst_in_blk=(last_elem-(int)idxpst_inp)/PSTSIZE+1;
990    last_elem=(int)idxpst_inp+(pst_in_blk-1)*PSTSIZE;
991    segp_tmp-= pst_in_blk;
992    x=memcmp((UCHR *)ppst,
993                PSTADDR( ( PREG(idx_curr_inp) ),last_elem),sizeof(POSTSTRU));
994    if ( x <= 0) {
995      found=TRUE;
996    }
997    else {
998        if (segp_tmp > 0) {
999            npst_read_in_seg+=pst_in_blk;
1000            next_input_blk();
1001        }else {
1002            next_input_seg();
1003            segp_tmp=segp_inp;
1004        }
1005     }
1006  }
1007 }
1008}
1009/*--------------------------------------------------------------------------*/
1010#if CICPP
1011void CIIFU :: upif_insert_into_seg(POSTSTRU *ppst)
1012#else /*CICPP*/
1013void upif_insert_into_seg(ppst)
1014POSTSTRU *ppst;
1015#endif /*CICPP*/
1016{
1017 POSTSTRU *p;
1018 while (npst_read_in_seg <= segp_inp-1){ /* npst_read_in_seg comeca 0 */
1019   insere_posting(idx_curr_inp,(int)idxpst_inp,ppst);
1020   next_input_element();
1021 }
1022 /* Insere o ultimo elemento */
1023 p=PSTADDR( (PREG(idx_curr_inp)),(int)idxpst_inp);
1024 memcpy(p,ppst,sizeof(POSTSTRU));
1025 STATUS(idx_curr_inp)=MODIFIED;
1026#if CNV_PCBINUM
1027 /*hh*/
1028 /*hh* Nao mexeu com headers. Nao precisa alterar 
1029     ifp_ins_new_hd(BLKX(idx_curr_inp),off_inp,hdblk,hdoff,IFLmaxhd,&hdn);
1030     
1031 */
1032#endif /*CNV_PCBINUM */
1033
1034 update_frst_curr_headers((INFO)1);
1035 /*Deixa proximo elemento disponivel -( se existir) */
1036 if (npst_read_in_seg<=segp_inp)next_input_element();
1037}
1038/*--------------------------------------------------------------------------*/
1039#if CICPP
1040void CIIFU :: upif_process_posting(POSTSTRU *ppst,
1041                                   INFO blk,
1042                                   INFO off,
1043                                   UCHR operation)
1044#else /*CICPP*/
1045void upif_process_posting(ppst,blk,off,operation)
1046POSTSTRU *ppst;
1047INFO blk,off;
1048UCHR operation;
1049#endif /*CICPP*/
1050{
1051 int i;
1052 blk_inp=blk;
1053 off_inp=off;
1054 nxtb_inp=blk;
1055 nxtp_inp=off;
1056 for (i=0;i<=3;i++)
1057        STATUS(i)=NOT_MODIFIED;
1058 idx_curr_inp=UNDEFINED;
1059 next_input_seg();
1060 accurate_totp=totp_inp;/* guarda total de postings da chave.
1061                           Correto somente no primeiro segmento
1062                        */
1063 upif_find_segment(ppst);
1064 posiciona_inicio_seg();
1065 dupl_msg=FALSE;
1066 if (operation==INSERTION) {
1067         if (segp_inp<segc_inp) {        /* Tem espaco para um posting */
1068         upif_insert_into_seg( ppst);
1069      } else {
1070          upif_split_segment(ppst);
1071         
1072     }
1073 }else{
1074   if(operation==DELETION){
1075     upif_delete_posting(ppst);
1076   }else fatal("ciifu/invalid post operation");
1077  }
1078 verif_grava_rec(dbxp,idx_curr_inp);
1079 verif_grava_rec(dbxp,idx_segh);
1080 verif_grava_rec(dbxp,idx_first);
1081 /*hh*/ /* Inicializa marcadores de headers*/
1082#if CNV_PCBINUM
1083  ifp_init_hd(&hdn);
1084#endif /*CNV_PCBINUM */ 
1085
1086 }
1087/*------------------------------------------------------------------------*/
1088#if CICPP
1089void CIIFU :: upif_process_new_key(POSTSTRU *ppst,
1090                                   INFO     *blk,
1091                                   INFO     *off)
1092#else /*CICPP*/
1093void upif_process_new_key(ppst,blk,off)
1094POSTSTRU *ppst;
1095INFO *blk,*off;
1096#endif /*CICPP*/
1097{
1098  POSTSTRU *out;
1099  idx_curr_out=CURR_OUT;
1100  npst_read_in_seg=0;
1101  BLK( (PREG(idx_curr_out)) )=0L; /* para funcionar quando a 1 chave e' nova
1102*/
1103  BLK( (PREG(idx_curr_inp)) )=0L; /*27/10/95 */
1104   /* Correcao do erro que apareceu no atendimento ao sistema de fotocopia.
1105      O programa estava considerando para idx_curr_inp o registro da ultima
1106      chave e, em determinado caso, estava utilizando um registro incorreto.
1107      Esta modificacao vai obrigar, na rotina create_new_segment,
1108      que seja lido o ifp do disco e forcar que
1109      os registros sejam reinicializados.
1110   */
1111  nxtp_inp=0;
1112  nxtb_inp=0;
1113  create_new_segment(1,1);
1114  out=PSTADDR( (PREG(idx_curr_out)) ,(int)idxpst_out);
1115  memcpy(out,ppst,sizeof(POSTSTRU));
1116  *blk=nxtb_out;
1117  *off=nxtp_out;
1118  STATUS(idx_curr_out)=MODIFIED;
1119  /* Tentar posionar no proximo elemento para forcar a criar
1120         novo registro quando estamos no limite maximo do vetor
1121  */
1122  next_output_element(); /* se chegou fim  grava e cria novo.
1123                            Caso contrario so incrementa pointer
1124                         */
1125  verif_grava_rec(dbxp,idx_curr_out);/* grava o registro em que
1126                                        inseriu o posting ou o novo criado
1127                                     */
1128  /*hh*/
1129#if CNV_PCBINUM
1130  ifp_init_hd(&hdn);
1131#endif /*CNV_PCBINUM */
1132  update_ifpcntrl(nxtb_out,idxpst_out);
1133}
1134#endif /* !LIND 8 */
1135
1136/*----------------------------------------------------------------------*/
1137#if CICPP
1138void CIIFU :: trace_records(LONGX tell)
1139#else /*CICPP*/
1140void trace_records(tell)
1141LONGX tell;
1142#endif /*CICPP*/
1143{
1144        nlidos=nlidos+1;
1145        if (tell > 0) {
1146#if TRACEOPT
1147           if (nlidos-nlidos/tell*tell==0)
1148#if 0 /* 0 */
1149                 printf("\n Leitura %"_LD_"=> %s ",nlidos,key);
1150#else
1151                 fprintf(stderr,"+++ %"_LD_" %s\n",nlidos,key);
1152#endif /* 0 */
1153#endif
1154        }
1155}
1156/*----------------------------------------------------------------------*/
1157#if CICPP
1158void CIIFU :: optlnk2(char *lnk2p,
1159                      LONGX qtylk2,
1160                      char *olnk2p,
1161                      LONGX oqtylk2)
1162#else /*CICPP*/
1163void optlnk2( lnk2p, qtylk2, olnk2p,oqtylk2)
1164char *lnk2p;
1165LONGX qtylk2;
1166char *olnk2p;
1167LONGX oqtylk2;
1168#endif /*CICPP*/
1169{
1170  char *p,*q;
1171  LONGX qty;
1172  int ig;
1173  BOOLEAN achou;
1174#if TRACEOPT
1175   char reg[sizeof(LINK2)+1];
1176#endif
1177  char branco[LE2+1];
1178  memset((char *)branco,' ',LE2);
1179 ig=0;
1180#if TRACEOPT
1181  reg[sizeof(LINK2)]='\0';
1182 printf("\n =========DENTRO optlkn2===============");
1183#endif
1184/* Processa arvore do tipo 2*/
1185 for (p=olnk2p; oqtylk2--; p+=sizeof(LINK2)) {
1186#if TRACEOPT
1187       memcpy(reg,p,sizeof(LINK2));
1188       printf("\n Old :%s",reg);
1189#endif
1190    qty=qtylk2;
1191    achou=FALSE;
1192    for (q=lnk2p; qty-- && achou==FALSE; q+=sizeof(LINK2)){
1193#if TRACEOPT
1194       memcpy((char *)reg,q,sizeof(LINK2));
1195       printf("\n  New:%s",reg);
1196#endif
1197           if (memcmp(p,q,sizeof(LINK2))==0) {
1198/*
1199         memcpy(p,(char *)branco,sizeof(LINK2)) ;
1200         memcpy(q,(char *)branco,sizeof(LINK2)) ;
1201*/
1202          *p='\0';
1203          *q='\0';
1204          ig++;
1205          achou=TRUE;
1206#if TRACEOPT
1207          printf("\n +++ Ignorando:%d",ig);
1208#endif
1209        }
1210    }
1211 }
1212}
1213/*----------------------------------------------------------------------*/
1214#if CICPP
1215void CIIFU :: optlnk1(char *lnk1p,
1216                      LONGX  qtylk1,
1217                      char *olnk1p,
1218                      LONGX oqtylk1)
1219#else /*CICPP*/
1220void optlnk1( lnk1p, qtylk1, olnk1p,oqtylk1)
1221char *lnk1p;
1222LONGX qtylk1;
1223char *olnk1p;
1224LONGX oqtylk1;
1225#endif /*CICPP*/
1226{
1227  char *p,*q;
1228  LONGX qty;
1229  int ig;
1230  BOOLEAN achou;
1231  char branco[LE2+1];
1232#if TRACEOPT
1233   char reg[sizeof(LINK2)+1];
1234#endif
1235 ig=0;
1236  memset((char *)branco,' ',LE2);
1237#if TRACEOPT
1238  reg[sizeof(LINK1)]='\0';
1239 printf("\n =========DENTRO optlkn1===============");
1240#endif
1241/* Processa arvore do tipo 1*/
1242 for (p=olnk1p; oqtylk1--; p+=sizeof(LINK1)) {
1243#if TRACEOPT
1244       memcpy(reg,p,sizeof(LINK1));
1245       printf("\n Old :%s",reg);
1246#endif
1247    qty=qtylk1;
1248    achou=FALSE;
1249    for (q=lnk1p; qty-- && achou==FALSE; q+=sizeof(LINK1)){
1250#if TRACEOPT
1251       memcpy(reg,q,sizeof(LINK1));
1252       printf("\n  New:%s",reg);
1253#endif
1254           if (memcmp(p,q,sizeof(LINK1))==0) {
1255/*
1256         memcpy(p,(char *)branco,sizeof(LINK1)) ;
1257         memcpy(q,(char *)branco,sizeof(LINK1)) ;
1258*/
1259          *p='\0';
1260          *q='\0';
1261          ig++;
1262          achou=TRUE;
1263#if TRACEOPT
1264          printf("\n +++ Ignorando:%d",ig);
1265#endif
1266        }
1267    }
1268 }
1269}
1270/*----------------------------------------------------------------------*/
1271#if CICPP
1272void CIIFU :: svdifupd(char *lnk1p,
1273                       LONGX qtylk1,
1274                       char *lnk2p,
1275                       LONGX qtylk2,
1276                       char *olnk1p,
1277                       LONGX oqtylk1,
1278                       char *olnk2p,
1279                       LONGX oqtylk2,
1280                       int  pstflag,
1281                       LONGX tell)
1282#else /*CICPP*/
1283void svdifupd( lnk1p, qtylk1, lnk2p, qtylk2,
1284                          olnk1p,oqtylk1,olnk2p,oqtylk2,pstflag,tell)
1285char *lnk1p;
1286LONGX qtylk1;
1287char *lnk2p;
1288LONGX qtylk2;
1289char *olnk1p;
1290LONGX oqtylk1;
1291char *olnk2p;
1292LONGX oqtylk2;
1293int pstflag;
1294LONGX tell;
1295#endif /*CICPP*/
1296{
1297  LINK1 *p1; LINK2 *p2; /* char *p; */
1298  int treecase;
1299  char branco[LE2+1];
1300  POSTSTRU pst;
1301  UCHR oper;
1302  memset((char *)branco,' ',LE2);
1303  keyp[0]='\0';
1304  treecase=0; /* new */
1305
1306  trmifupd=IFUPDXUP; /* trm IFUPDATE operation + cntwrit */
1307
1308#if 1
1309  optlnk1( lnk1p, qtylk1, olnk1p,oqtylk1);
1310  optlnk2( lnk2p, qtylk2, olnk2p,oqtylk2);
1311#endif
1312/* Processa arvore do tipo 1*/
1313         treecase=0;
1314         oper=DELETION;
1315#if TRACEOPT
1316         if (tell>0) printf("\n=====> Delecao oqtylk1=%"_LD_,oqtylk1);
1317#endif
1318         for (p1=(LINK1 *)olnk1p; oqtylk1--; p1++ /* LINK1 */) {
1319                memcpy(keyp,p1->key,vlex[treecase]);
1320                keyp[vlex[treecase]]='\0';
1321                memcpy((char *)&pst, &(p1->post),POSTSIZE);
1322                /* para futuro: Ignora entradas em branco */
1323#if TRACEhh
1324                printf("\n-----------------------------------------------\n");
1325                upif_print_msg((POSTSTRU *)&pst,"Tree[0] Removendo...");
1326#endif
1327                if (*keyp > branco[0]) {
1328                        upif_fnd_pifp(dbxp,keyp,treecase,&pst,oper,pstflag);
1329                }
1330                trace_records(tell);
1331         }
1332         oper=INSERTION;
1333#if TRACEOPT
1334         if (tell>0) printf("\n=====> Insercao qtylk1=%"_LD_,qtylk1);
1335#endif
1336         for (p1=(LINK1 *)lnk1p; qtylk1--; p1++ /* LINK1 */) {
1337                memcpy(keyp,p1->key,vlex[treecase]);
1338                keyp[vlex[treecase]]='\0';
1339                memcpy((char *)&pst, &(p1->post),POSTSIZE);
1340#if TRACEhh
1341                printf("\n------------------------------------ %"_LD_"\n",nlidos);
1342                upif_print_msg((POSTSTRU *)&pst,"Tree[0] Inserindo...");
1343#endif
1344                if (*keyp > branco[0]) {
1345                        upif_fnd_pifp(dbxp,keyp,treecase,&pst,oper,pstflag);
1346                }
1347                trace_records(tell);
1348          }
1349/* Processa arvore do tipo 2*/
1350         treecase=1;
1351         oper=DELETION;
1352#if TRACEOPT
1353         if (tell>0) printf("\n=====> Delecao oqtylk2=%"_LD_,oqtylk2);
1354#endif
1355         for (p2=(LINK2 *)olnk2p; oqtylk2--; p2++ /* LINK2 */) {
1356                memcpy(keyp,p2->key,vlex[treecase]);
1357                keyp[vlex[treecase]]='\0';
1358                memcpy((char *)&pst, &(p2->post),POSTSIZE);
1359                /* para futuro: Ignora entradas em branco */
1360#if TRACEhh
1361                printf("\n-----------------------------------------------\n");
1362                upif_print_msg((POSTSTRU *)&pst,"Tree[1] Removendo...");
1363#endif
1364                if (*keyp > branco[0]) {
1365                        upif_fnd_pifp(dbxp,keyp,treecase,&pst,oper,pstflag);
1366                }
1367                trace_records(tell);
1368         }
1369         oper=INSERTION;
1370#if TRACEOPT
1371         if (tell>0) printf("\n=====> Insercao qtylk2=%"_LD_,qtylk2);
1372#endif
1373         for (p2=(LINK2 *)lnk2p; qtylk2--; p2++ /* LINK2 */) {
1374                memcpy(keyp,p2->key,vlex[treecase]);
1375                keyp[vlex[treecase]]='\0';
1376                memcpy((char *)&pst, &(p2->post),POSTSIZE);
1377#if TRACEhh
1378                printf("\n-----------------------------------------------\n");
1379                upif_print_msg((POSTSTRU *)&pst,"Tree[1] Inserindo...");
1380#endif
1381                if (*keyp > branco[0]) {
1382                        upif_fnd_pifp(dbxp,keyp,treecase,&pst,oper,pstflag);
1383                }
1384                trace_records(tell);
1385          }
1386
1387
1388    trmifupd=0; /* reset IFUPDXUP */
1389}
1390
1391#if !LIND /* 9 */
1392/*----------------------------------------------------------------------*/
1393#if CICPP
1394void CIIFU :: upif_delete_elem()
1395#else /*CICPP*/
1396void upif_delete_elem()
1397#endif /*CICPP*/
1398{
1399  /* Achou o elemento a ser retirado */
1400  /* Copia o bloco atual em um novo bloco de saida, eliminando o pst*/
1401  /* Atualiza firsthead e segment atual */
1402  /* Incrementa somente o indice de input */
1403 update_frst_curr_headers((INFO)(-1));
1404   verif_grava_rec(dbxp,idx_segh);
1405   verif_grava_rec(dbxp,idx_first);
1406  idx_curr_out=CURR_OUT;
1407  v[idx_curr_out]=v[idx_curr_inp];
1408  nxtb_out=BLK( (PREG(idx_curr_out)) );
1409  idxpst_out=idxpst_inp; /* Aponta para a mesma posicao - Depois o
1410                        input ficara uma posicao adiante;
1411                                                 */
1412}
1413/*------------------------------------------------------------------------*/
1414#if CICPP
1415void CIIFU :: upif_delete_posting(POSTSTRU *ppst)
1416#else /*CICPP*/
1417void upif_delete_posting(ppst)
1418POSTSTRU *ppst;
1419#endif /*CICPP*/
1420{
1421   int  x;
1422   POSTSTRU *p,*out,*inp;
1423   BOOLEAN deleted,fim;
1424   deleted=FALSE;
1425   fim=FALSE;
1426 while (fim==FALSE) {
1427   if (npst_read_in_seg==segp_inp) fim=TRUE;
1428   else {
1429          p=PSTADDR( (PREG(idx_curr_inp)) ,(int)idxpst_inp);
1430          x= memcmp(p,ppst,sizeof(POSTSTRU));
1431      if (x==0) {
1432        upif_delete_elem();
1433        deleted=TRUE;
1434        fim=TRUE;
1435        next_input_element();
1436      }else{
1437         if (x>0) {
1438              fim=TRUE;
1439              npst_read_in_seg=segp_inp+1; /* forcar nao copiar mais */
1440            } else {
1441              next_input_element();
1442         }
1443      }
1444   }
1445}
1446if (deleted!=TRUE)
1447       upif_print_msg(ppst,(UCHR *)lnk_not_found_msg);
1448 else {
1449  /* Copia o resto do segmento para saida */
1450  while (npst_read_in_seg <= segp_inp-1){
1451        inp = PSTADDR( (PREG(idx_curr_inp)) ,(int)idxpst_inp);
1452        out = PSTADDR( (PREG(idx_curr_out)) ,(int)idxpst_out);
1453        memcpy(out,inp,sizeof(POSTSTRU));
1454        STATUS(idx_curr_out)=MODIFIED;
1455    next_input_element();
1456        next_output_element();
1457        if (idxpst_out==0) {/*Precisa mudar de segmento. Como teria que ter
1458                              copiado em out todo o current para nao perder
1459                              a parte que nao vai mudar de valor
1460                            */
1461           idx_curr_out=CURR_OUT;
1462           memcpy( PREG(idx_curr_out),PREG(idx_curr_inp),sizeof(IFPSTRU));
1463        }
1464   }
1465   verif_grava_rec(dbxp,idx_curr_out);
1466 }/*deleted*/
1467}
1468#endif /* !LIND 9 */
1469/* ============================ rotupd.c ================================ */
1470
1471#if !CICPP
1472#if ANSI
1473LONGX aloca_prat(void);
1474void libera_prat(LONGX idx_prat);
1475#else
1476LONGX aloca_prat();
1477void libera_prat();
1478#endif
1479/*----------------------------------------------------------------------*/
1480LONGX aloca_prat()
1481{
1482 LONGX idx_prat;
1483#if PRINT
1484 printf ("\n aloca_prat >inicio>NRECS=%"_LD_, nrecs);
1485#endif
1486     for (idx_prat=maxnrec; idx_prat--; ) {
1487        if (!vrecp[idx_prat]) /* ja' decrementado */
1488            break;
1489     }
1490     if (idx_prat < 0) fatal("ciifu/readoldrec");
1491#if PRINT
1492 printf ("\n aloca_prat >fim>prat=%"_LD_,idx_prat);
1493#endif
1494     recallok(idx_prat,rec_maxmfrl);
1495     return idx_prat;
1496}
1497/*----------------------------------------------------------------------*/
1498void libera_prat(idx_prat)
1499LONGX idx_prat;
1500{
1501#if PRINT
1502    printf ("\n libera_prat >inicio>NRECS=%"_LD_, nrecs);
1503#endif
1504    if (!vrecp[idx_prat]) fatal("ciifu/refrec/free");
1505    FREE(vrecp[idx_prat]); vrecp[idx_prat]=NULL; nrecs--;
1506#if PRINT
1507    printf ("\n libera_prat >fim>NRECS=%"_LD_, nrecs);
1508#endif
1509}
1510#endif /* CICPP */
1511
1512/*----------------------------------------------------------------------*/
1513#if !INPUTFILE
1514#if CICPP
1515#if USE_GDBFMT
1516int CIIFU :: ifupdat(FSTSTRU *fst,
1517                     LONGX mfn1,
1518                     LONGX mfn2,
1519                     int pstflag,
1520                     int endup)
1521#else
1522int CIIFU :: ifupdat(char *mdbnp,
1523                     LONGX mfn1,
1524                     LONGX mfn2,
1525                     char *idbnp,
1526                     FSTSTRU *fst,
1527                     int pstflag,
1528                     int endup)
1529#endif /* USE_GDBFMT */
1530#else
1531int ifupdat(mdbnp,mfn1,mfn2,idbnp,fstp,stwp,maxlk1,maxlk2,pstflag,endup)
1532char *mdbnp;
1533LONGX mfn1;
1534LONGX mfn2;
1535char *idbnp;
1536FST_CODE *fstp;
1537char *stwp;
1538LONGX maxlk1;
1539LONGX maxlk2;
1540int pstflag;
1541int endup;
1542#endif /* CICPP */
1543{
1544#if CICPP
1545#if USE_GDBFMT
1546    MST_FILE *mst = fst->fst_mst;
1547    char *mdbnp = fst->fst_mst->getdbase();
1548    char *idbnp = fst->fst_btree->getdbase();
1549#endif /* USE_GDBFMT */
1550    char *lnk1p=fst->fst_area1p;
1551    char *lnk2p=fst->fst_area2p;
1552    char *olnk1p=fst->fst_oarea1p;
1553    char *olnk2p=fst->fst_oarea2p;
1554
1555#else /* CICPP */
1556    LONGX irec;
1557    static char *lnk1p=NULL;
1558    static char *lnk2p=NULL;
1559    static char *olnk1p=NULL;
1560    static char *olnk2p=NULL;
1561#endif /* CICPP */
1562
1563    RECSTRU *recp; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */
1564    LONGX mfn;
1565    LONGX qtylk1;
1566    LONGX qtylk2;
1567    DBXSTRU *dbxp;
1568    LONGX pmfn;
1569    UWORD ptag,pocc,pcnt;
1570    LINK1 *p1; LINK2 *p2; /* char *p; */
1571    LONGX loop;
1572    int rc=0;
1573
1574#if !LIND /* 18 */
1575#if !CICPP
1576    LONGX orec;
1577#endif /* CICPP */
1578    int flagnew,flagmod;
1579    LONGX oqtylk1;
1580    LONGX oqtylk2;
1581#endif /* !LIND 18 */
1582
1583#ifdef USE_INFO_SYS
1584         char mess_str[255];
1585        UIW_STRING *procstr=NULL;
1586        UIW_PROGRESSBAR *progbar=NULL;
1587        if (wprogress) {
1588                procstr=((UIW_STRING*)wprogress->Get("PROCESSING_STRING"));
1589                progbar=((UIW_PROGRESSBAR*)wprogress->Get("PROG_BAR"));
1590                progbar->Assign(0,0);
1591                progbar->SetColor(8);
1592                }
1593        LONGX prog_to, prog_from=mfn1;
1594        prog_to=mfn2; if (prog_to>mst->getmaxmfn()) prog_to=mst->getmaxmfn();
1595
1596#endif
1597
1598    dbxp=dbxstorp(idbnp);               /* inverted file ! */
1599
1600#if MULTI_IF
1601    if (dbxtrace) printf("+++ ifupdat - %s (%s/%"_LD_"/%"_LD_") netws=%d\n",
1602                                idbnp,mdbnp,mfn1,mfn2,DBXnetws);
1603#endif
1604
1605    trmifupd=IFUPDXUP; /* trm IFUPDATE operation + cntwrit */
1606
1607#if MULTI_IF
1608    if (DBXnetws != MONONETS) {
1609        if (endup == IFUPCORE) fatal("ciifu/MULTI/IFUPCORE");
1610        if (mfn1 != mfn2) fatal("ciifu/MULTI/mfn1!=mfn2");
1611    }
1612    else
1613#endif /* MULTI_IF */
1614    if (!DBXiinit){
1615        upif_init(idbnp);
1616    }
1617
1618#if !LIND /* 21 */
1619#if CICPP
1620    RECSTRU *orecp = new RECSTRU(cisisxp);
1621#if BEFORE970428
1622    orecp->recdbxp=dbxp; /* recread */
1623#else
1624    orecp->recdbxp=dbxstorp(mdbnp); /* recread */
1625#endif
1626#else /* CICPP */
1627    orec=aloca_prat();                  /* old version */
1628#if BEFORE970428
1629    VRECdbxp(orec)=dbxp; /* recread */
1630#else
1631    VRECdbxp(orec)=dbxstorp(mdbnp); /* recread */
1632#endif
1633#endif /* CICPP */
1634#endif /* !LIND 21 */
1635
1636#if CICPP
1637#if USE_GDBFMT
1638    recp = fst->xfst_getrecp();
1639    recp->xrecord(mdbnp,1L); // good - ver
1640#else
1641    recp = fst->xfst_getrecp();             // <===============================
1642    recp->xrecord(mdbnp,1L);                // <===============================
1643#endif /* USE_GDBFMT */
1644#else /* CICPP */
1645    irec=aloca_prat();                  /* current */
1646#endif /* CICPP */
1647
1648    for (mfn=mfn1; mfn <= mfn2; mfn++) {
1649
1650        if (mfn <= 0) break;            /* endup */
1651
1652#if MULTI_IF
1653        if (DBXnetws != MONONETS && mfn1 > 0) {
1654#if SHTEST
1655printf("0."); gets(shtest);
1656if (shtest[0]=='.') system(shtest+1);
1657#endif /* SHTEST */
1658            INVMAP *lastinvp=DBXifmap;
1659            /* lock MF/check EWL/lock IF/set EWL/unlock MF => keep IF locked */
1660            if (dbxilock(dbxp,mdbnp,"L"))
1661                if (dbxewlrc) {rc=RCLOCK; break;} else fatal("ciifu/lock");
1662            upif_init(idbnp);   /* invsetup() and DBXinit */
1663            /* if instead of invflush only invclose() is called,
1664               invsetup() does not load the .cnt again! */
1665            if (lastinvp) cntread(dbxp,NULL,NULL,NULL); /* load .cnt from locked IF */
1666#if SHTEST
1667printf("1."); gets(shtest);
1668if (shtest[0]=='.') system(shtest+1);
1669#endif /* SHTEST */
1670        }
1671#endif /* MULTI_IF */
1672
1673#ifdef USE_INFO_SYS
1674                if (wprogress) {
1675                        sprintf(mess_str,"MFN %"_LD_" (%s %5"_LD_")",mfn,mess->get(452),DBXirecs);
1676                        procstr->DataSet(mess_str);
1677                        progbar->Assign(mfn-prog_from,prog_to-prog_from);
1678                        UI_EVENT event,event1,event2;
1679                        wprogress->eventManager->Get(event1,Q_NO_BLOCK|Q_BEGIN|Q_DESTROY|Q_POLL);
1680                        mainwindow->windowManager->Event(event1);
1681                        wprogress->eventManager->Get(event2,Q_NO_BLOCK|Q_BEGIN|Q_DESTROY|Q_POLL);
1682                        mainwindow->windowManager->Event(event2);
1683                        wprogress->eventManager->Get(event,Q_NO_BLOCK|Q_BEGIN|Q_DESTROY|Q_POLL);
1684                        if (event.type==10235 || event1.type==10235 || event2.type==10235) {            // EXPORT_CANCEL) {
1685                                int ok=errsys->ErrorMessage(wprogress->windowManager,WOS_INVALID,mess->get(420));
1686                                if (ok==WOS_INVALID) {
1687                                        mfn=-1;    // STOP
1688                                        DS_OperationStopped=1;
1689                                        continue;
1690                                        }
1691                                }
1692                        mainwindow->windowManager->Event(event);
1693                        }
1694#endif
1695
1696#if CICPP
1697#if USE_GDBFMT
1698        mst->getrec(mfn);
1699        int status=mst->getstatus();
1700        if (mst->getstatus_eof()) RECrc=RCEOF;
1701        else switch (status) {
1702               case REC_LOCKED:        RECrc=RCLOCK; break;
1703               case REC_ACTIV:         RECrc=RCNORMAL; break;
1704               case REC_LOG_DEL:       RECrc=RCLDEL; break;
1705               case MST_FIL_BAD:
1706               case REC_PHYS_DEL:      RECrc=RCPDEL; break;
1707             }
1708        if (RECrc == RCNORMAL || RECrc == RCLDEL)
1709            memcpy(MFX,mst->getrecbuf(),mst->getreclen());
1710#else /* USE_GDBFMT */
1711        recp->xrecord(mdbnp,mfn);
1712#endif /* USE_GDBFMT */
1713#else /* CICPP */
1714        RECORD(irec,mdbnp,mfn);
1715#endif /* CICPP */
1716
1717        if (RECrc == RCEOF) break;
1718        if (RECrc == RCPDEL) continue;
1719
1720#if !CICPP
1721#if GEN_UTL
1722        if (DBXitrac) prtleader(recp,MFRmfn);
1723#endif /* GEN_UTL */
1724#endif /* CICPP */
1725#if !LIND /* 19 */
1726        flagnew=recxrefn; flagmod=recxrefm;
1727        if (flagnew && flagmod) fatal("ciifu/check/flags");
1728        if (!flagnew && !flagmod) continue;
1729#endif /* !LIND 19 */
1730
1731/*
1732irec
1733recp
1734*/
1735#if CICPP
1736            if(fst->xfst_inter(0) == -2) {
1737                 fatal("ciifu/fst_inter0");
1738                }
1739                lnk1p=fst->fst_area1p;
1740                lnk2p=fst->fst_area2p;
1741                qtylk1=fst->fst_qtylk1;
1742                qtylk2=fst->fst_qtylk2;
1743#else /* CICPP */
1744        fst_inter(fstp,irec,stwp,
1745                        &lnk1p,maxlk1,&lnk2p,maxlk2,&qtylk1,&qtylk2);
1746#endif /* CICPP */
1747
1748        if (DBXitrac) {
1749                for (p1=(LINK1 *)lnk1p, loop=qtylk1; loop--; p1++ /* LINK1 */) {
1750                    pstdecod(&(p1->post),&pmfn,&ptag,&pocc,&pcnt);
1751                    prtlink("[ ] ",pmfn,ptag,pocc,pcnt,p1->key,LE1);
1752                }
1753                for (p2=(LINK2 *)lnk2p, loop=qtylk2; loop--; p2++ /* LINK2 */) {
1754                    pstdecod(&(p2->post),&pmfn,&ptag,&pocc,&pcnt);
1755                    prtlink("[ ] ",pmfn,ptag,pocc,pcnt,p2->key,LE2);
1756                }
1757        }
1758
1759#if !LIND /* 17 */
1760/*      if (MFRstatus == ACTIVE && MFRmfbwb) { */
1761        if (flagmod) {
1762#if BEFORE970204
1763          if (!MFRmfbwb) fatal("ciifu/check/MFRmfbwb");
1764#endif
1765          if (MFRmfbwb) {
1766            recreadb=MFRmfbwb;
1767            recreadp=MFRmfbwp;
1768#if CICPP
1769        if (!orecp->recnbytes) orecp->xrecalloc(rec_maxmfrl); // alloc
1770            recread(orecp,MFRmfn); /* get old */
1771            orecp->recrc=RCNORMAL; /* good */
1772#else /* CICPP */
1773            recread(vrecp[orec],MFRmfn); /* get old */
1774            VRECrc(orec)=RCNORMAL; /* good */
1775#if GEN_UTL
1776            if (DBXitrac) prtleader(vrecp[orec],0L);
1777#endif /* GEN_UTL */
1778#endif /* CICPP */
1779
1780#if CICPP
1781            fst->xfst_setrecp(orecp);
1782                if (fst->xfst_inter(1) == -2) {
1783                        fatal("ciifu/fst_inter1");
1784                }
1785                olnk1p=fst->fst_oarea1p;
1786                olnk2p=fst->fst_oarea2p;
1787                oqtylk1=fst->fst_oqtylk1;
1788                oqtylk2=fst->fst_oqtylk2;
1789            fst->xfst_setrecp(recp);    // recp will be deleted in ~FSTSTRU
1790#else /* CICPP */
1791            fst_inter(fstp,orec,stwp,
1792                        &olnk1p,maxlk1,&olnk2p,maxlk2,&oqtylk1,&oqtylk2);
1793#endif /* CICPP */
1794            if (DBXitrac) {
1795                for (p1=(LINK1 *)olnk1p, loop=oqtylk1; loop--; p1++ /* LINK1 */) {
1796                    pstdecod(&(p1->post),&pmfn,&ptag,&pocc,&pcnt);
1797                    prtlink("[B] ",pmfn,ptag,pocc,pcnt,p1->key,LE1);
1798                }
1799                for (p2=(LINK2 *)olnk2p, loop=oqtylk2; loop--; p2++ /* LINK2 */) {
1800                    pstdecod(&(p2->post),&pmfn,&ptag,&pocc,&pcnt);
1801                    prtlink("[B] ",pmfn,ptag,pocc,pcnt,p2->key,LE2);
1802                }
1803            }
1804          } /* MFRmfbwb */
1805          else { /* see recwrite: !pend && rc!=RCNORMAL */
1806#if CICPP
1807            if (!orecp->recnbytes) orecp->xrecalloc(LEADER); // alloc
1808            orecp->recmfp->m1.m1status=DELETED;
1809#else /* CICPP */
1810            VMFRstatus(orec)=DELETED;
1811#endif /* CICPP */
1812          } /* MFRmfbwb */
1813        } /* flagmod */
1814       
1815        /* update the inverted file */
1816        if (flagnew)
1817#endif /* !LIND 17 */
1818            if (MFRstatus == ACTIVE) {
1819                if (DBXitrac) {
1820            prtlink("[ ]+",0L,0,0,0,(UCHR *)"OK new",6);
1821                }
1822/*//*/          svdifupd(lnk1p,qtylk1,lnk2p,qtylk2,             /* add new */
1823/*//*/                   NULL,0,NULL,0,                         /*         */
1824/*//*/                   pstflag,DBXitell);
1825                DBXipadd[0]+=qtylk1;  DBXipadd[1]+=qtylk2;
1826            }
1827#if !LIND /* 16 */
1828        if (flagmod)
1829            if (MFRstatus == DELETED) {                 /* new is deleted */
1830#if CICPP
1831              if (orecp->recmfp->m1.m1status != DELETED) {
1832#else /* CICPP */
1833              if (VMFRstatus(orec) != DELETED) {        /* old is active */
1834#endif /* CICPP */
1835                if (DBXitrac) {
1836            prtlink("[B]-",0L,0,0,0,(unsigned char*)"OK",2);
1837                }
1838/*//*/          svdifupd(NULL,0,NULL,0,                         /*         */
1839/*//*/                   olnk1p,oqtylk1,olnk2p,oqtylk2,         /* del old */
1840/*//*/                   pstflag,DBXitell);
1841                DBXipdel[0]+=oqtylk1; DBXipdel[1]+=oqtylk2;
1842              }
1843            }
1844            else {                                      /* new is active */
1845#if CICPP
1846              if (orecp->recmfp->m1.m1status == DELETED) {
1847#else /* CICPP */
1848              if (VMFRstatus(orec) == DELETED) {        /* old is deleted */
1849#endif /* CICPP */
1850                if (DBXitrac) {
1851            prtlink("[ ]+",0L,0,0,0,(unsigned char*)"OK mod",6);
1852                }
1853/*//*/          svdifupd(lnk1p,qtylk1,lnk2p,qtylk2,             /* add new */
1854/*//*/                   NULL,0,NULL,0,                         /*         */
1855/*//*/                   pstflag,DBXitell);
1856                DBXipadd[0]+=qtylk1;  DBXipadd[1]+=qtylk2;
1857              }
1858              else {                                    /* new is active */
1859                if (DBXitrac) {                         /* old is active */
1860                    prtlink("[ ]+",0L,0,0,0,(unsigned char*)"OK mod",6);
1861                    prtlink("[B]-",0L,0,0,0,(unsigned char*)"OK",2);
1862                }
1863/*//*/          svdifupd(lnk1p,qtylk1,lnk2p,qtylk2,             /* add new */
1864/*//*/                   olnk1p,oqtylk1,olnk2p,oqtylk2,         /* del old */
1865/*//*/                   pstflag,DBXitell);
1866                DBXipadd[0]+=qtylk1;  DBXipadd[1]+=qtylk2;
1867                DBXipdel[0]+=oqtylk1; DBXipdel[1]+=oqtylk2;
1868              }
1869            }
1870
1871#if MULTI_IF
1872        /* unlock IF */
1873        if (DBXnetws != MONONETS) {
1874            upif_end(idbnp,pstflag);
1875            rc=dbxilock(dbxp,NULL,"UI"); 
1876            invflush(idbnp); /* invclose(dbxp); */
1877            if (rc)
1878                if (dbxewlrc) {rc=RCLOCK; break;} else fatal("ciifu/unlock/I");
1879        }
1880#endif /* MULTI_IF */
1881
1882        /* reset .mst bw ptrs and .xrf flags */
1883#if CICPP
1884        if (ifupd_reset) recreset(mdbnp,0L,0L,recp,0L);
1885#else /* CICPP */
1886        if (ifupd_reset) recreset(mdbnp,0L,0L,irec,0L);
1887#endif /* CICPP */
1888
1889#if MULTI_IF
1890        /* lock MF/reset EWL/unlock MF */
1891        if (DBXnetws != MONONETS) {
1892            rc=dbxilock(NULL,mdbnp,"UM");
1893            if (rc)
1894                if (dbxewlrc) {rc=RCLOCK; break;} else fatal("ciifu/unlock/M");
1895        }
1896#endif /* MULTI_IF */
1897
1898#endif /* !LIND 16 */
1899        DBXirecs++;
1900        if (DBXitell)
1901/*          if ((10 * (DBXirecs*100/DBXirang) + 5) / 10)% DBXitell == 0) */
1902            if (DBXirecs % DBXitell == 0) {
1903#if 0
1904fprintf(stderr,"+++ name=%s irecs/itell/irang=%"_LD_"/%"_LD_"/%"_LD_" \n",
1905 DBXname,DBXirecs,DBXitell,DBXirang);
1906#endif
1907#if LINDLUX /* x2999 */
1908                fprintf(stderr,"%s %5"_LD_"  %3"_LD_"%% \n",
1909                    (invp->lvxiflind) ? "+ +" : " + ",
1910                    DBXirecs,
1911                    (10 * (DBXirecs*100/DBXirang) + 5) / 10);
1912#else /* LINDLUX x2999 */
1913#ifdef USE_INFO_SYS
1914//              errsys->sys_info_data(ltoa(mfn,mfnstr,10));
1915                if (wprogress) {
1916                        sprintf(mess_str,"MFN %"_LD_" (%s %5"_LD_")",mfn,mess->get(452),DBXirecs);
1917                        procstr->DataSet(mess_str);
1918                        progbar->Assign(mfn-prog_from,prog_to-prog_from);
1919                        UI_EVENT event;
1920                        wprogress->eventManager->Get(event,Q_NO_BLOCK|Q_BEGIN|Q_DESTROY|Q_POLL);
1921                        if (event.type==10235) {                // EXPORT_CANCEL) {
1922                                int ok=errsys->ErrorMessage(wprogress->windowManager,WOS_INVALID,mess->get(420));
1923                                if (ok==WOS_INVALID) {
1924                                        mfn=-1;    // STOP
1925                                        DS_OperationStopped=1;
1926                                        continue;
1927                                        }
1928                                }
1929                        mainwindow->windowManager->Event(event);
1930                        }
1931#else
1932                fprintf(stderr,"%s %5"_LD_"  %3"_LD_"%%  [mfn=%"_LD_"]\n",
1933                    "+++",
1934                    DBXirecs,
1935                    (10 * (DBXirecs*100/DBXirang) + 5) / 10,
1936                    mfn);
1937#endif
1938#endif /* LINDLUX x2999 */
1939            }
1940    } /* end for */
1941
1942#if MULTI_IF
1943    /* undo dbxilock/L: RCEOF/etc or dbxilock/UI error */
1944    if (DBXnetws != MONONETS) {
1945        /* unlock IF */
1946        if (DBXifmap) if (DBIifopv) {
1947            if (DBXiinit) upif_end(idbnp,pstflag);
1948            rc=dbxilock(dbxp,NULL,"UI");
1949            invflush(idbnp); /* invclose(dbxp); */
1950            if (rc)
1951                if (dbxewlrc) rc=RCLOCK; else fatal("ciifu/unlock/I2");
1952        }
1953        /* lock MF/reset EWL/unlock MF */
1954        if (dbxstorp(mdbnp)->dbxewlxx) {
1955            rc=dbxilock(NULL,mdbnp,"UM");
1956#if BEFORE951103
1957            mstclose(dbxp);
1958#endif
1959            if (rc)
1960                if (dbxewlrc) rc=RCLOCK; else fatal("ciifu/unlock/M2");
1961        }
1962    }
1963#endif /* MULTI_IF */
1964
1965#if SHTEST
1966printf("2."); gets(shtest);
1967if (shtest[0]=='.') system(shtest+1);
1968#endif /* SHTEST */
1969
1970#if CICPP
1971    /* don't delete recp: recp = fst->fst_recp */
1972#else /* CICPP */
1973    libera_prat(irec);
1974#endif /* CICPP */
1975
1976#if !LIND /* 22 */
1977#if CICPP
1978    delete orecp;
1979#else /* CICPP */
1980    libera_prat(orec);
1981#endif /* CICPP */
1982#endif /* !LIND 22 */
1983
1984#if MULTI_IF
1985    if (DBXnetws == MONONETS)
1986#endif
1987    if (endup & IFUPWRIT || endup & IFUPCLOS) {
1988        upif_end(idbnp,pstflag);
1989        invflush(idbnp); /* invclose(dbxp); */
1990#if LIND /* 2y */
1991#include "ciifu2.c"
1992#endif /* LIND 2y */
1993    }
1994
1995#if !CICPP
1996    FREE(lnk1p); lnk1p=NULL;
1997    FREE(lnk2p); lnk2p=NULL;
1998    FREE(olnk1p); olnk1p=NULL;
1999    FREE(olnk2p); olnk2p=NULL;
2000#endif /* CICPP */
2001
2002#if PRINT || LUXPRINT
2003    printf ("\n fim de ifupdat() - nrecs=%"_LD_, nrecs);
2004#endif
2005
2006    trmifupd=0; /* reset IFUPDXUP */
2007
2008    return(rc);
2009}
2010#endif /* INPUTFILE */
Note: See TracBrowser for help on using the browser.