small refactoring of lcdproc client: get rid of global variables tmp & buffer

This commit is contained in:
marschap committed 2006-10-15 20:48:13 +00:00
1 parent 7811b491db
commit 8fb54a71ff
20 files changed
+240 -339

No files matched your search

+31 -54
View File
@@ -40,13 +40,13 @@ cpu_screen(int rep, int display, int *flags_ptr)
int i, j, n;
double value;
load_type load;
char tmp[25]; // should be large enough
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
sock_send_string(sock, "screen_add C\n");
sprintf(buffer, "screen_set C -name {CPU Use: %s}\n", get_hostname());
sock_send_string(sock, buffer);
sock_printf(sock, "screen_set C -name {CPU Use: %s}\n", get_hostname());
if (lcd_hgt >= 4) {
gauge_wid = lcd_wid - 6; // room between 0%...100%
@@ -55,14 +55,11 @@ cpu_screen(int rep, int display, int *flags_ptr)
sock_send_string(sock, "widget_add C one string\n");
sock_send_string(sock, "widget_add C two string\n");
sock_send_string(sock, "widget_add C three string\n");
sprintf(buffer, "widget_set C one 1 2 {%-*s%-*s}\n",
lcd_wid / 2, "Usr", lcd_wid / 2, "Nice");
sock_send_string(sock, buffer);
sprintf(buffer, "widget_set C two 1 3 {%-*s%-*s}\n",
lcd_wid / 2, "Sys", lcd_wid / 2, "Idle");
sock_send_string(sock, buffer);
sprintf(buffer, "widget_set C three 1 4 {0%%%*s100%%}\n", gauge_wid, "");
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C one 1 2 {%-*s%-*s}\n",
lcd_wid / 2, "Usr", lcd_wid / 2, "Nice");
sock_printf(sock, "widget_set C two 1 3 {%-*s%-*s}\n",
lcd_wid / 2, "Sys", lcd_wid / 2, "Idle");
sock_printf(sock, "widget_set C three 1 4 {0%%%*s100%%}\n", gauge_wid, "");
sock_send_string(sock, "widget_add C usr string\n");
sock_send_string(sock, "widget_add C nice string\n");
sock_send_string(sock, "widget_add C idle string\n");
@@ -75,15 +72,12 @@ cpu_screen(int rep, int display, int *flags_ptr)
gauge_wid = lcd_wid - 12; // room between [...]
sock_send_string(sock, "widget_add C cpu string\n");
sprintf(buffer, "widget_set C cpu 1 1 {CPU [%*s]}\n", gauge_wid, "");
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C cpu 1 1 {CPU [%*s]}\n", gauge_wid, "");
sock_send_string(sock, "widget_add C cpu% string\n");
sprintf(buffer, "widget_set C cpu%% 1 %d { 0.0%%}\n", lcd_wid - 5);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C cpu%% 1 %d { 0.0%%}\n", lcd_wid - 5);
sock_send_string(sock, "widget_add C usni string\n");
sprintf(buffer, "widget_set C usni 1 2 {U%*sS%*sN%*sI%*s}\n",
usni_wid, "", usni_wid, "", usni_wid, "", usni_wid, "");
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C usni 1 2 {U%*sS%*sN%*sI%*s}\n",
usni_wid, "", usni_wid, "", usni_wid, "", usni_wid, "");
sock_send_string(sock, "widget_add C usr hbar\n");
sock_send_string(sock, "widget_add C sys hbar\n");
sock_send_string(sock, "widget_add C nice hbar\n");
@@ -142,53 +136,41 @@ cpu_screen(int rep, int display, int *flags_ptr)
if (lcd_hgt >= 4) { // 4-line display
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][4]);
sprintf(buffer, "widget_set C title {CPU %5s: %s}\n", tmp, get_hostname());
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C title {CPU %5s: %s}\n", tmp, get_hostname());
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][0]);
sprintf(buffer, "widget_set C usr %i 2 {%5s}\n", (lcd_wid / 2) - 5, tmp);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C usr %i 2 {%5s}\n", (lcd_wid / 2) - 5, tmp);
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][1]);
sprintf(buffer, "widget_set C sys %i 3 {%5s}\n", (lcd_wid / 2) - 5, tmp);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C sys %i 3 {%5s}\n", (lcd_wid / 2) - 5, tmp);
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][2]);
sprintf(buffer, "widget_set C nice %i 2 {%5s}\n", lcd_wid - 4, tmp);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C nice %i 2 {%5s}\n", lcd_wid - 4, tmp);
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][3]);
sprintf(buffer, "widget_set C idle %i 3 {%5s}\n", lcd_wid - 4, tmp);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C idle %i 3 {%5s}\n", lcd_wid - 4, tmp);
n = (int) ((cpu[CPU_BUF_SIZE][4] * lcd_cellwid * gauge_wid) / 100.0);
sprintf(buffer, "widget_set C bar 3 4 %d\n", n);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C bar 3 4 %d\n", n);
}
else { // 2-line display
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][4]);
sprintf(buffer, "widget_set C cpu%% %d 1 {%5s}\n", lcd_wid - 5, tmp);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C cpu%% %d 1 {%5s}\n", lcd_wid - 5, tmp);
n = (int) ((cpu[CPU_BUF_SIZE][4] * lcd_cellwid * gauge_wid) / 100.0);
sprintf(buffer, "widget_set C total 6 1 %d\n", n);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C total 6 1 %d\n", n);
n = (int) ((cpu[CPU_BUF_SIZE][0] * lcd_cellwid * usni_wid) / 100.0);
sprintf(buffer, "widget_set C usr %d 2 %d\n", 0 * (usni_wid + 1) + 2, n);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C usr %d 2 %d\n", 0 * (usni_wid + 1) + 2, n);
n = (int) ((cpu[CPU_BUF_SIZE][1] * lcd_cellwid * usni_wid) / 100.0);
sprintf(buffer, "widget_set C sys %d 2 %d\n", 1 * (usni_wid + 1) + 2, n);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C sys %d 2 %d\n", 1 * (usni_wid + 1) + 2, n);
n = (int) ((cpu[CPU_BUF_SIZE][2] * lcd_cellwid * usni_wid) / 100.0);
sprintf(buffer, "widget_set C nice %d 2 %d\n", 2 * (usni_wid + 1) + 2, n);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C nice %d 2 %d\n", 2 * (usni_wid + 1) + 2, n);
n = (int) ((cpu[CPU_BUF_SIZE][3] * lcd_cellwid * usni_wid) / 100.0);
sprintf(buffer, "widget_set C idle %d 2 %d\n", 3 * (usni_wid + 1) + 2, n);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set C idle %d 2 %d\n", 3 * (usni_wid + 1) + 2, n);
}
return(0);
@@ -225,23 +207,20 @@ cpu_graph_screen(int rep, int display, int *flags_ptr)
gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt;
sock_send_string(sock, "screen_add G\n");
sprintf(buffer, "screen_set G -name {CPU Graph: %s}\n", get_hostname());
sock_send_string(sock, buffer);
sock_printf(sock, "screen_set G -name {CPU Graph: %s}\n", get_hostname());
if (lcd_hgt >= 4) {
sock_send_string(sock, "widget_add G title title\n");
sprintf(buffer, "widget_set G title {CPU: %s}\n", get_hostname());
sock_printf(sock, "widget_set G title {CPU: %s}\n", get_hostname());
}
else {
sock_send_string(sock, "widget_add G title string\n");
sprintf(buffer, "widget_set G title 1 1 {CPU: %s}\n", get_hostname());
sock_printf(sock, "widget_set G title 1 1 {CPU: %s}\n", get_hostname());
}
sock_send_string(sock, buffer);
for (i = 1; i <= lcd_wid; i++) {
sprintf(buffer, "widget_add G bar%d vbar\n", i);
sock_send_string(sock, buffer);
sprintf(buffer, "widget_set G bar%d %d %d 0\n", i, i, lcd_hgt);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_add G bar%d vbar\n", i);
sock_printf(sock, "widget_set G bar%d %d %d 0\n", i, i, lcd_hgt);
cpu_past[i-1] = 0;
};
@@ -274,17 +253,15 @@ cpu_graph_screen(int rep, int display, int *flags_ptr)
cpu_past[i] = cpu_past[i + 1];
if (display) {
sprintf(buffer, "widget_set G bar%d %d %d %d\n",
sock_printf(sock, "widget_set G bar%d %d %d %d\n",
i + 1, i + 1, lcd_hgt, cpu_past[i]);
sock_send_string(sock, buffer);
}
}
// Save the newest entry and display it
cpu_past[lcd_wid - 1] = n;
if (display) {
sprintf(buffer, "widget_set G bar%d %d %d %d\n", lcd_wid, lcd_wid, lcd_hgt, n);
sock_send_string(sock, buffer);
sock_printf(sock, "widget_set G bar%d %d %d %d\n", lcd_wid, lcd_wid, lcd_hgt, n);
}
return(0);