home *** CD-ROM | disk | FTP | other *** search
- /*
- * variable record length routines
- *
- * 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) 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 */
- #include "ctisam.h" /* c-tree isam header */
- #include "ctvrec.h" /* var length header */
-
-
- COUNT ierr(),frmkey(),ADDKEY(),DELCHK();
- COUNT getvhdr(),putvhdr(),compar(),frmlkey();
- COUNT WRTVREC(),RETVREC(),addikey(),delikey(),rwtikey();
- CTFILE *tstfnm();
- POINTER EQLKEY(),NEWVREC();
- VRLEN GTVLEN();
- VOID iundo();
- #ifdef MUSTFRCE
- COUNT DLOCK(),UDLOCK();
- #endif
-
- LOCAL TEXT lenkey[VARI_LEN];
-
- POINTER chkvsm(datno)
- COUNT datno;
-
- {
- VATFILE *vnum;
- POINTER pntr;
-
- COUNT addlok();
-
- isam_err = NO_ERROR;
-
- if ((vnum = tstfnm(datno)) == NULL)
- ierr(uerr_cod,datno);
- else if (vnum->clstyp != VAT_CLOSE)
- ierr(FMOD_ERR,datno);
- else if (!(pntr = cur_recno[datno]))
- ierr(ICUR_ERR,datno);
- else
- addlok(pntr,datno);
-
- if (!isam_err)
- return(pntr);
- else
- return(DRNZERO);
- }
-
-
- VRLEN GETVLEN(datno)
- COUNT datno;
- {
- VRLEN vlen;
-
- isam_err = 0;
- if (vlen = GTVLEN(datno,cur_recno[datno]))
- return(vlen);
- else if (uerr_cod == ZREC_ERR)
- uerr_cod = ICUR_ERR;
- ierr(uerr_cod,datno);
- return(0);
- }
-
- COUNT ADDVREC(datno,recptr,varlen)
-
- PFAST COUNT datno;
- TEXT *recptr;
- VRLEN varlen;
-
- {
- POINTER pntr;
- VATFILE *vnum;
-
- COUNT addlok();
-
- isam_err = NO_ERROR;
- if ((vnum = tstfnm(datno)) == NULL)
- return(ierr(uerr_cod,datno));
- else if (vnum->clstyp != VAT_CLOSE)
- return(ierr(FMOD_ERR,datno));
- else if (varlen < vnum->reclen)
- return(ierr(VRLN_ERR,datno));
- else if (!(pntr = NEWVREC(datno,varlen)))
- return(ierr(uerr_cod,datno));
- setsrlpos(datno,recptr);
-
- ct_nwrcfg = YES;
- if (addlok(pntr,datno))
- return(isam_err);
-
- if (WRTVREC(datno,pntr,recptr,varlen)) {
- ierr(uerr_cod,datno);
- iundo(ISADD,datno,0,recptr,pntr,DRNZERO);
- return(isam_err);
- }
-
- if (addikey(datno,recptr,pntr))
- return(isam_err);
-
- cur_recno[datno] = pntr;
- cur_image[datno] = recptr;
- #ifdef DOSFLUSH
- flushdos(datno);
- #endif
- return(NO_ERROR);
- }
-
-
- COUNT DELVREC(datno)
-
- PFAST COUNT datno;
-
- {
- TEXT *recptr;
- POINTER pntr;
- COUNT i;
-
- POINTER chkvsm();
-
- if (!(pntr = chkvsm(datno)))
- return(isam_err);
-
- recptr = cur_image[datno];
- if ((i = delikey(datno,recptr,pntr)) > 0)
- return(isam_err);
-
- if (RETVREC(datno,pntr)) {
- ierr(uerr_cod,datno);
- iundo(ISDEL,datno,-i,recptr,DRNZERO,pntr);
- return(isam_err);
- }
- #ifdef DOSFLUSH
- flushdos(datno);
- #endif
- return(NO_ERROR);
- }
-
- COUNT RWTVREC(datno,recptr,varlen)
- COUNT datno;
- TEXT *recptr;
- VRLEN varlen;
- {
- VHDR vrhdr,nrhdr;
- CTFILE *vnum;
- LONG pntr,old_pntr,nrecbyt;
- VRLEN old_totlen,test;
- COUNT i;
- #ifdef MUSTFRCE
- LOKS *lp;
- COUNT tstlok;
- #endif
-
- POINTER chkvsm();
-
- #ifdef MUSTFRCE
- tstlok = DLOK_ERR;
- #endif
- vnum = ct_key + datno;
- if (!(old_pntr = chkvsm(datno)))
- return(isam_err);
- else if (vnum->flmode & READFIL)
- return(ierr(REDF_ERR,datno));
- else if (getvhdr(vnum,old_pntr,&vrhdr))
- return(ierr(uerr_cod,datno));
-
- old_totlen = vrhdr.trclen;
-
- if (varlen > old_totlen) {
- if ((nrecbyt = old_pntr + old_totlen + SIZVHDR) > old_pntr &&
- getvhdr(vnum,nrecbyt,&nrhdr) == NO_ERROR &&
- nrhdr.recmrk == VDEL_FLAG && (test = old_totlen + SIZVHDR +
- #ifndef MUSTFRCE
- nrhdr.trclen) >= varlen) {
- frmlkey(lenkey,&nrhdr.trclen,DRNZERO);
- #else
- nrhdr.trclen) >= varlen && (tstlok = DLOCK(nrecbyt,vnum))
- == NO_ERROR && frmlkey(lenkey,&nrhdr.trclen,nrecbyt) &&
- EQLKEY(datno,lenkey) != DRNZERO) {
- #endif
- /* enlarge current space */
- vrhdr.trclen = test;
- if (putvhdr(vnum,old_pntr,&vrhdr) ||
- DELCHK(datno,lenkey,nrecbyt))
- /* no UDLOCK here (FPUTFGET) since VDLK_ERR *
- * should "never" arise here */
- return(ierr(VDLK_ERR,datno));
- pntr = old_pntr;
- #ifdef MUSTFRCE
- UDLOCK(nrecbyt,vnum);
- } else {
- if (tstlok == NO_ERROR)
- UDLOCK(nrecbyt,vnum);
- if (!(pntr = NEWVREC(datno,varlen)))
- return(ierr(uerr_cod,datno));
- }
- #else
- } else if (!(pntr = NEWVREC(datno,varlen)))
- return(ierr(uerr_cod,datno));
- #endif
- } else
- pntr = old_pntr;
-
- if ((i = rwtikey(datno,recptr,pntr,old_pntr)) > 0)
- return(isam_err);
-
- if (WRTVREC(datno,pntr,recptr,varlen)) {
- ierr(uerr_cod,datno);
- iundo(ISRWT,datno,-i,recptr,pntr,old_pntr);
- return(isam_err);
- }
-
- cur_recno[datno] = pntr;
- cur_image[datno] = recptr;
-
- if (pntr != old_pntr) {
- #ifdef MUSTFRCE
- for (i = 0, lp = ct_locks; i++ < MAX_LOCKS; lp++)
- if (lp->datfnm == datno && lp->recnum == old_pntr) {
- lp->recnum = pntr;
- break;
- }
- #endif
- RETVREC(datno,old_pntr);
- #ifdef DOSFLUSH
- flushdos(datno);
- #endif
- return(ierr(uerr_cod,datno));
- } else {
- #ifdef DOSFLUSH
- flushdos(datno);
- #endif
- return(NO_ERROR);
- }
- }
-
- COUNT REDVREC(datno,recptr,bufsiz)
- PFAST COUNT datno;
- TEXT *recptr;
- VRLEN bufsiz;
- {
- POINTER pntr;
- VRLEN vrclen;
- #ifdef MUSTFRCE
- COUNT keyno;
- TEXT chkkey[MAXLEN];
- #endif
-
- VRLEN prprdv();
- COUNT ctio(),addlok();
-
- isam_err = 0;
- if ((vrclen = prprdv(datno,pntr = cur_recno[datno],recptr,
- bufsiz)) == 0) {
- if (uerr_cod == ZREC_ERR)
- uerr_cod = ICUR_ERR;
- } else if (addlok(pntr,datno))
- uerr_cod = isam_err;
- else
- ctio(CTREAD,ct_key + datno,pntr,recptr,vrclen);
- if (uerr_cod)
- return(ierr(uerr_cod,datno));
-
- #ifdef MUSTFRCE
- if (ct_vfsg) {
- frmkey(keyno = (ct_vfsg - 1),recptr,chkkey,pntr);
- ct_vfsg = NO;
- if (compar(chkkey,ct_fndval,ct_key + keyno))
- return(ierr(ITIM_ERR,datno));
- }
- #endif
- cur_image[datno] = recptr;
- return(isam_err);
- }
-
- /* end of ctvrec.c */
-