2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1995-09-28 09:19:40 adam
8 * xfree/xmalloc used everywhere.
9 * Extract/retrieve method seems to work for text records.
11 * Revision 1.6 1995/09/08 14:52:26 adam
12 * Minor changes. Dictionary is lower case now.
14 * Revision 1.5 1995/09/06 16:11:16 adam
15 * Option: only one word key per file.
17 * Revision 1.4 1995/09/04 12:33:41 adam
18 * Various cleanup. YAZ util used instead.
20 * Revision 1.3 1995/09/01 14:06:35 adam
21 * Split of work into more files.
23 * Revision 1.2 1995/09/01 10:57:07 adam
26 * Revision 1.1 1995/09/01 10:34:51 adam
35 #include <sys/types.h>
42 struct dir_entry *dir_open (const char *rep)
46 size_t entry_max = 50;
48 struct dir_entry *entry;
50 logf (LOG_LOG, "dir_open %s", rep);
51 if (!(dir = opendir(rep)))
53 logf (LOG_WARN|LOG_ERRNO, "opendir %s", rep);
58 entry = xmalloc (sizeof(*entry) * entry_max);
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 entry_n = xmalloc (sizeof(*entry) * (entry_max + 400));
69 memcpy (entry_n, entry, idx * sizeof(*entry));
74 entry[idx].name = xmalloc (strlen(dent->d_name)+1);
75 strcpy (entry[idx].name, dent->d_name);
78 entry[idx].name = NULL;
83 static int dir_cmp (const void *p1, const void *p2)
85 return strcmp (((struct dir_entry *) p1)->name,
86 ((struct dir_entry *) p2)->name);
89 void dir_sort (struct dir_entry *e)
94 qsort (e, nmemb, sizeof(*e), dir_cmp);
97 void dir_free (struct dir_entry **e_p)
100 struct dir_entry *e = *e_p;