Created
July 10, 2018 12:25
-
-
Save yoe/126e4b50bc1c78eb67b01a49c09628a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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...