2 * Copyright (C) 1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-09-04 12:33:42 adam
8 * Various cleanup. YAZ util used instead.
10 * Revision 1.1 1995/09/04 09:10:37 adam
11 * More work on index add/del/update.
12 * Merge sort implemented.
13 * Initial work on z39 server.
25 #define KEY_SIZE (1+sizeof(struct it_key))
26 #define INP_NAME_MAX 8192
27 #define INP_BUF_START 60000
28 #define INP_BUF_ADD 400000
30 static int no_diffs = 0;
31 static int no_updates = 0;
32 static int no_insertions = 0;
33 static int no_iterations = 0;
35 static int read_one (FILE *inf, char *name, char *key)
42 if ((c=getc(inf)) == EOF)
46 for (i = 0; i<KEY_SIZE; i++)
47 ((char *)key)[i] = getc (inf);
52 static int inp (Dict dict, ISAM isam, const char *name)
56 char next_name[INP_NAME_MAX+1];
57 char cur_name[INP_NAME_MAX+1];
58 int key_buf_size = INP_BUF_START;
63 next_key = xmalloc (KEY_SIZE);
64 key_buf = xmalloc (key_buf_size * (KEY_SIZE));
65 if (!(inf = fopen (name, "r")))
67 logf (LOG_FATAL|LOG_ERRNO, "cannot open `%s'", name);
70 read_one (inf, cur_name, key_buf);
71 while (cur_name[0]) /* EOF ? */
74 key_buf_ptr = KEY_SIZE;
77 if (!read_one (inf, next_name, next_key))
79 if (strcmp (next_name, cur_name))
81 memcpy (key_buf + key_buf_ptr, next_key, KEY_SIZE);
82 key_buf_ptr += KEY_SIZE;
83 if (key_buf_ptr+KEY_SIZE >= key_buf_size)
86 new_key_buf = xmalloc (key_buf_size + INP_BUF_ADD);
87 memcpy (new_key_buf, key_buf, key_buf_size);
88 key_buf_size += INP_BUF_ADD;
90 key_buf = new_key_buf;
94 nmemb = key_buf_ptr / KEY_SIZE;
95 assert (nmemb*KEY_SIZE == key_buf_ptr);
96 if ((info = dict_lookup (dict, cur_name)))
98 ISAM_P isam_p, isam_p2;
99 logf (LOG_DEBUG, "updating %s", cur_name);
101 memcpy (&isam_p, info+1, sizeof(ISAM_P));
102 isam_p2 = is_merge (isam, isam_p, nmemb, key_buf);
103 if (isam_p2 != isam_p)
104 dict_insert (dict, cur_name, sizeof(ISAM_P), &isam_p2);
109 logf (LOG_DEBUG, "inserting %s", cur_name);
111 isam_p = is_merge (isam, 0, nmemb, key_buf);
112 dict_insert (dict, cur_name, sizeof(ISAM_P), &isam_p);
114 memcpy (key_buf, next_key, KEY_SIZE);
115 strcpy (cur_name, next_name);
121 void key_input (const char *dict_fname, const char *isam_fname,
122 const char *key_fname, int cache)
127 dict = dict_open (dict_fname, cache, 1);
130 logf (LOG_FATAL, "dict_open fail of `%s'", dict_fname);
133 isam = is_open (isam_fname, key_compare, 1);
136 logf (LOG_FATAL, "is_open fail of `%s'", isam_fname);
139 inp (dict, isam, key_fname);
142 logf (LOG_LOG, "Iterations . . .%7d", no_iterations);
143 logf (LOG_LOG, "Distinct words .%7d", no_diffs);
144 logf (LOG_LOG, "Updates. . . . .%7d", no_updates);
145 logf (LOG_LOG, "Insertions . . .%7d", no_insertions);