diff options
author | Kovensky <diogomfranco@gmail.com> | 2012-11-07 11:49:44 -0300 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2012-11-08 00:28:59 +0100 |
commit | fae73079310eef9dce9737f2e37ff4b80c8830ee (patch) | |
tree | 4a9c7d9fbc398b237808283df39562e55077a225 /TOOLS/file2string.pl | |
parent | 58f821e096392e27994102f6de6f8f76c63e38e1 (diff) | |
download | mpv-fae73079310eef9dce9737f2e37ff4b80c8830ee.tar.bz2 mpv-fae73079310eef9dce9737f2e37ff4b80c8830ee.tar.xz |
Port several python scripts to Perl
file2string.pl and vdpau_functions.pl are direct ports.
matroska.py was reimplemented as the Parse::Matroska module in CPAN,
and matroska.pl was made a client of Parse::Matroska.
A copy of Parse::Matroska is included in TOOLS/lib, and matroska.pl
looks there first when trying to load the module.
osxbundle.py was not ported since I have no means to verify it.
Python is always available on OSX though, so there is no harm in
removing the check for it on configure.
Diffstat (limited to 'TOOLS/file2string.pl')
-rwxr-xr-x | TOOLS/file2string.pl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/TOOLS/file2string.pl b/TOOLS/file2string.pl new file mode 100755 index 0000000000..d9ad215d6d --- /dev/null +++ b/TOOLS/file2string.pl @@ -0,0 +1,24 @@ +#! /usr/bin/env perl + +use strict; +use warnings; + +# Convert the contents of a file into a C string constant. +# Note that the compiler will implicitly add an extra 0 byte at the end +# of every string, so code using the string may need to remove that to get +# the exact contents of the original file. +# FIXME: why not a char array? + +# treat only alphanumeric and not-" punctuation as safe +my $unsafe_chars = qr{[^][A-Za-z0-9!#%&'()*+,./:;<=>?^_{|}~ -]}; + +for my $file (@ARGV) { + open my $fh, '<:raw', $file or next; + print "/* Generated from $file */\n"; + while (<$fh>) { + # replace unsafe chars with their equivalent octal escapes + s/($unsafe_chars)/\\@{[sprintf '%03o', ord($1)]}/gos; + print "\"$_\"\n" + } + close $fh; +} |