MCPcopy Create free account
hub / github.com/cppla/ServerStatus / argparse_getvalue

Function argparse_getvalue

server/src/argparse.c:39–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39static int
40argparse_getvalue(struct argparse *this_, const struct argparse_option *opt,
41 int flags)
42{
43 const char *s = NULL;
44 if (!opt->value)
45 goto skipped;
46 switch (opt->type) {
47 case ARGPARSE_OPT_BOOLEAN:
48 if (flags & OPT_UNSET) {
49 *(int *)opt->value = *(int *)opt->value - 1;
50 } else {
51 *(int *)opt->value = *(int *)opt->value + 1;
52 }
53 if (*(int *)opt->value < 0) {
54 *(int *)opt->value = 0;
55 }
56 break;
57 case ARGPARSE_OPT_BIT:
58 if (flags & OPT_UNSET) {
59 *(int *)opt->value &= ~opt->data;
60 } else {
61 *(int *)opt->value |= opt->data;
62 }
63 break;
64 case ARGPARSE_OPT_STRING:
65 if (this_->optvalue) {
66 *(const char **)opt->value = this_->optvalue;
67 this_->optvalue = NULL;
68 } else if (this_->argc > 1) {
69 this_->argc--;
70 *(const char **)opt->value = *++this_->argv;
71 } else {
72 argparse_error(this_, opt, "requires a value");
73 }
74 break;
75 case ARGPARSE_OPT_INTEGER:
76 if (this_->optvalue) {
77 *(int *)opt->value = strtol(this_->optvalue, (char **)&s, 0);
78 this_->optvalue = NULL;
79 } else if (this_->argc > 1) {
80 this_->argc--;
81 *(int *)opt->value = strtol(*++this_->argv, (char **)&s, 0);
82 } else {
83 argparse_error(this_, opt, "requires a value");
84 }
85 if (*s)
86 argparse_error(this_, opt, "expects a numerical value");
87 break;
88 default:
89 assert(0);
90 }
91
92skipped:
93 if (opt->callback) {
94 return opt->callback(this_, opt);
95 }
96

Callers 2

argparse_short_optFunction · 0.85
argparse_long_optFunction · 0.85

Calls 1

argparse_errorFunction · 0.85

Tested by

no test coverage detected