Skip to content

Commit

Permalink
Tool for making the http-string.c file from http-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdunkels committed Mar 29, 2007
1 parent d1b791f commit 5230c1b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tools/makestrings
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/perl


sub stringify {
my $name = shift(@_);
open(OUTPUTC, "> $name.c");
open(OUTPUTH, "> $name.h");

open(FILE, "$name");

while(<FILE>) {
if(/(.+) "(.+)"/) {
$var = $1;
$data = $2;

$datan = $data;
$datan =~ s/\\r/\r/g;
$datan =~ s/\\n/\n/g;
$datan =~ s/\\01/\01/g;
$datan =~ s/\\0/\0/g;

printf(OUTPUTC "const char $var\[%d] = \n", length($datan) + 1);
printf(OUTPUTC "/* \"$data\" */\n");
printf(OUTPUTC "{");
for($j = 0; $j < length($datan); $j++) {
printf(OUTPUTC "%#02x, ", unpack("C", substr($datan, $j, 1)));
}
printf(OUTPUTC "};\n");

printf(OUTPUTH "extern const char $var\[%d];\n", length($datan) + 1);

}
}
close(OUTPUTC);
close(OUTPUTH);
}
stringify($ARGV[0]);

exit 0;

0 comments on commit 5230c1b

Please sign in to comment.