new file structure according to subject
This commit is contained in:
10
C/1_Colleen/Colleen.c
Normal file
10
C/1_Colleen/Colleen.c
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
comment outside
|
||||
*/
|
||||
#include <stdio.h>
|
||||
char *second_function() { return "/*%c comment outside%c*/%c#include <stdio.h>%cchar *second_function() { return %c%s%c; }%cint main() { char *program = second_function(); printf(program, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10); return 0;%c /*%c comment inside%c */%c}%c"; }
|
||||
int main() { char *program = second_function(); printf(program, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10); return 0;
|
||||
/*
|
||||
comment inside
|
||||
*/
|
||||
}
|
||||
32
C/1_Colleen/Colleen_exploded.c
Normal file
32
C/1_Colleen/Colleen_exploded.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
comment outside
|
||||
*/
|
||||
#include <stdio.h>
|
||||
\
|
||||
char *second_function() \
|
||||
{ \
|
||||
return "\
|
||||
/*%c comment outside%c*/%c\
|
||||
#include <stdio.h>%c\
|
||||
char *second_function() \
|
||||
{ \
|
||||
return %c%s%c; \
|
||||
}%c\
|
||||
int main() \
|
||||
{ \
|
||||
char *program = second_function(); \
|
||||
printf(program, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10); \
|
||||
return 0;%c \
|
||||
/*%c comment inside%c */%c\
|
||||
}%c\
|
||||
"; \
|
||||
}
|
||||
int main() \
|
||||
{ \
|
||||
char *program = second_function(); \
|
||||
printf(program, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10); \
|
||||
return 0;
|
||||
/*
|
||||
comment inside
|
||||
*/
|
||||
}
|
||||
6
C/1_Colleen/Makefile
Normal file
6
C/1_Colleen/Makefile
Normal file
@@ -0,0 +1,6 @@
|
||||
NAME = Colleen
|
||||
SRCS = Colleen.c
|
||||
CLONES = $(NAME)_kid.c
|
||||
CREATE_CLONE = ./$(NAME) > $(CLONES)
|
||||
|
||||
include ../MakefileCommon
|
||||
8
C/2_Grace/Grace.c
Normal file
8
C/2_Grace/Grace.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#define xstr(s) #s
|
||||
#define str(s) xstr(s)
|
||||
#define MAIN(s) int main() { char *before = "#include <stdio.h>\n#define xstr(s) #s\n#define str(s) xstr(s)\n#define MAIN(s) "; char *quine = s; char *after = "\n/*\n comment\n*/\nMAIN(str(MAIN(s)))\n"; FILE *file = fopen("Grace_kid.c", "w"); fprintf(file, "%s%s%s", before, quine, after); fclose(file); return 0; }
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
MAIN(str(MAIN(s)))
|
||||
18
C/2_Grace/Grace_exploded.c
Normal file
18
C/2_Grace/Grace_exploded.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#define xstr(s) #s
|
||||
#define str(s) xstr(s)
|
||||
#define MAIN(s) \
|
||||
int main() \
|
||||
{ \
|
||||
char *before = "#include <stdio.h>\n#define xstr(s) #s\n#define str(s) xstr(s)\n#define MAIN(s) "; \
|
||||
char *quine = s; \
|
||||
char *after = "\n/*\n comment\n*/\nMAIN(str(MAIN(s)))\n"; \
|
||||
FILE *file = fopen("Grace_kid.c", "w"); \
|
||||
fprintf(file, "%s%s%s", before, quine, after); \
|
||||
fclose(file); \
|
||||
return 0; \
|
||||
}
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
MAIN(str(MAIN(s)))
|
||||
6
C/2_Grace/Makefile
Normal file
6
C/2_Grace/Makefile
Normal file
@@ -0,0 +1,6 @@
|
||||
NAME = Grace
|
||||
SRCS = Grace.c
|
||||
CLONES = $(NAME)_kid.c
|
||||
CREATE_CLONE = ./$(NAME)
|
||||
|
||||
include ../MakefileCommon
|
||||
16
C/3_Sully/Makefile
Normal file
16
C/3_Sully/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
NAME = Sully
|
||||
SRCS = Sully.c
|
||||
CLONES = Sully_4.c \
|
||||
Sully_3.c \
|
||||
Sully_2.c \
|
||||
Sully_1.c \
|
||||
Sully_0.c
|
||||
CREATE_CLONE = ./$(NAME)
|
||||
RM_MORE = rm -f
|
||||
RM_MORE += Sully_4 \
|
||||
Sully_3 \
|
||||
Sully_2 \
|
||||
Sully_1 \
|
||||
Sully_0
|
||||
|
||||
include ../MakefileCommon
|
||||
8
C/3_Sully/Sully.c
Normal file
8
C/3_Sully/Sully.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#define _GNU_SOURCE /* for asprintf */
|
||||
#include <stdlib.h> /* for free and system */
|
||||
#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); 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;
|
||||
FT(str(FT(s)))
|
||||
56
C/3_Sully/Sully_exploded.c
Normal file
56
C/3_Sully/Sully_exploded.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#define _GNU_SOURCE /* for asprintf */
|
||||
#include <stdlib.h> /* for free and system */
|
||||
#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 = \
|
||||
"\
|
||||
\n\
|
||||
int i = %i;\n\
|
||||
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); \
|
||||
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;
|
||||
FT(str(FT(s)))
|
||||
72
C/Makefile
Normal file
72
C/Makefile
Normal file
@@ -0,0 +1,72 @@
|
||||
# - - - - - - #
|
||||
# #
|
||||
# COLORS #
|
||||
# #
|
||||
# - - - - - - #
|
||||
|
||||
GRAY = "\e[0;30m"
|
||||
RED = "\e[0;31m"
|
||||
GREEN = "\e[0;32m"
|
||||
YELLOW = "\e[0;33m"
|
||||
BLUE = "\e[0;34m"
|
||||
PURPLE = "\e[0;35m"
|
||||
CYAN = "\e[0;36m"
|
||||
WHITE = "\e[0;37m"
|
||||
|
||||
B_GRAY = "\e[1;30m"
|
||||
B_RED = "\e[1;31m"
|
||||
B_GREEN = "\e[1;32m"
|
||||
B_YELLOW = "\e[1;33m"
|
||||
B_BLUE = "\e[1;34m"
|
||||
B_PURPLE = "\e[1;35m"
|
||||
B_CYAN = "\e[1;36m"
|
||||
B_WHITE = "\e[1;37m"
|
||||
|
||||
RESET = "\e[0m"
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
# . name = value \ . += append to a variable #
|
||||
# VARIABLES . value . != set result of command #
|
||||
# . name is case sensitive . ?= set if not already set #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
|
||||
D_QUINES = ./1_Colleen \
|
||||
./2_Grace \
|
||||
./3_Sully
|
||||
|
||||
RULE = all
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
# . target: prerequisites . $@ : target #
|
||||
# RULES . recipe . $< : 1st prerequisite #
|
||||
# . recipe . $^ : all prerequisites #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
|
||||
all:
|
||||
@$(MAKE) RULE=$@ loop
|
||||
|
||||
run:
|
||||
@$(MAKE) RULE=$@ loop
|
||||
|
||||
diff:
|
||||
@$(MAKE) RULE=$@ loop
|
||||
|
||||
leaks:
|
||||
@$(MAKE) RULE=$@ loop
|
||||
|
||||
clean:
|
||||
@$(MAKE) RULE=$@ loop
|
||||
|
||||
fclean:
|
||||
@$(MAKE) RULE=$@ loop
|
||||
|
||||
loop: $(D_QUINES)
|
||||
@for dir in $^; do \
|
||||
echo $(B_GREEN)"$(RULE) $$dir"$(RESET); \
|
||||
$(MAKE) $(RULE) -C $$dir; \
|
||||
done
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY : all clean fclean re loop run diff leaks
|
||||
|
||||
126
C/MakefileCommon
Normal file
126
C/MakefileCommon
Normal file
@@ -0,0 +1,126 @@
|
||||
# - - - - - - #
|
||||
# #
|
||||
# COLORS #
|
||||
# #
|
||||
# - - - - - - #
|
||||
|
||||
GRAY = "\e[0;30m"
|
||||
RED = "\e[0;31m"
|
||||
GREEN = "\e[0;32m"
|
||||
YELLOW = "\e[0;33m"
|
||||
BLUE = "\e[0;34m"
|
||||
PURPLE = "\e[0;35m"
|
||||
CYAN = "\e[0;36m"
|
||||
WHITE = "\e[0;37m"
|
||||
|
||||
B_GRAY = "\e[1;30m"
|
||||
B_RED = "\e[1;31m"
|
||||
B_GREEN = "\e[1;32m"
|
||||
B_YELLOW = "\e[1;33m"
|
||||
B_BLUE = "\e[1;34m"
|
||||
B_PURPLE = "\e[1;35m"
|
||||
B_CYAN = "\e[1;36m"
|
||||
B_WHITE = "\e[1;37m"
|
||||
|
||||
RESET = "\e[0m"
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
# . name = value \ . += append to a variable #
|
||||
# VARIABLES . value . != set result of command #
|
||||
# . name is case sensitive . ?= set if not already set #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
|
||||
# FILES :
|
||||
#NAME -> defined in subfolder makefiles
|
||||
#SRCS -> defined in subfolder makefiles
|
||||
#CLONES -> defined in subfolder makefiles
|
||||
#CREATE_CLONE -> defined in subfolder makefiles
|
||||
#RM_MORE -> might be defined in subfolder makefiles
|
||||
LIBS =
|
||||
D_SRCS = .
|
||||
D_HEADERS = .
|
||||
HEADERS =
|
||||
|
||||
# COMPILATION CONFIG :
|
||||
CC = clang
|
||||
EXT = c
|
||||
CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
|
||||
CFLAGS += -g3
|
||||
|
||||
# AUTOMATICALLY CREATED :
|
||||
D_OBJS = builds
|
||||
OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o)
|
||||
EXPLODED = $(SRCS:%.$(EXT)=%_exploded.$(EXT))
|
||||
VPATH = $(D_SRCS)
|
||||
F_INCLUDES = $(HEADERS:%=$(D_HEADERS)/%)
|
||||
INCLUDES = -I$(D_HEADERS)
|
||||
ifeq "$(D_OBJS)" "."
|
||||
RM_OBJS = rm -f $(OBJS)
|
||||
else
|
||||
RM_OBJS = rm -rf $(D_OBJS)
|
||||
endif
|
||||
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
# . target: prerequisites . $@ : target #
|
||||
# RULES . recipe . $< : 1st prerequisite #
|
||||
# . recipe . $^ : all prerequisites #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
|
||||
all: concat $(NAME)
|
||||
|
||||
# sed :
|
||||
# -z : instead of classic "-e", looks for lines that ends with \0 instead of \n, usefull when lines can contain \n
|
||||
# 's/\\\n\t*//g' : subsitutes backslash '\\' followed by newline '\n' followed by any number of tabs '\t*', and replace them by nothing
|
||||
# empty recipe :
|
||||
# - to avoid makefile complaining when $(EXPLODED) does not exist
|
||||
# - https://www.gnu.org/software/make/manual/html_node/Empty-Recipes.html
|
||||
concat: $(EXPLODED)
|
||||
@echo $(CYAN)"create the condensed version of the quine :"$(RESET)
|
||||
- test -f $< && sed -z 's/\\\n\t*//g' $< > $(SRCS)
|
||||
$(EXPLODED): ;
|
||||
|
||||
# %.$(EXT) | $(D_OBJS) -> pipe is for order-only prerequisites :
|
||||
# - for each file "%.$(EXT)" :
|
||||
# - if it has been modified since last time
|
||||
# - execute rules on corresponding target file "$(D_OBJS)/%.o"
|
||||
# - and directory "$(D_OBJS)" is order-only prerequisite :
|
||||
# - it must exist before executing rule
|
||||
# - but last time modification is not checked
|
||||
# - it avoids recompiling each time because the build folder was
|
||||
# modified by creation of other objects files
|
||||
$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS)
|
||||
@echo $(CYAN)"compilation (objects.o) :"$(RESET)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(D_OBJS):
|
||||
mkdir $@
|
||||
|
||||
$(OBJS): $(F_INCLUDES)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
@echo $(CYAN)"linkage (link objects.o) :"$(RESET)
|
||||
$(CC) $(OBJS) -o $@ $(LIBS)
|
||||
|
||||
leaks: $(NAME)
|
||||
valgrind --leak-check=full --show-leak-kinds=all $(CREATE_CLONE)
|
||||
|
||||
run:
|
||||
$(CREATE_CLONE)
|
||||
|
||||
diff: $(NAME)
|
||||
@echo $(CYAN)"compare source with output :"$(RESET)
|
||||
- diff --color $(CLONE) $(SRCS); \
|
||||
if [ $$? -eq 0 ]; then echo $(GREEN)"Files $(SRCS) and $(CLONES) are identical"$(RESET); else echo $(RED)":Files $(SRCS) and $(CLONES) differ"$(RESET); fi
|
||||
|
||||
clean:
|
||||
$(RM_OBJS)
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
rm -f $(CLONES)
|
||||
$(RM_MORE)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY : all clean fclean re concat run diff leaks
|
||||
|
||||
Reference in New Issue
Block a user