added sed command in makefile to concat quine

This commit is contained in:
asus
2024-01-25 18:40:37 +01:00
parent 805f3b695f
commit 65aac2c25a
4 changed files with 60 additions and 24 deletions

View File

@@ -2,16 +2,9 @@
comment outside
*/
#include <stdio.h>
char *second_function() {
return "/*%c comment outside%c*/%c#include <stdio.h>%c%cchar *second_function() {%c return %c%s%c;%c}%c%cint main() {%c /*%c comment inside%c */%c char *program = second_function();%c printf(program, 10, 10, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c";
}
int main() {
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
*/
char *program = second_function();
printf(program, 10, 10, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10);
return 0;
}

View File

@@ -1,14 +1,8 @@
#include <stdio.h>
#define PRINT quine, 10, print, 10, 92, 10, 92, 10, 92, 10, 92, 10, 92, 10, 34, quine, 34, 92, 10, 92, 10, 92, 10, 10, 10, 10, 10
#define FT(...) int main(){\
/*\
comment\
*/\
char *print = #__VA_ARGS__;\
char *quine = "#include <stdio.h>%c#define PRINT %s%c#define FT(...) int main(){%c%c /*%c%c comment%c%c */%c%c char *print = #__VA_ARGS__;%c%c char *quine = %c%s%c;%c%c printf(PRINT);%c%c return 0;%c%c}%c#define FFT(...) FT(__VA_ARGS__)%c%cFFT(PRINT)%c";\
printf(PRINT);\
return 0;\
}
#define FFT(...) FT(__VA_ARGS__)
FFT(PRINT)
#define xstr(s) #s
#define str(s) xstr(s)
#define MAIN(s) int main() { char *quine = "#include <stdio.h>\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
*/
MAIN(str(MAIN(s)))

View File

@@ -49,6 +49,7 @@ 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)
@@ -65,7 +66,18 @@ endif
# . recipe . $^ : all prerequisites #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
all: $(NAME)
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)" :
@@ -74,6 +86,8 @@ all: $(NAME)
# - 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 $@
@@ -104,6 +118,6 @@ fclean: clean
re: fclean all
.PHONY : all clean fclean re
.PHONY : all clean fclean re concat diff leaks

View File

@@ -2,6 +2,41 @@
- [preprocessor strip comments before exapnding macros](https://stackoverflow.com/questions/1510869/does-the-c-preprocessor-strip-comments-or-expand-macros-first)
- [create an include with a macro OR NOT](https://stackoverflow.com/questions/1135822/escaping-a-symbol-in-a-define-macro)
---
## make rules :
- make in root will make all projects
- make in each project will compile this project
- make diff : compile if necessary, and run the program then compare the output
- make concat : create the concatenated version, finale version, of the quine
## folder structure
> Each programs will have to be coded in C and in Assembly, and respectivly in a folder named C and ASM, each folders containing its own Makefile with the usual rules.
```
dr_quine/
├─ C/
│ ├─ Colleen.c
│ ├─ Grace.c
│ ├─ Sully.c
│ ├─ Makefile
│ └─ ...
└─ ASM/
├─ Colleen.asm
├─ Grace.asm
├─ Sully.asm
├─ Makefile
└─ ...
```
---
## Grace
---