2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1996-03-21 14:50:09 adam
8 * File update uses modify-time instead of change-time.
10 * Revision 1.6 1996/02/02 13:44:43 adam
11 * The public dictionary functions simply use char instead of Dict_char
12 * to represent search strings. Dict_char is used internally only.
14 * Revision 1.5 1996/01/17 14:54:44 adam
15 * Function dirs_rmdir uses dict_delete.
17 * Revision 1.4 1995/11/30 08:34:27 adam
18 * Started work on commit facility.
19 * Changed a few malloc/free to xmalloc/xfree.
21 * Revision 1.3 1995/11/20 16:59:45 adam
22 * New update method: the 'old' keys are saved for each records.
24 * Revision 1.2 1995/11/20 11:56:23 adam
25 * Work on new traversal.
27 * Revision 1.1 1995/11/17 15:54:42 adam
28 * Started work on virtual directory structure.
44 struct dirs_entry *entries;
48 struct dirs_entry *last_entry;
51 static int dirs_client_proc (char *name, const char *info, int pos,
54 struct dirs_info *ci = client;
55 struct dirs_entry *entry;
57 if (memcmp (name, ci->prefix, ci->prelen))
64 if (ci->no_cur == ci->no_max)
68 entry = ci->entries + ci->no_cur;
69 if (info[0] == sizeof(entry->sysno)+sizeof(entry->mtime))
71 strcpy (entry->path, name + ci->prelen);
72 entry->kind = dirs_file;
73 memcpy (&entry->sysno, info+1, sizeof(entry->sysno));
74 memcpy (&entry->mtime, info+1+sizeof(entry->sysno),
75 sizeof(entry->mtime));
78 else if (info[0] == sizeof(entry->mtime))
80 strcpy (entry->path, name + ci->prelen);
81 entry->kind = dirs_dir;
82 memcpy (&entry->mtime, info+1, sizeof(entry->mtime));
88 struct dirs_info *dirs_open (Dict dict, const char *rep)
91 int before = 0, after;
93 logf (LOG_DEBUG, "dirs_open %s", rep);
94 p = xmalloc (sizeof (*p));
96 strcpy (p->prefix, rep);
97 p->prelen = strlen(p->prefix);
98 strcpy (p->nextpath, rep);
99 p->no_read = p->no_cur = 0;
100 after = p->no_max = 400;
101 p->entries = xmalloc (sizeof(*p->entries) * (p->no_max));
102 logf (LOG_DEBUG, "dirs_open first scan");
103 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
107 struct dirs_entry *dirs_read (struct dirs_info *p)
109 int before = 0, after = p->no_max+1;
111 if (p->no_read < p->no_cur)
113 logf (LOG_DEBUG, "dirs_read %d. returns %s", p->no_read,
114 (p->entries + p->no_read)->path);
115 return p->last_entry = p->entries + (p->no_read++);
117 if (p->no_cur < p->no_max)
118 return p->last_entry = NULL;
120 logf (LOG_DEBUG, "dirs_read rescan");
121 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
123 if (p->no_read < p->no_cur)
124 return p->last_entry = p->entries;
125 return p->last_entry = NULL;
128 struct dirs_entry *dirs_last (struct dirs_info *p)
130 return p->last_entry;
133 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime)
137 sprintf (path, "%s%s", p->prefix, src);
138 logf (LOG_DEBUG, "dirs_mkdir %s", path);
139 dict_insert (p->dict, path, sizeof(mtime), &mtime);
142 void dirs_rmdir (struct dirs_info *p, const char *src)
146 sprintf (path, "%s%s", p->prefix, src);
147 logf (LOG_DEBUG, "dirs_rmdir %s", path);
148 dict_delete (p->dict, path);
151 void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime)
156 sprintf (path, "%s%s", p->prefix, src);
157 logf (LOG_DEBUG, "dirs_add %s", path);
158 memcpy (info, &sysno, sizeof(sysno));
159 memcpy (info+sizeof(sysno), &mtime, sizeof(mtime));
160 dict_insert (p->dict, path, sizeof(sysno)+sizeof(mtime), info);
163 void dirs_del (struct dirs_info *p, const char *src)
168 sprintf (path, "%s%s", p->prefix, src);
169 logf (LOG_DEBUG, "dirs_del %s", path);
171 dict_insert (p->dict, path, 1, info);
174 void dirs_free (struct dirs_info **pp)
176 struct dirs_info *p = *pp;