-/*
- * Copyright (C) 1994, Index Data I/S
- * All rights reserved.
- * Sebastian Hammer, Adam Dickmeiss
- *
- * $Log: main.c,v $
- * Revision 1.1 1995-08-31 14:50:24 adam
- * New simple file index tool.
- *
- */
-#include <stdio.h>
-#include <assert.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <ctype.h>
-
-#include <util.h>
-#include "index.h"
-
-char *prog;
-
-static int key_fd = -1;
-#define KEY_BUF_SIZE 100000
-static char *key_buf;
-int key_offset;
-SYSNO sysno_next;
-Dict file_idx;
-static char *base_path = NULL;
-
-void key_open (const char *fname)
-{
- void *file_key;
- if (key_fd != -1)
- return;
- if ((key_fd = open (fname, O_RDWR|O_CREAT, 0666)) == -1)
- {
- log (LOG_FATAL|LOG_ERRNO, "Creat %s", fname);
- exit (1);
- }
- if (!(key_buf = malloc (KEY_BUF_SIZE)))
- {
- log (LOG_FATAL|LOG_ERRNO, "malloc");
- exit (1);
- }
- key_offset = 0;
- if (!(file_idx = dict_open ("fileidx", 10, 1)))
- {
- log (LOG_FATAL, "dict_open fail of %s", "fileidx");
- exit (1);
- }
- file_key = dict_lookup (file_idx, ".");
- if (file_key)
- memcpy (&sysno_next, (char*)file_key+1, sizeof(sysno_next));
- else
- sysno_next = 1;
-}
-
-void key_close (void)
-{
- if (key_fd == -1)
- return;
- close (key_fd);
- dict_insert (file_idx, ".", sizeof(sysno_next), &sysno_next);
- dict_close (file_idx);
- key_fd = -1;
-}
-
-void key_flush (void)
-{
- size_t i = 0;
- int w;
-
- while (i < key_offset)
- {
- w = write (key_fd, key_buf + i, key_offset - i);
- if (w == -1)
- {
- log (LOG_FATAL|LOG_ERRNO, "Write key fail");
- exit (1);
- }
- i += w;
- }
- key_offset = 0;
-}
+/* $Id: main.c,v 1.113 2004-08-25 09:23:36 adam Exp $
+ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
+ Index Data Aps