-
Notifications
You must be signed in to change notification settings - Fork 2
/
records.rb
55 lines (40 loc) · 988 Bytes
/
records.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env ruby -w
offset = 0
record = nil
records = {}
puts "/* generated on #{Time.now.ctime} */"
puts ""
ARGF.each_line {|x|
x.chomp!
x.gsub!(/(;.*)$/,'')
x = x.rstrip
next if x.empty?
if record.nil?
record = $1 if /^(\w+\d*)\s+begin_struct$/.match x
next
end
case x
when /^\s+end_struct$/
puts ""
records[record] = offset
record = nil
offset = 0
when /^(\w+\d*)?\s+ds\s+(\w+\d*)$/i
# bleh ds timerec
puts "#define #{record}_#{$1} #{offset}" if $1
raise "unknown record #{$2}" unless records.include? $2
offset += records[$2]
when /^(\w+\d*)?\s+ds\.b\s+(\d+)$/i
puts "#define #{record}_#{$1} #{offset}" if $1
offset += $2.to_i
when /^(\w+\d*)?\s+ds\.w\s+(\d+)$/i
puts "#define #{record}_#{$1} #{offset}" if $1
offset += $2.to_i * 2
when /^(\w+\d*)?\s+ds\.l\s+(\d+)$/i
puts "#define #{record}_#{$1} #{offset}" if $1
offset += $2.to_i * 4
else
raise "bad line #{x}"
end
}
exit 0