Brian Silverman | 069eb25 | 2013-12-14 16:38:35 -0800 | [diff] [blame^] | 1 | #!/usr/bin/env ruby |
| 2 | |
| 3 | system 'rm temp.*' |
| 4 | system 'gsch2pcb cape.gsch2pcb -o temp > /dev/null 2>&1' |
| 5 | |
| 6 | $elements = {} |
| 7 | |
| 8 | ElementRegex = /[ \t]*(Element[\[(].+) "(.*)" "(.*)" "(.*)" (.*)/ |
| 9 | |
| 10 | File.open('temp.pcb') do |f| |
| 11 | f.readlines.each do |temp_element| |
| 12 | match = ElementRegex.match(temp_element) |
| 13 | if match |
| 14 | refdes = match[3] |
| 15 | value = match[4] |
| 16 | $elements[refdes] = value |
| 17 | end |
| 18 | end |
| 19 | end |
| 20 | |
| 21 | File.open('cape.pcb') do |f| |
| 22 | $start_lines = f.readlines |
| 23 | end |
| 24 | |
| 25 | File.open('cape.pcb', 'w') do |f| |
| 26 | $start_lines.each do |line| |
| 27 | match = ElementRegex.match(line) |
| 28 | if match |
| 29 | footprint = match[2] |
| 30 | refdes = match[3] |
| 31 | value = match[4] |
| 32 | f.puts "#{match[1]} \"#{footprint}\" \"#{refdes}\" \"#{$elements[refdes] || value}\" #{match[5]}" |
| 33 | else |
| 34 | f.puts line |
| 35 | end |
| 36 | end |
| 37 | end |