about summary refs log blame commit diff stats
path: root/js-merge-helper.pl
blob: 34216c5b8a40fbbd1a014a4c35e6d9387387cb83 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
1
#!/bin/env perl -w
# Copyright (c) 2009 Leon Winter
# Copyright (c) 2009, 2010 Hannes Schueller
# Copyright (c) 2009, 2010 Matto Fransen
# Copyright (c) 2010 Hans-Peter Deifel
# Copyright (c) 2010 Thomas Adam
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

use strict;

sub escape_c_string {
	shift;
	s/\t|\r|\n/ /g;     # convert spacings to whitespaces
	s/[^\/]\/\*.*?\*\///g;   # remove comments (careful: hinttags look like comment!)
	s/ {2,}/ /g;        # strip whitespaces
	s/(^|\(|\)|;|,|:|\}|\{|=|\+|\-|\*|\&|\||\<|\>|!) +/$1/g;
	s/ +($|\(|\)|;|,|:|\}|\{|=|\+|\-|\*|\&|\||\<|\>|!)/$1/g;
	s/\\/\\\\/g;        # escape backslashes
	s/\"/\\\"/g;        # escape quotes
	return $_
}

if (scalar @ARGV < 1) {
	print "usage: js-merge-helper.pl jsfile ... \n";
	exit 1;
}

my ($jsfile, $define, $js);

while (@ARGV) {

	$jsfile = shift @ARGV;
	my @fn = split /\//, $jsfile;
	my $fn = pop @fn;
	$fn =~ /^(.*)\.js$/;

	$define = "JS_".uc($1);
	$define =~ s/\-/_/;

	open(JSFILE, $jsfile) or die "Failed to open file: $!";
	$_ = do { local $/; <JSFILE> };
	close(JSFILE);

	$js = escape_c_string($_);

	print "#define $define ";
	printf "\"%s\"\n", $js;

}

exit;
class="p">> <dl><dt><a name="-isalpha"><strong>isalpha</strong></a>(c)</dt></dl> <dl><dt><a name="-isascii"><strong>isascii</strong></a>(c)</dt></dl> <dl><dt><a name="-isblank"><strong>isblank</strong></a>(c)</dt></dl> <dl><dt><a name="-iscntrl"><strong>iscntrl</strong></a>(c)</dt></dl> <dl><dt><a name="-isctrl"><strong>isctrl</strong></a>(c)</dt></dl> <dl><dt><a name="-isdigit"><strong>isdigit</strong></a>(c)</dt></dl> <dl><dt><a name="-isgraph"><strong>isgraph</strong></a>(c)</dt></dl> <dl><dt><a name="-islower"><strong>islower</strong></a>(c)</dt></dl> <dl><dt><a name="-ismeta"><strong>ismeta</strong></a>(c)</dt></dl> <dl><dt><a name="-isprint"><strong>isprint</strong></a>(c)</dt></dl> <dl><dt><a name="-ispunct"><strong>ispunct</strong></a>(c)</dt></dl> <dl><dt><a name="-isspace"><strong>isspace</strong></a>(c)</dt></dl> <dl><dt><a name="-isupper"><strong>isupper</strong></a>(c)</dt></dl> <dl><dt><a name="-isxdigit"><strong>isxdigit</strong></a>(c)</dt></dl> <dl><dt><a name="-unctrl"><strong>unctrl</strong></a>(c)</dt></dl> </td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#55aa55"> <td colspan=3 valign=bottom>&nbsp;<br> <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> <tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td> <td width="100%"><strong>ACK</strong> = 6<br> <strong>BEL</strong> = 7<br> <strong>BS</strong> = 8<br> <strong>CAN</strong> = 24<br> <strong>CR</strong> = 13<br> <strong>DC1</strong> = 17<br> <strong>DC2</strong> = 18<br> <strong>DC3</strong> = 19<br> <strong>DC4</strong> = 20<br> <strong>DEL</strong> = 127<br> <strong>DLE</strong> = 16<br> <strong>EM</strong> = 25<br> <strong>ENQ</strong> = 5<br> <strong>EOT</strong> = 4<br> <strong>ESC</strong> = 27<br> <strong>ETB</strong> = 23<br> <strong>ETX</strong> = 3<br> <strong>FF</strong> = 12<br> <strong>FS</strong> = 28<br> <strong>GS</strong> = 29<br> <strong>HT</strong> = 9<br> <strong>LF</strong> = 10<br> <strong>NAK</strong> = 21<br> <strong>NL</strong> = 10<br> <strong>NUL</strong> = 0<br> <strong>RS</strong> = 30<br> <strong>SI</strong> = 15<br> <strong>SO</strong> = 14<br> <strong>SOH</strong> = 1<br> <strong>SP</strong> = 32<br> <strong>STX</strong> = 2<br> <strong>SUB</strong> = 26<br> <strong>SYN</strong> = 22<br> <strong>TAB</strong> = 9<br> <strong>US</strong> = 31<br> <strong>VT</strong> = 11<br> <strong>controlnames</strong> = ['NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'HT', 'LF', 'VT', 'FF', 'CR', 'SO', 'SI', 'DLE', 'DC1', 'DC2', 'DC3', ...]</td></tr></table> </body></html>