From: Bruno Haible Date: Fri, 8 Feb 2019 19:29:07 +0000 (+0100) Subject: color: Make color.c package-neutral. X-Git-Tag: v0.20~181 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c32906f11dae76442c21beeca330e80fb9999f97;p=thirdparty%2Fgettext.git color: Make color.c package-neutral. * gettext-tools/src/color.h (style_file_prepare): Add arguments. * gettext-tools/src/color.c: Don't include relocatable.h. (style_file_lookup): Add stylesdir_after_install argument. (style_file_prepare): Add arguments. * gettext-tools/src/write-catalog.c: Include relocatable.h. (GETTEXTSTYLESDIR): New macro. (msgdomain_list_print): Update style_file_prepare calls. * gettext-tools/tests/init-env.in (GETTEXTSTYLESDIR): New environment variable. --- diff --git a/gettext-tools/src/color.c b/gettext-tools/src/color.c index 02eb1bc7d..b4451cd50 100644 --- a/gettext-tools/src/color.c +++ b/gettext-tools/src/color.c @@ -1,5 +1,5 @@ /* Color and styling handling. - Copyright (C) 2006-2008, 2015-2016 Free Software Foundation, Inc. + Copyright (C) 2006-2008, 2019 Free Software Foundation, Inc. Written by Bruno Haible , 2006. This program is free software: you can redistribute it and/or modify @@ -30,7 +30,6 @@ #include "term-ostream.h" #include "xalloc.h" -#include "relocatable.h" #include "filename.h" #include "concat-filename.h" @@ -387,7 +386,7 @@ print_color_test () /* Lookup the location of the style file. */ static const char * -style_file_lookup (const char *file_name) +style_file_lookup (const char *file_name, const char *stylesdir_after_install) { if (!IS_PATH_WITH_DIR (file_name)) { @@ -398,9 +397,8 @@ style_file_lookup (const char *file_name) if (stat (file_name, &statbuf) < 0) { /* ... but it exists in the styles installation location... */ - const char *gettextstylesdir = relocate (GETTEXTDATADIR "/styles"); char *possible_file_name = - xconcatenated_filename (gettextstylesdir, file_name, NULL); + xconcatenated_filename (stylesdir_after_install, file_name, NULL); if (stat (possible_file_name, &statbuf) >= 0) { @@ -417,29 +415,35 @@ style_file_lookup (const char *file_name) /* Assign a default value to style_file_name if necessary. */ void -style_file_prepare () +style_file_prepare (const char *style_file_envvar, + const char *stylesdir_envvar, + const char *stylesdir_after_install, + const char *default_style_file) { if (style_file_name == NULL) { - const char *user_preference = getenv ("PO_STYLE"); + const char *user_preference = getenv (style_file_envvar); if (user_preference != NULL && user_preference[0] != '\0') - style_file_name = style_file_lookup (xstrdup (user_preference)); + style_file_name = + style_file_lookup (xstrdup (user_preference), + stylesdir_after_install); else { - const char *gettextdatadir; + const char *stylesdir; - /* Make it possible to override the po-default.css location. This is - necessary for running the testsuite before "make install". */ - gettextdatadir = getenv ("GETTEXTDATADIR"); - if (gettextdatadir == NULL || gettextdatadir[0] == '\0') - gettextdatadir = relocate (GETTEXTDATADIR); + /* Make it possible to override the default style file location. This + is necessary for running the testsuite before "make install". */ + stylesdir = getenv (stylesdir_envvar); + if (stylesdir == NULL || stylesdir[0] == '\0') + stylesdir = stylesdir_after_install; style_file_name = - xconcatenated_filename (gettextdatadir, "styles/po-default.css", + xconcatenated_filename (stylesdir, default_style_file, NULL); } } else - style_file_name = style_file_lookup (style_file_name); + style_file_name = + style_file_lookup (style_file_name, stylesdir_after_install); } diff --git a/gettext-tools/src/color.h b/gettext-tools/src/color.h index 8daadd015..3c3fa850b 100644 --- a/gettext-tools/src/color.h +++ b/gettext-tools/src/color.h @@ -1,5 +1,5 @@ /* Color and styling handling. - Copyright (C) 2006, 2015-2016 Free Software Foundation, Inc. + Copyright (C) 2006, 2019 Free Software Foundation, Inc. Written by Bruno Haible , 2006. This program is free software: you can redistribute it and/or modify @@ -45,8 +45,21 @@ extern void handle_style_option (const char *option); /* Print a color test page. */ extern void print_color_test (void); -/* Assign a default value to style_file_name if necessary. */ -extern void style_file_prepare (void); +/* Assign a default value to style_file_name if necessary. + STYLE_FILE_ENVVAR is an environment variable that, when set to a non-empty + value, specifies the style file to use. This environment variable is meant + to be set by the user. + STYLESDIR_ENVVAR is an environment variable that, when set to a non-empty + value, specifies the directory with the styles files, or NULL. This is + necessary for running the testsuite before "make install". + STYLESDIR_AFTER_INSTALL is the directory with the styles files after + "make install". + DEFAULT_STYLE_FILE is the file name of the default style file, relative to + STYLESDIR. */ +extern void style_file_prepare (const char *style_file_envvar, + const char *stylesdir_envvar, + const char *stylesdir_after_install, + const char *default_style_file); #ifdef __cplusplus diff --git a/gettext-tools/src/write-catalog.c b/gettext-tools/src/write-catalog.c index da298ac3e..7090f0cf0 100644 --- a/gettext-tools/src/write-catalog.c +++ b/gettext-tools/src/write-catalog.c @@ -1,5 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-1998, 2000-2008, 2012, 2015-2016 Free Software + Copyright (C) 1995-1998, 2000-2008, 2012, 2019 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -57,9 +57,12 @@ # include "fd-ostream.h" # include "color.h" +# include "relocatable.h" # include "po-charset.h" # include "msgl-iconv.h" +# define GETTEXTSTYLESDIR GETTEXTDATADIR "/styles" + #endif @@ -240,7 +243,9 @@ message catalog has plural form translations, but the output format does not sup filename = _("standard output"); } - style_file_prepare (); + style_file_prepare ("PO_STYLE", + "GETTEXTSTYLESDIR", relocate (GETTEXTSTYLESDIR), + "po-default.css"); stream = term_styled_ostream_create (fd, filename, style_file_name); if (stream == NULL) stream = fd_ostream_create (fd, filename, true); @@ -298,7 +303,9 @@ message catalog has plural form translations, but the output format does not sup mdlp = iconv_msgdomain_list (mdlp, po_charset_utf8, false, NULL); } - style_file_prepare (); + style_file_prepare ("PO_STYLE", + "GETTEXTSTYLESDIR", relocate (GETTEXTSTYLESDIR), + "po-default.css"); html_stream = html_styled_ostream_create (stream, style_file_name); output_syntax->print (mdlp, html_stream, page_width, debug); ostream_free (html_stream); diff --git a/gettext-tools/tests/init-env.in b/gettext-tools/tests/init-env.in index 9f150bc78..cc84ffd39 100644 --- a/gettext-tools/tests/init-env.in +++ b/gettext-tools/tests/init-env.in @@ -42,6 +42,10 @@ esac GETTEXTDATADIR="$wabs_top_srcdir" export GETTEXTDATADIR +# Variable needed for checking output with --color. +GETTEXTSTYLESDIR="$GETTEXTDATADIR/styles" +export GETTEXTSTYLESDIR + : ${GETTEXT=tstgettext} : ${NGETTEXT=tstngettext} : ${XGETTEXT=xgettext}