| 1 | # This package assists in handling comments from the control file | ||
| 2 | # of classgen | ||
| 3 | # | ||
| 4 | # Michael Schlueter 5.3.2000 3.00 | ||
| 5 | |||
| 6 | |||
| 7 | # 3.03: | ||
| 8 | # No changes in here 02.10.2000 | ||
| 9 | |||
| 10 | # 3.02: | ||
| 11 | # No changes in here 06.07.2000 | ||
| 12 | |||
| 13 | # 3.01: | ||
| 14 | # removed an error from just_var. this error suppressed most of | ||
| 15 | # the information in the header: section. 19.5.2000 | ||
| 16 | |||
| 17 | package Class::Classgen::Comments; | ||
| 18 | |||
| 19 | $VERSION=3.03; | ||
| 20 | |||
| 21 | use strict; | ||
| 22 | |||
| 23 | sub find { # to find the comments in a line | ||
| 24 | my ($line) = @_; | ||
| 25 | |||
| 26 | $line=~m/(^[^#]*)(.*)/; | ||
| 27 | return ( $1, $2 ); # $1 source text, $2 comments | ||
| 28 | } | ||
| 29 | |||
| 30 | sub repair_header { # to put in missing ';' in the header section | ||
| 31 | my (@code) = @_; # the code edited into the header section | ||
| 32 | my @code2; | ||
| 33 | |||
| 34 | shift @code; # remove fragment | ||
| 35 | foreach (@code) { | ||
| 36 | # next if( $_=~m/:/); # this is an identifier for the sect. | ||
| 37 | unless ( $_=~m/;/ ) { # then find insertion point | ||
| 38 | if($_=~m/#/){ # case where comment is present | ||
| 39 | $_=m/(^.*)(\s*)#(.*)/; | ||
| 40 | push @code2, ($1 . $2 . ";#$3\n"); | ||
| 41 | }else{ # case without comment | ||
| 42 | chomp; | ||
| 43 | push @code2, ($_ . ";\n"); | ||
| 44 | } | ||
| 45 | } else { # case with ; and eventually comment | ||
| 46 | push @code2, $_; # use original code | ||
| 47 | } | ||
| 48 | } | ||
| 49 | return @code2; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub just_comments { # to extract just the comments themselves | ||
| 53 | my ($line) = @_; # some line of code | ||
| 54 | |||
| 55 | $line =~ m/.*(#.*)/; | ||
| 56 | if($1){ return $1; } else { return ''; }; | ||
| 57 | } | ||
| 58 | |||
| 59 | sub just_var { # to extract just the variable itself | ||
| 60 | my ($var) = @_; # the variable plus eventualy comments | ||
| 61 | |||
| 62 | $var =~ m/([\$\%\@]\w+)/; | ||
| 63 | # if($1){ return $1; } else { return ''; }; # 3.00 error ! | ||
| 64 | if($1){ return $1; } else { return $var; }; # 3.01 | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | 1; | ||
| 69 | |||
| 70 | __END__ |