home *** CD-ROM | disk | FTP | other *** search
- /* btopen */
- #include <stdio.h>
- #include <btextern.h>
-
- int btopen (gfilnam)
- char gfilnam[];
-
-
- /* open an existing index file */
- {
- int i, *ip,occurs;
- char *cp;
-
- if ((fp = fopen (gfilnam, "rwb")) == NULL)
- BTSETCOD (NULL, NULL, 4); /* set file open error */
- if ((openkt = btopnkt () ) == -1)
- BTSETCOD (NULL, NULL, 63); /* set max files open */
- if (!(btfilar[openkt].infobuf =
- (int *)calloc (LBLEN, sizeof (char))))
- BTSETCOD (openkt, NULL, 7); /* no memory */
- if (!(btfilar[openkt].filbuf =
- (int *)calloc (LBLEN ,sizeof (char))))
- BTSETCOD (openkt, NULL, 7); /* no memory */
-
- /* now read index info record = # zero */
- btfilar[openkt].fdesc = fp;
- if ((i = btread (openkt, 0)))
- BTSETCOD (openkt, 0, i); /* bad read */
- movmem (btfilar[openkt].filbuf, btfilar[openkt].infobuf,LBLEN);
-
- /* initialize file control block */
- ip = btfilar[openkt].infobuf; /* initialize pointer */
- btfilar[openkt].handle = openkt;
- strcpy (btfilar[openkt].curkey," ");
- occurs = (LBLEN - 1) / (gkeylen + 3);
- btfilar[openkt].ikeyptr =
- (char *)(btfilar[openkt].filbuf + occurs);
- btfilar[openkt].root = *ip++; /* 1 st integer */
- btfilar[openkt].keylen = *ip; /* 2 nd integer */
- strcpy (btfilar[openkt].filnam, gfilnam); /* copy file name */
- btfilar[openkt].fdesc = fp;
-
- /* now read root record into filbuf */
- if ((i = btread (openkt, btfilar[openkt].root)))
- BTSETCOD (openkt, btfilar[openkt].root, i); /* bad read */
-
- /* give value of openkt to the world */
- gfilhand = openkt;
- return (0);
- }
- /* end of btopen */