diff --git a/2_Grace/Grace.c b/2_Grace/Grace.c index bfb97c5..7654dd4 100644 --- a/2_Grace/Grace.c +++ b/2_Grace/Grace.c @@ -1,7 +1,7 @@ #include #define xstr(s) #s #define str(s) xstr(s) -#define MAIN(s) int main() { char *quine = "#include \n#define xstr(s) #s\n#define str(s) xstr(s)\n#define MAIN(s) "s"\n/*\n comment\n*/\nMAIN(str(MAIN(s)))\n"; FILE *file = fopen("Grace_kid.c", "w"); fprintf(file, "%s", quine); return 0; } +#define MAIN(s) int main() { char *quine = "#include \n#define xstr(s) #s\n#define str(s) xstr(s)\n#define MAIN(s) "s"\n/*\n comment\n*/\nMAIN(str(MAIN(s)))\n"; FILE *file = fopen("Grace_kid.c", "w"); fprintf(file, "%s", quine); fclose(file); return 0; } /* comment */ diff --git a/3_Sully/Makefile b/3_Sully/Makefile index f317404..79abff0 100644 --- a/3_Sully/Makefile +++ b/3_Sully/Makefile @@ -1,6 +1,6 @@ NAME = Sully SRCS = Sully.c -CLONE = $(NAME)_kid.c +CLONE = Sully_kid.c CREATE_CLONE = ./$(NAME) include ../MakefileCommon diff --git a/3_Sully/Sully.c b/3_Sully/Sully.c index bfb97c5..1f8dde7 100644 --- a/3_Sully/Sully.c +++ b/3_Sully/Sully.c @@ -1,8 +1,8 @@ +#define _GNU_SOURCE /* for asprintf */ +#include /* for free */ #include #define xstr(s) #s #define str(s) xstr(s) -#define MAIN(s) int main() { char *quine = "#include \n#define xstr(s) #s\n#define str(s) xstr(s)\n#define MAIN(s) "s"\n/*\n comment\n*/\nMAIN(str(MAIN(s)))\n"; FILE *file = fopen("Grace_kid.c", "w"); fprintf(file, "%s", quine); return 0; } -/* - comment -*/ +#define MAIN(s) int main() { char *quine = "#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) "s"\nint i = %i;\nMAIN(str(MAIN(s,n)))\n"; char *kid_name; char *temp; asprintf(&temp, quine, 10, 20, 30); asprintf(&kid_name, "Sully_%i.c", 40); FILE *file = fopen(kid_name, "w"); fprintf(file, temp, 50, 60); fclose(file);free(temp);free(kid_name);return 0; } +int i = 5; MAIN(str(MAIN(s))) diff --git a/3_Sully/calculate_print.sh b/3_Sully/calculate_print.sh deleted file mode 100755 index 93149c9..0000000 --- a/3_Sully/calculate_print.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# it's important to put the input_string inside single quotes -input_string='#include %[\r]#define PRINT %[\s]%[\r]#define FT(...) int main(){%[\\]%[\r]' - -special_cahracters=$(echo -E "$input_string" | grep -o "%\[..\]") -echo $special_cahracters - -# assiocative array : https://www.gnu.org/software/bash/manual/html_node/Arrays.html -declare -A instructions -instructions["%[\r]"]=10 -instructions["%[\s]"]="S" -instructions["%[\\]"]=92 -instructions["%[\"]"]=34 - -for key diff --git a/MakefileCommon b/MakefileCommon index 4aed8ec..7534ce2 100644 --- a/MakefileCommon +++ b/MakefileCommon @@ -102,13 +102,13 @@ $(NAME): $(OBJS) $(CC) $(OBJS) -o $@ $(LIBS) leaks: $(NAME) - valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) + valgrind --leak-check=full --show-leak-kinds=all $(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 $(NAME) and $(SRCS) differ"$(RESET); fi + if [ $$? -eq 0 ]; then echo $(GREEN)"Files $(SRCS) and $(CLONE) are identical"$(RESET); else echo $(RED)":Files $(SRCS) and $(CLONE) differ"$(RESET); fi clean: $(RM_OBJS) @@ -120,4 +120,3 @@ re: fclean all .PHONY : all clean fclean re concat diff leaks - diff --git a/notes.md b/notes.md index c101333..85b3022 100644 --- a/notes.md +++ b/notes.md @@ -17,20 +17,18 @@ ``` dr_quine/ -│ -├─ C/ -│ ├─ Colleen.c -│ ├─ Grace.c -│ ├─ Sully.c -│ ├─ Makefile -│ └─ ... -│ -└─ ASM/ - ├─ Colleen.asm - ├─ Grace.asm - ├─ Sully.asm - ├─ Makefile - └─ ... +| C/ +| | Colleen.c +| | Grace.c +| | Sully.c +| | Makefile +| | ... +| ASM/ +| | Colleen.asm +| | Grace.asm +| | Sully.asm +| | Makefile +| | ... ```