2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1995-11-30 08:34:27 adam
8 * Started work on commit facility.
9 * Changed a few malloc/free to xmalloc/xfree.
11 * Revision 1.3 1995/11/20 16:59:45 adam
12 * New update method: the 'old' keys are saved for each records.
14 * Revision 1.2 1995/11/20 11:56:23 adam
15 * Work on new traversal.
17 * Revision 1.1 1995/11/17 15:54:42 adam
18 * Started work on virtual directory structure.
34 struct dirs_entry *entries;
38 struct dirs_entry *last_entry;
41 static int dirs_client_proc (Dict_char *name, const char *info, int pos,
44 struct dirs_info *ci = client;
45 struct dirs_entry *entry;
47 if (memcmp (name, ci->prefix, ci->prelen))
54 if (ci->no_cur == ci->no_max)
58 entry = ci->entries + ci->no_cur;
59 if (info[0] == sizeof(entry->sysno)+sizeof(entry->ctime))
61 strcpy (entry->path, name + ci->prelen);
62 entry->kind = dirs_file;
63 memcpy (&entry->sysno, info+1, sizeof(entry->sysno));
64 memcpy (&entry->ctime, info+1+sizeof(entry->sysno),
65 sizeof(entry->ctime));
68 else if (info[0] == sizeof(entry->ctime))
70 strcpy (entry->path, name + ci->prelen);
71 entry->kind = dirs_dir;
72 memcpy (&entry->ctime, info+1, sizeof(entry->ctime));
78 struct dirs_info *dirs_open (Dict dict, const char *rep)
81 int before = 0, after;
83 logf (LOG_DEBUG, "dirs_open %s", rep);
84 p = xmalloc (sizeof (*p));
86 strcpy (p->prefix, rep);
87 p->prelen = strlen(p->prefix);
88 strcpy (p->nextpath, rep);
89 p->no_read = p->no_cur = 0;
90 after = p->no_max = 400;
91 p->entries = xmalloc (sizeof(*p->entries) * (p->no_max));
92 logf (LOG_DEBUG, "dirs_open first scan");
93 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
97 struct dirs_entry *dirs_read (struct dirs_info *p)
99 int before = 0, after = p->no_max+1;
101 if (p->no_read < p->no_cur)
103 logf (LOG_DEBUG, "dirs_read %d. returns %s", p->no_read,
104 (p->entries + p->no_read)->path);
105 return p->last_entry = p->entries + (p->no_read++);
107 if (p->no_cur < p->no_max)
108 return p->last_entry = NULL;
110 logf (LOG_DEBUG, "dirs_read rescan");
111 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
113 if (p->no_read < p->no_cur)
114 return p->last_entry = p->entries;
115 return p->last_entry = NULL;
118 struct dirs_entry *dirs_last (struct dirs_info *p)
120 return p->last_entry;
123 void dirs_mkdir (struct dirs_info *p, const char *src, int ctime)
127 sprintf (path, "%s%s", p->prefix, src);
128 logf (LOG_DEBUG, "dirs_mkdir %s", path);
129 dict_insert (p->dict, path, sizeof(ctime), &ctime);
132 void dirs_rmdir (struct dirs_info *p, const char *src)
137 sprintf (path, "%s%s", p->prefix, src);
138 logf (LOG_DEBUG, "dirs_rmdir %s", path);
140 dict_insert (p->dict, path, 1, info);
143 void dirs_add (struct dirs_info *p, const char *src, int sysno, int ctime)
148 sprintf (path, "%s%s", p->prefix, src);
149 logf (LOG_DEBUG, "dirs_add %s", path);
150 memcpy (info, &sysno, sizeof(sysno));
151 memcpy (info+sizeof(sysno), &ctime, sizeof(ctime));
152 dict_insert (p->dict, path, sizeof(sysno)+sizeof(ctime), info);
155 void dirs_del (struct dirs_info *p, const char *src)
160 sprintf (path, "%s%s", p->prefix, src);
161 logf (LOG_DEBUG, "dirs_del %s", path);
163 dict_insert (p->dict, path, 1, info);
166 void dirs_free (struct dirs_info **pp)
168 struct dirs_info *p = *pp;