Skip to content

Commit 50aca17

Browse files
committed
cli: update to latest version of adopt
1 parent 1e44d32 commit 50aca17

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

cli/ntlm_cli_opt.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* This file was produced by using the `rename.pl` script included with
1111
* adopt. The command-line specified was:
1212
*
13-
* ./rename.pl --out=../ntlmclient/cli/ --filename=ntlm_cli_opt ntlm_opt
13+
* ./rename.pl --filename=ntlm_cli_opt ntlm_opt
1414
*/
1515

1616
#include <stdlib.h>
@@ -22,7 +22,7 @@
2222
#include "ntlm_cli_opt.h"
2323

2424
#ifdef _WIN32
25-
# include <Windows.h>
25+
# include <windows.h>
2626
#else
2727
# include <fcntl.h>
2828
# include <sys/ioctl.h>
@@ -78,7 +78,7 @@ INLINE(const ntlm_opt_spec *) spec_for_long(
7878

7979
/* Handle --option=value arguments */
8080
if (spec->type == NTLM_OPT_TYPE_VALUE &&
81-
eql &&
81+
spec->name && eql &&
8282
strncmp(arg, spec->name, eql_pos) == 0 &&
8383
spec->name[eql_pos] == '\0') {
8484
*has_value = 1;
@@ -580,6 +580,28 @@ ntlm_opt_status_t ntlm_opt_parse(
580580
return validate_required(opt, specs, given_specs);
581581
}
582582

583+
int ntlm_opt_foreach(
584+
const ntlm_opt_spec specs[],
585+
char **args,
586+
size_t args_len,
587+
unsigned int flags,
588+
int (*callback)(ntlm_opt *, void *),
589+
void *callback_data)
590+
{
591+
ntlm_opt_parser parser;
592+
ntlm_opt opt;
593+
int ret;
594+
595+
ntlm_opt_parser_init(&parser, specs, args, args_len, flags);
596+
597+
while (ntlm_opt_parser_next(&opt, &parser)) {
598+
if ((ret = callback(&opt, callback_data)) != 0)
599+
return ret;
600+
}
601+
602+
return 0;
603+
}
604+
583605
static int spec_name_fprint(FILE *file, const ntlm_opt_spec *spec)
584606
{
585607
int error;
@@ -621,7 +643,7 @@ int ntlm_opt_status_fprint(
621643
if ((error = fprintf(file, "argument '")) < 0 ||
622644
(error = spec_name_fprint(file, opt->spec)) < 0 ||
623645
(error = fprintf(file, "' requires a value.\n")) < 0)
624-
;
646+
break;
625647
break;
626648
case NTLM_OPT_STATUS_MISSING_ARGUMENT:
627649
if (spec_is_choice(opt->spec)) {

cli/ntlm_cli_opt.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* This file was produced by using the `rename.pl` script included with
1111
* adopt. The command-line specified was:
1212
*
13-
* ./rename.pl --out=../ntlmclient/cli/ --filename=ntlm_cli_opt ntlm_opt
13+
* ./rename.pl --filename=ntlm_cli_opt ntlm_opt
1414
*/
1515

1616
#ifndef NTLM_CLI_OPT_H
@@ -300,6 +300,24 @@ ntlm_opt_status_t ntlm_opt_parse(
300300
size_t args_len,
301301
unsigned int flags);
302302

303+
/**
304+
* Quickly executes the given callback for each argument.
305+
*
306+
* @param specs A NULL-terminated array of `ntlm_opt_spec`s that can be parsed
307+
* @param args The arguments that will be parsed
308+
* @param args_len The length of arguments to be parsed
309+
* @param flags The `ntlm_opt_flag_t flags for parsing
310+
* @param callback The callback to invoke for each specified option
311+
* @param callback_data Data to be provided to the callback
312+
*/
313+
int ntlm_opt_foreach(
314+
const ntlm_opt_spec specs[],
315+
char **args,
316+
size_t args_len,
317+
unsigned int flags,
318+
int (*callback)(ntlm_opt *, void *),
319+
void *callback_data);
320+
303321
/**
304322
* Initializes a parser that parses the given arguments according to the
305323
* given specifications.

0 commit comments

Comments
 (0)