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