DEFINITIONS
This source file includes following functions.
1 #!/usr/bin/env ruby
2
3 if ARGV[0] == "-c"
4 out_stdout = 1
5 ARGV.shift
6 end
7
8 $sawbegin = 0
9 $sawend = 0
10
11 while line = gets()
12 if /^begin\s*(\d*)\s*(\S*)/ =~ line
13 $mode, $file = $1, $2
14 $sawbegin+=1
15 if out_stdout
16 out = STDOUT
17 else
18 out = open($file, "w") if $file != ""
19 end
20 out.binmode
21 break
22 end
23 end
24
25 raise "missing begin" unless $sawbegin
26
27 out.binmode
28 while line = gets()
29 if /^end/ =~ line
30 $sawend+=1
31 out.close unless out_stdout
32 File.chmod $mode.oct, $file unless out_stdout
33 next
34 end
35 line.sub!(/[a-z]+$/, "") # handle stupid trailing lowercase letters
36 next if /[a-z]/ =~ line
37 next if !(((($_[0] - 32) & 077) + 2) / 3 == $_.length / 4)
38 out << $_.unpack("u") if $sawbegin > $sawend
39 end
40
41 raise "missing end" if $sawbegin > $sawend
42 raise "missing begin" if ! $sawbegin
43 exit 0