yait

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 19c1e37cd296e77ac847dad05f10f3781c720b09
parent 13b15cb07fbebb040b76ca983e4b81d530dac270
Author: vx-clutch <[email protected]>
Date:   Wed,  3 Sep 2025 19:43:09 -0400

save

Diffstat:
Adoc/default | 11+++++++++++
Ddoc/styles | 71-----------------------------------------------------------------------
Minclude/yait.h | 7+++----
Msrc/create_project.c | 39++++++++++++++++++++++++++++++++++++++-
Msrc/file.c | 3++-
Msrc/licence.h | 2+-
Msrc/main.c | 29++++++++++++++++-------------
7 files changed, 71 insertions(+), 91 deletions(-)

diff --git a/doc/default b/doc/default @@ -0,0 +1,11 @@ + Yb dP db 88 888888 + YbdP dPYb 88 88 + 8P dP__Yb 88 88 + dP dP""""Yb 88 88 + + yait manual + +default +####### + +This documentation goes over the whats and whys of the yait default layout. diff --git a/doc/styles b/doc/styles @@ -1,71 +0,0 @@ - Yb dP db 88 888888 - YbdP dPYb 88 88 - 8P dP__Yb 88 88 - dP dP""""Yb 88 88 - - yait manual - -styles -###### - -In yait there are a few pre-made styles you can choose from. Those styles being -the following. - * posix (default) - * gnu - * simple - * lib - * fasm -These can be selected through setting the --style=<STYLE> flag. - -The POSIX style is the default style of yait and is the format used for the -project. The POSIX style is structured as the following: - project/ - bin/ - build/ - doc/ - include/ - project.h - man/ - project.1 - src/ - main.c - COPYING - Makefile - README - -The GNU style is based on the GNU project layout guide; however, it is minified. - project/ - man/ - project.1 - src/ - main.c - AUTHORS - COPYING - INSTALL - NEWS - README - configure.ac - -The Simple style is a minimal layout for short and sweet projects. - project/ - project.c - Makefile - README - -The Lib style is a layout for created libraries that compile to a .a and .so file. - project/ - include/ - project.h - src/ - project.c - Makefile - README - -The Fasm style is a layout based on the flat assembler. - project/ - SOURCE/ - main.c - TOOLS/ - build.sh - PROJECT.TXT - diff --git a/include/yait.h b/include/yait.h @@ -15,7 +15,6 @@ typedef struct { licence_t licence; bool lib; - bool exe; bool git; bool autotools; @@ -26,9 +25,9 @@ typedef struct { bool open_editor; struct { - bool nob; - bool clang_format; - bool Cleanup; + bool build_nob; + bool tools_format; + bool tools_Cleanup; } extra; char *project; diff --git a/src/create_project.c b/src/create_project.c @@ -2,7 +2,7 @@ * * This file is part of yait * - * This project and file is licenced under the BSD-3-Clause licence. + * This project and file is licensed under the BSD-3-Clause licence. * <https://opensource.org/licence/bsd-3-clause> */ @@ -29,6 +29,43 @@ int create_project(manifest_t manifest) if (status) return 1; + if (manifest.bare) { + cfprintf("main.c", ""); + cfprintf( + "Makefile", + ".POSIX:\nCC ::= gcc\nCFLAGS ::= -std=c23 -Wall -Wextra -Wpedantic\n\nall: %s\n\nclean\n\t$(RM) %s", + manifest.project, manifest.project); + cfprintf("README", "%s", manifest.project); + goto bare_skip; + } + + main_source = manifest.flat ? "main.c" : "src/main.c"; + cfprintf(main_source, "#include <stdio.h>\n" + "\n" + "int main()\n" + "{\n" + "\tputs(\"Hello, World!\");\n" + "\treturn 0;\n" + "}\n"); + char *upr_name = tostrupr(manifest.project); + if (manifest.make) { + cfprintf( + "Makefile", + "PREFIX = /usr/bin\n" + "\n" + "%s_SRCS := $(wildcard src/*.c)\n" + "%s_OBJS := $(patsubst src/%.c,build/obj/%.o,$(%s_SRCS))" + "\n" + "%s := bin/%s" + "\n" + "-include config.mak\n" + "\n" + "ifeq ($(wildcard config.mak),)\n", + upr_name, upr_name, upr_name, upr_name, + manifest.project); + } + +bare_skip: flast = true; switch (manifest.licence) { case MIT: diff --git a/src/file.c b/src/file.c @@ -2,7 +2,7 @@ * * This file is part of yait * - * This project and file is licenced under the BSD-3-Clause licence. + * This project and file is licensed under the BSD-3-Clause licence. * <https://opensource.org/license/bsd-3-clause> */ @@ -49,6 +49,7 @@ int mkdir_p(const char *path) int cfprintf(const char *path, const char *format, ...) { + int lines = atoi(getenv("LINES")); char *dirpath; const char *slash = strrchr(path, '/'); if (slash) { diff --git a/src/licence.h b/src/licence.h @@ -2,7 +2,7 @@ * * This file is part of yait * - * This project and file is licenced under the BSD-3-Clause licence. + * This project and file is licensed under the BSD-3-Clause licence. * <https://opensource.org/licence/bsd-3-clause> */ diff --git a/src/main.c b/src/main.c @@ -37,8 +37,10 @@ static void usage(int status) puts("Creates a C project with opinionated defaults"); puts("When only given the first argument it will detect your name\n"); puts("Mandatory arguments to long options are mandatory for short options too"); + print_option("--git", "Initialize git repository (default)"); print_option("--no-git", "Do not initialize git repository"); - print_option("-L <licence>", + print_option("--lib", "Make this a library"); + print_option("-l <licence>", "Set licence. This list can be found by passing 'list'"); print_option("-E", "Open editor after project creation"); puts(" --help display this help text and exit\n"); @@ -66,11 +68,11 @@ static inline int parse_extras_token(manifest_t *conf, char *s) } if (!strcmp(s, "nob")) - return conf->extra.nob = true, 0; + return conf->extra.build_nob = true, 0; if (!strcmp(s, "Cleanup")) - return conf->extra.Cleanup = true, 0; + return conf->extra.tools_Cleanup = true, 0; if (!strcmp(s, "format")) - return conf->extra.clang_format = true, 0; + return conf->extra.tools_format = true, 0; fprintf(stderr, "Option '%s' is not valid. See %s --extras=list\n", s, PROGRAM); return 1; @@ -85,7 +87,6 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv) { "git", no_argument, 0, 'g' }, { "no-git", no_argument, 0, 'G' }, { "lib", no_argument, 0, 'L' }, - { "both", no_argument, 0, 'b' }, { "autotools", no_argument, 0, 'a' }, { "cmake", no_argument, 0, 'c' }, { "make", no_argument, 0, 'm' }, @@ -120,18 +121,20 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv) case 'L': conf->lib = true; break; - case 'b': - conf->lib = true; - conf->exe = true; - break; case 'a': conf->autotools = true; + conf->cmake = false; + conf->make = false; break; case 'c': conf->cmake = true; + conf->autotools = false; + conf->make = false; break; case 'm': conf->make = true; + conf->autotools = false; + conf->cmake = false; break; case 'B': conf->bare = true; @@ -183,7 +186,6 @@ int get_name(char **output) size_t chunk_len = strlen(buffer); char *new_output = realloc(*output, output_len + chunk_len + 1); if (!new_output) { - free(*output); pclose(pipe); exit(EXIT_FAILURE); } @@ -218,10 +220,11 @@ int main(int argc, char **argv) .bare = false, .flat = false, .open_editor = false, + .lib = false, - .extra.nob = false, - .extra.clang_format = false, - .extra.Cleanup = false, + .extra.build_nob = false, + .extra.tools_format = false, + .extra.tools_Cleanup = false, }; status = parse_standard_options(usage, argc, argv);