diff options
author | jozan <jozan@noemail.net> | 2020-11-05 23:41:43 +0000 |
---|---|---|
committer | jozan <jozan@noemail.net> | 2020-11-05 23:41:43 +0000 |
commit | a92830d0ad7eaf08e78bc1d2ad7ded8b06eaf1e8 (patch) | |
tree | f26bc4aa0dac67ed1513a90817f021de5b291fff | |
parent | Improvement, skipping "." and ".." (diff) | |
download | unixize-a92830d0ad7eaf08e78bc1d2ad7ded8b06eaf1e8.tar.gz unixize-a92830d0ad7eaf08e78bc1d2ad7ded8b06eaf1e8.tar.bz2 unixize-a92830d0ad7eaf08e78bc1d2ad7ded8b06eaf1e8.tar.xz unixize-a92830d0ad7eaf08e78bc1d2ad7ded8b06eaf1e8.tar.zst unixize-a92830d0ad7eaf08e78bc1d2ad7ded8b06eaf1e8.zip |
Duplicate done, trying to go recursive
FossilOrigin-Name: 7edc4e006cb1ee4e1baf5bc2f0d01524e5cd37ae3d2a046e9581d47475fa92aa
-rw-r--r-- | src/c_lfiles.c | 19 | ||||
-rw-r--r-- | src/c_lfiles.h | 2 | ||||
-rw-r--r-- | src/c_unixize.c | 51 | ||||
-rw-r--r-- | src/u_utils.c | 11 | ||||
-rw-r--r-- | src/u_utils.h | 1 |
5 files changed, 72 insertions, 12 deletions
diff --git a/src/c_lfiles.c b/src/c_lfiles.c index 53f8ad3..36976b6 100644 --- a/src/c_lfiles.c +++ b/src/c_lfiles.c @@ -122,10 +122,20 @@ c_lfiles_duplicate(struct lfiles_s** head) struct lfiles_s* dup_link; struct lfiles_s* origin; - if (*head == NULL) { + dup_head = NULL; + if (head == NULL) { return (NULL); } origin = *head; + while (origin != NULL) { + dup_link = c_lfiles_new(origin->filename, origin->filetype); + if (dup_link == NULL) { + u_dump_errno(); + return (NULL); + } + origin = origin->next; + c_lfiles_add_back(&dup_head, dup_link); + } return (dup_head); } @@ -136,15 +146,10 @@ c_lfiles_gather(void) struct dirent* dp; struct lfiles_s* head; struct lfiles_s* link; - char path[MAXPATHLEN]; head = NULL; link = NULL; - if (getcwd(path, MAXPATHLEN) == NULL) { - u_dump_errno(); - return (NULL); - } - dirp = opendir(path); + dirp = opendir("."); if (dirp == NULL) { u_dump_errno(); return (NULL); diff --git a/src/c_lfiles.h b/src/c_lfiles.h index d2a82c2..039dbaa 100644 --- a/src/c_lfiles.h +++ b/src/c_lfiles.h @@ -49,7 +49,7 @@ #include "c_unixize.h" void c_lfiles_clear(struct lfiles_s**); -/* struct lfiles_s* c_lfiles_duplicate(struct lfiles_s*); */ +struct lfiles_s* c_lfiles_duplicate(struct lfiles_s**); struct lfiles_s* c_lfiles_gather(void); #endif /* end of include guard: __C_LFILES_H__ */ diff --git a/src/c_unixize.c b/src/c_unixize.c index 078423a..23f29d9 100644 --- a/src/c_unixize.c +++ b/src/c_unixize.c @@ -45,6 +45,7 @@ * This is the main function and entrypoint of the program. */ +#include <dirent.h> #include <errno.h> #include <stdio.h> #include <stddef.h> @@ -63,19 +64,60 @@ main struct opts_s opts; struct lfiles_s* og_files; struct lfiles_s* new_files; + struct lfiles_s* og_files_head; + struct lfiles_s* new_files_head; + char rargv[8][3]; + char i; c_get_opts(&opts, argc, argv); if (chdir((const char*)opts.dir) == -1) { - u_dump_errno(); + u_dump_errno_path(opts.dir); return (1); } og_files = c_lfiles_gather(); - new_files = c_lfiles_duplicate(og_files); if (og_files == NULL) { + return (0); + } + new_files = c_lfiles_duplicate(&og_files); + if (og_files == NULL) { + c_lfiles_clear(&og_files); return (1); } - c_lfiles_clear(&og_files); - c_lfiles_clear(&new_files); + /* c_subst(&opts, og_files); */ + og_files_head = og_files; + new_files_head = new_files; + while (og_files != NULL && new_files != NULL) { + if (opts.hidden == FALSE && og_files->filename[0] == '.') { + og_files = og_files->next; + new_files = new_files->next; + continue; + } + printf("'%s' -> '%s'\n", og_files->filename, new_files->filename); + if (opts.recursive == TRUE && og_files->filetype == DT_DIR) { + if (chdir((const char*)og_files->filename) == -1) { + u_dump_errno_path(og_files->filename); + } + else { + i = 1; + strlcpy(rargv[0], "-R", 3 * sizeof(char)); + if (opts.hidden == TRUE) { + strlcpy(rargv[i], "-a", 3 * sizeof(char)); + i++; + } + if (opts.hyphen == TRUE) { + strlcpy(rargv[i], "-n", 3 * sizeof(char)); + i++; + } + main(); + chdir("../"); + } + } + /* rename(); */ + og_files = og_files->next; + new_files = new_files->next; + } + c_lfiles_clear(&og_files_head); + c_lfiles_clear(&new_files_head); return (0); } @@ -83,4 +125,5 @@ main * Files prefixes index * -------------------- * c_ -> core program related + * u_ -> utils related */ diff --git a/src/u_utils.c b/src/u_utils.c index 13cb245..cc7faeb 100644 --- a/src/u_utils.c +++ b/src/u_utils.c @@ -65,3 +65,14 @@ u_dump_errno(void) strerror(errno) ); } + +void +u_dump_errno_path(const char path[]) +{ + dprintf( + STDERR_FILENO, + "unixize: %s: %s\n", + path, + strerror(errno) + ); +} diff --git a/src/u_utils.h b/src/u_utils.h index a4568a8..63e5075 100644 --- a/src/u_utils.h +++ b/src/u_utils.h @@ -45,3 +45,4 @@ void u_memdel(void**); void u_dump_errno(void); +void u_dump_errno_path(const char[]); |