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. */
| 256 | * into the original argv strings, valid for the process lifetime) or NULL if the |
| 257 | * flag is absent. */ |
| 258 | static const char *cli_strip_flag_value(int *argc, char **argv, const char *flag) { |
| 259 | for (int i = 0; i < *argc; i++) { |
| 260 | if (strcmp(argv[i], flag) != 0) { |
| 261 | continue; |
| 262 | } |
| 263 | const char *value = (i + SKIP_ONE < *argc) ? argv[i + SKIP_ONE] : NULL; |
| 264 | int remove_count = value ? 2 : 1; |
| 265 | for (int j = i; j < *argc - remove_count; j++) { |
| 266 | argv[j] = argv[j + remove_count]; |
| 267 | } |
| 268 | *argc -= remove_count; |
| 269 | return value; |
| 270 | } |
| 271 | return NULL; |
| 272 | } |
| 273 | |
| 274 | /* Portable "is fd a terminal?" — _isatty on Windows, isatty on POSIX. */ |
| 275 | #ifdef _WIN32 |