forked from osmocom/wireshark
wsutil: Revert some changes to format_size()
Revert change to format_size() added in
f509a83381
. This commit broke formatting
with spaces and introduced some dead code.
Also replace unnecessary call to format_size_wmem() and remove
unnecessary casts (since our warning settings were fixed in the
mean time).
This commit is contained in:
parent
c4731738fc
commit
396d560744
|
@ -16,7 +16,7 @@
|
|||
#include <string.h>
|
||||
#include <epan/packet.h>
|
||||
#include <epan/timestamp.h>
|
||||
#include <epan/strutil.h>
|
||||
#include <wsutil/str_util.h>
|
||||
#include <ui/cmdarg_err.h>
|
||||
#include <ui/cli/tshark-tap.h>
|
||||
|
||||
|
@ -98,9 +98,9 @@ iousers_draw(void *arg)
|
|||
if (tot_frames == last_frames) {
|
||||
char *rx_bytes, *tx_bytes, *total_bytes;
|
||||
|
||||
rx_bytes = format_size_wmem(NULL, iui->rx_bytes, (format_size_flags_e)(format_size_unit_bytes|format_size_suffix_no_space));
|
||||
tx_bytes = format_size_wmem(NULL, iui->tx_bytes, (format_size_flags_e)(format_size_unit_bytes|format_size_suffix_no_space));
|
||||
total_bytes = format_size_wmem(NULL, iui->tx_bytes + iui->rx_bytes, (format_size_flags_e)(format_size_unit_bytes|format_size_suffix_no_space));
|
||||
rx_bytes = format_size(iui->rx_bytes, format_size_unit_bytes);
|
||||
tx_bytes = format_size(iui->tx_bytes, format_size_unit_bytes);
|
||||
total_bytes = format_size(iui->tx_bytes + iui->rx_bytes, format_size_unit_bytes);
|
||||
|
||||
/* XXX - TODO: make name / port resolution configurable (through gbl_resolv_flags?) */
|
||||
src_addr = get_conversation_address(NULL, &iui->src_address, TRUE);
|
||||
|
|
|
@ -118,9 +118,8 @@ isdigit_string(const guchar *str)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
#define FORMAT_SIZE_UNIT_MASK 0x0000ff
|
||||
#define FORMAT_SIZE_PFX_MASK 0x00ff00
|
||||
#define FORMAT_SIZE_SFX_MASK 0xff0000
|
||||
#define FORMAT_SIZE_UNIT_MASK 0x00ff
|
||||
#define FORMAT_SIZE_PFX_MASK 0xff00
|
||||
|
||||
static const char *thousands_grouping_fmt = NULL;
|
||||
|
||||
|
@ -147,8 +146,7 @@ format_size(gint64 size, format_size_flags_e flags)
|
|||
int power = 1000;
|
||||
int pfx_off = 0;
|
||||
gboolean is_small = FALSE;
|
||||
gboolean separate = ((flags & format_size_suffix_no_space) != format_size_suffix_no_space);
|
||||
static const gchar *prefix[] = {"T", "G", "M", "k", "Ti", "Gi", "Mi", "Ki"};
|
||||
static const gchar *prefix[] = {" T", " G", " M", " k", " Ti", " Gi", " Mi", " Ki"};
|
||||
gchar *ret_val;
|
||||
|
||||
if (thousands_grouping_fmt == NULL)
|
||||
|
@ -159,51 +157,43 @@ format_size(gint64 size, format_size_flags_e flags)
|
|||
power = 1024;
|
||||
}
|
||||
|
||||
if ((size / power >= 10) && separate) {
|
||||
g_string_append_c(human_str, ' ');
|
||||
}
|
||||
|
||||
if (size / power / power / power / power >= 10) {
|
||||
g_string_printf(human_str, thousands_grouping_fmt, size / power / power / power / power);
|
||||
g_string_append_printf(human_str, "%s", prefix[pfx_off]);
|
||||
g_string_append(human_str, prefix[pfx_off]);
|
||||
} else if (size / power / power / power >= 10) {
|
||||
g_string_printf(human_str, thousands_grouping_fmt, size / power / power / power);
|
||||
g_string_append_printf(human_str, "%s", prefix[pfx_off+1]);
|
||||
g_string_append(human_str, prefix[pfx_off+1]);
|
||||
} else if (size / power / power >= 10) {
|
||||
g_string_printf(human_str, thousands_grouping_fmt, size / power / power);
|
||||
g_string_append_printf(human_str, "%s", prefix[pfx_off+2]);
|
||||
g_string_append(human_str, prefix[pfx_off+2]);
|
||||
} else if (size / power >= 10) {
|
||||
g_string_printf(human_str, thousands_grouping_fmt, size / power);
|
||||
g_string_append_printf(human_str, "%s", prefix[pfx_off+3]);
|
||||
g_string_append(human_str, prefix[pfx_off+3]);
|
||||
} else {
|
||||
g_string_printf(human_str, thousands_grouping_fmt, size);
|
||||
is_small = TRUE;
|
||||
}
|
||||
|
||||
if ((flags & FORMAT_SIZE_UNIT_MASK) != format_size_unit_none && is_small && separate) {
|
||||
g_string_append_c(human_str, ' ');
|
||||
}
|
||||
|
||||
switch (flags & FORMAT_SIZE_UNIT_MASK) {
|
||||
case format_size_unit_none:
|
||||
break;
|
||||
case format_size_unit_bytes:
|
||||
g_string_append(human_str, is_small ? "bytes" : "B");
|
||||
g_string_append(human_str, is_small ? " bytes" : "B");
|
||||
break;
|
||||
case format_size_unit_bits:
|
||||
g_string_append(human_str, is_small ? "bits" : "b");
|
||||
g_string_append(human_str, is_small ? " bits" : "b");
|
||||
break;
|
||||
case format_size_unit_bits_s:
|
||||
g_string_append(human_str, is_small ? "bits/s" : "bps");
|
||||
g_string_append(human_str, is_small ? " bits/s" : "bps");
|
||||
break;
|
||||
case format_size_unit_bytes_s:
|
||||
g_string_append(human_str, is_small ? "bytes/s" : "Bps");
|
||||
g_string_append(human_str, is_small ? " bytes/s" : "Bps");
|
||||
break;
|
||||
case format_size_unit_packets:
|
||||
g_string_append(human_str, "packets");
|
||||
g_string_append(human_str, is_small ? " packets" : "packets");
|
||||
break;
|
||||
case format_size_unit_packets_s:
|
||||
g_string_append(human_str, "packets/s");
|
||||
g_string_append(human_str, is_small ? " packets/s" : "packets/s");
|
||||
break;
|
||||
default:
|
||||
ws_assert_not_reached();
|
||||
|
|
|
@ -91,8 +91,7 @@ typedef enum {
|
|||
format_size_unit_packets = 5, /**< "packets" */
|
||||
format_size_unit_packets_s = 6, /**< "packets/s" */
|
||||
format_size_prefix_si = 0 << 8, /**< SI (power of 1000) prefixes will be used. */
|
||||
format_size_prefix_iec = 1 << 8, /**< IEC (power of 1024) prefixes will be used. */
|
||||
format_size_suffix_no_space = 1 << 16 /**< Omit space between value and unit. */
|
||||
format_size_prefix_iec = 1 << 8 /**< IEC (power of 1024) prefixes will be used. */
|
||||
/* XXX format_size_prefix_default_for_this_particular_os ? */
|
||||
} format_size_flags_e;
|
||||
|
||||
|
@ -102,7 +101,7 @@ typedef enum {
|
|||
*
|
||||
* @param size The size value
|
||||
* @param flags Flags to control the output (unit of measurement,
|
||||
* SI vs IEC, etc). Unit, prefix and suffix flags may be ORed together.
|
||||
* SI vs IEC, etc). Unit and prefix flags may be ORed together.
|
||||
* @return A newly-allocated string representing the value.
|
||||
*/
|
||||
WS_DLL_PUBLIC
|
||||
|
|
Loading…
Reference in New Issue