2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1995-09-08 14:52:26 adam
8 * Minor changes. Dictionary is lower case now.
10 * Revision 1.5 1995/09/06 16:11:16 adam
11 * Option: only one word key per file.
13 * Revision 1.4 1995/09/04 12:33:41 adam
14 * Various cleanup. YAZ util used instead.
16 * Revision 1.3 1995/09/01 14:06:35 adam
17 * Split of work into more files.
19 * Revision 1.2 1995/09/01 10:57:07 adam
22 * Revision 1.1 1995/09/01 10:34:51 adam
31 #include <sys/types.h>
38 struct dir_entry *dir_open (const char *rep)
42 size_t entry_max = 50;
44 struct dir_entry *entry;
46 logf (LOG_LOG, "dir_open %s", rep);
47 if (!(dir = opendir(rep)))
49 logf (LOG_WARN|LOG_ERRNO, "opendir %s", rep);
54 if (!(entry = malloc (sizeof(*entry) * entry_max)))
56 logf (LOG_FATAL|LOG_ERRNO, "malloc");
59 while ((dent = readdir (dir)))
61 if (strcmp (dent->d_name, ".") == 0 ||
62 strcmp (dent->d_name, "..") == 0)
64 if (idx == entry_max-1)
66 struct dir_entry *entry_n;
68 if (!(entry_n = malloc (sizeof(*entry) * (entry_max + 400))))
70 logf (LOG_FATAL|LOG_ERRNO, "malloc");
73 memcpy (entry_n, entry, idx * sizeof(*entry));
78 if (!(entry[idx].name = malloc (strlen(dent->d_name)+1)))
80 logf (LOG_FATAL|LOG_ERRNO, "malloc");
83 strcpy (entry[idx].name, dent->d_name);
86 entry[idx].name = NULL;
91 static int dir_cmp (const void *p1, const void *p2)
93 return strcmp (((struct dir_entry *) p1)->name,
94 ((struct dir_entry *) p2)->name);
97 void dir_sort (struct dir_entry *e)
100 while (e[nmemb].name)
102 qsort (e, nmemb, sizeof(*e), dir_cmp);
105 void dir_free (struct dir_entry **e_p)
108 struct dir_entry *e = *e_p;