From: John Darrington Date: Wed, 27 Oct 2010 11:13:19 +0000 (+0200) Subject: Make ascii driver's length and width parameters fit the terminal. X-Git-Tag: v0.7.7~169 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a77c12af47a9ed94b5c38d4a762bb287bfadda93;p=pspp-builds.git Make ascii driver's length and width parameters fit the terminal. If the driver's output is a tty, then handle SIGWINCH to adjust the length and width according to the size of the terminal. --- diff --git a/src/output/ascii.c b/src/output/ascii.c index c9f96b21..8b48d9bd 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "data/file-name.h" #include "data/settings.h" @@ -786,6 +788,14 @@ ascii_layout_cell (struct ascii_driver *a, const struct table_cell *cell, /* ascii_close_page () and support routines. */ +static struct ascii_driver *the_driver; + +static void +winch_handler (int signum UNUSED) +{ + update_page_size (the_driver, false); +} + static bool ascii_open_page (struct ascii_driver *a) { @@ -799,6 +809,18 @@ ascii_open_page (struct ascii_driver *a) a->file = fn_open (a->file_name, a->append ? "a" : "w"); if (a->file != NULL) { + 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); + } + if (a->init != NULL) fputs (a->init, a->file); }