1
#!/usr/bin/ruby
2
###########################################################################
3
#   This script puts a DEBUG_BLOCK in every method of a given C++ file.   #
4
#   Use with caution.                                                     #
5
#                                                                         #
6
#   Copyright                                                             #
7
#   (C) 2008 Casey Link <unnamedrambler@gmail.com>                        #
8
#                                                                         #
9
#   This program is free software; you can redistribute it and/or modify  #
10
#   it under the terms of the GNU General Public License as published by  #
11
#   the Free Software Foundation; either version 2 of the License, or     #
12
#   (at your option) any later version.                                   #
13
#                                                                         #
14
#   This program is distributed in the hope that it will be useful,       #
15
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
16
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
17
#   GNU General Public License for more details.                          #
18
#                                                                         #
19
#   You should have received a copy of the GNU General Public License     #
20
#   along with this program; if not, write to the                         #
21
#   Free Software Foundation, Inc.,                                       #
22
#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         #
23
###########################################################################
24
25
if ARGV.size < 1
26
  print "USAGE: #{__FILE__} <filename> \n"
27
  exit
28
end
29
30
regex = Regexp.new(/^.+::(.+)\(.*\)\s*(?:const)*\s*(?::\s*(?:\s*.+\(.*\))*)*\s*\{\s*(?:DEBUG_BLOCK)*/)
31
f = File.new(ARGV[0])
32
string = f.read
33
news = string.gsub(regex){ |s|
34
  if not s.include? "DEBUG_BLOCK"
35
    "#{$&}\n\tDEBUG_BLOCK\n"
36
  else
37
    $&
38
  end
39
}
40
print news