Description:
add php
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r165:6f663119800b - - 4 files changed: 20 inserted, 3 deleted
@@ -21,30 +21,32 | |||
|
21 | 21 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
22 | 22 | fp.close |
|
23 | 23 | end |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | C_COMPILER = "/usr/bin/gcc" |
|
27 | 27 | CPLUSPLUS_COMPILER = "/usr/bin/g++" |
|
28 | 28 | PASCAL_COMPILER = "/usr/bin/fpc" |
|
29 | 29 | JAVA_COMPILER = "/usr/bin/javac" |
|
30 | 30 | RUBY_INTERPRETER = "/usr/bin/ruby" |
|
31 | 31 | PYTHON_INTERPRETER = "/usr/bin/python" |
|
32 | 32 | PYTHON_CHECKER = "/usr/bin/pyflakes" |
|
33 | + PHP_INTERPRETER = "/usr/bin/php" | |
|
33 | 34 | |
|
34 | 35 | C_OPTIONS = "-O2 -s -static -std=c99 -DCONTEST -lm -Wall" |
|
35 | 36 | CPLUSPLUS_OPTIONS = "-O2 -s -std=c++11 -static -DCONTEST -lm -Wall" |
|
36 | 37 | PASCAL_OPTIONS = "-O1 -XS -dCONTEST" |
|
37 | 38 | JAVA_OPTIONS = "" |
|
38 | 39 | PYTHON_OPTIONS = "" |
|
40 | + PHP_OPTIONS = "-l" | |
|
39 | 41 | |
|
40 | 42 | # Check for the correct number of arguments. Otherwise, print usage. |
|
41 | 43 | if ARGV.length == 0 or ARGV.length > 4 |
|
42 | 44 | puts "Usage: compile <language> [<source-file>] [<output-file>] [<message-file>]" |
|
43 | 45 | puts |
|
44 | 46 | puts "<source-file> is defaulted to \"source\"." |
|
45 | 47 | puts "<output-file> is defaulted to \"a.out\"." |
|
46 | 48 | puts "<message-file> is defaulted to \"compiler_message\"." |
|
47 | 49 | puts |
|
48 | 50 | exit(127) |
|
49 | 51 | end |
|
50 | 52 | |
@@ -140,25 +142,37 | |||
|
140 | 142 | #compile to python bytecode |
|
141 | 143 | command = "#{PYTHON_INTERPRETER} -m py_compile #{params[:source_file]}" |
|
142 | 144 | puts "compile: #{command}" |
|
143 | 145 | system(command) |
|
144 | 146 | puts "pwd: " + Dir.pwd |
|
145 | 147 | Dir.new('.').each {|file| puts file} |
|
146 | 148 | File.open(params[:output_file],"w") do |out_file| |
|
147 | 149 | out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c" |
|
148 | 150 | end |
|
149 | 151 | File.chmod(0755, params[:output_file]) |
|
150 | 152 | FileUtils.cp("#{params[:source_file]}c",params[:output_file]) |
|
151 | 153 | end |
|
152 | - | |
|
154 | + | |
|
155 | + when "php" | |
|
156 | + command = "#{PHP_INTERPRETER} #{PHP_OPTIONS} #{params[:source_file]} 2> #{params[:message_file]}" | |
|
157 | + if system(command) | |
|
158 | + File.open(params[:output_file],"w") do |out_file| | |
|
159 | + out_file.puts "#!#{PHP_INTERPRETER}" | |
|
160 | + File.open(params[:source_file],"r").each do |line| | |
|
161 | + out_file.print line | |
|
162 | + end | |
|
163 | + end | |
|
164 | + File.chmod(0755, params[:output_file]) | |
|
165 | + end | |
|
166 | + | |
|
153 | 167 | else |
|
154 | 168 | talk("ERROR: Invalid language specified!") |
|
155 | 169 | open(params[:message_file],"w") do |f| |
|
156 | 170 | f.puts "ERROR: Invalid language specified!" |
|
157 | 171 | end |
|
158 | 172 | exit(127) |
|
159 | 173 | end |
|
160 | 174 | |
|
161 | 175 | # Report success or failure. |
|
162 | 176 | if FileTest.exists? params[:output_file] |
|
163 | 177 | talk "Compilation was successful!" |
|
164 | 178 | else |
@@ -23,25 +23,25 | |||
|
23 | 23 | elsif comment =~ /[Cc]orrect/ |
|
24 | 24 | CORRECT_MARK |
|
25 | 25 | elsif comment =~ /[Tt]ime/ |
|
26 | 26 | TIMEOUT_MARK |
|
27 | 27 | elsif res = /^[Cc]omment:(.*)$/.match(comment) |
|
28 | 28 | res[1] |
|
29 | 29 | else |
|
30 | 30 | RUN_ERROR_MARK # these are run time errors |
|
31 | 31 | end |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def extract_time(t) |
|
35 | - puts "TIME: #{t}" | |
|
35 | + #puts "TIME: #{t}" | |
|
36 | 36 | if (result=/^(.*)r(.*)u(.*)s(.*)kbytes/.match(t)) |
|
37 | 37 | {:real => result[1], :user => result[2], :sys => result[3], :mem => result[4]} |
|
38 | 38 | else |
|
39 | 39 | #{:real => 0, :user => 0, :sys => 0} |
|
40 | 40 | #puts "ERROR READING RUNNING TIME: #{t}" |
|
41 | 41 | raise "Error reading running time: #{t}" |
|
42 | 42 | end |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | problem_home = ENV['PROBLEM_HOME'] |
|
46 | 46 | require "#{problem_home}/script/test_dsl.rb" |
|
47 | 47 | load "#{problem_home}/test_cases/all_tests.cfg" |
@@ -44,25 +44,25 | |||
|
44 | 44 | # ARGV[2] --- test result directory |
|
45 | 45 | # ARGV[3] --- sandbox directory |
|
46 | 46 | |
|
47 | 47 | if ARGV.length < 2 || ARGV.length > 4 |
|
48 | 48 | puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]" |
|
49 | 49 | puts " <sandbox-directory> is defaulted to ./sandbox" |
|
50 | 50 | puts " <test-result-directory> is defaulted to ./test-result" |
|
51 | 51 | puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it." |
|
52 | 52 | exit(127) |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | language = ARGV[0] |
|
56 | - if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" && language != "python" | |
|
56 | + if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" && language != "python" && language != "php" | |
|
57 | 57 | log "You specified a language that is not supported: #{language}." |
|
58 | 58 | exit(127) |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | source_file = ARGV[1] |
|
62 | 62 | ENV['SOURCE_NAME'] = source_file |
|
63 | 63 | if File.exist?(source_file) == false |
|
64 | 64 | log "The source file does not exist." |
|
65 | 65 | exit(127) |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | log "Making test result and sandbox directories..." |
@@ -84,39 +84,42 | |||
|
84 | 84 | |
|
85 | 85 | # Hide PROBLEM_HOME |
|
86 | 86 | ENV['PROBLEM_HOME'] = nil |
|
87 | 87 | ENV['SOURCE_NAME'] = nil |
|
88 | 88 | |
|
89 | 89 | # Run the program. |
|
90 | 90 | #run_command = "/usr/bin/time -f \"#{time_output_format}\" 2>run_result #{problem_home}/script/box_new -a 2 -f -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name}" |
|
91 | 91 | # |
|
92 | 92 | |
|
93 | 93 | JAVA_OPTION = "-s set_robust_list -s futex -s clone -s getppid -s clone -s wait4 -p /usr/bin/ -p ./" |
|
94 | 94 | RUBY_OPTION = "-p /usr/lib64/ -p /lib64/ -p /dev/urandom -p #{sandbox_dir}/#{program_name} -s set_robust_list -s sched_getaffinity -s clock_gettime -s sigaltstack -s pipe2 -s clone -s futex -s openat" |
|
95 | 95 | PYTHON_OPTION = "-p /usr/lib64/ -p /lib64/ -p /usr/bin/ -p /usr/local/lib64/ -p /usr/local/lib/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p #{sandbox_dir}/#{source_name} -s set_robust_list -s openat -s recvmsg -s connect -s socket -s sendto -E PYTHONNOUSERSITE=yes" |
|
96 | + PHP_OPTION = "-p /usr/lib64/ -p/lib64/ -p /usr/bin/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p /usr/share/ -s setfsuid -s setfsgid -s openat -s set_robust_list -s futex " | |
|
96 | 97 | |
|
97 | 98 | case language |
|
98 | 99 | when "java" |
|
99 | 100 | # for java, extract the classname |
|
100 | 101 | # wne have to add additional systemcall and we don't check the mem limit (dunno how to fix...) |
|
101 | 102 | classname = 'DUMMY' |
|
102 | 103 | File.open(program_name,"r").each do |line| |
|
103 | 104 | classname = line |
|
104 | 105 | end |
|
105 | 106 | #for java, we cannot really check the memory limit... |
|
106 | 107 | run_command = "#{problem_home}/script/box -a 3 -f -T -t #{time_limit} #{JAVA_OPTION} -i #{input_file_name} -o output.txt /usr/bin/java #{classname} 2>run_result" |
|
107 | 108 | when "ruby" |
|
108 | 109 | run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{mem_limit} #{RUBY_OPTION} -i #{input_file_name} -o output.txt /usr/bin/ruby #{program_name} 2>run_result" |
|
109 | 110 | when "python" |
|
110 | 111 | run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{mem_limit} #{PYTHON_OPTION} -i #{input_file_name} -o output.txt /usr/bin/python #{program_name} 2>run_result" |
|
112 | + when "php" | |
|
113 | + run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} #{PHP_OPTION} -i #{input_file_name} -o output.txt /usr/bin/php #{program_name} 2>run_result" | |
|
111 | 114 | else # for c++, pascal, we do the normal checking |
|
112 | 115 | run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name} 2>run_result" |
|
113 | 116 | end |
|
114 | 117 | |
|
115 | 118 | |
|
116 | 119 | log "Running test #{test_num}..." |
|
117 | 120 | log run_command |
|
118 | 121 | log |
|
119 | 122 | system(run_command) |
|
120 | 123 | |
|
121 | 124 | # Restore PROBLEM_HOME |
|
122 | 125 | ENV['PROBLEM_HOME'] = problem_home |
You need to be logged in to leave comments.
Login now