Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement judgedaemon fixme's #2745

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions judge/judgedaemon.main.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,52 @@
$endpoints = [];
$domjudge_config = [];

function dj_getopt(string $short_options, array $long_options = []): array
{
global $argv;
define('GETOPT_REGEX', "/^([a-zA-Z0-9]:{0,2})*$/");
if (preg_match(GETOPT_REGEX, $short_options) !== 1) {
vmcj marked this conversation as resolved.
Show resolved Hide resolved
echo "Error: short options format specified is invalid.\n";
usage();
}
$options = getopt($short_options, $long_options);
if ($options===false || !is_array($argv)) {
echo "Error: parsing options failed.\nPlease check: `register_argc_arg` in php.ini.\n";
usage();
}
$unknown_option = false;
foreach (array_slice($argv, 1) as $arg) {
if ($arg === '--') {
// By convention we can stop processing arguments.
break;
}
if (str_starts_with($arg, '--')) {
foreach($long_options as $long_option) {

Check failure on line 39 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space(s) after FOREACH keyword; 0 found
$stripped_arg = substr($arg, 2);
if (str_starts_with($long_option, $stripped_arg) && $stripped_arg !== $long_option) {
echo "Error: Shorten long options is not supported: $arg\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Error: Shorten long options is not supported: $arg\n";
echo "Error: shortening long options is not supported: $arg\n";

$unknown_option = true;
} elseif (!array_key_exists($stripped_arg, $options)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this will work with something like --my-long-option=foo.

echo "Error: Unknown option: $arg\n";
$unknown_option = true;
}
}
} elseif (str_starts_with($arg, '-')) {
foreach (str_split(ltrim($arg, '-')) as $c) {
if (!array_key_exists($c, $options)) {
echo "Error: Unknown option: $arg\n";
$unknown_option = true;
}
}
}
}
if ($unknown_option) {
echo "\n";
usage();
}
return $options;
}

function judging_directory(string $workdirpath, array $judgeTask) : string
{
if (filter_var($judgeTask['submitid'], FILTER_VALIDATE_INT) === false ||
Expand Down Expand Up @@ -487,12 +533,7 @@
return [$execrunpath, null, null];
}

$options = getopt("dv:n:hVe:j:t:", ["diskspace-error"]);
// FIXME: getopt doesn't return FALSE on parse failure as documented!
vmcj marked this conversation as resolved.
Show resolved Hide resolved
if ($options===false) {
echo "Error: parsing options failed.\n";
usage();
}
$options = dj_getopt("dv:n:hVe:j:t:", ["diskspace-error"]);
if (isset($options['v'])) {
$options['verbose'] = $options['v'];
}
Expand Down
Loading