From 2e0b5dd8d90eaab16a989d71c2fb69c4764ed051 Mon Sep 17 00:00:00 2001 From: asus Date: Thu, 25 Jan 2024 14:12:49 +0100 Subject: [PATCH] new version of grace --- 2_Grace/Grace.c | 17 ++++------------- README.md | 14 ++++++++------ notes.md | 2 +- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/2_Grace/Grace.c b/2_Grace/Grace.c index 14d4efb..f2aea43 100644 --- a/2_Grace/Grace.c +++ b/2_Grace/Grace.c @@ -1,15 +1,6 @@ #include -#define PRINT quine, 10, print, 10, 92, 10, 92, 10, 92, 10, 92, 10, 34, 34, 34, 34, 92, 10, 92, 10, 34, quine, 34, 92, 10, 92, 10, 92, 10, 10, 10, 10, 10 -#define FT(...) int main(){\ - /*\ - comment\ - */\ - FILE *file = fopen("Grace_kid.c", "w");\ - char *print = #__VA_ARGS__;\ - char *quine = "#include %c#define PRINT %s%c#define FT(...) int main(){%c%c /*%c%c comment%c%c */%c%c FILE *file = fopen(%cGrace_kid.c%c, %cw%c);%c%c char *print = #__VA_ARGS__;%c%c char *quine = %c%s%c;%c%c fprintf(file, PRINT);%c%c return 0;%c%c}%c#define FFT(...) FT(__VA_ARGS__)%c%cFFT(PRINT)%c";\ - fprintf(file, PRINT);\ - return 0;\ -} -#define FFT(...) FT(__VA_ARGS__) +#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\nMAIN(str(MAIN(s)))\n"; printf(quine); return 0; } -FFT(PRINT) +MAIN(str(MAIN(s))) diff --git a/README.md b/README.md index d630fba..847474a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # DR QUINE -#### constructing a quine with macro : +## 2. GRACE + +#### 2.1 constructing a quine with macro : --- **a quine could be this structure basically :** @@ -27,7 +29,7 @@ MAIN() ``` -#### let's try it +#### 2.2 let's try it --- ``` @@ -53,7 +55,7 @@ int main() **problem :** the `char *quine` string should contain a copy of the whole code in place of "s" -#### second try, macro calling itself : MAIN(MAIN) +#### 2.3 second try, macro calling itself : MAIN(MAIN) --- ``` @@ -80,7 +82,7 @@ int main() -#### lets stringify the content of the inner MAIN +#### 2.4 lets stringify the content of the inner MAIN --- **the previous can be written with an extra step :** @@ -118,10 +120,10 @@ int main() } ``` -**problem :** oops, it stringified the paramter name, not it's expanded version, see https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html +**problem :** oops, it stringified the parameter name, not it's expanded version, see https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html -#### working stringification +#### 2.5 working stringification --- ``` diff --git a/notes.md b/notes.md index 514ac29..5598f52 100644 --- a/notes.md +++ b/notes.md @@ -272,7 +272,7 @@ int main() } ``` -**problem :** oops, it stringified the paramter name, not it's expanded version, see https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html +**problem :** oops, it stringified the parameter name, not it's expanded version, see https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html #### 2.4 : working stringification