From: Bruno Haible Date: Sun, 28 Oct 2007 16:06:16 +0000 (+0000) Subject: Lookup style files also in the installation directory. X-Git-Tag: v0.17~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=541a306056a5d9cbfd7af450acc970e49f8788d4;p=thirdparty%2Fgettext.git Lookup style files also in the installation directory. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index f870e01d9..3efdea524 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,8 @@ +2007-10-28 Bruno Haible + + * color.c (style_file_lookup): New function. + (style_file_prepare): Use it. + 2007-10-21 Bruno Haible Normalize the leading space of every comment line during input, not diff --git a/gettext-tools/src/color.c b/gettext-tools/src/color.c index 05ac2f1c0..ed548a963 100644 --- a/gettext-tools/src/color.c +++ b/gettext-tools/src/color.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include "term-ostream.h" #include "xalloc.h" @@ -382,6 +384,36 @@ print_color_test () ostream_free (stream); } +/* Lookup the location of the style file. */ +static const char * +style_file_lookup (const char *file_name) +{ + if (!IS_PATH_WITH_DIR (file_name)) + { + /* It's a file name without a directory specification. + If it does not exist in the current directory... */ + struct stat statbuf; + + if (stat (file_name, &statbuf) < 0) + { + /* ... but it exists in the styles installation location... */ + const char *gettextstylesdir = relocate (GETTEXTDATADIR "/styles"); + char *possible_file_name = + concatenated_filename (gettextstylesdir, file_name, NULL); + + if (stat (possible_file_name, &statbuf) >= 0) + { + /* ... then use the file in the styles installation directory. */ + return possible_file_name; + } + free (possible_file_name); + } + + /* Let the CSS library show a warning. */ + } + return file_name; +} + /* Assign a default value to style_file_name if necessary. */ void style_file_prepare () @@ -391,7 +423,7 @@ style_file_prepare () const char *user_preference = getenv ("PO_STYLE"); if (user_preference != NULL && user_preference[0] != '\0') - style_file_name = xstrdup (user_preference); + style_file_name = style_file_lookup (xstrdup (user_preference)); else { const char *gettextdatadir; @@ -407,4 +439,6 @@ style_file_prepare () NULL); } } + else + style_file_name = style_file_lookup (style_file_name); }