Description:
merge fix utf8
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r188:4805f3ab73c4 - - 2 files changed: 4 inserted, 2 deleted
@@ -66,108 +66,109 | |||
|
66 | 66 | params[param_name] = default |
|
67 | 67 | end |
|
68 | 68 | talk "#{param_name}: #{params[param_name]}" |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | # Remove any remaining output files or message files. |
|
72 | 72 | if FileTest.exists? params[:output_file] |
|
73 | 73 | FileUtils.rm(params[:output_file]) |
|
74 | 74 | end |
|
75 | 75 | if FileTest.exists? params[:message_file] |
|
76 | 76 | FileUtils.rm(params[:message_file]) |
|
77 | 77 | end |
|
78 | 78 | |
|
79 | 79 | # Check if the source file exists before attempt compiling. |
|
80 | 80 | if !FileTest.exists? params[:source_file] |
|
81 | 81 | talk("ERROR: The source file does not exist!") |
|
82 | 82 | open(params[:message_file],"w") do |f| |
|
83 | 83 | f.puts "ERROR: The source file did not exist." |
|
84 | 84 | end |
|
85 | 85 | exit(127) |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | if params[:prog_lang]=='cpp' |
|
89 | 89 | params[:prog_lang] = 'c++' |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | # Compile. |
|
93 | 93 | case params[:prog_lang] |
|
94 | 94 | |
|
95 | 95 | when "c" |
|
96 | 96 | command = "#{C_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{C_OPTIONS}" |
|
97 | 97 | system(command, err: params[:message_file]) |
|
98 | 98 | |
|
99 | 99 | when "c++" |
|
100 | 100 | command = "#{CPLUSPLUS_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{CPLUSPLUS_OPTIONS}" |
|
101 | 101 | system(command, err: params[:message_file]) |
|
102 | 102 | |
|
103 | 103 | when "pas" |
|
104 | 104 | command = "#{PASCAL_COMPILER} #{params[:source_file]} -ooutpas #{PASCAL_OPTIONS}" |
|
105 | 105 | system(command,out: params[:message_file]) |
|
106 | 106 | FileUtils.mv("output", params[:output_file]) |
|
107 | 107 | |
|
108 | 108 | when "java" |
|
109 | 109 | #rename the file to the public class name |
|
110 | 110 | |
|
111 | 111 | #get the class name |
|
112 | 112 | classname = 'DUMMY' |
|
113 | 113 | source = Array.new |
|
114 | - File.foreach(params[:source_file]) do |line| | |
|
114 | + File.foreach(params[:source_file],'r:UTF-8') do |line| | |
|
115 | + line.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') | |
|
115 | 116 | md = /\s*public\s*class\s*(\w*)/.match(line) |
|
116 | 117 | classname=md[1] if md |
|
117 | 118 | source << line unless line =~ /\s*package\s*\w+\s*\;/ |
|
118 | 119 | end |
|
119 | 120 | File.open("#{classname}.java","w") do |file| |
|
120 | 121 | source.each do |s| |
|
121 | 122 | file.puts s |
|
122 | 123 | end |
|
123 | 124 | end |
|
124 | 125 | #system("cp #{params[:source_file]} #{classname}.java") |
|
125 | - command = "#{JAVA_COMPILER} #{classname}.java" | |
|
126 | + command = "#{JAVA_COMPILER} -encoding utf8 #{classname}.java" | |
|
126 | 127 | system(command, err: params[:message_file]) |
|
127 | 128 | if File.exists?(classname + ".class") |
|
128 | 129 | File.open(params[:output_file],"w") {|file| file.write("#{classname}")} |
|
129 | 130 | end |
|
130 | 131 | if classname == 'DUMMY' |
|
131 | 132 | File.open(params[:message_file],"w") {|file| file.write("Cannot find any public class in the source code\n")} |
|
132 | 133 | end |
|
133 | 134 | |
|
134 | 135 | when "ruby" |
|
135 | 136 | command = "#{RUBY_INTERPRETER} -c #{params[:source_file]}" |
|
136 | 137 | if system(command, err: params[:message_file]) |
|
137 | 138 | File.open(params[:output_file],"w") do |out_file| |
|
138 | 139 | out_file.puts "#!#{RUBY_INTERPRETER}" |
|
139 | 140 | File.open(params[:source_file],"r").each do |line| |
|
140 | 141 | out_file.print line |
|
141 | 142 | end |
|
142 | 143 | end |
|
143 | 144 | File.chmod(0755, params[:output_file]) |
|
144 | 145 | end |
|
145 | 146 | |
|
146 | 147 | when "python" |
|
147 | 148 | command = "#{PYTHON_CHECKER} #{params[:source_file]}" |
|
148 | 149 | if system(command, out: params[:message_file]) |
|
149 | 150 | #compile to python bytecode |
|
150 | 151 | command = "#{PYTHON_INTERPRETER} -m py_compile #{params[:source_file]}" |
|
151 | 152 | puts "compile: #{command}" |
|
152 | 153 | system(command) |
|
153 | 154 | puts "pwd: " + Dir.pwd |
|
154 | 155 | Dir.new('.').each {|file| puts file} |
|
155 | 156 | File.open(params[:output_file],"w") do |out_file| |
|
156 | 157 | out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c" |
|
157 | 158 | end |
|
158 | 159 | File.chmod(0755, params[:output_file]) |
|
159 | 160 | FileUtils.cp("#{params[:source_file]}c",params[:output_file]) |
|
160 | 161 | end |
|
161 | 162 | |
|
162 | 163 | when "php" |
|
163 | 164 | command = "#{PHP_INTERPRETER} #{PHP_OPTIONS} #{params[:source_file]}" |
|
164 | 165 | if system(command, err: params[:message_file]) |
|
165 | 166 | File.open(params[:output_file],"w") do |out_file| |
|
166 | 167 | out_file.puts "#!#{PHP_INTERPRETER}" |
|
167 | 168 | File.open(params[:source_file],"r").each do |line| |
|
168 | 169 | out_file.print line |
|
169 | 170 | end |
|
170 | 171 | end |
|
171 | 172 | File.chmod(0755, params[:output_file]) |
|
172 | 173 | end |
|
173 | 174 |
@@ -84,50 +84,51 | |||
|
84 | 84 | current_run_score = 0 |
|
85 | 85 | run_comment += "result file for test #{test_num} error\n" |
|
86 | 86 | run_comment_short += RUN_ERROR_MARK |
|
87 | 87 | log "Error in #{test_num}/result!" |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | # the score of this run should be the minimum of the score for |
|
91 | 91 | # each test case |
|
92 | 92 | if (run_score==nil) or (run_score>current_run_score) |
|
93 | 93 | run_score = current_run_score |
|
94 | 94 | end |
|
95 | 95 | result_file.close |
|
96 | 96 | end |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | run_result_file = File.new("result-#{k}", "w") |
|
100 | 100 | run_result_file.write run_score |
|
101 | 101 | run_result_file.write "\n" |
|
102 | 102 | run_result_file.close |
|
103 | 103 | |
|
104 | 104 | run_comment_file = File.new("comment-#{k}", "w") |
|
105 | 105 | run_comment_file.write "#{run_comment}\n" |
|
106 | 106 | run_comment_file.close |
|
107 | 107 | |
|
108 | 108 | all_score = all_score + run_score |
|
109 | 109 | |
|
110 | 110 | # append comment for test run with many test cases |
|
111 | 111 | if run.tests.length > 1 |
|
112 | 112 | run_comment_short = '[' + run_comment_short + ']' |
|
113 | 113 | end |
|
114 | 114 | all_comment += run_comment_short |
|
115 | 115 | end |
|
116 | 116 | |
|
117 | 117 | result_file = File.new("result", "w") |
|
118 | 118 | result_file.write all_score |
|
119 | 119 | result_file.write "\n" |
|
120 | 120 | result_file.close |
|
121 | 121 | |
|
122 | 122 | comment_file = File.new("comment", "w") |
|
123 | 123 | comment_file.write "#{all_comment}\n" |
|
124 | 124 | comment_file.close |
|
125 | 125 | |
|
126 | 126 | |
|
127 | 127 | File.open("run_stat","w") do |file| |
|
128 | 128 | file.puts max_runtime |
|
129 | 129 | file.puts peak_memory |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | + puts "#{all_score} #{all_comment}" | |
|
132 | 133 | log "score = #{all_score}\ncomment = #{all_comment}" |
|
133 | 134 | log "max_runtime = #{max_runtime}\npeak_memory = #{peak_memory}" |
You need to be logged in to leave comments.
Login now