Hi,
here is another small patch for GTKG:
- modified/added 64-bit functions for converting bytes/KB to a
readable string
- improved output of the HORIZON command in GTKG's remote shell
BTW: Several days ago I sent a patch for sorting by count and filesize
instead of just count in the search results panel, but it doesn't seem
to have been committed yet.
Greetings,
Thomas.
Index: misc.c
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/misc.c,v
retrieving revision 1.111
diff -u -r1.111 misc.c
--- misc.c 20 Apr 2004 21:23:43 -0000 1.111
+++ misc.c 27 May 2004 12:58:51 -0000
@@ -393,9 +393,15 @@
gm_snprintf(b, sizeof(b), "%.1f MB", (float) size / 1048576.0);
else if ((size >> 10) < 1073741824)
gm_snprintf(b, sizeof(b), "%.1f GB", (float) size / 1073741824.0);
- else
+ else if ((size >> 20) < 1073741824)
gm_snprintf(b, sizeof(b), "%.1f TB",
(float) (size >> 10) / 1073741824.0);
+ else if ((size >> 30) < 1073741824)
+ gm_snprintf(b, sizeof(b), "%.1f PB",
+ (float) (size >> 20) / 1073741824.0);
+ else
+ gm_snprintf(b, sizeof(b), "%.1f EB",
+ (float) (size >> 30) / 1073741824.0);
return b;
}
@@ -418,6 +424,31 @@
return b;
}
+gchar *short_kb_size64(guint64 size)
+{
+ static gchar b[SIZE_FIELD_MAX];
+
+ if (size < 1024)
+ gm_snprintf(b, sizeof(b), "%u KB", (guint32) size);
+ else if (size < 1048576)
+ gm_snprintf(b, sizeof(b), "%.1f MB", (float) size / 1024.0);
+ else if (size < 1073741824)
+ gm_snprintf(b, sizeof(b), "%.1f GB", (float) size / 1048576.0);
+ else if ((size >> 10) < 1073741824)
+ gm_snprintf(b, sizeof(b), "%.1f TB", (float) size / 1073741824.0);
+ else if ((size >> 20) < 1073741824)
+ gm_snprintf(b, sizeof(b), "%.1f PB",
+ (float) (size >> 10) / 1073741824.0);
+ else if ((size >> 30) < 1073741824)
+ gm_snprintf(b, sizeof(b), "%.1f EB",
+ (float) (size >> 20) / 1073741824.0);
+ else
+ gm_snprintf(b, sizeof(b), "%.1f ZB",
+ (float) (size >> 30) / 1073741824.0);
+
+ return b;
+}
+
/* Returns a number of bytes in a compact readable form */
gchar *compact_size(guint32 size)
Index: misc.h
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/misc.h,v
retrieving revision 1.81
diff -u -r1.81 misc.h
--- misc.h 25 May 2004 02:30:19 -0000 1.81
+++ misc.h 27 May 2004 12:58:51 -0000
@@ -148,6 +148,7 @@
gchar *short_size(guint32);
gchar *short_size64(guint64 size);
gchar *short_kb_size(guint32);
+gchar *short_kb_size64(guint64 size);
gchar *compact_size(guint32 size);
gchar *compact_size64(guint64 size);
gchar *compact_kb_size(guint32 size);
Index: shell.c
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/shell.c,v
retrieving revision 1.28
diff -u -r1.28 shell.c
--- shell.c 2 Mar 2004 17:19:02 -0000 1.28
+++ shell.c 27 May 2004 12:58:53 -0000
@@ -592,6 +592,9 @@
for (sl = (GSList *) node_all_nodes() ; sl; sl = g_slist_next(sl)) {
struct gnutella_node *n = (struct gnutella_node *) sl->data;
+ if (!NODE_IS_ESTABLISHED(n))
+ continue;
+
nodes++;
if (!(n->attrs & NODE_A_CAN_HSEP))
@@ -620,18 +623,23 @@
maxlen[0] = 5; /* length of Nodes */
maxlen[1] = 5; /* length of Files */
- maxlen[2] = 3; /* length of KiB */
+ maxlen[2] = 4; /* length of Size */
for (i=0; i < HSEP_N_MAX * 3; i++)
{
- int n = gm_snprintf(buf, sizeof(buf) - 1, "%llu", *globalt++);
+ int n;
+
+ if ((i % 3) == 2)
+ n = strlen(short_kb_size64(*globalt++));
+ else
+ n = gm_snprintf(buf, sizeof(buf) - 1, "%llu", *globalt++);
if(n > maxlen[i % 3])
maxlen[i % 3] = n;
}
gm_snprintf(buf, sizeof(buf) - 1, "Hops %*s %*s %*s\n----------",
- maxlen[0], "Nodes", maxlen[1], "Files", maxlen[2], "KiB");
+ maxlen[0], "Nodes", maxlen[1], "Files", maxlen[2], "Size");
shell_write(sh, buf);
@@ -644,10 +652,10 @@
for (i = 0; i < HSEP_N_MAX; i++)
{
- gm_snprintf(buf, sizeof(buf) - 1, "%4d %*llu %*llu %*llu\n", i+1,
+ gm_snprintf(buf, sizeof(buf) - 1, "%4d %*llu %*llu %*s\n", i+1,
maxlen[0], globalt[HSEP_IDX_NODES],
maxlen[1], globalt[HSEP_IDX_FILES],
- maxlen[2], globalt[HSEP_IDX_KIB]);
+ maxlen[2], short_kb_size64(globalt[HSEP_IDX_KIB]));
shell_write(sh, buf);
globalt += 3;