-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.h
55 lines (46 loc) · 1 KB
/
options.h
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
49
50
51
52
53
54
55
#ifndef OPTIONSH
#define OPTIONSH
#include <stdio.h>
#include <string.h>
#include "usage.h"
typedef struct globalArgs_t {
char* file;
int num;
char* delimiter; // TODO: Useful option
// int overwrite; // TODO: Useful option
// char* table_name; // TODO: Useful option
} globalArgs;
globalArgs getOpts(int argc, char** argv) {
#ifdef DEBUG
printf("Inside getOpts - Argc [%d].\n", argc);
#endif
int i;
globalArgs result;
result.file = NULL;
result.num = 0;
result.delimiter = NULL;
// result.table_name = NULL
// result.overwrite = 1;
// NOTE: Incrementing i by 2 as all flags take a param
for(i = 0; i < argc; i++) {
#ifdef DEBUG
printf("Inside getOpts - Arg %d - [%s].\n", i, argv[i]);
#endif
if(0 == strcmp("-f", argv[i])) {
result.file = argv[i+1];
result.num += 2;
i++;
} else
if(0 == strcmp("-d", argv[i])) {
result.delimiter = argv[i+1];
result.num += 2;
i++;
} else
if(0 == strcmp("-h",argv[i])) {
usage();
exit(1);
}
}
return result;
}
#endif