fix mismatch xstr vs str

This commit is contained in:
Hugo LAMY
2025-01-04 11:30:57 +01:00
parent acd99e3e30
commit 15beb4aa3f
3 changed files with 22 additions and 22 deletions

View File

@@ -2,9 +2,9 @@
#include <stdlib.h> /* for free and system */
#include <string.h> /* for __FILE__ */
#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 <string.h> /* for __FILE__ */\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;\nchar *file_name = %s%s;\nFT(str(FT(s)))\n"; if (i == 0) return 0; if ((strchr(file_name, '_')) != ((void*)0)) i--;char *kid_name; char *kid_name_c; char *after_expanded; char *cmd; asprintf(&kid_name, "Sully_%i", i); asprintf(&kid_name_c, "%s.c", kid_name); FILE *file = fopen(kid_name_c, "w"); asprintf(&after_expanded, after, i, "__FI", "LE__"); fprintf(file, "%s%s%s", before, quine, after_expanded); 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(after_expanded); return 0; }
#define str(s) #s
#define xstr(s) str(s)
#define FT(s) int main() { char *before = "#define _GNU_SOURCE /* for asprintf */\n#include <stdlib.h> /* for free and system */\n#include <string.h> /* for __FILE__ */\n#include <stdio.h>\n#define str(s) #s\n#define xstr(s) str(s)\n#define FT(s) "; char *quine = s; char *after = "\nint i = %i;\nchar *file_name = %s%s;\nFT(xstr(FT(s)))\n"; if (i == 0) return 0; if ((strchr(file_name, '_')) != ((void*)0)) i--;char *kid_name; char *kid_name_c; char *after_expanded; char *cmd; asprintf(&kid_name, "Sully_%i", i); asprintf(&kid_name_c, "%s.c", kid_name); FILE *file = fopen(kid_name_c, "w"); asprintf(&after_expanded, after, i, "__FI", "LE__"); fprintf(file, "%s%s%s", before, quine, after_expanded); 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(after_expanded); return 0; }
int i = 5;
char *file_name = __FILE__;
FT(str(FT(s)))
FT(xstr(FT(s)))

View File

@@ -2,8 +2,8 @@
#include <stdlib.h> /* for free and system */
#include <string.h> /* for __FILE__ */
#include <stdio.h>
#define xstr(s) #s
#define str(s) xstr(s)
#define str(s) #s
#define xstr(s) str(s)
#define FT(s) \
int main() \
{ \
@@ -13,15 +13,15 @@ int main() \
#include <stdlib.h> /* for free and system */\n\
#include <string.h> /* for __FILE__ */\n\
#include <stdio.h>\n\
#define xstr(s) #s\n\
#define str(s) xstr(s)\n\
#define str(s) #s\n\
#define xstr(s) str(s)\n\
#define FT(s) "; \
char *quine = s; \
char *after = "\
\n\
int i = %i;\n\
char *file_name = %s%s;\n\
FT(str(FT(s)))\n"; \
FT(xstr(FT(s)))\n"; \
\
if (i == 0) \
return 0; \
@@ -52,4 +52,4 @@ int main() \
}
int i = 5;
char *file_name = __FILE__;
FT(str(FT(s)))
FT(xstr(FT(s)))

View File

@@ -341,28 +341,28 @@ int main()
```
#include <stdio.h>
#define xstr(s) #s
#define str(s) xstr(s)
#define str(s) #s
#define xstr(s) str(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) " \
char *quine = "#include <stdio.h>\n#define str(s) #s\n#define xstr(s) str(s)\n#define MAIN(s) " \
s \
"\n\nMAIN(str(MAIN(s)))\n"; \
"\n\nMAIN(xstr(MAIN(s)))\n"; \
printf(quine); \
return 0; \
}
MAIN(str(MAIN(s)))
MAIN(xstr(MAIN(s)))
```
**expands to :**
```
int main()
{
char *quine = "#include <stdio.h>\n#define xstr(s) #s\n#define str(s) xstr(s)\n#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\\nMAIN(str(MAIN(s)))\\n\"; printf(quine); return 0; }"
"\n\nMAIN(str(MAIN(s)))\n";
char *quine = "#include <stdio.h>\n#define str(s) #s\n#define xstr(s) str(s)\n#define MAIN(s) "
"int main() { char *quine = \"#include <stdio.h>\\n#define str(s) #s\\n#define xstr(s) str(s)\\n#define MAIN(s) \" s \"\\n\\nMAIN(xstr(MAIN(s)))\\n\"; printf(quine); return 0; }"
"\n\nMAIN(xstr(MAIN(s)))\n";
printf(quine);
return 0;
}
@@ -371,11 +371,11 @@ int main()
**output :**
```
#include <stdio.h>
#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\nMAIN(str(MAIN(s)))\n"; printf(quine); return 0; }
#define str(s) #s
#define xstr(s) str(s)
#define MAIN(s) int main() { char *quine = "#include <stdio.h>\n#define str(s) #s\n#define xstr(s) str(s)\n#define MAIN(s) "s"\n\nMAIN(xstr(MAIN(s)))\n"; printf(quine); return 0; }
MAIN(str(MAIN(s)))
MAIN(xstr(MAIN(s)))
```
**victory ;)**