2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.11 1995-11-20 16:59:44 adam
8 * New update method: the 'old' keys are saved for each records.
10 * Revision 1.10 1995/11/20 11:56:22 adam
11 * Work on new traversal.
13 * Revision 1.9 1995/10/30 13:42:12 adam
16 * Revision 1.8 1995/10/10 13:59:23 adam
17 * Function rset_open changed its wflag parameter to general flags.
19 * Revision 1.7 1995/09/28 09:19:40 adam
20 * xfree/xmalloc used everywhere.
21 * Extract/retrieve method seems to work for text records.
23 * Revision 1.6 1995/09/08 14:52:26 adam
24 * Minor changes. Dictionary is lower case now.
26 * Revision 1.5 1995/09/06 16:11:16 adam
27 * Option: only one word key per file.
29 * Revision 1.4 1995/09/04 12:33:41 adam
30 * Various cleanup. YAZ util used instead.
32 * Revision 1.3 1995/09/01 14:06:35 adam
33 * Split of work into more files.
35 * Revision 1.2 1995/09/01 10:57:07 adam
38 * Revision 1.1 1995/09/01 10:34:51 adam
48 #include <sys/types.h>
56 struct dir_entry *dir_open (const char *rep)
62 size_t entry_max = 500;
64 struct dir_entry *entry;
66 logf (LOG_LOG, "dir_open %s", rep);
67 if (!(dir = opendir(rep)))
69 logf (LOG_WARN|LOG_ERRNO, "opendir %s", rep);
70 if (errno != ENOENT && errno != EACCES)
74 entry = xmalloc (sizeof(*entry) * entry_max);
76 pathpos = strlen(path);
77 if (!pathpos || path[pathpos-1] != '/')
78 path[pathpos++] = '/';
79 while ((dent = readdir (dir)))
82 if (strcmp (dent->d_name, ".") == 0 ||
83 strcmp (dent->d_name, "..") == 0)
85 if (idx == entry_max-1)
87 struct dir_entry *entry_n;
89 entry_n = xmalloc (sizeof(*entry) * (entry_max += 1000));
90 memcpy (entry_n, entry, idx * sizeof(*entry));
94 strcpy (path + pathpos, dent->d_name);
96 switch (finfo.st_mode & S_IFMT)
99 entry[idx].kind = dirs_file;
100 entry[idx].ctime = finfo.st_ctime;
101 entry[idx].name = xmalloc (strlen(dent->d_name)+1);
102 strcpy (entry[idx].name, dent->d_name);
106 entry[idx].kind = dirs_dir;
107 entry[idx].ctime = finfo.st_ctime;
108 entry[idx].name = xmalloc (strlen(dent->d_name)+2);
109 strcpy (entry[idx].name, dent->d_name);
110 strcat (entry[idx].name, "/");
115 entry[idx].name = NULL;
117 logf (LOG_LOG, "dir_close");
121 static int dir_cmp (const void *p1, const void *p2)
123 return strcmp (((struct dir_entry *) p1)->name,
124 ((struct dir_entry *) p2)->name);
127 void dir_sort (struct dir_entry *e)
130 while (e[nmemb].name)
132 qsort (e, nmemb, sizeof(*e), dir_cmp);
135 void dir_free (struct dir_entry **e_p)
138 struct dir_entry *e = *e_p;