/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223#include <tmx.h>24#include <ctype.h>2526/*27* parse duration expression in s and return Time_t value28* if non-null, e points to the first unused char in s29* returns 0 with *e==s on error30*/3132Time_t33tmxduration(const char* s, char** e)34{35Time_t ns;36Time_t ts;37Time_t now;38char* last;39char* t;40char* x;41Sfio_t* f;42int i;4344now = TMX_NOW;45while (isspace(*s))46s++;47if (*s == 'P' || *s == 'p')48ns = tmxdate(s, &last, now) - now;49else50{51ns = strtod(s, &last) * TMX_RESOLUTION;52if (*last && (f = sfstropen()))53{54sfprintf(f, "exact %s", s);55t = sfstruse(f);56ts = tmxdate(t, &x, now);57if ((i = x - t - 6) > (last - s))58{59last = (char*)s + i;60ns = ts - now;61}62else63{64sfprintf(f, "p%s", s);65t = sfstruse(f);66ts = tmxdate(t, &x, now);67if ((i = x - t - 1) > (last - s))68{69last = (char*)s + i;70ns = ts - now;71}72}73sfstrclose(f);74}75}76if (e)77*e = last;78return ns;79}808182