|
diff --git a/main.c b/main.c
|
| 1 |
#include <stdio.h> |
1 |
#include <stdio.h> |
|
|
2 |
#include <stdlib.h> |
|
|
3 |
#include <stdarg.h> |
|
|
4 |
#include <getopt.h> |
|
|
5 |
|
|
|
6 |
void help(const char *argv0) { |
|
|
7 |
printf("Usage: %s [options]\n" |
|
|
8 |
"\nAvailable options:\n" |
|
|
9 |
" -h,--help this help\n" |
|
|
10 |
" -v,--version show version\n" |
|
|
11 |
" -p,--port=client:port device port\n", |
|
|
12 |
argv0); |
|
|
13 |
} |
| 2 |
|
14 |
|
| 3 |
int main(int argc, char *argv[]) { |
15 |
int main(int argc, char *argv[]) { |
| 4 |
fprintf(stdout, "Oh, hi Mark!\n"); |
16 |
const char short_options[] = "hvlp"; |
|
|
17 |
const struct option long_options[] = { |
|
|
18 |
{"help", 0, NULL, 'h'}, |
|
|
19 |
{"version", 0, NULL, 'v'}, |
|
|
20 |
{"list", 0, NULL, 'l'}, |
|
|
21 |
{"port", 1, NULL, 'p'}, |
|
|
22 |
{0}, |
|
|
23 |
}; |
|
|
24 |
|
|
|
25 |
int c; |
|
|
26 |
while ((c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) { |
|
|
27 |
switch (c) { |
|
|
28 |
case 'h': |
|
|
29 |
help(argv[0]); |
|
|
30 |
return 0; |
|
|
31 |
case 'v': |
|
|
32 |
fprintf(stdout, "Version\n"); |
|
|
33 |
return 0; |
|
|
34 |
case 'l': |
|
|
35 |
fprintf(stdout, "List\n"); |
|
|
36 |
return 0; |
|
|
37 |
case 'p': |
|
|
38 |
fprintf(stdout, "Port\n"); |
|
|
39 |
return 0; |
|
|
40 |
default: |
|
|
41 |
fprintf(stdout, "No option provided\n"); |
|
|
42 |
return 0; |
|
|
43 |
} |
|
|
44 |
} |
|
|
45 |
|
| 5 |
return 0; |
46 |
return 0; |
| 6 |
} |
47 |
} |
| 7 |
|
48 |
|