From 04d28a7555405a15b3e93de769510b18c4a58c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Thu, 31 May 2018 09:37:04 +0200 Subject: Send informational messages to stderr rather than the output when used in non-interactive mode --- src/macros.h | 2 ++ src/pipe.c | 10 +++++----- src/tui.c | 12 ++++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/macros.h b/src/macros.h index 3bb1afa..486c846 100644 --- a/src/macros.h +++ b/src/macros.h @@ -103,10 +103,12 @@ #define CELL_NEGATIVE 17 #define DEFAULT 18 #define DEBUG_MSG 19 +#define VALUE_MSG 20 void ui_sc_msg(char * s, int type, ...); #define sc_error(x, ...) ui_sc_msg(x, ERROR_MSG, ##__VA_ARGS__) #define sc_debug(x, ...) ui_sc_msg(x, DEBUG_MSG, ##__VA_ARGS__) #define sc_info(x, ...) ui_sc_msg(x, INFO_MSG, ##__VA_ARGS__) +#define sc_value(x, ...) ui_sc_msg(x, VALUE_MSG, ##__VA_ARGS__) #define RUNTIME ((current_tv.tv_sec - startup_tv.tv_sec) * 1000L + (current_tv.tv_usec - startup_tv.tv_usec) / 1000L) diff --git a/src/pipe.c b/src/pipe.c index 5ae89c2..30c2417 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -83,7 +83,7 @@ void getnum(int r0, int c0, int rn, int cn, FILE * fd) { sprintf(line, "%.15g", p->v); } } - sc_info("%s", line); + sc_value("%s", line); if (brokenpipe) { linelim = -1; return; @@ -106,7 +106,7 @@ void getnum(int r0, int c0, int rn, int cn, FILE * fd) { void getformat(int col, FILE * fd) { sprintf(line, "%d %d %d\n", fwidth[col], precision[col], realfmt[col]); //write(fd, line, strlen(line)); - sc_info("%s", line); + sc_value("%s", line); linelim = -1; } @@ -130,7 +130,7 @@ void getfmt(int r0, int c0, int rn, int cn, FILE * fd) { for (c = c0, pp = ATBL(tbl, r, c); c <= cn; pp++, c++) { *line = '\0'; if (*pp && (*pp)->format) sprintf(line, "%s", (*pp)->format); - sc_info("%s", line); + sc_value("%s", line); if (brokenpipe) { linelim = -1; return; @@ -161,7 +161,7 @@ void getstring(int r0, int c0, int rn, int cn, FILE * fd) { *line = '\0'; if (*pp && (*pp)->label) sprintf(line, "%s", (*pp)->label); - sc_info("%s", line); + sc_value("%s", line); if (brokenpipe) { linelim = -1; return; @@ -199,7 +199,7 @@ void getexp(int r0, int c0, int rn, int cn, FILE * fd) { if (*line == '?') *line = '\0'; } - sc_info("%s", line); + sc_value("%s", line); if (brokenpipe) { linelim = -1; return; diff --git a/src/tui.c b/src/tui.c index 737eb40..81998cd 100644 --- a/src/tui.c +++ b/src/tui.c @@ -239,9 +239,9 @@ void ui_sc_msg(char * s, int type, ...) { } wrefresh(input_win); - } else if (get_conf_value("output") != NULL && fdoutput != NULL) { + } else if (type == VALUE_MSG && get_conf_value("output") != NULL && fdoutput != NULL) { fwprintf(fdoutput, L"%s\n", t); - } else { + } else if (type == VALUE_MSG) { if (fwide(stdout, 0) >0) //wprintf(L"wide %s\n", t); wprintf(L"%s\n", t); @@ -249,6 +249,14 @@ void ui_sc_msg(char * s, int type, ...) { //printf("nowide %s\n", t); printf("%s\n", t); fflush(stdout); + } else { + if (fwide(stderr, 0) >0) + //wprintf(L"wide %s\n", t); + fwprintf(stderr, L"%s\n", t); + else + //printf("nowide %s\n", t); + fprintf(stderr, "%s\n", t); + fflush(stderr); } va_end(args); return; -- cgit v1.2.3