Skip to content

Instantly share code, notes, and snippets.

@alexbevi
Last active May 31, 2021 13:03
Show Gist options
  • Save alexbevi/3425815ea17d6a14e0832bd263e97954 to your computer and use it in GitHub Desktop.
Save alexbevi/3425815ea17d6a14e0832bd263e97954 to your computer and use it in GitHub Desktop.
Generate a Markdown Table from the ScummVM source code
def replace_target(path, target)
p = path.split('/')
p[-1] = target
return p.join('/').to_s
end
def cleanup_title(c)
title = c.gsub('{','').gsub('}','').gsub("\t", ' ').split(', ')[1..-1].join.strip
title = title.delete_prefix('"').delete_suffix('"').delete_suffix(' ,').delete_suffix("\",").delete_suffix("\"").delete_suffix("\" ;")
title
end
target = "detection.cpp"
fallback = "detection_tables.h"
search_term = "static const PlainGameDescriptor "
fallback_term = "const PlainGameDescriptor "
files = %x[find `pwd` -name '#{target}'].split("\n")
result = []
files.each do |f|
offset = %x[grep -n "#{search_term}" #{f}].split(':')[0].to_i
if offset == 0
f = replace_target(f, fallback)
offset = %x[grep -n "#{search_term}" #{f}].split(':')[0].to_i if File.exists?(f)
# kyra
offset = %x[grep -n "#{fallback_term}" #{f}].split(':')[0].to_i if offset == 0 && File.exists?(f)
end
if offset > 0
terminator1 = %x[sed -n '#{offset + 1}, $ p' '#{f}' | grep -n '0, 0'].split(':')[0].to_i
terminator2 = %x[sed -n '#{offset + 1}, $ p' '#{f}' | grep -n ';'].split(':')[0].to_i
length = (terminator1 < terminator2) ? terminator1 : terminator2
content = %x[sed -n '#{offset + 1}, #{offset + length - 1} p' #{f}]
engine = f.split('/')[-2]
content.strip.split(",\n").each do |c|
title = cleanup_title(c)
if title.index("//").nil?
result << { engine: engine, title: title } unless title == "nullptr"
else
titles = c.split("\n\t")
titles.each do |t|
result << { engine: engine, title: cleanup_title(t) }
end
end
end
end
end
result.reject! { |obj| obj[:title].empty? }
puts "| Engine | Title (#{result.length}) |"
puts "|--------|--------------------------|"
result.sort_by { |obj| obj[:title] }.each do |o|
puts "|#{o[:engine]}|#{o[:title]}|"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment