Skip to content

Commit 4c9f959

Browse files
committed
Add -O option to redirect output to stderr.
1 parent 75ccf18 commit 4c9f959

File tree

8 files changed

+33
-19
lines changed

8 files changed

+33
-19
lines changed

Diff for: src/atest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ int main (int argc, char *argv[])
217217
}
218218
#endif
219219

220-
text_color_init(1);
220+
text_color_init(1, 0);
221221
text_color_set(DW_COLOR_INFO);
222222

223223
/*

Diff for: src/cm108.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106

107107
int main (void)
108108
{
109-
text_color_init (0); // Turn off text color.
109+
text_color_init (0, 0); // Turn off text color.
110110
#if defined(__OpenBSD__) || defined(__FreeBSD__)
111111
dw_printf ("CM108 PTT support is not available for this operating system.\n");
112112
#else
@@ -319,7 +319,7 @@ int main (int argc, char **argv)
319319
int num_things;
320320
int i;
321321

322-
text_color_init (0); // Turn off text color.
322+
text_color_init (0, 0); // Turn off text color.
323323
text_color_set(DW_COLOR_INFO);
324324

325325
if (argc >=2) {

Diff for: src/decode_aprs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5116,7 +5116,7 @@ int main (int argc, char *argv[])
51165116
}
51175117

51185118
// If you don't like the text colors, use 0 instead of 1 here.
5119-
text_color_init(1);
5119+
text_color_init(1, 0);
51205120
text_color_set(DW_COLOR_INFO);
51215121

51225122
while (fgets(stuff, sizeof(stuff), stdin) != NULL)

Diff for: src/direwolf.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ int main (int argc, char *argv[])
241241
char x_opt_mode = ' '; /* "-x N" option for transmitting calibration tones. */
242242
int x_opt_chan = 0; /* Split into 2 parts. Mode e.g. m, a, and optional channel. */
243243

244+
int O_opt = 0; /* Redirect text io to stderr for use with stdout audio */
245+
244246
strlcpy(l_opt_logdir, "", sizeof(l_opt_logdir));
245247
strlcpy(L_opt_logfile, "", sizeof(L_opt_logfile));
246248
strlcpy(P_opt, "", sizeof(P_opt));
@@ -269,8 +271,8 @@ int main (int argc, char *argv[])
269271
#endif
270272

271273
/*
272-
* Pre-scan the command line options for the text color option.
273-
* We need to set this before any text output.
274+
* Pre-scan the command line options for the text color and stdout redirect options.
275+
* We need to set these before any text output.
274276
* Default will be no colors if stdout is not a terminal (i.e. piped into
275277
* something else such as "tee") but command line can override this.
276278
*/
@@ -285,10 +287,12 @@ int main (int argc, char *argv[])
285287

286288
// FIXME: consider case of no space between t and number.
287289

288-
for (j=1; j<argc-1; j++) {
290+
for (j=1; j<argc; j++) {
289291
if (strcmp(argv[j], "-t") == 0) {
290292
t_opt = atoi (argv[j+1]);
291293
//dw_printf ("DEBUG: text color option = %d.\n", t_opt);
294+
} else if (strcmp(argv[j], "-O") == 0) {
295+
O_opt = 1;
292296
}
293297
}
294298

@@ -298,7 +302,7 @@ int main (int argc, char *argv[])
298302
// Might want to print OS version here. For Windows, see:
299303
// https://msdn.microsoft.com/en-us/library/ms724451(v=VS.85).aspx
300304

301-
text_color_init(t_opt);
305+
text_color_init(t_opt, O_opt);
302306
text_color_set(DW_COLOR_INFO);
303307
//dw_printf ("Dire Wolf version %d.%d (%s) Beta Test 4\n", MAJOR_VERSION, MINOR_VERSION, __DATE__);
304308
dw_printf ("Dire Wolf DEVELOPMENT version %d.%d %s (%s)\n", MAJOR_VERSION, MINOR_VERSION, "F", __DATE__);
@@ -420,7 +424,7 @@ int main (int argc, char *argv[])
420424

421425
/* ':' following option character means arg is required. */
422426

423-
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:",
427+
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",
424428
long_options, &option_index);
425429
if (c == -1)
426430
break;
@@ -737,6 +741,10 @@ int main (int argc, char *argv[])
737741
A_opt_ais_to_obj = 1;
738742
break;
739743

744+
case 'O': /* Was handled earlier. -O Redirects output to stderr. */
745+
break;
746+
747+
740748
default:
741749

742750
/* Should not be here. */

Diff for: src/il2p_test.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void decode_bitstream(void);
5353
int main ()
5454
{
5555
int enable_color = 1;
56-
text_color_init (enable_color);
56+
text_color_init (enable_color, 0);
5757

5858
int enable_debug_out = 0;
5959
il2p_init(enable_debug_out);
@@ -974,4 +974,4 @@ alevel_t demod_get_audio_level (int chan, int subchan)
974974
return (alevel);
975975
}
976976

977-
// end il2p_test.c
977+
// end il2p_test.c

Diff for: src/kissutil.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static void trim (char *stuff)
179179

180180
int main (int argc, char *argv[])
181181
{
182-
text_color_init (0); // Turn off text color.
182+
text_color_init (0, 0); // Turn off text color.
183183
// It could interfere with trying to pipe stdout to some other application.
184184

185185
#if __WIN32__

Diff for: src/textcolor.c

+12-6
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,20 @@ static const char clear_eos[] = "\e[0J";
171171
*/
172172

173173
static int g_enable_color = 1;
174+
static FILE *g_dw_printf_dest = 0;
174175

175-
176-
void text_color_init (int enable_color)
176+
void text_color_init (int enable_color, int redirect_output)
177177
{
178-
178+
if (redirect_output != 0) {
179+
g_dw_printf_dest = stderr;
180+
enable_color = 0;
181+
} else {
182+
g_dw_printf_dest = stdout;
183+
}
179184

180185
#if __WIN32__
181186

187+
g_enable_color = enable_color;
182188

183189
if (g_enable_color != 0) {
184190

@@ -208,7 +214,7 @@ void text_color_init (int enable_color)
208214
if (enable_color < 0 || enable_color > MAX_T) {
209215
int t;
210216
for (t = 0; t <= MAX_T; t++) {
211-
text_color_init (t);
217+
text_color_init (t, redirect_output);
212218
printf ("-t %d", t);
213219
if (t) printf (" [white background] ");
214220
printf ("\n");
@@ -377,7 +383,7 @@ int dw_printf (const char *fmt, ...)
377383

378384
// TODO: other possible destinations...
379385

380-
fputs (buffer, stdout);
386+
fputs (buffer, g_dw_printf_dest);
381387
return (len);
382388
}
383389

@@ -387,7 +393,7 @@ int dw_printf (const char *fmt, ...)
387393
main ()
388394
{
389395
printf ("Initial condition\n");
390-
text_color_init (1);
396+
text_color_init (1, 0);
391397
printf ("After text_color_init\n");
392398
text_color_set(DW_COLOR_INFO); printf ("Info\n");
393399
text_color_set(DW_COLOR_ERROR); printf ("Error\n");

Diff for: src/textcolor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ enum dw_color_e { DW_COLOR_INFO, /* black */
2222
typedef enum dw_color_e dw_color_t;
2323

2424

25-
void text_color_init (int enable_color);
25+
void text_color_init (int enable_color, int redirect_output);
2626
void text_color_set (dw_color_t c);
2727
void text_color_term (void);
2828

0 commit comments

Comments
 (0)