comparison lwlib/lw_cmdline.c @ 105:3e9057059a43

Even more command line parser fixing
author lost@l-w.ca
date Sat, 06 Aug 2011 23:20:10 -0600
parents bc82df7f6bbe
children ddffceb3c331
comparison
equal deleted inserted replaced
104:bc82df7f6bbe 105:3e9057059a43
393 for (j = 0; parser -> options[j].name; j++) 393 for (j = 0; parser -> options[j].name; j++)
394 if (parser -> options[j].key == argv[i][cch]) 394 if (parser -> options[j].key == argv[i][cch])
395 break; 395 break;
396 cch++; 396 cch++;
397 tstr = argv[i] + cch; 397 tstr = argv[i] + cch;
398 if (!*tstr && (parser -> options[j].flags & lw_cmdline_opt_optional) == 0) 398 if (*tstr == 0)
399 tstr = NULL;
400 if (!tstr && (parser -> options[j].flags & lw_cmdline_opt_optional) == 0)
399 { 401 {
400 /* only consume the next arg if the argument is optional */ 402 /* only consume the next arg if the argument is optional */
401 if (nextarg < argc) 403 if (nextarg < argc)
402 tstr = argv[nextarg]; 404 tstr = argv[nextarg];
403 else 405 else
427 if (strcmp(parser -> options[j].name, tstr) == 0) 429 if (strcmp(parser -> options[j].name, tstr) == 0)
428 break; 430 break;
429 } 431 }
430 lw_free(tstr); 432 lw_free(tstr);
431 tstr = argv[i] + cch; 433 tstr = argv[i] + cch;
434 if (*tstr == 0)
435 tstr = NULL;
432 cch = 0; 436 cch = 0;
433 i++; 437 i++;
434 438
435 common: 439 common:
436 /* j will be the offset into the option table when we get here */ 440 /* j will be the offset into the option table when we get here */
448 if (parser -> options[j].arg) 452 if (parser -> options[j].arg)
449 { 453 {
450 if (tstr && cch && argv[i][cch] == 0) 454 if (tstr && cch && argv[i][cch] == 0)
451 nextarg++; 455 nextarg++;
452 456
453 if (!*tstr) 457 //if (!*tstr)
454 tstr = NULL; 458 // tstr = NULL;
455 459
456 /* move on to next argument if we have an arg specified */ 460 /* move on to next argument if we have an arg specified */
457 if (tstr && cch && argv[i][cch] != 0) 461 if (tstr && cch && argv[i][cch] != 0)
458 { 462 {
459 i++; 463 i++;