@@ -29,57 +29,17 @@ function dj_getopt(string $short_options, array $long_options = []): array
2929 echo "Error: parsing options failed. \nPlease check: `register_argc_arg` in php.ini. \n" ;
3030 usage ();
3131 }
32- check_unknown_cli_options ($ options );
33- return $ options ;
34- }
35-
36- function check_unknown_cli_options (array $ options ): void
37- {
38- global $ argc ;
39- global $ argv ;
40-
41- $ t_argv = $ argv ;
42-
43- // The first is the script name
44- $ t_argc = $ argc -1 ;
45- unset($ t_argv [0 ]);
46- $ t_argv = array_values ($ t_argv );
47-
48- foreach ($ options as $ option_key => $ option_value ) {
49- $ short = '- ' .$ option_key ;
50- $ long = '-- ' .$ option_key ;
51- $ possible = [$ short , $ long ];
52-
53- $ values = [];
54- if ($ option_value !== false ) {
55- if (is_string ($ option_value )) {
56- $ values = [$ option_value ];
57- } else {
58- $ values = $ option_value ;
59- }
60- foreach ($ values as $ value ) {
61- // The value can be appended to the short option
62- $ possible [] = $ short .$ value ;
63- }
64- }
65-
66- $ t_remove = [];
67- for ($ i = 0 ; $ i < $ t_argc ; $ i ++) {
68- if (in_array ($ t_argv [$ i ], array_merge ($ possible , $ values ))) {
69- $ t_remove [] = $ i ;
70- }
32+ $ unknown = false ;
33+ foreach (array_slice ($ argv , 1 ) as $ arg ) {
34+ if (str_starts_with ($ arg , '- ' ) && !array_key_exists (ltrim ($ arg , '- ' ), $ options )) {
35+ echo "Error: Unknown option: $ arg \n" ;
36+ $ unknown = true ;
7137 }
72- foreach ($ t_remove as $ t ) {
73- unset($ t_argv [$ t ]);
74- }
75- $ t_argv = array_values ($ t_argv );
76- $ t_argc -= count ($ t_remove );
7738 }
78-
79- if (count ($ t_argv ) !== 0 ) {
80- echo "Error: found unknown arguments: ' " . implode (' ' , $ t_argv ) . "'. \n" ;
39+ if ($ unknown ) {
8140 usage ();
8241 }
42+ return $ options ;
8343}
8444
8545function judging_directory (string $ workdirpath , array $ judgeTask ) : string
0 commit comments