07:47 <stevan> you broke it, you fix it :-p
[xxxterm.git] / js-merge-helper.pl
blob35a72edf2a11598af1e72610314af14245e23c30
1 #!/bin/env perl -w
2 use strict;
4 sub escape_c_string {
5 shift;
6 s/\t|\r|\n/ /g; # convert spacings to whitespaces
7 s/[^\/]\/\*.*?\*\///g; # remove comments (careful: hinttags look like comment!)
8 s/ {2,}/ /g; # strip whitespaces
9 s/(^|\(|\)|;|,|:|\}|\{|=|\+|\-|\*|\&|\||\<|\>|!) +/$1/g;
10 s/ +($|\(|\)|;|,|:|\}|\{|=|\+|\-|\*|\&|\||\<|\>|!)/$1/g;
11 s/\\/\\\\/g; # escape backslashes
12 s/\"/\\\"/g; # escape quotes
13 return $_
16 if (scalar @ARGV < 1) {
17 print "usage: js-merge-helper.pl jsfile ... \n";
18 exit 1;
21 my ($jsfile, $define, $js);
23 while (@ARGV) {
25 $jsfile = shift @ARGV;
26 my @fn = split /\//, $jsfile;
27 my $fn = pop @fn;
28 $fn =~ /^(.*)\.js$/;
30 $define = "JS_".uc($1);
31 $define =~ s/\-/_/;
33 open(JSFILE, $jsfile) or die "Failed to open file: $!";
34 $_ = do { local $/; <JSFILE> };
35 close(JSFILE);
37 $js = escape_c_string($_);
39 print "#define $define ";
40 printf "\"%s\"\n", $js;
44 exit;