Mercurial > hg > CbC > CbC_xv6
changeset 278:9cbd1ecac10d tobaru-master
merged
author | anatofuz |
---|---|
date | Sat, 08 Feb 2020 15:50:02 +0900 |
parents | 5854cbf18c67 (current diff) 793a266bf3c7 (diff) |
children | 03be5144b072 |
files | |
diffstat | 1 files changed, 34 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gearsTools/trans_impl.pl Sat Feb 08 15:49:00 2020 +0900 +++ b/src/gearsTools/trans_impl.pl Sat Feb 08 15:50:02 2020 +0900 @@ -23,12 +23,19 @@ my $stdout = *STDOUT; if ($opt{w}) { + if(-f $output_file) { + update_file($output_file, $inter_ir, $impl_ir, $impl_file); + exit 0; + } open $stdout, '>', $output_file; } elsif ($opt{o}) { + if(-f $opt{o}) { + update_file($opt{o}, $inter_ir, $impl_ir, $impl_file); + exit 0; + } open $stdout, '>', $opt{o}; } - emit_include_part($stdout, $inter_ir->{name}); emit_impl_header_in_comment($stdout, $impl_file); emit_constracutor($stdout,$impl_ir,$inter_ir); @@ -177,3 +184,29 @@ } print $out "}\n\n"; } + +sub update_file { + my ($output_file, $inter_ir, $impl_ir, $impl_file) = @_; + my $under_code = collection_save_code_gears($output_file,$inter_ir->{name}); + open my $fh, '>', $output_file; + emit_include_part($fh, $inter_ir->{name}); + emit_impl_header_in_comment($fh, $impl_file); + emit_constracutor($fh,$impl_ir,$inter_ir); + map { print $fh $_ } @{$under_code}; + close $fh; +} + +sub collection_save_code_gears { + my ($output_file,$interface_name) = @_; + open my $fh, '<', $output_file; + while (my $line = <$fh>) { + if ($line =~ /\s*return $interface_name;\s*/) { + $line = <$fh>; # } skip... + last; + } + } + + my @res; + push(@res, <$fh>); + return \@res; +}