Skip to content

Commit 9015531

Browse files
committed
Direct usage text to stderr or stdout depending on context
Prints usage text to stdout when requested with -h/--help or to stderr otherwise.
1 parent ad8707c commit 9015531

12 files changed

Lines changed: 99 additions & 104 deletions

File tree

tests/ampctl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extern int read_history();
7070
/*
7171
* Prototypes
7272
*/
73-
void usage();
73+
void usage(FILE *fout);
7474

7575
/*
7676
* Reminder: when adding long options,
@@ -153,7 +153,7 @@ int main(int argc, char *argv[])
153153
switch (c)
154154
{
155155
case 'h':
156-
usage();
156+
usage(stdout);
157157
exit(0);
158158

159159
case 'V':
@@ -237,7 +237,7 @@ int main(int argc, char *argv[])
237237
break;
238238

239239
default:
240-
usage(); /* unknown option? */
240+
usage(stderr); /* unknown option? */
241241
exit(1);
242242
}
243243
}
@@ -438,12 +438,12 @@ int main(int argc, char *argv[])
438438
}
439439

440440

441-
void usage()
441+
void usage(FILE *fout)
442442
{
443-
printf("Usage: ampctl [OPTION]... [COMMAND]...\n"
443+
fprintf(fout, "Usage: ampctl [OPTION]... [COMMAND]...\n"
444444
"Send COMMANDs to a connected amplifier.\n\n");
445445

446-
printf(
446+
fprintf(fout,
447447
" -m, --model=ID select amplifier model number. See model list (-l)\n"
448448
" -r, --amp-file=DEVICE set device of the amplifier to operate on\n"
449449
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
@@ -464,5 +464,5 @@ void usage()
464464
"\n"
465465
);
466466

467-
usage_amp(stdout);
467+
usage_amp(fout);
468468
}

tests/ampctld.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct handle_data
7474

7575
void *handle_socket(void *arg);
7676

77-
void usage();
77+
void usage(FILE *fout);
7878

7979
/*
8080
* Reminder: when adding long options,
@@ -196,7 +196,7 @@ int main(int argc, char *argv[])
196196
switch (c)
197197
{
198198
case 'h':
199-
usage();
199+
usage(stdout);
200200
exit(0);
201201

202202
case 'V':
@@ -266,7 +266,7 @@ int main(int argc, char *argv[])
266266
break;
267267

268268
default:
269-
usage(); /* unknown option? */
269+
usage(stderr); /* unknown option? */
270270
exit(1);
271271
}
272272
}
@@ -683,12 +683,12 @@ void *handle_socket(void *arg)
683683
}
684684

685685

686-
void usage()
686+
void usage(FILE *fout)
687687
{
688-
printf("Usage: ampctld [OPTION]... [COMMAND]...\n"
688+
fprintf(fout, "Usage: ampctld [OPTION]... [COMMAND]...\n"
689689
"Daemon serving COMMANDs to a connected amplifier.\n\n");
690690

691-
printf(
691+
fprintf(fout,
692692
" -m, --model=ID select amplifier model number. See model list (-l)\n"
693693
" -r, --amp-file=DEVICE set device of the amplifier to operate on\n"
694694
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
@@ -704,5 +704,5 @@ void usage()
704704
" -V, --version output version information and exit\n\n",
705705
portno);
706706

707-
usage_amp(stdout);
707+
usage_amp(fout);
708708
}

tests/rigctl.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extern int read_history();
7474
#define MAXNBOPT 100 /* max number of different options */
7575

7676

77-
static void usage(void);
77+
static void usage(FILE *fout);
7878

7979
/*
8080
* Reminder: when adding long options,
@@ -269,7 +269,7 @@ int main(int argc, char *argv[])
269269
break;
270270

271271
case 'h':
272-
usage();
272+
usage(stdout);
273273
exit(0);
274274

275275
case 'V':
@@ -463,7 +463,7 @@ int main(int argc, char *argv[])
463463
break;
464464

465465
default:
466-
usage(); /* unknown option? */
466+
usage(stderr); /* unknown option? */
467467
exit(1);
468468
}
469469
}
@@ -871,13 +871,12 @@ int main(int argc, char *argv[])
871871
}
872872

873873

874-
void usage(void)
874+
void usage(FILE *fout)
875875
{
876-
printf("Usage: rigctl [OPTION]... [COMMAND]...\n"
876+
fprintf(fout, "Usage: rigctl [OPTION]... [COMMAND]...\n"
877877
"Send COMMANDs to a connected radio transceiver or receiver.\n\n");
878878

879-
880-
printf(
879+
fprintf(fout,
881880
" -m, --model=ID select radio model number. See model list (-l)\n"
882881
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
883882
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
@@ -908,5 +907,5 @@ void usage(void)
908907
"\n"
909908
);
910909

911-
usage_rig(stdout);
910+
usage_rig(fout);
912911
}

tests/rigctlcom.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static struct option long_options[] =
114114
{0, 0, 0, 0}
115115
};
116116

117-
void usage();
117+
void usage(FILE *fout);
118118
static int handle_ts2000(void *arg);
119119

120120
static RIG *my_rig; /* handle to rig */
@@ -248,7 +248,7 @@ int main(int argc, char *argv[])
248248
switch (c)
249249
{
250250
case 'h':
251-
usage();
251+
usage(stdout);
252252
exit(0);
253253

254254
case 'V':
@@ -400,7 +400,7 @@ int main(int argc, char *argv[])
400400
break;
401401

402402
default:
403-
usage(); /* unknown option? */
403+
usage(stderr); /* unknown option? */
404404
exit(1);
405405
}
406406
}
@@ -411,7 +411,7 @@ int main(int argc, char *argv[])
411411

412412
if (argc == 1)
413413
{
414-
usage();
414+
usage(stderr);
415415
exit(1);
416416
}
417417

@@ -1690,20 +1690,21 @@ static int handle_ts2000(void *arg)
16901690
}
16911691

16921692

1693-
void usage()
1693+
void usage(FILE *fout)
16941694
{
16951695
char *name = "rigctlcom";
1696-
printf("Usage: %s -m rignumber -r comport -s baud -R comport [OPTIONS]...\n\n"
1696+
1697+
fprintf(fout, "Usage: %s -m rignumber -r comport -s baud -R comport [OPTIONS]...\n\n"
16971698
"A TS-2000 emulator for rig sharing with programs that don't support Hamlib or FLRig to be able\n"
16981699
"to use a connected radio transceiver or receiver with FLRig or rigctld via Hamlib.\n\n",
16991700
name);
17001701

1701-
printf("Example: Using FLRig with virtual COM5/COM6 and other program:\n");
1702-
printf("\t%s -m 4 -R COM5 -S 115200\n\n", name);
1703-
printf("Other program would connect to COM6 and use TS-2000 115200 8N1\n\n");
1704-
printf("See the %s.1 manual page for complete details.\n\n", name);
1702+
fprintf(fout, "Example: Using FLRig with virtual COM5/COM6 and other program:\n");
1703+
fprintf(fout, "\t%s -m 4 -R COM5 -S 115200\n\n", name);
1704+
fprintf(fout, "Other program would connect to COM6 and use TS-2000 115200 8N1\n\n");
1705+
fprintf(fout, "See the %s.1 manual page for complete details.\n\n", name);
17051706

1706-
printf(
1707+
fprintf(fout,
17071708
" -m, --model=ID select radio model number. See model list (-l)\n"
17081709
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
17091710
" -R, --rig-file2=DEVICE set device of the virtual com port to operate on\n"
@@ -1725,6 +1726,5 @@ void usage()
17251726
" -V, --version output version information and exit\n\n"
17261727
);
17271728

1728-
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
1729-
1729+
fprintf(fout, "\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
17301730
}

tests/rigctld.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ struct handle_data
126126

127127

128128
void *handle_socket(void *arg);
129-
void usage(void);
129+
void usage(FILE *fout);
130130

131131

132132
#ifdef HAVE_PTHREAD
@@ -309,7 +309,7 @@ int main(int argc, char *argv[])
309309
switch (c)
310310
{
311311
case 'h':
312-
usage();
312+
usage(stdout);
313313
exit(0);
314314

315315
case 'V':
@@ -532,7 +532,7 @@ int main(int argc, char *argv[])
532532
break;
533533

534534
default:
535-
usage(); /* unknown option? */
535+
usage(stderr); /* unknown option? */
536536
exit(1);
537537
}
538538
}
@@ -1411,13 +1411,13 @@ void *handle_socket(void *arg)
14111411
}
14121412

14131413

1414-
void usage(void)
1414+
void usage(FILE *fout)
14151415
{
1416-
printf("Usage: rigctld [OPTION]...\n"
1416+
fprintf(fout, "Usage: rigctld [OPTION]...\n"
14171417
"Daemon serving COMMANDs to a connected radio transceiver or receiver.\n\n");
14181418

14191419

1420-
printf(
1420+
fprintf(fout,
14211421
" -m, --model=ID select radio model number. See model list (-l)\n"
14221422
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
14231423
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
@@ -1446,5 +1446,5 @@ void usage(void)
14461446
" -V, --version output version information and exit\n\n",
14471447
portno);
14481448

1449-
usage_rig(stdout);
1449+
usage_rig(fout);
14501450
}

tests/rigctlsync.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static struct option long_options[] =
105105
{0, 0, 0, 0}
106106
};
107107

108-
void usage();
108+
void usage(FILE *fout);
109109
static RIG *my_rig; /* handle to rig */
110110
static RIG
111111
*my_rig_sync; /* rig the gets synchronized -- freq only for now */
@@ -236,7 +236,7 @@ int main(int argc, char *argv[])
236236
switch (c)
237237
{
238238
case 'h':
239-
usage();
239+
usage(stdout);
240240
exit(0);
241241

242242
case 'V':
@@ -409,7 +409,7 @@ int main(int argc, char *argv[])
409409
break;
410410

411411
default:
412-
usage(); /* unknown option? */
412+
usage(stderr); /* unknown option? */
413413
exit(1);
414414
}
415415
}
@@ -420,7 +420,7 @@ int main(int argc, char *argv[])
420420

421421
if (argc < 3)
422422
{
423-
usage();
423+
usage(stderr);
424424
exit(1);
425425
}
426426

@@ -591,19 +591,20 @@ int main(int argc, char *argv[])
591591
return 0;
592592
}
593593

594-
void usage()
594+
void usage(FILE *fout)
595595
{
596596
const char *name = "rigctlsync";
597-
printf("Usage: %s -m rignumber -r comport -s baud -M rignumber -R comport [OPTIONS]...\n\n"
597+
598+
fprintf(fout, "Usage: %s -m rignumber -r comport -s baud -M rignumber -R comport [OPTIONS]...\n\n"
598599
"Will copy frequency from -m rig to -M rig\n"
599600
"e.g. will keep SDR# synchronized to a rig.\n\n",
600601
name);
601602

602-
printf("Example: Sync freq from rigctld to SDR#\n");
603-
printf("\t%s -m 2 -M 9 -R 127.0.0.1:4532\n\n", name);
604-
printf("See the %s.1 manual page for complete details.\n\n", name);
603+
fprintf(fout, "Example: Sync freq from rigctld to SDR#\n");
604+
fprintf(fout, "\t%s -m 2 -M 9 -R 127.0.0.1:4532\n\n", name);
605+
fprintf(fout, "See the %s.1 manual page for complete details.\n\n", name);
605606

606-
printf(
607+
fprintf(fout,
607608
" -m, --model=ID select radio model number. See model list (-l)\n"
608609
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
609610
" -R, --rig-file2=DEVICE set device of the virtual com port to operate on\n"
@@ -620,6 +621,5 @@ void usage()
620621
" -V, --version output version information and exit\n\n"
621622
);
622623

623-
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
624-
624+
fprintf(fout, "\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
625625
}

tests/rigctltcp.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct handle_data
130130

131131

132132
void *handle_socket(void *arg);
133-
void usage(void);
133+
void usage(FILE *fout);
134134

135135

136136
#ifdef HAVE_PTHREAD
@@ -310,7 +310,7 @@ int main(int argc, char *argv[])
310310
switch (c)
311311
{
312312
case 'h':
313-
usage();
313+
usage(stdout);
314314
exit(0);
315315

316316
case 'V':
@@ -534,7 +534,7 @@ int main(int argc, char *argv[])
534534
break;
535535

536536
default:
537-
usage(); /* unknown option? */
537+
usage(stderr); /* unknown option? */
538538
exit(1);
539539
}
540540
}
@@ -1413,13 +1413,12 @@ void *handle_socket(void *arg)
14131413
}
14141414

14151415

1416-
void usage(void)
1416+
void usage(FILE *fout)
14171417
{
1418-
printf("Usage: rigctltcp [OPTION]...\n"
1418+
fprintf(fout, "Usage: rigctltcp [OPTION]...\n"
14191419
"Daemon serving COMMANDs to a connected radio transceiver or receiver.\n\n");
14201420

1421-
1422-
printf(
1421+
fprintf(fout,
14231422
" -m, --model=ID select radio model number. See model list (-l)\n"
14241423
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
14251424
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
@@ -1449,5 +1448,5 @@ void usage(void)
14491448
" -V, --version output version information and exit\n\n",
14501449
portno);
14511450

1452-
usage_rig(stdout);
1451+
usage_rig(fout);
14531452
}

0 commit comments

Comments
 (0)