2 * Copyright (C) 1998, Index Data ApS
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1999-11-30 13:48:03 adam
8 * Improved installation. Updated for inclusion of YAZ header files.
10 * Revision 1.3 1999/05/26 07:49:13 adam
13 * Revision 1.2 1998/06/25 09:55:50 adam
14 * Minor changes - fixex headers.
24 #define SORT_IDX_BLOCKSIZE 64
33 struct sortFile *next;
34 struct sortFileHead head;
42 struct sortFile *current_file;
43 struct sortFile *files;
46 SortIdx sortIdx_open (BFiles bfs, int write_flag)
48 SortIdx si = (SortIdx) xmalloc (sizeof(*si));
50 si->write_flag = write_flag;
51 si->current_file = NULL;
53 si->entry_buf = (char *) xmalloc (SORT_IDX_ENTRYSIZE);
57 void sortIdx_close (SortIdx si)
59 struct sortFile *sf = si->files;
62 struct sortFile *sf_next = sf->next;
68 xfree (si->entry_buf);
72 int sortIdx_type (SortIdx si, int type)
76 if (si->current_file && si->current_file->type == type)
78 for (sf = si->files; sf; sf = sf->next)
81 si->current_file = sf;
84 sf = (struct sortFile *) xmalloc (sizeof(*sf));
88 si->current_file = si->files = sf;
89 sprintf (fname, "sort%d", type);
90 logf (LOG_DEBUG, "sort idx %s wr=%d", fname, si->write_flag);
91 sf->bf = bf_open (si->bfs, fname, SORT_IDX_BLOCKSIZE, si->write_flag);
94 if (!bf_read (sf->bf, 0, 0, sizeof(sf->head), &sf->head))
96 sf->head.sysno_max = 0;
103 void sortIdx_sysno (SortIdx si, int sysno)
108 void sortIdx_add (SortIdx si, const char *buf, int len)
110 if (!si->current_file || !si->current_file->bf)
112 if (len > SORT_IDX_ENTRYSIZE)
114 len = SORT_IDX_ENTRYSIZE;
115 memcpy (si->entry_buf, buf, len);
119 memcpy (si->entry_buf, buf, len);
120 memset (si->entry_buf+len, 0, SORT_IDX_ENTRYSIZE-len);
122 bf_write (si->current_file->bf, si->sysno+1, 0, 0, si->entry_buf);
125 void sortIdx_read (SortIdx si, char *buf)
127 bf_read (si->current_file->bf, si->sysno+1, 0, 0, buf);