summaryrefslogtreecommitdiff
path: root/gcc/fortran/error.c
diff options
context:
space:
mode:
authorjanus <janus@138bc75d-0d04-0410-961f-82ee72b054a4>2013-06-01 19:12:57 +0000
committerjanus <janus@138bc75d-0d04-0410-961f-82ee72b054a4>2013-06-01 19:12:57 +0000
commitf3b719b373c54bc689c29a46932b0b7bb3250c4a (patch)
treea6739e4409a3e10989d6e8017e82b8fcd4de69d5 /gcc/fortran/error.c
parent47269859a5bb1d55547b4dbc3213206706db5813 (diff)
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@199585 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fortran/error.c')
-rw-r--r--gcc/fortran/error.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
index ee0dea0c1c7c..35fe62706c6a 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;
}