Commit f335464c authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(struct suffix_conversion): New struct.

(suffix_table): New table.
(assign_timeval): New assigner.
parent 96524840
/*
* $Id: conf-file.c,v 1.26 2003/07/12 00:16:49 ceder Exp $
* $Id: conf-file.c,v 1.27 2003/07/12 21:29:03 ceder Exp $
* Copyright (C) 1994-1995, 1998-1999, 2001-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -59,6 +59,7 @@
#include "conf-file.h"
#include "lyskomd.h"
#include "eintr.h"
#include "timeval-util.h"
#define MAXLINE 1001
......@@ -379,6 +380,87 @@ assign_double(const char *val,
return OK;
}
struct suffix_conversion {
const char *suffix;
double factor;
};
static const struct suffix_conversion suffix_table[] = {
{"seconds", 1.0},
{"second", 1.0},
{"sec", 1.0},
{"s", 1.0},
{"minutes", 60.0},
{"minute", 60.0},
{"min", 60.0},
{"hours", 3600.0},
{"hour", 3600.0},
{"h", 3600.0},
{"days", 86400.0},
{"day", 86400.0},
{"d", 86400.0},
{"milliseconds", 0.001},
{"millisecond", 0.001},
{"milli", 0.001},
{"ms", 0.001},
{"microseconds", 0.000001},
{"microsecond", 0.000001},
{"micro", 0.000001},
{"us", 0.000001},
{"u", 0.000001},
{"kiloseconds", 1000.0},
{"megaseconds", 1000000.0},
{"microfortnights", 1.2096},
{"microfortnight", 1.2096},
{NULL, 0.0},
};
Success
assign_timeval(const char *val,
const struct parameter *par)
{
char *tail = NULL;
double number;
const char *suffix;
const struct suffix_conversion *s;
assert(par->default_suffix != NULL);
if (val != NULL)
{
errno = 0;
number = strtod(val, &tail);
if (errno || tail == val)
return FAILURE;
if (*tail != '\0')
suffix = tail;
else
suffix = par->default_suffix;
for (s = suffix_table; s->suffix != NULL; ++s)
if (!strcmp(s->suffix, suffix))
break;
if (s->suffix == NULL)
return FAILURE;
number *= s->factor;
*(struct timeval*)par->value = timeval_ctor(
number, (number - (int)number) * 1000000);
}
return OK;
}
void
unassign_string(const struct parameter *par)
......
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