masqmail

annotate src/timeival.c @ 366:41958685480d

Switched to `type *name' style Andrew Koenig's ``C Traps and Pitfalls'' (Ch.2.1) convinced me that it is best to go with the way C had been designed. The ``declaration reflects use'' concept conflicts with a ``type* name'' notation. Hence I switched.
author markus schnalke <meillo@marmaro.de>
date Thu, 22 Sep 2011 15:07:40 +0200
parents 2e7d3a02edb1
children b27f66555ba8
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@366 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 }