now using __FILE__ to check if file is Sully.c or Sully_5.c

This commit is contained in:
asus
2024-01-28 19:40:13 +01:00
parent 3334c8b0db
commit e645122f15
3 changed files with 31 additions and 21 deletions

2
.gitignore vendored
View File

@@ -62,5 +62,7 @@ Sully_*.c
!Grace_exploded.c !Grace_exploded.c
!Sully_exploded.c !Sully_exploded.c
*test* *test*
*tmp*
*temp*
clones/ clones/
*.su *.su

View File

@@ -1,8 +1,10 @@
#define _GNU_SOURCE /* for asprintf */ #define _GNU_SOURCE /* for asprintf */
#include <stdlib.h> /* for free and system */ #include <stdlib.h> /* for free and system */
#include <string.h> /* for __FILE__ */
#include <stdio.h> #include <stdio.h>
#define xstr(s) #s #define xstr(s) #s
#define str(s) xstr(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 <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;\nFT(str(FT(s)))\n"; if (i >= 0) {char *kid_name; char *kid_name_c; char *decremented_after; char *cmd; asprintf(&kid_name, "Sully_%i", i); asprintf(&kid_name_c, "%s.c", kid_name); FILE *file = fopen(kid_name_c, "w"); asprintf(&decremented_after, after, i - 1); fprintf(file, "%s%s%s", before, quine, decremented_after); 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(decremented_after); } 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 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; }
int i = 5; int i = 5;
char *file_name = __FILE__;
FT(str(FT(s))) FT(str(FT(s)))

View File

@@ -1,5 +1,6 @@
#define _GNU_SOURCE /* for asprintf */ #define _GNU_SOURCE /* for asprintf */
#include <stdlib.h> /* for free and system */ #include <stdlib.h> /* for free and system */
#include <string.h> /* for __FILE__ */
#include <stdio.h> #include <stdio.h>
#define xstr(s) #s #define xstr(s) #s
#define str(s) xstr(s) #define str(s) xstr(s)
@@ -10,40 +11,45 @@ int main() \
char *before = "\ char *before = "\
#define _GNU_SOURCE /* for asprintf */\n\ #define _GNU_SOURCE /* for asprintf */\n\
#include <stdlib.h> /* for free and system */\n\ #include <stdlib.h> /* for free and system */\n\
#include <string.h> /* for __FILE__ */\n\
#include <stdio.h>\n\ #include <stdio.h>\n\
#define xstr(s) #s\n\ #define xstr(s) #s\n\
#define str(s) xstr(s)\n\ #define str(s) xstr(s)\n\
#define FT(s)"; \ #define FT(s) "; \
char *quine = s; \ char *quine = s; \
char *after = "\ char *after = "\
\n\ \n\
int i = %i;\n\ int i = %i;\n\
char *file_name = %s%s;\n\
FT(str(FT(s)))\n"; \ FT(str(FT(s)))\n"; \
\ \
if (i >= 0) \ if (i == 0) \
{\ return 0; \
char *kid_name; \ if ((strchr(file_name, '_')) != ((void*)0)) \
char *kid_name_c; \ i--;\
char *decremented_after; \
char *cmd; \
\ \
asprintf(&kid_name, "Sully_%i", i); \ char *kid_name; \
asprintf(&kid_name_c, "%s.c", kid_name); \ char *kid_name_c; \
char *after_expanded; \
char *cmd; \
\ \
FILE *file = fopen(kid_name_c, "w"); \ asprintf(&kid_name, "Sully_%i", i); \
asprintf(&decremented_after, after, i - 1); \ asprintf(&kid_name_c, "%s.c", kid_name); \
fprintf(file, "%s%s%s", before, quine, decremented_after); \
fclose(file); \
\ \
asprintf(&cmd, "clang %1$s -o %2$s ; ./%2$s", kid_name_c, kid_name); \ FILE *file = fopen(kid_name_c, "w"); \
system(cmd); \ asprintf(&after_expanded, after, i, "__FI", "LE__"); \
fprintf(file, "%s%s%s", before, quine, after_expanded); \
fclose(file); \
\ \
free(cmd); \ asprintf(&cmd, "clang %1$s -o %2$s ; ./%2$s", kid_name_c, kid_name); \
free(kid_name_c); \ system(cmd); \
free(kid_name); \ \
free(decremented_after); \ free(cmd); \
} \ free(kid_name_c); \
free(kid_name); \
free(after_expanded); \
return 0; \ return 0; \
} }
int i = 5; int i = 5;
char *file_name = __FILE__;
FT(str(FT(s))) FT(str(FT(s)))