diff options
author | Janus Weil <janus@gcc.gnu.org> | 2013-06-01 21:12:57 +0200 |
---|---|---|
committer | Janus Weil <janus@gcc.gnu.org> | 2013-06-01 21:12:57 +0200 |
commit | c68a6e08c5177557d7ecc99a173593f064a15a7d (patch) | |
tree | a6739e4409a3e10989d6e8017e82b8fcd4de69d5 /gcc/fortran | |
parent | 1c9f675fd91d50b9c4eb944481ab6a59386a89c7 (diff) | |
download | gcc-c68a6e08c5177557d7ecc99a173593f064a15a7d.zip gcc-c68a6e08c5177557d7ecc99a173593f064a15a7d.tar.gz gcc-c68a6e08c5177557d7ecc99a173593f064a15a7d.tar.bz2 |
configure.ac: Add AC_HEADER_TIOCGWINSZ macro.
2013-06-01 Janus Weil <janus@gcc.gnu.org>
Mikael Morin <mikael@gcc.gnu.org>
* configure.ac: Add AC_HEADER_TIOCGWINSZ macro.
* config.in: Regenerated.
* configure: Regenerated.
2013-06-01 Janus Weil <janus@gcc.gnu.org>
Mikael Morin <mikael@gcc.gnu.org>
* error.c (get_terminal_width): Only limit the width if we're
outputting to a terminal. Try to determine width via ioctl.
Co-Authored-By: Mikael Morin <mikael@gcc.gnu.org>
From-SVN: r199585
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fortran/error.c | 29 |
2 files changed, 34 insertions, 1 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 4d76a44..2043691 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2013-06-01 Janus Weil <janus@gcc.gnu.org> + Mikael Morin <mikael@gcc.gnu.org> + + * error.c (get_terminal_width): Only limit the width if we're + outputting to a terminal. Try to determine width via ioctl. + 2013-06-01 Tobias Burnus <burnus@net-b.de> * decl.c (add_global_entry): Take locus. diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c index ee0dea0..35fe627 100644 --- a/gcc/fortran/error.c +++ b/gcc/fortran/error.c @@ -30,6 +30,15 @@ along with GCC; see the file COPYING3. If not see #include "flags.h" #include "gfortran.h" +#ifdef HAVE_TERMIOS_H +# include <termios.h> +#endif + +#ifdef GWINSZ_IN_SYS_IOCTL +# include <sys/ioctl.h> +#endif + + static int suppress_errors = 0; static int warnings_not_errors = 0; @@ -59,9 +68,26 @@ gfc_pop_suppress_errors (void) } +/* Determine terminal width (for trimming source lines in output). */ + static int get_terminal_width (void) { + /* Only limit the width if we're outputting to a terminal. */ +#ifdef HAVE_UNISTD_H + if (!isatty (STDERR_FILENO)) + return INT_MAX; +#endif + + /* Method #1: Use ioctl (not available on all systems). */ +#ifdef TIOCGWINSZ + struct winsize w; + w.ws_col = 0; + if (ioctl (0, TIOCGWINSZ, &w) == 0 && w.ws_col > 0) + return w.ws_col; +#endif + + /* Method #2: Query environment variable $COLUMNS. */ const char *p = getenv ("COLUMNS"); if (p) { @@ -69,7 +95,8 @@ get_terminal_width (void) if (value > 0) return value; } - /* Use a reasonable default. */ + + /* If both fail, use reasonable default. */ return 80; } |