2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-11-20 11:56:23 adam
8 * Work on new traversal.
10 * Revision 1.1 1995/11/17 15:54:42 adam
11 * Started work on virtual directory structure.
27 struct dirs_entry *entries;
31 struct dirs_entry *last_entry;
34 static int dirs_client_proc (Dict_char *name, const char *info, int pos,
37 struct dirs_info *ci = client;
38 struct dirs_entry *entry;
40 if (memcmp (name, ci->prefix, ci->prelen))
47 if (ci->no_cur == ci->no_max)
51 entry = ci->entries + ci->no_cur;
52 if (info[0] == sizeof(entry->sysno)+sizeof(entry->ctime))
54 strcpy (entry->path, name + ci->prelen);
55 entry->kind = dirs_file;
56 memcpy (&entry->sysno, info+1, sizeof(entry->sysno));
57 memcpy (&entry->ctime, info+1+sizeof(entry->sysno),
58 sizeof(entry->ctime));
61 else if (info[0] == sizeof(entry->ctime))
63 strcpy (entry->path, name + ci->prelen);
64 entry->kind = dirs_dir;
65 memcpy (&entry->ctime, info+1, sizeof(entry->ctime));
71 struct dirs_info *dirs_open (Dict dict, const char *rep)
74 int before = 0, after;
76 logf (LOG_DEBUG, "dirs_open %s", rep);
77 if (!(p = malloc (sizeof (*p))))
79 logf (LOG_FATAL|LOG_ERRNO, "malloc");
83 strcpy (p->prefix, rep);
84 p->prelen = strlen(p->prefix);
85 strcpy (p->nextpath, rep);
86 p->no_read = p->no_cur = 0;
87 after = p->no_max = 400;
88 if (!(p->entries = malloc (sizeof(*p->entries) * (p->no_max))))
90 logf (LOG_FATAL|LOG_ERRNO, "malloc");
93 logf (LOG_DEBUG, "dirs_open first scan");
94 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
98 struct dirs_entry *dirs_read (struct dirs_info *p)
100 int before = 0, after = p->no_max;
102 if (p->no_read < p->no_cur)
104 logf (LOG_DEBUG, "dirs_read %d. returns %s", p->no_read,
105 (p->entries + p->no_read)->path);
106 return p->last_entry = p->entries + (p->no_read++);
108 if (p->no_cur < p->no_max)
109 return p->last_entry = NULL;
111 strcpy (p->nextpath, p->prefix);
112 strcat (p->nextpath, (p->entries + p->no_max-1)->path);
115 logf (LOG_DEBUG, "dirs_read rescan");
116 dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc);
118 if (p->no_read < p->no_cur)
119 return p->last_entry = p->entries;
120 return p->last_entry = NULL;
123 struct dirs_entry *dirs_last (struct dirs_info *p)
125 return p->last_entry;
128 void dirs_mkdir (struct dirs_info *p, const char *src, int ctime)
132 sprintf (path, "%s%s", p->prefix, src);
133 logf (LOG_DEBUG, "dirs_mkdir %s", path);
134 dict_insert (p->dict, path, sizeof(ctime), &ctime);
137 void dirs_rmdir (struct dirs_info *p, const char *src)
142 sprintf (path, "%s%s", p->prefix, src);
143 logf (LOG_DEBUG, "dirs_rmdir %s", path);
145 dict_insert (p->dict, path, 1, info);
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;