From 7674010155663271286067453ec7f573d9f5516c Mon Sep 17 00:00:00 2001 From: vx-clutch Date: Thu, 17 Jul 2025 13:46:22 -0400 Subject: [PATCH] save --- .clang-format | 2 ++ Makefile | 23 ++++++++++------------- README | 3 --- core/e.c | 11 +++++++++++ core/e.h | 7 ++++++- core/file.c | 40 +++++++++++++++++++++++++++++++++++----- core/file.h | 9 +++++++-- tools/format | 3 +++ yait/main.c | 25 +++++++++++++++++++++---- 9 files changed, 95 insertions(+), 28 deletions(-) create mode 100644 .clang-format create mode 100644 core/e.c create mode 100644 tools/format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f802caa --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +Language: Cpp +BasedOnStyle: GNU diff --git a/Makefile b/Makefile index f05bc3c..4c6218f 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,9 @@ prefix = /usr/bin -YAIT_SRCS := $(wildcard yait/*.c) $(wildcard lib/*.c) +YAIT_SRCS := $(wildcard yait/*.c) $(wildcard core/*.c) +YAIT_OBJS := $(patsubst yait/%.c,c-out/obj/%.o,$(YAIT_SRCS)) -YAIT_OBJS := $(patsubst yait/%.c,obj/yait/%.o,$(YAIT_SRCS)) - -YAIT := bin/yait +YAIT := c-out/bin/yait -include config.mak @@ -14,15 +13,13 @@ all: @exit 1 else -all: obj bin $(YAIT) $(YAIT_DOC) +all: build $(YAIT) $(YAIT_DOC) -obj: - mkdir -p obj/yait +build: + mkdir -p c-out/bin + mkdir -p c-out/obj -bin: - mkdir -p bin - -obj/yait/%.o: yait/%.c +c-out/obj/%.o: yait/%.c $(CC) $(CFLAGS) -c $< -o $@ $(YAIT): $(YAIT_OBJS) @@ -40,9 +37,9 @@ uninstall: exit 1 clean: - rm -rf obj bin + rm -rf c-out dist-clean: clean rm -f config.mak -.PHONY: all clean dist-clean install uninstall +.PHONY: all clean dist-clean install uninstall build format diff --git a/README b/README index 029685c..16eb077 100644 --- a/README +++ b/README @@ -5,6 +5,3 @@ definitely complete. This tool will create a new directory containing all project files needed for your new C ( maybe C++ ) project. It provides you with a build system and some basic source files to give you a kick start on your new project--with optional libraries! - -For a more in-depth explanation of how to use the tool refer to `--help` or use -the doc tool `yait-doc`. diff --git a/core/e.c b/core/e.c new file mode 100644 index 0000000..6e25a93 --- /dev/null +++ b/core/e.c @@ -0,0 +1,11 @@ +#include "e.h" +#include "print.h" +#include + +error_t unwrap(error_t err) { + if (!err.null) { + printfn("error: %s", err.src); + exit(err.status); + } + return err; +} diff --git a/core/e.h b/core/e.h index 5ac3f79..0dcbf05 100644 --- a/core/e.h +++ b/core/e.h @@ -1,9 +1,14 @@ #ifndef ERROR_H #define ERROR_H +#include + typedef struct { - int stat; + bool null; + int status; const char *src; } error_t; +error_t unwrap(error_t); + #endif diff --git a/core/file.c b/core/file.c index 2c7c1be..edd829f 100644 --- a/core/file.c +++ b/core/file.c @@ -4,19 +4,49 @@ #include #include #include +#include +#include + +error_t touch(char *path, char *format, ...) { + error_t err = {0}; + err.null = true; // success by default -error_t write(char *path, char *format, ...) { - error_t err; va_list args; va_start(args, format); - FILE *fp; - fp = fopen(path, "w"); + + FILE *fp = fopen(path, "w"); if (!fp) { - err.stat = errno; + err.null = false; + err.status = errno; err.src = strerror(errno); + va_end(args); + return err; } + vfprintf(fp, format, args); fclose(fp); + va_end(args); return err; } + +error_t dir(char *format, ...) { + error_t err = {0}; + err.null = true; // success by default + + va_list args; + va_start(args, format); + + char path[1024]; + vsnprintf(path, sizeof(path), format, args); + + va_end(args); + + if (mkdir(path, 0777) < 0) { + err.null = false; + err.status = errno; + err.src = strerror(errno); + } + + return err; +} diff --git a/core/file.h b/core/file.h index d395733..a4a8a69 100644 --- a/core/file.h +++ b/core/file.h @@ -2,8 +2,13 @@ #define FILE_H #include "e.h" +#include -error_t write(char *, char *, ...); -void printfn(char *, ...); +#define take(x, ...) \ + dir(x, ##__VA_ARGS__); \ + chdir(x); + +error_t touch(char *, char *, ...); +error_t dir(char *, ...); #endif diff --git a/tools/format b/tools/format new file mode 100644 index 0000000..b9b2492 --- /dev/null +++ b/tools/format @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +find . -name "*.c" -exec clang-format -i {} \; diff --git a/yait/main.c b/yait/main.c index 78dfac9..1c01b2d 100644 --- a/yait/main.c +++ b/yait/main.c @@ -1,18 +1,35 @@ -#include "../lib/print.h" -#include "core.h" +#include "../core/print.h" +#include "../core/file.h" +#include "format.h" -void create(format_t); +int create(format_t); int main(int argc, char **argv) { if (argc < 2) { printfn("error: not enough arguments."); return 1; } + format_t conf; conf.name = argv[1]; conf.nogit = false; + + create(conf); return 0; } -void create(format_t conf) { +int create(format_t fmt) { + take(fmt.name); + + touch("README", + "%s ( concise description )\n\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor\n" + "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis\n" + "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n" + "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu\n" + "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in\n" + "culpa qui officia deserunt mollit anim id est laborum.", + fmt.name); + touch ("hello", "world"); + return 0; }