This commit is contained in:
zhaarey
2024-12-20 17:34:58 +08:00
parent caf52b1f91
commit de7cff2b54
13 changed files with 95 additions and 634 deletions

View File

@@ -40,11 +40,13 @@ const char *gengetopt_args_info_help[] = {
" -D, --decrypt-port=INT (default=`10020')",
" -M, --m3u8-port=INT (default=`20020')",
" -P, --proxy=STRING (default=`')",
" -L, --login=STRING ",
" -L, --login=STRING username:password",
" -F, --code-from-file (default=off)",
0
};
typedef enum {ARG_NO
, ARG_FLAG
, ARG_STRING
, ARG_INT
} cmdline_parser_arg_type;
@@ -72,6 +74,7 @@ void clear_given (struct gengetopt_args_info *args_info)
args_info->m3u8_port_given = 0 ;
args_info->proxy_given = 0 ;
args_info->login_given = 0 ;
args_info->code_from_file_given = 0 ;
}
static
@@ -88,6 +91,7 @@ void clear_args (struct gengetopt_args_info *args_info)
args_info->proxy_orig = NULL;
args_info->login_arg = NULL;
args_info->login_orig = NULL;
args_info->code_from_file_flag = 0;
}
@@ -103,6 +107,7 @@ void init_args_info(struct gengetopt_args_info *args_info)
args_info->m3u8_port_help = gengetopt_args_info_help[4] ;
args_info->proxy_help = gengetopt_args_info_help[5] ;
args_info->login_help = gengetopt_args_info_help[6] ;
args_info->code_from_file_help = gengetopt_args_info_help[7] ;
}
@@ -244,6 +249,8 @@ cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
write_into_file(outfile, "proxy", args_info->proxy_orig, 0);
if (args_info->login_given)
write_into_file(outfile, "login", args_info->login_orig, 0);
if (args_info->code_from_file_given)
write_into_file(outfile, "code-from-file", 0, 0 );
i = EXIT_SUCCESS;
@@ -410,6 +417,9 @@ int update_arg(void *field, char **orig_field,
val = possible_values[found];
switch(arg_type) {
case ARG_FLAG:
*((int *)field) = !*((int *)field);
break;
case ARG_INT:
if (val) *((int *)field) = strtol (val, &stop_char, 0);
break;
@@ -440,6 +450,7 @@ int update_arg(void *field, char **orig_field,
/* store the original value */
switch(arg_type) {
case ARG_NO:
case ARG_FLAG:
break;
default:
if (value && orig_field) {
@@ -507,10 +518,11 @@ cmdline_parser_internal (
{ "m3u8-port", 1, NULL, 'M' },
{ "proxy", 1, NULL, 'P' },
{ "login", 1, NULL, 'L' },
{ "code-from-file", 0, NULL, 'F' },
{ 0, 0, 0, 0 }
};
c = getopt_long (argc, argv, "hVH:D:M:P:L:", long_options, &option_index);
c = getopt_long (argc, argv, "hVH:D:M:P:L:F", long_options, &option_index);
if (c == -1) break; /* Exit from `while (1)' loop. */
@@ -574,7 +586,7 @@ cmdline_parser_internal (
goto failure;
break;
case 'L': /* . */
case 'L': /* username:password. */
if (update_arg( (void *)&(args_info->login_arg),
@@ -586,6 +598,16 @@ cmdline_parser_internal (
goto failure;
break;
case 'F': /* . */
if (update_arg((void *)&(args_info->code_from_file_flag), 0, &(args_info->code_from_file_given),
&(local_args_info.code_from_file_given), optarg, 0, 0, ARG_FLAG,
check_ambiguity, override, 1, 0, "code-from-file", 'F',
additional_error))
goto failure;
break;
case 0: /* Long option with no short option */
case '?': /* Invalid option. */