home *** CD-ROM | disk | FTP | other *** search
- /*
- * sequence set 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 */
- #include "ctisam.h" /* c-tree isam header */
-
- POINTER GTEKEY(),GTKEY(),LTEKEY(),LTKEY();
- COUNT ierr(),reset_cur();
- CTFILE *tstfnm();
- TEXT *mballc();
-
- LOCAL TEXT seqbuf[MAXLEN]; /* holds matching "partial" ct_key */
- LOCAL COUNT seqlen; /* significant length of ct_key */
- LOCAL COUNT seqkey = -1; /* current keyno */
- LOCAL COUNT seqnum = -1; /* current set number */
- LOCAL COUNT maxqset;
- #ifdef CTSERVER
- EXTERN COUNT cts_csuc,cts_cseq;
- EXTERN UCOUNT cts_clen;
- EXTERN TEXT *ct_apxdat;
- #endif
-
- COUNT ALCSET(numset)
- COUNT numset;
- {
- isam_err = 0;
- if ((TEXT *) ct_savset != NULL)
- return(ierr(ISDP_ERR,0));
- else if (numset == 0)
- return(NO_ERROR);
- else if ((ct_savset = (SAVSET *) mballc(numset,sizeof(SAVSET))) == NULL)
- return(ierr(ISAL_ERR,0));
- maxqset = numset;
- return(NO_ERROR);
- }
-
- COUNT FRESET()
- {
- VOID mbfree();
-
- mbfree(ct_savset);
- ct_savset = NULL;
- seqkey = seqnum = -1;
- return(isam_err = maxqset = 0);
- }
-
- COUNT CHGSET(setnum)
- FAST COUNT setnum;
- {
- FAST SAVSET *ss;
-
- if (setnum < 0 || setnum >= maxqset || ct_savset == NULL)
- return(ierr(ISNM_ERR,0));
- else
- isam_err = 0;
-
- if (setnum == seqnum) /* no need to switch */
- return(NO_ERROR);
-
- if (seqnum >= 0 && seqnum < maxqset) { /* save current set */
-
- ss = ct_savset + seqnum;
- ss->qlen = seqlen;
- ss->qkey = seqkey + 1;
- cpybuf(ss->qbuf,seqbuf,MAXLEN);
- }
-
- ss = ct_savset + setnum;
- seqlen = ss->qlen;
- seqkey = ss->qkey - 1;
- seqnum = setnum;
- cpybuf(seqbuf,ss->qbuf,MAXLEN);
- return(NO_ERROR);
- }
-
-
- COUNT chkset(keyno,recpos,recptr)
- COUNT keyno;
- POINTER recpos;
- TEXT *recptr;
- {
- FAST COUNT i;
- FAST TEXT *kp;
- CTFILE *knum;
-
- if (recpos == DRNZERO) /* no match */ {
- /* seqkey = -1; */ /* remove comments for old behavior */
- return(reset_cur(keyno,DRNZERO,recptr));
- }
- for (i = 0, kp = ct_fndval, knum = ct_key + keyno; i < seqlen; i++)
- if (seqbuf[i] != *kp++) {
- /* no match */
- /* seqkey = -1;*/ /* remove comments for old behavior */
- #ifdef CTSERVER
- if (cts_csuc && (ct_ismlk == ENABLE ||
- ct_ismlk == READREC)) {
- /* lock already acquired by server */
- cts_csuc = NO;
- LOKREC(ct_rvmap[keyno],FREE,recpos);
- }
- #endif
- return(ierr(INOT_ERR,keyno));
- }
-
- seqkey = keyno;
- for ( ; i < knum->length; i++)
- seqbuf[i] = *kp++;
- #ifdef CTSERVER
- if (cts_csuc)
- cpybuf(recptr,ct_apxdat + knum->length,cts_clen);
- #endif
- return(reset_cur(keyno,recpos,recptr));
- }
-
- COUNT setset(keyno,target,siglen)
- COUNT keyno;
- TEXT *target;
- PFAST COUNT siglen;
- {
- CTFILE *cnum;
- FAST TEXT *kp;
-
- seqkey = -1;
- if ((cnum = tstfnm(keyno)) == NULL)
- return(ierr(uerr_cod,keyno));
- else if ((cnum->ktype & MSK_ALT) >= INTKEY && (cnum->ktype & MSK_ALT)
- <= DFLOATKEY)
- return(ierr(SKTY_ERR,keyno));
-
- if (siglen >= cnum->length)
- seqlen = cnum->length;
- else
- seqlen = siglen;
- for (siglen = 0,kp = seqbuf; siglen++ < seqlen; )
- *kp++ = *target++;
- return(NO_ERROR);
- }
-
-
- COUNT FRSSET(keyno,target, recptr,siglen)
- COUNT keyno;
- TEXT *target,*recptr;
- PFAST COUNT siglen;
- {
- FAST TEXT *kp;
-
- if (setset(keyno,target,siglen))
- return(isam_err);
-
- kp = seqbuf + siglen;
- while (siglen++ < (ct_key + keyno)->length)
- *kp++ = '\0';
-
- #ifdef CTSERVER
- cmbchk(keyno,recptr);
- cts_cseq = YES;
- #endif
- return(chkset(keyno,GTEKEY(keyno,seqbuf,ct_fndval),recptr));
- }
-
- COUNT MIDSET(keyno,recptr,siglen)
- COUNT keyno;
- TEXT *recptr;
- COUNT siglen;
- {
- TEXT target[MAXLEN];
- FAST COUNT len,datno;
- POINTER pntr;
- FAST CTFILE *ctnum;
-
- if ((ctnum = tstfnm(keyno)) == NULL)
- return(ierr(uerr_cod,keyno));
- if ((pntr = cur_recno[datno = ct_rvmap[keyno]]) == DRNZERO)
- return(ierr(ICUR_ERR,keyno));
- if (frmkey(keyno,cur_image[datno],target,pntr))
- len = ctnum->length;
- else
- len = 0;
- if (FRSSET(keyno,target,recptr,len))
- return(isam_err);
- if (siglen > len)
- siglen = len;
- seqlen = siglen;
- return(NO_ERROR);
- }
-
- COUNT LSTSET(keyno,target, recptr,siglen)
- COUNT keyno;
- TEXT *target,*recptr;
- PFAST COUNT siglen;
- {
- FAST TEXT *kp;
-
- if (setset(keyno,target,siglen))
- return(isam_err);
-
- kp = seqbuf + siglen;
- while (siglen++ < (ct_key + keyno)->length)
- *kp++ = '\377';
-
- #ifdef CTSERVER
- cmbchk(keyno,recptr);
- cts_cseq = YES;
- #endif
- return(chkset(keyno,LTEKEY(keyno,seqbuf,ct_fndval),recptr));
- }
-
-
- COUNT NXTSET(keyno,recptr)
- COUNT keyno;
- TEXT *recptr;
- {
- if (tstfnm(keyno) == NULL)
- return(ierr(uerr_cod,keyno));
- else if (keyno != seqkey)
- return(ierr(SKEY_ERR,keyno));
- else {
- #ifdef CTSERVER
- cmbchk(keyno,recptr);
- cts_cseq = YES;
- #endif
- return(chkset(keyno,GTKEY(keyno,seqbuf,ct_fndval),recptr));
- }
- }
-
-
- COUNT PRVSET(keyno,recptr)
- COUNT keyno;
- TEXT *recptr;
- {
- if (tstfnm(keyno) == NULL)
- return(ierr(uerr_cod,keyno));
- else if (keyno != seqkey)
- return(ierr(SKEY_ERR,keyno));
- else {
- #ifdef CTSERVER
- cmbchk(keyno,recptr);
- cts_cseq = YES;
- #endif
- return(chkset(keyno,LTKEY(keyno,seqbuf,ct_fndval),recptr));
- }
- }
-
- /* end of ctsset.c */
-