From Nathan Hartwell via bug 2733:
authorstig <stig@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 25 Jun 2009 02:07:17 +0000 (02:07 +0000)
committerstig <stig@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 25 Jun 2009 02:07:17 +0000 (02:07 +0000)
Added time_secs_to_str_unsigned().

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@28840 f5534014-38df-0310-8fa8-9805f1628bb7

epan/to_str.c
epan/to_str.h

index 37b6f3c49b8da403a8fb1bfe0819e8e8252a742c..5350a46cd738b209ced6d41549943a6eb537283b 100644 (file)
@@ -426,6 +426,61 @@ time_secs_to_str(gint32 time)
   return buf->str;
 }
 
+static void
+time_secs_to_str_buf_unsigned(guint32 time, guint32 frac, gboolean is_nsecs,
+                        emem_strbuf_t *buf)
+{
+  int hours, mins, secs;
+  const gchar *msign = "";
+  gboolean do_comma = FALSE;
+
+  secs = time % 60;
+  time /= 60;
+  mins = time % 60;
+  time /= 60;
+  hours = time % 24;
+  time /= 24;
+
+  if (time != 0) {
+    ep_strbuf_append_printf(buf, "%s%u day%s", msign, time, PLURALIZE(time));
+    do_comma = TRUE;
+  }
+  if (hours != 0) {
+    ep_strbuf_append_printf(buf, "%s%s%u hour%s", COMMA(do_comma), msign, hours, PLURALIZE(hours));
+    do_comma = TRUE;
+  }
+  if (mins != 0) {
+    ep_strbuf_append_printf(buf, "%s%s%u minute%s", COMMA(do_comma), msign, mins, PLURALIZE(mins));
+    do_comma = TRUE;
+  }
+  if (secs != 0 || frac != 0) {
+    if (frac != 0) {
+      if (is_nsecs)
+        ep_strbuf_append_printf(buf, "%s%s%u.%09u seconds", COMMA(do_comma), msign, secs, frac);
+      else
+        ep_strbuf_append_printf(buf, "%s%s%u.%03u seconds", COMMA(do_comma), msign, secs, frac);
+    } else
+      ep_strbuf_append_printf(buf, "%s%s%u second%s", COMMA(do_comma), msign, secs, PLURALIZE(secs));
+  }
+}
+
+gchar *
+time_secs_to_str_unsigned(guint32 time)
+{
+  emem_strbuf_t *buf;
+
+  buf=ep_strbuf_sized_new(TIME_SECS_LEN+1, TIME_SECS_LEN+1);
+
+  if (time == 0) {
+    ep_strbuf_append(buf, "0 time");
+    return buf->str;
+  }
+
+  time_secs_to_str_buf_unsigned(time, 0, FALSE, buf);
+  return buf->str;
+}
+
+
 gchar *
 time_msecs_to_str(gint32 time)
 {
index 6bf5a6cfc1da5c8a4703861389c4644678942e76..f2727ad7712a9f2afc7a5d2768164afb6421985f 100644 (file)
@@ -69,6 +69,7 @@ extern gchar* ipxnet_to_str_punct(const guint32 ad, char punct);
 extern gchar*  vines_addr_to_str(const guint8 *addrp);
 extern void    vines_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len);
 extern gchar*  time_secs_to_str(gint32);
+extern gchar*  time_secs_to_str_unsigned(guint32);
 extern gchar*  time_msecs_to_str(gint32);
 extern gchar*  abs_time_to_str(nstime_t*);
 extern gchar*  abs_time_secs_to_str(time_t);