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