Skip to content

Commit 3370e63

Browse files
committed
Add -O option to redirect output to stderr.
1 parent 399ffcc commit 3370e63

File tree

7 files changed

+31
-17
lines changed

7 files changed

+31
-17
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
@@ -5052,7 +5052,7 @@ int main (int argc, char *argv[])
50525052
}
50535053

50545054
// If you don't like the text colors, use 0 instead of 1 here.
5055-
text_color_init(1);
5055+
text_color_init(1, 0);
50565056
text_color_set(DW_COLOR_INFO);
50575057

50585058
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
*/
@@ -283,10 +285,12 @@ int main (int argc, char *argv[])
283285
/* 1 = normal, 0 = no text colors. */
284286
/* 2, 3, ... alternate escape sequences for different terminals. */
285287

286-
for (j=1; j<argc-1; j++) {
288+
for (j=1; j<argc; j++) {
287289
if (strcmp(argv[j], "-t") == 0) {
288290
t_opt = atoi (argv[j+1]);
289291
//dw_printf ("DEBUG: text color option = %d.\n", t_opt);
292+
} else if (strcmp(argv[j], "-O") == 0) {
293+
O_opt = 1;
290294
}
291295
}
292296

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

299-
text_color_init(t_opt);
303+
text_color_init(t_opt, O_opt);
300304
text_color_set(DW_COLOR_INFO);
301305
//dw_printf ("Dire Wolf version %d.%d (%s) Beta Test 4\n", MAJOR_VERSION, MINOR_VERSION, __DATE__);
302306
dw_printf ("Dire Wolf DEVELOPMENT version %d.%d %s (%s)\n", MAJOR_VERSION, MINOR_VERSION, "E", __DATE__);
@@ -415,7 +419,7 @@ int main (int argc, char *argv[])
415419

416420
/* ':' following option character means arg is required. */
417421

418-
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:",
422+
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",
419423
long_options, &option_index);
420424
if (c == -1)
421425
break;
@@ -732,6 +736,10 @@ int main (int argc, char *argv[])
732736
A_opt_ais_to_obj = 1;
733737
break;
734738

739+
case 'O': /* Was handled earlier. -O Redirects output to stderr. */
740+
break;
741+
742+
735743
default:
736744

737745
/* Should not be here. */

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)