diff --git a/configure.ac b/configure.ac index 33a397a..d5c6632 100644 --- a/configure.ac +++ b/configure.ac @@ -118,6 +118,15 @@ AC_ARG_ENABLE([cats], AC_DEFINE([MAN_CATS], [1], [Allow man to create/update cat files.]) fi], [AC_DEFINE([MAN_CATS], [1], [Allow man to create/update cat files.])]) +AC_ARG_WITH([override-dir], +[AS_HELP_STRING([--with-override-dir=OVERRIDE], [use OVERRIDE as relative override dir inside the man path - the first directory to be searched when looking for man pages])], + [if test "$withval" = "yes" || test "$withval" = "no" + then + AC_MSG_ERROR([--with-override-dir requires an argument]) + else + override_dir=$withval + fi], + [: ${override_dir=""}]) # Finish the argument parsing. AC_SUBST([man_owner])dnl @@ -126,6 +135,7 @@ AC_SUBST([config_file])dnl AC_SUBST([config_file_basename])dnl AC_SUBST([config_file_dirname])dnl AC_SUBST([sections])dnl +AC_SUBST([override_dir])dnl # Check $PATH for the following programs and append suitable options. AC_PROG_CC diff --git a/include/manconfig.h.in b/include/manconfig.h.in index f485312..9981443 100644 --- a/include/manconfig.h.in +++ b/include/manconfig.h.in @@ -166,6 +166,10 @@ # define PIC "@pic@" #endif +#ifndef OVERRIDE_DIR +# define OVERRIDE_DIR "@override_dir@" +#endif + /*------------------------------------------------------------------*/ /* The following definitions are best left alone by the uninitiated */ /*------------------------------------------------------------------*/ diff --git a/src/manp.c b/src/manp.c index e73e838..3223b39 100644 --- a/src/manp.c +++ b/src/manp.c @@ -931,6 +931,24 @@ static char *def_path (int flag) } /* + * If specified with configure, append OVERRIDE_DIR to dir param and add it + * to the lp list. + */ +static void insert_override_dir (char **lp, const char *dir) +{ + char *override_dir = NULL; + + if (!strlen (OVERRIDE_DIR)) { + return; + } + + if ((override_dir = xasprintf ("%s/%s", dir, OVERRIDE_DIR))) { + add_dir_to_list (lp, override_dir); + free (override_dir); + } +} + +/* * For each directory in the user's path, see if it is one of the * directories listed in the man_db.config file. If so, and it is * not already in the manpath, add it. If the directory is not listed @@ -977,6 +995,7 @@ char *get_manpath_from_path (const char *path, int mandatory) if (mandir_list) { debug ("is in the config file\n"); while (mandir_list) { + insert_override_dir(tmplist, mandir_list->cont); add_dir_to_list (tmplist, mandir_list->cont); mandir_list = iterate_over_list (mandir_list, p, MANPATH_MAP); @@ -994,7 +1013,8 @@ char *get_manpath_from_path (const char *path, int mandatory) debug ("but does have a ../man, man, " "../share/man, or share/man " "subdirectory\n"); - + + insert_override_dir(tmplist, t); add_dir_to_list (tmplist, t); free (t); } else @@ -1010,8 +1030,10 @@ char *get_manpath_from_path (const char *path, int mandatory) debug ("\nadding mandatory man directories\n\n"); for (list = namestore; list; list = list->next) - if (list->flag == MANDATORY) + if (list->flag == MANDATORY) { + insert_override_dir(tmplist, list->key); add_dir_to_list (tmplist, list->key); + } } len = 0; diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index fa1c2e9..df4afc3 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -22,12 +22,13 @@ TESTS_ENVIRONMENT = PATH=..:$$PATH; export PATH; \ DBTYPE=$(DBTYPE); export DBTYPE; \ MANDIR_LAYOUT=$(MANDIR_LAYOUT); export MANDIR_LAYOUT; \ top_builddir=$(top_builddir); export top_builddir; \ - @LOCALCHARSET_TESTS_ENVIRONMENT@; export CHARSETALIASDIR; + @LOCALCHARSET_TESTS_ENVIRONMENT@; export CHARSETALIASDIR; \ + OVERRIDE_DIR="@override_dir@"; export OVERRIDE_DIR; # Each test must use the configure-detected shell, not necessarily /bin/sh. AM_LOG_FLAGS = $(SHELL) ALL_TESTS = \ lexgrog-1 \ - man-1 man-2 man-3 man-4 man-5 man-6 man-7 man-8 \ + man-1 man-2 man-3 man-4 man-5 man-6 man-7 man-8 man-9 \ manconv-1 manconv-2 manconv-3 \ mandb-1 mandb-2 mandb-3 mandb-4 mandb-5 mandb-6 \ whatis-1 \ diff --git a/src/tests/man-9 b/src/tests/man-9 new file mode 100755 index 0000000..a82bfa1 --- /dev/null +++ b/src/tests/man-9 @@ -0,0 +1,45 @@ +#! /bin/sh + +# Testing override dir. This test covers both use cases - when override dir is +# enabled and when it's not. +# + +: ${srcdir=.} +. "$srcdir/testlib.sh" + +: ${MAN=man} + +if [ -n "$OVERRIDE_DIR" ]; then + OVERRIDE=$OVERRIDE_DIR +else + OVERRIDE="override" +fi + +init +fake_config /usr/share/man +mkdir -p "${tmpdir}/usr/share/man/${OVERRIDE}/man1" + + +write_page abc 1 "${tmpdir}/usr/share/man/man1/abc.1" \ + UTF-8 '' '' 'abc \- top-level test page' +write_page abc 1 "${tmpdir}/usr/share/man/${OVERRIDE}/man1/abc.1" \ + UTF-8 '' '' 'abc \- modified test page' + +if [ -n "$OVERRIDE_DIR" ]; then +cat >"$tmpdir/1.exp" <"$tmpdir/1.exp" <"$tmpdir/1.out" +expect_pass 'testing override dir' \ + 'diff -u "$tmpdir/1.exp" "$tmpdir/1.out"' + +finish +