aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjozan <jozan@noemail.net>2020-11-05 20:16:00 +0000
committerjozan <jozan@noemail.net>2020-11-05 20:16:00 +0000
commit3c7eee6494a7452272ac1008f0d77c4230763549 (patch)
tree5225e0e56da6995c5f5ce96e2b94cb6aceb1cf63
parentNow getting directory files (diff)
downloadunixize-3c7eee6494a7452272ac1008f0d77c4230763549.tar.gz
unixize-3c7eee6494a7452272ac1008f0d77c4230763549.tar.bz2
unixize-3c7eee6494a7452272ac1008f0d77c4230763549.tar.xz
unixize-3c7eee6494a7452272ac1008f0d77c4230763549.tar.zst
unixize-3c7eee6494a7452272ac1008f0d77c4230763549.zip
Reading in progress
FossilOrigin-Name: c8e2947b1c632acc386ad416322affb951f4542b866a4b252b4cc5b0f41ee831
-rw-r--r--Makefile4
-rw-r--r--src/c_lfiles.c161
-rw-r--r--src/c_lfiles.h55
-rw-r--r--src/c_opts.c17
-rw-r--r--src/c_opts.h2
-rw-r--r--src/c_unixize.c25
-rw-r--r--src/c_unixize.h6
-rw-r--r--src/u_utils.c53
-rw-r--r--src/u_utils.h46
9 files changed, 350 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index 49dc8ac..07147e2 100644
--- a/Makefile
+++ b/Makefile
@@ -33,8 +33,10 @@ CFLAGS += -pedantic
RM = rm -rf
MKDIR = mkdir -p
-SRCS_NAME = c_unixize
+SRCS_NAME = c_lfiles
SRCS_NAME += c_opts
+SRCS_NAME += c_unixize
+SRCS_NAME += u_utils
SRCS = $(addprefix ${SRCS_DIR}, $(addsuffix .c, ${SRCS_NAME}))
INCS = $(addprefix ${SRCS_DIR}, $(addsuffix .h, ${SRCS_NAME}))
diff --git a/src/c_lfiles.c b/src/c_lfiles.c
new file mode 100644
index 0000000..af13a39
--- /dev/null
+++ b/src/c_lfiles.c
@@ -0,0 +1,161 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright © 2020 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * unixize: src/c_lfiles.c
+ * 2020-11-05 18:05
+ * Joe
+ *
+ * In this files are functions to handle the files linked list.
+ */
+
+#include <dirent.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "c_unixize.h"
+#include "u_utils.h"
+
+static void
+c_lfiles_add_back
+(struct lfiles_s** head,
+ struct lfiles_s* new)
+{
+ struct lfiles_s* tmp;
+
+ if (*head == NULL) {
+ *head = new;
+ return;
+ }
+ tmp = *head;
+ while (tmp->next != NULL) {
+ tmp = tmp->next;
+ }
+ tmp->next = new;
+}
+
+void
+c_lfiles_clear(struct lfiles_s** head)
+{
+ struct lfiles_s* renext;
+ struct lfiles_s* tmp;
+
+ if (head == NULL) {
+ return;
+ }
+ tmp = *head;
+ while (tmp != NULL) {
+ renext = tmp->next;
+ u_memdel((void*)&tmp->filename);
+ u_memdel((void*)&tmp);
+ tmp = renext;
+ }
+ *head = NULL;
+}
+
+static struct lfiles_s*
+c_lfiles_new
+(const char filename[],
+ unsigned char filetype)
+{
+ struct lfiles_s* link;
+
+ link = (struct lfiles_s*)malloc(sizeof(struct lfiles_s*));
+ if (link == NULL) {
+ return (NULL);
+ }
+ link->filename = strdup(filename);
+ link->filetype = filetype;
+ if (link->filename == NULL) {
+ u_memdel((void*)&link);
+ return (NULL);
+ }
+ link->next = NULL;
+ return (link);
+}
+
+/* struct lfiles_s* */
+/* c_lfiles_duplicate(struct lfiles_s** head) */
+/* { */
+/* struct lfiles_s* dup; */
+/* struct lfiles_s* origin; */
+/* */
+/* if (head == NULL) { */
+/* return (NULL); */
+/* } */
+/* } */
+
+struct lfiles_s*
+c_lfiles_gather(void)
+{
+ DIR* dirp;
+ struct dirent* dp;
+ struct lfiles_s* head;
+ struct lfiles_s* link;
+
+ head = NULL;
+ link = NULL;
+ dirp = opendir(".");
+ if (dirp == NULL) {
+ dprintf(
+ STDERR_FILENO,
+ "unixize: %s\n",
+ strerror(errno)
+ );
+ return (NULL);
+ }
+ while ((dp = readdir(dirp)) != NULL) {
+ link = c_lfiles_new(dp->d_name, dp->d_type);
+ if (link == NULL) {
+ dprintf(
+ STDERR_FILENO,
+ "unixize: %s\n",
+ strerror(errno)
+ );
+ c_lfiles_clear(&link);
+ return (NULL);
+ }
+ c_lfiles_add_back(&head, link);
+ }
+ closedir(dirp);
+ return (head);
+}
diff --git a/src/c_lfiles.h b/src/c_lfiles.h
new file mode 100644
index 0000000..d2a82c2
--- /dev/null
+++ b/src/c_lfiles.h
@@ -0,0 +1,55 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright © 2020 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * unixize: src/c_lfiles.h
+ * 2020-11-05 18:06
+ * Joe
+ */
+
+#ifndef __C_LFILES_H__
+#define __C_LFILES_H__
+
+#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_gather(void);
+
+#endif /* end of include guard: __C_LFILES_H__ */
diff --git a/src/c_opts.c b/src/c_opts.c
index 3884250..6b163c7 100644
--- a/src/c_opts.c
+++ b/src/c_opts.c
@@ -45,10 +45,10 @@
* This is where we handle command line options.
*/
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <stdio.h>
#include "c_opts.h"
#include "c_unixize.h"
@@ -56,9 +56,11 @@
static void
c_dump_usage(void)
{
- dprintf(STDERR_FILENO,
- C_USAGE_FMT,
- C_OPTS);
+ dprintf(
+ STDERR_FILENO,
+ C_USAGE_FMT,
+ C_OPTS
+ );
}
static void
@@ -80,9 +82,10 @@ c_ask_confirm(const char dir[])
}
void
-c_get_opts(struct opts_s* opts,
- int argc,
- const char* argv[])
+c_get_opts
+(struct opts_s* opts,
+ int argc,
+ const char* argv[])
{
int opt;
bool_t confirm;
diff --git a/src/c_opts.h b/src/c_opts.h
index 5cbe4c0..b2c76ce 100644
--- a/src/c_opts.h
+++ b/src/c_opts.h
@@ -51,6 +51,6 @@
#define C_OPTS "ahinpRv"
#define C_USAGE_FMT "usage: unixize [-%s] [directory]\n"
-void c_get_opts(struct opts_s*, int, const char*[]);
+void c_get_opts(struct opts_s*, int, const char*[]);
#endif /* ifndef __C_OPTS_H__ */
diff --git a/src/c_unixize.c b/src/c_unixize.c
index c78af26..9f4dbde 100644
--- a/src/c_unixize.c
+++ b/src/c_unixize.c
@@ -45,22 +45,29 @@
* This is the main function and entrypoint of the program.
*/
-#include "c_opts.h"
+#include <stdio.h>
+#include <stddef.h>
-void
-c_init(struct opts_s* opts)
-{
- (void)opts;
-}
+#include "c_lfiles.h"
+#include "c_opts.h"
int
-main(int argc,
- const char* argv[])
+main
+(int argc,
+ const char* argv[])
{
struct opts_s opts;
+ struct lfiles_s* files;
c_get_opts(&opts, argc, argv);
- c_init(&opts);
+ files = c_lfiles_gather();
+ if (files == NULL) {
+ return (1);
+ }
+ while (files != NULL) {
+ printf("'%s' - %hhu\n", files->filename, files->filetype);
+ files = files->next;
+ }
return (0);
}
diff --git a/src/c_unixize.h b/src/c_unixize.h
index 2583af2..edf9cde 100644
--- a/src/c_unixize.h
+++ b/src/c_unixize.h
@@ -66,6 +66,10 @@ struct opts_s {
char dir[PATH_MAX];
};
-void c_init(struct opts_s*);
+struct lfiles_s {
+ struct lfiles_s* next;
+ char* filename;
+ unsigned char filetype;
+};
#endif /* ifndef __C_UNIXIZE_H__ */
diff --git a/src/u_utils.c b/src/u_utils.c
new file mode 100644
index 0000000..cfaec25
--- /dev/null
+++ b/src/u_utils.c
@@ -0,0 +1,53 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright © 2020 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * unixize: src/u_utils.c
+ * Joe
+ * 2020-11-05 19:27
+ */
+
+#include <stdlib.h>
+
+void
+u_memdel(void** ptr)
+{
+ free(*ptr);
+ *ptr = NULL;
+}
diff --git a/src/u_utils.h b/src/u_utils.h
new file mode 100644
index 0000000..b95fa86
--- /dev/null
+++ b/src/u_utils.h
@@ -0,0 +1,46 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright © 2020 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * unixize: src/u_utils.h
+ * Joe
+ * 2020-11-05 19:28
+ */
+
+void u_memdel(void**);