5 my $diacodefile = $ARGV[0];
6 my $subcodefile = $ARGV[1];
7 my $use_debug_class = @ARGV > 2 ?
$ARGV[2] : 1;
9 print "$diacodefile does not exist\n" unless ( -e
$diacodefile );
10 print "$subcodefile does not exist\n" unless ( -e
$subcodefile );
12 open ( DIACODE
, $diacodefile );
13 my @diacode = <DIACODE
>;
16 open ( SUBCODE
, $subcodefile );
17 my @subcode = <SUBCODE
>;
20 open ( NEWCODE
, '>tmp.txt' );
23 my $diacode_line_number = 1;
29 my ( $junk, $junk2, $sub );
33 foreach ( @diacode ) {
34 $diacode_line_number ++;
37 foreach ( @subcode ) {
38 next unless ( /\s*start include statements/ or $in_sub );
39 if ( /\s*start include statements/ ) {
43 if ( /\s*end include/ ) {
45 push( @include, "use debug;\n" ) unless( $package eq 'debug.pm' or ! $use_debug_class );
48 push ( @include, $_ );
52 die "Warning, no end of include statements found in $subcodefile \n";
55 $diacode_line_number += scalar( @include ) + 1;
56 print NEWCODE
@include, "\n";
61 ($junk, $package, $junk2) = split(' ', $_, 3);
67 ($junk, $sub, $junk2) = split(' ', $_, 3);
70 if( /# Start of Non-Dia code #/ ) {
72 foreach ( @subcode ) {
74 next unless ( /\s*start $sub\s*$/ or $in_sub );
75 if ( /\s*start $sub\s*$/ ) {
77 if( $package ne 'debug' and $use_debug_class ) {
78 if ( $sub eq 'new' ) {
79 push( @transfer, ' \'debug\' -> warn(level => 3, message => "Entering \t" . ref($this). \'-> '.$sub."\');\n" );
81 push( @transfer, ' \'debug\' -> warn(level => 3, message => "Entering \t" . ref($self). \'-> '.$sub."\');\n" );
84 push ( @transfer,"# line $line_number \"$subcodefile\" \n" );
87 if ( /\s*end $sub\s*$/ ) {
89 $diacode_line_number += scalar( @transfer ) + 1;
90 my $local_diacode_file = $diacodefile;
91 $local_diacode_file =~ s/_temp//;
92 push ( @transfer,"# line $diacode_line_number $local_diacode_file \n" );
93 if( $package ne 'debug' and $use_debug_class ) {
94 $diacode_line_number ++;
95 if ( $sub eq 'new' ) {
96 push( @transfer, ' \'debug\' -> warn(level => 3, message => "Leaving \t" . ref($this). \'-> '.$sub."\');\n" );
98 push( @transfer, ' \'debug\' -> warn(level => 3, message => "Leaving \t" . ref($self). \'-> '.$sub."\');\n" );
103 push ( @transfer, $_ );
108 if ( /# End of Non-Dia code #/ ) {
110 print NEWCODE
@transfer;
118 system( "mv tmp.txt $diacodefile" );