From 58f47c66148028de2ae350a191e90e4e07180833 Mon Sep 17 00:00:00 2001 From: albert <> Date: Sun, 22 Jan 2006 07:57:13 +0000 Subject: [PATCH] terabytes --- NEWS | 1 + top.c | 23 ++++++++++++----------- top.h | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index f4c78b29..408c485a 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ procps-3.2.6 --> procps-3.2.7 top: document H option -- thanks Tony Ernst +top: terabytes -- thanks Tony Ernst procps-3.2.5 --> procps-3.2.6 diff --git a/top.c b/top.c index b0894c06..86587f19 100644 --- a/top.c +++ b/top.c @@ -745,23 +745,24 @@ static int get_int (const char *prompt) * SK_no (0) it's a byte count * SK_Kb (1) it's kilobytes * SK_Mb (2) it's megabytes - * SK_Gb (3) it's gigabytes */ -static const char *scale_num (unsigned num, const int width, const unsigned type) + * SK_Gb (3) it's gigabytes + * SK_Tb (4) it's terabytes */ +static const char *scale_num (unsigned long num, const int width, const unsigned type) { - /* kilobytes, megabytes, gigabytes, duh! */ - static float scale[] = { 1024, 1024*1024, 1024*1024*1024, 0 }; - /* kilo, mega, giga, none */ + /* kilobytes, megabytes, gigabytes, terabytes, duh! */ + static double scale[] = { 1024.0, 1024.0*1024, 1024.0*1024*1024, 1024.0*1024*1024*1024, 0 }; + /* kilo, mega, giga, tera, none */ #ifdef CASEUP_SCALE - static char nextup[] = { 'K', 'M', 'G', 0 }; + static char nextup[] = { 'K', 'M', 'G', 'T', 0 }; #else - static char nextup[] = { 'k', 'm', 'g', 0 }; + static char nextup[] = { 'k', 'm', 'g', 't', 0 }; #endif static char buf[TNYBUFSIZ]; - float *dp; + double *dp; char *up; /* try an unscaled version first... */ - if (width >= snprintf(buf, sizeof(buf), "%u", num)) return buf; + if (width >= snprintf(buf, sizeof(buf), "%lu", num)) return buf; /* now try successively higher types until it fits */ for (up = nextup + type, dp = scale; *dp; ++dp, ++up) { @@ -769,7 +770,7 @@ static const char *scale_num (unsigned num, const int width, const unsigned type if (width >= snprintf(buf, sizeof(buf), "%.1f%c", num / *dp, *up)) return buf; /* the integer version */ - if (width >= snprintf(buf, sizeof(buf), "%d%c", (int)(num / *dp), *up)) + if (width >= snprintf(buf, sizeof(buf), "%ld%c", (unsigned long)(num / *dp), *up)) return buf; } /* well shoot, this outta' fit... */ @@ -2991,7 +2992,7 @@ static proc_t **summary_show (void) } -#define PAGES_TO_KB(n) (unsigned)( (n) << page_to_kb_shift ) +#define PAGES_TO_KB(n) (unsigned long)( (n) << page_to_kb_shift ) // the following macro is our means to 'inline' emitting a column -- next to // procs_refresh, that's the most frequent and costly part of top's job ! diff --git a/top.h b/top.h index f6387c9e..5dc1bbc5 100644 --- a/top.h +++ b/top.h @@ -240,7 +240,7 @@ typedef struct RCF_t { // the complete rcfile (new style) // The scaling 'type' used with scale_num() -- this is how // the passed number is interpreted should scaling be necessary enum scale_num { - SK_no, SK_Kb, SK_Mb, SK_Gb + SK_no, SK_Kb, SK_Mb, SK_Gb, SK_Tb }; // Flags for each possible field