home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / isam.lzh / ISAMC.C < prev    next >
Text File  |  1985-03-16  |  2KB  |  55 lines

  1. #include "stdio.h"
  2. #include "setjmp.h"
  3. #include "isamstr.h"
  4. #include "isam.h"
  5.  
  6.  /* checked correct 6-7-84 */
  7.  
  8.  /***************************************************************
  9.  *                      File ISAMC.C                            *
  10.  *      this function creates an isam file.                     *
  11.  *      name= file name                                         *
  12.  *      asize= size of allocation allowed for this index        *
  13.  *      ikeylen = length of a key in bytes                      *
  14.  *      ireclen = length of a record in bytes                   *
  15.  *      dupflag= true for errors on duplicate keys, else 0      *
  16.  ***************************************************************/
  17.  
  18. char    *calloc();
  19. int     creat(), write();
  20.  
  21. int     ind_create(name, asize, ikeylen, ireclen, dupflag)
  22.  
  23. char    *name;
  24. unsigned ikeylen, ireclen, dupflag, asize;
  25. {
  26.    unsigned al, n, m, l2, l3, r, rem;
  27.    char     iflags;
  28.  
  29.    r = 30;
  30.  
  31.    n = asize - (sizeof(struct global) + ikeylen - 1);
  32.    n -= (sizeof(struct recov) + (r - 1) * sizeof(long));
  33.  
  34.    n -= 2 * sizeof(struct l2_link) + sizeof(struct l2_elem) - 3 + 3
  35.        * ikeylen;
  36.  
  37.    al = (sizeof(struct m_elem) + 2 * sizeof(struct l2_elem)
  38.        + sizeof(struct l3_elem) - 4 + 4 * ikeylen);
  39.  
  40.    l2 = l3 = m = n / al;
  41.    rem = n % al;
  42.  
  43.    while(rem > (sizeof(struct l3_elem) - 1 + ikeylen)) {
  44.        ++l3;
  45.        rem -= (sizeof(struct l3_elem) - 1 + ikeylen);
  46.    }
  47.  
  48.    iflags = dupflag ? 1 : 0;
  49.  
  50.    return(ind_build(name, iflags, ikeylen, ireclen, m, l2, l3, r));
  51. }
  52.  /***************************************************************
  53.  *                      end of function                         *
  54.  ***************************************************************/
  55.