2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.8 1995-10-10 13:59:23 adam
8 * Function rset_open changed its wflag parameter to general flags.
10 * Revision 1.7 1995/09/28 09:19:40 adam
11 * xfree/xmalloc used everywhere.
12 * Extract/retrieve method seems to work for text records.
14 * Revision 1.6 1995/09/08 14:52:26 adam
15 * Minor changes. Dictionary is lower case now.
17 * Revision 1.5 1995/09/06 16:11:16 adam
18 * Option: only one word key per file.
20 * Revision 1.4 1995/09/04 12:33:41 adam
21 * Various cleanup. YAZ util used instead.
23 * Revision 1.3 1995/09/01 14:06:35 adam
24 * Split of work into more files.
26 * Revision 1.2 1995/09/01 10:57:07 adam
29 * Revision 1.1 1995/09/01 10:34:51 adam
38 #include <sys/types.h>
45 struct dir_entry *dir_open (const char *rep)
49 size_t entry_max = 500;
51 struct dir_entry *entry;
53 logf (LOG_LOG, "dir_open %s", rep);
54 if (!(dir = opendir(rep)))
56 logf (LOG_WARN|LOG_ERRNO, "opendir %s", rep);
61 entry = xmalloc (sizeof(*entry) * entry_max);
62 while ((dent = readdir (dir)))
64 if (strcmp (dent->d_name, ".") == 0 ||
65 strcmp (dent->d_name, "..") == 0)
67 if (idx == entry_max-1)
69 struct dir_entry *entry_n;
71 entry_n = xmalloc (sizeof(*entry) * (entry_max + 1000));
72 memcpy (entry_n, entry, idx * sizeof(*entry));
77 entry[idx].name = xmalloc (strlen(dent->d_name)+1);
78 strcpy (entry[idx].name, dent->d_name);
81 entry[idx].name = NULL;
86 static int dir_cmp (const void *p1, const void *p2)
88 return strcmp (((struct dir_entry *) p1)->name,
89 ((struct dir_entry *) p2)->name);
92 void dir_sort (struct dir_entry *e)
97 qsort (e, nmemb, sizeof(*e), dir_cmp);
100 void dir_free (struct dir_entry **e_p)
103 struct dir_entry *e = *e_p;