Skip to content

Commit 58652df

Browse files
committed
Add -O option to redirect output to stderr.
1 parent ab834f3 commit 58652df

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
@@ -113,7 +113,7 @@
113113

114114
int main (void)
115115
{
116-
text_color_init (0); // Turn off text color.
116+
text_color_init (0, 0); // Turn off text color.
117117
#if defined(__OpenBSD__) || defined(__FreeBSD__)
118118
dw_printf ("CM108 PTT support is not available for this operating system.\n");
119119
#else
@@ -340,7 +340,7 @@ int main (int argc, char **argv)
340340
int num_things;
341341
int i;
342342

343-
text_color_init (0); // Turn off text color.
343+
text_color_init (0, 0); // Turn off text color.
344344
text_color_set(DW_COLOR_INFO);
345345

346346
if (argc >=2) {

Diff for: src/decode_aprs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5330,7 +5330,7 @@ int main (int argc, char *argv[])
53305330
}
53315331

53325332
// If you don't like the text colors, use 0 instead of 1 here.
5333-
text_color_init(1);
5333+
text_color_init(1, 0);
53345334
text_color_set(DW_COLOR_INFO);
53355335

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

Diff for: src/direwolf.c

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

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

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

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

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

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

302-
text_color_init(t_opt);
306+
text_color_init(t_opt, O_opt);
303307
text_color_set(DW_COLOR_INFO);
304308
dw_printf ("Dire Wolf version %d.%d (%s) BETA TEST 7\n", MAJOR_VERSION, MINOR_VERSION, __DATE__);
305309
//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[])
421425

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

424-
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:",
428+
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",
425429
long_options, &option_index);
426430
if (c == -1)
427431
break;
@@ -738,6 +742,10 @@ int main (int argc, char *argv[])
738742
A_opt_ais_to_obj = 1;
739743
break;
740744

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

743751
/* 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)