#!perl use 5.10.0; use re 'eval'; use strict; use warnings; use HTML::Entities qw/encode_entities decode_entities/; use DefineAnalyser; our $parens; $parens = qr{ (?: (?: [^()](?!<_MY_STRING_TO_REPLACE>) )+ | \( (??{$parens}) \) )* }x; sub initDefinesList { my %args = @_; my $filename = $args{-filename}; my $rresult_list; # if(!open FH, $filename) # { # print STDERR "Couldn't open define base($filename): ", $!; # return (); # } # # my $str = join"", ; # close FH; my $str = "#define abc(def) /*sourcepath: abc.h*/\\\n def*2+5\n"x 10000; my $begintime=time; print STDERR "begin:", $begintime, "\n"; while($str =~ /\#define \s+ (?\w+) (?

\([^)]*\))? (?(.*\\\n)*.*\n)/gx) { my ($name, $params, $content) = ($+{n}, $+{p}, $+{c}); if(!defined($params)) { $params='' } $content =~ s/\\\n/\n/g; $content =~ s/^\s+//; $content =~ s/\s+$//; $content =~ s!(/\*sourcepath: .*?\*/)!!; my $source = $1; my @params = $params=~/\w+/g; my $macro_def = $name; my $pattern = "\\b$name\\b"; if(@params>0) { $macro_def .= '('.join(', ', @params).')'; $pattern .= qr{\((?

$parens)\)}; } else { $pattern .= qr{(\(\s*\))?}; } my $balloon = genDivBalloon( -divid => $name, -sourcefilename => $source, -macrodefinition => $macro_def, -balloontext => $content ); push @$rresult_list, { source=>$source, name=>$name, params=>[@params], content=>$content, macro_def => $macro_def, pattern => $pattern, balloon => $balloon }; } my $endtime=time; print STDERR "end:", $endtime, "\n"; print STDERR "total time: ", $endtime-$begintime, "\n"; return $rresult_list } sub genDivBalloon { my %args = @_; my ($divid, $sourcefilename, $macro_def, $balloontext) = @args{-divid, -sourcefilename, -macrodefinition, -balloontext}; if(!defined $divid) { say STDERR "divid not defined" } if(!defined $sourcefilename) { say STDERR "$divid: sourcefilename not defined" } if(!defined $macro_def) { say STDERR "$divid: macro_def not defined" } if(!defined $balloontext) { say STDERR "$divid: balloontext not defined" } return "

" . encode_entities($sourcefilename) . "
#define " . $macro_def . "
"
				. encode_entities($balloontext)
				. "
"; } initDefinesList(-filename => 'all_defines_tidy.txt'); __DATA__ #define _APS_NEXT_COMMAND_VALUE 32768 /*sourcepath: ./src/Resource.h*/ #define _APS_NEXT_CONTROL_VALUE 201 /*sourcepath: ./src/Resource.h*/ #define COUNT_STR_LEN_FROM_BSRELAYDATA(start, count) /*sourcepath: ./src/ImplXX.cpp*/\ count = 0; \ for (i = start; i < bsRelayData.data.length && \ i < bsRelayData.data.MAX_LENGTH_C && \ bsRelayData.data.user_data[i] != 0; i++) \ { \ count++; \ } \ dwCountStart += count+1;