man-db-2.6.1-wildcards.patch 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. diff -up man-db-2.6.2/src/globbing.c.wildcards man-db-2.6.2/src/globbing.c
  2. --- man-db-2.6.2/src/globbing.c.wildcards 2010-09-26 23:08:14.000000000 +0200
  3. +++ man-db-2.6.2/src/globbing.c 2012-07-20 19:18:20.000000000 +0200
  4. @@ -427,3 +427,30 @@ char **look_for_file (const char *hier,
  5. else
  6. return gbuf.gl_pathv;
  7. }
  8. +
  9. +char **expand_path (const char *path)
  10. +{
  11. + int res = 0;
  12. + char **result = NULL;
  13. + glob_t globbuf;
  14. +
  15. + res = glob (path, 0, NULL, &globbuf);
  16. + /* if glob failed, return the given path */
  17. + if (res != 0) {
  18. + result = (char **) xmalloc (2 * sizeof(char **));
  19. + result[0] = xstrndup (path, strlen(path));
  20. + result[1] = NULL;
  21. + return result;
  22. + }
  23. +
  24. + result = (char **) xmalloc ((globbuf.gl_pathc + 1) * sizeof(char **));
  25. + size_t i;
  26. + for (i = 0; i < globbuf.gl_pathc; i++) {
  27. + result[i] = xstrndup (globbuf.gl_pathv[i], strlen (globbuf.gl_pathv[i]));
  28. + }
  29. + result[globbuf.gl_pathc] = NULL;
  30. +
  31. + globfree (&globbuf);
  32. +
  33. + return result;
  34. +}
  35. diff -up man-db-2.6.2/src/globbing.h.wildcards man-db-2.6.2/src/globbing.h
  36. --- man-db-2.6.2/src/globbing.h.wildcards 2008-12-11 00:06:18.000000000 +0100
  37. +++ man-db-2.6.2/src/globbing.h 2012-07-20 19:18:20.000000000 +0200
  38. @@ -29,3 +29,6 @@ enum look_for_file_opts {
  39. /* globbing.c */
  40. extern char **look_for_file (const char *hier, const char *sec,
  41. const char *unesc_name, int cat, int opts);
  42. +
  43. +/* Expand path with wildcards into list of all existing directories. */
  44. +extern char **expand_path (const char *path);
  45. diff -up man-db-2.6.2/src/Makefile.am.wildcards man-db-2.6.2/src/Makefile.am
  46. --- man-db-2.6.2/src/Makefile.am.wildcards 2012-02-05 14:25:20.000000000 +0100
  47. +++ man-db-2.6.2/src/Makefile.am 2012-07-20 19:18:20.000000000 +0200
  48. @@ -72,6 +72,8 @@ zsoelim_LDADD = $(LIBMAN) $(libpipeline_
  49. accessdb_SOURCES = \
  50. accessdb.c
  51. catman_SOURCES = \
  52. + globbing.c \
  53. + globbing.h \
  54. catman.c \
  55. manp.c \
  56. manp.h
  57. @@ -140,10 +142,14 @@ mandb_SOURCES = \
  58. ult_src.c \
  59. ult_src.h
  60. manpath_SOURCES = \
  61. + globbing.c \
  62. + globbing.h \
  63. manp.c \
  64. manp.h \
  65. manpath.c
  66. whatis_SOURCES = \
  67. + globbing.c \
  68. + globbing.h \
  69. manconv.c \
  70. manconv.h \
  71. manp.c \
  72. diff -up man-db-2.6.2/src/Makefile.in.wildcards man-db-2.6.2/src/Makefile.in
  73. --- man-db-2.6.2/src/Makefile.in.wildcards 2012-06-18 14:39:42.000000000 +0200
  74. +++ man-db-2.6.2/src/Makefile.in 2012-07-20 19:20:29.000000000 +0200
  75. @@ -251,7 +251,7 @@ accessdb_DEPENDENCIES = $(am__DEPENDENCI
  76. AM_V_lt = $(am__v_lt_@AM_V@)
  77. am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
  78. am__v_lt_0 = --silent
  79. -am_catman_OBJECTS = catman.$(OBJEXT) manp.$(OBJEXT)
  80. +am_catman_OBJECTS = globbing.$(OBJEXT) catman.$(OBJEXT) manp.$(OBJEXT)
  81. catman_OBJECTS = $(am_catman_OBJECTS)
  82. catman_DEPENDENCIES = $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_2)
  83. am_globbing_OBJECTS = globbing.$(OBJEXT) globbing_test.$(OBJEXT)
  84. @@ -282,10 +282,10 @@ am_mandb_OBJECTS = check_mandirs.$(OBJEX
  85. mandb_OBJECTS = $(am_mandb_OBJECTS)
  86. mandb_DEPENDENCIES = $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_2) \
  87. $(am__DEPENDENCIES_2)
  88. -am_manpath_OBJECTS = manp.$(OBJEXT) manpath.$(OBJEXT)
  89. +am_manpath_OBJECTS = globbing.$(OBJEXT) manp.$(OBJEXT) manpath.$(OBJEXT)
  90. manpath_OBJECTS = $(am_manpath_OBJECTS)
  91. manpath_DEPENDENCIES = $(am__DEPENDENCIES_1)
  92. -am_whatis_OBJECTS = manconv.$(OBJEXT) manp.$(OBJEXT) whatis.$(OBJEXT)
  93. +am_whatis_OBJECTS = globbing.$(OBJEXT) manconv.$(OBJEXT) manp.$(OBJEXT) whatis.$(OBJEXT)
  94. whatis_OBJECTS = $(am_whatis_OBJECTS)
  95. whatis_DEPENDENCIES = $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_2) \
  96. $(am__DEPENDENCIES_2)
  97. @@ -1340,6 +1340,8 @@ accessdb_SOURCES = \
  98. catman_SOURCES = \
  99. catman.c \
  100. + globbing.c \
  101. + globbing.h \
  102. manp.c \
  103. manp.h
  104. @@ -1413,11 +1415,15 @@ mandb_SOURCES = \
  105. ult_src.h
  106. manpath_SOURCES = \
  107. + globbing.c \
  108. + globbing.h \
  109. manp.c \
  110. manp.h \
  111. manpath.c
  112. whatis_SOURCES = \
  113. + globbing.c \
  114. + globbing.h \
  115. manconv.c \
  116. manconv.h \
  117. manp.c \
  118. diff -up man-db-2.6.2/src/manp.c.wildcards man-db-2.6.2/src/manp.c
  119. --- man-db-2.6.2/src/manp.c.wildcards 2012-02-05 14:18:59.000000000 +0100
  120. +++ man-db-2.6.2/src/manp.c 2012-07-20 19:18:20.000000000 +0200
  121. @@ -75,6 +75,7 @@
  122. #endif
  123. #include "manp.h"
  124. +#include "globbing.h"
  125. struct list {
  126. char *key;
  127. @@ -1035,32 +1036,45 @@ char *get_manpath_from_path (const char
  128. static void add_dir_to_list (char **lp, const char *dir)
  129. {
  130. int status;
  131. - int pos = 0;
  132. -
  133. - while (*lp != NULL) {
  134. - if (pos > MAXDIRS - 1)
  135. - gripe_overlong_list ();
  136. - if (!strcmp (*lp, dir)) {
  137. - debug ("%s is already in the manpath\n", dir);
  138. - return;
  139. + int pos = 0, i = 0;
  140. + char *d = NULL;
  141. + char **expanded_dirs = NULL;
  142. +
  143. + expanded_dirs = expand_path (dir);
  144. + for (i = 0; expanded_dirs[i] != NULL; i++) {
  145. + d = expanded_dirs[i];
  146. +
  147. + while (*lp != NULL) {
  148. + if (pos > MAXDIRS - 1)
  149. + gripe_overlong_list ();
  150. + if (!strcmp (*lp, d)) {
  151. + debug ("%s is already in the manpath\n", d);
  152. + return;
  153. + }
  154. + lp++;
  155. + pos++;
  156. }
  157. - lp++;
  158. - pos++;
  159. - }
  160. - /* Not found -- add it. */
  161. + /* Not found -- add it. */
  162. +
  163. + status = is_directory (d);
  164. - status = is_directory (dir);
  165. + if (status < 0)
  166. + gripe_stat_file (d);
  167. + else if (status == 0)
  168. + gripe_not_directory (d);
  169. + else if (status == 1) {
  170. + debug ("adding %s to manpath\n", d);
  171. - if (status < 0)
  172. - gripe_stat_file (dir);
  173. - else if (status == 0)
  174. - gripe_not_directory (dir);
  175. - else if (status == 1) {
  176. - debug ("adding %s to manpath\n", dir);
  177. + *lp = xstrdup (d);
  178. + }
  179. - *lp = xstrdup (dir);
  180. + free (d);
  181. }
  182. +
  183. + /* free also the last NULL pointer */
  184. + free (expanded_dirs[i]);
  185. + free (expanded_dirs);
  186. }
  187. /* path does not exist in config file: check to see if path/../man,
  188. @@ -1104,33 +1118,47 @@ static inline char *has_mandir (const ch
  189. static char **add_dir_to_path_list (char **mphead, char **mp, const char *p)
  190. {
  191. - int status;
  192. + int status, i = 0;
  193. char *cwd;
  194. + char *d = NULL;
  195. + char **expanded_dirs = NULL;
  196. if (mp - mphead > MAXDIRS - 1)
  197. gripe_overlong_list ();
  198. - status = is_directory (p);
  199. -
  200. - if (status < 0)
  201. - gripe_stat_file (p);
  202. - else if (status == 0)
  203. - gripe_not_directory (p);
  204. - else {
  205. - /* deal with relative paths */
  206. + expanded_dirs = expand_path (p);
  207. + for (i = 0; expanded_dirs[i] != NULL; i++) {
  208. + d = expanded_dirs[i];
  209. +
  210. + status = is_directory (d);
  211. +
  212. + if (status < 0)
  213. + gripe_stat_file (d);
  214. + else if (status == 0)
  215. + gripe_not_directory (d);
  216. + else {
  217. + /* deal with relative paths */
  218. +
  219. + if (*d != '/') {
  220. + cwd = xgetcwd ();
  221. + if (!cwd)
  222. + error (FATAL, errno,
  223. + _("can't determine current directory"));
  224. + *mp = appendstr (cwd, "/", d, NULL);
  225. + } else
  226. + *mp = xstrdup (d);
  227. - if (*p != '/') {
  228. - cwd = xgetcwd ();
  229. - if (!cwd)
  230. - error (FATAL, errno,
  231. - _("can't determine current directory"));
  232. - *mp = appendstr (cwd, "/", p, NULL);
  233. - } else
  234. - *mp = xstrdup (p);
  235. + debug ("adding %s to manpathlist\n", *mp);
  236. + mp++;
  237. + }
  238. - debug ("adding %s to manpathlist\n", *mp);
  239. - mp++;
  240. + free (d);
  241. }
  242. +
  243. + /* free also the last NULL pointer */
  244. + free (expanded_dirs[i]);
  245. + free (expanded_dirs);
  246. +
  247. return mp;
  248. }