#!ruby -EShift_JIS
#coding: Shift_JIS

s = File.binread ARGV[0]
while s.length != 0
	i = s.index "\0"
	raise if i == -1
	t = s.slice! 0, (i + 1) + (2 * 2)
	fname, x, y = t.unpack "Z* s2"
	#//
	sig, size = s.unpack "a2 i"
	raise if sig != "BM"
	t = s.slice! 0, size
	#//
	path = File.join "tmp", fname + ".bmp"
	puts "/\\b#{fname.upcase}\\b/s/,50%,50%/,#{-x},#{-y}/"
	File.binwrite path, t
end
