class Array
def indentation(i)
return self if self == []
self.del_tem!
ary = [" "] * i
unshift(*ary)
end
def del_tem!
while self[0] == " "
self.delete_at(0)
end
end
end
class String
def in_in?(ary)
ary1 = self.split("")
ary1.size.times{|i|return false if ary1[i] != ary[i]}
true
end
end
Word1 = ["class ","ensure","def ","while ","for ","if(",
"loop ","if ","begin","module ","unless ","until "]
Word2 = ["rescue","when ","else","elsif ","elsif("]
show = Sprite.new
show.bitmap = Bitmap.new(640,32)
show.y = 100
show.bitmap.draw_text(show.bitmap.rect, "请将Scripts.*文件放入根目录",1)
40.times{|i|Graphics.update}
show.bitmap.clear
show.bitmap.draw_text(show.bitmap.rect, "读取脚本文件",1)
40.times{|i|Graphics.update}
file = Dir["Scripts.*"]
begin
scripts = load_data(file[0])
show.bitmap.clear
show.bitmap.draw_text(show.bitmap.rect, "读取#{file[0]}成功",1)
40.times{|i|Graphics.update}
rescue
show.bitmap.clear
show.bitmap.draw_text(show.bitmap.rect, "读取失败",1)
40.times{|i|Graphics.update}
exit
end
$lines = 0;$in_ = 0;$tem = false
scripts.size.times{|t|
sc_new = "";$in_ = 0
sc = Zlib::Inflate.inflate(scripts[t][2])
sc.each_line{|line|$tem = false
$lines += 1;$lines%=100
Graphics.update if $lines == 0
line_a = line.split("")
line_a.del_tem!
Word1.each{|w|$tem = true if w.in_in?(line_a)}
Word2.each{|w|$in_ -= 2 if w.in_in?(line_a) and $tem = true}
$in_ -= 2 if "end".in_in?(line_a)
$in_ = [$in_,0].max
line_a.indentation(line_a[0] == "=" ? 0 : $in_)
sc_new += line_a.to_s
$in_ += 2 if $tem
}
scripts[t][2] = Zlib::Deflate.deflate(sc_new,6)
show.bitmap.clear
show.bitmap.draw_text(show.bitmap.rect, "处理中#{t}/#{scripts.size}",1)
}
save_data(scripts, file[0])
show.bitmap.clear
show.bitmap.draw_text(show.bitmap.rect, "处理完毕",1)
10.times{|i|Graphics.update}