root/trunk/cidbx.c

Revision 391, 36.4 kB (checked in by heitor.barbieri, 2 weeks ago)

default master creation size changed in cisisb

Line 
1#include <stdio.h>
2#include <string.h>
3#include <ctype.h>
4
5#include "cisis.h"
6
7#if PC
8#if !MSC
9#include <dir.h>
10#endif /* !MSC */
11#endif
12
13#if MSC
14#include <share.h>
15#include <sys\locking.h>
16#endif
17
18#if CICPP
19#define CIDBX_SOURCE
20#include <cidbx.hpp>
21#include <cirun.hpp>
22
23#ifdef USE_ERROR_SYS
24void ISIS_OemToAnsi(char *in, char *out);
25#endif
26
27/* ------------------------- CIDBX.HPP --------------------------------- */
28#if MULTI
29/*#define dbxcinet  xdbxcinet    moved to CISISX */
30#define dbxflock  xdbxflock   /* internal use */
31#define dbxulock  xdbxulock   /* internal use */
32/*#define dbxilock  xdbxilock    moved to CISISX */
33#define dbxwlock  xdbxwlock   /* internal use */
34#endif
35/*#define dbxinit   xdbxinit     moved to CISISX */
36/*#define dbxstorp  xdbxstorp    moved to CISISX */
37/*#define dbxsrchp  xdbxsrchp    moved to CISISX */
38/*#define dbxopen   xdbxopen     moved to CISISX */
39/*#define dbxopenw  xdbxopenw    moved to CISISX */
40/*#define dbxopenc  xdbxopenc    moved to CISISX */
41/*#define fatal     xfatal       moved to CISISX */
42#define dbxflush  xdbxflush   /* internal use */
43#define mstclose  xmstclose   /* internal use */
44#define mstflush  xmstflush   /* internal use */
45/*#if RECGIZM */
46/*#define gizflush  xgizflush    moved to CISISX */
47/*#endif*/
48/*#if RECDECO */
49/*#define decflush  xdecflush    moved to CISISX */
50/*#endif */
51#define dbxinvmp  xdbxinvmp   /* internal use */
52#define invclose  xinvclose   /* internal use */
53#define invflush  xinvflush   /* internal use */
54/*#define loadfile  xloadfile    moved to CISISX */
55/*#define dbxciset  xdbxciset    moved to CISISX */
56/*#define dbxcipar  xdbxcipar    moved to CISISX */
57#if GIPAR
58/*#define dbxgipar  xdbxgipar    moved to CISISX */
59#endif
60#define fpccreat  xfpccreat   /* internal use */
61#define fpcwrite  xfpcwrite   /* internal use */
62#define fpcclose  xfpcclose   /* internal use */
63/*#define dbxtmpnm  xdbxtmpnm    moved to CISISX */
64#define cicopyr   xcicopyr    /* internal use */
65#if GEN_CORELEFT
66#define coreleft  xcoreleft   /* internal use */
67#endif
68#if GEN_LABS
69#define labs      DBXSTRU::xlabs       /* internal use */
70#endif
71#if GEN_STRSTR
72#define strstr    DBXSTRU::xstrstr     /* internal use */
73#endif
74#if GEN_STRUPR
75#define strupr    DBXSTRU::xstrupr     /* internal use */
76#endif
77#if GEN_STRREV
78#define strrev    DBXSTRU::xstrrev     /* internal use */
79#endif
80#if GEN_MEMICMP
81#define memicmp   DBXSTRU::xmemicmp    /* internal use */
82#endif
83/* --------------------------------------------------------------------- */
84#endif /* CICPP */
85
86
87#ifdef USE_ERROR_SYS    /* Peter Diry error window (compiler environment) */
88#include <ui_win.hpp>
89#include <errorsys.hpp>
90extern MY_ERROR_SYSTEM * errsys;
91#endif
92
93/* ----------------------------- dbx.c ------------------------------ */
94#define DBXTRACw    0
95#define DBXTRAC0    0
96#define DBXTRAC1    0
97#define DBXTRAC2    0
98#define CNVTRACE    0
99
100#define DBXTRACE    1           /* dbxtrace */
101#define DBGTRACE    1           /* dbxtrace */
102
103#define SHTEST      0
104
105#if !CICPP
106#if SHTEST
107static char shtest[CIMPL+1];
108#endif /* SHTEST */
109
110#if CNV_PCBINUM
111char cnv_pcbuff[MAXMFRL];       /* PC data representation (swapped) */
112#endif
113
114#if CNV_PCFILES
115UCHR nodeunibuff[N2BSIZ];       /* area para ler pagina de .n01/.n02 */
116#endif
117#if LEAFCNV_PCFILES
118UCHR leafunibuff[L2BSIZ];       /* area para ler pagina de .l01/.l02 */
119#endif
120
121#endif /* !CICPP */
122
123#if !CICPP
124/* global */
125int partrace=0;                 /* dbxopen/dbxcipar trace */
126int dbxtrace=0;                 /* dbxopen/dbxcipar trace */
127int rectrace=0;                 /* rec RESTRACE runtime switch */
128int dectrace=0;                 /* decoread()/recdeco() runtime switch  */
129int trmtrace=0;                 /* trm TRSTRACE runtime switch */
130int b40trace=0;                 /* b40 RUXTRACE runtime switch */
131int b50trace=0;                 /* b50 RUXTRACE runtime switch */
132int b70trace=0;                 /* b70 RUXTRACE runtime switch */
133int fmttrace=0;                 /* fmt runtime switch */
134int fsttrace=0;                 /* fst FSSTRACE runtime switch */
135int multrace=0;                 /* upd MULTRACE runtime switch */
136int cgitrace=0;                 /* cicgi trace */
137int bugadddel=1;                /* 13/03/94 */
138
139int dbxopt_fatal = 1;           /* dbxopen() - fatal when file doesn't exist */
140int dbxopt_errno = 1;           /* dbxopen() - dbname/errno msg before fatal */
141
142int dbxopt_mflush = 0;          /* record() - flush lastrecread if != dbname */
143int dbxopt_mclose = 0;          /* record() - close lastrecread if != dbname */
144int dbxopt_iflush = 0;          /* term() - flush lasttrmread if != dbname */
145
146LONGX rec_maxmfrl=MAXMFRL;      /* 25/02/97 */
147LONGX rec_mstload=0L;           /* 28/03/97 */
148LONGX trm_invload=0L;           /* 28/03/97 */
149
150LONGX fmt_fsiz=MAXMFRL;               /* fmt_inter() - to set max field length */
151
152#if MULTI
153#if BEFOREISIS301
154off_t dbxfloff=0L;              /* dbxflock()/dbxulock() - offset */
155LONGX dbxflsiz=MSBSIZ;          /* dbxflock()/dbxulock() - length */
156#else
157off_t dbxfloff=MSBSIZ;          /* dbxflock()/dbxulock() - offset = blk #2 */
158LONGX dbxflsiz=MSBSIZ;          /* dbxflock()/dbxulock() - length */
159#endif
160#if BEFORE990317
161int dbxfloop = INT_MAX;         /* dbxflock() - #retries */
162int dbxwloop = INT_MAX;         /* dbxwlock() - #retries */
163int dbxiloop = INT_MAX;         /* dbxilock() - #retries */
164#else
165int dbxfloop = SHRT_MAX;         /* dbxflock() - #retries */
166int dbxwloop = SHRT_MAX;         /* dbxwlock() - #retries */
167int dbxiloop = SHRT_MAX;         /* dbxilock() - #retries */
168#endif
169int dbxuclos = 1;               /* dbxulock() - close/reopen */
170int dbxewlrc = 0;               /* dbxflock()/dbxwlock() error action */
171int dbxsleep = 0;               /* dbxilock() seconds to sleep */
172#endif /* MULTI */
173
174#if MULTI
175int dbxopt_ordwr = O_RDONLY;    /* dbxopen() */
176#else
177int dbxopt_ordwr = O_RDONLY;    /* dbxopen() - O_RDWR / O_RDONLY */
178#endif
179int dbxordwr = 0;               /* dbxopen() - dbxopt_ordwr & O_RDWR */
180
181unsigned char bitmask[8] = { 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01 };
182
183int fpc_fd=0;                   /* fpccreat()/fpcwrite()/fpcclose() */
184FFI fpc_left=FPCBSIZ;           /* fpccreat()/fpcwrite()/fpcclose() */
185char *fpc_buffer=NULL;          /* fpccreat()/fpcwrite()/fpcclose() */
186
187int vlex[NTREE] = { LE1, LE2 };                 /* use it */
188int nxbsiz[NTREE] = { N1BSIZ, N2BSIZ };         /* use it */
189int lxbsiz[NTREE] = { L1BSIZ, L2BSIZ };         /* use it */
190
191char *mx1extp = ".mst";                         /* mstsetup/recisis0 */
192char *xx1extp = ".xrf";                         /* mstsetup/recisis0 */
193
194char *cx1extp = ".cnt";                         /* invsetup/trmisis0 */
195char *nx12extp[NTREE] = { ".n01", ".n02" };     /* invsetup/trmisis0 */
196#if LIND
197char *lx12extp[NTREE] = { ".ly1", ".ly2" };     /* invsetup/trmisis0 */
198char *ix1extp = ".iyp";                         /* invsetup/trmisis0 */
199#else
200char *lx12extp[NTREE] = { ".l01", ".l02" };     /* invsetup/trmisis0 */
201char *ix1extp = ".ifp";                         /* invsetup/trmisis0 */
202#endif
203#if CNLI
204char *iy0extp = ".iy0";                         /* All IF into 1. To ALP, WL */
205#endif
206
207#if MULTI
208int cipnetws=MONONETS;          /* MULTI default operation */
209#endif
210
211#if DBXMSTXL
212#if ( LIND4 || SUPERISIS==1 ) && _LARGEFILE64_SOURCE
213int cipmstxl=6;                 /* extended .mst capacity */
214#elif CIFFI
215int cipmstxl=4;                 /* extended .mst capacity */
216#else
217int cipmstxl=0;                 /* extended .mst capacity */
218#endif
219#endif
220
221#if BEFORE20000323           /* because some BRM's GCC - ask rpiva */
222FILE *cistderr=stderr;      /* 20/05/98 (Asael!) */
223#else
224#define cistderr stderr
225#endif
226
227/* ----------------------------- par.c ------------------------------ */
228/* global */
229FILE *dbxcipfp = NULL;          /* dbxcipar() input parameter file pointer */
230char *dbxcdcip = NULL;          /* dbxcipar() input data */
231char dbxcikey[BUFSIZ];          /* dbxcipar() actual file name */
232int dbxcipok = 0;               /* dbxcipar() found */
233
234#if GIPAR
235char dbxgikey[BUFSIZ];         /* dbxgipar() actual file name */
236
237char *dbxgiext[] = {
238                     ".xrf",".mst",
239                     ".cnt",".n01",".n02",
240#if LIND
241                     ".ly1",".ly2",".iyp",
242#else /* LIND */
243                     ".l01",".l02",".ifp",
244#endif /* LIND */
245                     /*
246                     xx1extp, mx1extp,
247                     cx1extp,
248                     nx12extp[0], nx12extp[1],
249                     lx12extp[0], lx12extp[1],
250                     ix1extp,
251                     */
252                     ".any",
253                     ".fdt",".fst",".fmt",".pft",".stw",".srt",".wpr",".val",
254                     /*
255                     iy0extp,
256                     */
257                     NULL }; /* bc4.5/C++ */
258int   dbxgiexn[] = { 1,2,
259                     3,
260                     4,5,
261                     6,7,
262                     8,
263                     9,
264                     10,10,10,10,10,10,10,10
265                     /*
266                     ,11
267                     */ };
268
269#endif /* GIPAR */
270
271#endif /* !CICPP */
272
273#if !CICPP
274#define CIDBX_CISISX_SOURCE 1
275#include "cisisx.c"
276#endif
277
278#if CICPP
279DBXSTRU :: DBXSTRU(CISISX *parm_cisisxp)
280{
281 memset(this,0x00,sizeof(DBXSTRU));
282 cisisxp = parm_cisisxp;
283 //try {
284 //}
285 //catch {
286 //}
287 //strncpy(dbxname,dbnamep,*highv);
288}
289
290#endif /* CICPP */
291
292
293#if MULTI
294
295#if CICPP
296int DBXSTRU :: xdbxflock(DBXSTRU *dbxp,
297                         char *typ)
298#else /* CICPP */
299int dbxflock(dbxp,typ)
300DBXSTRU *dbxp;
301char *typ;
302#endif /* CICPP */
303{
304    int floop;                                  /* dbxflock() - #retries */
305    int rc,fd=0,type=0;
306    int opw,*opvp;
307
308    if (!dbxp) fatal("dbxflock/dbxp");
309    if (dbxtrace) printf("+++ dbxflock - %s / %s \n",DBXname,typ);
310
311    if (strcmp(typ,"M") == 0) {
312        type=1; fd=DBXmsopn; opw=DBXmsopw; opvp= &DBXmsopv;
313    }
314    if (strcmp(typ,"I") == 0) {
315        type=2; fd=DBIifopn; opw=DBIifopw; opvp= &DBIifopv;
316    }
317    if (!type) fatal("dbxflock/type");
318
319    if (fd <= 0) fatal("dbxflock/fd");
320    if (!opw)   fatal("dbxflock/file is not opened for write");
321    if (*opvp) fatal("dbxflock/file is locked");
322
323    for (floop=dbxfloop; floop--; ) {           /* dbxflock() - #retries */
324#if PC
325#if MSC
326        if (LSEEK64(fd,dbxfloff,SEEK_SET) != dbxfloff) fatal("dbxflock/lseek");
327        rc=locking(fd,LK_LOCK,dbxflsiz);
328#else
329        rc=lock(fd,dbxfloff,dbxflsiz);
330#endif
331#else
332        if (LSEEK64(fd,dbxfloff,SEEK_SET) != dbxfloff) fatal("dbxflock/lseek");
333        rc=lockf(fd,F_TLOCK,dbxflsiz);
334#endif
335        if (rc == 0) { (*opvp)++; /* locked */   return(0); }
336
337        if (floop == 0) {
338            if (multrace)
339                printf("<F> File %s (%s) is locked by another user\n",DBXname,typ);
340#if SHTEST
341            printf(".."); if (*gets(shtest)) if (strcmp(shtest,"x")) system(shtest); else fatal("dbxflock/shtest");
342#endif
343            return(RCLOCK);
344        }
345    }
346    return(rc);
347}
348
349
350#if CICPP
351int DBXSTRU :: xdbxulock(DBXSTRU *dbxp,
352                         char *typ)
353#else /* CICPP */
354int dbxulock(dbxp,typ)
355DBXSTRU *dbxp;
356char *typ;
357#endif /* CICPP */
358{
359    int rc,fd,type=0;
360    char *extp;
361    int *opnp,*opwp,*opvp;
362
363    if (!dbxp) fatal("dbxulock/dbxp");
364    if (dbxtrace) printf("+++ dbxulock - %s / %s \n",DBXname,typ);
365
366    if (strcmp(typ,"M") == 0) {
367        type=1;
368        opnp= &DBXmsopn; extp=mx1extp; opwp= &DBXmsopw; opvp= &DBXmsopv;
369    }
370    if (strcmp(typ,"I") == 0) {
371        type=2;
372        opnp= &DBIifopn; extp=ix1extp; opwp= &DBIifopw; opvp= &DBIifopv;
373    }
374    if (!type) fatal("dbxulock/type");
375    fd= *opnp;
376
377    if (dbxtrace)
378     printf("+++ dbxulock - fd=%d ext=%s opw=%d opv=%d\n",fd,extp,*opwp,*opvp);
379
380    if (fd <= 0) fatal("dbxulock/fd");
381    if (!*opwp) fatal("dbxulock/file is not opened for write");
382    if (!*opvp) fatal("dbxulock/file is not locked");
383
384#if PC
385#if MSC
386    if (LSEEK64(fd,dbxfloff,SEEK_SET) != dbxfloff) fatal("dbxulock/lseek");
387    rc=locking(fd,LK_UNLCK,dbxflsiz);
388#else
389    rc=unlock(fd,dbxfloff,dbxflsiz);
390#endif
391#else
392    if (LSEEK64(fd,dbxfloff,SEEK_SET) != dbxfloff) fatal("dbxulock/lseek");
393    rc=lockf(fd,F_ULOCK,dbxflsiz);
394#endif
395    *opvp=0; /* unlocked */
396    if (dbxuclos < 0) {
397        if (dbxtrace) printf("dbxulock - will close %d \n",fd);
398        CLOSE(fd); *opnp=0; *opwp=0;
399    }
400    else {
401        if (dbxtrace) printf("dbxulock - will close/open %d \n",fd);
402        *opwp=0; /* force close&open/w in dbxopenw */
403        dbxopenw(DBXname,DBXname,extp,opnp,opwp,"dbxulock/reopn/w");
404    }
405    return(rc);
406}
407
408#if CICPP
409int DBXSTRU :: xdbxwlock(DBXSTRU *dbxp,
410                         char *m0p,
411                         int   times)
412#else /* CICPP */
413int dbxwlock(dbxp,m0p,times)
414DBXSTRU *dbxp;
415char *m0p;
416int times;
417#endif /* CICPP */
418{
419    char m0area[sizeof(M0STRU)];
420    int wloop,n;
421
422    if (dbxtrace)
423        printf("+++ dbxwlock - %s %p %d (%d)\n",DBXname,m0p,times,DBXewlxx);
424
425    if (!m0p) m0p=m0area;
426    for (wloop=times; wloop--; ) {
427        /* get the control record */
428        if (LSEEK64(DBXmsopn,0L,SEEK_SET) != 0) fatal("dbxwlock/lock/LSEEK64/ewl");
429        n=CIREAD(DBXmsopn,m0p,sizeof(M0STRU));
430#if CNV_PCBINUM
431        ConvertMST_CTLSTRUCT(m0p);
432#endif
433        if (n != sizeof(M0STRU)) fatal("dbxwlock/lock/read/ewl");
434#if DBXMSTXL /* AOT 18/06/2002 */
435        ((M0STRU *)m0p)->m0mftype = ((M0STRU *)m0p)->m0mftype & 0x00FF;
436#endif
437        if (((M0STRU *)m0p)->m0mfcxx3 == 0) break;
438        if (multrace) printf("<W> %s has exclusive write lock\n",DBXname);
439        if (DBXewlxx) break; /* user's ewl */
440        /* .mst file lock: unlock */
441        if (multrace) printf("<W> %s .mst unlock/ewl \n",DBXname);
442        if (dbxulock(dbxp,"M")) fatal("dbxwlock/lock/file unlock/ewl");
443        if (wloop == 0) {
444            if (multrace)
445                printf("<W> Database %s is locked by another user\n",DBXname);
446#if SHTEST
447            printf(".."); if (*gets(shtest)) if (strcmp(shtest,"x")) system(shtest); else fatal("dbxwlock/shtest");
448#endif
449            return(RCLOCK);
450        }
451        /* .mst file lock: lock */
452        if (multrace) printf("<W> %s .mst lock/ewl \n",DBXname);
453        if (dbxflock(dbxp,"M"))
454#if BEFORE20000608
455            fatal("dbxwlock/lock/file lock/ewl");
456#else
457            return(RCLOCK);
458#endif
459    }
460
461    return(0);
462}
463
464#endif /* MULTI */
465
466#if CICPP
467void DBXSTRU :: xdbxflush(char *dbnamp)
468#else /* CICPP */
469void dbxflush(dbnamp)                                                   /*
470-------------
471                    seta dbxp;
472                    flush master e invertido;
473                    libera dbxp;
474                    reloca vdbxp[]
475                                                                        */
476char *dbnamp;                   /* dbn to be flushed */
477#endif /* CICPP */
478{
479    DBXSTRU *dbxp;
480    LONGX idbx;
481#if DBXTRACE
482    char dbname[sizeof(dbxp->dbxname)];
483#endif
484
485    dbxp=dbxsrchp(dbnamp);
486    if (dbxp == NULL)
487        return;
488
489    mstflush(dbnamp);
490    invflush(dbnamp);
491
492    for (idbx=ndbxs; idbx--; )
493        if (strcmp(VDBXname(idbx),dbnamp) == 0) {
494#if DBXTRACE
495 if (dbxtrace) strcpy(dbname,dbnamp);
496#endif
497
498#if GIPAR
499            if (DBXgicip) {
500#if CICPP
501                delete [] DBXgicip;
502#else /* CICPP */
503                FREE(DBXgicip);
504#endif /* CICPP */
505            }
506#endif /* GIPAR */
507
508#if BEFORE981202
509#if CICPP
510            delete vdbxp[idbx];
511#else /* CICPP */
512            FREE(vdbxp[idbx]);
513#endif /* CICPP */
514            vdbxp[idbx]=(DBXSTRU *)NULL;
515            while (++idbx < ndbxs) vdbxp[idbx-1] = vdbxp[idbx];
516            ndbxs--;
517#else /* BEFORE */
518            /* Agora mantem estrutura - apenas reinicializa */
519#if CICPP
520            CISISX *cp = dbxp->cisisxp;
521            memset(dbxp,0x00,sizeof(DBXSTRU)); /* init everything */
522            dbxp->cisisxp = cp;
523#else /* CICPP */
524            memset(dbxp,0x00,sizeof(DBXSTRU)); /* init everything */
525#endif /* CICPP */
526            strcpy(DBXname,dbnamp);            /* store dbnamp */
527            /* HB/ISIS_DLL precisa de ndbxs--; para nao cair */
528            /* rever dbxgipar: chamar dbxsrchp e nao dbxstorp */
529#endif /* BEFORE */
530
531#if DBXTRACE
532 if (dbxtrace) printf("dbxflush - dbnamp='%s' \n",dbname);
533#endif
534#if DBXTRAC2
535 for (idbx=0L; idbx < ndbxs; idbx++)
536  printf("dbxflush - ndbxs=%"_LD_"  idbx=%"_LD_"=%s=%p \n",
537   ndbxs,idbx,VDBXname(idbx),vdbxp[idbx]);
538#endif
539            return;
540        }
541
542    fatal("dbxflush");
543}
544
545#if CLOSEX
546int CLOSE(fd)
547int fd;
548{
549#define XTC 0
550#if XTC
551    unsigned int eof;
552#endif /* CICPP */
553#if 0
554int n;
555for (n=0; n<HANDLE_MAX; n++)
556 printf("openfd[%d] = %04x\n",n,_openfd[n]);
557#endif
558    if (dbxtrace) printf("+++ CLOSE/closing %d\n",fd);
559
560#if XTC
561    if (fd < 0 || fd >= HANDLE_MAX) fatal("CLOSE/fd");
562    eof=(unsigned int)EOF;
563    if (_openfd[fd] == eof) fatal("CLOSE/openfd");
564#endif
565    return(CLOSEX(fd));
566}
567#endif
568
569/* ----------------------------- std.c ------------------------------ */
570
571
572/* ----------------------------- flush.c ------------------------------ */
573
574#if CICPP
575void DBXSTRU :: xmstclose(DBXSTRU *dbxp)
576#else /* CICPP */
577void mstclose(dbxp)                                                     /*
578-------------
579                    faz close dos arquivos abertos do master file
580                                                                        */
581DBXSTRU *dbxp;
582#endif /* CICPP */
583{
584    if (dbxp == NULL) return;
585
586    if (DBXmsopn) {
587        CLOSE(DBXmsopn); DBXmsopn=DBXmsopw=DBXmsopv=0;
588    }
589    if (DBXxropn) {
590        CLOSE(DBXxropn); DBXxropn=DBXxropw=0;
591    }
592}
593
594
595#if CICPP
596void DBXSTRU :: xmstflush(char *dbnamp)
597#else /* CICPP */
598void mstflush(dbnamp)                                                   /*
599-------------
600                    seta dbxp;
601                    faz close dos arquivos abertos do master file
602                    flush gizmo,etc;
603                                                                        */
604char *dbnamp;                   /* dbn to be flushed */
605#endif /* CICPP */
606{
607    DBXSTRU *dbxp;
608
609    dbxp=dbxsrchp(dbnamp);
610    if (dbxp == NULL) return;
611
612#if RECGIZM
613    if (DBXvgzrp) { gizflush(DBXvgzrp); DBXvgzrp=NULL; }
614#endif
615#if RECDECO
616    if (DBXvderp) { decflush(DBXvderp); DBXvderp=NULL; }
617#endif
618
619    if (DBXxribp != NULL) {
620#if CICPP
621        delete [] DBXxribp;
622#else /* CICPP */
623        FREE(DBXxribp);
624#endif /* CICPP */
625        DBXxribp=NULL;
626    }
627
628    if (DBXmsibp != NULL) {
629#if CICPP
630        delete [] DBXmsibp;
631#else /* CICPP */
632        FREE(DBXmsibp);
633#endif /* CICPP */
634        DBXmsibp=NULL;
635    }
636
637    if (DBXxryyp != NULL) {
638#if CICPP
639        delete [] DBXxryyp;
640#else /* CICPP */
641        FREE(DBXxryyp);
642#endif /* CICPP */
643        DBXxryyp=NULL;
644    }
645
646    if (DBXmsyyp != NULL) {
647#if CICPP
648        delete [] DBXmsyyp;
649#else /* CICPP */
650        FREE(DBXmsyyp);
651#endif /* CICPP */
652        DBXmsyyp=NULL;
653    }
654
655    mstclose(dbxp);
656}
657
658
659
660#if CICPP
661INVMAP * DBXSTRU :: xdbxinvmp(DBXSTRU *dbxp)
662#else /* CICPP */
663INVMAP *dbxinvmp(dbxp)                                                  /*
664-----------------
665                    aloca/seta dbxifmap
666                                                                        */
667DBXSTRU *dbxp;
668#endif /* CICPP */
669{
670    INVMAP *invp;
671#if !CICPP
672    LONGX lvar;
673#endif /* CICPP */
674
675    if (!DBXifmap) { /* funtion */
676#if CICPP
677        try { invp=(INVMAP *) new char [(sizeof(INVMAP))]; }
678        catch (BAD_ALLOC) { invp = (INVMAP *)ALLONULL; }
679#else /* CICPP */
680        lvar=sizeof(INVMAP);
681        if ((lvar) > ALLOMAXV)
682            fatal("dbxinvmp/ALLOMAXV/sizeof(INVMAP)");
683        invp=(INVMAP *)ALLOC((ALLOPARM)(sizeof(INVMAP)));
684#endif /* CICPP */
685        if (invp == (INVMAP *)ALLONULL) fatal("dbxinvmp/ALLOC/invmap");
686        memset(invp,0x00,sizeof(INVMAP));
687        DBXifmap=invp;
688    }
689    if (dbxtrace) printf("+++ dbxinvmp - %s = %p\n",DBXname,DBXifmap);
690
691    return(DBXifmap);
692}
693
694#if CICPP
695void DBXSTRU :: xinvclose(DBXSTRU *dbxp)
696#else /* CICPP */
697void invclose(dbxp)                                                     /*
698-------------
699                    faz close dos arquivos abertos do inverted file
700                                                                        */
701DBXSTRU *dbxp;
702#endif /* CICPP */
703{
704    INVMAP *invp;
705#if SAMEL
706    int lxx;
707#endif
708
709    if (dbxp == NULL) return;
710
711    if (DBXifmap) {
712        invp=DBXifmap;
713#if SAMEL
714        for (lxx=0; lxx < MAXSAMEL; )
715            if (invp->ifopn[lxx]) CLOSE(invp->ifopn[lxx]);
716#else
717        if (invp->ifopn) CLOSE(invp->ifopn); /* 1st */
718#endif
719        if (invp->cnopn) CLOSE(invp->cnopn);
720        if (invp->n1opn) CLOSE(invp->n1opn);
721        if (invp->n2opn) CLOSE(invp->n2opn);
722        if (invp->l1opn) CLOSE(invp->l1opn);
723        if (invp->l2opn) CLOSE(invp->l2opn);
724
725        invp->cnopn=invp->cnopw=0;
726        invp->n1opn=invp->n1opw=0;
727        invp->n2opn=invp->n2opw=0;
728        invp->l1opn=invp->l1opw=0;
729        invp->l2opn=invp->l2opw=0;
730        invp->ifopn=invp->ifopw=0;
731    }
732}
733
734#if CICPP
735void DBXSTRU :: xinvflush(char *dbnamp)
736#else /* CICPP */
737void invflush(dbnamp)                                                   /*
738-------------
739                    seta dbxp;
740                    faz close dos arquivos abertos do inverted file
741                                                                        */
742char *dbnamp;                   /* dbn to be flushed */
743#endif /* CICPP */
744{
745    DBXSTRU *dbxp;
746    INVMAP *invp;
747    int treecase;
748    NXSTRU *nxp;
749    int level;
750
751    dbxp=dbxsrchp(dbnamp);
752    if (dbxp == NULL) return;
753
754    if (DBXifmap) {
755
756        invclose(dbxp);
757        invp=DBXifmap;
758
759        for (treecase=0; treecase<2; treecase++) {
760            for (level=invp->cn[treecase].liv; level>=0; level--) {
761                if ((nxp= &invp->nx[treecase][level]) != NULL)
762#if CICPP
763                    delete [] nxp->basep;
764#else /* CICPP */
765                    FREE(nxp->basep);
766#endif /* CICPP */
767            }
768        }
769        for (treecase=0; treecase<2; treecase++) {
770            if (invp->nybasep[treecase] != NULL)
771#if CICPP
772                delete [] invp->nybasep[treecase];
773#else /* CICPP */
774                FREE(invp->nybasep[treecase]);
775#endif /* CICPP */
776        }
777        for (treecase=0; treecase<2; treecase++) {
778            if (invp->lybasep[treecase] != NULL)
779#if CICPP
780                delete [] invp->lybasep[treecase];
781#else /* CICPP */
782                FREE(invp->lybasep[treecase]);
783#endif /* CICPP */
784        }
785        if (invp->iybasep != NULL)
786#if CICPP
787            delete [] invp->iybasep;
788#else /* CICPP */
789            FREE(invp->iybasep);
790#endif /* CICPP */
791
792        if (invp->ifl1p != NULL)
793#if CICPP
794            delete [] invp->ifl1p;
795#else /* CICPP */
796            FREE(invp->ifl1p);
797#endif /* CICPP */
798        if (invp->ifl2p != NULL)
799#if CICPP
800            delete [] invp->ifl2p;
801#else /* CICPP */
802            FREE(invp->ifl2p);
803#endif /* CICPP */
804
805#if CICPP
806        delete [] invp;
807#else /* CICPP */
808        FREE(invp);
809#endif /* CICPP */
810        DBXifmap=NULL;
811    }
812}
813
814
815/* ***************** Standard Library extensions **************** */
816
817#if GEN_CORELEFT
818#if CICPP
819unsigned LONGX DBXSTRU :: xcoreleft(void)
820#else /* CICPP */
821unsigned LONGX coreleft()
822#endif /* CICPP */
823{
824#if UNIX && !GCC
825    LONGX bytes;
826    bytes=ulimit(3,0L)-(LONGX)sbrk(0);
827    if (dbxtrace) printf("+++ coreleft=%"_LD_"\n",bytes);
828    return((unsigned LONGX)bytes);
829#else
830    return(ALLOMAXV);
831#endif
832}
833#endif /* GEN_CORELEFT */
834
835
836#if GEN_LABS
837#if CICPP
838long DBXSTRU :: xlabs(long x)
839#else /* CICPP */
840long labs(x)
841long x;
842#endif /* CICPP */
843{
844    if (x < 0) return(-x); else return(x);
845}
846#endif /* GEN_LABS */
847
848
849#if GEN_STRSTR
850#if CICPP
851char * DBXSTRU :: xstrstr (CONST char *p1,
852                           CONST char *p2)
853#else /* CICPP */
854char *strstr(p1, p2)
855CONST char *p1;
856CONST char *p2;
857#endif /* CICPP */
858{
859    char *p3, *p4;
860    do {
861        for ( ; *p1 != *p2; p1++) if (*p1 == '\0') return (NULL);
862        for (p3 = p1, p4 = p2; ; p3++, p4++) {
863            if (*p4 == '\0') return (p1);
864            if (*p3 != *p4) break;
865        }
866        p1++;
867    } while (*p1 != '\0');
868    return (NULL);
869}
870#endif /* GEN_STRSTR */
871
872
873#if GEN_STRUPR
874#if CICPP
875char * DBXSTRU :: xstrupr (char* p)
876#else /* CICPP */
877char *strupr(p)
878char *p;
879#endif /* CICPP */
880{
881    char *p1;
882    for (p1 = p; *p1; p1++) *p1 = toupper (*p1);
883    return (p);
884}
885#endif /* GEN_STRUPR */
886
887
888#if GEN_STRREV
889#if CICPP
890char * DBXSTRU :: xstrrev (char *p)
891#else /* CICPP */
892char *strrev(p)
893char *p;
894#endif /* CICPP */
895{
896    char *p1, *p2, c;
897    int lp;
898    lp = strlen(p);
899    p2 = p+lp-1;
900    lp = lp/2;
901    for (p1 = p; lp; lp--, p1++, p2--) {
902        c = *p1;
903        *p1 = *p2;
904        *p2 = c;
905    }
906    return (p);
907}
908#endif /* GEN_STRREV */
909
910
911#if GEN_MEMICMP
912#if CICPP
913int DBXSTRU :: xmemicmp(CONST void *s1,
914                        CONST void *s2,
915                        size_t      n)
916#else /* CICPP */
917int memicmp(s1, s2, n)
918CONST void *s1;
919CONST void *s2;
920size_t n;
921#endif /* CICPP */
922{
923    size_t loop;
924    int rc;
925    unsigned char *p1,*p2;
926    for (rc=0, p1=(unsigned char *)s1, p2=(unsigned char *)s2, loop=n; loop--; p1++, p2++) {
927        rc=(int)*p1-(int)*p2;
928        if (rc) break;
929    }
930    return(rc);
931}
932#endif /* GEN_MEMICMP */
933
934
935
936/* *********************** fpc_ extension ******************** */
937#if CICPP
938void DBXSTRU :: xfpcwrite(char *recbufp,
939                          FFI   reclen)
940#else /* CICPP */
941void fpcwrite(recbufp,reclen)
942char *recbufp;
943FFI reclen;
944#endif /* CICPP */
945{
946    char *p;
947
948#if fpc_TRACE
949    FFI loop;
950    for (p=recbufp, loop=0; loop<reclen; p++) {
951        /* printf("%02x ",*p); */
952        printf("%02x%c ",*p,isprint(*p)?*p:' ');
953        if (++loop%16 == 0) printf("\n");
954    }
955    printf("\n");
956#endif
957
958    /* allocate fpcwrite() output buffer */
959    if (!fpc_buffer) {
960#if CICPP
961        try { fpc_buffer= new char [FPCBSIZ]; }
962        catch (BAD_ALLOC) { fpc_buffer=(char *)NULL; }
963#else /* CICPP */
964        fpc_buffer=(char *)ALLOC((ALLOPARM)FPCBSIZ);
965#endif /* CICPP */
966        if (fpc_buffer == (char *)ALLONULL)
967                fatal("fpcwrite/ALLOC/fpc_buffer");
968#if fpc_TRACE
969        if (dbxtrace) printf("fpc_buffer: coreleft=%"_LD_"\n",CORELEFT());
970#endif
971    }
972
973    if (!fpc_fd) fatal("fpcwrite/fd");
974    for (p=recbufp; reclen; ) {
975        if (reclen <= fpc_left) {
976            memcpy(&fpc_buffer[FPCBSIZ-fpc_left],p,(size_t)reclen);
977            fpc_left-=reclen;
978            break;
979        }
980        memcpy(&fpc_buffer[FPCBSIZ-fpc_left],p,fpc_left);
981        if (CIWRITE(fpc_fd,fpc_buffer,FPCBSIZ) != FPCBSIZ)
982            fatal("fpcwrite/write");
983        reclen-=fpc_left;
984        p+=fpc_left;
985        fpc_left=FPCBSIZ;
986    }
987}
988
989
990#if CICPP
991void DBXSTRU :: xfpcclose(void)
992#else /* CICPP */
993void fpcclose()
994#endif /* CICPP */
995{
996    FFI n;
997
998    if (fpc_left < FPCBSIZ) {
999        if (/* fpc_left < 0 || */ fpc_left > FPCBSIZ) fatal("fpcclose/left");
1000        if (!fpc_fd) fatal("fpcclose/fd");
1001        if (!fpc_buffer) fatal("fpcclose/buffer");
1002        n=FPCBSIZ-fpc_left;
1003        if (CIWRITE(fpc_fd,fpc_buffer,n) != n) fatal("fpcclose/write");
1004    }
1005    fpc_left=FPCBSIZ;
1006
1007    CLOSE(fpc_fd); fpc_fd=0;
1008
1009    if (fpc_buffer) {
1010#if CICPP
1011        delete [] fpc_buffer;
1012#else /* CICPP */
1013        FREE(fpc_buffer);
1014#endif /* CICPP */
1015        fpc_buffer=NULL;
1016    }
1017}
1018
1019
1020#if CICPP
1021int DBXSTRU :: xfpccreat(char *gidbnp,
1022                         char *namp,
1023                         char *extp,
1024                         int   lrecl)
1025#else /* CICPP */
1026int fpccreat(gidbnp,namp,extp,lrecl)
1027char *gidbnp;                   /* dbn.par */
1028char *namp;
1029char *extp;
1030int lrecl;
1031#endif /* CICPP */
1032{
1033    char line[BUFSIZ];
1034#if MPE
1035    char dcb[80];
1036#endif
1037
1038    strcpy(line,namp);
1039    strcat(line,extp);
1040    strcpy(line,dbxcipar(gidbnp,line,'='));
1041
1042#if MPE
1043    sprintf(dcb,"b R%d",lrecl);
1044    fpc_fd=OPEN(line,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,dcb);
1045#else
1046    fpc_fd=CREAT(line,PERMIS);
1047    if (lrecl) fatal("fpccreat/lrecl");
1048#endif
1049    if (fpc_fd <= 0) fatal(line);
1050    if (dbxtrace) printf("+++ %s=%d\n",line,fpc_fd);
1051
1052    return(fpc_fd);
1053}
1054
1055#if CICPP
1056char * DBXSTRU :: xcicopyr(char *namep)
1057#else /* CICPP */
1058char *cicopyr(namep)
1059char *namep;
1060#endif /* CICPP */
1061{
1062    //static char cicopyr_area[3*100+9];
1063    static char cicopyr_area[5*100+9];
1064    //char *p,*q;
1065    char *p,*q,*q2,*q3;
1066    char vci[100],vwi[100],*vp;
1067
1068    vci[0]='\0';
1069    vwi[0]='\0';
1070#if GCC
1071    strcat(vci,"/G");
1072#endif
1073#if ISPACKED || CNV_PCFILES
1074    strcat(vci,"/P");
1075#endif
1076#if PCREADLINUX
1077    strcat(vci,"X");
1078#endif
1079#if SWAPPED || CNV_PCBINUM
1080    strcat(vci,"C");
1081#endif
1082#if DOS32BITS
1083    strcat(vci,"32");
1084#endif
1085#if _LARGEFILE64_SOURCE
1086      /*sprintf(vwi,"/%dG",2<<cipmstxl);
1087      strcat(vci,vwi);*/
1088      strcat(vci,"/512G");
1089#endif
1090#if ISISUNISYS
1091    strcat(vci,"/X");
1092#endif
1093#if CIWTF
1094    strcat(vci,"/W");
1095#endif
1096#if CIFFI
1097    strcat(vci,"/F");
1098#endif
1099#if LIND
1100    strcat(vci,"/L");
1101#if LIND4
1102    strcat(vci,"4");
1103#endif
1104#endif
1105#if MULTI
1106    strcat(vci,"/M");
1107#endif
1108    vp=vci+strlen(vci);
1109    sprintf(vp,"/%"_LD_"/%d/%d",MAXMFRL,LE1,LE2);
1110    vp+=strlen(vp);
1111#if IFUPDATE                       /* Inverted file update */
1112    sprintf(vp,"/I");
1113    vp+=strlen(vp);
1114#endif
1115#if SIXTY_FOUR
1116    sprintf(vp,"/64bits");
1117    vp+=strlen(vp);
1118#endif
1119
1120    if (!namep) namep="";
1121    if (namep[0] == '?') {
1122        vp=vwi;
1123#if CNLI
1124        sprintf(vp,"/%s",iy0extp); vp+=strlen(vp);
1125#endif
1126#if ZTREE                          /* MY: must be off */
1127        sprintf(vp,"/Z"); vp+=strlen(vp);
1128#endif
1129#if DBXMSTXL                       /* extended .mst capacity */
1130        /* strcat(vp,"/xGB"); vp+=strlen(vp); */
1131#endif
1132/* #if !CICPP - AOT 27/03/2001 */
1133#if RECGIZM                        /* CIGIZ */
1134        sprintf(vp,"/GIZ"); vp+=strlen(vp);
1135#endif
1136#if RECXPND                        /* MX: putdir/getdir */
1137        sprintf(vp,"/XPND"); vp+=strlen(vp);
1138#endif
1139#if RECDECO                        /* DEC */
1140        sprintf(vp,"/DEC"); vp+=strlen(vp);
1141#endif
1142/* #endif  CICPP   AOT 27/03/2001 */
1143
1144#if GEN_ISI                        /* enable iso_open()/iso_read() */
1145        sprintf(vp,"/ISI"); vp+=strlen(vp);
1146#endif
1147#if GEN_UTL                        /* enable except loaductb() */
1148        sprintf(vp,"/UTL"); vp+=strlen(vp);
1149#endif
1150#if INVXBOOL                       /* Bx0 use several inverted files */
1151        sprintf(vp,"/INVX"); vp+=strlen(vp);
1152#endif
1153#if CIB64                          /* cib62 using ISIS I/F */
1154        sprintf(vp,"/B6"); vp+=strlen(vp);
1155#endif
1156#if CIB71                          /* cib71/cib72 */
1157        sprintf(vp,"/B7"); vp+=strlen(vp);
1158#endif
1159#if  TW_BOOL                       /* Bx0 multiple ifp's for text word */
1160        sprintf(vp,"/TW"); vp+=strlen(vp);
1161#endif
1162#if FATRAP                         /* fatal() trapping */
1163        sprintf(vp,"/FAT"); vp+=strlen(vp);
1164#endif
1165#if GIPAR                          /* dbn.par & dbxgicip processing */
1166        sprintf(vp,"/PAR"); vp+=strlen(vp);
1167#endif
1168#if CIPAR                          /* dbxcipfp & dbxcdcip processing */
1169        sprintf(vp,"/CIP"); vp+=strlen(vp);
1170#endif
1171#if CIPARIC                        /* CIPAR ignore case */
1172        sprintf(vp,"/IC"); vp+=strlen(vp);
1173#endif
1174#if CICGI
1175        sprintf(vp,"/CGI"); vp+=strlen(vp);
1176#endif
1177#if MXFUN || IFLOADFUN
1178    strcat(vp,"/MX");
1179#endif
1180#if CIAPI || CIAPI_SOURCE
1181    strcat(vp,"/A");
1182#endif
1183#if CI_XMLELEM
1184    strcat(vp,"/X");
1185#endif
1186#if CIWTF
1187    strcat(vp,"/W");
1188#endif
1189#if PROCXSLT
1190    strcat(vp,"/XSL");
1191#endif
1192    }
1193
1194    p="CISIS Interface v5.7b";
1195    q="Copyright (c)BIREME/PAHO 2010. [http://reddes.bvsalud.org/projects/cisis]";
1196  //q="Copyright (c)BIREME/PAHO 2010. [http://www.bireme.br/products/cisis]";
1197  //q2="Copyright (c)BIREME/PAHO 2010. [http://bvsmodelo.bvsalud.org/php/index.php?lang=pt]";
1198    q3="Copyright (c)BIREME/PAHO 2010. [http://bvsmodelo.bvsalud.org/php/level.php?lang=pt&component=28&item=1]";
1199
1200    if (namep[0] == '?')
1201      sprintf(cicopyr_area,"%s%s - %s\n%s%s\n%s\n",p,vci,namep+1,p,vwi,q);
1202      //sprintf(cicopyr_area,"%s%s - %s\n%s%s\n%s\n%s\n",p,vci,namep+1,p,vwi,q,q3);
1203    else
1204      sprintf(cicopyr_area,"%s%s - %s\n%s\n",p,vci,namep,q);
1205     
1206    return(cicopyr_area);
1207}
1208
1209
1210
1211/* *****************************************************
1212   Funzioni di Conversione
1213   Original code by Beppe Romano (quadri.nis.garr.it)
1214***************************************************** */
1215
1216#if CNV_PCBINUM
1217
1218#if CICPP
1219int ConvertMST_CTLSTRUCT(char *buffer)
1220#else /*CICPP*/
1221int ConvertMST_CTLSTRUCT(buffer)
1222char *buffer;
1223#endif /*CICPP*/
1224{
1225  static int fieldlength[9]={4,4,4,2,2,4,4,4,4};
1226  int x,y;
1227#if CNVTRACE
1228  printf ("Converting MST_CTLSTRUCT\n");
1229#endif
1230  y=0;
1231  for (x=0;x<9;x++) {
1232    ConvertBuffer(buffer+y,fieldlength[x]);
1233    y+=fieldlength[x];
1234  }
1235  return (1);
1236}
1237
1238#if CICPP
1239int ConvertMST_LEADER(char *buffer,
1240                      int   skipval,
1241                      int   breakval)
1242#else /*CICPP*/
1243int ConvertMST_LEADER(buffer,skipval,breakval)
1244char *buffer;
1245int skipval;
1246int breakval;
1247#endif /*CICPP*/
1248{
1249  static int fieldlength[7]={4,2,4,2,2,2,2};
1250  int x,y;
1251#if CNVTRACE
1252  LONGX *w;
1253  printf ("Converting MST_LEADER (skip=%d break=%d)\n",skipval,breakval);
1254for (x=0; x<LEADER; x++) printf("%02x ",buffer[x]);
1255printf("\n");
1256#endif
1257  y=0;
1258  for (x=0;x<7;x++) {
1259    if (y >= skipval) ConvertBuffer(buffer+y,fieldlength[x]);
1260    y+=fieldlength[x];
1261    if (y >= breakval) break;
1262  }
1263#if CNVTRACE
1264for (x=0; x<LEADER; x++) printf("%02x ",buffer[x]);
1265printf("\n");
1266  w=(LONGX *)buffer;
1267  printf("MFN converted:%d\n",*w);
1268#endif
1269  return (1);
1270}
1271
1272#if CICPP
1273int ConvertMST_DIR(char *buffer,
1274                   int   nvf)
1275#else /*CICPP*/
1276int ConvertMST_DIR(buffer,nvf)
1277char *buffer;
1278int nvf;
1279#endif /*CICPP*/
1280{
1281  int x,y,z;
1282  char *c;
1283#if CNVTRACE
1284  printf ("Converting MST_DIR\n");
1285for (x=0; x<LEADER+6*nvf; x++) printf("%02x ",buffer[x]);
1286printf("\n");
1287#endif
1288  c=buffer+LEADER;
1289  y=0;
1290  for (x=nvf;x--; ){
1291     for (z=0;z<3;z++){
1292       ConvertBuffer(c+y,2);
1293       y+=2;
1294     }
1295  }
1296#if CNVTRACE
1297for (x=0; x<LEADER+6*nvf; x++) printf("%02x ",buffer[x]);
1298printf("\n");
1299#endif
1300  return (1);
1301}
1302
1303
1304#if CICPP
1305int ConvertXRF_PTR(char *buffer)
1306#else /*CICPP*/
1307int ConvertXRF_PTR(buffer)
1308char *buffer;
1309#endif /*CICPP*/
1310{
1311#if CNVTRACEx
1312    printf ("Converting XRF_PTR\n");
1313#endif
1314    ConvertBuffer(buffer,XRPTRSIZ);
1315    return(1);
1316}
1317
1318#if CICPP
1319int ConvertXRF_REC(char *buffer)
1320#else /*CICPP*/
1321int ConvertXRF_REC(buffer)
1322char *buffer;
1323#endif /*CICPP*/
1324{
1325    XRSTRU *xrp;
1326    int n;
1327#if CNVTRACE
1328    printf ("Converting XRF_REC\n");
1329#endif
1330    xrp=(XRSTRU *)buffer;
1331    ConvertBuffer((char *)&xrp->xrxrpos,XRPOSSIZ);
1332    for (n=0; n < XRMAXTIV; n++)
1333        ConvertXRF_PTR((char *)&xrp->xrmfptr[n]);
1334    return(1);
1335}
1336
1337
1338#if CICPP
1339int ConvertL02_REC(char *buffer)
1340#else /*CICPP*/
1341int ConvertL02_REC(buffer)
1342char *buffer;
1343#endif /*CICPP*/
1344{
1345  static int fieldlength[34]={4,2,2,4,30,4,4,30,4,4,30,4,4,30,4,4,30,4,4,30,4,4,30,4,4,30,4,4,30,4,4,30,4,4};
1346  static int yes[34]={1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1};
1347  int x,y;
1348#if CNVTRACE
1349  UCHR *c;
1350  LONGX v;
1351  printf ("Converting L02_REC\n");
1352#endif
1353  y=0;
1354  for (x=0;x<34;x++) {
1355         if (yes[x]) ConvertBuffer(buffer+y,fieldlength[x]);
1356         y+=fieldlength[x];
1357  }
1358#if CNVTRACE
1359  printf(" -  Number of active key: %d\n",256*(int)buffer[4]+(int)buffer[5]);
1360  c=buffer;
1361  c+=12;
1362  for (x=0;x<TWORDF;x++) {
1363    printf ("K: ");
1364    for (y=0;y<30;y++,c++) printf ("%c",*c);
1365    for (v=y=0;y<4;y++,c++) v=v*256+(UWORD)*c;
1366    printf (" info1: %"_LD_"\n",v);
1367    for (v=y=0;y<4;y++,c++) v=v*256+(UWORD)*c;
1368    printf (" info2: %"_LD_"\n",v);
1369  }
1370#endif
1371  return (1);
1372}
1373
1374#if CICPP
1375int ConvertN02_REC(char *buffer)
1376#else /*CICPP*/
1377int ConvertN02_REC(buffer)
1378char *buffer;
1379#endif /*CICPP*/
1380{
1381  static int fieldlength[23]={4,2,2,30,4,30,4,30,4,30,4,30,4,30,4,30,4,30,4,30,4,30,4,};
1382  static int yes[23]={1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1};
1383  int x,y;
1384#if CNVTRACE
1385  UCHR *c;
1386  LONGX v;
1387  printf ("Converting N02_REC\n");
1388#endif
1389  y=0;
1390  for (x=0;x<23;x++) {
1391    if (yes[x]) ConvertBuffer(buffer+y,fieldlength[x]);
1392    y+=fieldlength[x];
1393  }
1394#if CNVTRACE
1395  printf(" -  Number of active key: %d\n",256*(int)buffer[4]+(int)buffer[5]);
1396  c=buffer;
1397  c+=8;
1398  for (x=0;x<TWORDN;x++) {
1399    printf ("K: ");
1400    for (y=0;y<30;y++,c++) printf ("%c",*c);
1401    for (v=y=0;y<4;y++,c++) v=v*256+(UWORD)*c;
1402    printf (" punt: %"_LD_"\n",v);
1403  }
1404#endif
1405  return (1);
1406}
1407
1408#if CICPP
1409int ConvertL01_REC(char *buffer)
1410#else /*CICPP*/
1411int ConvertL01_REC(buffer)
1412char *buffer;
1413#endif /*CICPP*/
1414{
1415  static int fieldlength[34]={4,2,2,4,10,4,4,10,4,4,10,4,4,10,4,4,10,4,4,10,4,4,10,4,4,10,4,4,10,4,4,10,4,4,};
1416  static int yes[34]={1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1};
1417  int x,y;
1418#if CNVTRACE
1419  UCHR *c;
1420  LONGX v;
1421  printf ("Converting L01_REC\n");
1422#endif
1423  y=0;
1424  for (x=0;x<34;x++) {
1425    if (yes[x]) ConvertBuffer(buffer+y,fieldlength[x]);
1426    y+=fieldlength[x];
1427  }
1428#if CNVTRACE
1429  printf(" -  Number of active key: %d\n",256*(int)buffer[4]+(int)buffer[5]);
1430  c=buffer;
1431  c+=12;
1432  for (x=0;x<TWORDF;x++) {
1433    printf ("K: ");
1434    for (y=0;y<10;y++,c++) printf ("%c",*c);
1435    for (v=y=0;y<4;y++,c++) v=v*256+(UWORD)*c;
1436    printf (" info1: %"_LD_"\n",v);
1437    for (v=y=0;y<4;y++,c++) v=v*256+(UWORD)*c;
1438    printf (" info2: %"_LD_"\n",v);
1439  }
1440#endif
1441  return (1);
1442}
1443
1444#if CICPP
1445int ConvertN01_REC(char *buffer)
1446#else /*CICPP*/
1447int ConvertN01_REC(buffer)
1448char *buffer;
1449#endif /*CICPP*/
1450{
1451  static int fieldlength[23]={4,2,2,10,4,10,4,10,4,10,4,10,4,10,4,10,4,10,4,10,4,10,4,};
1452  static int yes[23]={1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1};
1453  int x,y;
1454#if CNVTRACE
1455  UCHR *c;
1456  LONGX v;
1457  printf ("Converting N01_REC\n");
1458#endif
1459  y=0;
1460  for (x=0;x<23;x++) {
1461    if (yes[x]) ConvertBuffer(buffer+y,fieldlength[x]);
1462    y+=fieldlength[x];
1463  }
1464#if CNVTRACE
1465  printf(" -  Number of active key: %d\n",256*(int)buffer[4]+(int)buffer[5]);
1466  c=buffer;
1467  c+=8;
1468  for (x=0;x<TWORDN;x++) {
1469    printf ("K: ");
1470    for (y=0;y<10;y++,c++) printf ("%c",*c);
1471    for (v=y=0;y<4;y++,c++) v=v*256+(UWORD)*c;
1472    printf (" punt: %"_LD_"\n",v);
1473  }
1474#endif
1475  return (1);
1476}
1477
1478
1479#if CICPP
1480int ConvertCNT_REC(char *buffer)
1481#else /*CICPP*/
1482int ConvertCNT_REC(buffer)
1483char *buffer;
1484#endif /*CICPP*/
1485{
1486  static int fieldlength[10]={2,2,2,2,2,2,4,4,4,2};
1487  int x,y;
1488  y=0;
1489#if CNVTRACE
1490  printf ("Converting CNT_REC\n");
1491#endif
1492  for (x=0;x<10;x++) {
1493    ConvertBuffer(buffer+y,fieldlength[x]);
1494    y+=fieldlength[x];
1495  }
1496  return (1);
1497}
1498
1499
1500#if CICPP
1501int ConvertBuffer(char *buffer,
1502                  int   fieldlength)
1503#else /*CICPP*/
1504int ConvertBuffer(buffer,fieldlength)
1505char *buffer;
1506int fieldlength;
1507#endif /*CICPP*/
1508{
1509  char cc[4];
1510  int x,y;
1511  y=fieldlength-1;
1512  for (x=0;x<fieldlength;x++) cc[y--]=buffer[x];
1513  for (x=0;x<fieldlength;x++) buffer[x]=cc[x];
1514  return 1;
1515}
1516
1517
1518
1519#if CICPP
1520int ConvertIFP_BLKCTL(char *buffer,
1521                      int   blk1)
1522#else /*CICPP*/
1523int ConvertIFP_BLKCTL(buffer,blk1)
1524char *buffer;
1525int blk1;
1526#endif /*CICPP*/
1527{
1528  int y;
1529#if CNVTRACE
1530  LONGX *v;
1531  printf ("Converting IFP_BLKCTL blk1=%d\n",blk1);
1532#endif
1533  y=0;
1534  ConvertBuffer(buffer,4);
1535  y+=4;
1536#if CNVTRACE
1537  v=(LONGX *)buffer;
1538  printf("IFPRECNUM=%"_LD_"\n",*v);
1539#endif
1540  if (blk1) {
1541    ConvertBuffer(buffer+y,4);
1542    y+=4;
1543    ConvertBuffer(buffer+y,4);
1544  }
1545  return (1);
1546}
1547
1548
1549#if CICPP
1550int ConvertIFP_PSTHDR(char *buffer)
1551#else /*CICPP*/
1552int ConvertIFP_PSTHDR(buffer)
1553char *buffer;
1554#endif /*CICPP*/
1555{
1556  int x,y;
1557#if CNVTRACE
1558  printf ("Converting IFP_PSTHDR\n");
1559#endif
1560  y=0;
1561  for (x=0;x<5;x++) {
1562    ConvertBuffer(buffer+y,4);
1563    y+=4;
1564  }
1565  return (1);
1566}
1567
1568#endif /* CNV_PCBINUM */
Note: See TracBrowser for help on using the browser.