#!/usr/bin/perl our %parameters; while($para=shift) { $parameters{$1}=$2 if $para =~ /^--(.+)=(.+)$/; $parameters{file}=$para unless $para =~ /^--(.+)=(.+)$/; } find_language($file) unless our $language=$parameters{language}; our $file=$parameters{file}; our $level=0 unless $level=$parameters{level}; comment_code(); sub comment_code() { open(ARQ, $file) or die "File '$file' not found"; for(){ $lines++; $test=$_; chomp($test); unless($test =~ /^\s*#/) { open(RC, "/etc/comentarios") or die "Configuration file '/etc/comments' not found"; for(){ $_ =~ //; $eni=$1; if($_ =~ /<$language>/i and $eni >= $level) { $_ =~ /(.+)<\/expr>/; $expre=$1; chomp($expre); $_ =~ /(.+)<\/coment>/; $comen=$1; chomp($comen); if($test =~ /$expre/) { @vector=split(/\[|\]/, $comen); $i=0; while($vector[$i]){ print $vector[$i].${$vector[$i+1]}; $i+=2; } print "\n"; $comments++; } } } } close RC; print $test."\n"; open(RC, "/etc/comentarios") or die "Configuration file '/etc/comments' not found"; for(){ if($_ =~ /<$language>/i and $_ =~ //i) { $_ =~ /(.*)<\/expr>/; $expre=$1; chomp($expre); $_ =~ /(.*)<\/coment>/; $comen=$1; chomp($comen); if($test =~ /$expre/) { @vector=split(/\[|\]/, $comen); $i=0; while($vector[$i]){ print $vector[$i].${$vector[$i+1]}; $i+=2; } print "\n"; $comments++; } } } close RC; } close ARQ; } sub find_language() { ($arq)=@_; $arq=~/.*\.([a-z]{1,2})/; $ext=$1; open(LIN, "/etc/comenta.conf") or die "Configuration file '/etc/comenta.conf' not found"; for() { $a=$_; chomp($a); our $language=$1 if $a =~ /^(.*)=(\w{1,2},)*$ext,?(\w{1,2},?)*$/; return() if $a =~ /^(.*)=(\w{1,2},)*$ext,?(\w{1,2},?)*$/; $language="" unless $a =~ /^(.*)=(\w{1,2},)*$ext,?(\w{1,2},?)*$/; } close LIN; } #### # If formula '[1]' is true, it executes the next commands if\((.*)\)\ *\{ #\!\/usr\/bin\/perl ####################################################### #\!\/usr\/bin\/perl # Code commented by the script 'comenta' # #!/usr/bin/perl # by Fernando Correa de Oliveira # #!/usr/bin/perl ####################################################### #!/usr/bin/perl #!/usr/bin/perl # If formula '[1]' is true, it executes the next commands ^\s*if\s?\((.*)\)\s*\{? # If formula '[2]' is true, it executes command '[1]' ^\s*(.*)\ if\ ?\(?(.*)\)?\s?; # Unless formula '[1]' is true, it executes the next commands ^\s*unless\ ?\(?(.*)\)?\ *\{ # Unless formula '[2]' is true, it executes command '[1]' ^\s*(.*)\ unless\ ?\(?(.*)\)?\ *; # While expression '[1]' is true... while\s?\((.*)\)\s?\{? # For expression '[1]' for\s?\((.*)\)\s?\{ # '[1]' => the same as: '[2] = [2] + [3]' ((\$\w)+\+=(\d+)) # Opens file '[2]' with the handle '[1]' open\((.*)\ ?\,\ ?(.*)\) # Removes '\n' from the end of variable [1] chomp\((\$.*)\) # Closes file with the handle '[1]' close\(?\ ?(.*)\)?\ ?; # User [1] with UID [3] and home [6] (.*):(x?):(.*):(.*):(.*):(.*):(.*) # For each of the arguments of '[1]' do foreach\ *\((.*)\)\ *{ # For [1] being the same as each one of the arguments in '[2]' do foreach\ *($.*)\ \((.*)\)\ ?{ # '[1]' => from [2] to [3] (([0-9]+)\ ?\.\.\ ?([0-9]+)) # '[1]' receives parameter passed on function call \((\$.*)\)=\@_ # [1] => '[2]' receives the first parameter passed on program call, deleting it. ((\$.*)=shift) # Declaration of local variable '[1]' my\s*(\$\w*); # Declaration of global variable '[1]' our\s*(\$\w*); # [1] => Declaration of local variable '[2]' containing '[3]' (my\s*(\$\w+)=(.*)); # [1] => Declaration of global variable '[2]' containing '[3]' (our\s*(\$\w+)=(.*)); # Declaration of local hash '[1]' my\s*(\%\w+); # Declaration of global hash '[1]' our\s*(\%\w+); # [1] => Value of position '[3]' in hash %[2] (\$(\w+)\{(.+)\}) # return() => Leaves the function return\ ?\(?\ ?\)? # return([1]) => Leaves the function with '[1]' as return value return\ ?\(?\ (.*)\ ?\)? # As the function already says: Uses module '[1]' ^use\s+(.+); ############################### Function '[1]' ####################### ^\s*sub (\w*\(?\)?)\ *\{?$ # [1] => Tests regular expression '[3]' in variable '[2]' \s?((\$\w+)\s?=~\s?(\/.+\/)) # [1] => Recognises any type of space, as whitespace, tab or line break \s?\$\w+\s?=~\s?\/.*(\\s).*\/ # [1] => Recognises any letter \s?\$\w+\s?=~\s?\/.*(\\w).*\/ # [1] => Recognises any word \s?\$\w+\s?=~\s?\/.*(\\W).*\/ # [1] => Recognises any number \s?\$\w+\s?=~\s?\/.*(\\d).*\/ # [1] => Recognises anything between '[2]' and '[3]' \s?\$\w+\s?=~\s?\/.*(\[(\w|\d)\-(\w|\d)\]).*\/ # [1] => The expression '[2]' must appear between [3] and [4] times \s?\$\w+\s?=~\s?\/.*(([\[|\(].+[\]|\)])\{(\d),(\d)\}).*\/ # [1] => The expression '[2]' must appear between [3] and [4] times \s?\$\w+\s?=~\s?\/.*((\\.)\{(\d),(\d)\}).*\/