diff options
author | Tobias Burnus <burnus@net-b.de> | 2014-12-11 09:20:24 +0100 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2014-12-11 09:20:24 +0100 |
commit | c9db45aaf49be681ba6e16203ab4b455bfa9746e (patch) | |
tree | e31e886ed230649c1e858eb51f469565c87e1754 /gcc/diagnostic.c | |
parent | 01ca36af914385acfc864adfae6923768581888a (diff) | |
download | gcc-c9db45aaf49be681ba6e16203ab4b455bfa9746e.zip gcc-c9db45aaf49be681ba6e16203ab4b455bfa9746e.tar.gz gcc-c9db45aaf49be681ba6e16203ab4b455bfa9746e.tar.bz2 |
diagnostic.c (get_terminal_width): Renamed from
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.
Co-Authored-By: Manuel López-Ibáñez <manu@gcc.gnu.org>
From-SVN: r218619
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 28ef81c..2c2477f 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; |