3 # Copyright (C) 2011 Morten Welinder <terra@gnome.org>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of the
8 # License, or (at your option) version 3.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 use IO
::Compress
::Gzip
qw(gzip $GzipError);
29 my $unregfunc = undef;
30 my $regfuncstatic = 0;
31 my $regfilefunc = "go_rsm_register_file";
32 my $unregfilefunc = "go_rsm_unregister_file";
36 &GetOptions("register-function=s" => \$regfunc,
37 "unregister-function=s" => \$unregfunc,
38 "register-file-function=s" => \$regfilefunc,
39 "unregister-file-function=s" => \$unregfilefunc,
40 "static" => \$regfuncstatic,
41 "id-prefix=s" => \$id_prefix,
42 "include=s" => \@includes,
43 ) or die "$0: invalid usage -- inquire within\n";
45 # -----------------------------------------------------------------------------
47 print "/* Generated by $myself -- do not edit! */\n\n";
48 foreach my $include (@includes) {
49 $include = "\"$include\"" unless $include =~ /^[<""]/;
50 print "#include $include\n";
57 print "static " if $regfuncstatic;
59 print "$regfunc (void)\n";
61 foreach my $file (@ARGV) {
62 if ($file eq 'COMPRESS') {
66 if ($file eq 'NOCOMPRESS') {
70 &embed ($file, $docompress);
75 if (defined $unregfunc) {
77 print "static " if $regfuncstatic;
79 print "$unregfunc (void)\n";
86 my ($file, $docompress) = @_;
88 print " /* Embedded file $file */\n";
95 open (*FIL, "<$file") or die "$myself: cannot read $file: $!\n";
101 gzip \$data => \$zdata, TIME => 0,
102 or die "gzip failed: $GzipError\n";
106 my $id = "data$fileno";
109 &embed_data ($data, $id);
111 my $res = "$id_prefix$file";
112 my $len = length ($data);
113 $reg .= " $regfilefunc (\"$res\", $id, $len);\n";
114 $unreg .= " $unregfilefunc (\"$res\");\n";
120 my $len = length ($data);
122 print " static const char ${id}[] = \"\";\n";
126 print " static const char ${id}[] =\n";
129 foreach my $c (split (//, $data)) {
130 if ($linelen > $WIDTH) {
140 my $thisnohex = $nohex;
147 } elsif ($c eq "\t") {
150 } elsif ($c eq '"') {
153 } elsif ($c eq "\\") {
156 } elsif ($ci >= 32 && $ci < 127) {
157 if ($thisnohex && $c =~ /[a-fA-F0-9]/) {
164 printf ("\\x%02x", $ci);