From 8fb97ffa8fd7e2cec654b5148e7e570e42672f67 Mon Sep 17 00:00:00 2001 From: vx-clutch Date: Fri, 22 Aug 2025 13:40:07 -0400 Subject: [PATCH] feat: argument parse 1 --- TODO | 8 +++-- include/yait.h | 15 ++++++---- src/create_project.c | 2 +- src/main.c | 71 ++++++++++++++++++++++++++++++-------------- 4 files changed, 63 insertions(+), 33 deletions(-) diff --git a/TODO b/TODO index 57b420e..8e02fa0 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,10 @@ VX yait --- TODO Todo: - - * Argument Parsing - * Project creation + * Project formats + * GNU + * FASM + * POSIX + * LIBRARY end of file TODO diff --git a/include/yait.h b/include/yait.h index 33a3805..73f1971 100644 --- a/include/yait.h +++ b/include/yait.h @@ -10,14 +10,8 @@ #define YAIT_H typedef struct { - bool posix; bool git; bool clang; - bool lib; - bool cc; - bool gnu; - /* If this flag is set it will ignore: GNU, and enforce POSIX. */ - bool simple; } flag_t; typedef struct { @@ -35,10 +29,19 @@ typedef enum { UNL, } licence_t; +typedef enum { + POSIX, + SIMPLE, + GNU, + LIBRARY, + FASM, +} style_t; + typedef struct { libmap_t libraries; licence_t licence; flag_t flags; + style_t style; char *project; char *name; diff --git a/src/create_project.c b/src/create_project.c index 5ae6a57..8bd72d6 100644 --- a/src/create_project.c +++ b/src/create_project.c @@ -20,7 +20,7 @@ int create_project(manifest_t manifest) mkdir_p(manifest.project); chdir(manifest.project); - if (manifest.flags.simple) { + if (manifest.style == SIMPLE) { /* This only works if the source files's root name is the same as the target on all of the Makefile becuase of how it checks for files. */ cfprintf( diff --git a/src/main.c b/src/main.c index 5471f6c..ad4ffd9 100644 --- a/src/main.c +++ b/src/main.c @@ -24,6 +24,15 @@ #define print_option(option, description) \ printf(" %-20s %-20s\n", option, description) +char *str_dup(char *s) +{ + char *new = malloc(strlen(s) + 1); + if (!new) + return NULL; + strcpy(new, s); + return new; +} + static void usage(int status) { if (status != 0) { @@ -35,42 +44,59 @@ 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("--posix", "Enable POSIX compliance"); - print_option("--git", "Do not inititize git reposity"); + print_option("--no-git", "Do not inititize git reposity"); print_option("--clang", "Add clang-format files and tooling"); print_option("-L ", "Set licence"); print_option("-l ", "Add a library"); - print_option("-C", "Use C++"); - print_option("--GNU", "Add version and help parsing"); - print_option("-S, --simple", "Enable simple mode"); + print_option("-n ", "Set the name of the project"); + print_option( + "--style=