MCPcopy Create free account
hub / github.com/ElementsProject/lightning / parse_one

Function parse_one

ccan/ccan/opt/parse.c:82–184  ·  view source on GitHub ↗

Returns 1 if argument consumed, 0 if all done, -1 on error. */

Source from the content-addressed store, hash-verified

80
81/* Returns 1 if argument consumed, 0 if all done, -1 on error. */
82int parse_one(int *argc, char *argv[], enum opt_type is_early, unsigned *offset,
83 void (*errlog)(const char *fmt, ...), bool unknown_ok)
84{
85 unsigned arg, len;
86 const char *o, *optarg = NULL;
87 char *problem = NULL;
88 struct opt_table *ot;
89
90 if (getenv("POSIXLY_CORRECT")) {
91 /* Don't find options after non-options. */
92 arg = 1;
93 } else {
94 for (arg = 1; argv[arg]; arg++) {
95 if (argv[arg][0] == '-' && argv[arg][1])
96 break;
97 }
98 }
99
100 /* A bare '-' is an operand, not an option. */
101 if (!argv[arg] || argv[arg][0] != '-' || argv[arg][1] == '\0')
102 return 0;
103
104 /* Special arg terminator option. */
105 if (strcmp(argv[arg], "--") == 0) {
106 consume_option(argc, argv, arg);
107 return 0;
108 }
109
110 /* Long options start with -- */
111 if (argv[arg][1] == '-') {
112 assert(*offset == 0);
113
114 ot = opt_find_long_extra(argv[arg]+2, &optarg, &len, &o);
115 if (!ot) {
116 if (unknown_ok)
117 goto ok;
118 return parse_err(errlog, argv[0],
119 argv[arg], strlen(argv[arg]),
120 "unrecognized option");
121 }
122
123 /* For error messages, we include the leading '--' */
124 o -= 2;
125 len += 2;
126 } else {
127 ot = opt_find_short_extra(argv[arg][*offset + 1], &o);
128 if (!ot) {
129 if (unknown_ok) {
130 (*offset)++;
131 goto ok;
132 }
133 return parse_err(errlog, argv[0],
134 argv[arg], strlen(argv[arg]),
135 "unrecognized option");
136 }
137
138 (*offset)++;
139 /* For error messages, we include the leading '-' */

Callers 2

opt_parseFunction · 0.85
early_parseFunction · 0.85

Calls 4

consume_optionFunction · 0.85
opt_find_long_extraFunction · 0.85
parse_errFunction · 0.85
opt_find_short_extraFunction · 0.85

Tested by

no test coverage detected