# HG changeset patch # User anatofuz # Date 1581144602 -32400 # Node ID 9cbd1ecac10dbb7fbace556a763e4ae431a3f68d # Parent 5854cbf18c67585845f564e27196346ec393b844# Parent 793a266bf3c7c10046b4417de00a68a5c40357ba merged diff -r 5854cbf18c67 -r 9cbd1ecac10d src/gearsTools/trans_impl.pl --- 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; +}