Use FLT_DIG and DBL_DIG from float.h to create printf-style print format
authorgram <gram@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 4 Jul 2003 03:41:00 +0000 (03:41 +0000)
committergram <gram@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 4 Jul 2003 03:41:00 +0000 (03:41 +0000)
for FT_FLOAT and FT_DOUBLE values.

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

epan/proto.c
epan/strutil.h

index 97050528a5764d5a40b11327f2aee54d715f8b08..7bda9f5dfa61151c7e727e422819065691bb63af 100644 (file)
@@ -1,7 +1,7 @@
 /* proto.c
  * Routines for protocol tree
  *
- * $Id: proto.c,v 1.93 2003/06/12 08:33:31 guy Exp $
+ * $Id: proto.c,v 1.94 2003/07/04 03:41:00 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
+#include <float.h>
 
 #ifdef NEED_SNPRINTF_H
 # include "snprintf.h"
@@ -2506,14 +2507,16 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
 
                case FT_FLOAT:
                        ret = snprintf(label_str, ITEM_LABEL_LENGTH,
-                               "%s: %.9g", hfinfo->name, fvalue_get_floating(fi->value));
+                               "%s: %." STRINGIFY(FLT_DIG) "f",
+                               hfinfo->name, fvalue_get_floating(fi->value));
                        if ((ret == -1) || (ret >= ITEM_LABEL_LENGTH))
                                label_str[ITEM_LABEL_LENGTH - 1] = '\0';
                        break;
 
                case FT_DOUBLE:
                        ret = snprintf(label_str, ITEM_LABEL_LENGTH,
-                               "%s: %.14g", hfinfo->name, fvalue_get_floating(fi->value));
+                               "%s: %." STRINGIFY(DBL_DIG) "g",
+                               hfinfo->name, fvalue_get_floating(fi->value));
                        if ((ret == -1) || (ret >= ITEM_LABEL_LENGTH))
                                label_str[ITEM_LABEL_LENGTH - 1] = '\0';
                        break;
@@ -3614,7 +3617,8 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
                         */
                        dfilter_len = abbrev_len + 4 + 1 + 26 + 1;
                        buf = g_malloc0(dfilter_len);
-                       snprintf(buf, dfilter_len, "%s == %f", hfinfo->abbrev,
+                       snprintf(buf, dfilter_len, "%s == %." STRINGIFY(FLT_DIG) "f",
+                                       hfinfo->abbrev,
                                        fvalue_get_floating(finfo->value));
                        break;
 
@@ -3630,7 +3634,8 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
                         */
                        dfilter_len = abbrev_len + 4 + 1 + 26 + 1;
                        buf = g_malloc0(dfilter_len);
-                       snprintf(buf, dfilter_len, "%s == %f", hfinfo->abbrev,
+                       snprintf(buf, dfilter_len, "%s == %." STRINGIFY(DBL_DIG) "g",
+                                       hfinfo->abbrev,
                                        fvalue_get_floating(finfo->value));
                        break;
 
index 6c03e3281062b04c5920978814f4684812d9acc6..78aabe3dd2826bb0993227dbf4e703824741d6e6 100644 (file)
@@ -1,7 +1,7 @@
 /* strutil.h
  * String utility definitions
  *
- * $Id: strutil.h,v 1.9 2002/08/28 20:40:45 jmayer Exp $
+ * $Id: strutil.h,v 1.10 2003/07/04 03:41:00 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -34,4 +34,9 @@ int        get_token_len(const guchar *linep, const guchar *lineend,
 gchar*     format_text(const guchar *line, int len);
 gchar*     bytes_to_str(const guint8 *, int);
 gchar*     bytes_to_str_punct(const guint8 *, int, gchar punct);
+
+/* Surround a string or a macro, resolved to a string, with double quotes */
+#define _STRINGIFY(a)           # a
+#define STRINGIFY(a)            _STRINGIFY(a)
+
 #endif /* __STRUTIL_H__ */