Automatically generate a man page

Add --help and --version for help2man.
pull/122/head
Daniele Forsi 2021-12-20 18:57:44 +01:00
rodzic 692a64efad
commit 5790d02ceb
4 zmienionych plików z 33 dodań i 8 usunięć

1
.gitignore vendored
Wyświetl plik

@ -1,3 +1,4 @@
*.1
*.o
*.a
*.iq

Wyświetl plik

@ -8,7 +8,7 @@ LIBS = -lusb-1.0 -lrtlsdr -lpthread -lfftw3f -lcurl -lm
OBJS = rtlsdr_wsprd.o wsprd/wsprd.o wsprd/wsprsim_utils.o wsprd/wsprd_utils.o wsprd/tab.o wsprd/fano.o wsprd/nhash.o
TARGETS = rtlsdr_wsprd
TARGETS = rtlsdr_wsprd rtlsdr_wsprd.1
.PHONY: all clean
@ -25,3 +25,6 @@ clean:
install:
install rtlsdr_wsprd /usr/local/bin/rtlsdr_wsprd
%.1: %.c | %
-help2man --no-info --output=$@ ./$|

Wyświetl plik

@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <getopt.h>
#include <math.h>
#include <string.h>
#include <sys/time.h>
@ -746,8 +747,8 @@ int32_t decoderSelfTest() {
}
void usage(void) {
fprintf(stderr,
void usage(FILE *stream, int32_t status) {
fprintf(stream,
"rtlsdr_wsprd, a simple WSPR daemon for RTL receivers\n\n"
"Use:\trtlsdr_wsprd -f frequency -c callsign -l locator [options]\n"
"\t-f dial frequency [(,k,M) Hz] or band string\n"
@ -773,14 +774,24 @@ void usage(void) {
"\t-w write received signal and exit [filename prefix]\n"
"\t-r read signal with .iq or .c2 format, decode and exit [filename]\n"
"\t (raw format: 375sps, float 32 bits, 2 channels)\n"
"Other options:\n"
"\t--help show list of options\n"
"\t--version show version of program\n"
"Example:\n"
"\trtlsdr_wsprd -f 2m -c A1XYZ -l AB12cd -g 29 -o -4200\n");
exit(1);
exit(status);
}
int main(int argc, char **argv) {
uint32_t opt;
char *short_options = "f:c:l:g:ao:p:u:d:n:i:tw:r:HQS";
int32_t option_index = 0;
struct option long_options[] = {
{"help", no_argument, 0, 0 },
{"version", no_argument, 0, 0 },
{0, 0, 0, 0 }
};
int32_t rtl_result;
int32_t rtl_count;
@ -794,10 +805,20 @@ int main(int argc, char **argv) {
uint32_t nLoop = 0;
if (argc <= 1)
usage();
usage(stderr, 1);
while ((opt = getopt(argc, argv, "f:c:l:g:ao:p:u:d:n:i:tw:r:HQS")) != -1) {
while ((opt = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) {
switch (opt) {
case 0:
switch (option_index) {
case 0: // --help
usage(stdout, 0);
break;
case 1: // --version
printf("rtlsdr_wsprd 0.5.3\n");
exit(0);
break;
}
case 'f': // Frequency
if (!strcasecmp(optarg, "LF")) {
rx_options.dialfreq = 136000;
@ -919,7 +940,7 @@ int main(int argc, char **argv) {
rx_options.filename = optarg;
break;
default:
usage();
usage(stderr, 1);
break;
}
}

Wyświetl plik

@ -46,4 +46,4 @@ int32_t readC2file(float *iSamples, float *qSamples, char *filename);
void decodeRecordedFile(char *filename);
float whiteGaussianNoise(float factor);
int32_t decoderSelfTest();
void usage(void);
void usage(FILE *stream, int32_t status);