-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
48 lines (39 loc) · 891 Bytes
/
example.c
File metadata and controls
48 lines (39 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include "arglib.h"
// Argument processor function
void argparse(int argc, char *argv[]){
FORARGS {
// Positional argument
POSANY(ARGLAST, "filename", "Must be the last argument"){
printf("%s\n", ARGVAL);
ARGNEXT;
}
// Can run single line code after statement
// Built-in help menu
ARG ("--help", "Show this basic help menu")
HELP(argparse);
// Multi-line code execution
ARG ("--alt-test", "Another testing argument"){
printf ("test123\n");
printf ("test321\n");
puts(ARGVAL);
}
// ...
}
exit:
}
// Argument processor function
int main (int argc, char *argv[]) {
// If no args are given.
if (argc == 1){
/* When not inside a FORARGS loop,
* you can use ALTHELP. */
HELP(argparse);
return 1;
}
/* Pass the command line arguments into parser
* function. */
argparse(argc, argv);
// That's it!
return 0;
}