#!/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' END_HEADER def xmlesc(s) s.gsub('&', '&').gsub('<', '<').gsub('>', '&rt;') end grooves.each do |style,grooves| OUT.puts "\t#{xmlesc(style)}" OUT.puts "\t" grooves.each do |name,desc| OUT.puts "\t\t#{xmlesc(name)}" if name == ".ORDER" OUT.puts "\t\t" desc.each do |name| OUT.puts "\t\t\t#{xmlesc(name)}" end OUT.puts "\t\t" else OUT.puts "\t\t#{xmlesc(desc)}" end end OUT.puts "\t" end OUT.puts "" OUT.puts ""