- changed sully to decrement from 5 included to 0
- changed sully makefile to adapt to different starting decrement number
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -62,3 +62,5 @@ Sully_*.c
|
||||
!Grace_exploded.c
|
||||
!Sully_exploded.c
|
||||
*test*
|
||||
clones/
|
||||
*.su
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
#include <stdio.h>
|
||||
#define xstr(s) #s
|
||||
#define str(s) xstr(s)
|
||||
#define FT(s) int main() { char *before = "#define _GNU_SOURCE /* for asprintf */\n#include <stdlib.h> /* for free and system */\n#include <stdio.h>\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 <stdlib.h> /* for free and system */\n#include <stdio.h>\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)))
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user