aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_opts.c13
-rw-r--r--src/c_unixize.c13
-rw-r--r--src/c_unixize.h7
-rw-r--r--src/u_utils.c96
-rw-r--r--src/u_utils.h3
5 files changed, 120 insertions, 12 deletions
diff --git a/src/c_opts.c b/src/c_opts.c
index 6b163c7..c4efa73 100644
--- a/src/c_opts.c
+++ b/src/c_opts.c
@@ -88,14 +88,13 @@ c_get_opts
const char* argv[])
{
int opt;
- bool_t confirm;
- opts->recursive = FALSE;
- opts->verbose = FALSE;
- opts->pretend = FALSE;
+ opts->confirm = FALSE;
opts->hidden = FALSE;
opts->hyphen = FALSE;
- confirm = FALSE;
+ opts->pretend = FALSE;
+ opts->recursive = FALSE;
+ opts->verbose = FALSE;
while ((opt = getopt(argc, (char *const *)argv, C_OPTS)) != -1) {
if (opt == 'a') {
opts->hidden = TRUE;
@@ -105,7 +104,7 @@ c_get_opts
exit(0);
}
else if (opt == 'i') {
- confirm = TRUE;
+ opts->confirm = TRUE;
}
else if (opt == 'n') {
opts->hyphen = TRUE;
@@ -133,7 +132,7 @@ c_get_opts
else if (argv[optind] == NULL) {
strncpy(opts->dir, ".", 2 * sizeof(char));
}
- if (confirm == TRUE) {
+ if (opts->confirm == TRUE) {
c_ask_confirm(opts->dir);
}
if (opts->pretend == TRUE) {
diff --git a/src/c_unixize.c b/src/c_unixize.c
index 5e92f71..bbf75f6 100644
--- a/src/c_unixize.c
+++ b/src/c_unixize.c
@@ -54,6 +54,7 @@
#include "c_lfiles.h"
#include "c_opts.h"
+#include "c_unixize.h"
#include "u_utils.h"
int
@@ -67,7 +68,7 @@ main
struct lfiles_s* og_files_head;
struct lfiles_s* new_files_head;
int nargc;
- char* nargv;
+ char** nargv;
c_get_opts(&opts, argc, argv);
if (chdir((const char*)opts.dir) == -1) {
@@ -97,8 +98,14 @@ main
u_dump_errno_path(og_files->filename);
}
else {
- /* rargc = u_get_rargv(&opts); */
- main(nargc, (const char**)nargv);
+ nargv = u_get_nargv(&opts);
+ if (nargv != NULL) {
+ nargc = 0;
+ while (argv[nargc] != NULL) {
+ nargc++;
+ }
+ main(nargc, (const char**)nargv);
+ }
chdir("../");
}
}
diff --git a/src/c_unixize.h b/src/c_unixize.h
index a43f887..965ff3f 100644
--- a/src/c_unixize.h
+++ b/src/c_unixize.h
@@ -48,12 +48,15 @@
#include <sys/param.h>
-typedef enum bool_e {
+typedef unsigned char bool_t;
+
+enum bool_e {
FALSE,
TRUE
-} bool_t;
+};
struct opts_s {
+ bool_t confirm;
bool_t hidden;
bool_t hyphen;
bool_t pretend;
diff --git a/src/u_utils.c b/src/u_utils.c
index cc7faeb..000cbca 100644
--- a/src/u_utils.c
+++ b/src/u_utils.c
@@ -49,6 +49,8 @@
#include <string.h>
#include <unistd.h>
+#include "c_unixize.h"
+
void
u_memdel(void** ptr)
{
@@ -76,3 +78,97 @@ u_dump_errno_path(const char path[])
strerror(errno)
);
}
+
+static char
+u_get_extra_args(char args[], struct opts_s* opts)
+{
+ char i;
+
+ i = 0;
+ args[0] = 0x00;
+ if (opts->hidden == TRUE) {
+ memcpy((char*)args + (i * 3), "-a:", 4 * sizeof(char));
+ i++;
+ }
+ if (opts->confirm == TRUE) {
+ memcpy((char*)args + (i * 3), "-i:", 4 * sizeof(char));
+ i++;
+ }
+ if (opts->hyphen == TRUE) {
+ memcpy((char*)args + (i * 3), "-n:", 4 * sizeof(char));
+ i++;
+ }
+ if (opts->pretend == TRUE) {
+ memcpy((char*)args + (i * 3), "-p:", 4 * sizeof(char));
+ i++;
+ }
+ if (opts->verbose == TRUE) {
+ memcpy((char*)args + (i * 3), "-v:", 4 * sizeof(char));
+ i++;
+ }
+ if (i > 0) {
+ *(args + ((i - 2) * 3) - 1) = 0x00;
+ }
+ return (i);
+}
+
+static void
+u_del_nargv(char** nargv)
+{
+ char** ptr;
+
+ ptr = nargv;
+ while (*ptr != NULL) {
+ ptr++;
+ }
+}
+
+char**
+u_get_nargv(struct opts_s* opts)
+{
+ short i;
+ char args[19];
+ char** nargv;
+ char* tok;
+
+ i = u_get_extra_args(args, opts) + 2;
+ nargv = (char**)malloc((i + 1) * sizeof(char*));
+ if (nargv == NULL) {
+ u_dump_errno();
+ return (NULL);
+ }
+ nargv[0] = strdup("unixize");
+ nargv[1] = NULL;
+ if (nargv[0] == NULL) {
+ u_memdel((void*)&nargv);
+ return (NULL);
+ }
+ nargv[1] = strdup("-R");
+ nargv[2] = NULL;
+ if (nargv[1] == NULL) {
+ u_memdel((void*)&nargv[0]);
+ u_memdel((void*)&nargv);
+ return (NULL);
+ }
+ if (i > 2) {
+ i = 2;
+ tok = strtok(args, ":");
+ nargv[i] = strdup(tok);
+ if (nargv[i] == NULL) {
+ u_del_nargv(nargv);
+ return (NULL);
+ }
+ nargv[i + 1] = NULL;
+ while ((tok = strtok(NULL, ":")) != NULL) {
+ nargv[i] = strdup(tok);
+ if (nargv[i] == NULL) {
+ u_del_nargv(nargv);
+ return (NULL);
+ }
+ nargv[i + 1] = NULL;
+ i++;
+ }
+ }
+ exit(0);
+ return (nargv);
+}
diff --git a/src/u_utils.h b/src/u_utils.h
index 63e5075..4c298d6 100644
--- a/src/u_utils.h
+++ b/src/u_utils.h
@@ -43,6 +43,9 @@
* 2020-11-05 19:28
*/
+#include "c_unixize.h"
+
void u_memdel(void**);
void u_dump_errno(void);
void u_dump_errno_path(const char[]);
+char** u_get_nargv(struct opts_s*);