home *** CD-ROM | disk | FTP | other *** search
- /*
- * isam utilities
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
-
- #include "ctstdr.h" /* standard i/o header */
- #include "ctoptn.h" /* c-tree configuration options */
- #include "cterrc.h" /* c-tree error codes */
- #include "ctstrc.h" /* c-tree data structures */
- #include "ctgvar.h" /* c-tree global variables */
- #undef EXTERN
- #define EXTERN /* */
- #include "ctisam.h" /* c-tree isam header */
-
- #ifdef REVBIN
- #undef REVBIN
- #endif
- #ifdef LOW_HIGH
- #define REVBIN
- #endif
- #ifdef HIGH_LOW
- #ifdef UNIFRMAT
- #define REVBIN
- #endif
- #endif
-
- #ifdef CTSERVER
- extern COUNT cts_csuc;
- #endif
-
- #ifdef PARMFILE
- #ifdef PERC_H
- #define IC1 "%h %h %h %h"
- #define IC2 "%h %s %h %h %h %h"
- #define IC3 "%h %h %h"
- #define IC4 "%h %s %h %h %h %h %h %h %h %h %h"
- #define IC5 "%h %h %h %h %h %h %h"
- #endif
- #ifdef PERC_D
- #define IC1 "%d %d %d %d"
- #define IC2 "%d %s %d %d %d %d"
- #define IC3 "%d %d %d"
- #define IC4 "%d %s %d %d %d %d %d %d %d %d %d"
- #define IC5 "%d %d %d %d %d %d %d"
- #endif
- #ifdef PERC_HD
- #define IC1 "%hd %hd %hd %hd"
- #define IC2 "%hd %s %hd %hd %hd %hd"
- #define IC3 "%hd %hd %hd"
- #define IC4 "%hd %s %hd %hd %hd %hd %hd %hd %hd %hd %hd"
- #define IC5 "%hd %hd %hd %hd %hd %hd %hd"
- #endif
- #endif
-
- #ifdef RTREE
- #include "rtpars.h"
- #include "rtstrc.h"
-
- RKEY usrkey[MAXFIL];
- RDAT usrdat[MAXFIL];
- COUNT srtknm,srtdat,tmpdat;
-
- #ifdef PARMFILE
- TEXT *mballc();
-
- COUNT setudat(ifd,datno)
- FILE *ifd;
- COUNT datno;
- {
- COUNT ierr();
-
- COUNT i;
-
- for (i = 1; i < 3; i++) {
- if (fscanf(ifd,"%s",ct_buf) != 1)
- return(ierr(IDRU_ERR,datno));
- if ((usrdat[datno].fldnam[i] = mballc(1,strlen(ct_buf)+1)) ==
- NULL)
- return(ierr(IDMU_ERR,datno));
- strcpy(usrdat[datno].fldnam[i],ct_buf);
- }
- return(NO_ERROR);
- }
-
- COUNT setukey(ifd,keyno,keytyp)
- FILE *ifd;
- COUNT keyno,keytyp;
- {
- COUNT ierr();
-
- if (fscanf(ifd,"%s",ct_buf) != 1)
- return(ierr(IKRU_ERR,keyno));
- else if ((usrkey[keyno].rsymb = mballc(1,strlen(ct_buf)+1)) == NULL)
- return(ierr(IKMU_ERR,keyno));
- else {
- strcpy(usrkey[keyno].rsymb,ct_buf);
- usrkey[keyno].rtype = keytyp;
- return(NO_ERROR);
- }
- }
- #endif
- #endif
-
- COUNT RLOCK(),DLOCK();
-
- COUNT ierr(err_cod,file_no)
- COUNT err_cod;
- COUNT file_no;
-
- {
- isam_fil = file_no;
- return(isam_err = err_cod);
- }
-
-
- COUNT addlok(pntr,datno)
- POINTER pntr;
- COUNT datno;
- {
- FAST COUNT i,d;
- COUNT is,tmpflg;
- FAST LOKS *lp;
-
- CTFILE *tstfnm();
-
- tmpflg = ct_nwrcfg;
- ct_nwrcfg = NO;
- if (ct_ismlk == FREE || ct_ismlk == SUSPEND)
- return(NO_ERROR);
-
- for (i = 0, is = -1, lp = ct_locks; i < MAX_LOCKS; i++,lp++)
- if ((d = lp->datfnm) < 0 && is < 0)
- is = i;
- else if (d == datno && lp->recnum == pntr) {
- if (lp->ltltyp == ct_ismlk)
- return(NO_ERROR);
- else {
- is = i;
- break;
- }
- }
-
- if (is < 0)
- return(ierr(INOL_ERR,datno));
- if (!tmpflg && (tstfnm(datno) == NULL ||
- #ifdef CTSERVER
- (ct_ismlk == ENABLE && cts_csuc == NO && DLOCK(pntr,ct_key + datno)) ||
- (ct_ismlk == READREC && cts_csuc == NO && RLOCK(pntr,ct_key + datno))))
- #else
- (ct_ismlk == ENABLE && DLOCK(pntr,ct_key + datno)) ||
- (ct_ismlk == READREC && RLOCK(pntr,ct_key + datno))))
- #endif
- return(ierr(uerr_cod,datno));
-
- (lp = ct_locks + is)->datfnm = datno;
- lp->recnum = pntr;
- lp->ltltyp = ct_ismlk;
- return(NO_ERROR);
- }
-
- TEXT ucase(t)
- TEXT t;
- {
- if (t >= 'a' && t <= 'z')
- return((TEXT) (t + 'A' - 'a'));
- else
- return(t);
- }
-
-
- COUNT frmkey(keyno,recptr,txt,pntr)
- COUNT keyno;
- TEXT *recptr;
- PFAST TEXT *txt;
- POINTER pntr;
- {
- FAST COUNT j;
- COUNT i,k,len,slen,mod,altflg,dscflg;
- FAST TEXT *recpos;
- TEXT *savtxt;
- CTFILE *ctnum;
-
- ctnum = ct_key + ct_rvmap[keyno];
- savtxt = txt;
- for (i = len = 0; i < MAX_KEY_SEG; i++) {
- if ((k = ct_sgpos[keyno][i]) < 0)
- break;
- recpos = recptr + k;
- len += (slen = ct_sglen[keyno][i]);
- mod = ct_sgmod[keyno][i];
- dscflg = mod & DSCSEG;
- altflg = mod & ALTSEG;
- mod &= SEGMSK;
- switch (mod) {
- case REGSEG:
- #ifndef NATURAL_SERIAL
- case SRLSEG:
- #endif
- #ifndef REVBIN
- case INTSEG:
- #ifdef NATURAL_SERIAL
- case SRLSEG:
- #endif
- #endif
- for (j = 0; j++ < slen; )
- *txt++ = *recpos++;
- break;
- #ifdef REVBIN
- case INTSEG:
- #ifdef NATURAL_SERIAL
- case SRLSEG:
- #endif
- recpos += slen;
- for (j = 0; j++ < slen; )
- *txt++ = *(--recpos);
- break;
- #endif
- case UREGSEG:
- for (j = 0; j++ < slen; )
- *txt++ = ucase(*recpos++);
- break;
-
- #ifdef VARLDATA
- case VARSEG:
- case UVARSEG:
- recpos = recptr + ctnum->reclen; /* ptr to end of minlen */
- /* skip k var segments each terminated by FIELD_DELIM */
- while (k-- > 0)
- while (*recpos++ != FIELD_DELIM)
- ;
- k = 0;
- while (k < slen && *recpos != FIELD_DELIM) {
- k++;
- if (mod == UVARSEG)
- *txt++ = ucase(*recpos++);
- else
- *txt++ = *recpos++;
- }
- while (k++ < slen)
- *txt++ = PADDING;
- break;
- #endif
-
- case SGNSEG:
- case FLTSEG:
- #ifdef REVBIN
- txt += slen;
- for (j = 0; j++ < slen; )
- *(--txt) = *recpos++;
- #else
- cpybuf(txt,recpos,slen);
- #endif
- if (*txt & 0x0080) {
- if (mod == SGNSEG)
- *txt &= 0x007f;
- else
- dscflg = !dscflg;
- } else
- *txt |= 0x0080;
-
- txt += slen;
- break;
-
- default:
- terr(226);
- }
-
- /* ALTERNATIVE COLLATING SEQUENCE */
- /* */
- /* altseq should point to an array which contains a remapping of */
- /* ASCII bytes into an acceptable ordering for those cases (such as */
- /* foreign language character sets) in which the standard ASCII sequence*/
- /* is not acceptable. altseq will only be used if the key segment mode */
- /* has been or'ed with 16. For example, a segment mode of 4 (variable */
- /* length field segment) can be converted to an alternative sequence by */
- /* adding 16 yielding a mode value of 20. */
- /* */
- /* The constraints on altseq[] are that altseq[0] == 0, */
- /* altseq[255] == 255, and that no value of altseq[] exceed 255. */
- /* */
-
-
- if (altflg) {
- txt -= slen;
- for (j = 0; j < slen; j++, txt++)
- *txt = altseq[0x00ff & *txt];
- }
- if (dscflg) {
- txt -= slen;
- for (j = 0; j < slen; j++, txt++)
- *txt = 0x00ff & ~(*txt);
- }
- }
-
- slen = len;
- if ((ct_key + keyno)->autodup) {
- recpos = (TEXT *) &pntr;
- len += sizeof(POINTER);
-
- #ifdef LOW_HIGH
- txt += sizeof(POINTER);
- for (j = 0; j < sizeof(POINTER); j++)
- *--txt = *recpos++;
- #else
- for (j = 0; j < sizeof(POINTER); j++)
- *txt++ = *recpos++;
- #endif
- }
-
- if (ct_nlkey[keyno] == CHKNUL) {
- recpos = &ct_nlchr[keyno];
- for (j = 0, txt = savtxt; j < slen; j++)
- if (*txt++ != *recpos)
- return(len);
- return(0);
- }
-
- return(len);
- }
-
- TEXT *TFRMKEY(keyno,tarptr)
- COUNT keyno;
- TEXT *tarptr;
- {
- COUNT i,len,tarpos[MAX_KEY_SEG],tarmod[MAX_KEY_SEG],savmsk;
- TEXT tmpkey[MAXLEN];
-
- /* temporarily store actual parm file info & replace with */
- /* target oriented info */
- for (i = len = 0; i < MAX_KEY_SEG; i++) {
- if ((tarpos[i] = ct_sgpos[keyno][i]) < 0)
- break;
- tarmod[i] = ct_sgmod[keyno][i];
- savmsk = tarmod[i] & ~SEGMSK;
- ct_sgpos[keyno][i] = len;
- len += ct_sglen[keyno][i];
-
- /* disable varying field segments */
- if ((tarmod[i] & SEGMSK) == VARSEG)
- ct_sgmod[keyno][i] = REGSEG | savmsk;
- else if ((tarmod[i] & SEGMSK) == UVARSEG)
- ct_sgmod[keyno][i] = UREGSEG | savmsk;
- }
-
- /* invoke frmkey with modified parm file info */
- len = frmkey(keyno,tarptr,tmpkey,DRNZERO);
-
- /* copy target key back to tarptr */
- cpybuf(tarptr,tmpkey,len);
-
- /* restore parm file info */
- for (i = 0; i < MAX_KEY_SEG; i++) {
- if ((ct_sgpos[keyno][i] = tarpos[i]) < 0)
- break;
- ct_sgmod[keyno][i] = tarmod[i];
- }
- /* return pointer to target key */
- return(tarptr);
- }
-
- COUNT tstinm(filno)
- COUNT filno;
- {
- if (filno < 0 || filno >= ct_mxfil)
- return(ierr(FNUM_ERR,filno));
- else if (ct_dtmap[filno])
- return(ierr(FUSE_ERR,filno));
- else {
- ct_dtmap[filno] = YES;
- return(NO_ERROR);
- }
- }
-
- #ifdef PARMFILE
- COUNT getintr(ifd,pbufs,pkeys,psecs,pdats)
- FILE *ifd;
- COUNT *pbufs,*pkeys,*psecs,*pdats;
- {
-
- #ifdef RTREE
- COUNT i;
-
- for (i = 0; i < MAXFIL; i++) {
- usrkey[i].rtype = -1;
- usrkey[i].rsymb = NULL;
- }
- #endif
-
- if (fscanf(ifd,IC1,pbufs,pkeys,psecs,pdats) != 4)
- return(ierr(IGIN_ERR,0));
- else if ((*pdats + *pkeys) > MAXFIL)
- return(ierr(IFIL_ERR,0));
- #ifdef RTREE
- else if ((*pdats + *pkeys) > (MAXFIL - 3))
- return(ierr(IKSR_ERR,0));
- *pkeys += 3;
- srtknm = *pdats + *pkeys - 1;
- srtdat = srtknm - 1;
- tmpdat = srtdat - 1;
- #endif
- return(NO_ERROR);
- }
-
-
- COUNT getdatr(ifd,pdatno,pname,pdatln,pdkeys,pxtsiz,pfilmd)
- FILE *ifd;
- COUNT *pdatno;
- TEXT *pname;
- UCOUNT *pdatln;
- COUNT *pdkeys;
- UCOUNT *pxtsiz;
- COUNT *pfilmd;
- {
- if (fscanf(ifd,IC2,pdatno,pname,pdatln,pxtsiz,pfilmd,pdkeys) != 6)
- return(ierr(IDRI_ERR,*pdatno));
- else if (*pdkeys > MAX_DAT_KEY)
- return(ierr(IDRK_ERR,*pdatno));
- else if (tstinm(*pdatno))
- return(isam_err);
- #ifdef RTREE
- else if (setudat(ifd,*pdatno))
- return(isam_err);
- #endif
- else
- return(NO_ERROR);
- }
-
- COUNT setmap(datno,j,keyno,klen,ksegs,dflg,nchar,nulflg,ifd)
- COUNT datno,j,keyno,klen,ksegs,dflg,nchar,nulflg;
- FILE *ifd;
- {
- FAST COUNT k,totseg;
- COUNT tstmod;
-
- ct_kymap[datno][j] = keyno;
- ct_rvmap[keyno] = datno;
- ct_nlchr[keyno] = nchar;
- ct_nlkey[keyno] = nulflg;
- ct_vfin[keyno] = NO;
-
- for (k = 0, totseg = klen; k < ksegs; k++) {
- if (fscanf(ifd,IC3,&ct_sgpos[keyno][k],
- &ct_sglen[keyno][k],&ct_sgmod[keyno][k]) != 3)
- return(ierr(ISRC_ERR,keyno));
- tstmod = ct_sgmod[keyno][k] & SEGMSK;
- totseg -= ct_sglen[keyno][k];
- if (tstmod == SRLSEG)
- (ct_key + datno)->srlpos = ct_sgpos[keyno][k] + 1;
- else if (tstmod == VARSEG || tstmod == UVARSEG)
- ct_vfin[keyno] = YES;
- }
- if ((dflg == DUPKEY && totseg != sizeof(POINTER)) ||
- (dflg != DUPKEY && totseg))
- return(ierr(ISLN_ERR,keyno));
-
- if (k < MAX_KEY_SEG)
- ct_sgpos[keyno][k] = -1;
- return(NO_ERROR);
- }
-
-
- COUNT getidxr(ifd,datno,j,pkeyno,pname,pklen,pktyp,pdflg,pnmem,pxtsiz,pfilmd)
- FILE *ifd;
- COUNT datno,j,*pkeyno;
- TEXT *pname;
- COUNT *pklen,*pktyp,*pdflg,*pnmem;
- UCOUNT *pxtsiz;
- COUNT *pfilmd;
- {
- COUNT nulflg,nchar,ksegs;
-
- if (fscanf(ifd,IC4,pkeyno,pname,pklen,pktyp,pdflg,pnmem,pxtsiz,pfilmd,
- &nulflg,&nchar,&ksegs)
- != 11)
- return(ierr(IKRI_ERR,j));
- else if (ksegs > MAX_KEY_SEG)
- return(ierr(IKRS_ERR,*pkeyno));
- else if (tstinm(*pkeyno))
- return(isam_err);
- #ifdef RTREE
- else if (setukey(ifd,*pkeyno,*pktyp))
- return(isam_err);
- #endif
- else
- return(setmap(datno,j,*pkeyno,*pklen,ksegs,*pdflg,
- nchar,nulflg,ifd));
- }
-
- COUNT getambr(ifd,datno,j,keyno,pklen,pktyp,pdflg)
- FILE *ifd;
- COUNT datno,j,keyno,*pklen,*pktyp,*pdflg;
- {
- COUNT impkey,nulflg,nchar,ksegs;
-
- if (fscanf(ifd,IC5,&impkey,pklen,pktyp,pdflg,&nulflg,
- &nchar,&ksegs) != 7)
- return(ierr(IMRI_ERR,keyno));
- else if (impkey != keyno)
- return(ierr(IMKY_ERR,keyno));
- else if (ksegs > MAX_KEY_SEG)
- return(ierr(IKRS_ERR,keyno));
- #ifdef RTREE
- else if (setukey(ifd,keyno,*pktyp))
- return(isam_err);
- #endif
- else
- return(setmap(datno,j,keyno,*pklen,ksegs,*pdflg,
- nchar,nulflg,ifd));
- }
- #endif
-
- /* end of ctismu.c */
-