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