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. */
| 755 | * into the original argv strings, valid for the process lifetime) or NULL if the |
| 756 | * flag is absent. */ |
| 757 | static const char *cli_strip_flag_value(int *argc, char **argv, const char *flag) { |
| 758 | for (int i = 0; i < *argc; i++) { |
| 759 | if (strcmp(argv[i], flag) != 0) { |
| 760 | continue; |
| 761 | } |
| 762 | const char *value = (i + SKIP_ONE < *argc) ? argv[i + SKIP_ONE] : NULL; |
| 763 | int remove_count = value ? 2 : 1; |
| 764 | for (int j = i; j < *argc - remove_count; j++) { |
| 765 | argv[j] = argv[j + remove_count]; |
| 766 | } |
| 767 | *argc -= remove_count; |
| 768 | return value; |
| 769 | } |
| 770 | return NULL; |
| 771 | } |
| 772 | |
| 773 | /* Portable "is fd a terminal?" — _isatty on Windows, isatty on POSIX. */ |
| 774 | #ifdef _WIN32 |