home *** CD-ROM | disk | FTP | other *** search
- /*
- * data file 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) 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 */
-
- COUNT uerr(),ctio(),DLOCK(),UDLOCK(),RLOCK();
-
- POINTER NEWREC(datno)
- COUNT datno;
- {
- FAST DATFILE *dnum;
- LOCAL POINTER pntr;
-
- DATFILE *tstfnm();
- COUNT tstupd(),wrthdr(),redhdr();
- POINTER extfil();
-
- uerr_cod = 0;
- if ((dnum = tstfnm(datno)) == NULL || chkredf(dnum))
- return(DRNZERO);
- if (dnum->clstyp != DAT_CLOSE) {
- uerr(FMOD_ERR);
- return(DRNZERO);
- }
-
- #ifdef FPUTFGET
- if (DLOCK(DRNZERO,dnum) || redhdr(dnum))
- return(DRNZERO);
- #endif
-
- dnum->nument++;
- if ((ct_gsrl = ++dnum->sernum) == DRNZERO) {
- uerr_cod = OSRL_ERR;
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,dnum);
- #endif
- goto err_newrec;
- }
-
- if (!(pntr = dnum->delstk)) {
- if (!(pntr = extfil(dnum,dnum->reclen))) {
- /* could not extend file */
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,dnum);
- #endif
- goto err_newrec;
- }
- } else {
- if (ctio(CTREAD,dnum,pntr,ct_buf,sizeof(POINTER) + 1)) {
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,dnum);
- #endif
- goto err_newrec;
- }
- if (ct_buf[0] != DELFLG) {
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,dnum);
- #endif
- uerr(DELFLG_ERR);
- goto err_newrec;
- }
- #ifdef UNIFRMAT
- revobj(ct_buf + 1,sizeof(POINTER));
- #endif
- cpybuf(&dnum->delstk,ct_buf + 1,sizeof(POINTER));
- }
-
- #ifdef FPUTFGET
- if (DLOCK(pntr,dnum)) {
- UDLOCK(DRNZERO,dnum);
- goto err_newrec;
- }
- #endif
- #ifdef CTSERVER
- if (DLOCK(pntr,dnum))
- goto err_newrec;
- #endif
-
- #ifdef NOTFORCE
- if (tstupd(dnum))
- goto err_newrec;
- #else
- if (wrthdr(dnum)) {
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,dnum);
- #endif
- goto err_newrec;
- }
-
- #ifdef FPUTFGET
- if (UDLOCK(DRNZERO,dnum))
- goto err_newrec;
- #endif
- #endif
- return(pntr);
-
- err_newrec:
- dnum->nument--;
- return(ct_gsrl = DRNZERO);
- }
-
- COUNT RETREC(datno,recbyt)
- COUNT datno;
- POINTER recbyt;
- {
- FAST DATFILE *dnum;
- LOCAL POINTER pntr;
-
- DATFILE *tstfnm();
- COUNT tstupd(),tstrec(),wrthdr(),redhdr();
-
- uerr_cod = 0;
- if ((dnum = tstfnm(datno)) == NULL || chkredf(dnum) ||
- tstrec(dnum,recbyt))
- return(uerr_cod);
- if (dnum->clstyp != DAT_CLOSE)
- return(uerr(FMOD_ERR));
-
-
- #ifdef FPUTFGET
- if (DLOCK(DRNZERO,dnum) || redhdr(dnum))
- return(uerr_cod);
- #endif
-
- dnum->nument--;
- pntr = dnum->delstk;
- if (pntr == recbyt) {
-
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,dnum);
- #endif
- uerr_cod = DDRN_ERR;
- goto err_retrec;
- }
- dnum->delstk = recbyt;
- ct_buf[0] = DELFLG;
- cpybuf(ct_buf + 1,&pntr,sizeof(POINTER));
- #ifdef UNIFRMAT
- revobj(ct_buf + 1,sizeof(POINTER));
- #endif
-
- if (ctio(CTWRITE,dnum,recbyt,ct_buf,sizeof(POINTER) + 1)) {
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,dnum);
- #endif
- goto err_retrec;
- }
-
- #ifdef MUSTFRCE
- UDLOCK(recbyt,dnum); /* assumes no error if recbyt not locked */
- uerr_cod = 0;
- #endif
-
- #ifdef NOTFORCE
- if (tstupd(dnum))
- goto err_retrec;
- #else
- if (wrthdr(dnum)) {
- #ifdef FPUTFGET
- UDLOCK(DRNZERO,dnum);
- #endif
- goto err_retrec;
- }
- #ifdef FPUTFGET
- if (UDLOCK(DRNZERO,dnum))
- goto err_retrec;
- #endif
- #endif
- return(NO_ERROR);
-
- err_retrec:
- dnum->nument++;
- return(uerr_cod);
- }
-
-
-
- /* --------------------------------------------------------------------
- read data record
- */
-
- COUNT REDREC(datno,recbyt,recptr)
- COUNT datno;
- POINTER recbyt;
- TEXT *recptr;
- {
- FAST DATFILE *dnum;
-
- DATFILE *tstfnm();
- COUNT tstrec();
-
- uerr_cod = 0;
- if ((dnum = tstfnm(datno)) == NULL || tstrec(dnum,recbyt))
- return(uerr_cod);
- if (recptr == NULL)
- return(uerr(DNUL_ERR));
- return(ctio(CTREAD,dnum,recbyt,recptr,0));
- }
-
- COUNT WRTREC(datno,recbyt,recptr)
- COUNT datno;
- POINTER recbyt;
- TEXT *recptr;
- {
- FAST DATFILE *dnum;
-
- DATFILE *tstfnm();
- COUNT tstupd(),tstrec();
-
- uerr_cod = 0;
- if ((dnum = tstfnm(datno)) == NULL || chkredf(dnum) ||
- tstrec(dnum,recbyt) || tstupd(dnum))
- return(uerr_cod);
- if (recptr == NULL)
- return(uerr(DNUL_ERR));
- return(ctio(CTWRITE,dnum,recbyt,recptr,0));
- }
-
- COUNT tstrec(dnum,recbyt)
- PFAST DATFILE *dnum;
- POINTER recbyt;
- {
- if (!recbyt)
- return(uerr(ZREC_ERR));
- if (recbyt > dnum->numrec)
- #ifndef FPUTFGET
- return(uerr(LEOF_ERR));
- #else
- if (redhdr(dnum))
- return(uerr_cod);
- else if (recbyt > dnum->numrec)
- return(uerr(LEOF_ERR));
- #endif
- return(NO_ERROR);
- }
-
-
- /* --------------------------------------------------------------------
- return the number of active records in the date file datno
- */
-
- POINTER DATENT(datno)
- PFAST COUNT datno;
- {
- CTFILE *tstfnm();
- FAST CTFILE *dnum;
-
- uerr_cod = 0;
- if ((dnum = tstfnm(datno)) == NULL) /* then error condition */
- return(DRNZERO);
- else if (dnum->clstyp != DAT_CLOSE) {
- uerr_cod = FMOD_ERR;
- return(DRNZERO);
- }
-
- #ifdef FPUTFGET
- if ((dnum->flmode & SHARED) && redhdr(dnum)) /* then error */
- return(DRNZERO);
- #endif
-
- return(dnum->nument);
- }
-
- /* -------------------------------------------------------------------
- lock and unlock data records: lokmod: FREE(0) / ENABLE(2) / READREC
- */
-
- COUNT LOKREC(datno,lokmod,recbyt)
- COUNT datno,lokmod;
- POINTER recbyt;
- {
- CTFILE *tstfnm();
- #ifdef MUSTFRCE
- FAST CTFILE *dnum;
- #endif
- uerr_cod = 0;
-
- #ifdef MUSTFRCE
- if ((dnum = tstfnm(datno)) == NULL)
- return(uerr_cod);
- else if (dnum->clstyp == IDX_CLOSE)
- return(uerr_cod = FMOD_ERR);
-
- if (lokmod == FREE)
- return(uerr_cod = UDLOCK(recbyt,dnum));
- else if (lokmod == READREC)
- return(uerr_cod = RLOCK(recbyt,dnum));
- else
- return(uerr_cod = DLOCK(recbyt,dnum));
- #else
- return(NO_ERROR);
- #endif
- }
-
- /* end of ctdatf.c */
-