diff --git a/clients/lcdproc/batt.c b/clients/lcdproc/batt.c index 953bcfe..83dea90 100644 --- a/clients/lcdproc/batt.c +++ b/clients/lcdproc/batt.c @@ -139,14 +139,14 @@ battery_screen(int rep, int display, int *flags_ptr) (acstat == LCDP_AC_ON && battstat == LCDP_BATT_ABSENT) ? "AC" : "Batt", tmp, get_hostname()); - if (lcd_hgt >= 4) { // 4-line version of the screen + if (lcd_hgt >= 4) { /* 4-line version of the screen */ sock_printf(sock, "widget_set B one 1 2 {AC: %s}\n", ac_status(acstat)); sock_printf(sock, "widget_set B two 1 3 {Batt: %s}\n", battery_status(battstat)); if (percent > 0) sock_printf(sock, "widget_set B gauge 2 4 %d\n", (percent * gauge_wid * lcd_cellwid) / 100); } - else { // two-line version of the screen + else { /* two-line version of the screen */ sock_printf(sock, "widget_set B one 1 2 {%sBatt: %s}\n", (acstat == LCDP_AC_ON) ? "AC, " : "", battery_status(battstat)); diff --git a/clients/lcdproc/chrono.c b/clients/lcdproc/chrono.c index 6402adc..679eb32 100644 --- a/clients/lcdproc/chrono.c +++ b/clients/lcdproc/chrono.c @@ -97,16 +97,17 @@ time_screen(int rep, int display, int *flags_ptr) sock_send_string(sock, "widget_add T two string\n"); sock_send_string(sock, "widget_add T three string\n"); - // write title bar: OS name, OS version, hostname + /* write title bar: OS name, OS version, hostname */ sock_printf(sock, "widget_set T title {%s %s: %s}\n", get_sysname(), get_sysrelease(), get_hostname()); - } else { - // write title bar: hostname + } + else { + /* write title bar: hostname */ sock_printf(sock, "widget_set T title {TIME: %s}\n", get_hostname()); } } - // toggle colon display + /* toggle colon display */ heartbeat ^= 1; time(&thetime); @@ -119,11 +120,11 @@ time_screen(int rep, int display, int *flags_ptr) tickTime(now, heartbeat); if (lcd_hgt >= 4) { - char tmp[40]; // should be large enough + char tmp[40]; /* should be large enough */ machine_get_uptime(&uptime, &idle); - // display the uptime... + /* display the uptime... */ days = (int) uptime / 86400; hour = ((int) uptime % 86400) / 3600; min = ((int) uptime % 3600) / 60; @@ -139,18 +140,18 @@ time_screen(int rep, int display, int *flags_ptr) if (display) sock_printf(sock, "widget_set T one %i 2 {%s}\n", xoffs, tmp); - // display the date + /* display the date */ xoffs = (lcd_wid > strlen(today)) ? ((lcd_wid - strlen(today)) / 2) + 1 : 1; if (display) sock_printf(sock, "widget_set T two %i 3 {%s}\n", xoffs, today); - // display the time & idle time... + /* display the time & idle time... */ sprintf(tmp, "%s %3i%% idle", now, (int) idle); xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1; if (display) sock_printf(sock, "widget_set T three %i 4 {%s}\n", xoffs, tmp); } - else { // 2 line version of the screen + else { /* 2 line version of the screen */ xoffs = (lcd_wid > (strlen(today) + strlen(now) + 1)) ? ((lcd_wid - ((strlen(today) + strlen(now) + 1))) / 2) + 1 : 1; if (display) @@ -158,7 +159,7 @@ time_screen(int rep, int display, int *flags_ptr) } return 0; -} // End time_screen() +} /* End time_screen() */ /** @@ -193,7 +194,7 @@ clock_screen(int rep, int display, int *flags_ptr) struct tm *rtime; if ((*flags_ptr & INITIALIZED) == 0) { - char tmp[257]; // should be large enough for host name + char tmp[257]; /* should be large enough for host name */ *flags_ptr |= INITIALIZED; @@ -214,12 +215,13 @@ clock_screen(int rep, int display, int *flags_ptr) sprintf(tmp, "%s", get_hostname()); xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1; sock_printf(sock, "widget_set O one %i 2 {%s}\n", xoffs, tmp); - } else { + } + else { sock_printf(sock, "widget_set O title {TIME: %s}\n", get_hostname()); } } - // toggle colon display + /* toggle colon display */ heartbeat ^= 1; time(&thetime); @@ -231,7 +233,7 @@ clock_screen(int rep, int display, int *flags_ptr) *now = '\0'; tickTime(now, heartbeat); - if (lcd_hgt >= 4) { // 4-line version of the screen + if (lcd_hgt >= 4) { /* 4-line version of the screen */ xoffs = (lcd_wid > strlen(today)) ? ((lcd_wid - strlen(today)) / 2) + 1 : 1; if (display) sock_printf(sock, "widget_set O two %i 3 {%s}\n", xoffs, today); @@ -240,7 +242,7 @@ clock_screen(int rep, int display, int *flags_ptr) if (display) sock_printf(sock, "widget_set O three %i 4 {%s}\n", xoffs, now); } - else { // 2-line version of the screen + else { /* 2-line version of the screen */ xoffs = (lcd_wid > (strlen(today) + strlen(now) + 1)) ? ((lcd_wid - ((strlen(today) + strlen(now) + 1))) / 2) + 1 : 1; if (display) @@ -248,7 +250,7 @@ clock_screen(int rep, int display, int *flags_ptr) } return 0; -} // End clock_screen() +} /* End clock_screen() */ /** @@ -277,7 +279,7 @@ uptime_screen(int rep, int display, int *flags_ptr) int days, hour, min, sec; double uptime, idle; static int heartbeat = 0; - char tmp[257]; // should be large enough for host name + char tmp[257]; /* should be large enough for host name */ if ((*flags_ptr & INITIALIZED) == 0) { *flags_ptr |= INITIALIZED; @@ -299,7 +301,8 @@ uptime_screen(int rep, int display, int *flags_ptr) sprintf(tmp, "%s %s", get_sysname(), get_sysrelease()); xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1; sock_printf(sock, "widget_set U three %i 4 {%s}\n", xoffs, tmp); - } else { + } + else { sock_send_string(sock, "widget_add U one string\n"); sock_printf(sock, "widget_set U title {%s %s: %s}\n", @@ -307,7 +310,7 @@ uptime_screen(int rep, int display, int *flags_ptr) } } - // toggle colon display + /* toggle colon display */ heartbeat ^= 1; machine_get_uptime(&uptime, &idle); @@ -330,7 +333,7 @@ uptime_screen(int rep, int display, int *flags_ptr) } return 0; -} // End uptime_screen() +} /* End uptime_screen() */ /** @@ -357,16 +360,16 @@ big_clock_screen(int rep, int display, int *flags_ptr) { time_t thetime; struct tm *rtime; - int pos[] = { 1, 4, 8, 11, 15, 18 }; + int pos[] = {1, 4, 8, 11, 15, 18}; char fulltxt[16]; static char old_fulltxt[16]; static int heartbeat = 0; static int TwentyFourHour = 1; int j = 0; int digits = (lcd_wid >= 20) ? 6 : 4; - int xoffs = (lcd_wid + 1 - (pos[digits-1] + 2)) / 2; + int xoffs = (lcd_wid + 1 - (pos[digits - 1] + 2)) / 2; - // toggle colon display + /* toggle colon display */ heartbeat ^= 1; if ((*flags_ptr & INITIALIZED) == 0) { @@ -403,19 +406,19 @@ big_clock_screen(int rep, int display, int *flags_ptr) } } - if (heartbeat) { // 10 means: colon + if (heartbeat) { /* 10 means: colon */ sock_printf(sock, "widget_set K c0 %d 10\n", xoffs + 7); if (digits > 4) sock_printf(sock, "widget_set K c1 %d 10\n", xoffs + 14); } - else { // kludge: use illegal number to clear colon display + else { /* kludge: use illegal number to clear colon display */ sock_printf(sock, "widget_set K c0 %d 11\n", xoffs + 7); if (digits > 4) sock_printf(sock, "widget_set K c1 %d 11\n", xoffs + 14); } return 0; -} // End big_clock_screen() +} /* End big_clock_screen() */ /** @@ -447,7 +450,7 @@ mini_clock_screen(int rep, int display, int *flags_ptr) static int heartbeat = 0; int xoffs; - // toggle colon display + /* toggle colon display */ heartbeat ^= 1; if ((*flags_ptr & INITIALIZED) == 0) { @@ -472,7 +475,7 @@ mini_clock_screen(int rep, int display, int *flags_ptr) sock_printf(sock, "widget_set N one %d %d {%s}\n", xoffs, (lcd_hgt / 2), now); return 0; -} // End mini_clock_screen() +} /* End mini_clock_screen() */ /** Helper function: toggle between ':' and ' ' in time strings. @@ -493,6 +496,6 @@ tickTime(char *time, int heartbeat) *ptr = colon[heartbeat]; } } - return(time); + return (time); } diff --git a/clients/lcdproc/chrono.h b/clients/lcdproc/chrono.h index 2732c17..e69de29 100644 --- a/clients/lcdproc/chrono.h +++ b/clients/lcdproc/chrono.h @@ -1,10 +0,0 @@ -#ifndef CHRONO_H -#define CHRONO_H - -int clock_screen(int rep, int display, int *flags_ptr); -int uptime_screen(int rep, int display, int *flags_ptr); -int time_screen(int rep, int display, int *flags_ptr); -int big_clock_screen(int rep, int display, int *flags_ptr); -int mini_clock_screen(int rep, int display, int *flags_ptr); - -#endif diff --git a/clients/lcdproc/cpu.c b/clients/lcdproc/cpu.c index e91a7bb..9ce69ae 100644 --- a/clients/lcdproc/cpu.c +++ b/clients/lcdproc/cpu.c @@ -52,14 +52,14 @@ cpu_screen(int rep, int display, int *flags_ptr) { #undef CPU_BUF_SIZE #define CPU_BUF_SIZE 4 - static double cpu[CPU_BUF_SIZE + 1][5]; // last buffer is scratch + static double cpu[CPU_BUF_SIZE + 1][5]; /* last buffer is scratch */ static int gauge_wid = 0; static int usni_wid = 0; int i, j, n; double value; load_type load; - char tmp[25]; // should be large enough + char tmp[25]; /* should be large enough */ if ((*flags_ptr & INITIALIZED) == 0) { *flags_ptr |= INITIALIZED; @@ -67,7 +67,7 @@ cpu_screen(int rep, int display, int *flags_ptr) sock_send_string(sock, "screen_add C\n"); 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% + gauge_wid = lcd_wid - 6; /* room between 0%...100% */ sock_send_string(sock, "widget_add C title title\n"); sock_send_string(sock, "widget_set C title {CPU LOAD}\n"); @@ -87,8 +87,8 @@ cpu_screen(int rep, int display, int *flags_ptr) sock_send_string(sock, "widget_set C bar 3 4 0\n"); } else { - usni_wid = (lcd_wid - 4) / 4; // 4 gauges + 1 letter for each - gauge_wid = lcd_wid - 12; // room between [...] + usni_wid = (lcd_wid - 4) / 4; /* 4 gauges + 1 letter for each */ + gauge_wid = lcd_wid - 12; /* room between [...] */ sock_send_string(sock, "widget_add C cpu string\n"); sock_printf(sock, "widget_set C cpu 1 1 {CPU [%*s]}\n", gauge_wid, ""); @@ -105,43 +105,33 @@ cpu_screen(int rep, int display, int *flags_ptr) sock_send_string(sock, "widget_set C total 6 1 0\n"); } - return(0); + return (0); } machine_get_load(&load); - // Shift values over by one + /* Shift values over by one */ for (i = 0; i < (CPU_BUF_SIZE - 1); i++) for (j = 0; j < 5; j++) cpu[i][j] = cpu[i + 1][j]; - // Read new data + /* Read new data */ if (load.total > 0L) { - cpu[CPU_BUF_SIZE - 1][0] = 100.0 * ((double) load.user / (double) load.total); - cpu[CPU_BUF_SIZE - 1][1] = 100.0 * ((double) load.system / (double) load.total); - cpu[CPU_BUF_SIZE - 1][2] = 100.0 * ((double) load.nice / (double) load.total); - cpu[CPU_BUF_SIZE - 1][3] = 100.0 * ((double) load.idle / (double) load.total); - cpu[CPU_BUF_SIZE - 1][4] = 100.0 * (((double) load.user + (double) load.system + (double) load.nice) / (double) load.total); + cpu[CPU_BUF_SIZE - 1][0] = 100.0 * ((double) load.user / (double) load.total); + cpu[CPU_BUF_SIZE - 1][1] = 100.0 * ((double) load.system / (double) load.total); + cpu[CPU_BUF_SIZE - 1][2] = 100.0 * ((double) load.nice / (double) load.total); + cpu[CPU_BUF_SIZE - 1][3] = 100.0 * ((double) load.idle / (double) load.total); + cpu[CPU_BUF_SIZE - 1][4] = 100.0 * (((double) load.user + (double) load.system + (double) load.nice) / (double) load.total); } else { - cpu[CPU_BUF_SIZE - 1][0] = 0.0; - cpu[CPU_BUF_SIZE - 1][1] = 0.0; - cpu[CPU_BUF_SIZE - 1][2] = 0.0; - cpu[CPU_BUF_SIZE - 1][3] = 0.0; - cpu[CPU_BUF_SIZE - 1][4] = 0.0; + cpu[CPU_BUF_SIZE - 1][0] = 0.0; + cpu[CPU_BUF_SIZE - 1][1] = 0.0; + cpu[CPU_BUF_SIZE - 1][2] = 0.0; + cpu[CPU_BUF_SIZE - 1][3] = 0.0; + cpu[CPU_BUF_SIZE - 1][4] = 0.0; } - /* - // Only clear on first display... - if (!rep) { - // Make all the same, if this is the first time... - for (i=0; i < CPU_BUF_SIZE-1; i++) - for (j=0; j < 5; j++) - cpu[i][j] = cpu[CPU_BUF_SIZE-1][j]; - } - */ - - // Average values for final result + /* Average values for final result */ for (i = 0; i < 5; i++) { value = 0.0; for (j = 0; j < CPU_BUF_SIZE; j++) @@ -151,9 +141,9 @@ cpu_screen(int rep, int display, int *flags_ptr) } if (!display) - return(0); + return (0); - if (lcd_hgt >= 4) { // 4-line display + if (lcd_hgt >= 4) { /* 4-line display */ sprintf_percent(tmp, cpu[CPU_BUF_SIZE][4]); sock_printf(sock, "widget_set C title {CPU %5s: %s}\n", tmp, get_hostname()); @@ -172,7 +162,7 @@ cpu_screen(int rep, int display, int *flags_ptr) n = (int) ((cpu[CPU_BUF_SIZE][4] * lcd_cellwid * gauge_wid) / 100.0); sock_printf(sock, "widget_set C bar 3 4 %d\n", n); } - else { // 2-line display + else { /* 2-line display */ sprintf_percent(tmp, cpu[CPU_BUF_SIZE][4]); sock_printf(sock, "widget_set C cpu%% %d 1 {%5s}\n", lcd_wid - 5, tmp); @@ -192,8 +182,8 @@ cpu_screen(int rep, int display, int *flags_ptr) sock_printf(sock, "widget_set C idle %d 2 %d\n", 3 * (usni_wid + 1) + 2, n); } - return(0); -} // End cpu_screen() + return (0); +} /* End cpu_screen() */ @@ -226,7 +216,7 @@ cpu_graph_screen(int rep, int display, int *flags_ptr) static int gauge_hgt = 0; int i, n = 0; - double value ; + double value; load_type load; if ((*flags_ptr & INITIALIZED) == 0) { @@ -249,34 +239,34 @@ cpu_graph_screen(int rep, int display, int *flags_ptr) for (i = 1; i <= lcd_wid; i++) { 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; + cpu_past[i - 1] = 0; }; - // Clear out CPU averaging array - for (i = 0; i < CPU_BUF_SIZE ; i++) + /* Clear out CPU averaging array */ + for (i = 0; i < CPU_BUF_SIZE; i++) cpu[i] = 0.; } - // Shift values over by one - for (i = 0; i < (CPU_BUF_SIZE-1); i++) - cpu[i] = cpu[i+1]; + /* Shift values over by one */ + for (i = 0; i < (CPU_BUF_SIZE - 1); i++) + cpu[i] = cpu[i + 1]; - // Read and save new data + /* Read and save new data */ machine_get_load(&load); cpu[CPU_BUF_SIZE-1] = (load.total > 0L) ? ((double) load.user + (double) load.system + (double) load.nice) / (double) load.total : 0; - // Average values for final result + /* Average values for final result */ value = 0.0; for (i = 0; i < CPU_BUF_SIZE; i++) value += cpu[i]; value /= CPU_BUF_SIZE; - // Scale result to available height (leave 1st line free when height > 2) + /* Scale result to available height (leave 1st line free when height > 2) */ n = (int) (value * lcd_cellhgt * gauge_hgt); - // Shift and update display the graph + /* Shift and update display the graph */ for (i = 0; i < lcd_wid - 1; i++) { cpu_past[i] = cpu_past[i + 1]; @@ -286,12 +276,11 @@ cpu_graph_screen(int rep, int display, int *flags_ptr) } } - // Save the newest entry and display it + /* Save the newest entry and display it */ cpu_past[lcd_wid - 1] = n; if (display) { sock_printf(sock, "widget_set G bar%d %d %d %d\n", lcd_wid, lcd_wid, lcd_hgt, n); } - return(0); -} // End cpu_graph_screen() - + return (0); +} /* End cpu_graph_screen() */ diff --git a/clients/lcdproc/cpu_smp.c b/clients/lcdproc/cpu_smp.c index 873815d..c5f362c 100644 --- a/clients/lcdproc/cpu_smp.c +++ b/clients/lcdproc/cpu_smp.c @@ -1,40 +1,31 @@ /** \file clients/lcdproc/cpu_smp.c -* Display cpu info for multi-processor machines. -* -* Adapted from cpu.c. -* -* Really boring for the moment, it only shows a current usage percentage graph -* for each CPU. -* -* It will handle up to 2xlcd_hgt or 8 CPUs, whichever is less. If there are -* more CPUs than lines on the LCD, it puts 2 CPUs per line, splitting the line -* in half. Otherwise, it uses one line per CPU. -* -* If the number of lines used to display the bar graphs for the CPUs is smaller -* than the LCD's height, a title line is introduced, so that the screen looks -* similar to other lcdproc screens. -* In all other cases (i.e. \#CPUs == LCD height or \#CPUs >= 2 * LCD height), -* the title is left out to display as many CPUs graphs as possible. -*/ + * Display cpu info for multi-processor machines. + * + * Adapted from cpu.c. + * + * Really boring for the moment, it only shows a current usage percentage graph + * for each CPU. + * + * It will handle up to 2xlcd_hgt or 8 CPUs, whichever is less. If there are + * more CPUs than lines on the LCD, it puts 2 CPUs per line, splitting the line + * in half. Otherwise, it uses one line per CPU. + * + * If the number of lines used to display the bar graphs for the CPUs is smaller + * than the LCD's height, a title line is introduced, so that the screen looks + * similar to other lcdproc screens. + * In all other cases (i.e. \#CPUs == LCD height or \#CPUs >= 2 * LCD height), + * the title is left out to display as many CPUs graphs as possible. + */ /*- -* Copyright (C) 2000 J Robert Ray -* Copyright (C) 2006,7 Peter Marschall -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software Foundation, -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ + * Copyright (C) 2000 J Robert Ray + * Copyright (C) 2006,2007 Peter Marschall + * + * This file is part of lcdproc, the lcdproc client. + * + * This file is released under the GNU General Public License. + * Refer to the COPYING file distributed with this package. + */ #include #include @@ -65,20 +56,20 @@ cpu_smp_screen (int rep, int display, int *flags_ptr) #undef CPU_BUF_SIZE #define CPU_BUF_SIZE 4 int z; - static float cpu[MAX_CPUS][CPU_BUF_SIZE + 1]; // last buffer is scratch + static float cpu[MAX_CPUS][CPU_BUF_SIZE + 1]; /* last buffer is scratch */ load_type load[MAX_CPUS]; int num_cpus = MAX_CPUS; int bar_size; int lines_used; - // get SMP load - inform about max #CPUs allowed + /* get SMP load - inform about max #CPUs allowed */ machine_get_smpload(load, &num_cpus); - // restrict num_cpus to max. twice the display height + /* restrict num_cpus to max. twice the display height */ if (num_cpus > 2 * lcd_hgt) num_cpus = 2 * lcd_hgt; - // 2 CPUs per line if more CPUs than lines + /* 2 CPUs per line if more CPUs than lines */ bar_size = (num_cpus > lcd_hgt) ? (lcd_wid / 2 - 6) : (lcd_wid - 6); lines_used = (num_cpus > lcd_hgt) ? (num_cpus + 1) / 2 : num_cpus; @@ -87,7 +78,7 @@ cpu_smp_screen (int rep, int display, int *flags_ptr) sock_send_string(sock, "screen_add P\n"); - // print title if he have room for it + /* print title if he have room for it */ if (lines_used < lcd_hgt) { sock_send_string(sock, "widget_add P title title\n"); sock_printf(sock, "widget_set P title {SMP CPU %s}\n", get_hostname()); @@ -119,16 +110,16 @@ cpu_smp_screen (int rep, int display, int *flags_ptr) float value = 0.0; int i, n; - // Shift values over by one + /* Shift values over by one */ for (i = 0; i < (CPU_BUF_SIZE - 1); i++) cpu[z][i] = cpu[z][i + 1]; - // Read new data + /* Read new data */ cpu[z][CPU_BUF_SIZE-1] = (load[z].total > 0L) ? (((float) load[z].user + (float) load[z].system + (float) load[z].nice) / (float) load[z].total) * 100.0 : 0.0; - // Average values for final result + /* Average values for final result */ for (i = 0; i < CPU_BUF_SIZE; i++) { value += cpu[z][i]; } @@ -139,4 +130,4 @@ cpu_smp_screen (int rep, int display, int *flags_ptr) } return 0; -} // End cpu_screen() +} diff --git a/clients/lcdproc/disk.c b/clients/lcdproc/disk.c index d7bf8ee..6c87222 100644 --- a/clients/lcdproc/disk.c +++ b/clients/lcdproc/disk.c @@ -56,7 +56,7 @@ disk_screen(int rep, int display, int *flags_ptr) static mounts_type mnt[256]; static int count = 0; - // Holds info to display (avoid recalculating it) + /* Holds info to display (avoid recalculating it) */ struct disp { char dev[16]; char cap[8]; @@ -87,12 +87,11 @@ disk_screen(int rep, int display, int *flags_ptr) sock_send_string(sock, "widget_set D err1 5 2 { Reading }\n"); sock_send_string(sock, "widget_set D err2 5 3 {Filesystems}\n"); } - // Grab disk stats on first display, and fill "table". - // Get rid of old, unmounted filesystems... + /* Get rid of old, unmounted filesystems... */ machine_get_fs(mnt, &count); - // Fill the display structure... + /* Fill the display structure... */ if (count) { sock_send_string(sock, "widget_set D err1 0 0 .\n"); sock_send_string(sock, "widget_set D err2 0 0 .\n"); @@ -103,8 +102,8 @@ disk_screen(int rep, int display, int *flags_ptr) sprintf(table[i].dev, "%s", mnt[i].mpoint); table[i].full = (huge) (lcd_cellwid * gauge_wid) - * (huge) (mnt[i].blocks - mnt[i].bfree) - / (huge) mnt[i].blocks; + * (huge) (mnt[i].blocks - mnt[i].bfree) + / (huge) mnt[i].blocks; size = (huge) mnt[i].bsize * (huge) mnt[i].blocks; memset(table[i].cap, '\0', 8); @@ -118,33 +117,35 @@ disk_screen(int rep, int display, int *flags_ptr) return 0; } - // Display stuff... (show for two seconds, then scroll once per - // second, then hold at the end for two seconds) + /* + * Display stuff... (show for two seconds, then scroll once per + * second, then hold at the end for two seconds) + */ sock_printf(sock, "widget_set D f 1 2 %i %i %i %i v 12\n", lcd_wid, lcd_hgt, lcd_wid, count); for (i = 0; i < count; i++) { - char tmp[lcd_wid+1]; // should be large enough + char tmp[lcd_wid + 1]; /* should be large enough */ if (table[i].dev[0] == '\0') continue; - if (i >= num_disks) { // Make sure we have enough lines... + if (i >= num_disks) { /* Make sure we have enough lines... */ sock_printf(sock, "widget_add D s%i string -in f\n", i); sock_printf(sock, "widget_add D h%i hbar -in f\n", i); } - if (lcd_wid >= 20) { // 20+x columns + if (lcd_wid >= 20) { /* 20+x columns */ sprintf(tmp, "%-*s %6s E%*sF", dev_wid, table[i].dev, table[i].cap, gauge_wid, ""); sock_printf(sock, "widget_set D s%i 1 %i {%s}\n", i, i + 1, tmp); sock_printf(sock, "widget_set D h%i %i %i %i\n", i, 10 + dev_wid, i + 1, table[i].full); } - else { // < 20 columns + else { /* < 20 columns */ sprintf(tmp, "%-*s E%*sF", dev_wid, table[i].dev, gauge_wid, ""); sock_printf(sock, "widget_set D s%i 1 %i {%s}\n", i, i + 1, tmp); sock_printf(sock, "widget_set D h%i %i %i %i\n", i, 3 + dev_wid, i + 1, table[i].full); } } - // Now remove extra widgets... - for ( ; i < num_disks; i++) { + /* Now remove extra widgets... */ + for (; i < num_disks; i++) { sock_printf(sock, "widget_del D s%i\n", i); sock_printf(sock, "widget_del D h%i\n", i); } diff --git a/clients/lcdproc/eyebox.c b/clients/lcdproc/eyebox.c index af17ec7..37e88ea 100644 --- a/clients/lcdproc/eyebox.c +++ b/clients/lcdproc/eyebox.c @@ -1,29 +1,16 @@ /** \file clients/lcdproc/eyebox.c - This is the LCDproc client module for EyeboxOne devices - - This allows to use leds, one as a free CPU meter, and one - as a free RAM meter. - - All this is in BETA version, take it as a demo... -*/ + * This is the LCDproc client module for EyeboxOne devices + * + * This allows to use leds, one as a free CPU meter, and one as a free RAM + * meter. + */ /*- - Copyright (C) 2006 Cedric TESSIER (aka NeZetiC) http://www.nezetic.info - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 -*/ + * Copyright (C) 2006 Cedric TESSIER (aka NeZetiC) http://www.nezetic.info + * + * This file is released under the GNU General Public License. + * Refer to the COPYING file distributed with this package. + */ #include #include @@ -50,7 +37,7 @@ eyebox_screen(char display, int init) #define CPU_BUF_SIZE 4 int i, j; double value; - static double cpu[CPU_BUF_SIZE + 1][5]; // last buffer is scratch + static double cpu[CPU_BUF_SIZE + 1][5]; /* last buffer is scratch */ meminfo_type mem[2]; load_type load; @@ -58,18 +45,18 @@ eyebox_screen(char display, int init) sock_printf(sock, "widget_add %c eyebo_cpu string\n", display); sock_printf(sock, "widget_add %c eyebo_mem string\n", display); - return(0); + return 0; } machine_get_load(&load); machine_get_meminfo(mem); - // Shift values over by one + /* Shift values over by one */ for (i = 0; i < (CPU_BUF_SIZE - 1); i++) for (j = 0; j < 5; j++) cpu[i][j] = cpu[i + 1][j]; - // Read new data + /* Read new data */ if (load.total > 0L) { cpu[CPU_BUF_SIZE - 1][0] = 100.0 * ((double) load.user / (double) load.total); cpu[CPU_BUF_SIZE - 1][1] = 100.0 * ((double) load.system / (double) load.total); @@ -85,7 +72,7 @@ eyebox_screen(char display, int init) cpu[CPU_BUF_SIZE - 1][4] = 0.0; } - // Average values for final result + /* Average values for final result */ for (i = 0; i < 5; i++) { value = 0.0; for (j = 0; j < CPU_BUF_SIZE; j++) @@ -94,34 +81,30 @@ eyebox_screen(char display, int init) cpu[CPU_BUF_SIZE][i] = value; } - /* + /*- * /xBab = Use Bar * a = Bar ID * b = Level */ - sock_printf(sock, "widget_set %c eyebo_cpu 1 2 {/xB%d%d}\n", display, 2,(int)(cpu[CPU_BUF_SIZE][4]/10)); - /* + /*- * /xBab = Use Bas * a = Bar ID * b = Level */ - value = 1.0 - (double) (mem[0].free + mem[0].buffers + mem[0].cache) / (double) mem[0].total; - sock_printf(sock, "widget_set %c eyebo_mem 1 3 {/xB%d%d}\n", display, 1, (int) (value * 10)) ; + sock_printf(sock, "widget_set %c eyebo_mem 1 3 {/xB%d%d}\n", display, 1, (int) (value * 10)); return 0; -} // End mem_screen() +} void eyebox_clear(void) { - /* - * Clear LEDs before exit - */ + /* Clear LEDs before exit */ sock_send_string(sock, "screen_add OFF\n"); sock_send_string(sock, "screen_set OFF -priority alert -name {EyeBO}\n"); sock_send_string(sock, "widget_add OFF title title\n"); @@ -135,6 +118,6 @@ eyebox_clear(void) sock_send_string(sock, "widget_set OFF about 5 4 {EyeBO by NeZetiC}\n"); sock_printf(sock, "widget_set OFF cpu 1 2 {/xB%d%d}\n", 2, 0); sock_printf(sock, "widget_set OFF mem 1 3 {/xB%d%d}\n", 1, 0); - usleep(2000000); /* Wait last order execution */ + usleep(2000000); /* Wait last order execution */ } diff --git a/clients/lcdproc/iface.c b/clients/lcdproc/iface.c index a7654b3..ae8d9a6 100644 --- a/clients/lcdproc/iface.c +++ b/clients/lcdproc/iface.c @@ -3,25 +3,15 @@ */ /*- - Copyright (C) 2002 Luis Llorente Campo - Multiinterface Extension by Stephan Skrodzki - Adaptions to lcdproc by Andrew Foss with fixes by M. Dolze - Cleanup, reorganization by Peter Marschall - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ + * Copyright (C) 2002 Luis Llorente Campo + * + * Multi-interface extension by Stephan Skrodzki + * Adaptions to lcdproc by Andrew Foss with fixes by M. Dolze + * Cleanup, reorganization by Peter Marschall + * + * This file is released under the GNU General Public License. + * Refer to the COPYING file distributed with this package. + */ #include #include @@ -43,9 +33,9 @@ #define UNSET_STR "\01" -static int iface_count = 0; /* number of interfaces */ -static char unit_label[10] = "B"; /* default unit label is Bytes */ -static int transfer_screen = 0; /* by default, transfer screen is not shown */ +static int iface_count = 0; /* number of interfaces */ +static char unit_label[10] = "B"; /* default unit label is Bytes */ +static int transfer_screen = 0; /* by default, transfer screen is not shown */ /** Reads and parses configuration file. @@ -56,10 +46,9 @@ iface_process_configfile(void) { const char *unit; - debug( RPT_DEBUG, "%s()", __FUNCTION__ ); + debug(RPT_DEBUG, "%s()", __FUNCTION__); /* Read config settings */ - for (iface_count = 0; iface_count < MAX_INTERFACES; iface_count++) { char iface_label[12]; @@ -75,10 +64,13 @@ iface_process_configfile(void) sprintf(iface_label, "Alias%i", iface_count); iface[iface_count].alias = strdup(config_get_string("Iface", iface_label, 0, iface[iface_count].name)); if (iface[iface_count].alias == NULL) - // make alia the same as the interface name in case strdup() failed + /* + * make alias the same as the interface name in case # + * strdup() failed + */ iface[iface_count].alias = iface[iface_count].name; debug(RPT_DEBUG, "Interface %i: %s alias %s", - iface_count, iface[iface_count].name, iface[iface_count].alias); + iface_count, iface[iface_count].name, iface[iface_count].alias); } unit = config_get_string("Iface", "Unit", 0, "byte"); @@ -95,7 +87,7 @@ iface_process_configfile(void) report(RPT_ERR, "illegal Unit value: %s", unit); return -1; } - unit_label[sizeof(unit_label)-1] = '\0'; + unit_label[sizeof(unit_label) - 1] = '\0'; transfer_screen = config_get_bool("Iface", "Transfer", 0, 0); @@ -126,12 +118,12 @@ iface_process_configfile(void) int iface_screen(int rep, int display, int *flags_ptr) { - /* ALF TODO need to make this actual time since last run */ - unsigned int interval = difftime(time(NULL), iface[0].last_online); /* interval since last update */ + /* interval since last update */ + unsigned int interval = difftime(time(NULL), iface[0].last_online); int iface_nmbr; if (!interval) - return 0; /* need at least 1 second, no divide by 0 */ + return 0; /* need at least 1 second, no divide by 0 */ if ((*flags_ptr & INITIALIZED) == 0) { *flags_ptr |= INITIALIZED; @@ -149,15 +141,15 @@ iface_screen(int rep, int display, int *flags_ptr) /* initialize all interface structs */ for (iface_nmbr = 0; iface_nmbr < iface_count; iface_nmbr++) { - iface[iface_nmbr].last_online = 0; - iface[iface_nmbr].status = down; + iface[iface_nmbr].last_online = 0; + iface[iface_nmbr].status = down; } return 0; } /* for each interface do */ for (iface_nmbr = 0; iface_nmbr < iface_count; iface_nmbr++) { - /*read iface_parameter stats */ + /* read iface_parameter stats */ if (!machine_get_iface_stats(&iface[iface_nmbr])) { /* there was an error, so we exit the loop */ break; @@ -178,8 +170,7 @@ iface_screen(int rep, int display, int *flags_ptr) } return 0; -} /* End iface_screen() */ - +} /** @@ -188,22 +179,15 @@ iface_screen(int rep, int display, int *flags_ptr) void initialize_speed_screen(void) { - int iface_nmbr; /* interface number */ + int iface_nmbr; /* interface number */ - /* Add screen */ sock_send_string(sock, "screen_add I\n"); - - /* Set screen name */ sock_send_string(sock, "screen_set I name {Load}\n"); - - /* Add title to screen */ sock_send_string(sock, "widget_add I title title\n"); - if ((iface_count == 1) && (lcd_hgt >= 4 )) { /* Single interface mode */ - /* Set title */ + /* Single interface mode */ + if ((iface_count == 1) && (lcd_hgt >= 4 )) { sock_printf(sock, "widget_set I title {Net Load: %s}\n", iface[0].alias); - - /* Add and set download, upload and total string widgets */ sock_send_string(sock, "widget_add I dl string\n"); sock_send_string(sock, "widget_set I dl 1 2 {DL:}\n"); sock_send_string(sock, "widget_add I ul string\n"); @@ -211,7 +195,8 @@ initialize_speed_screen(void) sock_send_string(sock, "widget_add I total string\n"); sock_send_string(sock, "widget_set I total 1 4 {Total:}\n"); } - else { /* multi-interfaces mode: one line per interface */ + /* multi-interfaces mode: one line per interface */ + else { /* Set title */ if (strstr(unit_label, "B")) { sock_printf(sock, "widget_set I title {Net Load (bytes)}\n"); @@ -225,22 +210,22 @@ initialize_speed_screen(void) } } + /* frame from (2, left) to (width, height) that is iface_count lines high */ sock_send_string (sock, "widget_add I f frame\n"); - - // frame from (2, left) to (width, height) that is iface_count lines high sock_printf(sock, "widget_set I f 1 2 %d %d %d %d v 16\n", - lcd_wid, lcd_hgt, lcd_wid, iface_count, - // scroll rate: 1 line every X ticks (=1/8 sec) - ((lcd_hgt >= 4) ? 8 : 16)); + lcd_wid, lcd_hgt, lcd_wid, iface_count, + /* scroll rate: 1 line every X ticks (=1/8 sec) */ + ((lcd_hgt >= 4) ? 8 : 16)); + /* Add interfaces to frame */ for (iface_nmbr = 0; iface_nmbr < iface_count; iface_nmbr++) { sock_printf(sock, "widget_add I i%1d string -in f\n", iface_nmbr); - sock_printf(sock, "widget_set I i%1d 1 %1d {%5.5s NA (never)}\n",\ - iface_nmbr, iface_nmbr+1, iface[iface_nmbr].alias); + sock_printf(sock, "widget_set I i%1d 1 %1d {%5.5s NA (never)}\n", + iface_nmbr, iface_nmbr+1, iface[iface_nmbr].alias); } } +} -} /* initialize_speed_screen() */ /** * Format the value (in bytes) passed as parameter according to its scale, @@ -264,7 +249,8 @@ format_value (char *buff, double value, char *unit) /* If units are bytes, then divide by 2^10, otherwise by 10^3 */ mag = convert_double(&value, (strstr(unit, "B")) ? 1024 : 1000, 1.0f); - /* Formatting rules: + /*- + * Formatting rules: * - if original value was < 1000, output decimal value only * - otherwise format with 3 precision */ @@ -272,8 +258,8 @@ format_value (char *buff, double value, char *unit) sprintf(buff, "%8ld %s", (long) value, unit); else sprintf(buff, "%7.3f %s%s", value, mag, unit); +} -} /* format_value() */ /** * Format the value (in bytes) passed as parameter according to its scale, @@ -286,7 +272,7 @@ format_value (char *buff, double value, char *unit) * to binary multiples (1024 bytes = 1 KiB). */ void -format_value_multi_interface (char *buff, double value, char *unit) +format_value_multi_interface(char *buff, double value, char *unit) { char *mag; @@ -295,7 +281,8 @@ format_value_multi_interface (char *buff, double value, char *unit) mag = convert_double(&value, (strstr(unit, "B")) ? 1024 : 1000, 1.0f); - /* Formatting rules: + /*- + * Formatting rules: * - if original value was < 1000, output decimal value only * - with 1 precision if <10 * - decimal value with magnitude otherwise @@ -306,8 +293,8 @@ format_value_multi_interface (char *buff, double value, char *unit) sprintf(buff, "%3.1f%s", value, mag); else sprintf(buff, "%3.0f%s", value, mag); +} -} /* format_value_multi_interface() */ /** * Format the time in ASCII, depending on the elapsed time. @@ -315,15 +302,15 @@ format_value_multi_interface (char *buff, double value, char *unit) * \param last_online Time value */ void -get_time_string (char *buff, time_t last_online) +get_time_string(char *buff, time_t last_online) { - time_t act_time; /* actual time */ + time_t act_time; /* actual time */ char timebuff[30]; act_time = time(NULL); - if (last_online == 0) { /* never was online */ + if (last_online == 0) { /* never was online */ sprintf(buff, "never"); return; } @@ -331,7 +318,8 @@ get_time_string (char *buff, time_t last_online) /* Transform Unix time format to UTC time format */ strcpy(timebuff, ctime(&last_online)); - if ((act_time - last_online) > 86400 ) { /* 86400 = 24 * 60 * 60. Is it more than 24 hours? */ + /* 86400 = 24 * 60 * 60. Is it more than 24 hours? */ + if ((act_time - last_online) > 86400 ) { timebuff[10] = '\0'; sprintf(buff, "%s", &timebuff[4]); return; @@ -341,7 +329,8 @@ get_time_string (char *buff, time_t last_online) sprintf(buff, "%s", &timebuff[11]); return; } -} /* get_time_string() */ +} + /** * Actualize values in display, calculating speeds in the defined interval @@ -354,14 +343,15 @@ get_time_string (char *buff, time_t last_online) void actualize_speed_screen(IfaceInfo *iface, unsigned int interval, int index) { - char speed[20]; /* buffer to store the formated speed string */ + char speed[20]; /* buffer to store the formated speed string */ double rc_speed; double tr_speed; - if ((iface_count == 1) && ( lcd_hgt >= 4)) { /* single interface mode */ + /* single interface mode */ + if ((iface_count == 1) && ( lcd_hgt >= 4)) { if (iface->status == up) { - /* Calculate Download speed */ - if (strstr(unit_label, "pkt")) { /* don't format this value */ + /* Calculate and actualize download speed */ + if (strstr(unit_label, "pkt")) { rc_speed = (iface->rc_pkt - iface->rc_pkt_old) / interval; sprintf(speed, "%8ld %s", (long) rc_speed, unit_label); } @@ -369,12 +359,10 @@ actualize_speed_screen(IfaceInfo *iface, unsigned int interval, int index) rc_speed = (iface->rc_byte - iface->rc_byte_old) / interval; format_value(speed, rc_speed, unit_label); } - - /* Actualize Download speed */ sock_printf(sock, "widget_set I dl 1 2 {DL: %*s/s}\n", lcd_wid - 6, speed); - /* Calculate Upload speed */ - if (strstr(unit_label, "pkt")) { /* don't format this value */ + /* Calculate and actualize upload speed */ + if (strstr(unit_label, "pkt")) { tr_speed = (iface->tr_pkt - iface->tr_pkt_old) / interval; sprintf(speed, "%8ld %s", (long)tr_speed, unit_label); } @@ -382,30 +370,27 @@ actualize_speed_screen(IfaceInfo *iface, unsigned int interval, int index) tr_speed = (iface->tr_byte - iface->tr_byte_old) / interval; format_value(speed, tr_speed, unit_label); } - - /* Actualize Upload speed */ sock_printf(sock, "widget_set I ul 1 3 {UL: %*s/s}\n", lcd_wid - 6, speed); - /* Calculate Total speed */ - if (strstr(unit_label, "pkt")) { /* don't format this value */ + /* Calculate and actualize total speed */ + if (strstr(unit_label, "pkt")) { sprintf(speed, "%7ld %s", (long)(rc_speed + tr_speed), unit_label); } else { format_value(speed, rc_speed + tr_speed, unit_label); } - - /* Actualize Total speed */ sock_printf(sock, "widget_set I total 1 4 {Total: %*s/s}\n", lcd_wid - 9, speed); } - else { /* Interface is down */ + else { get_time_string(speed, iface->last_online); sock_printf(sock, "widget_set I dl 1 2 {NA (%s)}\n", speed); sock_send_string(sock, "widget_set I ul 1 3 {}\n"); sock_send_string(sock, "widget_set I total 1 4 {}\n"); } } - else { /* multi-interfaces mode: 1 line per interface */ - char speed1[20]; /* buffer to store the formated speed string */ + /* multi-interfaces mode: 1 line per interface */ + else { + char speed1[20]; /* buffer to store the formated speed string */ if (iface->status == up) { if (strstr(unit_label, "pkt")) { @@ -425,13 +410,14 @@ actualize_speed_screen(IfaceInfo *iface, unsigned int interval, int index) sock_printf(sock, "widget_set I i%1d 1 %1d {%4.4s ^%.4s v%.4s}\n", index, index+1, iface->alias, speed1, speed); } - else { /* Interface is down */ + else { get_time_string(speed, iface->last_online); sock_printf(sock, "widget_set I i%1d 1 %1d {%5.5s NA (%s)}\n", index, index+1, iface->alias, speed); } } -} /* actualize_speed_screen() */ +} + /** * Send commands to server to add transfer screen with all required widgets. @@ -439,22 +425,15 @@ actualize_speed_screen(IfaceInfo *iface, unsigned int interval, int index) void initialize_transfer_screen(void) { - int iface_nmbr; /* interface number */ + int iface_nmbr; /* interface number */ - /* Add screen */ sock_send_string(sock, "screen_add NT\n"); - - /* Set screen name */ sock_send_string(sock, "screen_set NT name {Transfer}\n"); - - /* Add title to screen */ sock_send_string(sock, "widget_add NT title title\n"); - if ((iface_count == 1) && (lcd_hgt >= 4)) { /* single interface mode */ - /* Set title */ + /* single interface mode */ + if ((iface_count == 1) && (lcd_hgt >= 4)) { sock_printf(sock, "widget_set NT title {Transfer: %s}\n", iface[0].alias); - - /* Add and set download, upload and total string widgets */ sock_send_string(sock, "widget_add NT dl string\n"); sock_send_string(sock, "widget_set NT dl 1 2 {DL:}\n"); sock_send_string(sock, "widget_add NT ul string\n"); @@ -462,24 +441,27 @@ initialize_transfer_screen(void) sock_send_string(sock, "widget_add NT total string\n"); sock_send_string(sock, "widget_set NT total 1 4 {Total:}\n"); } - else { /* multi-interfaces mode: one line per interface */ + /* multi-interfaces mode: one line per interface */ + else { /* Set title (transfer screen is always in "bytes") */ sock_send_string(sock, "widget_set NT title {Net Transfer (bytes)}\n"); + + /* frame from (2, left) to (width, height) that is iface_count lines high */ sock_send_string(sock, "widget_add NT f frame\n"); - - // frame from (2, left) to (width, height) that is iface_count lines high sock_printf(sock, "widget_set NT f 1 2 %d %d %d %d v 16\n", - lcd_wid, lcd_hgt, lcd_wid, iface_count, - // scroll rate: 1 line every X ticks (=1/8 sec) - ((lcd_hgt >= 4) ? 8 : 16)); + lcd_wid, lcd_hgt, lcd_wid, iface_count, + /* scroll rate: 1 line every X ticks (=1/8 sec) */ + ((lcd_hgt >= 4) ? 8 : 16)); + /* Add interfaces */ for (iface_nmbr = 0; iface_nmbr < iface_count; iface_nmbr++) { sock_printf(sock, "widget_add NT i%1d string -in f\n", iface_nmbr); sock_printf(sock, "widget_set NT i%1d 1 %1d {%5.5s NA (never)}\n", - iface_nmbr, iface_nmbr+1, iface[iface_nmbr].alias); + iface_nmbr, iface_nmbr+1, iface[iface_nmbr].alias); } } -} /* initialize_transfer_screen() */ +} + /** * Actualize values in display, formatting transfer measures and sending @@ -490,9 +472,10 @@ initialize_transfer_screen(void) void actualize_transfer_screen(IfaceInfo *iface, int index) { - char transfer[20]; /* buffer to store the formated traffic string */ + char transfer[20]; /* buffer to store the formated traffic string */ - if ((iface_count == 1) && (lcd_hgt >= 4)) { /* single interface mode */ + /* single interface mode */ + if ((iface_count == 1) && (lcd_hgt >= 4)) { if (iface->status == up) { /* download traffic */ format_value(transfer, iface->rc_byte, "B"); @@ -506,15 +489,16 @@ actualize_transfer_screen(IfaceInfo *iface, int index) format_value(transfer, iface->rc_byte + iface->tr_byte, "B"); sock_printf(sock, "widget_set NT total 1 4 {Total: %*s}\n", lcd_wid - 7, transfer); } - else { /* Interface is down */ + else { get_time_string(transfer, iface->last_online); sock_printf(sock, "widget_set NT dl 1 2 {NA (%s)}\n", transfer); sock_send_string(sock, "widget_set NT ul 1 3 {}\n"); sock_send_string(sock, "widget_set NT total 1 4 {}\n"); } } - else { /* multi-interfaces mode: one line per interface */ - char transfer1[20]; /* buffer to store the formated traffic string */ + /* multi-interfaces mode: one line per interface */ + else { + char transfer1[20]; /* buffer to store the formated traffic string */ if (iface->status == up) { format_value_multi_interface(transfer, iface->rc_byte, "B"); @@ -526,10 +510,10 @@ actualize_transfer_screen(IfaceInfo *iface, int index) sock_printf(sock, "widget_set NT i%1d 1 %1d {%4.4s ^%.4s v%.4s}\n", index, index+1, iface->alias, transfer1, transfer); } - else { /* Interface is down */ + else { get_time_string(transfer, iface->last_online); sock_printf(sock, "widget_set NT i%1d 1 %1d {%5.5s NA (%s)}\n", index, index+1, iface->alias, transfer); } } -} /* actualize_transfer_screen() */ +} diff --git a/clients/lcdproc/iface.h b/clients/lcdproc/iface.h index e607e45..cc6dbaa 100644 --- a/clients/lcdproc/iface.h +++ b/clients/lcdproc/iface.h @@ -15,9 +15,10 @@ #ifndef IFACE_H #define IFACE_H -#define MAX_INTERFACES 3 /* max number of interfaces in multi-interface mode */ +/** max number of interfaces in multi-interface mode */ +#define MAX_INTERFACES 3 -IfaceInfo iface[MAX_INTERFACES]; /* interface info */ +IfaceInfo iface[MAX_INTERFACES]; /* interface info */ /** Update screen content */ int iface_screen(int rep, int display, int *flags_ptr); diff --git a/clients/lcdproc/load.c b/clients/lcdproc/load.c index 52ab3ad..d807def 100644 --- a/clients/lcdproc/load.c +++ b/clients/lcdproc/load.c @@ -69,12 +69,12 @@ xload_screen(int rep, int display, int *flags_ptr) sock_send_string(sock, "screen_add L\n"); sock_printf(sock, "screen_set L -name {Load: %s}\n", get_hostname()); - // Add the vbars... + /* Add the vbars... */ for (i = 1; i < lcd_wid; i++) { sock_printf(sock, "widget_add L bar%i vbar\n", i); sock_printf(sock, "widget_set L bar%i %i %i 0\n", i, i, lcd_hgt); } - // And add a title... + /* And add a title... */ if (lcd_hgt > 2) { sock_send_string(sock, "widget_add L title title\n"); sock_send_string(sock, "widget_set L title {LOAD }\n"); @@ -89,19 +89,21 @@ xload_screen(int rep, int display, int *flags_ptr) sock_printf(sock, "widget_set L top %i %i 1\n", lcd_wid, (lcd_hgt + 1 - gauge_hgt)); } - // shift load history + /* shift load history */ for (i = 0; i < (lcd_wid - 2); i++) loads[i] = loads[i + 1]; - // get new load value - // ignore failure: the shift above makes sure we still have the prev. value + /* + * get new load value, ignore failure: the shift above makes sure we + * still have the previous value + */ machine_get_loadavg(&(loads[lcd_wid - 2])); - // determine max. load from history + /* determine max. load from history */ for (i = 0; i < lcd_wid - 1; i++) loadmax = max(loadmax, loads[i]); - // poor man's ceil() + /* poor man's ceil() */ loadtop = (int) loadmax; if (loadtop < loadmax) loadtop++; @@ -109,7 +111,7 @@ xload_screen(int rep, int display, int *flags_ptr) factor = (double) (lcd_cellhgt * gauge_hgt) / (double) loadtop; - // display load + /* display load */ sock_printf(sock, "widget_set L top %i %i %i\n", lcd_wid, (lcd_hgt + 1 - gauge_hgt), loadtop); for (i = 0; i < lcd_wid - 1; i++) { @@ -118,13 +120,13 @@ xload_screen(int rep, int display, int *flags_ptr) sock_printf(sock, "widget_set L bar%i %i %i %i\n", i + 1, i + 1, lcd_hgt, (int) x); } - // And now the title... + /* And now the title... */ if (lcd_hgt > 2) sock_printf(sock, "widget_set L title {LOAD %2.2f: %s}\n", loads[lcd_wid - 2], get_hostname()); else sock_printf(sock, "widget_set L title 1 1 {%s %2.2f}\n", get_hostname(), loads[lcd_wid - 2]); - // set return status depending on max & current load + /* set return status depending on max & current load */ if (lowLoad < highLoad) { status = (loadmax > lowLoad) ? BACKLIGHT_ON : BACKLIGHT_OFF; if (loads[lcd_wid - 2] > highLoad) @@ -132,4 +134,4 @@ xload_screen(int rep, int display, int *flags_ptr) } return status; -} // End xload_screen() +} diff --git a/clients/lcdproc/mem.c b/clients/lcdproc/mem.c index 60235fa..d53030b 100644 --- a/clients/lcdproc/mem.c +++ b/clients/lcdproc/mem.c @@ -64,8 +64,8 @@ mem_screen(int rep, int display, int *flags_ptr) if (lcd_hgt >= 4) { gauge_wid = (lcd_wid >= 18) - ? (lcd_wid - 6) / 2 // room for E..F pairs and 2 spaces in between - : (lcd_wid - 4) / 2; // leave room for the E...F pairs + ? (lcd_wid - 6) / 2 /* room for E..F pairs and 2 spaces in between */ + : (lcd_wid - 4) / 2; /* leave room for the E...F pairs */ sock_send_string(sock, "widget_add M title title\n"); sock_send_string(sock, "widget_set M title { MEM}\n"); @@ -79,10 +79,11 @@ mem_screen(int rep, int display, int *flags_ptr) sock_printf(sock, "widget_set M EFmem 1 4 {E%*sF}\n", gauge_wid, ""); sock_send_string(sock, "widget_add M EFswap string\n"); sock_printf(sock, "widget_set M EFswap %i 4 {E%*sF}\n", - lcd_wid - gauge_wid - 1, gauge_wid, ""); + lcd_wid - gauge_wid - 1, gauge_wid, ""); sock_send_string(sock, "widget_add M memused string\n"); sock_send_string(sock, "widget_add M swapused string\n"); - } else { + } + else { gauge_wid = (lcd_wid >= 18) ? max(2, lcd_wid - 18) : 0; gauge_offs = (lcd_wid - gauge_wid) / 2 + 2; @@ -90,9 +91,9 @@ mem_screen(int rep, int display, int *flags_ptr) sock_send_string(sock, "widget_add M s string\n"); if (gauge_wid > 0) { sock_printf(sock, "widget_set M m 1 1 {M%*s[%*s]}\n", - gauge_offs - 3, "", gauge_wid, ""); + gauge_offs - 3, "", gauge_wid, ""); sock_printf(sock, "widget_set M s 1 2 {S%*s[%*s]}\n", - gauge_offs - 3, "", gauge_wid, ""); + gauge_offs - 3, "", gauge_wid, ""); } else { sock_send_string(sock, "widget_set M m 1 1 {M }\n"); @@ -112,82 +113,83 @@ mem_screen(int rep, int display, int *flags_ptr) machine_get_meminfo(mem); if (lcd_hgt >= 4) { - char tmp[12]; // should be sufficient + char tmp[12]; /* should be sufficient */ - // flip the title back and forth... (every 4 updates) + /* flip the title back and forth... (every 4 updates) */ if (which_title & 4) { sock_printf(sock, "widget_set M subtitle %i 1 {}\n", lcd_wid - 7); sock_printf(sock, "widget_set M title {%s}\n", get_hostname()); - } else { + } + else { sock_send_string(sock, "widget_set M title { MEM}\n"); sock_printf(sock, "widget_set M subtitle %i 1 { SWAP }\n", lcd_wid - 7); } which_title = (which_title + 1) & 7; - // Total memory + /* Total memory */ sprintf_memory(tmp, mem[0].total * 1024.0, 1); if (display) sock_printf(sock, "widget_set M memtotl 1 2 {%7s}\n", tmp); - // Free memory (plus buffers and cache) + /* Free memory (plus buffers and cache) */ sprintf_memory(tmp, (mem[0].free + mem[0].buffers + mem[0].cache) * 1024.0, 1); if (display) sock_printf(sock, "widget_set M memused 1 3 {%7s}\n", tmp); - // Total swap + /* Total swap */ sprintf_memory(tmp, mem[1].total * 1024.0, 1); if (display) sock_printf(sock, "widget_set M swaptotl %i 2 {%7s}\n", lcd_wid - 7, tmp); - // Free swap + /* Free swap */ sprintf_memory(tmp, mem[1].free * 1024.0, 1); if (display) sock_printf(sock, "widget_set M swapused %i 3 {%7s}\n", lcd_wid - 7, tmp); if (gauge_wid > 0) { - // Free memory graph + /* Free memory graph */ if (mem[0].total > 0) { double value = 1.0 - (double) (mem[0].free + mem[0].buffers + mem[0].cache) - / (double) mem[0].total; + / (double) mem[0].total; - //printf(".0f", val) only prints the integer part + /* printf(".0f", val) only prints the integer part */ if (display) sock_printf(sock, "widget_set M memgauge 2 4 %.0f\n", - lcd_cellwid * gauge_wid * value); + lcd_cellwid * gauge_wid * value); } - // Free swap graph + /* Free swap graph */ if (mem[1].total > 0) { double value = 1.0 - ((double) mem[1].free / (double) mem[1].total); - //printf(".0f", val) only prints the integer part + /* printf(".0f", val) only prints the integer part */ if (display) sock_printf(sock, "widget_set M swapgauge %i 4 %.0f\n", - lcd_wid - gauge_wid, lcd_cellwid * gauge_wid * value); + lcd_wid - gauge_wid, lcd_cellwid * gauge_wid * value); } } } else { - char tmp[12]; // should be sufficient + char tmp[12]; /* should be sufficient */ - // Total memory + /* Total memory */ sprintf_memory(tmp, mem[0].total * 1024.0, 1); if (display) sock_printf(sock, "widget_set M memtotl 3 1 {%6s}\n", tmp); - // Total swap + /* Total swap */ sprintf_memory(tmp, mem[1].total * 1024.0, 1); if (display) sock_printf(sock, "widget_set M swaptotl 3 2 {%6s}\n", tmp); - // Free memory graph + /* Free memory graph */ strcpy(tmp, "N/A"); if (mem[0].total > 0) { double value = 1.0 - (double) (mem[0].free + mem[0].buffers + mem[0].cache) / (double) mem[0].total; if (gauge_wid > 0) { - //printf(".0f", val) only prints the integer part + /* printf(".0f", val) only prints the integer part */ if (display) sock_printf(sock, "widget_set M memgauge %i 1 %.0f\n", gauge_offs, lcd_cellwid * gauge_wid * value); @@ -198,13 +200,13 @@ mem_screen(int rep, int display, int *flags_ptr) if (display) sock_printf(sock, "widget_set M mem%% %i 1 {%5s}\n", lcd_wid - 5, tmp); - // Free swap graph + /* Free swap graph */ strcpy(tmp, "N/A"); if (mem[1].total > 0) { double value = 1.0 - ((double) mem[1].free / (double) mem[1].total); if (gauge_wid > 0) { - //printf(".0f", val) only prints the integer part + /* printf(".0f", val) only prints the integer part */ if (display) sock_printf(sock, "widget_set M swapgauge %i 2 %.0f\n", gauge_offs, lcd_cellwid * gauge_wid * value); @@ -217,7 +219,7 @@ mem_screen(int rep, int display, int *flags_ptr) } return 0; -} // End mem_screen() +} /** @@ -272,14 +274,14 @@ mem_top_screen(int rep, int display, int *flags_ptr) sock_send_string(sock, "widget_add S title title\n"); sock_printf(sock, "widget_set S title {TOP MEM: %s}\n", get_hostname()); - // frame from (2nd line, left) to (last line, right) + /* frame from (2nd line, left) to (last line, right) */ sock_send_string(sock, "widget_add S f frame\n"); sock_printf(sock, "widget_set S f 1 2 %i %i %i 5 v %i\n", - lcd_wid, lcd_hgt, lcd_wid, - // scroll rate: 1 line every X ticks (= 1/8 sec) - ((lcd_hgt >= 4) ? 8 : 12)); + lcd_wid, lcd_hgt, lcd_wid, + /* scroll rate: 1 line every X ticks (= 1/8 sec) */ + ((lcd_hgt >= 4) ? 8 : 12)); - // frame contents + /* frame contents */ for (i = 1; i <= 5; i++) { sock_printf(sock, "widget_add S %i string -in f\n", i); } @@ -294,7 +296,7 @@ mem_top_screen(int rep, int display, int *flags_ptr) machine_get_procs(procs); - // Now, print some info... + /* Now, print some info... */ LL_Rewind(procs); LL_Sort(procs, sort_procs); LL_Rewind(procs); @@ -306,19 +308,16 @@ mem_top_screen(int rep, int display, int *flags_ptr) sprintf_memory(mem, (double) p->totl * 1024.0, 1); - //printf("Mem hog: %s: %s\n", p->name, mem); if (display) { if (p->number > 1) sock_printf(sock, "widget_set S %i 1 %i {%i %5s %s(%i)}\n", - i, i, i, mem, p->name, p->number); + i, i, i, mem, p->name, p->number); else sock_printf(sock, "widget_set S %i 1 %i {%i %5s %s}\n", - i, i, i, mem, p->name); + i, i, i, mem, p->name); } } else { - //printf("Mem hog: none?\n"); - //sprintf(buffer, "widget_set S %i 1 %i {}\n", i, i); if (display) sock_printf(sock, "widget_set S %i 1 %i { }\n", i, i); } @@ -326,12 +325,11 @@ mem_top_screen(int rep, int display, int *flags_ptr) LL_Next(procs); } - // Now clean it all up... + /* Now clean it all up... */ LL_Rewind(procs); do { procinfo_type *p = (procinfo_type *) LL_Get(procs); if (p != NULL) { - //printf("Proc: %6ik %s\n", p->size, p->name); free(p); } } while (LL_Next(procs) == 0); diff --git a/clients/lcdproc/mode.c b/clients/lcdproc/mode.c index e2f4bea..40da92e 100644 --- a/clients/lcdproc/mode.c +++ b/clients/lcdproc/mode.c @@ -18,11 +18,11 @@ #include #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #if defined( IRIX ) || defined( SOLARIS ) -#include +# include #endif #include "shared/sockets.h" @@ -40,7 +40,7 @@ mode_init(void) { machine_init(); - return(0); + return (0); } /** Clean up modes on exit */ @@ -75,9 +75,9 @@ update_screen(ScreenMode *m, int display) #ifdef LCDPROC_EYEBOXONE /* Eyebox Init */ if (init_flag == 0) - eyebox_screen(m->which,0); + eyebox_screen(m->which, 0); /* Eyebox Flush */ - eyebox_screen(m->which,1); + eyebox_screen(m->which, 1); #endif } @@ -90,7 +90,7 @@ update_screen(ScreenMode *m, int display) sock_send_string(sock, "backlight blink\n"); } - return(status); + return (status); } @@ -106,8 +106,8 @@ int credit_screen(int rep, int display, int *flags_ptr) { /* - * List of persons who contributed to LCDproc. - * Keep in sync with CREDITS file (ordered by appearance) + * List of persons who contributed to LCDproc. Keep in sync with + * CREDITS file (ordered by appearance) */ const char *contributors[] = { "William Ferrell", @@ -184,7 +184,8 @@ credit_screen(int rep, int display, int *flags_ptr) /* get number of contributors */ for (contr_num = 0; contributors[contr_num] != NULL; contr_num++) - ; + ; /* NADA */ + sock_send_string(sock, "screen_add A\n"); sock_send_string(sock, "screen_set A -name {Credits for LCDproc}\n"); sock_send_string(sock, "widget_add A title title\n"); @@ -192,15 +193,15 @@ credit_screen(int rep, int display, int *flags_ptr) if (lcd_hgt >= 4) { sock_send_string(sock, "widget_add A text scroller\n"); sock_printf(sock, "widget_set A text 1 2 %d 2 h 8 {%s}\n", - lcd_wid, "LCDproc was brought to you by:"); + lcd_wid, "LCDproc was brought to you by:"); } /* frame from (2nd/3rd line, left) to (last line, right) */ sock_send_string(sock, "widget_add A f frame\n"); sock_printf(sock, "widget_set A f 1 %i %i %i %i %i v %i\n", - ((lcd_hgt >= 4) ? 3 : 2), lcd_wid, lcd_hgt, lcd_wid, contr_num, - // scroll rate: 1 line every X ticks (= 1/8 sec) - ((lcd_hgt >= 4) ? 8 : 12)); + ((lcd_hgt >= 4) ? 3 : 2), lcd_wid, lcd_hgt, lcd_wid, contr_num, + /* scroll rate: 1 line every X ticks (= 1/8 sec) */ + ((lcd_hgt >= 4) ? 8 : 12)); /* frame contents */ for (i = 1; i < contr_num; i++) { @@ -209,7 +210,7 @@ credit_screen(int rep, int display, int *flags_ptr) } } - return(0); + return 0; } /* EOF */ diff --git a/clients/lcdproc/util.c b/clients/lcdproc/util.c index f2ed6cd..714445d 100644 --- a/clients/lcdproc/util.c +++ b/clients/lcdproc/util.c @@ -2,7 +2,7 @@ * Utility functions to print some numerical values in a nice fashion */ -/* +/*- * Copyright (C) 2005 Peter Marschall * * This program is free software; you can redistribute it and/or @@ -76,7 +76,7 @@ sprintf_percent(char *dst, double percent) char * convert_double(double *value, int base, double roundlimit) { - static char *units[] = { "", "k", "M", "G", "T", "P", "E", "Z", "Y", NULL }; + static char *units[] = {"", "k", "M", "G", "T", "P", "E", "Z", "Y", NULL}; int off = 0; if ((roundlimit <= 0.0) || (roundlimit > 1.0)) @@ -84,8 +84,10 @@ convert_double(double *value, int base, double roundlimit) /* Get value's order of magnitude */ while (units[off] != NULL) { - /* Note: the check for 1000 is to idenfity the number of - * characters in the output needed, not to decide if to scale value. + /* + * Note: the check for 1000 is to idenfity the number of + * characters in the output needed, not to decide if to scale + * value. */ if (*value < 1000 * roundlimit) break; diff --git a/clients/lcdproc/util.h b/clients/lcdproc/util.h index 8f01b41..d7391d3 100644 --- a/clients/lcdproc/util.h +++ b/clients/lcdproc/util.h @@ -2,25 +2,15 @@ * Header file for \c util.c */ -/* - * Copyright (C) 2005 Peter Marschall +/*- + * Copyright (C) 2005 Peter Marschall * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * This file is part of lcdproc, the lcdproc client. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * This file is released under the GNU General Public License. + * Refer to the COPYING file distributed with this package. */ - #ifndef LCDPROC_UTIL_H #define LCDPROC_UTIL_H @@ -36,6 +26,4 @@ char *sprintf_percent(char *dst, double percent); /** converts value into power-of-x representation */ char *convert_double(double *value, int base, double roundlimit); -#endif /* LCDPROC_UTIL_H */ - -/* EOF */ +#endif