-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
46 lines (35 loc) · 1.89 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <stdint.h>
#include "flag_parser.h"
int main(int argc, char *argv[]) {
int16_t threads;
int16_t optional_int;
int16_t array_size;
const char *Usage = "Usage: program_name [OPTIONS]\n\n"
"Description:\n"
" This program demonstrates flag parsing using the flag_parser library.\n\n"
"Options:\n"
"--threads NUM Number of threads to use (required, range: -32,768 to 32,767)\n"
"--optional_int [NUM] Optional integer value (default: 0, range: -32,768 to 32,767)\n"
"--array_size NUM Size of the array (required, range: -32,768 to 32,767)\n"
"--help Display this help message and exit\n\n"
"Usage Examples:\n"
" program_name -t 4 -a 100 # Run with 4 threads and array size 100\n"
" program_name --optional_int 42 # Run with optional integer set to 42\n"
" program_name -t 8 -a 256 -o 123 # Run with 8 threads, array size 256, and optional int 123\n";
// Define the flags
struct Flag flags[] = {
{"threads", required_argument, 't', &threads, INT16_T, "Number of threads"},
{"optional-int", optional_argument, 'o', &optional_int, INT16_T, "Optional int"},
{"array-size", required_argument, 'a', &array_size, INT16_T, "Size of the array"},
};
// Parse flags
parse_flags(argc, argv, flags, sizeof(flags) / sizeof(flags[0]), Usage);
// Print the flags
printf("threads = %d\n", threads);
printf("optional-int = %d\n", optional_int);
printf("array-size = %d\n", array_size);
return 0;
}