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
|
# File 'lib/loquat/bat.rb', line 7
def exec(src, &block)
file, line = *caller(1)[0].match(/(.+):(\d+)/).to_a[1..-1]
file = File.expand_path(file)
line = line.to_i + 1
next_noerror = false
src_map = src.each_line.with_index.map do |s,i|
if s.match(/^\s$/)
s
elsif s.match(/^\s*(rem\s+|::)skip_error/)
next_noerror = true
s
elsif next_noerror
next_noerror = false
s
else
ret = " \#{s}\n @if %errorlevel% == 9009 if NOT \"%no_error_break%\" == \"1\" echo You do not have \#{s.match(/\\w+/).to_a[0]} in your PATH. && exit\n @if errorlevel 1 if NOT \"%no_error_break%\" == \"1\" echo \#{file}(\#{line + i}): \#{s.gsub(\"\\n\", \"\").gsub(/\\&/, \"\\\\&\")} && echo if you write comment ** \"::skip_error\" or \"rem skip_error\" ** to not error stop && exit\n @set error_no_break=0\n EOSA\n end\n end\n src = src_map.join\n Tempfile.open([\"\", \".bat\"]) do |f|\n f.puts src.tosjis\n f.close\n system(\"\#{f.path} 2>&1\")\n end\nend\n"
|