1999-08-13 09:45:20 +04:00
|
|
|
#!/usr/bin/env ruby
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if ARGV[0] == "-c"
|
1998-01-16 15:19:22 +03:00
|
|
|
out_stdout = 1
|
1998-01-16 15:13:05 +03:00
|
|
|
ARGV.shift
|
|
|
|
end
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
$sawbegin = 0
|
|
|
|
$sawend = 0
|
|
|
|
|
2000-12-28 08:00:47 +03:00
|
|
|
while line = gets()
|
|
|
|
if /^begin\s*(\d*)\s*(\S*)/ =~ line
|
1998-01-16 15:13:05 +03:00
|
|
|
$mode, $file = $1, $2
|
|
|
|
$sawbegin+=1
|
1998-01-16 15:19:22 +03:00
|
|
|
if out_stdout
|
|
|
|
out = STDOUT
|
|
|
|
else
|
2022-11-25 08:22:37 +03:00
|
|
|
out = File.open($file, "w") if $file != ""
|
1998-01-16 15:19:22 +03:00
|
|
|
end
|
|
|
|
out.binmode
|
1999-08-13 09:45:20 +04:00
|
|
|
break
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
raise "missing begin" unless $sawbegin
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
out.binmode
|
2000-12-28 08:00:47 +03:00
|
|
|
while line = gets()
|
|
|
|
if /^end/ =~ line
|
1998-01-16 15:13:05 +03:00
|
|
|
$sawend+=1
|
1998-01-16 15:19:22 +03:00
|
|
|
out.close unless out_stdout
|
|
|
|
File.chmod $mode.oct, $file unless out_stdout
|
|
|
|
next
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
2000-12-28 08:00:47 +03:00
|
|
|
line.sub!(/[a-z]+$/, "") # handle stupid trailing lowercase letters
|
|
|
|
next if /[a-z]/ =~ line
|
1998-01-16 15:13:05 +03:00
|
|
|
next if !(((($_[0] - 32) & 077) + 2) / 3 == $_.length / 4)
|
1998-01-16 15:19:22 +03:00
|
|
|
out << $_.unpack("u") if $sawbegin > $sawend
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
raise "missing end" if $sawbegin > $sawend
|
|
|
|
raise "missing begin" if ! $sawbegin
|
|
|
|
exit 0
|