home *** CD-ROM | disk | FTP | other *** search
- /*
- * isam support routines: key manipulation
- *
- * 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 */
- #ifdef VARLDATA
- #include "ctvrec.h"
- #endif
- #ifdef CTSERVER
- #include "ctcomm.h"
- extern COUNT cts_keyops;
- extern KEYOPS *cts_kops;
- extern COUNT *cts_mops;
- COUNT MLTKEY();
- #endif
-
- COUNT compar(),ADDKEY();
- COUNT DELCHK(),RETREC(),frmkey();
- COUNT ierr();
- #ifdef VARLDATA
- COUNT RETVREC();
- #endif
-
- #ifndef CTSERVER
- VOID setsrlpos(datno,recptr)
- COUNT datno;
- TEXT *recptr;
- {
- if ((ct_key + datno)->srlpos) {
- #ifndef NATURAL_SERIAL
- #ifdef LOW_HIGH
- revobj(&ct_gsrl,sizeof(ct_gsrl));
- #endif
- #endif
- cpybuf(recptr + (ct_key + datno)->srlpos - 1,
- &ct_gsrl,sizeof(ct_gsrl));
- }
- }
- #endif
-
- VOID iundo(op_code,datno,i,recptr,pntr,old_pntr)
- COUNT op_code;
- PFAST COUNT datno,i;
- TEXT *recptr;
- POINTER pntr,old_pntr;
- {
- FAST COUNT keyno;
- COUNT old_flg,new_flg;
-
- #ifdef CTSERVER
- if (uerr_cod == ARQS_ERR || uerr_cod == ARSP_ERR)
- return;
- #endif
-
- if (op_code == ISADD || (op_code == ISRWT && pntr != old_pntr))
- #ifdef VARLDATA
- if ((ct_key + datno)->clstyp == VAT_CLOSE)
- RETVREC(datno,pntr);
- else
- #endif
- RETREC(datno,pntr);
-
- for (i--; i >= 0 ; i--) {
- keyno = ct_kymap[datno][i];
- if (op_code != ISRWT) {
- if (frmkey(keyno,recptr,ct_kyval,DRNZERO))
- if (op_code == ISADD) {
- if (DELCHK(keyno,ct_kyval,pntr))
- isam_err = IUND_ERR;
- } else {
- if (ADDKEY(keyno,ct_kyval,old_pntr,REGADD))
- isam_err = IUND_ERR;
- }
- } else {
- old_flg = frmkey(keyno,cur_image[datno],ct_fndval,old_pntr);
- new_flg = frmkey(keyno,recptr,ct_kyval,pntr);
- if (old_pntr != pntr ||
- compar(ct_fndval,ct_kyval,ct_key + keyno)) {
- if (new_flg)
- if (DELCHK(keyno,ct_kyval,pntr))
- isam_err = IUND_ERR;
- if (old_flg)
- if (ADDKEY(keyno,ct_fndval,old_pntr,REGADD))
- isam_err = IUND_ERR;
- }
- }
- }
- #ifdef DOSFLUSH
- flushdos(datno);
- #endif
- }
-
- COUNT addikey(datno,recptr,pntr)
- COUNT datno;
- TEXT *recptr;
- POINTER pntr;
- {
- FAST COUNT i,keyno;
- #ifdef CTSERVER
- COUNT j;
- FAST KEYOPS *k;
-
- for (i = j = 0; i < MAX_DAT_KEY; i++) {
- if ((keyno = ct_kymap[datno][i]) < 0 )
- break;
- if (frmkey(keyno,recptr,ct_kyval,DRNZERO)) {
- if (cts_keyops < 2) {
- if (ADDKEY(keyno,ct_kyval,pntr,REGADD)) {
- ierr(uerr_cod,keyno);
- iundo(ISADD,datno,i,recptr,pntr,DRNZERO);
- return(isam_err);
- }
- } else {
- cts_mops[j] = i + 1;
- k = cts_kops + j++;
- k->kokeyn = keyno;
- k->komode = FN_ADDKEY;
- k->kopntr = pntr;
- cpybuf(k->kobufr,ct_kyval,(ct_key + keyno)->length);
- if (j == cts_keyops) {
- j = MLTKEY(cts_keyops);
- if (j == -2)
- return(ierr(uerr_cod,0));
- else if (j) {
- i = j;
- j = - cts_mops[j - 1];
- break;
- }
- }
- }
- }
- }
- if (j > 0) {
- j = MLTKEY(j);
- if (j == -2)
- return(ierr(uerr_cod,0));
- else if (j) {
- i = j;
- j = - cts_mops[j - 1];
- }
- }
- if (j < 0) {
- ierr(uerr_cod,(cts_kops + i - 1)->kokeyn);
- iundo(ISADD,datno,-(j + 1),recptr,pntr,DRNZERO);
- return(isam_err);
- }
- #else
- for (i = 0; i < MAX_DAT_KEY; i++) {
- if ((keyno = ct_kymap[datno][i]) < 0 )
- break;
- if (frmkey(keyno,recptr,ct_kyval,DRNZERO))
- if (ADDKEY(keyno,ct_kyval,pntr,REGADD)) {
- ierr(uerr_cod,keyno);
- iundo(ISADD,datno,i,recptr,pntr,DRNZERO);
- return(isam_err);
- }
- }
- #endif
- return(NO_ERROR);
- }
-
- COUNT rwtikey(datno,recptr,pntr,old_pntr)
- COUNT datno;
- TEXT *recptr;
- POINTER pntr,old_pntr;
- {
- FAST COUNT i,keyno;
- COUNT old_flg,new_flg;
- #ifdef CTSERVER
- COUNT j,even_keyops;
- FAST KEYOPS *k;
-
- even_keyops = cts_keyops / 2 * 2;
- for (i = j = 0; i < MAX_DAT_KEY; i++) {
- if ((keyno = ct_kymap[datno][i]) < 0 )
- break;
- old_flg = frmkey(keyno,cur_image[datno],ct_fndval,old_pntr);
- new_flg = frmkey(keyno,recptr,ct_kyval,pntr);
- if (old_pntr != pntr || compar(ct_fndval,ct_kyval,
- ct_key + keyno)) {
- /* old <> new */
- if (even_keyops < 2) {
- if (old_flg && DELCHK(keyno,ct_fndval,old_pntr)) {
- ierr(uerr_cod,keyno);
- iundo(ISRWT,datno,i,recptr,pntr,old_pntr);
- return(isam_err);
- }
- if (new_flg && ADDKEY(keyno,ct_kyval,pntr,REGADD)) {
- ierr(uerr_cod,keyno);
- if (ADDKEY(keyno,ct_fndval,old_pntr,REGADD))
- isam_err = IUND_ERR;
- iundo(ISRWT,datno,i,recptr,pntr,old_pntr);
- return(isam_err);
- }
- } else {
- if (old_flg || new_flg) {
- cts_mops[j] = i + 1;
- k = cts_kops + j++;
- k->kokeyn = keyno;
- k->komode = FN_DELCHK;
- k->kopntr = old_pntr;
- if (old_flg)
- cpybuf(k->kobufr,ct_fndval,(ct_key + keyno)->length);
- else
- k->komode = 0;
- cts_mops[j] = i + 1;
- k = cts_kops + j++;
- k->kokeyn = keyno;
- k->komode = FN_ADDKEY;
- k->kopntr = pntr;
- if (new_flg)
- cpybuf(k->kobufr,ct_kyval,(ct_key + keyno)->length);
- else
- k->komode = 0;
- if (j == even_keyops) {
- j = MLTKEY(even_keyops);
- if (j == -2)
- return(ierr(uerr_cod,0));
- else if (j) {
- i = j;
- j = - cts_mops[j - 1];
- break;
- }
- }
- }
- }
- }
- }
- if (j > 0) {
- j = MLTKEY(j);
- if (j == -2)
- return(ierr(uerr_cod,0));
- else if (j) {
- i = j;
- j = - cts_mops[j - 1];
- }
- }
- if (j < 0) {
- ierr(uerr_cod,(cts_kops + --i)->kokeyn);
- if (i-- % 2)
- if ((k = (cts_kops + i))->komode)
- if (ADDKEY(k->kokeyn,k->kobufr,old_pntr,REGADD))
- isam_err = IUND_ERR;
- iundo(ISRWT,datno,-(j + 1),recptr,pntr,old_pntr);
- return(isam_err);
- }
- #else
- for (i = 0; i < MAX_DAT_KEY; i++) {
- if ((keyno = ct_kymap[datno][i]) < 0 )
- break;
- old_flg = frmkey(keyno,cur_image[datno],ct_fndval,old_pntr);
- new_flg = frmkey(keyno,recptr,ct_kyval,pntr);
- if (old_pntr != pntr || compar(ct_fndval,ct_kyval,ct_key + keyno)) {
- /* old <> new */
- if (old_flg && DELCHK(keyno,ct_fndval,old_pntr)) {
- ierr(uerr_cod,keyno);
- iundo(ISRWT,datno,i,recptr,pntr,old_pntr);
- return(isam_err);
- }
- if (new_flg && ADDKEY(keyno,ct_kyval,pntr,REGADD)) {
- ierr(uerr_cod,keyno);
- if (ADDKEY(keyno,ct_fndval,old_pntr,REGADD))
- isam_err = IUND_ERR;
- iundo(ISRWT,datno,i,recptr,pntr,old_pntr);
- return(isam_err);
- }
- }
- }
- #endif
- return(-i); /* NO_ERROR */
- }
-
- COUNT delikey(datno,recptr,pntr)
- COUNT datno;
- TEXT *recptr;
- POINTER pntr;
- {
- FAST COUNT i,keyno;
- #ifdef CTSERVER
- COUNT j;
- FAST KEYOPS *k;
-
- for (i = j = 0; i < MAX_DAT_KEY; i++) {
- if ((keyno = ct_kymap[datno][i]) < 0 )
- break;
- if (frmkey(keyno,recptr,ct_kyval,DRNZERO)) {
- if (cts_keyops < 2) {
- if (DELCHK(keyno,ct_kyval,pntr)) {
- ierr(uerr_cod,keyno);
- iundo(ISDEL,datno,i,recptr,DRNZERO,pntr);
- return(isam_err);
- }
- } else {
- cts_mops[j] = i + 1;
- k = cts_kops + j++;
- k->kokeyn = keyno;
- k->komode = FN_DELCHK;
- k->kopntr = pntr;
- cpybuf(k->kobufr,ct_kyval,(ct_key + keyno)->length);
- if (j == cts_keyops) {
- j = MLTKEY(cts_keyops);
- if (j == -2)
- return(ierr(uerr_cod,0));
- else if (j) {
- i = j;
- j = - cts_mops[j - 1];
- break;
- }
- }
- }
- }
- }
- if (j > 0) {
- j = MLTKEY(j);
- if (j == -2)
- return(ierr(uerr_cod,0));
- else if (j) {
- i = j;
- j = - cts_mops[j - 1];
- }
- }
- if (j < 0) {
- ierr(uerr_cod,(cts_kops + i - 1)->kokeyn);
- iundo(ISDEL,datno,-(j + 1),recptr,DRNZERO,pntr);
- return(isam_err);
- }
- #else
- for (i = 0; i < MAX_DAT_KEY; i++) {
- if ((keyno = ct_kymap[datno][i]) < 0)
- break;
- if (frmkey(keyno,recptr,ct_kyval,DRNZERO))
- if (DELCHK(keyno,ct_kyval,pntr)) {
- ierr(uerr_cod,keyno);
- iundo(ISDEL,datno,i,recptr,DRNZERO,pntr);
- return(isam_err);
- }
- }
- #endif
- return(-i); /* NO_ERROR */
- }
-
- /* end of ctism2.c */
-