2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.12 1996-02-05 12:29:55 adam
8 * Logging reduced a bit.
9 * The remaining running time is estimated during register merge.
11 * Revision 1.11 1995/11/20 16:59:44 adam
12 * New update method: the 'old' keys are saved for each records.
14 * Revision 1.10 1995/11/20 11:56:22 adam
15 * Work on new traversal.
17 * Revision 1.9 1995/10/30 13:42:12 adam
20 * Revision 1.8 1995/10/10 13:59:23 adam
21 * Function rset_open changed its wflag parameter to general flags.
23 * Revision 1.7 1995/09/28 09:19:40 adam
24 * xfree/xmalloc used everywhere.
25 * Extract/retrieve method seems to work for text records.
27 * Revision 1.6 1995/09/08 14:52:26 adam
28 * Minor changes. Dictionary is lower case now.
30 * Revision 1.5 1995/09/06 16:11:16 adam
31 * Option: only one word key per file.
33 * Revision 1.4 1995/09/04 12:33:41 adam
34 * Various cleanup. YAZ util used instead.
36 * Revision 1.3 1995/09/01 14:06:35 adam
37 * Split of work into more files.
39 * Revision 1.2 1995/09/01 10:57:07 adam
42 * Revision 1.1 1995/09/01 10:34:51 adam
52 #include <sys/types.h>
60 struct dir_entry *dir_open (const char *rep)
66 size_t entry_max = 500;
68 struct dir_entry *entry;
70 logf (LOG_DEBUG, "dir_open %s", rep);
71 if (!(dir = opendir(rep)))
73 logf (LOG_WARN|LOG_ERRNO, "opendir %s", rep);
74 if (errno != ENOENT && errno != EACCES)
78 entry = xmalloc (sizeof(*entry) * entry_max);
80 pathpos = strlen(path);
81 if (!pathpos || path[pathpos-1] != '/')
82 path[pathpos++] = '/';
83 while ((dent = readdir (dir)))
86 if (strcmp (dent->d_name, ".") == 0 ||
87 strcmp (dent->d_name, "..") == 0)
89 if (idx == entry_max-1)
91 struct dir_entry *entry_n;
93 entry_n = xmalloc (sizeof(*entry) * (entry_max += 1000));
94 memcpy (entry_n, entry, idx * sizeof(*entry));
98 strcpy (path + pathpos, dent->d_name);
100 switch (finfo.st_mode & S_IFMT)
103 entry[idx].kind = dirs_file;
104 entry[idx].ctime = finfo.st_ctime;
105 entry[idx].name = xmalloc (strlen(dent->d_name)+1);
106 strcpy (entry[idx].name, dent->d_name);
110 entry[idx].kind = dirs_dir;
111 entry[idx].ctime = finfo.st_ctime;
112 entry[idx].name = xmalloc (strlen(dent->d_name)+2);
113 strcpy (entry[idx].name, dent->d_name);
114 strcat (entry[idx].name, "/");
119 entry[idx].name = NULL;
121 logf (LOG_DEBUG, "dir_close");
125 static int dir_cmp (const void *p1, const void *p2)
127 return strcmp (((struct dir_entry *) p1)->name,
128 ((struct dir_entry *) p2)->name);
131 void dir_sort (struct dir_entry *e)
134 while (e[nmemb].name)
136 qsort (e, nmemb, sizeof(*e), dir_cmp);
139 void dir_free (struct dir_entry **e_p)
142 struct dir_entry *e = *e_p;