|
1 /* |
|
2 * cline.c |
|
3 * |
|
4 * Created on: 23.05.2011 |
|
5 * Author: beckermi |
|
6 */ |
|
7 |
1 #include "cline.h" |
8 #include "cline.h" |
2 #include "functions.h" |
9 #include "scanner.h" |
3 |
10 #include "settings.h" |
4 suffix_list_t* new_suffix_list_t() { |
|
5 suffix_list_t* suffixList = malloc(sizeof(suffix_list_t*)); |
|
6 suffixList->count = 0; |
|
7 suffixList->items = NULL; |
|
8 } |
|
9 |
|
10 void destroy_suffix_list_t(suffix_list_t* list) { |
|
11 while (--list->count >= 0) { |
|
12 free(list->items[list->count]); |
|
13 } |
|
14 free(list); |
|
15 } |
|
16 |
|
17 void add_suffix(suffix_list_t* list, char* item) { |
|
18 char** reallocated_list = |
|
19 realloc(list->items, sizeof(char**) * list->count + 1); |
|
20 if (reallocated_list != NULL) { |
|
21 list->items = reallocated_list; |
|
22 list->items[list->count] = item; |
|
23 list->count++; |
|
24 } |
|
25 } |
|
26 |
|
27 settings_t* new_settings_t() { |
|
28 settings_t *settings = malloc(sizeof(settings_t*)); |
|
29 if (settings != NULL) { |
|
30 #ifdef _WIN32 |
|
31 settings->fileSeparator = '\\'; |
|
32 #else |
|
33 settings->fileSeparator = '/'; |
|
34 #endif /* _WIN32 */ |
|
35 settings->recursive = false; |
|
36 settings->includeSuffixes = false; |
|
37 settings->matchesOnly = false; |
|
38 settings->suffixList = new_suffix_list_t(); |
|
39 } |
|
40 |
|
41 return settings; |
|
42 } |
|
43 |
|
44 void destroy_settings_t(settings_t* settings) { |
|
45 destroy_suffix_list_t(settings->suffixList); |
|
46 free(settings); |
|
47 } |
|
48 |
11 |
49 void printHelpText(const char* prgName) { |
12 void printHelpText(const char* prgName) { |
50 // Help text |
13 // Help text |
51 const char* helpText = |
14 const char* helpText = |
52 "\nUsage:" |
15 "\nUsage:" |
130 } |
93 } |
131 suffix = argv[t]; |
94 suffix = argv[t]; |
132 } |
95 } |
133 // h |
96 // h |
134 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { |
97 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { |
135 if (registerArgument(&checked, 1)) { |
98 return exit_with_help(prgName, settings, 1); |
136 return exit_with_help(prgName, settings, 1); |
|
137 } |
|
138 showHelp = true; |
|
139 } |
99 } |
140 // r, R |
100 // r, R |
141 if ((argflags & 24) > 0) { |
101 if ((argflags & 24) > 0) { |
142 if (registerArgument(&checked, 24)) { |
102 if (registerArgument(&checked, 24)) { |
143 return exit_with_help(prgName, settings, 1); |
103 return exit_with_help(prgName, settings, 1); |
156 if (registerArgument(&checked, 1024)) { |
116 if (registerArgument(&checked, 1024)) { |
157 return exit_with_help(prgName, settings, 1); |
117 return exit_with_help(prgName, settings, 1); |
158 } |
118 } |
159 directory = argv[t]; |
119 directory = argv[t]; |
160 } |
120 } |
161 } |
|
162 |
|
163 // Show help and quit |
|
164 if (showHelp) { |
|
165 return exit_with_help(prgName, settings, 0); |
|
166 } |
121 } |
167 |
122 |
168 // Find tokens |
123 // Find tokens |
169 char* finder = strtok(suffix, ","); |
124 char* finder = strtok(suffix, ","); |
170 while (finder != NULL) { |
125 while (finder != NULL) { |