]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
term-ostream: Prepare for robustness through signal handling.
authorBruno Haible <bruno@clisp.org>
Sun, 10 Feb 2019 02:01:13 +0000 (03:01 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 10 Feb 2019 19:41:04 +0000 (20:41 +0100)
* gnulib-local/lib/term-ostream.oo.h (ttyctl_t): New type.
(term_ostream_create): Add tty_control argument.
* gnulib-local/lib/term-ostream.oo.c (term_ostream_create): Likewise.
* gnulib-local/lib/term-styled-ostream.oo.h: Include term-ostream.h.
(term_styled_ostream_create): Add tty_control argument.
* gnulib-local/lib/term-styled-ostream.oo.c (term_styled_ostream_create):
Likewise.
* gnulib-local/tests/test-term-ostream.c (main): Use TTYCTL_AUTO.
* gettext-tools/src/color.c (print_color_test): Likewise.
* gettext-tools/src/write-catalog.c (msgdomain_list_print): Likewise.

gettext-tools/src/color.c
gettext-tools/src/write-catalog.c
gnulib-local/lib/term-ostream.oo.c
gnulib-local/lib/term-ostream.oo.h
gnulib-local/lib/term-styled-ostream.oo.c
gnulib-local/lib/term-styled-ostream.oo.h
gnulib-local/tests/test-term-ostream.c

index b4451cd50464301293dd3c88199ff71bac123d08..5f080c9ce3f4994dec45af0df3360815e4ee8f4e 100644 (file)
@@ -99,7 +99,7 @@ print_color_test ()
   term_ostream_t stream;
   int i, row, col;
 
-  stream = term_ostream_create (1, "stdout");
+  stream = term_ostream_create (1, "stdout", TTYCTL_AUTO);
 
   for (i = 0; i < 8; i++)
     colors[i].c =
index 7090f0cf0ab9aa314318a5170d3db329d4807c27..4bac4ba8e7f4fa65962b67f3e11aa3bd594035de 100644 (file)
@@ -246,7 +246,8 @@ message catalog has plural form translations, but the output format does not sup
       style_file_prepare ("PO_STYLE",
                           "GETTEXTSTYLESDIR", relocate (GETTEXTSTYLESDIR),
                           "po-default.css");
-      stream = term_styled_ostream_create (fd, filename, style_file_name);
+      stream =
+        term_styled_ostream_create (fd, filename, TTYCTL_AUTO, style_file_name);
       if (stream == NULL)
         stream = fd_ostream_create (fd, filename, true);
       output_syntax->print (mdlp, stream, page_width, debug);
index 5361ec301b0606c7b9b32e0254dd1fb33db5bb74..b1753d98ccdc269a6f221f8cbce741de84654280 100644 (file)
@@ -1,5 +1,5 @@
 /* Output stream for attributed text, producing ANSI escape sequences.
-   Copyright (C) 2006-2008, 2017 Free Software Foundation, Inc.
+   Copyright (C) 2006-2008, 2017, 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
@@ -1712,7 +1712,7 @@ xstrdup0 (const char *str)
 }
 
 term_ostream_t
-term_ostream_create (int fd, const char *filename)
+term_ostream_create (int fd, const char *filename, ttyctl_t tty_control)
 {
   term_ostream_t stream = XMALLOC (struct term_ostream_representation);
   const char *term;
index 2e2f8c22c0b088b35dae0ebfb4f31102dcdca2bf..336aff6b962894dac14fbbd8062e2a46fca70a6a 100644 (file)
@@ -1,5 +1,5 @@
 /* Output stream for attributed text, producing ANSI escape sequences.
-   Copyright (C) 2006 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
@@ -89,6 +89,26 @@ methods:
                                   term_underline_t underline);
 };
 
+/* The amount of control to take over the underlying tty in order to avoid
+   garbled output on the screen, due to interleaved output of escape sequences
+   and output from the kernel (such as when the kernel echoes user's input
+   or when the kernel prints '^C' after the user pressed Ctrl-C).  */
+typedef enum
+{
+  TTYCTL_AUTO = 0,  /* Automatic best-possible choice.  */
+  TTYCTL_NONE,      /* No control.
+                       Result: Garbled output can occur, and the terminal can
+                       be left in any state when the program is interrupted.  */
+  TTYCTL_PARTIAL,   /* Signal handling.
+                       Result: Garbled output can occur, but the terminal will
+                       be left in the default state when the program is
+                       interrupted.  */
+  TTYCTL_FULL       /* Signal handling and disabling echo and flush-upon-signal.
+                       Result: No garbled output, and the the terminal will
+                       be left in the default state when the program is
+                       interrupted.  */
+} ttyctl_t;
+
 
 #ifdef __cplusplus
 extern "C" {
@@ -97,9 +117,11 @@ extern "C" {
 
 /* Create an output stream referring to the file descriptor FD.
    FILENAME is used only for error messages.
+   TTY_CONTROL specifies the amount of control to take over the underlying tty.
    The resulting stream will be line-buffered.
    Note that the resulting stream must be closed before FD can be closed.  */
-extern term_ostream_t term_ostream_create (int fd, const char *filename);
+extern term_ostream_t
+       term_ostream_create (int fd, const char *filename, ttyctl_t tty_control);
 
 
 #ifdef __cplusplus
index d2148642370efd94d3dea8778725e79bc403e19d..c0e7003ac45c061db8e8bf9850698c9e35e2faa6 100644 (file)
@@ -1,5 +1,5 @@
 /* Output stream for CSS styled text, producing ANSI escape sequences.
-   Copyright (C) 2006-2007 Free Software Foundation, Inc.
+   Copyright (C) 2006-2007, 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
@@ -598,7 +598,7 @@ term_styled_ostream::end_use_class (term_styled_ostream_t stream,
 /* Constructor.  */
 
 term_styled_ostream_t
-term_styled_ostream_create (int fd, const char *filename,
+term_styled_ostream_create (int fd, const char *filename, ttyctl_t tty_control,
                             const char *css_filename)
 {
   term_styled_ostream_t stream =
@@ -606,7 +606,7 @@ term_styled_ostream_create (int fd, const char *filename,
   CRStyleSheet *css_file_contents;
 
   stream->base.base.vtable = &term_styled_ostream_vtable;
-  stream->destination = term_ostream_create (fd, filename);
+  stream->destination = term_ostream_create (fd, filename, tty_control);
 
   if (cr_om_parser_simply_parse_file ((const guchar *) css_filename,
                                       CR_UTF_8, /* CR_AUTO is not supported */
index 8a6447a882f66de6a934dea9ddf007ddbb4113d9..5918f28705731605a40170231c45e93f84548c67 100644 (file)
@@ -1,5 +1,5 @@
 /* Output stream for CSS styled text, producing ANSI escape sequences.
-   Copyright (C) 2006 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
@@ -19,6 +19,7 @@
 #define _TERM_STYLED_OSTREAM_H
 
 #include "styled-ostream.h"
+#include "term-ostream.h"
 
 
 struct term_styled_ostream : struct styled_ostream
@@ -35,10 +36,12 @@ extern "C" {
 /* Create an output stream referring to the file descriptor FD, styled with
    the file CSS_FILENAME.
    FILENAME is used only for error messages.
+   TTY_CONTROL specifies the amount of control to take over the underlying tty.
    Note that the resulting stream must be closed before FD can be closed.
    Return NULL upon failure.  */
 extern term_styled_ostream_t
        term_styled_ostream_create (int fd, const char *filename,
+                                   ttyctl_t tty_control,
                                    const char *css_filename);
 
 
index b8bdbd70bec0653159f251c68733bef755ba81ac..211f60eada44402ae55e192e5034b626abf300c8 100644 (file)
@@ -26,7 +26,7 @@ main ()
   term_ostream_t stream;
   int i, row, col;
 
-  stream = term_ostream_create (1, "stdout");
+  stream = term_ostream_create (1, "stdout", TTYCTL_AUTO);
 
   for (i = 0; i < 8; i++)
     colors[i].c =