#!/usr/bin/ruby ME="sl: " $release=false $git=false $lpath=[] $outfile=nil def get_path(fn) if fn.start_with?("/") begin return fn if File.stat(fn).readable? rescue end return nil end for p in $lpath n=p+"/"+fn begin return File.expand_path(n) if File.stat(n).readable? rescue end end return nil end $loaded=[] def load_file(buf,fn,_r=false) p=File.expand_path(fn) return if $loaded.include?(p) $loaded.push(p) begin f=File.open(fn,"r") rescue $stderr.puts ME+"unable to open file: "+fn exit 1 end _ea=false _ed=false for l in f l.chop! if _ea _ea=false buf<<"" if not l.empty? end if _r if _ed _ed=false next if l.empty? end if /^[#\-\/\*][\-\/\*]? vim:/.match(l) _ed=true next end end if tmp=/^@\+ (.*)/.match(l) if !p=get_path(tmp[1]) $stderr.puts ME+"file not found: "+tmp[1] f.close exit 1 end load_file(buf,p,true) next end if tmp=/^@ (.*)/.match(l) if !p=get_path(tmp[1]) $stderr.puts ME+"file not found: "+tmp[1] f.close exit 1 end if $release load_file(buf,p,true) _ea=true else buf<<"load "+p.dump end next end buf<] -o " exit 1 end i=0 while i0 end l.sub!(/\$Format:%h\$/,gv) end f.puts l end f.close