[PATCH] parser.c cleanup
[smatch.git] / cgcc
blob9cfdf7b7002bd7ec8fd43744321262a5d5c9a4a6
1 #!/usr/bin/perl -w
2 # -----------------------------------------------------------------------------
4 my $cc = $ENV{'REAL_CC'} || 'cc';
5 my $check = $ENV{'CHECK'} || 'check';
7 my $seen_a_c_file = 0;
8 foreach (@ARGV) {
9 # Look for a .c file. We don't want to run the checker on .o or .so files
10 # in the link run. (This simplistic check knows nothing about options
11 # with arguments, but it seems to do the job.)
12 $seen_a_c_file = 1 if /^[^-].*\.c/;
14 my $this_arg = ' ' . &quote_arg ($_);
15 $cc .= $this_arg unless &check_only_option ($_);
16 $check .= $this_arg;
19 system ($check) if $seen_a_c_file;
20 exec ($cc);
22 # -----------------------------------------------------------------------------
23 # Check if an option is for "check" only.
25 sub check_only_option {
26 my ($arg) = @_;
27 return 1 if $arg =~ /^-W(no-?)?default-bitfield-sign$/;
28 return 0;
31 # -----------------------------------------------------------------------------
32 # Simple arg-quoting function. Just adds backslashes when needed.
34 sub quote_arg {
35 my ($arg) = @_;
36 return "''" if $arg eq '';
37 return join ('',
38 map {
39 m|^[-a-zA-Z0-9._/,=]+$| ? $_ : "\\" . $_;
40 } (split (//, $arg)));
43 # -----------------------------------------------------------------------------