Use FLT_DIG and DBL_DIG from float.h to create printf-style print format

for FT_FLOAT and FT_DOUBLE values.

svn path=/trunk/; revision=7962
This commit is contained in:
Gilbert Ramirez 2003-07-04 03:41:00 +00:00
parent 8a8ea353c8
commit 803619a6dd
2 changed files with 16 additions and 6 deletions

View 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;

View 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__ */