]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
color: Make color.c package-neutral.
authorBruno Haible <bruno@clisp.org>
Fri, 8 Feb 2019 19:29:07 +0000 (20:29 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 8 Feb 2019 19:29:07 +0000 (20:29 +0100)
* 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.

gettext-tools/src/color.c
gettext-tools/src/color.h
gettext-tools/src/write-catalog.c
gettext-tools/tests/init-env.in

index 02eb1bc7d71572ba2e3a86ed38641d2ba1f6ae12..b4451cd50464301293dd3c88199ff71bac123d08 100644 (file)
@@ -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 <bruno@clisp.org>, 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);
 }
index 8daadd0153d4a87b01d21b3ce42e2c59a63b58c7..3c3fa850b2d1b39e98e2d2702a622be01cb460d8 100644 (file)
@@ -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 <bruno@clisp.org>, 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
index da298ac3ec3b1a052cff885444198061e6658bf8..7090f0cf0ab9aa314318a5170d3db329d4807c27 100644 (file)
@@ -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
 # 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);
index 9f150bc782e8725fd5a706d56032876d3ad108dd..cc84ffd39be8de32564a3b7581c0d872a1570f84 100644 (file)
@@ -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}