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