home *** CD-ROM | disk | FTP | other *** search
- /*
- * variable record length low level 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 "ctvrec.h" /* var length header */
-
- COUNT tstupd(),ctio(),uerr(),ADDKEY(),DELCHK();
- COUNT getvhdr(),putvhdr(),frmlkey(),chkvhdr();
- CTFILE *tstfnm();
- POINTER GTKEY(),GTEKEY(),EQLKEY();
- #ifdef FPUTFGET
- COUNT DLOCK(),UDLOCK(),redhdr();
- #endif
- #ifdef MUSTFRCE
- COUNT DLOCK(),UDLOCK();
- #endif
- #ifndef NOTFORCE
- COUNT wrthdr();
- #endif
-
- LOCAL TEXT lenkey[VARI_LEN],idxkey[VARI_LEN];
-
- VRLEN GTVLEN(datno,recbyt)
- COUNT datno;
- POINTER recbyt;
- {
- VHDR vrhdr;
- FAST VATFILE *vnum;
-
- uerr_cod = 0;
- if ((vnum = tstfnm(datno)) == NULL)
- /* no action */;
- else if (vnum->clstyp != VAT_CLOSE)
- uerr_cod = FMOD_ERR;
- else if (recbyt == DRNZERO)
- uerr_cod = ZREC_ERR;
- else if (getvhdr(vnum,recbyt,&vrhdr))
- /* no action */;
- else if (vrhdr.recmrk != VACT_FLAG)
- uerr_cod = VFLG_ERR;
-
- if (uerr_cod)
- return(0);
- else
- return(vrhdr.urclen);
- }
-
- LONG NEWVREC(datno,varlen)
- COUNT datno;
- VRLEN varlen;
- {
- LONG pntr,rpntr;
- VATFILE *vnum;
- VHDR vrhdr;
-
- POINTER extfil();
-
- uerr_cod = 0;
- if ((vnum = tstfnm(datno)) == NULL || chkredf(vnum))
- return(DRNZERO);
- if (vnum->clstyp != VAT_CLOSE) {
- uerr(FMOD_ERR);
- return(DRNZERO);
- }
- frmlkey(lenkey,&varlen,DRNZERO);
- rpntr = DRNZERO;
-
- #ifndef MUSTFRCE
- if (pntr = GTEKEY(datno,lenkey,idxkey)) {
- #else
- pntr = GTEKEY(datno,lenkey,idxkey);
- while (pntr)
- if (DLOCK(pntr,vnum)) {
- cpybuf(lenkey,idxkey,VARI_LEN);
- pntr = GTKEY(datno,lenkey,idxkey);
- } else {
- if (EQLKEY(datno,idxkey) != DRNZERO)
- break; /* ok to reuse this space */
- else { /* already used by someone else */
- UDLOCK(pntr,vnum);
- cpybuf(lenkey,idxkey,VARI_LEN);
- pntr = GTKEY(datno,lenkey,idxkey);
- }
- }
- if (pntr) {
- #endif
- if (getvhdr(vnum,pntr,&vrhdr))
- /* no action */ ;
- else if (vrhdr.recmrk != VDEL_FLAG)
- uerr(VDLFLG_ERR);
- else if (DELCHK(datno,idxkey,pntr))
- uerr(VDLK_ERR);
- else
- rpntr = pntr;
-
- if (tstupd(vnum))
- goto err_newvrec;
- #ifdef FPUTFGET
- if (DLOCK(DRNZERO,vnum) || redhdr(vnum))
- goto err_newvrec;
- #endif
- if ((ct_gsrl = ++vnum->sernum) == DRNZERO) {
- uerr_cod = OSRL_ERR;
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,vnum);
- #endif
- goto err_newvrec;
- }
- #ifndef NOTFORCE
- if (wrthdr(vnum)) {
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,vnum);
- #endif
- goto err_newvrec;
- }
-
- #ifdef FPUTFGET
- if (UDLOCK(DRNZERO,vnum))
- goto err_newvrec;
- #endif
- #endif
- return(rpntr);
- }
-
-
- if ((varlen + SIZVHDR) < varlen) {
- uerr(VMAX_ERR);
- goto err_newvrec;
- }
-
- #ifdef FPUTFGET
- if (DLOCK(DRNZERO,vnum) || redhdr(vnum))
- goto err_newvrec;
- #endif
- if ((ct_gsrl = ++vnum->sernum) == DRNZERO) {
- uerr_cod = OSRL_ERR;
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,vnum);
- #endif
- goto err_newvrec;
- }
- pntr = extfil(vnum,varlen + SIZVHDR);
-
- #ifdef FPUTFGET
- if (DLOCK(pntr + SIZVHDR,vnum)) {
- UDLOCK(DRNZERO,vnum);
- goto err_newvrec;
- }
- #endif
- #ifdef CTSERVER
- if (DLOCK(pntr + SIZVHDR,vnum)) {
- goto err_newvrec;
- }
- #endif
-
- #ifdef NOTFORCE
- if (tstupd(vnum))
- goto err_newvrec;
- #else
- if (wrthdr(vnum)) {
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,vnum);
- #endif
- goto err_newvrec;
- }
-
- #ifdef FPUTFGET
- if (UDLOCK(DRNZERO,vnum))
- goto err_newvrec;
- #endif
- #endif
-
- if (!pntr)
- goto err_newvrec;
-
- pntr += SIZVHDR;
- vrhdr.recmrk = VACT_FLAG;
- vrhdr.trclen = varlen;
- vrhdr.urclen = 0;
- if (putvhdr(vnum,pntr,&vrhdr))
- goto err_newvrec;
-
- return(pntr);
-
- err_newvrec:
- return(ct_gsrl = DRNZERO);
- }
-
-
- COUNT RETVREC(datno,recbyt)
- COUNT datno;
- LONG recbyt;
- {
- VATFILE *vnum;
- VHDR vrhdr,nrhdr;
- LONG nrecbyt;
- VRLEN test;
-
- uerr_cod = 0;
- if ((vnum = tstfnm(datno)) == NULL || chkredf(vnum) || getvhdr(vnum,
- recbyt,&vrhdr) || chkvhdr(&vrhdr))
- return(uerr_cod);
-
- if ((nrecbyt = recbyt + vrhdr.trclen + SIZVHDR) > recbyt &&
- getvhdr(vnum,nrecbyt,&nrhdr) == NO_ERROR &&
- #ifndef MUSTFRCE
- nrhdr.recmrk == VDEL_FLAG)
- #else
- nrhdr.recmrk == VDEL_FLAG && DLOCK(nrecbyt,vnum) == NO_ERROR) {
- frmlkey(lenkey,&nrhdr.trclen,nrecbyt); /* see if really avail */
- if (EQLKEY(datno,lenkey) != DRNZERO) /* then next if */
- #endif
- if ((test = vrhdr.trclen + SIZVHDR + nrhdr.trclen) >
- vrhdr.trclen) { /* combine consecutive deleted areas */
- vrhdr.trclen = test;
- frmlkey(lenkey,&nrhdr.trclen,DRNZERO);
- if (DELCHK(datno,lenkey,nrecbyt))
- return(uerr(VDLK_ERR));
- }
- #ifdef MUSTFRCE
- UDLOCK(nrecbyt,vnum);
- }
- #endif
-
- frmlkey(lenkey,&vrhdr.trclen,DRNZERO);
- vrhdr.recmrk = VDEL_FLAG;
- vrhdr.urclen = 0;
- if (putvhdr(vnum,recbyt,&vrhdr))
- return(uerr_cod);
-
- #ifdef MUSTFRCE
- UDLOCK(recbyt,vnum); /* assumes no error if record not locked */
- #endif
-
- return(ADDKEY(datno,lenkey,recbyt,REGADD));
- }
-
- COUNT WRTVREC(datno,recbyt,recptr,varlen)
- COUNT datno;
- LONG recbyt;
- VRLEN varlen;
- TEXT *recptr;
- {
- VATFILE *vnum;
- VHDR vrhdr;
- VRLEN unused;
-
- uerr_cod = 0;
- if ((vnum = tstfnm(datno)) == NULL || chkredf(vnum))
- return(uerr_cod);
- if (!recbyt)
- return(uerr(VPNT_ERR));
- if (recptr == NULL)
- return(uerr(DNUL_ERR));
- if (getvhdr(vnum,recbyt,&vrhdr) || chkvhdr(&vrhdr))
- return(uerr_cod);
- if (vrhdr.trclen < varlen)
- return(uerr(VLEN_ERR));
- vrhdr.urclen = varlen;
- vrhdr.recmrk = VACT_FLAG;
- unused = vrhdr.trclen - varlen;
- if (unused > (vnum->reclen + SIZVHDR) && unused > 64)
- vrhdr.trclen = varlen;
- else
- unused = 0;
- if (putvhdr(vnum,recbyt,&vrhdr))
- return(uerr_cod);
- if (ctio(CTWRITE,vnum,recbyt,recptr,varlen))
- return(uerr_cod);
- if (unused) { /* reclaim space */
- recbyt += (varlen + SIZVHDR);
- vrhdr.recmrk = VDEL_FLAG;
- vrhdr.trclen = unused - SIZVHDR;
- vrhdr.urclen = 0;
- if (putvhdr(vnum,recbyt,&vrhdr))
- return(uerr_cod);
- return(RETVREC(datno,recbyt));
- }
- return(tstupd(vnum));
- }
-
-
- COUNT RDVREC(datno,recbyt,recptr,bufsiz)
- PFAST COUNT datno;
- POINTER recbyt;
- TEXT *recptr;
- VRLEN bufsiz;
- {
- VRLEN vrclen;
- VRLEN prprdv();
-
- if ((vrclen = prprdv(datno,recbyt,recptr,bufsiz)) == 0)
- return(uerr_cod);
- return(ctio(CTREAD,ct_key + datno,recbyt,recptr,vrclen));
- }
-
- /* end of ctvrc2.c */
-