Move backspace handling to base class for all languages

This commit is contained in:
Pragmatic Software 2015-04-16 03:12:07 -07:00
parent 0d69796e6f
commit ef22f9578d
3 changed files with 19 additions and 42 deletions

View File

@ -202,7 +202,7 @@ sub preprocess_code {
my $has_main = 0;
my $prelude = '';
while($precode =~ s/^\s*(#.*\n{1,2})//g) {
while($precode =~ s/^\s*(#.*\n{1,2}|using.*\n{1,2})//g) {
$prelude .= $1;
}
@ -417,6 +417,8 @@ sub postprocess_output {
$output =~ s/ called by gdb \(\) at statement: void gdb\(\) { __asm__\(""\); }//g;
$output =~ s/called by \?\? \(\) //g;
$output =~ s/\s0x[a-z0-9]+: note: pointer points here.*?\^//gms;
$output =~ s/\s0x[a-z0-9]+: note: pointer points here\s+<memory cannot be printed>//gms;
$output =~ s/store to address 0x[a-z0-9]+ with insufficient space/store to location with insufficient space/gms;
my $removed_warning = 0;
@ -431,22 +433,6 @@ sub postprocess_output {
$output =~ s/^\[\s+(warning:|info:)/[$1/; # remove leading spaces in first warning/info
# backspace
my $boutput = "";
my $active_position = 0;
$output =~ s/\n$//;
while($output =~ /(.)/gms) {
my $c = $1;
if($c eq "\b") {
if(--$active_position <= 0) {
$active_position = 0;
}
next;
}
substr($boutput, $active_position++, 1) = $c;
}
$output = $boutput;
if($self->{warn_unterminated_define} == 1) {
if($output =~ m/^\[(warning:|info:)/) {
$output =~ s/^\[/[warning: preprocessor directive not terminated by \\n, the remainder of the line will be part of this directive /;

View File

@ -133,6 +133,22 @@ sub postprocess_output {
print FILE "$self->{output}\n";
close FILE;
}
# backspace
my $boutput = "";
my $active_position = 0;
$self->{output} =~ s/\n$//;
while($self->{output} =~ /(.)/gms) {
my $c = $1;
if($c eq "\b") {
if(--$active_position <= 0) {
$active_position = 0;
}
next;
}
substr($boutput, $active_position++, 1) = $c;
}
$self->{output} = $boutput;
}
sub show_output {

View File

@ -256,29 +256,4 @@ sub preprocess_code {
print "final code: [$self->{code}]\n" if $self->{debug};
}
sub postprocess_output {
my $self = shift;
$self->SUPER::postprocess_output;
my $output = $self->{output};
# backspace
my $boutput = "";
my $active_position = 0;
$output =~ s/\n$//;
while($output =~ /(.)/gms) {
my $c = $1;
if($c eq "\b") {
if(--$active_position <= 0) {
$active_position = 0;
}
next;
}
substr($boutput, $active_position++, 1) = $c;
}
$output = $boutput;
$self->{output} = $output;
}
1;