Commit c9db45aa by Tobias Burnus Committed by Tobias Burnus

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
parent 01ca36af
2014-12-11 Tobias Burnus <burnus@net-b.de>
Manuel López-Ibáñez <manu@gcc.gnu.org>
* error.c (gfc_get_terminal_width): Renamed from
get_terminal_width and use same-named common function.
(gfc_error_init_1): Update call.
2014-12-10 Ulrich Drepper <drepper@gmail.com> 2014-12-10 Ulrich Drepper <drepper@gmail.com>
Minor interface cleanups of libgccjit Minor interface cleanups of libgccjit
...@@ -33,6 +33,14 @@ along with GCC; see the file COPYING3. If not see ...@@ -33,6 +33,14 @@ along with GCC; see the file COPYING3. If not see
#include "diagnostic.h" #include "diagnostic.h"
#include "diagnostic-color.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. #include <new> // For placement new.
#define pedantic_warning_kind(DC) \ #define pedantic_warning_kind(DC) \
...@@ -83,9 +91,10 @@ file_name_as_prefix (diagnostic_context *context, const char *f) ...@@ -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 /* Return the value of the getenv("COLUMNS") as an integer. If the
value is not set to a positive integer, then return INT_MAX. */ value is not set to a positive integer, use ioctl to get the
static int terminal width. If it fails, return INT_MAX. */
getenv_columns (void) int
get_terminal_width (void)
{ {
const char * s = getenv ("COLUMNS"); const char * s = getenv ("COLUMNS");
if (s != NULL) { if (s != NULL) {
...@@ -93,6 +102,14 @@ getenv_columns (void) ...@@ -93,6 +102,14 @@ getenv_columns (void)
if (n > 0) if (n > 0)
return n; 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; return INT_MAX;
} }
...@@ -103,7 +120,7 @@ diagnostic_set_caret_max_width (diagnostic_context *context, int value) ...@@ -103,7 +120,7 @@ diagnostic_set_caret_max_width (diagnostic_context *context, int value)
/* One minus to account for the leading empty space. */ /* One minus to account for the leading empty space. */
value = value ? value - 1 value = value ? value - 1
: (isatty (fileno (pp_buffer (context->printer)->stream)) : (isatty (fileno (pp_buffer (context->printer)->stream))
? getenv_columns () - 1: INT_MAX); ? get_terminal_width () - 1: INT_MAX);
if (value <= 0) if (value <= 0)
value = INT_MAX; value = INT_MAX;
......
...@@ -297,6 +297,8 @@ void diagnostic_set_caret_max_width (diagnostic_context *context, int value); ...@@ -297,6 +297,8 @@ void diagnostic_set_caret_max_width (diagnostic_context *context, int value);
void diagnostic_file_cache_fini (void); void diagnostic_file_cache_fini (void);
int get_terminal_width (void);
/* Expand the location of this diagnostic. Use this function for consistency. */ /* Expand the location of this diagnostic. Use this function for consistency. */
static inline expanded_location static inline expanded_location
......
...@@ -3188,7 +3188,10 @@ option is known to the diagnostic machinery). Specifying the ...@@ -3188,7 +3188,10 @@ option is known to the diagnostic machinery). Specifying the
@opindex fdiagnostics-show-caret @opindex fdiagnostics-show-caret
By default, each diagnostic emitted includes the original source line By default, each diagnostic emitted includes the original source line
and a caret '^' indicating the column. This option suppresses this and a caret '^' indicating the column. This option suppresses this
information. information. The source line is truncated to @var{n} characters, if
the @option{-fmessage-length=n} is given. When the output is done
to the terminal, the width is limited to the width given by the
@env{COLUMNS} environment variable or, if not set, to the terminal width.
@end table @end table
......
2014-12-11 Tobias Burnus <burnus@net-b.de>
Manuel López-Ibáñez <manu@gcc.gnu.org>
* 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.
2014-12-10 Bernd Edlinger <bernd.edlinger@hotmail.de> 2014-12-10 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR fortran/60718 PR fortran/60718
......
...@@ -30,14 +30,6 @@ along with GCC; see the file COPYING3. If not see ...@@ -30,14 +30,6 @@ along with GCC; see the file COPYING3. If not see
#include "flags.h" #include "flags.h"
#include "gfortran.h" #include "gfortran.h"
#ifdef HAVE_TERMIOS_H
# include <termios.h>
#endif
#ifdef GWINSZ_IN_SYS_IOCTL
# include <sys/ioctl.h>
#endif
#include "diagnostic.h" #include "diagnostic.h"
#include "diagnostic-color.h" #include "diagnostic-color.h"
#include "tree-diagnostic.h" /* tree_diagnostics_defaults */ #include "tree-diagnostic.h" /* tree_diagnostics_defaults */
...@@ -83,33 +75,9 @@ gfc_pop_suppress_errors (void) ...@@ -83,33 +75,9 @@ gfc_pop_suppress_errors (void)
/* Determine terminal width (for trimming source lines in output). */ /* Determine terminal width (for trimming source lines in output). */
static int static int
get_terminal_width (void) gfc_get_terminal_width (void)
{ {
/* Only limit the width if we're outputting to a terminal. */ return isatty (STDERR_FILENO) ? get_terminal_width () : INT_MAX;
#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)
{
int value = atoi (p);
if (value > 0)
return value;
}
/* If both fail, use reasonable default. */
return 80;
} }
...@@ -118,7 +86,7 @@ get_terminal_width (void) ...@@ -118,7 +86,7 @@ get_terminal_width (void)
void void
gfc_error_init_1 (void) gfc_error_init_1 (void)
{ {
terminal_width = get_terminal_width (); terminal_width = gfc_get_terminal_width ();
errors = 0; errors = 0;
warnings = 0; warnings = 0;
gfc_buffer_error (false); gfc_buffer_error (false);
......
...@@ -1231,18 +1231,8 @@ print_specific_help (unsigned int include_flags, ...@@ -1231,18 +1231,8 @@ print_specific_help (unsigned int include_flags,
the desired maximum width of the output. */ the desired maximum width of the output. */
if (opts->x_help_columns == 0) if (opts->x_help_columns == 0)
{ {
const char *p; opts->x_help_columns = get_terminal_width ();
if (opts->x_help_columns == INT_MAX)
p = getenv ("COLUMNS");
if (p != NULL)
{
int value = atoi (p);
if (value > 0)
opts->x_help_columns = value;
}
if (opts->x_help_columns == 0)
/* Use a reasonable default. */ /* Use a reasonable default. */
opts->x_help_columns = 80; opts->x_help_columns = 80;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment