From 9dabdcfbfd0d503948a251f83346f58a677e2a3c Mon Sep 17 00:00:00 2001 From: Guillem George Date: Fri, 24 Oct 2025 23:16:13 +0200 Subject: [PATCH] ' --- .gitignore | 9 ++++++++- micromake/src/Microfile | 3 +++ minimake/Makefile | 3 +++ minimake/minimake.c | 31 +++++++++++++++++++++++++++++++ simple_ls/simple_ls.c | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 micromake/src/Microfile create mode 100644 minimake/Makefile create mode 100644 minimake/minimake.c create mode 100644 simple_ls/simple_ls.c diff --git a/.gitignore b/.gitignore index d7756c2..1801c29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ -a.out +*.out +*~ +*.swp *.o +*.a +*.so +*.class +*.log +*.core diff --git a/micromake/src/Microfile b/micromake/src/Microfile new file mode 100644 index 0000000..607b02a --- /dev/null +++ b/micromake/src/Microfile @@ -0,0 +1,3 @@ +qwertyu: +cbejw: a bc d +dmwq :d wdwd diff --git a/minimake/Makefile b/minimake/Makefile new file mode 100644 index 0000000..a1b29ea --- /dev/null +++ b/minimake/Makefile @@ -0,0 +1,3 @@ +CC= gcc +CFLAGS= -std=c99 -pedantic -Werror -Wall -Wextra -Wvla + diff --git a/minimake/minimake.c b/minimake/minimake.c new file mode 100644 index 0000000..e3abfb9 --- /dev/null +++ b/minimake/minimake.c @@ -0,0 +1,31 @@ +// Error Codes +#define INVALID_ARG 2 + +#include +#include +#include +#include +#include + +// TODO: +// Look at perror for stdlib functions +// Create an enum for error handling + +int handle_args(int argc, char **argv) +{ + int flags = 0; + for (int i = 1; i < argc; i++) + { + if (strcmp(argv[i], "-h")) + errx(INVALID_ARG, "-h: not implemented"); + else if (strcmp(argv[i], "-f")) + errx(INVALID_ARG, "-f: not implemented"); + else if (strcmp(argv[i], "-p")) + errx(INVALID_ARG, "-p: not implemented"); + else + errx(INVALID_ARG, ": Pleaase give an argument"); + } +} + +int main(int argc, char **argv) +{} diff --git a/simple_ls/simple_ls.c b/simple_ls/simple_ls.c new file mode 100644 index 0000000..508c5df --- /dev/null +++ b/simple_ls/simple_ls.c @@ -0,0 +1,37 @@ +#include +#include +#include + +static void simple_ls(char *path) +{ + if (path == NULL) + errx(1, "Internal error: Passed NULL path"); + + DIR *dir = opendir(path); + if (dir == NULL) + errx(1, "Internal error: cannot open directory"); + + struct dirent *element; + while ((element = readdir(dir))) + { + puts(element->d_name); + } + + int res = closedir(dir); + if (res == -1) + errx(1, "Could not close dir"); +} + +int main(int argc, char **argv) +{ + if (argc < 2) + simple_ls("."); + else + { + for (int i = 1; i < argc; i++) + { + simple_ls(argv[i]); + } + } + return 0; +}