-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tool for making the http-string.c file from http-strings
- Loading branch information
adamdunkels
committed
Mar 29, 2007
1 parent
d1b791f
commit 5230c1b
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
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
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; | ||
|