1#! /bin/sh --
2eval '(exit $?0)' && eval 'PERL_BADLANG=x;export PERL_BADLANG;: \
3;exec perl -x -S -- "$0" ${1+"$@"};#'if 0;
4eval 'setenv PERL_BADLANG x;exec perl -x -S -- "$0" $argv:q;#'.q
5#!perl -w
6+($0=~/(.*)/s);do$1;die$@if$@;__END__+if 0;
7# Don't touch/remove lines 1--7: http://www.inf.bme.hu/~pts/Magic.Perl.Header
8
9#
10# hq.pl -- convert binary STDIN to C language "quoted\\-string"
11# by pts@fazekas.hu at Tue Dec  3 17:46:52 CET 2002
12#
13# VC6.0 imposes the following restrictions:
14# -- the number of (destination) characters inside a single "..." block may
15#    not exceed 2048
16# -- the number of "..." blocks may not exceed 999 if the /Zm999 compiler
17#    option is specified; this number should be minimized
18# -- "\12319" causes a stupid warning, should be emitted as: "\123\51\61"
19# -- output lines should not be too long (I limit them to 79 chars)
20#
21
22my @numenc=('\60','\61','\62','\63','\64','\65','\66','\67','\70','\71');
23my @enc;
24for (my $I=0;$I<256;$I++) { $enc[$I]=sprintf"\\%03o",$I }
25
26binmode STDIN if @ARGV;
27binmode STDOUT; # UNIX NL in output
28while (0<read STDIN, $_, 2040) {
29  s/([^\w\.\/\- ])(\d*)/$enc[ord$1].join("",@numenc[split"",$2])/ge;
30  s/(.{74}[^\\]{0,3})/$1\\\n/gs;
31  # ^^^ Dat: [^\\]{0,3} is for ensuring not breaking a \\
32  print "\"$_\"\n";
33}
34