Skip to content

Instantly share code, notes, and snippets.

@aji
Created October 26, 2013 04:06
Show Gist options
  • Save aji/7165161 to your computer and use it in GitHub Desktop.
Save aji/7165161 to your computer and use it in GitHub Desktop.
char *f="char *f=\"$\";\n"
"char buf[65536];\n"
"char in[65536];\n"
"char *sub_copy(char *b){\n"
"char *a=f;\n"
"for(;*a;a++)switch(*a){\n"
"case 10:*b++=92;*b++=110;*b++=34;*b++=10;*b++=34; break;\n"
"case 34:\n"
"case 92:*b++=92;\n"
"default:*b++=*a;\n"
"}return b;}\n"
"void copy_to_buf(void) {\n"
"char*a=f,*b=buf;\n"
"for(;*a;a++)switch(*a){\n"
"case 36:b=sub_copy(b); break;\n"
"default:*b++=*a;break;\n"
"}}\n"
"#include <stdio.h>\n"
"#include <string.h>\n"
"int main(int c,char *argv[]){\n"
"char *a;\n"
"copy_to_buf();\n"
"fread(in,1,65536,stdin);\n"
"printf(\"%smatch\\n\", strcmp(in,buf)?\"no \":\"\");\n"
"}\n"
"";
char buf[65536];
char in[65536];
char *sub_copy(char *b){
char *a=f;
for(;*a;a++)switch(*a){
case 10:*b++=92;*b++=110;*b++=34;*b++=10;*b++=34; break;
case 34:
case 92:*b++=92;
default:*b++=*a;
}return b;}
void copy_to_buf(void) {
char*a=f,*b=buf;
for(;*a;a++)switch(*a){
case 36:b=sub_copy(b); break;
default:*b++=*a;break;
}}
#include <stdio.h>
#include <string.h>
int main(int c,char *argv[]){
char *a;
copy_to_buf();
fread(in,1,65536,stdin);
printf("%smatch\n", strcmp(in,buf)?"no ":"");
}
@psyomn
Copy link

psyomn commented Oct 26, 2013

That is quite amusing. Cheers for the chuckle :o)

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