light: option parser: allow negative numbers as option args

This commit is contained in:
Eric Wasylishen 2016-06-30 14:14:59 -06:00
parent a7e9d9bba4
commit ec6352a5fe
1 changed files with 14 additions and 5 deletions

View File

@ -1311,12 +1311,21 @@ static void PrintUsage()
static bool ParseVec3Optional(vec3_t vec3_out, int *i_inout, int argc, const char **argv)
{
if ((*i_inout + 3) < argc) {
// negative numbers are rejected, they would be confused with flags.
if (!isdigit(argv[*i_inout + 1][0])
|| !isdigit(argv[*i_inout + 2][0])
|| !isdigit(argv[*i_inout + 3][0])) {
return false;
const int start = (*i_inout + 1);
const int end = (*i_inout + 3);
// validate that there are 3 numbers
for (int j=start; j <= end; j++) {
if (argv[j][0] == '-' && isdigit(argv[j][1])) {
continue; // accept '-' followed by a digit for negative numbers
}
// otherwise, reject if the first character is not a digit
if (!isdigit(argv[j][0])) {
return false;
}
}
vec3_out[0] = atof( argv[ ++(*i_inout) ] );
vec3_out[1] = atof( argv[ ++(*i_inout) ] );
vec3_out[2] = atof( argv[ ++(*i_inout) ] );