Commit 7a7cacd2 authored by Baptiste Jonglez's avatar Baptiste Jonglez

Rename parse_msec() and getmsec() to parse_thousands() and getthousands()

parse_msec() is not specific to milliseconds, it can parse any
fixed-point string.  It can be used, for instance, to parse a
fixed-point string written in milliseconds and interpret it as an
integer in microseconds.
parent 9d0023e7
...@@ -148,13 +148,13 @@ main(int argc, char **argv) ...@@ -148,13 +148,13 @@ main(int argc, char **argv)
goto usage; goto usage;
break; break;
case 'h': case 'h':
default_wireless_hello_interval = parse_msec(optarg); default_wireless_hello_interval = parse_thousands(optarg);
if(default_wireless_hello_interval <= 0 || if(default_wireless_hello_interval <= 0 ||
default_wireless_hello_interval > 0xFFFF * 10) default_wireless_hello_interval > 0xFFFF * 10)
goto usage; goto usage;
break; break;
case 'H': case 'H':
default_wired_hello_interval = parse_msec(optarg); default_wired_hello_interval = parse_thousands(optarg);
if(default_wired_hello_interval <= 0 || if(default_wired_hello_interval <= 0 ||
default_wired_hello_interval > 0xFFFF * 10) default_wired_hello_interval > 0xFFFF * 10)
goto usage; goto usage;
......
...@@ -148,14 +148,14 @@ getint(int c, int *int_r, gnc_t gnc, void *closure) ...@@ -148,14 +148,14 @@ getint(int c, int *int_r, gnc_t gnc, void *closure)
} }
static int static int
getmsec(int c, int *int_r, gnc_t gnc, void *closure) getthousands(int c, int *int_r, gnc_t gnc, void *closure)
{ {
char *t; char *t;
int i; int i;
c = getword(c, &t, gnc, closure); c = getword(c, &t, gnc, closure);
if(c < -1) if(c < -1)
return c; return c;
i = parse_msec(t); i = parse_thousands(t);
if(i < 0) { if(i < 0) {
free(t); free(t);
return -2; return -2;
...@@ -408,13 +408,13 @@ parse_anonymous_ifconf(int c, gnc_t gnc, void *closure, ...@@ -408,13 +408,13 @@ parse_anonymous_ifconf(int c, gnc_t gnc, void *closure,
if_conf->cost = cost; if_conf->cost = cost;
} else if(strcmp(token, "hello-interval") == 0) { } else if(strcmp(token, "hello-interval") == 0) {
int interval; int interval;
c = getmsec(c, &interval, gnc, closure); c = getthousands(c, &interval, gnc, closure);
if(c < -1 || interval <= 0 || interval > 10 * 0xFFFF) if(c < -1 || interval <= 0 || interval > 10 * 0xFFFF)
goto error; goto error;
if_conf->hello_interval = interval; if_conf->hello_interval = interval;
} else if(strcmp(token, "update-interval") == 0) { } else if(strcmp(token, "update-interval") == 0) {
int interval; int interval;
c = getmsec(c, &interval, gnc, closure); c = getthousands(c, &interval, gnc, closure);
if(c < -1 || interval <= 0 || interval > 10 * 0xFFFF) if(c < -1 || interval <= 0 || interval > 10 * 0xFFFF)
goto error; goto error;
if_conf->update_interval = interval; if_conf->update_interval = interval;
......
...@@ -152,8 +152,10 @@ parse_nat(const char *string) ...@@ -152,8 +152,10 @@ parse_nat(const char *string)
return (int)l; return (int)l;
} }
/* Given a fixed-point string such as "42.1337", returns 1000 times
the value of the string, here 42133. */
int int
parse_msec(const char *string) parse_thousands(const char *string)
{ {
unsigned int in, fl; unsigned int in, fl;
int i, j; int i, j;
......
...@@ -78,7 +78,7 @@ int timeval_compare(const struct timeval *s1, const struct timeval *s2) ...@@ -78,7 +78,7 @@ int timeval_compare(const struct timeval *s1, const struct timeval *s2)
void timeval_min(struct timeval *d, const struct timeval *s); void timeval_min(struct timeval *d, const struct timeval *s);
void timeval_min_sec(struct timeval *d, time_t secs); void timeval_min_sec(struct timeval *d, time_t secs);
int parse_nat(const char *string) ATTRIBUTE ((pure)); int parse_nat(const char *string) ATTRIBUTE ((pure));
int parse_msec(const char *string) ATTRIBUTE ((pure)); int parse_thousands(const char *string) ATTRIBUTE ((pure));
void do_debugf(int level, const char *format, ...) void do_debugf(int level, const char *format, ...)
ATTRIBUTE ((format (printf, 2, 3))) COLD; ATTRIBUTE ((format (printf, 2, 3))) COLD;
int in_prefix(const unsigned char *restrict address, int in_prefix(const unsigned char *restrict address,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment