removed __FILE__ splited in 2 parts
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define str(s) #s
|
#define str(s) #s
|
||||||
#define xstr(s) str(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; }
|
#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;\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, "__FILE__"); 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;
|
int i = 5;
|
||||||
char *file_name = __FILE__;
|
char *file_name = __FILE__;
|
||||||
FT(xstr(FT(s)))
|
FT(xstr(FT(s)))
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ int main() \
|
|||||||
char *after = "\
|
char *after = "\
|
||||||
\n\
|
\n\
|
||||||
int i = %i;\n\
|
int i = %i;\n\
|
||||||
char *file_name = %s%s;\n\
|
char *file_name = %s;\n\
|
||||||
FT(xstr(FT(s)))\n"; \
|
FT(xstr(FT(s)))\n"; \
|
||||||
\
|
\
|
||||||
if (i == 0) \
|
if (i == 0) \
|
||||||
@@ -37,7 +37,7 @@ int main() \
|
|||||||
asprintf(&kid_name_c, "%s.c", kid_name); \
|
asprintf(&kid_name_c, "%s.c", kid_name); \
|
||||||
\
|
\
|
||||||
FILE *file = fopen(kid_name_c, "w"); \
|
FILE *file = fopen(kid_name_c, "w"); \
|
||||||
asprintf(&after_expanded, after, i, "__FI", "LE__"); \
|
asprintf(&after_expanded, after, i, "__FILE__"); \
|
||||||
fprintf(file, "%s%s%s", before, quine, after_expanded); \
|
fprintf(file, "%s%s%s", before, quine, after_expanded); \
|
||||||
fclose(file); \
|
fclose(file); \
|
||||||
\
|
\
|
||||||
|
|||||||
Reference in New Issue
Block a user