Strip a flag AND its following value from argv, returning the value (a pointer * into the original argv strings, valid for the process lifetime) or NULL if the * flag is absent. */
| 585 | * into the original argv strings, valid for the process lifetime) or NULL if the |
| 586 | * flag is absent. */ |
| 587 | static const char *cli_strip_flag_value(int *argc, char **argv, const char *flag) { |
| 588 | for (int i = 0; i < *argc; i++) { |
| 589 | if (strcmp(argv[i], flag) != 0) { |
| 590 | continue; |
| 591 | } |
| 592 | const char *value = (i + SKIP_ONE < *argc) ? argv[i + SKIP_ONE] : NULL; |
| 593 | int remove_count = value ? 2 : 1; |
| 594 | for (int j = i; j < *argc - remove_count; j++) { |
| 595 | argv[j] = argv[j + remove_count]; |
| 596 | } |
| 597 | *argc -= remove_count; |
| 598 | return value; |
| 599 | } |
| 600 | return NULL; |
| 601 | } |
| 602 | |
| 603 | /* Portable "is fd a terminal?" — _isatty on Windows, isatty on POSIX. */ |
| 604 | #ifdef _WIN32 |