str: Change "char" to "byte" in function names.
[pspp-builds.git] / src / output / ascii.c
index c5f30816fb12efefae8865ea43de35158b59d13c..06bd190633f8e5d95c3994fe3b6c743edc180192 100644 (file)
 #include <limits.h>
 #include <stdint.h>
 #include <stdlib.h>
-
-#include <data/file-name.h>
-#include <data/settings.h>
-#include <libpspp/assertion.h>
-#include <libpspp/compiler.h>
-#include <libpspp/message.h>
-#include <libpspp/start-date.h>
-#include <libpspp/string-map.h>
-#include <libpspp/version.h>
-#include <output/cairo.h>
-#include <output/chart-item-provider.h>
-#include <output/message-item.h>
-#include <output/options.h>
-#include <output/tab.h>
-#include <output/text-item.h>
-#include <output/driver-provider.h>
-#include <output/render.h>
-#include <output/table-item.h>
-
-#include "error.h"
-#include "minmax.h"
-#include "xalloc.h"
+#include <signal.h>
+#include <unistd.h>
+
+#include "data/file-name.h"
+#include "data/settings.h"
+#include "libpspp/assertion.h"
+#include "libpspp/cast.h"
+#include "libpspp/compiler.h"
+#include "libpspp/message.h"
+#include "libpspp/start-date.h"
+#include "libpspp/string-map.h"
+#include "libpspp/version.h"
+#include "output/cairo.h"
+#include "output/chart-item-provider.h"
+#include "output/driver-provider.h"
+#include "output/message-item.h"
+#include "output/options.h"
+#include "output/render.h"
+#include "output/tab.h"
+#include "output/table-item.h"
+#include "output/text-item.h"
+
+#include "gl/error.h"
+#include "gl/minmax.h"
+#include "gl/xalloc.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -184,7 +187,7 @@ ascii_create (const char *file_name, enum settings_output_devices device_type,
                             "bold", EMPH_BOLD,
                             "underline", EMPH_UNDERLINE,
                             "none", EMPH_NONE,
-                            (char *) NULL);
+                            NULL_SENTINEL);
 
   a->chart_file_name = parse_chart_file_name (opt (d, o, "charts", file_name));
 
@@ -357,7 +360,7 @@ ascii_flush (struct output_driver *driver)
       ascii_close_page (a);
 
       if (fn_close (a->file_name, a->file) != 0)
-        error (0, errno, _("ascii: closing output file \"%s\""),
+        error (0, errno, _("ascii: closing output file `%s'"),
                a->file_name);
       a->file = NULL;
     }
@@ -487,6 +490,7 @@ ascii_submit (struct output_driver *driver,
 
   if (is_table_item (output_item))
     ascii_output_table_item (a, to_table_item (output_item));
+#ifdef HAVE_CAIRO
   else if (is_chart_item (output_item) && a->chart_file_name != NULL)
     {
       struct chart_item *chart_item = to_chart_item (output_item);
@@ -506,6 +510,7 @@ ascii_submit (struct output_driver *driver,
           free (file_name);
         }
     }
+#endif  /* HAVE_CAIRO */
   else if (is_text_item (output_item))
     {
       const struct text_item *text_item = to_text_item (output_item);
@@ -783,6 +788,17 @@ ascii_layout_cell (struct ascii_driver *a, const struct table_cell *cell,
 \f
 /* ascii_close_page () and support routines. */
 
+
+#if HAVE_DECL_SIGWINCH
+static struct ascii_driver *the_driver;
+
+static void
+winch_handler (int signum UNUSED)
+{
+  update_page_size (the_driver, false);
+}
+#endif
+
 static bool
 ascii_open_page (struct ascii_driver *a)
 {
@@ -796,12 +812,25 @@ ascii_open_page (struct ascii_driver *a)
       a->file = fn_open (a->file_name, a->append ? "a" : "w");
       if (a->file != NULL)
         {
+#if HAVE_DECL_SIGWINCH
+         if ( isatty (fileno (a->file)))
+           {
+             struct sigaction action;
+             sigemptyset (&action.sa_mask);
+             action.sa_flags = 0;
+             action.sa_handler = winch_handler;
+             the_driver = a;
+             a->auto_width = true;
+             a->auto_length = true;
+             sigaction (SIGWINCH, &action, NULL);
+           }
+#endif
           if (a->init != NULL)
             fputs (a->init, a->file);
         }
       else
         {
-          error (0, errno, _("ascii: opening output file \"%s\""),
+          error (0, errno, _("ascii: opening output file `%s'"),
                  a->file_name);
           a->error = true;
           return false;
@@ -872,7 +901,7 @@ static void
 output_title_line (FILE *out, int width, const char *left, const char *right)
 {
   struct string s = DS_EMPTY_INITIALIZER;
-  ds_put_char_multiple (&s, ' ', width);
+  ds_put_byte_multiple (&s, ' ', width);
   if (left != NULL)
     {
       size_t length = MIN (strlen (left), width);
@@ -883,7 +912,7 @@ output_title_line (FILE *out, int width, const char *left, const char *right)
       size_t length = MIN (strlen (right), width);
       memcpy (ds_end (&s) - length, right, length);
     }
-  ds_put_char (&s, '\n');
+  ds_put_byte (&s, '\n');
   fputs (ds_cstr (&s), out);
   ds_destroy (&s);
 }