From: Andi K. <an...@fi...> - 2011-03-11 19:00:16
|
From: Andi Kleen <ak...@li...> If the output device of ophelp is a terminal query it for the line width, instead of hardcoding 99. Signed-off-by: Andi Kleen <ak...@li...> --- utils/ophelp.c | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/utils/ophelp.c b/utils/ophelp.c index a87a640..1b3d215 100644 --- a/utils/ophelp.c +++ b/utils/ophelp.c @@ -14,6 +14,8 @@ #include <stdlib.h> #include <string.h> #include <limits.h> +#include <sys/ioctl.h> +#include <unistd.h> #include "op_version.h" #include "op_events.h" @@ -61,13 +63,21 @@ static void do_arch_specific_event_help(struct op_event * event) } } -#define LINE_LEN 99 +static int line_len = 99; + +static void set_linelen(void) +{ + struct winsize ws; + + if (isatty(1) && ioctl(1, TIOCGWINSZ, &ws) >= 0) + line_len = ws.ws_col; +} static void word_wrap(int indent, int *column, char *msg) { while (*msg) { int wlen = strcspn(msg, " "); - if (*column + wlen > LINE_LEN) { + if (*column + wlen > line_len) { printf("\n%*s", indent, ""); *column = indent; } @@ -92,6 +102,8 @@ static void help_for_event(struct op_event * event) size_t nr_counters; char buf[32]; + set_linelen(); + do_arch_specific_event_help(event); nr_counters = op_get_nr_counters(cpu_type); -- 1.7.4 |