From bd9b9c1912168b6750c6aca230d54c6e86778119 Mon Sep 17 00:00:00 2001 From: asus Date: Sun, 28 Jan 2024 14:42:44 +0100 Subject: [PATCH] - changed sully to decrement from 5 included to 0 - changed sully makefile to adapt to different starting decrement number --- .gitignore | 2 ++ C/3_Sully/Makefile | 37 +++++++++++++++++++++++---------- C/3_Sully/Sully.c | 2 +- C/3_Sully/Sully_exploded.c | 42 ++++++++++++++++++-------------------- C/MakefileCommon | 4 +++- 5 files changed, 52 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 21ede4a..d9e15fd 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,5 @@ Sully_*.c !Grace_exploded.c !Sully_exploded.c *test* +clones/ +*.su diff --git a/C/3_Sully/Makefile b/C/3_Sully/Makefile index 4c831a5..db539f4 100644 --- a/C/3_Sully/Makefile +++ b/C/3_Sully/Makefile @@ -1,16 +1,31 @@ NAME = Sully SRCS = Sully.c -CLONES = Sully_4.c \ - Sully_3.c \ - Sully_2.c \ - Sully_1.c \ - Sully_0.c + +CLONES_D = clones +# extract value of i inside Sully.c : +CLONES_i = $(shell grep -oP 'int i = \K\d+' $(SRCS)) +# seq -s ' ' -w 5 -1 0 : output -> "5 4 3 2 1 0" +CLONES_SEQ = $(shell seq -s ' ' -w $(CLONES_i) -1 0) +# create liste of executables files : Sully_5 Sully_4 ... +CLONES_X = $(addprefix $(NAME)_,$(CLONES_SEQ)) +CLONES = $(CLONES_C) +# create liste of files : Sully_5.c Sully_4.c ... +CLONES_C = $(addsuffix .c,$(CLONES_X)) + CREATE_CLONE = ./$(NAME) -RM_MORE = rm -f -RM_MORE += Sully_4 \ - Sully_3 \ - Sully_2 \ - Sully_1 \ - Sully_0 +RM_MORE = rm -rf +RM_MORE += $(CLONES_X) +RM_MORE += ./$(CLONES_D) include ../MakefileCommon + +sully: + $(MAKE) re + rm -rf ./$(CLONES_D) + mkdir -p ./$(CLONES_D) + cd ./$(CLONES_D) ;\ + clang -Wall -Wextra -Werror ../Sully.c -o Sully ; ./Sully ;\ + ls -al | grep Sully | wc -l + +.PHONY : sully + diff --git a/C/3_Sully/Sully.c b/C/3_Sully/Sully.c index 644d8c2..53c9237 100644 --- a/C/3_Sully/Sully.c +++ b/C/3_Sully/Sully.c @@ -3,6 +3,6 @@ #include #define xstr(s) #s #define str(s) xstr(s) -#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); if (i > 0) {system(cmd); } free(kid_name_c); free(kid_name); free(decremented_after); free(cmd); 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"; if (i >= 0) {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 - 1); 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); system(cmd); free(cmd); free(kid_name_c); free(kid_name); free(decremented_after); } return 0; } int i = 5; FT(str(FT(s))) diff --git a/C/3_Sully/Sully_exploded.c b/C/3_Sully/Sully_exploded.c index 1cb72a0..e7c866a 100644 --- a/C/3_Sully/Sully_exploded.c +++ b/C/3_Sully/Sully_exploded.c @@ -24,31 +24,29 @@ int main() \ FT(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); \ - if (i > 0) \ + if (i >= 0) \ {\ + 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 - 1); \ + 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); \ system(cmd); \ +\ + free(cmd); \ + free(kid_name_c); \ + free(kid_name); \ + free(decremented_after); \ } \ -\ - free(kid_name_c); \ - free(kid_name); \ - free(decremented_after); \ - free(cmd); \ -\ return 0; \ } int i = 5; diff --git a/C/MakefileCommon b/C/MakefileCommon index 80989b1..2b9751c 100644 --- a/C/MakefileCommon +++ b/C/MakefileCommon @@ -42,10 +42,12 @@ D_HEADERS = . HEADERS = # COMPILATION CONFIG : -CC = clang +CC = gcc EXT = c CFLAGS = -Wall -Wextra -Werror $(INCLUDES) CFLAGS += -g3 +CFLAGS += -fstack-usage +#CFLAGS += -fcallgraph-info # AUTOMATICALLY CREATED : D_OBJS = builds