masqmail-0.2

diff src/timeival.c @ 0:08114f7dcc23

this is masqmail-0.2.21 from oliver kurth
author meillo@marmaro.de
date Fri, 26 Sep 2008 17:05:23 +0200
parents
children 26e34ae9a3e3
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/timeival.c	Fri Sep 26 17:05:23 2008 +0200
     1.3 @@ -0,0 +1,54 @@
     1.4 +/*  MasqMail
     1.5 +    Copyright (C) 1999-2002 Oliver Kurth
     1.6 +
     1.7 +    This program is free software; you can redistribute it and/or modify
     1.8 +    it under the terms of the GNU General Public License as published by
     1.9 +    the Free Software Foundation; either version 2 of the License, or
    1.10 +    (at your option) any later version.
    1.11 +
    1.12 +    This program is distributed in the hope that it will be useful,
    1.13 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 +    GNU General Public License for more details.
    1.16 +
    1.17 +    You should have received a copy of the GNU General Public License
    1.18 +    along with this program; if not, write to the Free Software
    1.19 +    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    1.20 +*/
    1.21 +
    1.22 +#include <ctype.h>
    1.23 +#include <glib.h>
    1.24 +
    1.25 +#include "masqmail.h"
    1.26 +
    1.27 +gint time_interval(gchar *str, gint *pos)
    1.28 +{
    1.29 +  gchar buf[16];
    1.30 +  gchar *p = str, *q = buf;
    1.31 +  gint factor = 1, val;
    1.32 +
    1.33 +  while(*p && isdigit(*p) && (q < buf+15)){
    1.34 +    *(q++) = *(p++);
    1.35 +    (*pos)++;
    1.36 +  }
    1.37 +  (*pos)++;
    1.38 +  *q = 0;
    1.39 +  val = atoi(buf);
    1.40 +  
    1.41 +  /* fall through: */
    1.42 +  switch(*p){
    1.43 +  case 'w':
    1.44 +    factor *= 7;
    1.45 +  case 'd':
    1.46 +    factor *= 24;
    1.47 +  case 'h':
    1.48 +    factor *= 60;
    1.49 +  case 'm':
    1.50 +    factor *= 60;
    1.51 +  case 's':
    1.52 +    break;
    1.53 +  default:
    1.54 +    return -1;
    1.55 +  }
    1.56 +  return val * factor;
    1.57 +}