1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
25 * AT&T Bell Laboratories
27 * parse elapsed time in 1/n secs from s
28 * compatible with fmtelapsed()
29 * also handles ps [day-][hour:]min:sec
30 * also handles coshell % for 'infinity'
31 * if e!=0 then it is set to first unrecognized char
38 strelapsed(register const char* s
, char** e
, int n
)
41 register unsigned long v
;
51 while (isspace(*s
) || *s
== '_')
58 if (*s
== '0' && (!(c
= *(s
+ 1)) || isspace(c
) || c
== '_'))
65 while ((c
= *s
++) >= '0' && c
<= '9')
69 for (m
= n
; (c
= *s
++) >= '0' && c
<= '9';)
70 f
+= (m
/= 10) * (c
- '0');
80 while (isspace(c
) || c
== '_')
85 if (*s
== 'E' || *s
== 'e')
91 v
*= 20 * 12 * 4 * 7 * 24 * 60 * 60;
95 v
*= 12 * 4 * 7 * 24 * 60 * 60;
98 if (*s
== 'I' || *s
== 'i')
101 v
*= 4 * 7 * 24 * 60 * 60;
104 v
*= 7 * 24 * 60 * 60;
117 v
*= strchr(s
, ':') ? (60 * 60) : 60;
121 v
*= 4 * 7 * 24 * 60 * 60;
128 v
*= 20 * 12 * 4 * 7 * 24 * 60 * 60;