This commit is contained in:
2025-07-17 13:46:22 -04:00
parent 3a9d52c513
commit 7674010155
9 changed files with 95 additions and 28 deletions

2
.clang-format Normal file
View File

@@ -0,0 +1,2 @@
Language: Cpp
BasedOnStyle: GNU

View File

@@ -1,10 +1,9 @@
prefix = /usr/bin 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 := c-out/bin/yait
YAIT := bin/yait
-include config.mak -include config.mak
@@ -14,15 +13,13 @@ all:
@exit 1 @exit 1
else else
all: obj bin $(YAIT) $(YAIT_DOC) all: build $(YAIT) $(YAIT_DOC)
obj: build:
mkdir -p obj/yait mkdir -p c-out/bin
mkdir -p c-out/obj
bin: c-out/obj/%.o: yait/%.c
mkdir -p bin
obj/yait/%.o: yait/%.c
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
$(YAIT): $(YAIT_OBJS) $(YAIT): $(YAIT_OBJS)
@@ -40,9 +37,9 @@ uninstall:
exit 1 exit 1
clean: clean:
rm -rf obj bin rm -rf c-out
dist-clean: clean dist-clean: clean
rm -f config.mak rm -f config.mak
.PHONY: all clean dist-clean install uninstall .PHONY: all clean dist-clean install uninstall build format

3
README
View File

@@ -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 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 a build system and some basic source files to give you a kick start on your new
project--with optional libraries! 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`.

11
core/e.c Normal file
View File

@@ -0,0 +1,11 @@
#include "e.h"
#include "print.h"
#include <stdlib.h>
error_t unwrap(error_t err) {
if (!err.null) {
printfn("error: %s", err.src);
exit(err.status);
}
return err;
}

View File

@@ -1,9 +1,14 @@
#ifndef ERROR_H #ifndef ERROR_H
#define ERROR_H #define ERROR_H
#include <stdbool.h>
typedef struct { typedef struct {
int stat; bool null;
int status;
const char *src; const char *src;
} error_t; } error_t;
error_t unwrap(error_t);
#endif #endif

View File

@@ -4,19 +4,49 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
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_list args;
va_start(args, format); va_start(args, format);
FILE *fp;
fp = fopen(path, "w"); FILE *fp = fopen(path, "w");
if (!fp) { if (!fp) {
err.stat = errno; err.null = false;
err.status = errno;
err.src = strerror(errno); err.src = strerror(errno);
}
vfprintf(fp, format, args);
fclose(fp);
va_end(args); va_end(args);
return err; 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;
}

View File

@@ -2,8 +2,13 @@
#define FILE_H #define FILE_H
#include "e.h" #include "e.h"
#include <unistd.h>
error_t write(char *, char *, ...); #define take(x, ...) \
void printfn(char *, ...); dir(x, ##__VA_ARGS__); \
chdir(x);
error_t touch(char *, char *, ...);
error_t dir(char *, ...);
#endif #endif

3
tools/format Normal file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
find . -name "*.c" -exec clang-format -i {} \;

View File

@@ -1,18 +1,35 @@
#include "../lib/print.h" #include "../core/print.h"
#include "core.h" #include "../core/file.h"
#include "format.h"
void create(format_t); int create(format_t);
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc < 2) { if (argc < 2) {
printfn("error: not enough arguments."); printfn("error: not enough arguments.");
return 1; return 1;
} }
format_t conf; format_t conf;
conf.name = argv[1]; conf.name = argv[1];
conf.nogit = false; conf.nogit = false;
create(conf);
return 0; 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;
} }