|
9 | 9 | #include "nmly.h" |
10 | 10 | #include "helper.h" |
11 | 11 |
|
12 | | -#define BEFORE 0 |
13 | | -#define AFTER 1 |
14 | | -#define REPLACE 2 |
15 | | -#define UPPER 3 |
16 | | -#define LOWER 4 |
17 | | -#define SWITCH 5 |
18 | | -#define REVERSE 6 |
19 | | -#define REMOVE 7 |
20 | | - |
21 | 12 | const char *preview_msg = "\n%i File(s) to be modified in %i folder(s)"; |
22 | 13 | const char *success_msg = "\n%i File(s) modified in %i folder(s)"; |
23 | 14 | const char *dir_error_msg = "Cannot open directory %s\n"; |
| 15 | +const char *dir_confirm_msg = "Apply the changes in the following directory '%s'? [Y/n] "; |
24 | 16 | const char *compare_msg = "%s > %s \n"; |
25 | 17 | const char *time_msg = "\n%f Segs\n"; |
26 | 18 | const char *arg_error_msg = "Error: Invalid command\n"; |
27 | | -const char *version_msg = "Nmly v0.9.4\n"; |
| 19 | +const char *version_msg = "Nmly v0.9.5\n"; |
28 | 20 | char *working_path = "."; |
29 | 21 | char *filter = ""; |
30 | 22 | int files_n = 0, folders_n = 0; |
@@ -56,7 +48,7 @@ char *getChanges(char *path, char *argv[]) |
56 | 48 | { |
57 | 49 | char *dir = strBefore(path, '/'); |
58 | 50 | char *filename = strAfter(path, '/'); |
59 | | - char *new_path = path; |
| 51 | + char *new_path = NULL; |
60 | 52 |
|
61 | 53 | //Matches filter by extension |
62 | 54 | char *extension = strAfter(filename, '.'); |
@@ -93,7 +85,7 @@ char *getChanges(char *path, char *argv[]) |
93 | 85 | void listDir(char *basedir, char *argv[]) |
94 | 86 | { |
95 | 87 | DIR *dir; |
96 | | - char b[512]; |
| 88 | + char b[BUFFER]; |
97 | 89 | struct dirent *ent; |
98 | 90 |
|
99 | 91 | if ((dir = opendir(basedir)) == NULL) { |
@@ -135,6 +127,8 @@ void processFile(char *entpath, char *argv[]) |
135 | 127 | char *new_path = getChanges(entpath, argv); |
136 | 128 |
|
137 | 129 | if (new_path == NULL) { |
| 130 | + free(new_path); |
| 131 | + |
138 | 132 | return; |
139 | 133 | } |
140 | 134 |
|
@@ -274,11 +268,23 @@ int main(int argc, char *argv[]) |
274 | 268 |
|
275 | 269 | float start_time = (float) clock() / CLOCKS_PER_SEC; |
276 | 270 |
|
| 271 | + //Confirmation |
| 272 | + if (!preview) { |
| 273 | + char confirm; |
| 274 | + |
| 275 | + printf(dir_confirm_msg, working_path); |
| 276 | + scanf("%c", &confirm); |
| 277 | + |
| 278 | + if (confirm != 'Y' && confirm != 'y') { |
| 279 | + return 0; |
| 280 | + } |
| 281 | + } |
| 282 | + |
277 | 283 | listDir(working_path, argv); |
278 | 284 |
|
279 | 285 | float total_time = ((float) clock() / CLOCKS_PER_SEC) - start_time; |
280 | 286 |
|
281 | | - const char *msg = (preview == 1) ? preview_msg : success_msg; |
| 287 | + const char *msg = (preview) ? preview_msg : success_msg; |
282 | 288 | printf(msg, files_n, folders_n); |
283 | 289 | printf(time_msg, total_time); |
284 | 290 |
|
|
0 commit comments