Commit 42038856 by Daniel Mendler

improve table generator

parent 66c3c660
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/usr/bin/ruby #!/usr/bin/ruby
gem 'nokogiri', '>= 0'
require 'nokogiri' require 'nokogiri'
class String
alias inspect_old inspect
def inspect
x = b.inspect_old.gsub(/\\x([0-9a-f]{2})/i) do
'\\%03o' % $1.to_i(16)
end
x =~ /[\\']/ ? x : x.gsub('"', '\'')
end
end
def str2int(s) def str2int(s)
return s.to_i(16) if s[0..1].downcase == '0x' return s.to_i(16) if s[0..1].downcase == '0x'
return s.to_i(8) if s[0..0].downcase == '0' return s.to_i(8) if s[0..0].downcase == '0'
...@@ -61,7 +71,7 @@ extensions = {} ...@@ -61,7 +71,7 @@ extensions = {}
types = {} types = {}
magics = [] magics = []
(doc/'mime-info/mime-type').each do |mime| (doc/'mime-info/mime-type').each do |mime|
comments = Hash[*(mime/'comment').map {|comment| [comment['lang'], comment.inner_text] }.flatten] comments = Hash[*(mime/'comment').map {|comment| [comment['xml:lang'], comment.inner_text] }.flatten]
type = mime['type'] type = mime['type']
subclass = (mime/'sub-class-of').map{|x| x['type']} subclass = (mime/'sub-class-of').map{|x| x['type']}
exts = (mime/'glob').map{|x| x['pattern'] =~ /^\*\.([^\[\]]+)$/ ? $1.downcase : nil }.compact exts = (mime/'glob').map{|x| x['pattern'] =~ /^\*\.([^\[\]]+)$/ ? $1.downcase : nil }.compact
...@@ -97,7 +107,7 @@ types.keys.sort.each do |key| ...@@ -97,7 +107,7 @@ types.keys.sort.each do |key|
end end
puts " }" puts " }"
puts " MAGIC = [" puts " MAGIC = ["
magics.each do |type, matches| magics.sort.each do |type, matches|
puts " ['#{type}', #{matches.inspect}]," puts " ['#{type}', #{matches.inspect}],"
end end
puts " ]" puts " ]"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment