-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddcArgs.h
72 lines (66 loc) · 1.51 KB
/
ddcArgs.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef __ddcArguments__
#define __ddcArguments__
typedef char bool;
typedef struct pArgs pArgs;
pArgs init_pArgs(int _argc, char** _argv);
bool pArgs_has(const pArgs args, const char* cstr);
char* pArgs_get(const pArgs args, int index);
int pArgs_get_index(const pArgs args, const char* cstr);
char* pArgs_get_value(const pArgs args, const char* cstr);
struct pArgs
{
int argc;
char** argv;
};
pArgs init_pArgs(int _argc, char** _argv)
{
pArgs output;
output.argc = _argc;
output.argv = _argv;
return output;
}
char* pArgs_get_value(const pArgs args, const char* cstr)
{
int index = pArgs_get_index(args, cstr);
return (index != -1) ? args.argv[index+1] : (char*)0;
}
char* pArgs_get(const pArgs args, int index)
{
return (index >= 0 && index < args.argc) ? args.argv[index] : (char*)0;
}
int pArgs_get_index(const pArgs args, const char* cstr)
{
for (int i = 0; i < args.argc; i++)
{
int indx = 0;
while (args.argv[i][indx] == cstr[indx])
{
if ((args.argv[i][indx] == 0) || (cstr[indx] == 0))
{
if ((args.argv[i][indx] == 0) && (cstr[indx] == 0)) return i;
else goto DDCARGS_CONTINUE_INDEX_LOOP;
}
indx++;
}
DDCARGS_CONTINUE_INDEX_LOOP:;
}
return -1;
}
bool pArgs_has(const pArgs args, const char* cstr)
{
for (int i = 0; i < args.argc; i++)
{
int indx = 0;
while (args.argv[i][indx] == cstr[indx])
{
if ((args.argv[i][indx] == 0) || (cstr[indx] == 0))
{
if ((args.argv[i][indx] == 0) && (cstr[indx] == 0)) return 1;
else return 0;
}
indx++;
}
}
return 0;
}
#endif