diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-02-16 01:30:44 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-02-16 01:37:24 +0200 |
commit | 5000c56d29cf616c8df80f8ec9a19682769f512e (patch) | |
tree | d2cc46fda9e8905bdd2fb81bffdaf3a58898be53 /src/interval.c | |
parent | a72cd5987c404080f18ba40bdc4c06811493ab1c (diff) | |
download | wydawca-5000c56d29cf616c8df80f8ec9a19682769f512e.tar.gz wydawca-5000c56d29cf616c8df80f8ec9a19682769f512e.tar.bz2 |
Rewrite configuration parser, drop dependency on GSC
* bootstrap: Replaced with a modified version from gnulib.
* configure.ac: Bump version to 1.9.90
(--without-preprocessor): New option
Require Mailutils 2.0
(AC_CONFIG_FILES): Remove lib, add gconf
* gconf/: New directory. Contains general-purpose configuration file
parser, distilled from Dico and Mailutils.
* src/Makefile.am (wydawca_SOURCES): Add interval.c
* src/pp-setup, src/update-2.0.awk: New files.
* src/config.c: Full rewrite.
* src/exec.c (start_prog): Use getdtablesize unconditionally.
* src/mail.c: Keep templates in a hash table.
Template references begin with a single @
* src/process.c, src/triplet.c, src/verify.c: Reflect changes to struct
directory_pair
* src/wydawca.c: Change configuration parsing.
* src/wydawca.h (enum access_method_id): New constants
(struct directory_pair): Replace four access methods with an array.
* Makefile.am (SUBDIRS): Remove lib, add gconf
* .gitignore, NEWS, doc/.gitignore, src/.gitignore
Diffstat (limited to 'src/interval.c')
-rw-r--r-- | src/interval.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/interval.c b/src/interval.c new file mode 100644 index 0000000..0792123 --- /dev/null +++ b/src/interval.c @@ -0,0 +1,119 @@ +/* wydawca - automatic release submission daemon + Copyright (C) 2007, 2009 Sergey Poznyakoff + + Wydawca is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. + + Wydawca is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with wydawca. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include "wydawca.h" + +static int +time_multiplier (const char *str, unsigned *m, unsigned *plen) +{ + static struct timetab + { + char *name; + unsigned mul; + } tab[] = { + { "seconds", 1 }, + { "minutes", 60 }, + { "hours", 60*60 }, + { "days", 24*60*60 }, + { "weeks", 7*24*60*60 }, + { "months", 31*7*24*60*60 }, + { NULL } + }; + struct timetab *p; + int slen; + + for (slen = 0; str[slen]; slen++) + if (isspace (str[slen])) + break; + + for (p = tab; p->name; p++) + { + if (p->name[0] == tolower (str[0])) + { + int nlen = strlen (p->name); + + if (nlen > slen) + nlen = slen; + + if (strncasecmp (p->name, str, nlen) == 0) + { + *m = p->mul; + if (plen) + *plen = nlen; + return 0; + } + } + } + return 1; +} + +int +parse_time_interval (const char *str, time_t *pint, const char **endp) +{ + int rc = 0; + time_t interval = 0; + + while (*str) + { + char *p; + unsigned long n; + unsigned mul, len; + + while (*str && isspace (*str)) + str++; + + if (!isdigit (*str) && time_multiplier (str, &mul, &len) == 0) + { + n = 1; + str += len; + } + else + { + n = strtoul (str, &p, 10); + if (*p && !isspace (*p)) + { + str = p; + rc = 1; + break; + } + + while (*p && isspace (*p)) + p++; + + str = p; + if (*str) + { + if (rc = time_multiplier (str, &mul, &len)) + break; + str += len; + } + else + mul = 1; + } + interval += n * mul; + } + + if (rc && endp) + *endp = str; + *pint = interval; + return rc; +} |