Module Name: src
Committed By: is
Date: Wed Jun 30 11:08:12 UTC 2010
Modified Files:
src/external/bsd/top/dist: display.c
Log Message:
Avoid steps and other artefacts in head for more than 9 CPUs.
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/external/bsd/top/dist/display.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/bsd/top/dist/display.c
diff -u src/external/bsd/top/dist/display.c:1.7 src/external/bsd/top/dist/display.c:1.8
--- src/external/bsd/top/dist/display.c:1.7 Tue May 5 18:52:13 2009
+++ src/external/bsd/top/dist/display.c Wed Jun 30 11:08:12 2010
@@ -854,7 +854,8 @@
*ip++ = cpustate_total_length;
if ((i = strlen(*pp++)) > 0)
{
- cpustate_total_length += i + 8;
+ cpustate_total_length += i + 7;
+ /* strlen(" 100% ") is 6, strlen(" 99.9% ") is 7. Never 8. */
}
}
}
@@ -1150,26 +1151,25 @@
cpustates_tag(int c)
{
- register const char *use;
+ unsigned width, u;
static char fmttag[100];
- const char *short_tag = ncpu > 1 && multi ? "CPU%d: " : "CPU: ";
- const char *long_tag = ncpu > 1 && multi ? "CPU%d states: " : "CPU states: ";
+ const char *short_tag = !multi || ncpu <= 1 ? "CPU: " : "CPU%0*d";
+ const char *long_tag = !multi || ncpu <= 1 ?
+ "CPU states: " : "CPU%0*d states: ";
- /* if length + strlen(long_tag) >= screen_width, then we have to
- use the shorter tag (we subtract 2 to account for ": ") */
- if (cpustate_total_length + (int)strlen(long_tag) - 2 - ((ncpu > 1) ? 1 : 0)
- >= screen_width)
- {
- use = short_tag;
- }
- else
- {
- use = long_tag;
+ for (width=0, u=ncpu; u>0; u /= 10) {
+ ++width;
}
+ /* if length + strlen(long_tag) > screen_width, then we have to
+ use the shorter tag */
+
+ snprintf(fmttag, sizeof(fmttag), long_tag, width, c);
- snprintf(fmttag, sizeof(fmttag), use, c);
+ if (cpustate_total_length + (signed)strlen(fmttag) > screen_width) {
+ snprintf(fmttag, sizeof(fmttag), short_tag, width, c);
+ }
/* set x_cpustates accordingly then return result */
x_cpustates = strlen(fmttag);