cline.c

changeset 4
c3acfb3b4957
parent 3
510d6b198dde
child 5
9393eff3d2f9
equal deleted inserted replaced
3:510d6b198dde 4:c3acfb3b4957
10 #endif /* _WIN32 */ 10 #endif /* _WIN32 */
11 settings->suffixc = 1; 11 settings->suffixc = 1;
12 settings->recursive = false; 12 settings->recursive = false;
13 settings->includeSuffixes = false; 13 settings->includeSuffixes = false;
14 settings->matchesOnly = false; 14 settings->matchesOnly = false;
15
16 return settings;
17 }
18
19 void destroy_settings_t(settings_t* settings) {
20 if (settings->suffixv != NULL) {
21 free(settings->suffixv);
22 }
23 free(settings);
15 } 24 }
16 25
17 void printHelpText(const char* prgName) { 26 void printHelpText(const char* prgName) {
18 // Help text 27 // Help text
19 const char* helpText = 28 const char* helpText =
175 184
176 // Open directory 185 // Open directory
177 DIR *dir = opendir(directory); 186 DIR *dir = opendir(directory);
178 if (dir == NULL) { 187 if (dir == NULL) {
179 perror("Operation failed"); 188 perror("Operation failed");
180 free(settings->suffixv); 189 destroy_settings_t(settings);
181 free(settings);
182 return 1; 190 return 1;
183 } 191 }
184 192
185 // Scan directory 193 // Scan directory
186 int lines = scanDirectory(dir, 0, directory, settings); 194 int lines = scanDirectory(dir, 0, directory, settings);
195 closedir(dir);
187 196
188 // Print double line and line count 197 // Print double line and line count
189 #ifdef _WIN32 198 #ifdef _WIN32
190 const int columns = 79; 199 const int columns = 79;
191 #else 200 #else
199 printf("\n%73d lines\n", lines); 208 printf("\n%73d lines\n", lines);
200 #else 209 #else
201 printf("\n%74d lines\n", lines); 210 printf("\n%74d lines\n", lines);
202 #endif /* _WIN32 */ 211 #endif /* _WIN32 */
203 212
204 closedir(dir); 213 destroy_settings_t(settings);
205 free(settings->suffixv);
206 free(settings);
207 return 0; 214 return 0;
208 } 215 }

mercurial