aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjozan <jozan@noemail.net>2020-11-08 00:27:27 +0000
committerjozan <jozan@noemail.net>2020-11-08 00:27:27 +0000
commit538efe3fc1e62a231fa10cd3071c2c7a69c7d281 (patch)
treea7ed803d4becaeea6a84b36def84952a9601e4da
parentMerging branch 'go-full-stack' into 'trunk' (diff)
downloadunixize-538efe3fc1e62a231fa10cd3071c2c7a69c7d281.tar.gz
unixize-538efe3fc1e62a231fa10cd3071c2c7a69c7d281.tar.bz2
unixize-538efe3fc1e62a231fa10cd3071c2c7a69c7d281.tar.xz
unixize-538efe3fc1e62a231fa10cd3071c2c7a69c7d281.tar.zst
unixize-538efe3fc1e62a231fa10cd3071c2c7a69c7d281.zip
Added relative path nice
FossilOrigin-Name: 9cca594d1c68d5b68ea84412f2d2809e337d6b9cd1d0b0ef034feec55a8c2ae0
-rw-r--r--src/c_unixize.c21
-rw-r--r--src/u_utils.c38
-rw-r--r--src/u_utils.h2
3 files changed, 58 insertions, 3 deletions
diff --git a/src/c_unixize.c b/src/c_unixize.c
index e08141b..15bfccf 100644
--- a/src/c_unixize.c
+++ b/src/c_unixize.c
@@ -71,7 +71,7 @@ main
struct opts_s opts;
int nargc;
char** nargv;
- /* static char subpath[MAXPATHLEN]; */
+ static char subpath[MAXPATHLEN] = "";
if (c_get_opts(&opts, argc, argv) == FALSE) {
return (0);
@@ -80,6 +80,15 @@ main
u_dump_errno_path(opts.dir);
return (1);
}
+ if (
+ argv[0][0] != 'r' &&
+ strlen(opts.dir) > 1 &&
+ strncmp(opts.dir, ".", 2 * sizeof(char)) != 0
+ ) {
+ strlcpy(subpath, opts.dir, MAXPATHLEN - 1);
+ subpath[strlen(subpath) + 1] = 0x00;
+ subpath[strlen(subpath)] = '/';
+ }
og_files = c_lfiles_gather();
if (og_files == NULL) {
return (0);
@@ -103,6 +112,7 @@ main
u_dump_errno_path(og_files->filename);
}
else {
+ u_increase_subpath(subpath, og_files->filename);
nargv = u_get_nargv(&opts);
if (nargv != NULL) {
nargc = 0;
@@ -113,17 +123,22 @@ main
u_del_nargv(nargv);
}
chdir("../");
+ u_decrease_subpath(subpath);
}
}
if (opts.verbose == TRUE) {
dprintf(
STDOUT_FILENO,
- "'%s' -> '%s'\n",
+ "'%s%s' -> '%s%s'\n",
+ subpath,
og_files->filename,
+ subpath,
new_files->filename
);
}
- /* rename(); */
+ if (opts.pretend == FALSE) {
+ /* rename(); */
+ }
og_files = og_files->next;
new_files = new_files->next;
}
diff --git a/src/u_utils.c b/src/u_utils.c
index e352eb6..65b59a3 100644
--- a/src/u_utils.c
+++ b/src/u_utils.c
@@ -43,6 +43,8 @@
* 2020-11-05 19:27
*/
+#include <sys/param.h>
+
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -177,3 +179,39 @@ u_get_nargv(struct opts_s* opts)
}
return (nargv);
}
+
+void
+u_increase_subpath
+(char subp[],
+ const char newp[])
+{
+ strlcpy(
+ subp + strlen(subp),
+ newp,
+ MAXPATHLEN - strlen(subp) - 1
+ );
+ subp[strlen(subp) + 1] = 0x00;
+ subp[strlen(subp)] = '/';
+}
+
+void
+u_decrease_subpath(char subp[])
+{
+ char* p;
+
+ p = subp;
+ p += strlen(subp);
+ if (p == 0) {
+ return;
+ }
+ p -= 2;
+ while (subp - p != 0 && *p != '/') {
+ p--;
+ }
+ if (*p == '/') {
+ *(p + 1) = 0x00;
+ }
+ else if (subp - p == 0) {
+ *p = 0x00;
+ }
+}
diff --git a/src/u_utils.h b/src/u_utils.h
index 5ea7534..f1e0571 100644
--- a/src/u_utils.h
+++ b/src/u_utils.h
@@ -50,3 +50,5 @@ void u_dump_errno(void);
void u_dump_errno_path(const char[]);
void u_del_nargv(char** nargv);
char** u_get_nargv(struct opts_s*);
+void u_increase_subpath(char[], const char[]);
+void u_decrease_subpath(char[]);