mirror of
https://github.com/specht/champ.git
synced 2024-12-26 13:31:35 +00:00
fix
This commit is contained in:
parent
2d2038e184
commit
1cec19787c
10
champ.rb
10
champ.rb
@ -63,6 +63,7 @@ class Champ
|
|||||||
@execution_log_size = 20
|
@execution_log_size = 20
|
||||||
@code_for_pc = {}
|
@code_for_pc = {}
|
||||||
@source_for_file = {}
|
@source_for_file = {}
|
||||||
|
@max_source_width_for_file = {}
|
||||||
@pc_for_file_and_line = {}
|
@pc_for_file_and_line = {}
|
||||||
args = ARGV.dup
|
args = ARGV.dup
|
||||||
while args.size > 1
|
while args.size > 1
|
||||||
@ -796,7 +797,8 @@ class Champ
|
|||||||
source_code = @code_for_pc[@error[:pc]]
|
source_code = @code_for_pc[@error[:pc]]
|
||||||
offset = source_code[:line] - 1
|
offset = source_code[:line] - 1
|
||||||
this_filename = source_code[:file]
|
this_filename = source_code[:file]
|
||||||
io.puts "<span class='heading'> Line | PC | #{sprintf('%-75s', this_filename)}</span>"
|
format_str = "%-#{@max_source_width_for_file[this_filename]}s"
|
||||||
|
io.puts "<span class='heading'> Line | PC | #{sprintf(format_str, this_filename)}</span>"
|
||||||
((offset - 16)..(offset + 16)).each do |i|
|
((offset - 16)..(offset + 16)).each do |i|
|
||||||
next if i < 0 || i >= @source_for_file[this_filename].size
|
next if i < 0 || i >= @source_for_file[this_filename].size
|
||||||
io.print "<span class='#{(i == offset) ? 'error' : 'code'}'>"
|
io.print "<span class='#{(i == offset) ? 'error' : 'code'}'>"
|
||||||
@ -807,7 +809,7 @@ class Champ
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
line_pc ||= ''
|
line_pc ||= ''
|
||||||
io.print sprintf('%5d | %6s | %-75s', i + 1, line_pc, @source_for_file[this_filename][i])
|
io.print sprintf("%5d | %6s | %-#{@max_source_width_for_file[this_filename]}s", i + 1, line_pc, @source_for_file[this_filename][i])
|
||||||
io.print "</span>" if i == offset
|
io.print "</span>" if i == offset
|
||||||
io.puts
|
io.puts
|
||||||
end
|
end
|
||||||
@ -850,7 +852,9 @@ class Champ
|
|||||||
|
|
||||||
def parse_merlin_output(path)
|
def parse_merlin_output(path)
|
||||||
input_file = File.basename(@source_path)
|
input_file = File.basename(@source_path)
|
||||||
@source_for_file[input_file] = File.read(@source_path).split("\n")
|
@source_for_file[input_file] = File.read(@source_path).split("\n").map { |x| x.gsub("\t", ' ' * 4) }
|
||||||
|
@max_source_width_for_file[input_file] = @source_for_file[input_file].map { |x| x.size }.max
|
||||||
|
|
||||||
@source_line = -3
|
@source_line = -3
|
||||||
File.open(path, 'r') do |f|
|
File.open(path, 'r') do |f|
|
||||||
f.each_line do |line|
|
f.each_line do |line|
|
||||||
|
Loading…
Reference in New Issue
Block a user