home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 228_01 / isamadd.c < prev    next >
Text File  |  1987-07-31  |  1KB  |  63 lines

  1. /*
  2. HEADER:         CUGXXX;
  3. TITLE:          Add an index record (of ISAM system);
  4. DATE:           3-31-86;
  5. DESCRIPTION:    Part of ISAM Library;
  6. KEYWORDS:       ISAM;
  7. FILENAME:       ISAMADD.C;
  8. WARNINGS:       None;
  9. AUTHORS:        John M. Dashner;
  10. COMPILER:       Lattice C;
  11. REFERENCES:     US-DISK 1310;
  12. ENDREF
  13. */
  14. /*
  15. **                 ISAMC - Written by John M. Dashner
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <ctype.h>
  20.  
  21. #include <isam.h>
  22.  
  23. /*
  24. **                  ADD - Add an Index Record
  25. */
  26.  
  27. isamadd(key, rec, hdr)
  28. char *key;
  29. unsigned rec;
  30. struct isam *hdr;
  31. {
  32.     struct rec1 *r1; struct rec2 *r2; struct rec3 *r3;
  33.     char buf[MAXKEY + 2];
  34.     int i, fp;
  35.     unsigned cur_rec, chn_rec;
  36.     int rec_len;
  37.     long lrec;
  38.  
  39.     rec_len = hdr->q6 + 2;
  40.     r1 = (struct rec1 *) buf;
  41.     r2 = (struct rec2 *) buf;
  42.     r3 = (struct rec3 *) buf;
  43.     fp = hdr->q7;
  44.  
  45.     cur_rec = hdr->q1;          /* tag to end of file */
  46.     hdr->q1 += 1;               /* update record count */
  47.     lrec = cur_rec * rec_len;
  48.     lseek(fp, lrec, 0);
  49.     r3->rec_ptr = rec;          /* build index record */
  50.     for(i=0;i<hdr->q6;i++)
  51.         r3->idx_key[i] = key[i];
  52.  
  53.     if(write(fp, buf, rec_len) == ERROR)
  54.     {
  55.         isam_err = 8;
  56.         return ERROR;
  57.     }
  58.     hdr->q4 = cur_rec;
  59.     hdr->q5 = 1;                /* mark as unsorted */
  60.     return NULL;
  61. }
  62.  
  63.