-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcidbx.c
1578 lines (1418 loc) · 36.6 KB
/
cidbx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "cisis.h"
#if PC
#if !MSC
#include <dir.h>
#endif /* !MSC */
#endif
#if MSC
#include <share.h>
#include <sys\locking.h>
#endif
#if CICPP
#define CIDBX_SOURCE
#include <cidbx.hpp>
#include <cirun.hpp>
#ifdef USE_ERROR_SYS
void ISIS_OemToAnsi(char *in, char *out);
#endif
/* ------------------------- CIDBX.HPP --------------------------------- */
#if MULTI
/*#define dbxcinet xdbxcinet moved to CISISX */
#define dbxflock xdbxflock /* internal use */
#define dbxulock xdbxulock /* internal use */
/*#define dbxilock xdbxilock moved to CISISX */
#define dbxwlock xdbxwlock /* internal use */
#endif
/*#define dbxinit xdbxinit moved to CISISX */
/*#define dbxstorp xdbxstorp moved to CISISX */
/*#define dbxsrchp xdbxsrchp moved to CISISX */
/*#define dbxopen xdbxopen moved to CISISX */
/*#define dbxopenw xdbxopenw moved to CISISX */
/*#define dbxopenc xdbxopenc moved to CISISX */
/*#define fatal xfatal moved to CISISX */
#define dbxflush xdbxflush /* internal use */
#define mstclose xmstclose /* internal use */
#define mstflush xmstflush /* internal use */
/*#if RECGIZM */
/*#define gizflush xgizflush moved to CISISX */
/*#endif*/
/*#if RECDECO */
/*#define decflush xdecflush moved to CISISX */
/*#endif */
#define dbxinvmp xdbxinvmp /* internal use */
#define invclose xinvclose /* internal use */
#define invflush xinvflush /* internal use */
/*#define loadfile xloadfile moved to CISISX */
/*#define dbxciset xdbxciset moved to CISISX */
/*#define dbxcipar xdbxcipar moved to CISISX */
#if GIPAR
/*#define dbxgipar xdbxgipar moved to CISISX */
#endif
#define fpccreat xfpccreat /* internal use */
#define fpcwrite xfpcwrite /* internal use */
#define fpcclose xfpcclose /* internal use */
/*#define dbxtmpnm xdbxtmpnm moved to CISISX */
#define cicopyr xcicopyr /* internal use */
#if GEN_CORELEFT
#define coreleft xcoreleft /* internal use */
#endif
#if GEN_LABS
#define labs DBXSTRU::xlabs /* internal use */
#endif
#if GEN_STRSTR
#define strstr DBXSTRU::xstrstr /* internal use */
#endif
#if GEN_STRUPR
#define strupr DBXSTRU::xstrupr /* internal use */
#endif
#if GEN_STRREV
#define strrev DBXSTRU::xstrrev /* internal use */
#endif
#if GEN_MEMICMP
#define memicmp DBXSTRU::xmemicmp /* internal use */
#endif
/* --------------------------------------------------------------------- */
#endif /* CICPP */
#ifdef USE_ERROR_SYS /* Peter Diry error window (compiler environment) */
#include <ui_win.hpp>
#include <errorsys.hpp>
extern MY_ERROR_SYSTEM * errsys;
#endif
/* ----------------------------- dbx.c ------------------------------ */
#define DBXTRACw 0
#define DBXTRAC0 0
#define DBXTRAC1 0
#define DBXTRAC2 0
#define CNVTRACE 0
#define DBXTRACE 1 /* dbxtrace */
#define DBGTRACE 1 /* dbxtrace */
#define SHTEST 0
#if !CICPP
#if SHTEST
static char shtest[CIMPL+1];
#endif /* SHTEST */
#if CNV_PCBINUM
char cnv_pcbuff[MAXMFRL]; /* PC data representation (swapped) */
#endif
#if CNV_PCFILES
UCHR nodeunibuff[N2BSIZ]; /* area para ler pagina de .n01/.n02 */
#endif
#if LEAFCNV_PCFILES
UCHR leafunibuff[L2BSIZ]; /* area para ler pagina de .l01/.l02 */
#endif
#endif /* !CICPP */
#if !CICPP
/* global */
int partrace=0; /* dbxopen/dbxcipar trace */
int dbxtrace=0; /* dbxopen/dbxcipar trace */
int rectrace=0; /* rec RESTRACE runtime switch */
int dectrace=0; /* decoread()/recdeco() runtime switch */
int trmtrace=0; /* trm TRSTRACE runtime switch */
int b40trace=0; /* b40 RUXTRACE runtime switch */
int b50trace=0; /* b50 RUXTRACE runtime switch */
int b70trace=0; /* b70 RUXTRACE runtime switch */
int fmttrace=0; /* fmt runtime switch */
int fsttrace=0; /* fst FSSTRACE runtime switch */
int multrace=0; /* upd MULTRACE runtime switch */
int cgitrace=0; /* cicgi trace */
int bugadddel=1; /* 13/03/94 */
int dbxopt_fatal = 1; /* dbxopen() - fatal when file doesn't exist */
int dbxopt_errno = 1; /* dbxopen() - dbname/errno msg before fatal */
int dbxopt_mflush = 0; /* record() - flush lastrecread if != dbname */
int dbxopt_mclose = 0; /* record() - close lastrecread if != dbname */
int dbxopt_iflush = 0; /* term() - flush lasttrmread if != dbname */
LONGX rec_maxmfrl=MAXMFRL; /* 25/02/97 */
LONGX rec_mstload=0L; /* 28/03/97 */
LONGX trm_invload=0L; /* 28/03/97 */
LONGX fmt_fsiz=MAXMFRL; /* fmt_inter() - to set max field length */
#if MULTI
#if BEFOREISIS301
off_t dbxfloff=0L; /* dbxflock()/dbxulock() - offset */
LONGX dbxflsiz=MSBSIZ; /* dbxflock()/dbxulock() - length */
#else
off_t dbxfloff=MSBSIZ; /* dbxflock()/dbxulock() - offset = blk #2 */
LONGX dbxflsiz=MSBSIZ; /* dbxflock()/dbxulock() - length */
#endif
#if BEFORE990317
int dbxfloop = INT_MAX; /* dbxflock() - #retries */
int dbxwloop = INT_MAX; /* dbxwlock() - #retries */
int dbxiloop = INT_MAX; /* dbxilock() - #retries */
#else
int dbxfloop = SHRT_MAX; /* dbxflock() - #retries */
int dbxwloop = SHRT_MAX; /* dbxwlock() - #retries */
int dbxiloop = SHRT_MAX; /* dbxilock() - #retries */
#endif
int dbxuclos = 1; /* dbxulock() - close/reopen */
int dbxewlrc = 0; /* dbxflock()/dbxwlock() error action */
int dbxsleep = 0; /* dbxilock() seconds to sleep */
#endif /* MULTI */
#if MULTI
int dbxopt_ordwr = O_RDONLY; /* dbxopen() */
#else
int dbxopt_ordwr = O_RDONLY; /* dbxopen() - O_RDWR / O_RDONLY */
#endif
int dbxordwr = 0; /* dbxopen() - dbxopt_ordwr & O_RDWR */
unsigned char bitmask[8] = { 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01 };
int fpc_fd=0; /* fpccreat()/fpcwrite()/fpcclose() */
FFI fpc_left=FPCBSIZ; /* fpccreat()/fpcwrite()/fpcclose() */
char *fpc_buffer=NULL; /* fpccreat()/fpcwrite()/fpcclose() */
int vlex[NTREE] = { LE1, LE2 }; /* use it */
int nxbsiz[NTREE] = { N1BSIZ, N2BSIZ }; /* use it */
int lxbsiz[NTREE] = { L1BSIZ, L2BSIZ }; /* use it */
char *mx1extp = ".mst"; /* mstsetup/recisis0 */
char *xx1extp = ".xrf"; /* mstsetup/recisis0 */
char *cx1extp = ".cnt"; /* invsetup/trmisis0 */
char *nx12extp[NTREE] = { ".n01", ".n02" }; /* invsetup/trmisis0 */
#if LIND
char *lx12extp[NTREE] = { ".ly1", ".ly2" }; /* invsetup/trmisis0 */
char *ix1extp = ".iyp"; /* invsetup/trmisis0 */
#else
char *lx12extp[NTREE] = { ".l01", ".l02" }; /* invsetup/trmisis0 */
char *ix1extp = ".ifp"; /* invsetup/trmisis0 */
#endif
#if CNLI
char *iy0extp = ".iy0"; /* All IF into 1. To ALP, WL */
#endif
#if MULTI
int cipnetws=MONONETS; /* MULTI default operation */
#endif
#if DBXMSTXL
#if ( LIND4 || SUPERISIS==1 ) && _LARGEFILE64_SOURCE
int cipmstxl=6; /* extended .mst capacity */
#elif CIFFI
int cipmstxl=4; /* extended .mst capacity */
#else
int cipmstxl=0; /* extended .mst capacity */
#endif
#endif
#if BEFORE20000323 /* because some BRM's GCC - ask rpiva */
FILE *cistderr=stderr; /* 20/05/98 (Asael!) */
#else
#define cistderr stderr
#endif
/* ----------------------------- par.c ------------------------------ */
/* global */
FILE *dbxcipfp = NULL; /* dbxcipar() input parameter file pointer */
char *dbxcdcip = NULL; /* dbxcipar() input data */
char dbxcikey[BUFSIZ]; /* dbxcipar() actual file name */
int dbxcipok = 0; /* dbxcipar() found */
#if GIPAR
char dbxgikey[BUFSIZ]; /* dbxgipar() actual file name */
char *dbxgiext[] = {
".xrf",".mst",
".cnt",".n01",".n02",
#if LIND
".ly1",".ly2",".iyp",
#else /* LIND */
".l01",".l02",".ifp",
#endif /* LIND */
/*
xx1extp, mx1extp,
cx1extp,
nx12extp[0], nx12extp[1],
lx12extp[0], lx12extp[1],
ix1extp,
*/
".any",
".fdt",".fst",".fmt",".pft",".stw",".srt",".wpr",".val",
/*
iy0extp,
*/
NULL }; /* bc4.5/C++ */
int dbxgiexn[] = { 1,2,
3,
4,5,
6,7,
8,
9,
10,10,10,10,10,10,10,10
/*
,11
*/ };
#endif /* GIPAR */
#endif /* !CICPP */
#if !CICPP
#define CIDBX_CISISX_SOURCE 1
#include "cisisx.c"
#endif
#if CICPP
DBXSTRU :: DBXSTRU(CISISX *parm_cisisxp)
{
memset(this,0x00,sizeof(DBXSTRU));
cisisxp = parm_cisisxp;
//try {
//}
//catch {
//}
//strncpy(dbxname,dbnamep,*highv);
}
#endif /* CICPP */
#if MULTI
#if CICPP
int DBXSTRU :: xdbxflock(DBXSTRU *dbxp,
char *typ)
#else /* CICPP */
int dbxflock(dbxp,typ)
DBXSTRU *dbxp;
char *typ;
#endif /* CICPP */
{
int floop; /* dbxflock() - #retries */
int rc,fd=0,type=0;
int opw,*opvp;
if (!dbxp) fatal("dbxflock/dbxp");
if (dbxtrace) printf("+++ dbxflock - %s / %s \n",DBXname,typ);
if (strcmp(typ,"M") == 0) {
type=1; fd=DBXmsopn; opw=DBXmsopw; opvp= &DBXmsopv;
}
if (strcmp(typ,"I") == 0) {
type=2; fd=DBIifopn; opw=DBIifopw; opvp= &DBIifopv;
}
if (!type) fatal("dbxflock/type");
if (fd <= 0) fatal("dbxflock/fd");
if (!opw) fatal("dbxflock/file is not opened for write");
if (*opvp) fatal("dbxflock/file is locked");
for (floop=dbxfloop; floop--; ) { /* dbxflock() - #retries */
#if PC
#if MSC
if (LSEEK64(fd,dbxfloff,SEEK_SET) != dbxfloff) fatal("dbxflock/lseek");
rc=locking(fd,LK_LOCK,dbxflsiz);
#else
rc=lock(fd,dbxfloff,dbxflsiz);
#endif
#else
if (LSEEK64(fd,dbxfloff,SEEK_SET) != dbxfloff) fatal("dbxflock/lseek");
rc=lockf(fd,F_TLOCK,dbxflsiz);
#endif
if (rc == 0) { (*opvp)++; /* locked */ return(0); }
if (floop == 0) {
if (multrace)
printf("<F> File %s (%s) is locked by another user\n",DBXname,typ);
#if SHTEST
printf(".."); if (*gets(shtest)) if (strcmp(shtest,"x")) system(shtest); else fatal("dbxflock/shtest");
#endif
return(RCLOCK);
}
}
return(rc);
}
#if CICPP
int DBXSTRU :: xdbxulock(DBXSTRU *dbxp,
char *typ)
#else /* CICPP */
int dbxulock(dbxp,typ)
DBXSTRU *dbxp;
char *typ;
#endif /* CICPP */
{
int rc,fd,type=0;
char *extp;
int *opnp,*opwp,*opvp;
if (!dbxp) fatal("dbxulock/dbxp");
if (dbxtrace) printf("+++ dbxulock - %s / %s \n",DBXname,typ);
if (strcmp(typ,"M") == 0) {
type=1;
opnp= &DBXmsopn; extp=mx1extp; opwp= &DBXmsopw; opvp= &DBXmsopv;
}
if (strcmp(typ,"I") == 0) {
type=2;
opnp= &DBIifopn; extp=ix1extp; opwp= &DBIifopw; opvp= &DBIifopv;
}
if (!type) fatal("dbxulock/type");
fd= *opnp;
if (dbxtrace)
printf("+++ dbxulock - fd=%d ext=%s opw=%d opv=%d\n",fd,extp,*opwp,*opvp);
if (fd <= 0) fatal("dbxulock/fd");
if (!*opwp) fatal("dbxulock/file is not opened for write");
if (!*opvp) fatal("dbxulock/file is not locked");
#if PC
#if MSC
if (LSEEK64(fd,dbxfloff,SEEK_SET) != dbxfloff) fatal("dbxulock/lseek");
rc=locking(fd,LK_UNLCK,dbxflsiz);
#else
rc=unlock(fd,dbxfloff,dbxflsiz);
#endif
#else
if (LSEEK64(fd,dbxfloff,SEEK_SET) != dbxfloff) fatal("dbxulock/lseek");
rc=lockf(fd,F_ULOCK,dbxflsiz);
#endif
*opvp=0; /* unlocked */
if (dbxuclos < 0) {
if (dbxtrace) printf("dbxulock - will close %d \n",fd);
CLOSE(fd); *opnp=0; *opwp=0;
}
else {
if (dbxtrace) printf("dbxulock - will close/open %d \n",fd);
*opwp=0; /* force close&open/w in dbxopenw */
dbxopenw(DBXname,DBXname,extp,opnp,opwp,"dbxulock/reopn/w");
}
return(rc);
}
#if CICPP
int DBXSTRU :: xdbxwlock(DBXSTRU *dbxp,
char *m0p,
int times)
#else /* CICPP */
int dbxwlock(dbxp,m0p,times)
DBXSTRU *dbxp;
char *m0p;
int times;
#endif /* CICPP */
{
char m0area[sizeof(M0STRU)];
int wloop,n;
if (dbxtrace)
printf("+++ dbxwlock - %s %p %d (%d)\n",DBXname,m0p,times,DBXewlxx);
if (!m0p) m0p=m0area;
for (wloop=times; wloop--; ) {
/* get the control record */
if (LSEEK64(DBXmsopn,0L,SEEK_SET) != 0) fatal("dbxwlock/lock/LSEEK64/ewl");
n=CIREAD(DBXmsopn,m0p,sizeof(M0STRU));
#if CNV_PCBINUM
ConvertMST_CTLSTRUCT(m0p);
#endif
if (n != sizeof(M0STRU)) fatal("dbxwlock/lock/read/ewl");
#if DBXMSTXL /* AOT 18/06/2002 */
((M0STRU *)m0p)->m0mftype = ((M0STRU *)m0p)->m0mftype & 0x00FF;
#endif
if (((M0STRU *)m0p)->m0mfcxx3 == 0) break;
if (multrace) printf("<W> %s has exclusive write lock\n",DBXname);
if (DBXewlxx) break; /* user's ewl */
/* .mst file lock: unlock */
if (multrace) printf("<W> %s .mst unlock/ewl \n",DBXname);
if (dbxulock(dbxp,"M")) fatal("dbxwlock/lock/file unlock/ewl");
if (wloop == 0) {
if (multrace)
printf("<W> Database %s is locked by another user\n",DBXname);
#if SHTEST
printf(".."); if (*gets(shtest)) if (strcmp(shtest,"x")) system(shtest); else fatal("dbxwlock/shtest");
#endif
return(RCLOCK);
}
/* .mst file lock: lock */
if (multrace) printf("<W> %s .mst lock/ewl \n",DBXname);
if (dbxflock(dbxp,"M"))
#if BEFORE20000608
fatal("dbxwlock/lock/file lock/ewl");
#else
return(RCLOCK);
#endif
}
return(0);
}
#endif /* MULTI */
#if CICPP
void DBXSTRU :: xdbxflush(char *dbnamp)
#else /* CICPP */
void dbxflush(dbnamp) /*
-------------
seta dbxp;
flush master e invertido;
libera dbxp;
reloca vdbxp[]
*/
char *dbnamp; /* dbn to be flushed */
#endif /* CICPP */
{
DBXSTRU *dbxp;
LONGX idbx;
#if DBXTRACE
char dbname[sizeof(dbxp->dbxname)];
#endif
dbxp=dbxsrchp(dbnamp);
if (dbxp == NULL)
return;
mstflush(dbnamp);
invflush(dbnamp);
for (idbx=ndbxs; idbx--; )
if (strcmp(VDBXname(idbx),dbnamp) == 0) {
#if DBXTRACE
if (dbxtrace) strcpy(dbname,dbnamp);
#endif
#if GIPAR
if (DBXgicip) {
#if CICPP
delete [] DBXgicip;
#else /* CICPP */
FREE(DBXgicip);
#endif /* CICPP */
}
#endif /* GIPAR */
#if BEFORE981202
#if CICPP
delete vdbxp[idbx];
#else /* CICPP */
FREE(vdbxp[idbx]);
#endif /* CICPP */
vdbxp[idbx]=(DBXSTRU *)NULL;
while (++idbx < ndbxs) vdbxp[idbx-1] = vdbxp[idbx];
ndbxs--;
#else /* BEFORE */
/* Agora mantem estrutura - apenas reinicializa */
#if CICPP
CISISX *cp = dbxp->cisisxp;
memset(dbxp,0x00,sizeof(DBXSTRU)); /* init everything */
dbxp->cisisxp = cp;
#else /* CICPP */
memset(dbxp,0x00,sizeof(DBXSTRU)); /* init everything */
#endif /* CICPP */
strcpy(DBXname,dbnamp); /* store dbnamp */
/* HB/ISIS_DLL precisa de ndbxs--; para nao cair */
/* rever dbxgipar: chamar dbxsrchp e nao dbxstorp */
#endif /* BEFORE */
#if DBXTRACE
if (dbxtrace) printf("dbxflush - dbnamp='%s' \n",dbname);
#endif
#if DBXTRAC2
for (idbx=0L; idbx < ndbxs; idbx++)
printf("dbxflush - ndbxs=%"_LD_" idbx=%"_LD_"=%s=%p \n",
ndbxs,idbx,VDBXname(idbx),vdbxp[idbx]);
#endif
return;
}
fatal("dbxflush");
}
#if CLOSEX
int CLOSE(fd)
int fd;
{
#define XTC 0
#if XTC
unsigned int eof;
#endif /* CICPP */
#if 0
int n;
for (n=0; n<HANDLE_MAX; n++)
printf("openfd[%d] = %04x\n",n,_openfd[n]);
#endif
if (dbxtrace) printf("+++ CLOSE/closing %d\n",fd);
#if XTC
if (fd < 0 || fd >= HANDLE_MAX) fatal("CLOSE/fd");
eof=(unsigned int)EOF;
if (_openfd[fd] == eof) fatal("CLOSE/openfd");
#endif
return(CLOSEX(fd));
}
#endif
/* ----------------------------- std.c ------------------------------ */
/* ----------------------------- flush.c ------------------------------ */
#if CICPP
void DBXSTRU :: xmstclose(DBXSTRU *dbxp)
#else /* CICPP */
void mstclose(dbxp) /*
-------------
faz close dos arquivos abertos do master file
*/
DBXSTRU *dbxp;
#endif /* CICPP */
{
if (dbxp == NULL) return;
if (DBXmsopn) {
CLOSE(DBXmsopn); DBXmsopn=DBXmsopw=DBXmsopv=0;
}
if (DBXxropn) {
CLOSE(DBXxropn); DBXxropn=DBXxropw=0;
}
}
#if CICPP
void DBXSTRU :: xmstflush(char *dbnamp)
#else /* CICPP */
void mstflush(dbnamp) /*
-------------
seta dbxp;
faz close dos arquivos abertos do master file
flush gizmo,etc;
*/
char *dbnamp; /* dbn to be flushed */
#endif /* CICPP */
{
DBXSTRU *dbxp;
dbxp=dbxsrchp(dbnamp);
if (dbxp == NULL) return;
#if RECGIZM
if (DBXvgzrp) { gizflush(DBXvgzrp); DBXvgzrp=NULL; }
#endif
#if RECDECO
if (DBXvderp) { decflush(DBXvderp); DBXvderp=NULL; }
#endif
if (DBXxribp != NULL) {
#if CICPP
delete [] DBXxribp;
#else /* CICPP */
FREE(DBXxribp);
#endif /* CICPP */
DBXxribp=NULL;
}
if (DBXmsibp != NULL) {
#if CICPP
delete [] DBXmsibp;
#else /* CICPP */
FREE(DBXmsibp);
#endif /* CICPP */
DBXmsibp=NULL;
}
if (DBXxryyp != NULL) {
#if CICPP
delete [] DBXxryyp;
#else /* CICPP */
FREE(DBXxryyp);
#endif /* CICPP */
DBXxryyp=NULL;
}
if (DBXmsyyp != NULL) {
#if CICPP
delete [] DBXmsyyp;
#else /* CICPP */
FREE(DBXmsyyp);
#endif /* CICPP */
DBXmsyyp=NULL;
}
mstclose(dbxp);
}
#if CICPP
INVMAP * DBXSTRU :: xdbxinvmp(DBXSTRU *dbxp)
#else /* CICPP */
INVMAP *dbxinvmp(dbxp) /*
-----------------
aloca/seta dbxifmap
*/
DBXSTRU *dbxp;
#endif /* CICPP */
{
INVMAP *invp;
#if !CICPP
LONGX lvar;
#endif /* CICPP */
if (!DBXifmap) { /* funtion */
#if CICPP
try { invp=(INVMAP *) new char [(sizeof(INVMAP))]; }
catch (BAD_ALLOC) { invp = (INVMAP *)ALLONULL; }
#else /* CICPP */
lvar=sizeof(INVMAP);
if ((lvar) > ALLOMAXV)
fatal("dbxinvmp/ALLOMAXV/sizeof(INVMAP)");
invp=(INVMAP *)ALLOC((ALLOPARM)(sizeof(INVMAP)));
#endif /* CICPP */
if (invp == (INVMAP *)ALLONULL) fatal("dbxinvmp/ALLOC/invmap");
memset(invp,0x00,sizeof(INVMAP));
DBXifmap=invp;
}
if (dbxtrace) printf("+++ dbxinvmp - %s = %p\n",DBXname,DBXifmap);
return(DBXifmap);
}
#if CICPP
void DBXSTRU :: xinvclose(DBXSTRU *dbxp)
#else /* CICPP */
void invclose(dbxp) /*
-------------
faz close dos arquivos abertos do inverted file
*/
DBXSTRU *dbxp;
#endif /* CICPP */
{
INVMAP *invp;
#if SAMEL
int lxx;
#endif
if (dbxp == NULL) return;
if (DBXifmap) {
invp=DBXifmap;
#if SAMEL
for (lxx=0; lxx < MAXSAMEL; )
if (invp->ifopn[lxx]) CLOSE(invp->ifopn[lxx]);
#else
if (invp->ifopn) CLOSE(invp->ifopn); /* 1st */
#endif
if (invp->cnopn) CLOSE(invp->cnopn);
if (invp->n1opn) CLOSE(invp->n1opn);
if (invp->n2opn) CLOSE(invp->n2opn);
if (invp->l1opn) CLOSE(invp->l1opn);
if (invp->l2opn) CLOSE(invp->l2opn);
invp->cnopn=invp->cnopw=0;
invp->n1opn=invp->n1opw=0;
invp->n2opn=invp->n2opw=0;
invp->l1opn=invp->l1opw=0;
invp->l2opn=invp->l2opw=0;
invp->ifopn=invp->ifopw=0;
}
}
#if CICPP
void DBXSTRU :: xinvflush(char *dbnamp)
#else /* CICPP */
void invflush(dbnamp) /*
-------------
seta dbxp;
faz close dos arquivos abertos do inverted file
*/
char *dbnamp; /* dbn to be flushed */
#endif /* CICPP */
{
DBXSTRU *dbxp;
INVMAP *invp;
int treecase;
NXSTRU *nxp;
int level;
dbxp=dbxsrchp(dbnamp);
if (dbxp == NULL) return;
if (DBXifmap) {
invclose(dbxp);
invp=DBXifmap;
for (treecase=0; treecase<2; treecase++) {
for (level=invp->cn[treecase].liv; level>=0; level--) {
if ((nxp= &invp->nx[treecase][level]) != NULL)
#if CICPP
delete [] nxp->basep;
#else /* CICPP */
FREE(nxp->basep);
#endif /* CICPP */
}
}
for (treecase=0; treecase<2; treecase++) {
if (invp->nybasep[treecase] != NULL)
#if CICPP
delete [] invp->nybasep[treecase];
#else /* CICPP */
FREE(invp->nybasep[treecase]);
#endif /* CICPP */
}
for (treecase=0; treecase<2; treecase++) {
if (invp->lybasep[treecase] != NULL)
#if CICPP
delete [] invp->lybasep[treecase];
#else /* CICPP */
FREE(invp->lybasep[treecase]);
#endif /* CICPP */
}
if (invp->iybasep != NULL)
#if CICPP
delete [] invp->iybasep;
#else /* CICPP */
FREE(invp->iybasep);
#endif /* CICPP */
if (invp->ifl1p != NULL)
#if CICPP
delete [] invp->ifl1p;
#else /* CICPP */
FREE(invp->ifl1p);
#endif /* CICPP */
if (invp->ifl2p != NULL)
#if CICPP
delete [] invp->ifl2p;
#else /* CICPP */
FREE(invp->ifl2p);
#endif /* CICPP */
#if CICPP
delete [] invp;
#else /* CICPP */
FREE(invp);
#endif /* CICPP */
DBXifmap=NULL;
}
}
/* ***************** Standard Library extensions **************** */
#if GEN_CORELEFT
#if CICPP
unsigned LONGX DBXSTRU :: xcoreleft(void)
#else /* CICPP */
unsigned LONGX coreleft()
#endif /* CICPP */
{
#if UNIX && !GCC
LONGX bytes;
bytes=ulimit(3,0L)-(LONGX)sbrk(0);
if (dbxtrace) printf("+++ coreleft=%"_LD_"\n",bytes);
return((unsigned LONGX)bytes);
#else
return(ALLOMAXV);
#endif
}
#endif /* GEN_CORELEFT */
#if GEN_LABS
#if CICPP
long DBXSTRU :: xlabs(long x)
#else /* CICPP */
long labs(x)
long x;
#endif /* CICPP */
{
if (x < 0) return(-x); else return(x);
}
#endif /* GEN_LABS */
#if GEN_STRSTR
#if CICPP
char * DBXSTRU :: xstrstr (CONST char *p1,
CONST char *p2)
#else /* CICPP */
char *strstr(p1, p2)
CONST char *p1;
CONST char *p2;
#endif /* CICPP */
{
char *p3, *p4;
do {
for ( ; *p1 != *p2; p1++) if (*p1 == '\0') return (NULL);
for (p3 = p1, p4 = p2; ; p3++, p4++) {
if (*p4 == '\0') return (p1);
if (*p3 != *p4) break;
}
p1++;
} while (*p1 != '\0');
return (NULL);
}
#endif /* GEN_STRSTR */
#if GEN_STRUPR
#if CICPP
char * DBXSTRU :: xstrupr (char* p)
#else /* CICPP */
char *strupr(p)
char *p;
#endif /* CICPP */
{
char *p1;
for (p1 = p; *p1; p1++) *p1 = toupper (*p1);
return (p);
}
#endif /* GEN_STRUPR */
#if GEN_STRREV
#if CICPP
char * DBXSTRU :: xstrrev (char *p)
#else /* CICPP */
char *strrev(p)
char *p;
#endif /* CICPP */
{
char *p1, *p2, c;
int lp;
lp = strlen(p);
p2 = p+lp-1;
lp = lp/2;
for (p1 = p; lp; lp--, p1++, p2--) {
c = *p1;
*p1 = *p2;
*p2 = c;
}
return (p);
}
#endif /* GEN_STRREV */
#if GEN_MEMICMP
#if CICPP
int DBXSTRU :: xmemicmp(CONST void *s1,
CONST void *s2,
size_t n)
#else /* CICPP */
int memicmp(s1, s2, n)
CONST void *s1;
CONST void *s2;
size_t n;
#endif /* CICPP */
{
size_t loop;
int rc;
unsigned char *p1,*p2;
for (rc=0, p1=(unsigned char *)s1, p2=(unsigned char *)s2, loop=n; loop--; p1++, p2++) {
rc=(int)*p1-(int)*p2;
if (rc) break;
}
return(rc);
}
#endif /* GEN_MEMICMP */
/* *********************** fpc_ extension ******************** */
#if CICPP
void DBXSTRU :: xfpcwrite(char *recbufp,
FFI reclen)
#else /* CICPP */
void fpcwrite(recbufp,reclen)
char *recbufp;
FFI reclen;
#endif /* CICPP */
{
char *p;
#if fpc_TRACE
FFI loop;
for (p=recbufp, loop=0; loop<reclen; p++) {
/* printf("%02x ",*p); */
printf("%02x%c ",*p,isprint(*p)?*p:' ');
if (++loop%16 == 0) printf("\n");
}
printf("\n");
#endif
/* allocate fpcwrite() output buffer */
if (!fpc_buffer) {
#if CICPP
try { fpc_buffer= new char [FPCBSIZ]; }
catch (BAD_ALLOC) { fpc_buffer=(char *)NULL; }
#else /* CICPP */
fpc_buffer=(char *)ALLOC((ALLOPARM)FPCBSIZ);
#endif /* CICPP */
if (fpc_buffer == (char *)ALLONULL)
fatal("fpcwrite/ALLOC/fpc_buffer");
#if fpc_TRACE
if (dbxtrace) printf("fpc_buffer: coreleft=%"_LD_"\n",CORELEFT());
#endif
}
if (!fpc_fd) fatal("fpcwrite/fd");
for (p=recbufp; reclen; ) {
if (reclen <= fpc_left) {
memmove(&fpc_buffer[FPCBSIZ-fpc_left],p,(size_t)reclen);
fpc_left-=reclen;
break;
}
memmove(&fpc_buffer[FPCBSIZ-fpc_left],p,fpc_left);
if (CIWRITE(fpc_fd,fpc_buffer,FPCBSIZ) != FPCBSIZ)
fatal("fpcwrite/write");
reclen-=fpc_left;
p+=fpc_left;
fpc_left=FPCBSIZ;
}
}
#if CICPP
void DBXSTRU :: xfpcclose(void)
#else /* CICPP */
void fpcclose()
#endif /* CICPP */
{
FFI n;
if (fpc_left < FPCBSIZ) {
if (/* fpc_left < 0 || */ fpc_left > FPCBSIZ) fatal("fpcclose/left");
if (!fpc_fd) fatal("fpcclose/fd");