diff options
author | Guy Harris <guy@alum.mit.edu> | 2001-07-13 00:27:51 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2001-07-13 00:27:51 +0000 |
commit | 82a553e9c9275c9074b087b63e976ef63259dba9 (patch) | |
tree | 0e927a409742b23966e99c28e279e65874270290 /epan | |
parent | 01710d371c7c599952ea49eae49451e68b837e32 (diff) | |
download | wireshark-82a553e9c9275c9074b087b63e976ef63259dba9.tar.gz wireshark-82a553e9c9275c9074b087b63e976ef63259dba9.tar.bz2 wireshark-82a553e9c9275c9074b087b63e976ef63259dba9.zip |
Add a "time_msecs_to_str()" routine, to turn a time interval, expressed
as a 32-bit number of milliseconds, to a descriptive string.
Use that in the MS Browser dissector.
svn path=/trunk/; revision=3708
Diffstat (limited to 'epan')
-rw-r--r-- | epan/to_str.c | 62 | ||||
-rw-r--r-- | epan/to_str.h | 3 |
2 files changed, 63 insertions, 2 deletions
diff --git a/epan/to_str.c b/epan/to_str.c index b40628bff8..bbf8e97ed0 100644 --- a/epan/to_str.c +++ b/epan/to_str.c @@ -1,7 +1,7 @@ /* to_str.h * Routines for utilities to convert various other types to strings. * - * $Id: to_str.c,v 1.8 2001/05/31 06:47:59 guy Exp $ + * $Id: to_str.c,v 1.9 2001/07/13 00:27:51 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -320,6 +320,66 @@ time_secs_to_str(guint32 time) return cur; } +gchar * +time_msecs_to_str(guint32 time) +{ + static gchar str[3][8+1+4+2+2+5+2+2+7+2+2+11+1]; + static gchar *cur, *p; + int hours, mins, secs; + int msecs; + int do_comma; + + if (cur == &str[0][0]) { + cur = &str[1][0]; + } else if (cur == &str[1][0]) { + cur = &str[2][0]; + } else { + cur = &str[0][0]; + } + + if (time == 0) { + sprintf(cur, "0 time"); + return cur; + } + + msecs = time % 1000; + time /= 1000; + + secs = time % 60; + time /= 60; + mins = time % 60; + time /= 60; + hours = time % 24; + time /= 24; + + p = cur; + if (time != 0) { + sprintf(p, "%u day%s", time, PLURALIZE(time)); + p += strlen(p); + do_comma = 1; + } else + do_comma = 0; + if (hours != 0) { + sprintf(p, "%s%u hour%s", COMMA(do_comma), hours, PLURALIZE(hours)); + p += strlen(p); + do_comma = 1; + } else + do_comma = 0; + if (mins != 0) { + sprintf(p, "%s%u minute%s", COMMA(do_comma), mins, PLURALIZE(mins)); + p += strlen(p); + do_comma = 1; + } else + do_comma = 0; + if (secs != 0) { + if (msecs != 0) + sprintf(p, "%s%u.%03u seconds", COMMA(do_comma), secs, msecs); + else + sprintf(p, "%s%u second%s", COMMA(do_comma), secs, PLURALIZE(secs)); + } + return cur; +} + static const char *mon_names[12] = { "Jan", "Feb", diff --git a/epan/to_str.h b/epan/to_str.h index 077635438a..c657d523d3 100644 --- a/epan/to_str.h +++ b/epan/to_str.h @@ -1,7 +1,7 @@ /* to_str.h * Definitions for utilities to convert various other types to strings. * - * $Id: to_str.h,v 1.2 2001/04/01 06:32:10 hagbard Exp $ + * $Id: to_str.h,v 1.3 2001/07/13 00:27:51 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -52,6 +52,7 @@ gchar* ipxnet_to_string(const guint8 *ad); gchar* ipxnet_to_str_punct(const guint32 ad, char punct); gchar* vines_addr_to_str(const guint8 *addrp); gchar* time_secs_to_str(guint32); +gchar* time_msecs_to_str(guint32); gchar* abs_time_to_str(struct timeval*); void display_signed_time(gchar *, int, gint32, gint32); gchar* rel_time_to_str(struct timeval*); |