home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 170_01 / isamadd.c < prev    next >
Text File  |  1979-12-31  |  1KB  |  50 lines

  1. /*
  2. **                 ISAMC - Written by John M. Dashner
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7.  
  8. #include <isam.h>
  9.  
  10. /*
  11. **                  ADD - Add an Index Record
  12. */
  13.  
  14. isamadd(key, rec, hdr)
  15. char *key;
  16. unsigned rec;
  17. struct isam *hdr;
  18. {
  19.     struct rec1 *r1; struct rec2 *r2; struct rec3 *r3;
  20.     char buf[MAXKEY + 2];
  21.     int i, fp;
  22.     unsigned cur_rec, chn_rec;
  23.     int rec_len;
  24.     long lrec;
  25.  
  26.     rec_len = hdr->q6 + 2;
  27.     r1 = (struct rec1 *) buf;
  28.     r2 = (struct rec2 *) buf;
  29.     r3 = (struct rec3 *) buf;
  30.     fp = hdr->q7;
  31.  
  32.     cur_rec = hdr->q1;          /* tag to end of file */
  33.     hdr->q1 += 1;               /* update record count */
  34.     lrec = cur_rec * rec_len;
  35.     lseek(fp, lrec, 0);
  36.     r3->rec_ptr = rec;          /* build index record */
  37.     for(i=0;i<hdr->q6;i++)
  38.         r3->idx_key[i] = key[i];
  39.  
  40.     if(write(fp, buf, rec_len) == ERROR)
  41.     {
  42.         isam_err = 8;
  43.         return ERROR;
  44.     }
  45.     hdr->q4 = cur_rec;
  46.     hdr->q5 = 1;                /* mark as unsorted */
  47.     return NULL;
  48. }
  49.  
  50.