4 # This program corrects illegal lines introduced by the #14635 bug.
6 # Author:: Daigo Moriwaki <daigo at debian dot org>
7 # Copyright:: Copyright (C) 2008 Daigo Moriwaki <daigo at debian dot org>
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 # correct-bug14635.rb [OPTIONS] DIR ...
32 # do not modify files, but show what will happen
43 def initialize(file_path)
52 data = NKF.nkf("-e", @file.read)
53 data.each_line do |line|
56 puts "Found an empty line"
60 @lines << line.gsub(/%%TORYO/, "%TORYO")
64 @lines << line.gsub(/%%KACHI/, "%KACHI")
75 backup_name = @file.to_s + ".back"
76 FileUtils.cp @file, backup_name
77 @file.open("w") {|f| f.write @lines.join}
84 puts "Usage: #{$0} [OPTIONS] dir [...]"
86 puts " --dry-run do not modify files, but show what to do"
92 parser = GetoptLong.new(
93 ['--dry-run', GetoptLong::NO_ARGUMENT]
96 parser.each_option do |name, arg|
97 eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_').upcase} = '#{arg}'"
103 while dir = ARGV.shift
104 Dir.glob(File.join(dir, "**", "*.csa")).each do |file|
105 path = Pathname.new(file)
106 csa = CheckCsaFile.new(path)