Files
xserver/os/cmdline.c
Enrico Weigelt, metux IT consult 2d5c8090a8 (!1688) os: helper for parsing an counting-flag or value-flag option
Parses an option that may either be used for setting an integer value or
given one or multiple times (without argument) to increase an value

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2024-09-18 17:23:12 +02:00

33 lines
665 B
C

/* SPDX-License-Identifier: MIT OR X11
*
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
*
* @brief command line helper functions
*/
#include <dix-config.h>
#include <string.h>
#include <stdlib.h>
#include "os/cmdline.h"
int ProcessCmdLineMultiInt(int argc, char *argv[], int *idx, const char* name, int *value)
{
if (strcmp(argv[*idx], name))
return 0;
int i2 = *idx+1;
if (i2 < argc && argv[i2]) {
char *end;
long val = strtol(argv[i2], &end, 0);
if (*end == '\0') {
(*idx)++;
(*value) = val;
return 1;
}
}
(*value)++;
return 1;
}