From 57e4f2958e0314ddc7bd73f48cd4eb058befadef Mon Sep 17 00:00:00 2001 From: asus Date: Fri, 26 Jan 2024 11:42:58 +0100 Subject: [PATCH] sully works --- .gitignore | 1 + 3_Sully/Makefile | 12 ++++++++---- 3_Sully/Sully.c | 6 +++--- MakefileCommon | 6 ++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 56e5e11..fdd08f5 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ builds/ Colleen Grace Sully +Sully_* a.out Colleen_*.c Grace_*.c diff --git a/3_Sully/Makefile b/3_Sully/Makefile index 79abff0..f2c3570 100644 --- a/3_Sully/Makefile +++ b/3_Sully/Makefile @@ -1,6 +1,10 @@ -NAME = Sully -SRCS = Sully.c -CLONE = Sully_kid.c -CREATE_CLONE = ./$(NAME) +NAME = Sully +SRCS = Sully.c +CLONE = Sully_4.c \ + Sully_3.c \ + Sully_2.c \ + Sully_1.c \ + Sully_0.c \ +CREATE_CLONE = ./$(NAME) include ../MakefileCommon diff --git a/3_Sully/Sully.c b/3_Sully/Sully.c index 26f922b..2dfca74 100644 --- a/3_Sully/Sully.c +++ b/3_Sully/Sully.c @@ -1,8 +1,8 @@ #define _GNU_SOURCE /* for asprintf */ -#include /* for free */ +#include /* for free and system */ #include #define xstr(s) #s #define str(s) xstr(s) -#define MAIN(s) int main() { char *before = "#define _GNU_SOURCE /* for asprintf */\n#include /* for free */\n#include \n#define xstr(s) #s\n#define str(s) xstr(s)\n#define MAIN(s) "; char *quine = s; char *after = "\nint i = %i;\nMAIN(str(MAIN(s)))\n"; i--;char *kid_name; asprintf(&kid_name, "Sully_%i.c", i); FILE *file = fopen(kid_name, "w"); char *decremented_after; asprintf(&decremented_after, after, i); fprintf(file, "%s%s%s", before, quine, decremented_after); fclose(file);free(decremented_after);free(kid_name);return 0; } +#define FT(s) int main() { char *before = "#define _GNU_SOURCE /* for asprintf */\n#include /* for free and system */\n#include \n#define xstr(s) #s\n#define str(s) xstr(s)\n#define FT(s) "; char *quine = s; char *after = "\nint i = %i;\nFT(str(FT(s)))\n"; i--; char *kid_name; char *kid_name_c; char *decremented_after; char *cmd; asprintf(&kid_name, "Sully_%i", i); asprintf(&kid_name_c, "%s.c", kid_name); FILE *file = fopen(kid_name_c, "w"); asprintf(&decremented_after, after, i); fprintf(file, "%s%s%s", before, quine, decremented_after); fclose(file); asprintf(&cmd, "clang %1$s -o %2$s ; ./%2$s", kid_name_c, kid_name); printf("cmd: %s\n", cmd); if (i > 0) {system(cmd); }free(kid_name_c); free(kid_name); free(decremented_after); free(cmd); return 0; } int i = 5; -MAIN(str(MAIN(s))) +FT(str(FT(s))) diff --git a/MakefileCommon b/MakefileCommon index 7534ce2..a6a6df1 100644 --- a/MakefileCommon +++ b/MakefileCommon @@ -104,9 +104,11 @@ $(NAME): $(OBJS) leaks: $(NAME) valgrind --leak-check=full --show-leak-kinds=all $(CREATE_CLONE) +run: + $(CREATE_CLONE) + diff: $(NAME) @echo $(CYAN)"compare source with output :"$(RESET) - $(CREATE_CLONE) - diff --color $(CLONE) $(SRCS); \ if [ $$? -eq 0 ]; then echo $(GREEN)"Files $(SRCS) and $(CLONE) are identical"$(RESET); else echo $(RED)":Files $(SRCS) and $(CLONE) differ"$(RESET); fi @@ -118,5 +120,5 @@ fclean: clean re: fclean all -.PHONY : all clean fclean re concat diff leaks +.PHONY : all clean fclean re concat run diff leaks