<commit_before>#!/usr/bin/perl -w

# qtguess.pl : check how Qt was compiled. Issue a list of all defined QT_NO_* macros, one per line.
#
# author:  <NAME> <<EMAIL>>
# licence: GPL v.2

# options: -q: be quieter
#	   -o file: redirect output to "file". (default: ./qtdefines)
#	   -p path: path to the Qt directory
#	   -t [0..15]: set the testing treshold (see below)
#	   -f "flags": additional compiler flags/parameters

use Getopt::Std;

use vars qw/$opt_f $opt_o $opt_p/;

getopts('qo:f:t:p:');

# Treshold :
#	 0 - test basic Qt types/classes
#	 5 - test higher level, non-gui classes
#	 8 - test options of the above (ex: QT_NO_IMAGE_SMOOTHSCALE)
#	10 - test basic widgets
#	12 - test composite widgets
#	13 - test widgets inheriting composite widgets
#	15 - test goodies (default)

my $default_treshold = 15;
my $cc = "g++";
my $ccflags = $opt_f || "";

my $tmp = gettmpfile();
my $qtdir = $opt_p || $ENV{'QTDIR'};
 -e "$qtdir/include/qapplication.h" or die "Invalid Qt directory. Use -p or set \$QTDIR\n";

my $ccmd = "$cc  -o $tmp $tmp.cpp -I$qtdir/include -L$qtdir/lib -lqt-mt $ccflags 2>/dev/null";

my $treshold = defined($opt_t)?$opt_t : $default_treshold;
$treshold >= 0 or die "invalid testing treshold: $treshold\n";

print "Checking how Qt was built... \n";
print "Treshold is set to $treshold\n" unless $opt_q;

my($count, $used, $total);
map{ $tests{$_}->[2]>=$treshold ? ($used++, $total++):$total++ } keys %tests;

print "Number of defines to be tested : $used/$total\n\n" unless $opt_q;
open( QTDEFS, ">".($opt_o || "qtdefines") ) or die "Can't open output file: $!\n";

preliminary_test();
perform_all_tests();

print +scalar(@qtdefs) . " defines found.\n";

print QTDEFS join("\n", @qtdefs), "\n";
close;

#--------------------------------------------------------------#

sub gettmpfile
{
	my $tmpdir = $ENV{'TMP'} || ".";
	my $tmpname = $$."-qtguess";
	while( -e "$tmpdir/$tmpname" || -e "$tmpdir/${tmpname}.cpp" )
	{
		$tmpname .= int (rand * 9);
	}
	return "$tmpdir/$tmpname";
}

#--------------------------------------------------------------#

sub preliminary_test
{
	print "Trying to compile and link a small program...\t";
	open( OUT, ">${tmp}.cpp" ) or die "Failed to open temp file ${tmp}.cpp: $!\n";
	my $simple=q
		#include <qapplication.h>
		int main( int argc, char **argv )
		{
			QApplication foo( argc, argv );
			return 0;
		}
	;
	print OUT $simple;
	close OUT;
	my $a = system($ccmd);
	if( $a)
	{
		die "FAILED : check your configuration.\nFailed program was: $simple";
	}
	else
	{
		print "OK\n";
	}
}

#--------------------------------------------------------------#

sub perform_all_tests
{
	foreach ( sort { $tests{$a}->[2] <=> $tests{$b}->[2]} keys %tests)
	{
		$tests{$_}->[2] < $treshold and next;
		print "\rTesting $_".( " " x (40 - length($_)) );
		open( OUT, ">${tmp}.cpp" ) or die "Failed to open temp file ${tmp}.cpp: $!\n";
		foreach $def(@qtdefs)
		{
			print OUT "#define $def\n";
		}
		foreach $inc(split /,\s*/, $tests{$_}->[0])
		{
			print OUT "#include <$inc>\n";
		}
		print OUT "#include <qfeatures.h>\n";
		print OUT $tests{$_}->[3] if $tests{$_}->[3]; # need to define some classes ?
		print OUT qq

		int main( int argc, char **argv )
		{
		$tests{$_}->[1]
		return 0;
		}
		;
		close OUT;
		my $a = system($ccmd);

		push (@qtdefs, $_) if $a;
		print +$opt_q ? ++$count."/$used" : ($a ? " [Defined]\n" : "*Undefined*\n" );
	}
	$opt_q && print "\n";
}

#--------------------------------------------------------------#

END
{
	unlink $tmp if -e $tmp;
	unlink "${tmp}.cpp" if -e "${tmp}.cpp";<commit_msg>Added checking of symbols already defined/undefined by global.h<commit_after>#!/usr/bin/perl -w

# qtguess.pl : check how Qt was compiled. Issue a list of all defined QT_NO_* macros, one per line.
#
# author:  <NAME> <<EMAIL>>
# licence: GPL v.2

# options: -q: be quieter
#	   -o file: redirect output to "file". (default: ./qtdefines)
#	   -p path: path to the Qt directory
#	   -t [0..15]: set the testing treshold (see below)
#	   -f "flags": additional compiler flags/parameters

use Getopt::Std;

use vars qw/$opt_f $opt_o $opt_p/;

getopts('qo:f:t:p:');

# Treshold :
#	 0 - test basic Qt types/classes
#	 5 - test higher level, non-gui classes
#	 8 - test options of the above (ex: QT_NO_IMAGE_SMOOTHSCALE)
#	10 - test basic widgets
#	12 - test composite widgets
#	13 - test widgets inheriting composite widgets
#	15 - test goodies (default)

my $default_treshold = 15;
my $cc = "g++";
my $ccflags = $opt_f || "";

my $nspaces = 50;

my %qtdefs=();
my %qtundefs=();

my $tmp = gettmpfile();
my $qtdir = $opt_p || $ENV{'QTDIR'};
my $qtinc = $qtdir . "/include";
 -e "$qtdir/include/qglobal.h" or die "Invalid Qt directory. Use -p or set \$QTDIR\n";

my $ccmd = "$cc  -o $tmp $tmp.cpp -I$qtdir/include -L$qtdir/lib -lqt-mt $ccflags 2>/dev/null";

my $treshold = defined($opt_t)?$opt_t : $default_treshold;
$treshold >= 0 or die "invalid testing treshold: $treshold\n";

print "Checking how Qt was built... \n";
print "Treshold is set to $treshold\n" unless $opt_q;

my($count, $used, $total);
map{ $tests{$_}->[2]>=$treshold ? ($used++, $total++):$total++ } keys %tests;

print "Number of defines to be tested : $used/$total\n\n" unless $opt_q;
open( QTDEFS, ">".($opt_o || "qtdefines") ) or die "Can't open output file: $!\n";

grab_qglobal_symbols();
preliminary_test();
perform_all_tests();

print +scalar(keys %qtdefs) . " defines found.\n";

print QTDEFS join("\n", keys %qtdefs), "\n";
close;

#--------------------------------------------------------------#

sub gettmpfile
{
	my $tmpdir = $ENV{'TMP'} || ".";
	my $tmpname = $$."-qtguess";
	while( -e "$tmpdir/$tmpname" || -e "$tmpdir/${tmpname}.cpp" )
	{
		$tmpname .= int (rand * 9);
	}
	return "$tmpdir/$tmpname";
}

#--------------------------------------------------------------#

sub grab_qglobal_symbols
{
	my $cmd = "$cc -E -D__cplusplus -dM -I$qtinc $qtinc/qglobal.h 2>/dev/null";
	my $symbols = `$cmd`;
	if( check_exit_status($?) )
	{
		while( $symbols =~/^#\s*define\s*(QT_NO_\S+)/gm )
		{
			$qtdefs{$1} = 1;
		}
		print "Found ". scalar( keys %qtdefs )." predefined symbol".((scalar( keys %qtdefs ) -1)?"s":"")." in qglobal.h\n" unless ($opt_q or !(keys %qtdefs));
		while( $symbols =~/^#\s*define\s*QT_MODULE_(\S+)/gm )
		{
			$qtundefs{"QT_NO_$1"} = 1;
		}
		print "Found ". scalar( keys %qtundefs )." undefined symbol".((scalar( keys %qtundefs ) -1)?"s":"")." in qglobal.h\n" unless ($opt_q or !(keys %qtundefs));

	}
	else
	{
		die "Failed to run $cmd.\n";
	}
}

#--------------------------------------------------------------#

sub preliminary_test
{
	my $msg = "Trying to compile and link a small program...";
	print $msg, " " x ($nspaces - length($msg) + 8);
	open( OUT, ">${tmp}.cpp" ) or die "Failed to open temp file ${tmp}.cpp: $!\n";
	my $simple=q
		#include <qapplication.h>
		int main( int argc, char **argv )
		{
			QApplication foo( argc, argv );
			return 0;
		}
	;
	print OUT $simple;
	close OUT;
	my $a = system($ccmd);
	if( !check_exit_status($a) )
	{
		die "\nFAILED : check your configuration.\nFailed program was: $simple";
	}
	else
	{
		print "OK\n";
	}
}

#--------------------------------------------------------------#

sub perform_all_tests
{
	foreach ( sort { $tests{$a}->[2] <=> $tests{$b}->[2]} keys %tests)
	{
		$tests{$_}->[2] < $treshold and next;
		($qtdefs{$_} || $qtundefs{$_}) and do
		{
			print "\rSkipping $_ (in qglobal.h)".( " " x (($nspaces-14) - length($_)) ).($qtundefs{$_}?"*Undefined*":" [Defined]").($opt_q?"":"\n");
			next
		};
		print "\rTesting $_".( " " x ($nspaces - length($_)) );
		open( OUT, ">${tmp}.cpp" ) or die "Failed to open temp file ${tmp}.cpp: $!\n";
		foreach $def(keys %qtdefs)
		{
			print OUT "#define $def\n";
		}
		foreach $inc(split /,\s*/, $tests{$_}->[0])
		{
			print OUT "#include <$inc>\n";
		}
		print OUT "#include <qfeatures.h>\n";
		print OUT $tests{$_}->[3] if $tests{$_}->[3]; # need to define some classes ?
		print OUT qq

		int main( int argc, char **argv )
		{
		$tests{$_}->[1]
		return 0;
		}
		;
		close OUT;

		my $ok = check_exit_status( system($ccmd) );
		if( !$ok )
		{
			$qtdefs{$_} = 1;
		}
		print +$opt_q ? ++$count."/$used" : ( $ok ? "*Undefined*\n" : " [Defined]\n" );
	}
	$opt_q && print "\n";
}

#--------------------------------------------------------------#

sub check_exit_status
{
	my $a = 0xFFFF & shift;
	if( !$a )
	{
		return 1;
	}
	elsif( $a == 0xFF00 )
	{
		die "\nSystem call failed: $!\n";
	}
	elsif( $a > 0x80 )
	{
		# non-zero status.
	}
	else
	{
		if( $a & 0x80 )
		{
			die "\n$cc coredumped with signal ". ($a & ~0x80);
		}
		die "\n$cc interrupted by signal $a\n";
	}
	return 0;
}

#--------------------------------------------------------------#

END
{
	unlink $tmp if -e $tmp;
	unlink "${tmp}.cpp" if -e "${tmp}.cpp";
{'fraction_non_alphanumeric': 0.26411015020482476, 'fraction_numerical': 0.010241238051888939, 'mean_word_length': 2.532556270096463, 'pattern_counts': {'":': 6, '<': 19, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4687619', 'n_tokens_mistral': 3579, 'n_tokens_neox': 3377, 'n_words': 927}