Skip to content

Instantly share code, notes, and snippets.

@chikuchikugonzalez
Created January 13, 2013 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chikuchikugonzalez/4524808 to your computer and use it in GitHub Desktop.
Save chikuchikugonzalez/4524808 to your computer and use it in GitHub Desktop.
MUGEN用tagsファイル作成スクリプト。 ステート番号をタグ扱いにしてます。
#!ruby
# -*- coding: utf-8 -*-
tags = {
}
tagfile = nil
section_pattern = /\s*\[\s*(statedef)\s+((-+)?\d+)\].*$/i
ARGV.each do |arg|
Dir.glob(arg) do |path|
File.binread(path).split(%r{\r\n|\r|\n}).each_with_index do |line, lineno|
match = line.match(section_pattern)
if match
tagname = match[2].to_i
unless taglist.has_key?(tagname)
tags[tagname] = []
end
tags[tagname] << "#{arg}\t#{lineno + 1}"
#tagfile.puts "#{tagname}\t#{arg}\t#{lineno}"
end
end
end
end
begin
tagfile = File.open("tags", "wb")
tags.keys.sort.each do |key|
tags[key].each do |value|
tagfile.puts "#{key}\t#{value}"
end
end
ensure
if tagfile != nil
tagfile.close
end
end
# vim: set sts=2 ts=2 sw=2 expandtab:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment