diff options
author | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2001-11-20 01:50:59 +0000 |
---|---|---|
committer | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2001-11-20 01:50:59 +0000 |
commit | edad2ed80a6c0536014fde17171481c65fcd1c39 (patch) | |
tree | 78e4fa0f65cb6b2247cab9e08f9252f3697f2034 | |
parent | 8140e77075a3a4c4c3b9ba453928d2a336012573 (diff) |
Now allows whitespace between macro name and arguments.
Better handling of things in strings.
Still doesn't work for ADM, so I was obviously too optinmistic in my
last commit; you probably don;t want to use it yet.
Tom
git-svn-id: http://svn.cactuscode.org/flesh/trunk@2467 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rwxr-xr-x | lib/sbin/cpp.pl | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/lib/sbin/cpp.pl b/lib/sbin/cpp.pl index 17d7ede7..ca96a8fa 100755 --- a/lib/sbin/cpp.pl +++ b/lib/sbin/cpp.pl @@ -846,27 +846,48 @@ sub SplitArgs my @thistoken = (); + my $insstring = 0; + my $indstring = 0; + for(my $pos = 0; $pos < @splitargs; $pos++) { - # Now split at , at the top level - if($splitargs[$pos] eq "(") + if($splitargs[$pos] eq '\'' || $splitargs[$pos] eq '"' || + $insstring == 1 || $indstring == 1) + { + # Just pass the token through if in a string. + if($splitargs[$pos] eq '\'') + { + if($pos == 0 || ($pos > 0 && $splitargs[$pos-1] ne '\\')) + { + $insstring = 1 - $insstring; + } + } + if($splitargs[$pos] eq '"') + { + if($pos == 0 || ($pos > 0 && $splitargs[$pos-1] ne '\\')) + { + $indstring = 1 - $indstring; + } + } + } + elsif($splitargs[$pos] eq "(") { + # Increase nesting level $nestlevel++; } elsif($splitargs[$pos] eq ")") { - $nestlevel++; + # Decrease nesting level + $nestlevel--; } elsif($splitargs[$pos] eq "," && $nestlevel == 0) { + # At top level, and not in a string, so must be end of this arg. push(@outargs, join("",@thistoken)); @thistoken = (); next; } - else - { - push(@thistoken, $splitargs[$pos]); - } + push(@thistoken, $splitargs[$pos]); } # Push any remaining token @@ -928,6 +949,20 @@ sub ParseAndExpand my $arg = ""; if($pos+1 < @splitline) { + # Eat up whitepace between token and arguments + for(my $newpos=$pos+1; $newpos < @splitline; $newpos++) + { + next if($splitline[$newpos] =~ m/\s/); + if($splitline[$newpos] eq "(") + { + $pos = $newpos-1; + last; + } + else + { + last; + } + } # Find any arguments if($splitline[$pos+1] eq "(") { @@ -998,19 +1033,27 @@ sub ArgumentSubstitute my @splitbody = split(//,$body); my @outbody = (); - my $instring = 0; + my $insstring = 0; + my $indstring = 0; for(my $pos = 0 ; $pos < @splitbody; $pos++) { # Just pass through all non-tokens and all tokens in a string. - if($splitbody[$pos] !~ m/[A-Za-z_]/ || $instring == 1) + if($splitbody[$pos] !~ m/[A-Za-z_]/ || $insstring == 1 || $indstring == 1) { + if($splitbody[$pos] eq '\'') + { + if($pos == 0 || ($pos > 0 && $splitbody[$pos-1] ne '\\')) + { + $insstring = 1 - $insstring; + } + } if($splitbody[$pos] eq '"') { if($pos == 0 || ($pos > 0 && $splitbody[$pos-1] ne '\\')) { - $instring = 1 - $instring; + $indstring = 1 - $indstring; } } push(@outbody, $splitbody[$pos]); |