Skip to content

Commit be4e82c

Browse files
author
Roger Shimizu
committed
Add -h/--help support to ks and ramdump
help2man is the tool to generate manpages from command line directly. Command qdl confirmed to be working well with help2man already. Adding --help to make help2man works for both ks.c and ramdump tool as well. Signed-off-by: Roger Shimizu <[email protected]>
1 parent ccc1b68 commit be4e82c

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

ks.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ int qdl_write(struct qdl_device *qdl, const void *buf, size_t len)
3434
return write(qdl->fd, buf, len);
3535
}
3636

37-
static void print_usage(void)
37+
static void print_usage(FILE *out)
3838
{
3939
extern const char *__progname;
4040

41-
fprintf(stderr,
41+
fprintf(out,
4242
"%s -p <sahara dev_node> -s <id:file path> ...\n",
4343
__progname);
44-
fprintf(stderr,
44+
fprintf(out,
45+
" -h --help Print this usage info\n"
4546
" -p --port Sahara device node to use\n"
4647
" -s <id:file path> --sahara <id:file path> Sahara protocol file mapping\n"
4748
"\n"
@@ -62,13 +63,14 @@ int main(int argc, char **argv)
6263

6364
static struct option options[] = {
6465
{"debug", no_argument, 0, 'd'},
66+
{"help", no_argument, 0, 'h'},
6567
{"version", no_argument, 0, 'v'},
6668
{"port", required_argument, 0, 'p'},
6769
{"sahara", required_argument, 0, 's'},
6870
{0, 0, 0, 0}
6971
};
7072

71-
while ((opt = getopt_long(argc, argv, "dvp:s:", options, NULL)) != -1) {
73+
while ((opt = getopt_long(argc, argv, "dvp:s:h", options, NULL)) != -1) {
7274
switch (opt) {
7375
case 'd':
7476
qdl_debug = true;
@@ -84,7 +86,7 @@ int main(int argc, char **argv)
8486
found_mapping = true;
8587
file_id = strtol(optarg, NULL, 10);
8688
if (file_id < 0) {
87-
print_usage();
89+
print_usage(stderr);
8890
return 1;
8991
}
9092
if (file_id >= MAPPING_SZ) {
@@ -96,21 +98,24 @@ int main(int argc, char **argv)
9698
}
9799
colon = strchr(optarg, ':');
98100
if (!colon) {
99-
print_usage();
101+
print_usage(stderr);
100102
return 1;
101103
}
102104
qdl.mappings[file_id] = &optarg[colon - optarg + 1];
103105
printf("Created mapping ID:%ld File:%s\n", file_id, qdl.mappings[file_id]);
104106
break;
107+
case 'h':
108+
print_usage(stdout);
109+
return 0;
105110
default:
106-
print_usage();
111+
print_usage(stderr);
107112
return 1;
108113
}
109114
}
110115

111116
// -p and -s is required
112117
if (!dev_node || !found_mapping) {
113-
print_usage();
118+
print_usage(stderr);
114119
return 1;
115120
}
116121

ramdump.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ const char *__progname = "ramdump";
1212

1313
bool qdl_debug;
1414

15-
static void print_usage(void)
15+
static void print_usage(FILE *out)
1616
{
1717
extern const char *__progname;
1818

19-
fprintf(stderr,
19+
fprintf(out,
2020
"%s [--debug] [-o <ramdump-path>] [segment-filter,...]\n",
2121
__progname);
22-
exit(1);
2322
}
2423

2524
int main(int argc, char **argv)
@@ -41,10 +40,11 @@ int main(int argc, char **argv)
4140
{"version", no_argument, 0, 'v'},
4241
{"output", required_argument, 0, 'o'},
4342
{"serial", required_argument, 0, 'S'},
43+
{"help", no_argument, 0, 'h'},
4444
{0, 0, 0, 0}
4545
};
4646

47-
while ((opt = getopt_long(argc, argv, "dvo:S:", options, NULL)) != -1) {
47+
while ((opt = getopt_long(argc, argv, "dvo:S:h", options, NULL)) != -1) {
4848
switch (opt) {
4949
case 'd':
5050
qdl_debug = true;
@@ -59,16 +59,22 @@ int main(int argc, char **argv)
5959
case 'S':
6060
serial = optarg;
6161
break;
62+
case 'h':
63+
print_usage(stdout);
64+
return 0;
6265
default:
63-
print_usage();
66+
print_usage(stderr);
67+
return 1;
6468
}
6569
}
6670

6771
if (optind < argc)
6872
filter = argv[optind++];
6973

70-
if (optind != argc)
71-
print_usage();
74+
if (optind != argc) {
75+
print_usage(stderr);
76+
return 1;
77+
}
7278

7379
if (qdl_debug)
7480
print_version();

0 commit comments

Comments
 (0)