Skip to content

Instantly share code, notes, and snippets.

@yoe
Created July 10, 2018 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoe/126e4b50bc1c78eb67b01a49c09628a5 to your computer and use it in GitHub Desktop.
Save yoe/126e4b50bc1c78eb67b01a49c09628a5 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#define sub int
#define eq ==
#define my$i int v$i
#define foreach$i(a) for(int v$i=0; v$i!=0; v$i++)
#define v$data data
#define foreach$j(a,b) for(int j=0; j<strlen(data[v$i]); j++)
#define v$j data[v$i][j]
#define use
#define constant const
#define ord(f) f
#if 0
sub v {
shift;
}
=pod
#endif
char * data[] = {
#if 0
=cut
@data = (
#endif
"#include <stdio.h>",
"#include <string.h>",
"#define sub int",
"#define eq ==",
"#define my\$i int v\$i",
"#define foreach\$i(a) for(int v\$i=0; v\$i!=0; v\$i++)",
"#define v\$data data",
"#define foreach\$j(a,b) for(int j=0; j<strlen(data[v\$i]); j++)",
"#define v\$j data[v\$i][j]",
"#define use",
"#define constant const",
"#define ord(f) f",
"#if 0",
"sub v {",
" shift;",
"}",
"=pod",
"#endif",
"char * data[] = {",
"#if 0",
"=cut",
"\@data = (",
"#endif",
"0E0",
"#if 0",
");",
"=pod",
"#endif",
"};",
"#if 0",
"=cut",
"#endif",
"#define START 23",
"#if 0",
"use constant START => 23;",
"#endif",
"sub main() {",
" for(my\$i = 0; v\$i<START; v\$i++) {",
" printf(\"%s\\n\", v\$data[v\$i]);",
" }",
" foreach\$i(\@data) {",
" if(v\$i) {",
" printf(\"\\\"\");",
" foreach\$j(split \"\", \$i) {",
" if(v\$j eq '\\\\' || v\$j eq '\$' || v\$j eq '\@' || v\$j eq '\"') {",
" printf(\"%c%c\", ord('\\\\'), ord(v\$j));",
" } else {",
" printf(\"%c\", ord(v\$j));",
" }",
" }",
" printf(\"\\\",\\n\");",
" }",
" }",
" for(my\$i=START;v\$data[v\$i];v\$i++) {",
" printf(\"%s\\n\", v\$data[v\$i]);",
" }",
" return 0;",
"}",
"#if 0",
"main()",
"#endif",
0E0
#if 0
);
=pod
#endif
};
#if 0
=cut
#endif
#define START 23
#if 0
use constant START => 23;
#endif
sub main() {
for(my$i = 0; v$i<START; v$i++) {
printf("%s\n", v$data[v$i]);
}
foreach$i(@data) {
if(v$i) {
printf("\"");
foreach$j(split "", $i) {
if(v$j eq '\\' || v$j eq '$' || v$j eq '@' || v$j eq '"') {
printf("%c%c", ord('\\'), ord(v$j));
} else {
printf("%c", ord(v$j));
}
}
printf("\",\n");
}
}
for(my$i=START;v$data[v$i];v$i++) {
printf("%s\n", v$data[v$i]);
}
return 0;
}
#if 0
main()
#endif
@yoe
Copy link
Author

yoe commented Jul 10, 2018

This is almost a quine in both C and perl. But not quite -- still need to make it actually work. It's harder than I initially thought, though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment