File indexing completed on 2024-04-21 04:47:54

0001 #!/usr/bin/ruby
0002 ###########################################################################
0003 #   Parses the Amarok debug log and prints methods which have unbalanced  #
0004 #   BEGIN and END. This script only works for those methods with a        #
0005 #   DEBUG_BLOCK.                                                          #
0006 #                                                                         #
0007 #   Copyright                                                             #
0008 #   (C) 2010 Casey Link <unnamedrambler@gmail.com>                        #
0009 #                                                                         #
0010 #   This program is free software; you can redistribute it and/or modify  #
0011 #   it under the terms of the GNU General Public License as published by  #
0012 #   the Free Software Foundation; either version 2 of the License, or     #
0013 #   (at your option) any later version.                                   #
0014 #                                                                         #
0015 #   This program is distributed in the hope that it will be useful,       #
0016 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
0017 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
0018 #   GNU General Public License for more details.                          #
0019 #                                                                         #
0020 #   You should have received a copy of the GNU General Public License     #
0021 #   along with this program; if not, write to the                         #
0022 #   Free Software Foundation, Inc.,                                       #
0023 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         #
0024 ###########################################################################
0025 
0026 # Use: cat amarok.log | beginend.rb
0027 
0028 input = STDIN.read
0029 stack = []
0030 
0031 input.each_line do |line|
0032     begins = line.scan(/amarok:\s+BEGIN: (.*)/)
0033     if begins[0] != nil
0034       stack.push(begins[0][0].strip)
0035     end
0036     ends = line.scan(/amarok:\s+END__: (.*) - (.*)/)
0037     if ends[0] != nil 
0038       if !stack.include? ends[0][0].strip
0039         # could this ever happen?
0040         puts "Method ended but not begun: #{ends[0][0]}"
0041       else
0042         # only delete the most recent matching block
0043         last = stack.rindex(ends[0][0].strip)
0044         stack.delete_at(last)
0045       end
0046     end
0047 end
0048 
0049 # Any remaining methods blocks will be unbalanced
0050 stack.each do |block|
0051   puts "Not ended: #{block}"
0052 end
0053 
0054 puts "Done."
0055