222 {
226 } else {
228 }
229 size_t args_cap = 4;
230 #define APPEND_ARG(arg) if (app->_args.length + 1 > args_cap) { \
231 args_cap += (args_cap / 2); \
232 app->_args.contents = realloc(app->_args.contents, \
233 sizeof(char*) * args_cap); \
234 } \
235 if (app->_proc) { \
236 app->_proc(app->_user_data, NULL, arg); \
237 } \
238 app->_args.contents[app->_args.length++] = arg;
239
240 bool only_args = false;
241 for (
int i = 0; i < app->
_argc; i++) {
242 char* current = app->
_argv[i];
243 if (only_args) {
245 continue;
246 }
247 const char* next = app->
_argv[i + 1];
249 only_args = true;
250 continue;
251 }
254
255 char*
arg = strchr(current,
'=');
256
260 }
263 if (
arg == NULL || *
arg == 0) {
264 eprintf(
"%s expects an argument\n", current);
266 }
270 } else {
272 eprintf(
"%s does not take arguments\n", current);
274 }
275 }
276 } else {
277 if (strncmp(current, "--help", 7) == 0) {
281 } else if (strncmp(current, "--version", 10) == 0) {
285 }
286 eprintf(
"Unrecognized command line option %s, try --help\n", current);
288 }
292 }
299 if (!current[2] && next && next[0] != '-') {
301 i++;
302 } else if (current[2] == 0) {
303 eprintf(
"-%c expects an argument\n", current[1]);
305 }
306 } else if ((current[2] != 0) || (next && next[0] != '-')) {
307 eprintf(
"-%c does not take arguments\n", current[1]);
309 }
310 } else {
311 eprintf(
"Unrecognized command line option -%c, try --help\n",
312 current[1]);
314 }
318 }
319 } else {
320 for (size_t j = 1; current[j]; j++) {
324 if (next && next[0] != '-') {
326 i++;
327 } else {
328 eprintf(
"-%c expects an argument\n", current[1]);
330 }
331 }
332 } else {
333 eprintf(
"Unrecognized command line option -%c\n",
334 current[1]);
336 }
337 }
338 }
339 } else {
341 }
342 }
343 #undef APPEND_ARG
344
347 }
348
350}
static int cmdapp_resolve_options(cmdapp_t *app)
void cmdapp_print_version(cmdapp_t *app)
#define IS_LONG_FLAG(str)
#define IS_END_OF_FLAGS(str)
#define IS_SHORT_FLAG(str)
void cmdapp_print_help(cmdapp_t *app)
static cmdarg_internal_t * cmdapp_search(cmdapp_t *app, char shorto, const char *longo)
#define _CMDAPP_MODE_EXIT
#define CMDAPP_MODE_SHORTARG