summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Hallendal <micke@codefactory.se>2002-08-04 13:53:39 +0000
committerMikael Hallendal <hallski@src.gnome.org>2002-08-04 13:53:39 +0000
commitb16ae9322a861d405da58a63978f6f056906d0f3 (patch)
tree751f419e9b8f6b847088ef7f29fa5fbad7c74808
parentb4d41e9d68bd20a3f0925fbad17bca0be8a8f013 (diff)
downloadyelp-b16ae9322a861d405da58a63978f6f056906d0f3.tar.gz
- support info files that is named name.gz. Fixes #85324. - Remove
2002-08-04 Mikael Hallendal <micke@codefactory.se> * src/yelp-info.c (yelp_info_read_info_dir): - support info files that is named name.gz. Fixes #85324. - Remove duplicates.
-rw-r--r--ChangeLog4
-rw-r--r--src/yelp-info.c47
2 files changed, 36 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index b1efd77f..e2906b32 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2002-08-04 Mikael Hallendal <micke@codefactory.se>
+ * src/yelp-info.c (yelp_info_read_info_dir):
+ - support info files that is named name.gz. Fixes #85324.
+ - Remove duplicates.
+
* src/yelp-window.c:
(window_init): don't automatically go to uri "toc:" in history.
(yelp_window_new): don't open "toc:", this is now done from
diff --git a/src/yelp-info.c b/src/yelp-info.c
index 86997862..6f1622e7 100644
--- a/src/yelp-info.c
+++ b/src/yelp-info.c
@@ -33,6 +33,7 @@
#include <sys/stat.h>
#include <sys/types.h>
+#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <dirent.h>
@@ -50,39 +51,54 @@ yelp_info_read_info_dir (const char *basedir, GSList **info_list)
struct dirent *dent;
YelpSection *section;
YelpURI *uri;
+ GHashTable *dup_hash;
dirh = opendir (basedir);
if (!dirh) {
return;
}
+ dup_hash = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ NULL);
+
while ((dent = readdir (dirh))) {
- char *ctmp = NULL;
+ char *ch = NULL;
+ char *name = NULL;
char *str_uri, *title;
if (dent->d_name[0] == '.') {
continue;
}
-
- do {
- if (ctmp) {
- *ctmp = '\0';
+
+ if ((ch = strrchr (dent->d_name, '-')) &&
+ ch[1] &&
+ isdigit (ch[1])) {
+ continue;
+ }
+
+ if ((ch = strstr (dent->d_name, ".info"))) {
+ name = g_strndup (dent->d_name, ch - dent->d_name);
+ } else {
+ while ((ch = strrchr (dent->d_name, '.'))) {
+ *ch = '\0';
}
-
- ctmp = strrchr (dent->d_name, '.');
- } while (ctmp && strcmp (ctmp, ".info"));
+ name = g_strdup (dent->d_name);
+ }
- if (!ctmp) {
+ if (g_hash_table_lookup_extended (dup_hash, name, NULL, NULL)) {
+ g_free (name);
continue;
}
+
+ title = g_strdup_printf ("%s (info)", name);
- *ctmp = '\0';
-
- title = g_strdup_printf ("%s (info)", dent->d_name);
-
- str_uri = g_strdup_printf ("info:%s", dent->d_name);
+ str_uri = g_strdup_printf ("info:%s", name);
uri = yelp_uri_new (str_uri);
g_free (str_uri);
+
+ g_hash_table_insert (dup_hash, name, NULL);
section = yelp_section_new (YELP_SECTION_DOCUMENT,
title, uri);
@@ -91,9 +107,10 @@ yelp_info_read_info_dir (const char *basedir, GSList **info_list)
yelp_uri_unref (uri);
*info_list = g_slist_prepend (*info_list, section);
-
}
+ g_hash_table_destroy (dup_hash);
+
closedir (dirh);
}