fixup <> includes
[xombrero.git] / js-merge-helper.pl
blob34216c5b8a40fbbd1a014a4c35e6d9387387cb83
1 #!/bin/env perl -w
2 # Copyright (c) 2009 Leon Winter
3 # Copyright (c) 2009, 2010 Hannes Schueller
4 # Copyright (c) 2009, 2010 Matto Fransen
5 # Copyright (c) 2010 Hans-Peter Deifel
6 # Copyright (c) 2010 Thomas Adam
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
9 # of this software and associated documentation files (the "Software"), to deal
10 # in the Software without restriction, including without limitation the rights
11 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 # copies of the Software, and to permit persons to whom the Software is
13 # furnished to do so, subject to the following conditions:
15 # The above copyright notice and this permission notice shall be included in
16 # all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 # THE SOFTWARE.
26 use strict;
28 sub escape_c_string {
29 shift;
30 s/\t|\r|\n/ /g; # convert spacings to whitespaces
31 s/[^\/]\/\*.*?\*\///g; # remove comments (careful: hinttags look like comment!)
32 s/ {2,}/ /g; # strip whitespaces
33 s/(^|\(|\)|;|,|:|\}|\{|=|\+|\-|\*|\&|\||\<|\>|!) +/$1/g;
34 s/ +($|\(|\)|;|,|:|\}|\{|=|\+|\-|\*|\&|\||\<|\>|!)/$1/g;
35 s/\\/\\\\/g; # escape backslashes
36 s/\"/\\\"/g; # escape quotes
37 return $_
40 if (scalar @ARGV < 1) {
41 print "usage: js-merge-helper.pl jsfile ... \n";
42 exit 1;
45 my ($jsfile, $define, $js);
47 while (@ARGV) {
49 $jsfile = shift @ARGV;
50 my @fn = split /\//, $jsfile;
51 my $fn = pop @fn;
52 $fn =~ /^(.*)\.js$/;
54 $define = "JS_".uc($1);
55 $define =~ s/\-/_/;
57 open(JSFILE, $jsfile) or die "Failed to open file: $!";
58 $_ = do { local $/; <JSFILE> };
59 close(JSFILE);
61 $js = escape_c_string($_);
63 print "#define $define ";
64 printf "\"%s\"\n", $js;
68 exit;