masqmail
view src/timeival.c @ 1:af25f5c39d90
added diff from debian (masqmail-0.2.21-4)
author | meillo@marmaro.de |
---|---|
date | Fri, 26 Sep 2008 20:56:23 +0200 |
parents | |
children | 26e34ae9a3e3 |
line source
1 /* MasqMail
2 Copyright (C) 1999-2002 Oliver Kurth
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
19 #include <ctype.h>
20 #include <glib.h>
22 #include "masqmail.h"
24 gint time_interval(gchar *str, gint *pos)
25 {
26 gchar buf[16];
27 gchar *p = str, *q = buf;
28 gint factor = 1, val;
30 while(*p && isdigit(*p) && (q < buf+15)){
31 *(q++) = *(p++);
32 (*pos)++;
33 }
34 (*pos)++;
35 *q = 0;
36 val = atoi(buf);
38 /* fall through: */
39 switch(*p){
40 case 'w':
41 factor *= 7;
42 case 'd':
43 factor *= 24;
44 case 'h':
45 factor *= 60;
46 case 'm':
47 factor *= 60;
48 case 's':
49 break;
50 default:
51 return -1;
52 }
53 return val * factor;
54 }