1# uglyboolhack.pl - Make ncurses header C++ compatible
2# Copyright (c) 2000 Kriang Lerdsuwanakij
3# email:	lerdsuwa@users.sourceforge.net
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
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.
14#
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., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19$prog_name = "uglyboolhack.pl";
20$prog_ver = "1.0.0";
21
22if (@ARGV != 2) {
23	print "$prog_name $prog_ver - Make ncurses header C++ compatible\n";
24	print "usage: perl uglyboolhack.pl INFILE OUTFILE\n";
25	exit 1;
26}
27
28open INFILE, $ARGV[0] or die "$prog_name: error: cannot open $ARGV[0] for reading\n";
29open OUTFILE, ">$ARGV[1]" or die "$prog_name: error: cannot open $ARGV[1] for writing\n";
30print "creating $ARGV[1] from $ARGV[0]\n";
31print OUTFILE "/*\n    Created from $ARGV[0] by $prog_name $prog_ver\n*/\n";
32
33$new_bool_type = "<unknown>";
34while (<INFILE>) {
35	if ($new_bool_type eq "<unknown>") {
36		if (/typedef (.*) bool/) {
37			$new_bool_type = $1;
38		}
39	}
40	else {
41		s/bool/$new_bool_type/g;
42	}
43	print OUTFILE $_;
44}
45
46close INFILE;
47close OUTFILE;
48
49if ($new_bool_type eq "<unknown>") {
50	print "$prog_name: error: bool replacement failed, cannot determine how ncurses defines bool\n";
51	print "$prog_name: error: compiled program will not work properly!\n";
52}
53else {
54	print "bool successfully replaced by $new_bool_type in $ARGV[1]\n";
55}
56