Add -O option to redirect output to stderr.

This commit is contained in:
ars-ka0s 2023-01-17 00:51:40 -06:00
parent ab834f338b
commit 58652df5b9
8 changed files with 33 additions and 19 deletions

View File

@ -217,7 +217,7 @@ int main (int argc, char *argv[])
} }
#endif #endif
text_color_init(1); text_color_init(1, 0);
text_color_set(DW_COLOR_INFO); text_color_set(DW_COLOR_INFO);
/* /*

View File

@ -113,7 +113,7 @@
int main (void) int main (void)
{ {
text_color_init (0); // Turn off text color. text_color_init (0, 0); // Turn off text color.
#if defined(__OpenBSD__) || defined(__FreeBSD__) #if defined(__OpenBSD__) || defined(__FreeBSD__)
dw_printf ("CM108 PTT support is not available for this operating system.\n"); dw_printf ("CM108 PTT support is not available for this operating system.\n");
#else #else
@ -340,7 +340,7 @@ int main (int argc, char **argv)
int num_things; int num_things;
int i; int i;
text_color_init (0); // Turn off text color. text_color_init (0, 0); // Turn off text color.
text_color_set(DW_COLOR_INFO); text_color_set(DW_COLOR_INFO);
if (argc >=2) { if (argc >=2) {

View File

@ -5330,7 +5330,7 @@ int main (int argc, char *argv[])
} }
// If you don't like the text colors, use 0 instead of 1 here. // If you don't like the text colors, use 0 instead of 1 here.
text_color_init(1); text_color_init(1, 0);
text_color_set(DW_COLOR_INFO); text_color_set(DW_COLOR_INFO);
while (fgets(stuff, sizeof(stuff), stdin) != NULL) while (fgets(stuff, sizeof(stuff), stdin) != NULL)

View File

@ -242,6 +242,8 @@ int main (int argc, char *argv[])
char x_opt_mode = ' '; /* "-x N" option for transmitting calibration tones. */ char x_opt_mode = ' '; /* "-x N" option for transmitting calibration tones. */
int x_opt_chan = 0; /* Split into 2 parts. Mode e.g. m, a, and optional channel. */ int x_opt_chan = 0; /* Split into 2 parts. Mode e.g. m, a, and optional channel. */
int O_opt = 0; /* Redirect text io to stderr for use with stdout audio */
strlcpy(l_opt_logdir, "", sizeof(l_opt_logdir)); strlcpy(l_opt_logdir, "", sizeof(l_opt_logdir));
strlcpy(L_opt_logfile, "", sizeof(L_opt_logfile)); strlcpy(L_opt_logfile, "", sizeof(L_opt_logfile));
strlcpy(P_opt, "", sizeof(P_opt)); strlcpy(P_opt, "", sizeof(P_opt));
@ -270,8 +272,8 @@ int main (int argc, char *argv[])
#endif #endif
/* /*
* Pre-scan the command line options for the text color option. * Pre-scan the command line options for the text color and stdout redirect options.
* We need to set this before any text output. * We need to set these before any text output.
* Default will be no colors if stdout is not a terminal (i.e. piped into * Default will be no colors if stdout is not a terminal (i.e. piped into
* something else such as "tee") but command line can override this. * something else such as "tee") but command line can override this.
*/ */
@ -286,10 +288,12 @@ int main (int argc, char *argv[])
// FIXME: consider case of no space between t and number. // FIXME: consider case of no space between t and number.
for (j=1; j<argc-1; j++) { for (j=1; j<argc; j++) {
if (strcmp(argv[j], "-t") == 0) { if (strcmp(argv[j], "-t") == 0) {
t_opt = atoi (argv[j+1]); t_opt = atoi (argv[j+1]);
//dw_printf ("DEBUG: text color option = %d.\n", t_opt); //dw_printf ("DEBUG: text color option = %d.\n", t_opt);
} else if (strcmp(argv[j], "-O") == 0) {
O_opt = 1;
} }
} }
@ -299,7 +303,7 @@ int main (int argc, char *argv[])
// Might want to print OS version here. For Windows, see: // Might want to print OS version here. For Windows, see:
// https://msdn.microsoft.com/en-us/library/ms724451(v=VS.85).aspx // https://msdn.microsoft.com/en-us/library/ms724451(v=VS.85).aspx
text_color_init(t_opt); text_color_init(t_opt, O_opt);
text_color_set(DW_COLOR_INFO); text_color_set(DW_COLOR_INFO);
dw_printf ("Dire Wolf version %d.%d (%s) BETA TEST 7\n", MAJOR_VERSION, MINOR_VERSION, __DATE__); dw_printf ("Dire Wolf version %d.%d (%s) BETA TEST 7\n", MAJOR_VERSION, MINOR_VERSION, __DATE__);
//dw_printf ("Dire Wolf DEVELOPMENT version %d.%d %s (%s)\n", MAJOR_VERSION, MINOR_VERSION, "G", __DATE__); //dw_printf ("Dire Wolf DEVELOPMENT version %d.%d %s (%s)\n", MAJOR_VERSION, MINOR_VERSION, "G", __DATE__);
@ -421,7 +425,7 @@ int main (int argc, char *argv[])
/* ':' following option character means arg is required. */ /* ':' following option character means arg is required. */
c = getopt_long(argc, argv, "hP:B:gjJD:U:c:px:r:b:n:d:q:t:ul:L:Sa:E:T:e:X:AI:i:", c = getopt_long(argc, argv, "hP:B:gjJD:U:c:px:r:b:n:d:q:t:ul:L:Sa:E:T:e:X:AI:i:O",
long_options, &option_index); long_options, &option_index);
if (c == -1) if (c == -1)
break; break;
@ -738,6 +742,10 @@ int main (int argc, char *argv[])
A_opt_ais_to_obj = 1; A_opt_ais_to_obj = 1;
break; break;
case 'O': /* Was handled earlier. -O Redirects output to stderr. */
break;
default: default:
/* Should not be here. */ /* Should not be here. */

View File

@ -53,7 +53,7 @@ static void decode_bitstream(void);
int main () int main ()
{ {
int enable_color = 1; int enable_color = 1;
text_color_init (enable_color); text_color_init (enable_color, 0);
int enable_debug_out = 0; int enable_debug_out = 0;
il2p_init(enable_debug_out); il2p_init(enable_debug_out);

View File

@ -179,7 +179,7 @@ static void trim (char *stuff)
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
text_color_init (0); // Turn off text color. text_color_init (0, 0); // Turn off text color.
// It could interfere with trying to pipe stdout to some other application. // It could interfere with trying to pipe stdout to some other application.
#if __WIN32__ #if __WIN32__

View File

@ -171,14 +171,20 @@ static const char clear_eos[] = "\e[0J";
*/ */
static int g_enable_color = 1; static int g_enable_color = 1;
static FILE *g_dw_printf_dest = 0;
void text_color_init (int enable_color, int redirect_output)
void text_color_init (int enable_color)
{ {
if (redirect_output != 0) {
g_dw_printf_dest = stderr;
enable_color = 0;
} else {
g_dw_printf_dest = stdout;
}
#if __WIN32__ #if __WIN32__
g_enable_color = enable_color;
if (g_enable_color != 0) { if (g_enable_color != 0) {
@ -208,7 +214,7 @@ void text_color_init (int enable_color)
if (enable_color < 0 || enable_color > MAX_T) { if (enable_color < 0 || enable_color > MAX_T) {
int t; int t;
for (t = 0; t <= MAX_T; t++) { for (t = 0; t <= MAX_T; t++) {
text_color_init (t); text_color_init (t, redirect_output);
printf ("-t %d", t); printf ("-t %d", t);
if (t) printf (" [white background] "); if (t) printf (" [white background] ");
printf ("\n"); printf ("\n");
@ -377,7 +383,7 @@ int dw_printf (const char *fmt, ...)
// TODO: other possible destinations... // TODO: other possible destinations...
fputs (buffer, stdout); fputs (buffer, g_dw_printf_dest);
return (len); return (len);
} }
@ -387,7 +393,7 @@ int dw_printf (const char *fmt, ...)
main () main ()
{ {
printf ("Initial condition\n"); printf ("Initial condition\n");
text_color_init (1); text_color_init (1, 0);
printf ("After text_color_init\n"); printf ("After text_color_init\n");
text_color_set(DW_COLOR_INFO); printf ("Info\n"); text_color_set(DW_COLOR_INFO); printf ("Info\n");
text_color_set(DW_COLOR_ERROR); printf ("Error\n"); text_color_set(DW_COLOR_ERROR); printf ("Error\n");

View File

@ -22,7 +22,7 @@ enum dw_color_e { DW_COLOR_INFO, /* black */
typedef enum dw_color_e dw_color_t; typedef enum dw_color_e dw_color_t;
void text_color_init (int enable_color); void text_color_init (int enable_color, int redirect_output);
void text_color_set (dw_color_t c); void text_color_set (dw_color_t c);
void text_color_term (void); void text_color_term (void);