2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.16 1999-05-26 07:49:13 adam
10 * Revision 1.15 1999/02/02 14:50:51 adam
11 * Updated WIN32 code specific sections. Changed header.
13 * Revision 1.14 1998/01/12 15:04:07 adam
14 * The test option (-s) only uses read-lock (and not write lock).
16 * Revision 1.13 1997/09/09 13:38:06 adam
17 * Partial port to WIN95/NT.
19 * Revision 1.12 1996/11/08 11:10:13 adam
20 * Buffers used during file match got bigger.
21 * Compressed ISAM support everywhere.
22 * Bug fixes regarding masking characters in queries.
23 * Redesigned Regexp-2 queries.
25 * Revision 1.11 1996/10/29 14:06:47 adam
26 * Include zebrautl.h instead of alexutil.h.
28 * Revision 1.10 1996/06/04 10:18:58 adam
29 * Minor changes - removed include of ctype.h.
31 * Revision 1.9 1996/04/23 12:39:07 adam
32 * Bug fix: In function dirs_del dict_delete is used to remove a file
33 * rather than a bogus dict_insert.
35 * Revision 1.8 1996/04/12 07:02:21 adam
36 * File update of single files.
38 * Revision 1.7 1996/03/21 14:50:09 adam
39 * File update uses modify-time instead of change-time.
41 * Revision 1.6 1996/02/02 13:44:43 adam
42 * The public dictionary functions simply use char instead of Dict_char
43 * to represent search strings. Dict_char is used internally only.
45 * Revision 1.5 1996/01/17 14:54:44 adam
46 * Function dirs_rmdir uses dict_delete.
48 * Revision 1.4 1995/11/30 08:34:27 adam
49 * Started work on commit facility.
50 * Changed a few malloc/free to xmalloc/xfree.
52 * Revision 1.3 1995/11/20 16:59:45 adam
53 * New update method: the 'old' keys are saved for each records.
55 * Revision 1.2 1995/11/20 11:56:23 adam
56 * Work on new traversal.
58 * Revision 1.1 1995/11/17 15:54:42 adam
59 * Started work on virtual directory structure.
69 #define DIRS_MAX_PATH 1024
77 struct dirs_entry *entries;
78 char nextpath[DIRS_MAX_PATH];
79 char prefix[DIRS_MAX_PATH];
81 struct dirs_entry *last_entry;
84 static int dirs_client_proc (char *name, const char *info, int pos,
87 struct dirs_info *ci = (struct dirs_info *) client;
88 struct dirs_entry *entry;
90 if (memcmp (name, ci->prefix, ci->prelen))
97 if (ci->no_cur == ci->no_max)
101 entry = ci->entries + ci->no_cur;
102 if (info[0] == sizeof(entry->sysno)+sizeof(entry->mtime))
104 strcpy (entry->path, name + ci->prelen);
105 entry->kind = dirs_file;
106 memcpy (&entry->sysno, info+1, sizeof(entry->sysno));
107 memcpy (&entry->mtime, info+1+sizeof(entry->sysno),
108 sizeof(entry->mtime));
111 else if (info[0] == sizeof(entry->mtime))
113 strcpy (entry->path, name + ci->prelen);
114 entry->kind = dirs_dir;
115 memcpy (&entry->mtime, info+1, sizeof(entry->mtime));
121 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw)
124 int before = 0, after;
126 logf (LOG_DEBUG, "dirs_open %s", rep);
127 p = (struct dirs_info *) xmalloc (sizeof (*p));
130 strcpy (p->prefix, rep);
131 p->prelen = strlen(p->prefix);
132 strcpy (p->nextpath, rep);
133 p->no_read = p->no_cur = 0;
134 after = p->no_max = 100;
135 p->entries = (struct dirs_entry *)
136 xmalloc (sizeof(*p->entries) * (p->no_max));
137 logf (LOG_DEBUG, "dirs_open first scan");
138 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
142 struct dirs_info *dirs_fopen (Dict dict, const char *path)
145 struct dirs_entry *entry;
148 p = (struct dirs_info *) xmalloc (sizeof(*p));
151 p->entries = (struct dirs_entry *) xmalloc (sizeof(*p->entries));
157 info = dict_lookup (dict, path);
158 if (info && info[0] == sizeof(entry->sysno)+sizeof(entry->mtime))
160 strcpy (entry->path, path);
161 entry->kind = dirs_file;
162 memcpy (&entry->sysno, info+1, sizeof(entry->sysno));
163 memcpy (&entry->mtime, info+1+sizeof(entry->sysno),
164 sizeof(entry->mtime));
170 struct dirs_entry *dirs_read (struct dirs_info *p)
172 int before = 0, after = p->no_max+1;
174 if (p->no_read < p->no_cur)
176 logf (LOG_DEBUG, "dirs_read %d. returns %s", p->no_read,
177 (p->entries + p->no_read)->path);
178 return p->last_entry = p->entries + (p->no_read++);
180 if (p->no_cur < p->no_max)
181 return p->last_entry = NULL;
183 logf (LOG_DEBUG, "dirs_read rescan");
184 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
186 if (p->no_read < p->no_cur)
187 return p->last_entry = p->entries;
188 return p->last_entry = NULL;
191 struct dirs_entry *dirs_last (struct dirs_info *p)
193 return p->last_entry;
196 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime)
198 char path[DIRS_MAX_PATH];
200 sprintf (path, "%s%s", p->prefix, src);
201 logf (LOG_DEBUG, "dirs_mkdir %s", path);
203 dict_insert (p->dict, path, sizeof(mtime), &mtime);
206 void dirs_rmdir (struct dirs_info *p, const char *src)
208 char path[DIRS_MAX_PATH];
210 sprintf (path, "%s%s", p->prefix, src);
211 logf (LOG_DEBUG, "dirs_rmdir %s", path);
213 dict_delete (p->dict, path);
216 void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime)
218 char path[DIRS_MAX_PATH];
221 sprintf (path, "%s%s", p->prefix, src);
222 logf (LOG_DEBUG, "dirs_add %s", path);
223 memcpy (info, &sysno, sizeof(sysno));
224 memcpy (info+sizeof(sysno), &mtime, sizeof(mtime));
226 dict_insert (p->dict, path, sizeof(sysno)+sizeof(mtime), info);
229 void dirs_del (struct dirs_info *p, const char *src)
231 char path[DIRS_MAX_PATH];
233 sprintf (path, "%s%s", p->prefix, src);
234 logf (LOG_DEBUG, "dirs_del %s", path);
236 dict_delete (p->dict, path);
239 void dirs_free (struct dirs_info **pp)
241 struct dirs_info *p = *pp;