2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.13 1997-09-09 13:38:06 adam
8 * Partial port to WIN95/NT.
10 * Revision 1.12 1996/11/08 11:10:13 adam
11 * Buffers used during file match got bigger.
12 * Compressed ISAM support everywhere.
13 * Bug fixes regarding masking characters in queries.
14 * Redesigned Regexp-2 queries.
16 * Revision 1.11 1996/10/29 14:06:47 adam
17 * Include zebrautl.h instead of alexutil.h.
19 * Revision 1.10 1996/06/04 10:18:58 adam
20 * Minor changes - removed include of ctype.h.
22 * Revision 1.9 1996/04/23 12:39:07 adam
23 * Bug fix: In function dirs_del dict_delete is used to remove a file
24 * rather than a bogus dict_insert.
26 * Revision 1.8 1996/04/12 07:02:21 adam
27 * File update of single files.
29 * Revision 1.7 1996/03/21 14:50:09 adam
30 * File update uses modify-time instead of change-time.
32 * Revision 1.6 1996/02/02 13:44:43 adam
33 * The public dictionary functions simply use char instead of Dict_char
34 * to represent search strings. Dict_char is used internally only.
36 * Revision 1.5 1996/01/17 14:54:44 adam
37 * Function dirs_rmdir uses dict_delete.
39 * Revision 1.4 1995/11/30 08:34:27 adam
40 * Started work on commit facility.
41 * Changed a few malloc/free to xmalloc/xfree.
43 * Revision 1.3 1995/11/20 16:59:45 adam
44 * New update method: the 'old' keys are saved for each records.
46 * Revision 1.2 1995/11/20 11:56:23 adam
47 * Work on new traversal.
49 * Revision 1.1 1995/11/17 15:54:42 adam
50 * Started work on virtual directory structure.
60 #define DIRS_MAX_PATH 1024
67 struct dirs_entry *entries;
68 char nextpath[DIRS_MAX_PATH];
69 char prefix[DIRS_MAX_PATH];
71 struct dirs_entry *last_entry;
74 static int dirs_client_proc (char *name, const char *info, int pos,
77 struct dirs_info *ci = client;
78 struct dirs_entry *entry;
80 if (memcmp (name, ci->prefix, ci->prelen))
87 if (ci->no_cur == ci->no_max)
91 entry = ci->entries + ci->no_cur;
92 if (info[0] == sizeof(entry->sysno)+sizeof(entry->mtime))
94 strcpy (entry->path, name + ci->prelen);
95 entry->kind = dirs_file;
96 memcpy (&entry->sysno, info+1, sizeof(entry->sysno));
97 memcpy (&entry->mtime, info+1+sizeof(entry->sysno),
98 sizeof(entry->mtime));
101 else if (info[0] == sizeof(entry->mtime))
103 strcpy (entry->path, name + ci->prelen);
104 entry->kind = dirs_dir;
105 memcpy (&entry->mtime, info+1, sizeof(entry->mtime));
111 struct dirs_info *dirs_open (Dict dict, const char *rep)
114 int before = 0, after;
116 logf (LOG_DEBUG, "dirs_open %s", rep);
117 p = xmalloc (sizeof (*p));
119 strcpy (p->prefix, rep);
120 p->prelen = strlen(p->prefix);
121 strcpy (p->nextpath, rep);
122 p->no_read = p->no_cur = 0;
123 after = p->no_max = 100;
124 p->entries = xmalloc (sizeof(*p->entries) * (p->no_max));
125 logf (LOG_DEBUG, "dirs_open first scan");
126 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
130 struct dirs_info *dirs_fopen (Dict dict, const char *path)
133 struct dirs_entry *entry;
136 p = xmalloc (sizeof(*p));
139 p->entries = xmalloc (sizeof(*p->entries));
145 info = dict_lookup (dict, path);
146 if (info && info[0] == sizeof(entry->sysno)+sizeof(entry->mtime))
148 strcpy (entry->path, path);
149 entry->kind = dirs_file;
150 memcpy (&entry->sysno, info+1, sizeof(entry->sysno));
151 memcpy (&entry->mtime, info+1+sizeof(entry->sysno),
152 sizeof(entry->mtime));
158 struct dirs_entry *dirs_read (struct dirs_info *p)
160 int before = 0, after = p->no_max+1;
162 if (p->no_read < p->no_cur)
164 logf (LOG_DEBUG, "dirs_read %d. returns %s", p->no_read,
165 (p->entries + p->no_read)->path);
166 return p->last_entry = p->entries + (p->no_read++);
168 if (p->no_cur < p->no_max)
169 return p->last_entry = NULL;
171 logf (LOG_DEBUG, "dirs_read rescan");
172 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
174 if (p->no_read < p->no_cur)
175 return p->last_entry = p->entries;
176 return p->last_entry = NULL;
179 struct dirs_entry *dirs_last (struct dirs_info *p)
181 return p->last_entry;
184 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime)
186 char path[DIRS_MAX_PATH];
188 sprintf (path, "%s%s", p->prefix, src);
189 logf (LOG_DEBUG, "dirs_mkdir %s", path);
190 dict_insert (p->dict, path, sizeof(mtime), &mtime);
193 void dirs_rmdir (struct dirs_info *p, const char *src)
195 char path[DIRS_MAX_PATH];
197 sprintf (path, "%s%s", p->prefix, src);
198 logf (LOG_DEBUG, "dirs_rmdir %s", path);
199 dict_delete (p->dict, path);
202 void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime)
204 char path[DIRS_MAX_PATH];
207 sprintf (path, "%s%s", p->prefix, src);
208 logf (LOG_DEBUG, "dirs_add %s", path);
209 memcpy (info, &sysno, sizeof(sysno));
210 memcpy (info+sizeof(sysno), &mtime, sizeof(mtime));
211 dict_insert (p->dict, path, sizeof(sysno)+sizeof(mtime), info);
214 void dirs_del (struct dirs_info *p, const char *src)
216 char path[DIRS_MAX_PATH];
218 sprintf (path, "%s%s", p->prefix, src);
219 logf (LOG_DEBUG, "dirs_del %s", path);
220 dict_delete (p->dict, path);
223 void dirs_free (struct dirs_info **pp)
225 struct dirs_info *p = *pp;