2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1996-02-02 13:44:43 adam
8 * The public dictionary functions simply use char instead of Dict_char
9 * to represent search strings. Dict_char is used internally only.
11 * Revision 1.5 1996/01/17 14:54:44 adam
12 * Function dirs_rmdir uses dict_delete.
14 * Revision 1.4 1995/11/30 08:34:27 adam
15 * Started work on commit facility.
16 * Changed a few malloc/free to xmalloc/xfree.
18 * Revision 1.3 1995/11/20 16:59:45 adam
19 * New update method: the 'old' keys are saved for each records.
21 * Revision 1.2 1995/11/20 11:56:23 adam
22 * Work on new traversal.
24 * Revision 1.1 1995/11/17 15:54:42 adam
25 * Started work on virtual directory structure.
41 struct dirs_entry *entries;
45 struct dirs_entry *last_entry;
48 static int dirs_client_proc (char *name, const char *info, int pos,
51 struct dirs_info *ci = client;
52 struct dirs_entry *entry;
54 if (memcmp (name, ci->prefix, ci->prelen))
61 if (ci->no_cur == ci->no_max)
65 entry = ci->entries + ci->no_cur;
66 if (info[0] == sizeof(entry->sysno)+sizeof(entry->ctime))
68 strcpy (entry->path, name + ci->prelen);
69 entry->kind = dirs_file;
70 memcpy (&entry->sysno, info+1, sizeof(entry->sysno));
71 memcpy (&entry->ctime, info+1+sizeof(entry->sysno),
72 sizeof(entry->ctime));
75 else if (info[0] == sizeof(entry->ctime))
77 strcpy (entry->path, name + ci->prelen);
78 entry->kind = dirs_dir;
79 memcpy (&entry->ctime, info+1, sizeof(entry->ctime));
85 struct dirs_info *dirs_open (Dict dict, const char *rep)
88 int before = 0, after;
90 logf (LOG_DEBUG, "dirs_open %s", rep);
91 p = xmalloc (sizeof (*p));
93 strcpy (p->prefix, rep);
94 p->prelen = strlen(p->prefix);
95 strcpy (p->nextpath, rep);
96 p->no_read = p->no_cur = 0;
97 after = p->no_max = 400;
98 p->entries = xmalloc (sizeof(*p->entries) * (p->no_max));
99 logf (LOG_DEBUG, "dirs_open first scan");
100 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
104 struct dirs_entry *dirs_read (struct dirs_info *p)
106 int before = 0, after = p->no_max+1;
108 if (p->no_read < p->no_cur)
110 logf (LOG_DEBUG, "dirs_read %d. returns %s", p->no_read,
111 (p->entries + p->no_read)->path);
112 return p->last_entry = p->entries + (p->no_read++);
114 if (p->no_cur < p->no_max)
115 return p->last_entry = NULL;
117 logf (LOG_DEBUG, "dirs_read rescan");
118 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
120 if (p->no_read < p->no_cur)
121 return p->last_entry = p->entries;
122 return p->last_entry = NULL;
125 struct dirs_entry *dirs_last (struct dirs_info *p)
127 return p->last_entry;
130 void dirs_mkdir (struct dirs_info *p, const char *src, int ctime)
134 sprintf (path, "%s%s", p->prefix, src);
135 logf (LOG_DEBUG, "dirs_mkdir %s", path);
136 dict_insert (p->dict, path, sizeof(ctime), &ctime);
139 void dirs_rmdir (struct dirs_info *p, const char *src)
143 sprintf (path, "%s%s", p->prefix, src);
144 logf (LOG_DEBUG, "dirs_rmdir %s", path);
145 dict_delete (p->dict, path);
148 void dirs_add (struct dirs_info *p, const char *src, int sysno, int ctime)
153 sprintf (path, "%s%s", p->prefix, src);
154 logf (LOG_DEBUG, "dirs_add %s", path);
155 memcpy (info, &sysno, sizeof(sysno));
156 memcpy (info+sizeof(sysno), &ctime, sizeof(ctime));
157 dict_insert (p->dict, path, sizeof(sysno)+sizeof(ctime), info);
160 void dirs_del (struct dirs_info *p, const char *src)
165 sprintf (path, "%s%s", p->prefix, src);
166 logf (LOG_DEBUG, "dirs_del %s", path);
168 dict_insert (p->dict, path, 1, info);
171 void dirs_free (struct dirs_info **pp)
173 struct dirs_info *p = *pp;