Mmm - a text file to C code convertion is a few lines of perl
Code:
-- The perl program to do the magic
$ cat bar.pl
#!/usr/bin/perl -w
use strict;
while ( <> ) {
chomp;s/\r//;
s/([\\"])/\\$1/g; # quote all backslashes and "
print "\"$_\\n\"\n";
}
-- Example C program
$ cat bar.c
#include <stdio.h>
int main ( ) {
printf(
#include "help.txt"
);
return 0;
}
-- The perl program run on itself
$ bar.pl bar.pl > help.txt
-- The file it produced, which is the C-string equivalent
$ cat help.txt
"#!/usr/bin/perl -w\n"
"use strict;\n"
"while ( <> ) {\n"
" chomp;s/\\r//;\n"
" s/([\\\\\"])/\\\\$1/g; # quote all backslashes and \"\n"
" print \"\\\"$_\\\\n\\\"\\n\";\n"
"}\n"
-- compile and test our program
-- voila, our original perl program!
$ gcc bar.c
$ ./a.exe
#!/usr/bin/perl -w
use strict;
while ( <> ) {
chomp;s/\r//;
s/([\\"])/\\$1/g; # quote all backslashes and "
print "\"$_\\n\"\n";
}