2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1996-01-17 14:54:44 adam
8 * Function dirs_rmdir uses dict_delete.
10 * Revision 1.4 1995/11/30 08:34:27 adam
11 * Started work on commit facility.
12 * Changed a few malloc/free to xmalloc/xfree.
14 * Revision 1.3 1995/11/20 16:59:45 adam
15 * New update method: the 'old' keys are saved for each records.
17 * Revision 1.2 1995/11/20 11:56:23 adam
18 * Work on new traversal.
20 * Revision 1.1 1995/11/17 15:54:42 adam
21 * Started work on virtual directory structure.
37 struct dirs_entry *entries;
41 struct dirs_entry *last_entry;
44 static int dirs_client_proc (Dict_char *name, const char *info, int pos,
47 struct dirs_info *ci = client;
48 struct dirs_entry *entry;
50 if (memcmp (name, ci->prefix, ci->prelen))
57 if (ci->no_cur == ci->no_max)
61 entry = ci->entries + ci->no_cur;
62 if (info[0] == sizeof(entry->sysno)+sizeof(entry->ctime))
64 strcpy (entry->path, name + ci->prelen);
65 entry->kind = dirs_file;
66 memcpy (&entry->sysno, info+1, sizeof(entry->sysno));
67 memcpy (&entry->ctime, info+1+sizeof(entry->sysno),
68 sizeof(entry->ctime));
71 else if (info[0] == sizeof(entry->ctime))
73 strcpy (entry->path, name + ci->prelen);
74 entry->kind = dirs_dir;
75 memcpy (&entry->ctime, info+1, sizeof(entry->ctime));
81 struct dirs_info *dirs_open (Dict dict, const char *rep)
84 int before = 0, after;
86 logf (LOG_DEBUG, "dirs_open %s", rep);
87 p = xmalloc (sizeof (*p));
89 strcpy (p->prefix, rep);
90 p->prelen = strlen(p->prefix);
91 strcpy (p->nextpath, rep);
92 p->no_read = p->no_cur = 0;
93 after = p->no_max = 400;
94 p->entries = xmalloc (sizeof(*p->entries) * (p->no_max));
95 logf (LOG_DEBUG, "dirs_open first scan");
96 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
100 struct dirs_entry *dirs_read (struct dirs_info *p)
102 int before = 0, after = p->no_max+1;
104 if (p->no_read < p->no_cur)
106 logf (LOG_DEBUG, "dirs_read %d. returns %s", p->no_read,
107 (p->entries + p->no_read)->path);
108 return p->last_entry = p->entries + (p->no_read++);
110 if (p->no_cur < p->no_max)
111 return p->last_entry = NULL;
113 logf (LOG_DEBUG, "dirs_read rescan");
114 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
116 if (p->no_read < p->no_cur)
117 return p->last_entry = p->entries;
118 return p->last_entry = NULL;
121 struct dirs_entry *dirs_last (struct dirs_info *p)
123 return p->last_entry;
126 void dirs_mkdir (struct dirs_info *p, const char *src, int ctime)
130 sprintf (path, "%s%s", p->prefix, src);
131 logf (LOG_DEBUG, "dirs_mkdir %s", path);
132 dict_insert (p->dict, path, sizeof(ctime), &ctime);
135 void dirs_rmdir (struct dirs_info *p, const char *src)
139 sprintf (path, "%s%s", p->prefix, src);
140 logf (LOG_DEBUG, "dirs_rmdir %s", path);
141 dict_delete (p->dict, path);
144 void dirs_add (struct dirs_info *p, const char *src, int sysno, int ctime)
149 sprintf (path, "%s%s", p->prefix, src);
150 logf (LOG_DEBUG, "dirs_add %s", path);
151 memcpy (info, &sysno, sizeof(sysno));
152 memcpy (info+sizeof(sysno), &ctime, sizeof(ctime));
153 dict_insert (p->dict, path, sizeof(sysno)+sizeof(ctime), info);
156 void dirs_del (struct dirs_info *p, const char *src)
161 sprintf (path, "%s%s", p->prefix, src);
162 logf (LOG_DEBUG, "dirs_del %s", path);
164 dict_insert (p->dict, path, 1, info);
167 void dirs_free (struct dirs_info **pp)
169 struct dirs_info *p = *pp;