configure.ac: Add AC_HEADER_TIOCGWINSZ macro.
authorJanus Weil <janus@gcc.gnu.org>
Sat, 1 Jun 2013 19:12:57 +0000 (21:12 +0200)
committerJanus Weil <janus@gcc.gnu.org>
Sat, 1 Jun 2013 19:12:57 +0000 (21:12 +0200)
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

gcc/ChangeLog
gcc/config.in
gcc/configure
gcc/configure.ac
gcc/fortran/ChangeLog
gcc/fortran/error.c

index 3df45d8ad9204c839ddc6968321eac4fcc810f7e..d9ab9eac21c79d97c7e0a74e5128d9f7ceb8498c 100644 (file)
@@ -1,3 +1,10 @@
+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  Jan Hubicka  <jh@suse.cz>
 
        PR middle-end/57366
index f122d48579e3ddd490c788afb451ae3285d7f5d8..288c11f937776b9463fbdd2e0c1b483bbd48a8c8 100644 (file)
 #endif
 
 
+/* Define to 1 if `TIOCGWINSZ' requires <sys/ioctl.h>. */
+#ifndef USED_FOR_TARGET
+#undef GWINSZ_IN_SYS_IOCTL
+#endif
+
+
 /* mcontext_t fields start with __ */
 #ifndef USED_FOR_TARGET
 #undef HAS_MCONTEXT_T_UNDERSCORES
 #endif
 
 
-/* Define if your AIX linker supports a large TOC. */
+/* Define if your PowerPC64 linker supports a large TOC. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_LD_LARGE_TOC
 #endif
index 1f03eac6e27e9a0ee2f9f929a2727e71a94360ce..8c221078102381412fb42da6dc4b81abb4695288 100755 (executable)
@@ -8293,6 +8293,66 @@ $as_echo "#define HAVE_SYS_WAIT_H 1" >>confdefs.h
 
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether termios.h defines TIOCGWINSZ" >&5
+$as_echo_n "checking whether termios.h defines TIOCGWINSZ... " >&6; }
+if test "${ac_cv_sys_tiocgwinsz_in_termios_h+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <termios.h>
+#ifdef TIOCGWINSZ
+  yes
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "yes" >/dev/null 2>&1; then :
+  ac_cv_sys_tiocgwinsz_in_termios_h=yes
+else
+  ac_cv_sys_tiocgwinsz_in_termios_h=no
+fi
+rm -f conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_tiocgwinsz_in_termios_h" >&5
+$as_echo "$ac_cv_sys_tiocgwinsz_in_termios_h" >&6; }
+
+if test $ac_cv_sys_tiocgwinsz_in_termios_h != yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether sys/ioctl.h defines TIOCGWINSZ" >&5
+$as_echo_n "checking whether sys/ioctl.h defines TIOCGWINSZ... " >&6; }
+if test "${ac_cv_sys_tiocgwinsz_in_sys_ioctl_h+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#ifdef TIOCGWINSZ
+  yes
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "yes" >/dev/null 2>&1; then :
+  ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=yes
+else
+  ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=no
+fi
+rm -f conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h" >&5
+$as_echo "$ac_cv_sys_tiocgwinsz_in_sys_ioctl_h" >&6; }
+
+  if test $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h = yes; then
+
+$as_echo "#define GWINSZ_IN_SYS_IOCTL 1" >>confdefs.h
+
+  fi
+fi
+
 for ac_header in limits.h stddef.h string.h strings.h stdlib.h time.h iconv.h \
                 fcntl.h unistd.h sys/file.h sys/time.h sys/mman.h \
                 sys/resource.h sys/param.h sys/times.h sys/stat.h \
@@ -17834,7 +17894,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 17837 "configure"
+#line 17897 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -17940,7 +18000,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 17943 "configure"
+#line 18003 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
index 855affdf152302e307f4f35611f2e370b5fc18ab..41b64c78736703e0645b8ba47abb6fd0d8d3c9a4 100644 (file)
@@ -939,6 +939,7 @@ AC_HEADER_STDC
 AC_HEADER_TIME
 ACX_HEADER_STRING
 AC_HEADER_SYS_WAIT
+AC_HEADER_TIOCGWINSZ
 AC_CHECK_HEADERS(limits.h stddef.h string.h strings.h stdlib.h time.h iconv.h \
                 fcntl.h unistd.h sys/file.h sys/time.h sys/mman.h \
                 sys/resource.h sys/param.h sys/times.h sys/stat.h \
index 4d76a444f93c5a7a62893b8aa942807087fd521a..20436913fc459093e421dbf783b1b22b83dbe37b 100644 (file)
@@ -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.
index ee0dea0c1c7c0c0407062b68ec9616a15d179fb2..35fe62706c6a946b25cd95e3efb263fbbcf6321e 100644 (file)
@@ -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;
 }