+void zebra_index_merge (ZebraHandle zh)
+{
+ struct key_file **kf;
+ char rbuf[1024];
+ int i, r;
+ struct heap_info *hi;
+ struct progressInfo progressInfo;
+ int nkeys = zh->key_file_no;
+
+ if (nkeys < 0)
+ {
+ char fname[1024];
+ nkeys = 0;
+ while (1)
+ {
+ extract_get_fname_tmp (zh, fname, nkeys+1);
+ if (access (fname, R_OK) == -1)
+ break;
+ nkeys++;
+ }
+ if (!nkeys)
+ return ;
+ }
+ kf = (struct key_file **) xmalloc ((1+nkeys) * sizeof(*kf));
+ progressInfo.totalBytes = 0;
+ progressInfo.totalOffset = 0;
+ time (&progressInfo.startTime);
+ time (&progressInfo.lastTime);
+ for (i = 1; i<=nkeys; i++)
+ {
+ kf[i] = key_file_init (i, 32768, zh->service->res);
+ kf[i]->readHandler = progressFunc;
+ kf[i]->readInfo = &progressInfo;
+ progressInfo.totalBytes += kf[i]->length;
+ progressInfo.totalOffset += kf[i]->buf_size;
+ }
+ hi = key_heap_init (nkeys, key_qsort_compare);
+ hi->dict = zh->service->dict;
+ hi->isams = zh->service->isams;
+#if ZMBOL
+ hi->isam = zh->service->isam;
+ hi->isamc = zh->service->isamc;
+ hi->isamd = zh->service->isamd;
+#endif
+
+ for (i = 1; i<=nkeys; i++)
+ if ((r = key_file_read (kf[i], rbuf)))
+ key_heap_insert (hi, rbuf, r, kf[i]);
+ if (zh->service->isams)
+ heap_inps (hi);
+#if ZMBOL
+ else if (zh->service->isamc)
+ heap_inpc (hi);
+ else if (zh->service->isam)
+ heap_inp (hi);
+ else if (zh->service->isamd)
+ heap_inpd (hi);
+#endif
+
+ for (i = 1; i<=nkeys; i++)
+ {
+ extract_get_fname_tmp (zh, rbuf, i);
+ unlink (rbuf);
+ }
+ logf (LOG_LOG, "Iterations . . .%7d", no_iterations);
+ logf (LOG_LOG, "Distinct words .%7d", no_diffs);
+ logf (LOG_LOG, "Updates. . . . .%7d", no_updates);
+ logf (LOG_LOG, "Deletions. . . .%7d", no_deletions);
+ logf (LOG_LOG, "Insertions . . .%7d", no_insertions);
+ zh->key_file_no = 0;
+}
+
+void key_input (BFiles bfs, int nkeys, int cache, Res res)