diff options
author | burnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-12-11 08:20:24 +0000 |
---|---|---|
committer | burnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-12-11 08:20:24 +0000 |
commit | de96a0631877cebe1a60d8f0864b1d460dd063a7 (patch) | |
tree | e31e886ed230649c1e858eb51f469565c87e1754 /gcc/diagnostic.c | |
parent | 5d95297a45e3dd0d3cdc83bc7a2bdf2d137c0e9a (diff) | |
download | gcc-de96a0631877cebe1a60d8f0864b1d460dd063a7.tar.gz |
2014-12-11 Tobias Burnus <burnus@net-b.de>
Manuel López-Ibáñez <manu@gcc.gnu.org>
gcc/
* diagnostic.c (get_terminal_width): Renamed from
* getenv_columns,
removed static, and additionally use ioctl to get width.
(diagnostic_set_caret_max_width): Update call.
* diagnostic.h (get_terminal_width): Add prototype.
* opts.c (print_specific_help): Use it for x_help_columns.
* doc/invoke.texi (fdiagnostics-show-caret): Document how the
width is set.
gcc/fortran/
* error.c (gfc_get_terminal_width): Renamed from
get_terminal_width and use same-named common function.
(gfc_error_init_1): Update call.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@218619 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/diagnostic.c')
-rw-r--r-- | gcc/diagnostic.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index 28ef81c5dad..2c2477f2488 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -33,6 +33,14 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "diagnostic-color.h" +#ifdef HAVE_TERMIOS_H +# include <termios.h> +#endif + +#ifdef GWINSZ_IN_SYS_IOCTL +# include <sys/ioctl.h> +#endif + #include <new> // For placement new. #define pedantic_warning_kind(DC) \ @@ -83,9 +91,10 @@ file_name_as_prefix (diagnostic_context *context, const char *f) /* Return the value of the getenv("COLUMNS") as an integer. If the - value is not set to a positive integer, then return INT_MAX. */ -static int -getenv_columns (void) + value is not set to a positive integer, use ioctl to get the + terminal width. If it fails, return INT_MAX. */ +int +get_terminal_width (void) { const char * s = getenv ("COLUMNS"); if (s != NULL) { @@ -93,6 +102,14 @@ getenv_columns (void) if (n > 0) return n; } + +#ifdef TIOCGWINSZ + struct winsize w; + w.ws_col = 0; + if (ioctl (0, TIOCGWINSZ, &w) == 0 && w.ws_col > 0) + return w.ws_col; +#endif + return INT_MAX; } @@ -103,7 +120,7 @@ diagnostic_set_caret_max_width (diagnostic_context *context, int value) /* One minus to account for the leading empty space. */ value = value ? value - 1 : (isatty (fileno (pp_buffer (context->printer)->stream)) - ? getenv_columns () - 1: INT_MAX); + ? get_terminal_width () - 1: INT_MAX); if (value <= 0) value = INT_MAX; |