Sha256: 42da8d22bd5cfb4d0f7ff3b96620ea13ef0d578d72cfa6b90f74473960ce7b08
Contents?: true
Size: 949 Bytes
Versions: 52
Compression:
Stored size: 949 Bytes
Contents
#!/usr/bin/env ruby # # Copyright (C) 2004 Satoru Takabayashi <satoru@namazu.org> # You can redistribute it and/or modify it under GPL2. # puts "Usage: tdiary-comment-clean PATTERN FILE..." if ARGV.length == 0 pattern = Regexp.new(ARGV.shift) file_names = ARGV deleted_comments = [] file_names.each {|file_name| i = File.open(file_name) first_line = i.gets comments = [] comment = "" while line = i.gets if line == ".\n" comments.push(comment) comment = "" else comment << line end end i.close tmp_name = "tmp.#{Process.pid}" File.open(tmp_name, "w") {|o| o.print first_line comments.each {|comment| if pattern.match(comment) deleted_comments.push(comment) else o.print comment o.puts "." end } } File.rename(file_name, file_name + ".bak") File.rename(tmp_name, file_name) } deleted_comments.each {|comment| print comment puts "." }
Version data entries
52 entries across 46 versions & 2 rubygems