rrse 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+ require "optparse"
3
+ require "bitclust"
4
+ require "pathname"
5
+
6
+ def dbpath_from_config_file(path, version)
7
+ path ||= ENV['HOME'] + "/.bitclust/config"
8
+ if File.exist?(path)
9
+ config = YAML.load_file(path)
10
+ version ||= config[:default_version]
11
+ "#{config[:database_prefix]}-#{version}"
12
+ else
13
+ nil
14
+ end
15
+ end
16
+
17
+ reverse = false
18
+ db_path = nil
19
+ config_path = nil
20
+ version = nil
21
+
22
+ opt = OptionParser.new
23
+ opt.on("-r") { reverse = true }
24
+ opt.on("-c CONFIG-FILE"){|path| config_path = path }
25
+ opt.on("-d PATH") {|path| db_path = path}
26
+ opt.on("--version VERSION"){|ver| version = ver }
27
+
28
+ opt.parse!(ARGV)
29
+
30
+ db_path ||= dbpath_from_config_file(config_path, version)
31
+
32
+ if db_path.nil?
33
+ print opt.help
34
+ exit
35
+ end
36
+
37
+ db = BitClust::MethodDatabase.new(db_path)
38
+
39
+ def normalize_typemark(typemark)
40
+ (typemark == ".#") ? "." : typemark
41
+ end
42
+
43
+ if reverse
44
+ rev_table = Hash.new{|h,k| h[k] = Array.new}
45
+ db.classes.each do |c|
46
+ c.entries.each do |m|
47
+ typemark = normalize_typemark(m.typemark)
48
+ next unless typemark == "." || typemark == "#"
49
+ m.names.each do |name|
50
+ rev_table[name] << "#{c.name}#{typemark}#{name}"
51
+ end
52
+ end
53
+ end
54
+ rev_table.sort_by{|key,val| key}.each{|key, val| puts(key + "\t" + val.join("\t"))}
55
+ else
56
+ all_entries = []
57
+ db.classes.sort_by{|c| c.name}.each do |c|
58
+ c.entries.sort_by{|m| m.name}.each do |m|
59
+ typemark = m.typemark
60
+ typemark = "." if typemark == ".#"
61
+ next unless typemark == "." || typemark == "#"
62
+ m.names.each do |name|
63
+ spec = "#{c.name}#{typemark}#{name}"
64
+ params = []
65
+ m.source.each_line do |line|
66
+ if /\A--- #{Regexp.quote(name)}[^a-zA-Z_\[\]=]/ =~ line
67
+ line.chomp!
68
+ line.gsub!(/\A--- #{Regexp.quote(name)}/, "")
69
+ line.gsub!(/\t/, "")
70
+ line.gsub!(/ +/, "")
71
+ line.gsub!(/->nil\Z/, "")
72
+ line.gsub!(/->\(\)\Z/, "")
73
+ params << line
74
+ end
75
+ end
76
+
77
+ table_entry = spec + "\t" + params.join("\t")
78
+ all_entries << table_entry
79
+ end
80
+ end
81
+ end
82
+
83
+ puts all_entries.sort_by{|ent| ent.split(/\t/)[0]}
84
+ end
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def usage
4
+ puts "USAGE: #{$0} [--ri] [--refe [-d DIR]] [--rdoc [-d DIR]] [--rd FILE] [--bitclust -d DIR] ..."
5
+ exit
6
+ end
7
+
8
+ rrsedir = "#{ENV["HOME"]}/.rrse"
9
+ if ARGV.size == 0
10
+ usage
11
+ end
12
+
13
+ if ARGV.first == "-h"
14
+ usage
15
+ end
16
+
17
+ if ARGV.first == "-v"
18
+ puts "rrse version 0.4"
19
+ exit
20
+ end
21
+
22
+ if !FileTest.directory?(rrsedir)
23
+ puts "mkdir #{rrsedir}"
24
+ Dir.mkdir(rrsedir)
25
+ end
26
+
27
+ n = 0
28
+ loop do
29
+ case ARGV.shift
30
+ when nil
31
+ break
32
+ when "--ri"
33
+ system("rrse-ri-listdescs > #{rrsedir}/table.#{n}")
34
+ system("rrse-ri-listdescs -r > #{rrsedir}/rev-table.#{n}")
35
+ when "--rdoc"
36
+ if ARGV.first == "-d"
37
+ opt = "#{ENV["RI"]} -d #{ARGV[1]}"
38
+ 2.times{ ARGV.shift }
39
+ else
40
+ opt = "#{ENV["RI"]} -d #{ENV["HOME"]}/.rdoc"
41
+ end
42
+ system("RI=\"#{opt}\" rrse-ri-listdescs > #{rrsedir}/table.#{n}")
43
+ system("RI=\"#{opt}\" rrse-ri-listdescs -r > #{rrsedir}/rev-table.#{n}")
44
+ when "--refe"
45
+ if ARGV.first == "-d"
46
+ opt = "-d #{ARGV[1]}"
47
+ 2.times{ ARGV.shift }
48
+ else
49
+ opt = ""
50
+ end
51
+ system("rrse-refe-listdescs #{opt} > #{rrsedir}/table.#{n}")
52
+ system("rrse-refe-listdescs -r #{opt} > #{rrsedir}/rev-table.#{n}")
53
+ when "--rd"
54
+ file = ARGV.shift
55
+ system("rrse-rd-listdescs #{file} > #{rrsedir}/table.#{n}")
56
+ system("rrse-rd-listdescs -r #{file} > #{rrsedir}/rev-table.#{n}")
57
+ when "--bitclust"
58
+ if ARGV.first == "-d"
59
+ opt = "-d #{ARGV[1]}"
60
+ 2.times{ ARGV.shift }
61
+ else
62
+ opt = ""
63
+ end
64
+ system("rrse-bitclust-listdescs #{opt} > #{rrsedir}/table.#{n}")
65
+ system("rrse-bitclust-listdescs -r #{opt} > #{rrsedir}/rev-table.#{n}")
66
+ else
67
+ usage
68
+ end
69
+
70
+ n += 1
71
+ end
72
+
73
+ tables = (0..n-1).map{|k| "#{rrsedir}/table.#{k}"}.join(" ")
74
+ rev_tables = (0..n-1).map{|k| "#{rrsedir}/rev-table.#{k}"}.join(" ")
75
+ system("rrse-merge-tables #{tables} > #{rrsedir}/table")
76
+ system("rrse-merge-tables #{rev_tables} > #{rrsedir}/rev-table")
77
+
78
+ system("rm #{tables}")
79
+ system("rm #{rev_tables}")
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ if ARGV.first == "-c"
3
+ ARGV.shift; compact = true
4
+ else
5
+ compact = false
6
+ end
7
+
8
+ dict = Hash.new{|h,k| h[k] = Array.new}
9
+
10
+ ARGF.each do |line|
11
+ key, *contents = *line.chomp.split(/\t/)
12
+ dict[key].concat(contents)
13
+ end
14
+
15
+ dict.each{|k, contents| contents.sort!; contents.uniq!} if compact
16
+
17
+ dict.sort.each{|k, contents| print k, "\t", contents.join("\t"), "\n"}
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ class RDInfo
6
+ def initialize(input)
7
+ @descs = input.grep(/\A---\s+/).map{|line|
8
+ if /\A\s*---\s+((\w|:)*)(#|\.)((\w|\[|\]|=|\?|\!)+)\s*((\(.*\))?)/ =~ line
9
+ Description.new($1+$3+$4, $4, $6)
10
+ end
11
+ }.compact
12
+ end
13
+
14
+ def display_info(reverse)
15
+ if reverse
16
+ @descs.
17
+ inject(Hash.new{|h,k| h[k]=[]}){|h, desc| h[desc.method] << desc.spec; h}.
18
+ sort_by{|method, *| method}.
19
+ each{|method, specs| puts "#{method}\t#{specs.join("\t")}"}
20
+ else
21
+ @descs.sort_by{|desc| desc.spec}.each{|desc| puts desc.show }
22
+ end
23
+ end
24
+
25
+ class Description
26
+ attr_reader :spec, :method, :descs
27
+ def initialize(spec, method, descs)
28
+ @spec = spec
29
+ @method = method
30
+ @descs = descs
31
+ end
32
+
33
+ def show
34
+ "#{@spec}\t#{@descs}"
35
+ end
36
+ end
37
+ end
38
+
39
+ opt = OptionParser.new
40
+ reverse = false
41
+ opt.on('-r', 'Print reverse data'){ reverse = true }
42
+ opt.parse!(ARGV)
43
+
44
+
45
+
46
+ begin
47
+ RDInfo.new(ARGF).display_info(reverse)
48
+ rescue RuntimeError
49
+ raise
50
+ rescue StandardError => err
51
+ raise if $DEBUG
52
+ $stderr.puts err.message
53
+ exit 1
54
+ end
55
+
56
+
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rdoc/ri/ri_driver'
4
+
5
+ class Symbol
6
+ def to_proc
7
+ proc{|obj, *p| obj.__send__(self, *p)}
8
+ end
9
+ end
10
+
11
+ module RI
12
+ class ClassEntry
13
+ attr_reader :class_methods, :instance_methods
14
+ end
15
+ end
16
+
17
+ if ARGV.first == "-r"
18
+ ARGV.shift; reverse = true
19
+ else
20
+ reverse = false
21
+ end
22
+
23
+ paths = nil
24
+
25
+ if ENV['RI']
26
+ options = RI::Options.instance
27
+ options.parse(ENV['RI'].split)
28
+ paths = options.path
29
+ end
30
+
31
+ paths ||= RI::Paths::PATH
32
+
33
+ cache = RI::RiCache.new(paths)
34
+
35
+ def format_full_name(str)
36
+ if str.index(?#)
37
+ str
38
+ else
39
+ s = str.split(/::/)
40
+ m = s.pop
41
+ s.join("::") + "." + m
42
+ end
43
+ end
44
+
45
+ class Info
46
+ def initialize(toplevel)
47
+ @toplevel = toplevel
48
+ @info = []
49
+ end
50
+
51
+ def visit_method(entry)
52
+ m = File.open(entry.path_name){|f| RI::Description.deserialize(f)}
53
+ full_name = format_full_name(m.full_name)
54
+
55
+ params = m.params.split("\n").map{|param|
56
+ if param[0] == ?(
57
+ param
58
+ elsif param.index(full_name)
59
+ param.gsub(/#{Regexp.quote(full_name)}/, "")
60
+ elsif param.index(m.name)
61
+ param.gsub(/^.*?#{Regexp.quote(m.name)}/, "")
62
+ else
63
+ nil
64
+ end
65
+ }.compact.map{|param|
66
+ param.gsub(/\sor\s/, "/").gsub(/ (?!block)/, "").gsub(/[=-]>nil$/, "")
67
+ }
68
+
69
+ @info << Desc.new(full_name, params)
70
+ end
71
+
72
+ def visit_class(node)
73
+ node.instance_methods.each(&method(:visit_method))
74
+ node.class_methods.each(&method(:visit_method))
75
+ node.classes_and_modules.each(&method(:visit_class))
76
+ end
77
+
78
+ def display_info
79
+ visit_class(@toplevel)
80
+ @info.sort_by{|i| i.full_name}.each{|i|
81
+ print i.full_name, "\t", i.params.join("\t"), "\n"
82
+ }
83
+ end
84
+
85
+ Desc = Struct.new(:full_name, :params)
86
+ end
87
+
88
+ class RevInfo
89
+ def initialize(toplevel)
90
+ @toplevel = toplevel
91
+ @info = Hash.new{|h, k| h[k] = Array.new}
92
+ end
93
+
94
+ def visit_method(node)
95
+ @info[node.name] << format_full_name(node.full_name)
96
+ end
97
+
98
+ def visit_class(node)
99
+ node.instance_methods.each(&method(:visit_method))
100
+ node.class_methods.each(&method(:visit_method))
101
+ node.classes_and_modules.each(&method(:visit_class))
102
+ end
103
+
104
+ def display_info
105
+ visit_class(@toplevel)
106
+ @info.sort_by{|name, methods| name}.each{|name, methods|
107
+ print name, "\t", methods.join("\t"), "\n"
108
+ }
109
+ end
110
+ end
111
+
112
+
113
+ if reverse
114
+ RevInfo.new(cache.toplevel).display_info
115
+ else
116
+ Info.new(cache.toplevel).display_info
117
+ end
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'pathname'
4
+ require 'fileutils'
5
+ require 'psych'
6
+ require 'yaml'
7
+ require 'tempfile'
8
+
9
+ DEFAULT_CONFIG = {
10
+ "source" =>
11
+ [
12
+ { "type" => "bitclust", "options" => ""}
13
+ ]
14
+ }
15
+
16
+ class Main
17
+ def initialize
18
+ @rrse_dir = DEFAULT_DIR
19
+ end
20
+
21
+ DEFAULT_DIR = Pathname(ENV["HOME"]) + ".rrse"
22
+
23
+ def options
24
+ opts = OptionParser.new
25
+ opts.version = "0.6"
26
+ opts.banner = <<EOS
27
+ Usage: rrse-table [global-options] subcommand ...
28
+
29
+ Subcommands:
30
+ setup-config
31
+ update
32
+ setup-default-db
33
+
34
+ Global Options:
35
+ EOS
36
+
37
+ opts.on("-d DIR", "rrse directory (default: #{DEFAULT_DIR})"){|dir|
38
+ @rrse_dir = dir
39
+ }
40
+
41
+ opts
42
+ end
43
+
44
+ def run(argv)
45
+ options.order!(argv)
46
+ subcommand = argv.shift
47
+
48
+ case subcommand
49
+ when "setup"
50
+ SetUp.new(@rrse_dir).run(argv)
51
+ when "update"
52
+ Update.new(@rrse_dir).run(argv)
53
+ when "setup-default-db"
54
+ SetUpDefaultDB.new(@rrse_dir).run(argv)
55
+ else
56
+ show_help
57
+ end
58
+ end
59
+
60
+ def show_help
61
+ print options.help
62
+ exit 1
63
+ end
64
+ end
65
+
66
+ class SetUp
67
+ def initialize(dir)
68
+ @dir = dir
69
+ end
70
+
71
+ def options
72
+ opts = OptionParser.new
73
+ opts.banner = <<EOS
74
+ Usage: rrse-table [global-options] setup
75
+
76
+ Create an rrse directory and a config file
77
+
78
+ EOS
79
+
80
+ opts
81
+ end
82
+
83
+ def run(argv)
84
+ options.order!(argv)
85
+
86
+ FileUtils.mkdir_p(@dir)
87
+ config_path = @dir + "config"
88
+ IO.write(config_path, YAML.dump(DEFAULT_CONFIG))
89
+ end
90
+ end
91
+
92
+ class Update
93
+ def initialize(dir)
94
+ @dir = dir
95
+ end
96
+
97
+ def options
98
+ opts = OptionParser.new
99
+ opts.banner = <<EOS
100
+ Usage: rrse-table [global-options] update
101
+
102
+ Update rrse databases
103
+
104
+ EOS
105
+
106
+ opts
107
+ end
108
+
109
+ def run(argv)
110
+ options.order!(argv)
111
+
112
+ @config_path = @dir + "config"
113
+ @table_path = @dir + "table"
114
+ @rev_table_path = @dir + "rev-table"
115
+
116
+ config = YAML.load_file(@config_path)
117
+ table_pairs = []
118
+
119
+ config["source"].each do |src|
120
+ case src["type"]
121
+ when "bitclust"
122
+ table_pairs << bitclust(src["options"])
123
+ when "rd"
124
+ table_pairs << rd(src["path"], src["options"])
125
+ else
126
+ STDERR.puts "unknown type: #{src["type"]}"
127
+ end
128
+ end
129
+
130
+ tables, rev_tables = table_pairs.transpose
131
+ system("rrse-merge-tables", *tables.map(&:path), out: @table_path.to_s)
132
+ system("rrse-merge-tables", *rev_tables.map(&:path), out: @rev_table_path.to_s)
133
+ end
134
+
135
+ def bitclust(opts)
136
+ table = Tempfile.new("rrse_table")
137
+ rev_table = Tempfile.new("rrse_rev_table")
138
+ table.close; rev_table.close
139
+
140
+ system("rrse-bitclust-listdescs #{opts} > #{table.path}")
141
+ system("rrse-bitclust-listdescs -r #{opts} > #{rev_table.path}")
142
+
143
+ return table, rev_table
144
+ end
145
+
146
+ def rd(path, opts)
147
+ table = Tempfile.new("rrse_table")
148
+ rev_table = Tempfile.new("rrse_rev_table")
149
+ table.close; rev_table.close
150
+
151
+ system("rrse-rd-listdescs #{opts} <#{path} >#{table.path}")
152
+ system("rrse-rd-listdescs -r #{opts} <#{path} >#{rev_table.path}")
153
+
154
+ return table, rev_table
155
+ end
156
+
157
+ #def system(*args); p args; end
158
+ end
159
+
160
+ class SetUpDefaultDB
161
+ def initialize(dir)
162
+ @dir = dir
163
+ end
164
+
165
+ def options
166
+ opts = OptionParser.new
167
+ opts.banner = <<EOS
168
+ Usage: rrse-table [global-options] setup
169
+
170
+ Create an rrse directory and a config file
171
+
172
+ EOS
173
+
174
+ opts
175
+ end
176
+
177
+ def run(argv)
178
+ options.order!(argv)
179
+
180
+ FileUtils.mkdir_p(@dir)
181
+ config_path = @dir + "config"
182
+ IO.write(config_path, YAML.dump(DEFAULT_CONFIG))
183
+
184
+ FileUtils.cp(find_file("misc/table"), @dir, verbose: true)
185
+ FileUtils.cp(find_file("misc/rev-table"), @dir, verbose: true)
186
+ end
187
+
188
+ def find_file(fname)
189
+ fullpaths = `gem contents rrse`.split(/\n/)
190
+ fullpaths.grep(/#{Regexp.quote(fname)}/).first
191
+ end
192
+ end
193
+
194
+ Main.new.run(ARGV)