#!/usr/bin/ruby # # rebuildGrooves # Vocalese # # Created by Matthias Neeracher on 2/5/07. # Copyright (c) 2007 __MyCompanyName__. All rights reserved. # require 'find' grooves = {} Find.find(ARGV[0]) do |f| if File.directory?(f) Find.prune if File.exist?("f/MMAIGNORE") elsif f =~ %r|.*/(\S+?).mma$| style = $1 g = {} o = [] doc = "" groove= "" File.open(f) do |file| inDoc = false inCont= false file.each do |line| if line =~ /^\s*Begin\s+Doc\s*$/ inDoc = true elsif inDoc if line =~ /^\s*End\s*$/ inDoc = false else doc = doc+" "+line.strip end elsif line =~ /^\s*DefGroove\s+(\S+)\s+(.+?)\s*$/ groove = $1 gdoc = $2 o.push(groove) if gdoc =~ /(.*?)\s+\\\s*$/ gdoc = $1 inCont = true end g[groove] = gdoc elsif inCont if line =~ /^\s*(.*?)\s*(\\)?\s*$/ g[groove] = g[groove] + " " + $1 inCont = $2 != nil else inCont = false end end end end unless g.empty? g[".DESC"] = doc.lstrip g[".ORDER"] = o grooves[style] = g end end end OUT = File.new(ARGV[1], "w") OUT.print <<'END_HEADER' <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> END_HEADER def xmlesc(s) s.gsub('&', '&').gsub('<', '<').gsub('>', '&rt;') end grooves.each do |style,grooves| OUT.puts "\t<key>#{xmlesc(style)}</key>" OUT.puts "\t<dict>" grooves.each do |name,desc| OUT.puts "\t\t<key>#{xmlesc(name)}</key>" if name == ".ORDER" OUT.puts "\t\t<array>" desc.each do |name| OUT.puts "\t\t\t<string>#{xmlesc(name)}</string>" end OUT.puts "\t\t</array>" else OUT.puts "\t\t<string>#{xmlesc(desc)}</string>" end end OUT.puts "\t</dict>" end OUT.puts "</dict>" OUT.puts "</plist>"