Merge remote-tracking branch 'refs/remotes/origin/master'

save
This commit is contained in:
2025-07-21 19:40:40 -04:00
4 changed files with 235 additions and 234 deletions

View File

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

4
TODO
View File

@@ -1,4 +0,0 @@
The following is a list of this that need to be done.
Urgent:
- Fix the segfault at Makefile

View File

@@ -3,10 +3,10 @@
#define line(l) l "\n" #define line(l) l "\n"
// README template /* README template */
char *readme_template = char *readme_template =
line ("%s ( concise description )") line ("%s ( concise description )")
line("") line ()
line ("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor") line ("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor")
line ("incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis") line ("incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis")
line ("nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.") line ("nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
@@ -14,33 +14,33 @@ char *readme_template =
line ("fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in") line ("fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in")
line ("culpa qui officia deserunt mollit anim id est laborum."); line ("culpa qui officia deserunt mollit anim id est laborum.");
// configure script template /* configure script template */
char *configure_template = char *configure_template =
line ("#!/bin/sh") line ("#!/bin/sh")
line("") line ()
line ("usage() {") line ("usage() {")
line ("cat <<EOF") line ("cat <<EOF")
line ("Usage: $0 [OPTION]... [VAR=VALUE]...") line ("Usage: $0 [OPTION]... [VAR=VALUE]...")
line("") line ()
line ("To assign environment variables (e.g., CC, CFLAGS...), specify them as") line ("To assign environment variables (e.g., CC, CFLAGS...), specify them as")
line ("VAR=VALUE.") line ("VAR=VALUE.")
line("") line ()
line (" CC C compiler command [detected]") line (" CC C compiler command [detected]")
line (" CFLAGS C compiler flags [-g, ...]") line (" CFLAGS C compiler flags [-g, ...]")
line("") line ()
line ("EOF") line ("EOF")
line ("exit 0") line ("exit 0")
line ("}") line ("}")
line("") line ()
line ("echo () { printf \"%%s\\n\" \"$*\" ; }") line ("echo () { printf \"%%s\\n\" \"$*\" ; }")
line ("cmdexists () { type \"$1\" >/dev/null 2>&1 ; }") line ("cmdexists () { type \"$1\" >/dev/null 2>&1 ; }")
line ("trycc () { test -z \"$CC\" && cmdexists \"$1\" && CC=$1 ; }") line ("trycc () { test -z \"$CC\" && cmdexists \"$1\" && CC=$1 ; }")
line("") line ()
line ("prefix=/usr/bin/") line ("prefix=/usr/bin/")
line ("CFLAGS=\"-Wall -Wextra -O2\"") line ("CFLAGS=\"-Wall -Wextra -O2\"")
line ("LDFLAGS=") line ("LDFLAGS=")
line ("CC=") line ("CC=")
line("") line ()
line ("for arg ; do") line ("for arg ; do")
line ("case \"$arg\" in") line ("case \"$arg\" in")
line ("--help|h) usage ;;") line ("--help|h) usage ;;")
@@ -48,13 +48,13 @@ char *configure_template =
line ("LDFLAGS=*) LDFLAGS=${arg#*=} ;;") line ("LDFLAGS=*) LDFLAGS=${arg#*=} ;;")
line ("esac") line ("esac")
line ("done") line ("done")
line("") line ()
line ("printf \"checking for C compiler... \"") line ("printf \"checking for C compiler... \"")
line ("trycc gcc") line ("trycc gcc")
line ("trycc cc") line ("trycc cc")
line ("trycc clang") line ("trycc clang")
line ("printf \"%%s\\n\" \"$CC\"") line ("printf \"%%s\\n\" \"$CC\"")
line("") line ()
line ("printf \"checking weather C compiler works... \"") line ("printf \"checking weather C compiler works... \"")
line ("status=\"fail\"") line ("status=\"fail\"")
line ("tmpc=\"$(mktemp -d)/test.c\"") line ("tmpc=\"$(mktemp -d)/test.c\"")
@@ -65,7 +65,7 @@ char *configure_template =
line ("printf \"no; %%s\\n\" \"$output\"") line ("printf \"no; %%s\\n\" \"$output\"")
line ("exit 1") line ("exit 1")
line ("fi") line ("fi")
line("") line ()
line ("printf \"creating config.mak... \"") line ("printf \"creating config.mak... \"")
line ("printf \"PREFIX=%%s\\n\" \"$prefix\" > config.mak") line ("printf \"PREFIX=%%s\\n\" \"$prefix\" > config.mak")
line ("printf \"CFLAGS=%%s\\n\" \"$CFLAGS\" >> config.mak") line ("printf \"CFLAGS=%%s\\n\" \"$CFLAGS\" >> config.mak")
@@ -73,79 +73,78 @@ char *configure_template =
line ("printf \"CC=%%s\\n\" \"$CC\" >> config.mak") line ("printf \"CC=%%s\\n\" \"$CC\" >> config.mak")
line ("printf \"done\\n\""); line ("printf \"done\\n\"");
// Makefile template /* Makefile template */
char *makefile_template = char *makefile_template =
line ("prefix = /usr/bin") line ("prefix = /usr/bin")
line("") line ()
line ("%s_SRCS := $(shell find . -name '%s/*.c')") line ("%s_SRCS := $(shell find . -name '%s/*.c')")
line ("%s_OBJS := $(patsubst ./%.c,c-out/obj/%.o,$(%s_SRCS))") line ("%s_OBJS := $(patsubst ./%.c,c-out/obj/%.o,$(%s_SRCS))")
line("") line ()
line ("%s := c-out/bin/%s") line ("%s := c-out/bin/%s")
line("") line ()
line ("-include config.mak") line ("-include config.mak")
line("") line ()
line ("ifeq ($(wildcard config.mak),)") line ("ifeq ($(wildcard config.mak),)")
line ("all:") line ("all:")
line ("\t@echo \"File config.mak not found, run configure\"") line ("\t@echo \"File config.mak not found, run configure\"")
line ("\t@exit 1") line ("\t@exit 1")
line ("else") line ("else")
line("") line ()
line ("all: build $(%s)") line ("all: build $(%s)")
line("") line ()
line ("build:") line ("build:")
line ("\tmkdir -p c-out/bin") line ("\tmkdir -p c-out/bin")
line ("\tmkdir -p c-out/obj") line ("\tmkdir -p c-out/obj")
line("") line ()
line ("c-out/obj/%.o: %.c") line ("c-out/obj/%.o: %.c")
line ("\t$(CC) $(CFLAGS) -c $< -o $@") line ("\t$(CC) $(CFLAGS) -c $< -o $@")
line("") line ()
line ("$(%s): $(%s_OBJS)") line ("$(%s): $(%s_OBJS)")
line ("\t$(CC) $(CFLAGS) -DCOMMIT=$(shell git rev-list --count --all 2>/dev/null || echo 0) $^ -o $@") line ("\t$(CC) $(CFLAGS) -DCOMMIT=$(shell git rev-list --count --all 2>/dev/null || echo 0) $^ -o $@")
line("") line ()
line ("endif") line ("endif")
line("") line ()
line ("install:") line ("install:")
line ("\t@echo \"NOT IMPL\"") line ("\t@echo \"NOT IMPL\"")
line ("\texit 1") line ("\texit 1")
line("") line ()
line ("uninstall:") line ("uninstall:")
line ("\t@echo \"NOT IMPL\"") line ("\t@echo \"NOT IMPL\"")
line ("\texit 1") line ("\texit 1")
line("") line ()
line ("clean:") line ("clean:")
line ("\trm -rf c-out") line ("\trm -rf c-out")
line("") line ()
line ("dist-clean: clean") line ("dist-clean: clean")
line ("\trm -f config.mak") line ("\trm -f config.mak")
line("") line ()
line (".PHONY: all clean dist-clean install uninstall build format"); line (".PHONY: all clean dist-clean install uninstall build format");
// .clang-format template /* .clang-format template */
char *clang_format_template = char *clang_format_template =
line("Language: Cpp")
line ("BasedOnStyle: GNU"); line ("BasedOnStyle: GNU");
// BSD 3-Clause License template /* BSD 3-Clause License template */
char *bsd3_license_template = char *bsd3_license_template =
line ("BSD 3-Clause License") line ("BSD 3-Clause License")
line("") line ()
line ("Copyright (c) %d, %s") line ("Copyright (c) %d, %s")
line("") line ()
line ("Redistribution and use in source and binary forms, with or without") line ("Redistribution and use in source and binary forms, with or without")
line ("modification, are permitted provided that the following conditions are met:") line ("modification, are permitted provided that the following conditions are met:")
line("") line ()
line ("1. Redistributions of source code must retain the above copyright notice, this") line ("1. Redistributions of source code must retain the above copyright notice, this")
line (" list of conditions and the following disclaimer.") line (" list of conditions and the following disclaimer.")
line("") line ()
line ("2. Redistributions in binary form must reproduce the above copyright notice,") line ("2. Redistributions in binary form must reproduce the above copyright notice,")
line (" this") line (" this")
line ("list of conditions and the following disclaimer in the documentation") line ("list of conditions and the following disclaimer in the documentation")
line (" and/or other materials provided with the distribution.") line (" and/or other materials provided with the distribution.")
line("") line ()
line ("3. Neither the name of the copyright holder nor the names of its") line ("3. Neither the name of the copyright holder nor the names of its")
line (" contributors may be used to endorse or promote products derived from") line (" contributors may be used to endorse or promote products derived from")
line (" this software without specific prior written permission.") line (" this software without specific prior written permission.")
line("") line ()
line ("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"") line ("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"")
line ("AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE") line ("AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE")
line ("IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE") line ("IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE")
@@ -157,54 +156,58 @@ char *bsd3_license_template =
line ("OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE") line ("OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE")
line ("OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."); line ("OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.");
// config.h template /* config.h template */
char *config_h_template = char *config_h_template =
line ("#ifndef CONFIG_H") line ("#ifndef CONFIG_H")
line ("#define CONFIG_H") line ("#define CONFIG_H")
line("") line ()
line ("/* Program information */") line ("/* Program information */")
line ("#define PROGRAM \"%s\"") line ("#define PROGRAM \"%s\"")
line("#define LICENSE_LINE \"%s\"") line ("#define LICENSE_line \"%s\"")
line ("#define AUTHORS \"%s\"") line ("#define AUTHORS \"%s\"")
line ("#define VERSION \"pre-alpha\"") line ("#define VERSION \"pre-alpha\"")
line ("#define YEAR 2025") line ("#define YEAR 2025")
line("") line ()
line ("#define HELP_REQUESTED 2") line ("#define HELP_REQUESTED 2")
line ("#define ERROR_MEMORY_ALLOCATION 3") line ("#define ERROR_MEMORY_ALLOCATION 3")
line ("#define ERROR_DIRECTORY_CREATION 4") line ("#define ERROR_DIRECTORY_CREATION 4")
line("") line ()
line ("#endif"); line ("#endif");
// main.c (non-GNU) template /* main.c (non-GNU) template */
char *main_c_template = char *main_c_template =
line ("#include <stdio.h>") line ("#include <stdio.h>")
line("") line ()
line ("int main(void) {") line ("int main(void) {")
line (" printf(\"%s: Hello %s!\\n\");") line (" printf(\"%s: Hello %s!\\n\");")
line (" return 0;") line (" return 0;")
line ("}"); line ("}");
// main.c (GNU) template /* main.c (GNU) template */
char *main_c_gnu_template = char *main_c_gnu_template =
line ("#include <stdio.h>") line ("#include <stdio.h>")
line ("#include \"standard.h\"") line ("#include \"standard.h\"")
line("") line ()
line("void usage(int status) {\n printf(\"Usage: %s [OPTION...]\\n\");\n}") line ("void usage(int status) {")
line("") line (" fprintf(stderr, \"Usage: %s [OPTION...]\\n\");")
line (" fprintf(stderr, \" --help\\tdisplay the help text and exit\\n\");")
line (" fprintf(stderr, \" --version\\toutput version information and exit\\n\");")
line ("}")
line ()
line ("int main(int argc, char **argv) {") line ("int main(int argc, char **argv) {")
line (" parse_standard_options(usage, argc, argv);") line (" parse_standard_options(usage, argc, argv);")
line (" printf(\"%s: Hello %s!\\n\");") line (" printf(\"%s: Hello %s!\\n\");")
line (" return 0;") line (" return 0;")
line ("}"); line ("}");
// standard.c template /* standard.c template */
char *standard_c_template = char *standard_c_template =
line ("#include \"standard.h\"") line ("#include \"standard.h\"")
line ("#include \"../config.h\"") line ("#include \"../config.h\"")
line ("#include <stdio.h>") line ("#include <stdio.h>")
line ("#include <stdlib.h>") line ("#include <stdlib.h>")
line ("#include <string.h>") line ("#include <string.h>")
line("") line ()
line ("int") line ("int")
line ("parse_standard_options (void (*usage) (int), int argc, char **argv)") line ("parse_standard_options (void (*usage) (int), int argc, char **argv)")
line ("{") line ("{")
@@ -217,18 +220,18 @@ char *standard_c_template =
line (" }") line (" }")
line (" else if (strcmp (argv[i], \"--version\") == 0)") line (" else if (strcmp (argv[i], \"--version\") == 0)")
line (" {") line (" {")
line(" printf (\"%%s %%s %%d\\nCopyright (C) %%d %%s.\\n%%s\\nThis is free software: you are free to change and redistribute it.\\nThere is NO WARRNTY, to the extent permitted by law.\\n\", PROGRAM, VERSION, COMMIT, YEAR, AUTHORS, LICENSE_LINE);") line (" printf (\"%%s %%s %%d\\nCopyright (C) %%d %%s.\\n%%s\\nThis is free software: you are free to change and redistribute it.\\nThere is NO WARRNTY, to the extent permitted by law.\\n\", PROGRAM, VERSION, COMMIT, YEAR, AUTHORS, LICENSE_line );")
line (" exit (EXIT_SUCCESS);") line (" exit (EXIT_SUCCESS);")
line (" }") line (" }")
line (" }") line (" }")
line (" return HELP_REQUESTED;") line (" return HELP_REQUESTED;")
line ("}"); line ("}");
// standard.h template /* standard.h template */
char *standard_h_template = char *standard_h_template =
line ("#ifndef STANDARD_H") line ("#ifndef STANDARD_H")
line ("#define STANDARD_H") line ("#define STANDARD_H")
line("") line ()
line ("/**") line ("/**")
line (" * Parse standard command line options (--help, --version)") line (" * Parse standard command line options (--help, --version)")
line (" * @param usage_func Function pointer to usage display function") line (" * @param usage_func Function pointer to usage display function")
@@ -237,7 +240,16 @@ char *standard_h_template =
line (" * @return 0 on success, 1 if help/version requested, errno on error") line (" * @return 0 on success, 1 if help/version requested, errno on error")
line (" */") line (" */")
line ("int parse_standard_options(void (*usage_func)(), int argc, char **argv);") line ("int parse_standard_options(void (*usage_func)(), int argc, char **argv);")
line("") line ()
line ("#endif"); line ("#endif");
/* WHATNEXT.md template */
char *what_next_template =
line ("# What next?")
line ("")
line ("## Steps")
line (" - Write a description in the README")
line (" - Write the usage function ( write to stderr )")
line (" - Start writing your program");
#endif #endif

View File

@@ -85,8 +85,6 @@ main (int argc, char **argv)
conf.flag.git = DEFAULT_GIT_INIT; conf.flag.git = DEFAULT_GIT_INIT;
conf.flag.clang_format = DEFAULT_CLANG_FORMAT; conf.flag.clang_format = DEFAULT_CLANG_FORMAT;
conf.flag.GNU = true; // debug
conf.licence = DEFAULT_LICENSE; conf.licence = DEFAULT_LICENSE;
int result = create_project (conf); int result = create_project (conf);
@@ -116,8 +114,8 @@ create_project (format_t fmt)
} }
if (!fmt.name) if (!fmt.name)
fmt.name = DEFAULT_USER_NAME; fmt.name = DEFAULT_USER_NAME;
create_file_with_content ("README", readme_template, create_file_with_content ("WHATNEXT.md", what_next_template);
fmt.project ? fmt.project : DEFAULT_PROJECT_NAME); create_file_with_content ("README", readme_template, fmt.project);
create_file_with_content ("configure", configure_template); create_file_with_content ("configure", configure_template);
int status = system ("chmod +x configure"); int status = system ("chmod +x configure");
if (status) if (status)
@@ -141,7 +139,7 @@ create_project (format_t fmt)
create_file_with_content ("Makefile", makefile_template, makefile_name, create_file_with_content ("Makefile", makefile_template, makefile_name,
makefile_name, makefile_name, makefile_name, makefile_name, makefile_name, makefile_name,
makefile_name, makefile_name, fmt.project, makefile_name, makefile_name, fmt.project,
makefile_name, makefile_name); makefile_name);
free (makefile_name); free (makefile_name);
if (fmt.flag.clang_format) if (fmt.flag.clang_format)
create_file_with_content (".clang-format", clang_format_template); create_file_with_content (".clang-format", clang_format_template);
@@ -163,17 +161,13 @@ create_project (format_t fmt)
create_and_enter_directory (fmt.project); create_and_enter_directory (fmt.project);
if (!fmt.flag.GNU) if (!fmt.flag.GNU)
{ {
create_file_with_content ("main.c", main_c_template, create_file_with_content ("main.c", main_c_template, fmt.project,
fmt.project ? fmt.project fmt.name);
: DEFAULT_PROJECT_NAME,
fmt.name ? fmt.name : "World");
} }
else else
{ {
create_file_with_content ("main.c", main_c_gnu_template, fmt.project, create_file_with_content ("main.c", main_c_gnu_template, fmt.project,
fmt.project ? fmt.project fmt.project, fmt.name);
: DEFAULT_PROJECT_NAME,
fmt.name ? fmt.name : "World");
} }
if (fmt.flag.GNU) if (fmt.flag.GNU)
{ {