Skip to content

Commit

Permalink
Fix some options not taking effect
Browse files Browse the repository at this point in the history
Fixes GH-20
  • Loading branch information
vicgeralds committed Dec 23, 2020
1 parent 69f8f3d commit fed2ce5
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@

struct sect sect_hd = {""};

static int to_integer(const char *str, int n)
{
int i = *str=='-';
if (str[i]>'0' && str[i]<='9') {
i++;
for (; i<n; i++)
if (!isdigit(str[i]))
return 0;
return atoi(str);
}
return 0;
}

int strtoval(char *str, union val *val)
{
int n, i;
int n;
while (isspace(*str))
str++;
n = strlen(str);
Expand All @@ -21,16 +34,10 @@ int strtoval(char *str, union val *val)
val->p = str;
return 2;
}
i = *str=='-';
if (str[i]>'0' && str[i]<='9') {
val->integ = atoi(str);
i++;
for (; i<n; i++)
if (!isdigit(str[i]))
goto str;
if ((val->integ = to_integer(str, n)) != 0) {
return 0;
}
str: strncpy(val->str, str, 4);
strncpy(val->str, str, 4);
if (n && n<4)
val->str[n] = '\0';
return 1;
Expand Down Expand Up @@ -129,7 +136,9 @@ int getopt_int(const char *sect_name, const char *key)
if (o) {
const char *s = opt_longstr(o);
if (s) {
return atoi(s);
int d = to_integer(s, strlen(s));
if (d != 0)
return d;
}
return o->val.integ;
}
Expand Down

0 comments on commit fed2ce5

Please sign in to comment.