new file structure according to subject

This commit is contained in:
asus
2024-01-26 12:30:38 +01:00
parent 78959d77cd
commit 318cff516b
11 changed files with 13 additions and 9 deletions

16
C/3_Sully/Makefile Normal file
View File

@@ -0,0 +1,16 @@
NAME = Sully
SRCS = Sully.c
CLONES = Sully_4.c \
Sully_3.c \
Sully_2.c \
Sully_1.c \
Sully_0.c
CREATE_CLONE = ./$(NAME)
RM_MORE = rm -f
RM_MORE += Sully_4 \
Sully_3 \
Sully_2 \
Sully_1 \
Sully_0
include ../MakefileCommon

8
C/3_Sully/Sully.c Normal file
View File

@@ -0,0 +1,8 @@
#define _GNU_SOURCE /* for asprintf */
#include <stdlib.h> /* for free and system */
#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 <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"; i--; 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); 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); printf("cmd: %s\n", cmd); if (i > 0) {system(cmd); } free(kid_name_c); free(kid_name); free(decremented_after); free(cmd); return 0; }
int i = 5;
FT(str(FT(s)))

View File

@@ -0,0 +1,56 @@
#define _GNU_SOURCE /* for asprintf */
#include <stdlib.h> /* for free and system */
#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 <stdio.h>\n\
#define xstr(s) #s\n\
#define str(s) xstr(s)\n\
#define FT(s) \
"; \
char *quine = s; \
char *after = \
"\
\n\
int i = %i;\n\
FT(str(FT(s)))\n\
"; \
\
i--; \
\
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); \
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); \
printf("cmd: %s\n", cmd); \
if (i > 0) \
{\
system(cmd); \
} \
\
free(kid_name_c); \
free(kid_name); \
free(decremented_after); \
free(cmd); \
\
return 0; \
}
int i = 5;
FT(str(FT(s)))