summaryrefslogtreecommitdiff
blob: ac42c8df7b3749266f7ec3ca9852ce28bc064a72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
improve the uncompressed .so search

--- a/src/man.c
+++ b/src/man.c
@@ -381,13 +381,23 @@ again:
 	  }
 	  /*
 	   * Some people have compressed man pages, but uncompressed
-	   * .so files - we could glob for all possible extensions,
-	   * for now: only try .gz
+	   * .so files - we should discover this list dynamically, but
+	   * for now just hardcode it.
 	   */
-	  else if (fp == NULL && get_expander(".gz") &&
-		   strlen(name)+strlen(".gz") < BUFSIZE) {
-	       strcat(name, ".gz");
-	       fp = fopen (name, "r");
+	  else if (fp == NULL) {
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
+	       size_t i, name_len = strlen(name);
+	       const char *extensions[] = { ".gz", ".bz2", ".lzma", ".xz", ".z", ".Z" };
+	       for (i = 0; i < ARRAY_SIZE(extensions); ++i) {
+		    const char *comp = extensions[i];
+		    name[name_len] = '\0';
+		    if (get_expander(comp) && name_len+strlen(comp) < BUFSIZE) {
+			 strcat(name, comp);
+			 fp = fopen(name, "r");
+			 if (fp)
+			      break;
+		    }
+	       }
 	  }
 
 	  if (fp == NULL) {