From d77ada0bde505e1e1e963a36ecfc5807783298dc Mon Sep 17 00:00:00 2001 From: marschap Date: Sat, 18 Feb 2006 16:18:22 +0000 Subject: [PATCH] add menu support to lcdproc client (currently hidden behind #ifdef LCDPROC_MENUS) - patch provided by Andrew Foss --- clients/lcdproc/batt.c | 20 +++- clients/lcdproc/batt.h | 4 + clients/lcdproc/chrono.c | 70 ++++++++++-- clients/lcdproc/chrono.h | 8 ++ clients/lcdproc/cpu.c | 44 ++++++-- clients/lcdproc/cpu.h | 5 + clients/lcdproc/cpu_smp.c | 14 ++- clients/lcdproc/cpu_smp.h | 4 + clients/lcdproc/disk.c | 14 ++- clients/lcdproc/disk.h | 4 + clients/lcdproc/load.c | 16 ++- clients/lcdproc/load.h | 4 + clients/lcdproc/machine_Darwin.c | 34 +++--- clients/lcdproc/machine_FreeBSD.c | 50 ++++----- clients/lcdproc/machine_Linux.c | 96 ++++++++-------- clients/lcdproc/machine_NetBSD.c | 40 +++---- clients/lcdproc/machine_OpenBSD.c | 40 +++---- clients/lcdproc/machine_SunOS.c | 68 +++++------ clients/lcdproc/main.c | 180 ++++++++++++++++++++++++++---- clients/lcdproc/main.h | 8 ++ clients/lcdproc/mem.c | 40 +++++-- clients/lcdproc/mem.h | 5 + clients/lcdproc/mode.c | 85 ++++++++++++-- clients/lcdproc/mode.h | 4 + 24 files changed, 619 insertions(+), 238 deletions(-) diff --git a/clients/lcdproc/batt.c b/clients/lcdproc/batt.c index 350bf36..bf30422 100644 --- a/clients/lcdproc/batt.c +++ b/clients/lcdproc/batt.c @@ -71,14 +71,24 @@ battery_status(int status) // +--------------------+ // int +#ifdef LCDPROC_MENUS +battery_screen (int rep, int display, int * flags_ptr) +#else battery_screen (int rep, int display) +#endif { - static int first = TRUE; int acstat = 0, battstat = 0, percent = 0; int gauge_wid = lcd_wid - 2; +#ifdef LCDPROC_MENUS - if (first == TRUE) { + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; + + if (first) { first = FALSE; +#endif sock_send_string (sock, "screen_add B\n"); sprintf (buffer, "screen_set B -name {APM stats: %s}\n", get_hostname()); @@ -111,10 +121,10 @@ battery_screen (int rep, int display) sprintf(buffer, "widget_set B title {%s: %s: %s}\n", (acstat == LCDP_AC_ON && battstat == LCDP_BATT_ABSENT) ? "AC" : "Batt", tmp, get_hostname()); - if(display) + if (display) sock_send_string (sock, buffer); - if(lcd_hgt >= 4) { // 4-line version of the screen + if (lcd_hgt >= 4) { // 4-line version of the screen sprintf(buffer, "widget_set B one 1 2 {AC: %s}\n", ac_status(acstat)); if (display) sock_send_string (sock, buffer); @@ -125,7 +135,7 @@ battery_screen (int rep, int display) if (percent > 0) { sprintf(buffer, "widget_set B gauge 2 4 %d\n", (percent * gauge_wid * lcd_cellwid) / 100); - if(display) + if (display) sock_send_string(sock, buffer); } } diff --git a/clients/lcdproc/batt.h b/clients/lcdproc/batt.h index 614ac84..3a1938c 100644 --- a/clients/lcdproc/batt.h +++ b/clients/lcdproc/batt.h @@ -1,6 +1,10 @@ #ifndef BATT_H #define BATT_H +#ifdef LCDPROC_MENUS +int battery_screen (int rep, int display, int * flags_ptr); +#else int battery_screen (int rep, int display); +#endif #endif diff --git a/clients/lcdproc/chrono.c b/clients/lcdproc/chrono.c index 106e9a6..f6c56b4 100644 --- a/clients/lcdproc/chrono.c +++ b/clients/lcdproc/chrono.c @@ -96,21 +96,31 @@ static char *shortmonths[] = { //+--------------------+ // int +#ifdef LCDPROC_MENUS +time_screen (int rep, int display, int * flags_ptr) +#else time_screen (int rep, int display) +#endif { char now[20]; char day[16], month[16]; int xoffs; int days, hour, min, sec; - static int first = 1; static int heartbeat = 0; static char colon[] = {':', ' '}; time_t thetime; struct tm *rtime; double uptime, idle; +#ifdef LCDPROC_MENUS + + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; if (first) { - first = 0; + first = FALSE; +#endif sock_send_string (sock, "screen_add T\n"); sprintf (buffer, "screen_set T -name {Time Screen: %s}\n", get_hostname()); @@ -212,19 +222,29 @@ time_screen (int rep, int display) //+--------------------+ // int +#ifdef LCDPROC_MENUS +clock_screen (int rep, int display, int * flags_ptr) +#else clock_screen (int rep, int display) +#endif { char now[20]; char day[16], month[16]; int xoffs; - static int first = 1; static int heartbeat = 0; static char colon[] = {':', ' '}; time_t thetime; struct tm *rtime; +#ifdef LCDPROC_MENUS + + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; if (first) { - first = 0; + first = FALSE; +#endif sock_send_string (sock, "screen_add O\n"); sprintf (buffer, "screen_set O -name {Old Clock Screen: %s}\n", get_hostname()); @@ -306,17 +326,27 @@ clock_screen (int rep, int display) //+--------------------+ // int +#ifdef LCDPROC_MENUS +uptime_screen (int rep, int display, int * flags_ptr) +#else uptime_screen (int rep, int display) +#endif { int xoffs; int days, hour, min, sec; double uptime, idle; - static int first = 1; static int heartbeat = 0; static char colon[] = {':', ' '}; +#ifdef LCDPROC_MENUS + + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; if (first) { - first = 0; + first = FALSE; +#endif sock_send_string (sock, "screen_add U\n"); sprintf (buffer, "screen_set U -name {Uptime Screen: %s}\n", get_hostname()); @@ -383,9 +413,12 @@ uptime_screen (int rep, int display) // +--------------------+ // int +#ifdef LCDPROC_MENUS +big_clock_screen (int rep, int display, int * flags_ptr) +#else big_clock_screen (int rep, int display) +#endif { - static int first = 1; time_t thetime; struct tm *rtime; int pos[] = { 1, 4, 8, 11, 15, 18 }; @@ -399,9 +432,16 @@ big_clock_screen (int rep, int display) // toggle colon display heartbeat ^= 1; +#ifdef LCDPROC_MENUS + + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; if (first) { - first = 0; + first = FALSE; +#endif sock_send_string (sock, "screen_add K\n"); sock_send_string (sock, "screen_set K -name {Big Clock Screen} -heartbeat off\n"); @@ -460,15 +500,25 @@ big_clock_screen (int rep, int display) //+--------------------+ // int +#ifdef LCDPROC_MENUS +essential_clock_screen (int rep, int display, int * flags_ptr) +#else essential_clock_screen (int rep, int display) +#endif { - static int first = 1; struct tm *rtime; struct timeval ttime; static char colon[] = {':', ' '}; +#ifdef LCDPROC_MENUS + + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; if (first) { - first = 0; + first = FALSE; +#endif sock_send_string (sock, "screen_add E\n"); sock_send_string (sock, "screen_set E -name {Essential Clock Screen} -heartbeat off\n"); diff --git a/clients/lcdproc/chrono.h b/clients/lcdproc/chrono.h index 02c63b4..9d049d1 100644 --- a/clients/lcdproc/chrono.h +++ b/clients/lcdproc/chrono.h @@ -1,10 +1,18 @@ #ifndef CHRONO_H #define CHRONO_H +#ifdef LCDPROC_MENUS +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 essential_clock_screen (int rep, int display, int * flags_ptr); +#else int clock_screen (int rep, int display); int uptime_screen (int rep, int display); int time_screen (int rep, int display); int big_clock_screen (int rep, int display); int essential_clock_screen (int rep, int display); +#endif #endif diff --git a/clients/lcdproc/cpu.c b/clients/lcdproc/cpu.c index 3648ea9..13ad80c 100644 --- a/clients/lcdproc/cpu.c +++ b/clients/lcdproc/cpu.c @@ -29,11 +29,14 @@ // +--------------------+ // int +#ifdef LCDPROC_MENUS +cpu_screen(int rep, int display, int * flags_ptr) +#else cpu_screen(int rep, int display) +#endif { #undef CPU_BUF_SIZE #define CPU_BUF_SIZE 4 - static int first = TRUE; static double cpu[CPU_BUF_SIZE + 1][5]; // last buffer is scratch static int gauge_wid = 0; static int usni_wid = 0; @@ -41,9 +44,16 @@ cpu_screen(int rep, int display) int i, j, n; double value; load_type load; +#ifdef LCDPROC_MENUS + + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; if (first) { first = FALSE; +#endif sock_send_string(sock, "screen_add C\n"); sprintf(buffer, "screen_set C -name {CPU Use: %s}\n", get_hostname()); @@ -121,27 +131,27 @@ cpu_screen(int rep, int display) /* // Only clear on first display... - if(!rep){ - // Make all the same, if this is the first time... - for(i=0; i= 4) { // 4-line display + 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); @@ -208,11 +218,14 @@ cpu_screen(int rep, int display) // +--------------------+ // int +#ifdef LCDPROC_MENUS +cpu_graph_screen(int rep, int display, int * flags_ptr) +#else cpu_graph_screen(int rep, int display) +#endif { #undef CPU_BUF_SIZE #define CPU_BUF_SIZE 2 - static int first = TRUE; static double cpu[CPU_BUF_SIZE]; static int cpu_past[LCD_MAX_WIDTH]; static int gauge_hgt = 0; @@ -220,15 +233,22 @@ cpu_graph_screen(int rep, int display) int i, n = 0; double value ; load_type load; +#ifdef LCDPROC_MENUS + + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; if (first) { first = FALSE; +#endif 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); - if(lcd_hgt >= 4) { + 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()); } diff --git a/clients/lcdproc/cpu.h b/clients/lcdproc/cpu.h index 2b63313..6251c10 100644 --- a/clients/lcdproc/cpu.h +++ b/clients/lcdproc/cpu.h @@ -1,7 +1,12 @@ #ifndef CPU_H #define CPU_H +#ifdef LCDPROC_MENUS +int cpu_screen (int rep, int display, int * flags_ptr); +int cpu_graph_screen (int rep, int display, int * flags_ptr); +#else int cpu_screen (int rep, int display); int cpu_graph_screen (int rep, int display); +#endif #endif diff --git a/clients/lcdproc/cpu_smp.c b/clients/lcdproc/cpu_smp.c index 6b73b9c..abfcfa3 100644 --- a/clients/lcdproc/cpu_smp.c +++ b/clients/lcdproc/cpu_smp.c @@ -65,21 +65,31 @@ static char *numnames[MAX_CPUS] = { "one", "two", "three", "four", "five", "six" // CPU screen shows info about percentage of the CPU being used // int +#ifdef LCDPROC_MENUS +cpu_smp_screen (int rep, int display, int * flags_ptr) +#else cpu_smp_screen (int rep, int display) +#endif { #undef CPU_BUF_SIZE #define CPU_BUF_SIZE 4 int i, j, n, z; - static int first = 1; float value; static float cpu[MAX_CPUS][CPU_BUF_SIZE + 1][5]; // last buffer is scratch load_type load[MAX_CPUS]; int numprocs; char buf[256]; char *graphsize; +#ifdef LCDPROC_MENUS + + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; if (first) { - first = 0; + first = FALSE; +#endif machine_get_smpload (load, &numprocs); diff --git a/clients/lcdproc/cpu_smp.h b/clients/lcdproc/cpu_smp.h index bc1be17..313b2e3 100644 --- a/clients/lcdproc/cpu_smp.h +++ b/clients/lcdproc/cpu_smp.h @@ -1,6 +1,10 @@ #ifndef CPU_SMP_H #define CPU_SMP_H +#ifdef LCDPROC_MENUS +int cpu_smp_screen (int rep, int display, int * flags_ptr); +#else int cpu_smp_screen (int rep, int display); +#endif #endif diff --git a/clients/lcdproc/disk.c b/clients/lcdproc/disk.c index 3b49f5d..8962ad9 100644 --- a/clients/lcdproc/disk.c +++ b/clients/lcdproc/disk.c @@ -32,7 +32,11 @@ // // TODO: Disk screen! Requires virtual pages in the server, though... int +#ifdef LCDPROC_MENUS +disk_screen (int rep, int display, int * flags_ptr) +#else disk_screen (int rep, int display) +#endif { static mounts_type mnt[256]; static int count = 0; @@ -45,15 +49,21 @@ disk_screen (int rep, int display) } table[256]; int i; static int num_disks = 0; - static int first = 1; // First line to display, sort of. static int dev_wid = 6; static int gauge_wid = 6; #define huge long long int huge size; +#ifdef LCDPROC_MENUS + + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; if (first) { - first = 0; + first = FALSE; +#endif dev_wid = (lcd_wid >= 20) ? (lcd_wid - 8) / 2 : (lcd_wid / 2) - 1; gauge_wid = (lcd_wid >= 20) ? (lcd_wid - dev_wid - 10) : (lcd_wid - dev_wid - 3); diff --git a/clients/lcdproc/disk.h b/clients/lcdproc/disk.h index 8dc7552..d903eff 100644 --- a/clients/lcdproc/disk.h +++ b/clients/lcdproc/disk.h @@ -1,6 +1,10 @@ #ifndef DISK_H #define DISK_H +#ifdef LCDPROC_MENUS +int disk_screen (int rep, int display, int * flags_ptr); +#else int disk_screen (int rep, int display); +#endif #endif diff --git a/clients/lcdproc/load.c b/clients/lcdproc/load.c index 153b985..727ca1f 100644 --- a/clients/lcdproc/load.c +++ b/clients/lcdproc/load.c @@ -26,17 +26,27 @@ // +--------------------+ // int +#ifdef LCDPROC_MENUS +xload_screen (int rep, int display, int * flags_ptr) +#else xload_screen (int rep, int display) +#endif { - static int first = 1; static int gauge_hgt = 0; static double loads[LCD_MAX_WIDTH]; int loadtop, i; double loadmax = 0, factor; int status = 0; +#ifdef LCDPROC_MENUS - if (first) { // Only the first time this is ever called... - first = 0; + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; + + if (first) { + first = FALSE; +#endif gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt; memset (loads, '\0', sizeof (double) * LCD_MAX_WIDTH); diff --git a/clients/lcdproc/load.h b/clients/lcdproc/load.h index 5f5a08e..2563c28 100644 --- a/clients/lcdproc/load.h +++ b/clients/lcdproc/load.h @@ -8,6 +8,10 @@ #define LOAD_MIN 0.5 #endif +#ifdef LCDPROC_MENUS +int xload_screen (int rep, int display, int * flags_ptr); +#else int xload_screen (int rep, int display); +#endif #endif diff --git a/clients/lcdproc/machine_Darwin.c b/clients/lcdproc/machine_Darwin.c index c013f8d..81a901f 100644 --- a/clients/lcdproc/machine_Darwin.c +++ b/clients/lcdproc/machine_Darwin.c @@ -76,7 +76,7 @@ int machine_init() lcdproc_port = mach_host_self(); host_page_size(lcdproc_port, &pagesize); - while(pagesize > 1) + while (pagesize > 1) { pageshift++; pagesize >>= 1; @@ -108,10 +108,10 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent) if (CFArrayGetCount(sources) == 0) return(FALSE); - for(i = 0; i < CFArrayGetCount(sources); i++) + for (i = 0; i < CFArrayGetCount(sources); i++) { pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sources, i)); - if(!pSource) break; + if (!pSource) break; psValue = (CFStringRef)CFDictionaryGetValue(pSource, CFSTR(kIOPSNameKey)); @@ -179,14 +179,14 @@ int machine_get_fs(mounts_type fs[], int *cnt) int statcnt, fscnt, i; fscnt = getmntinfo(&mntbuf, MNT_WAIT); - if(fscnt == 0) + if (fscnt == 0) { perror("getmntinfo"); return(FALSE); } - for(statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) + for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) { - if( strcmp(pp->f_fstypename, "procfs") + if ( strcmp(pp->f_fstypename, "procfs") && strcmp(pp->f_fstypename, "kernfs") && strcmp(pp->f_fstypename, "linprocfs") #ifndef STAT_NFS @@ -202,7 +202,7 @@ int machine_get_fs(mounts_type fs[], int *cnt) snprintf(fs[statcnt].type, 255, "%s", pp->f_fstypename); fs[statcnt].blocks = pp->f_blocks; - if(fs[statcnt].blocks > 0) + if (fs[statcnt].blocks > 0) { fs[statcnt].bsize = pp->f_bsize; fs[statcnt].bfree = pp->f_bfree; @@ -240,7 +240,7 @@ int machine_get_load(load_type *curr_load) load.idle = (unsigned long) (load_info.cpu_ticks[CPU_STATE_IDLE]); load.total = load.user + load.nice + load.system + load.idle; - if(load.total != last_load.total) + if (load.total != last_load.total) { curr_load->user = load.user - last_load.user; curr_load->nice = load.nice - last_load.nice; @@ -263,7 +263,7 @@ int machine_get_loadavg(double *load) { double loadavg[1]; - if(getloadavg(loadavg, 1) == -1) + if (getloadavg(loadavg, 1) == -1) return(FALSE); *load = loadavg[0]; @@ -296,7 +296,7 @@ int machine_get_meminfo(meminfo_type *result) result[1].total = 0; result[1].free = 0; - if(swapmode(&total_pages, &free_pages) != -1) + if (swapmode(&total_pages, &free_pages) != -1) { result[1].total = total_pages; result[1].free = free_pages; @@ -324,7 +324,7 @@ int machine_get_procs(LinkedList *procs) return(FALSE); } - for(i = 0; i < nproc; i++) + for (i = 0; i < nproc; i++) { if (host_processor_set_priv(lcdproc_port, psets[i], &pset)) { @@ -333,7 +333,7 @@ int machine_get_procs(LinkedList *procs) } p = malloc(sizeof(procinfo_type)); - if(!p) + if (!p) { perror("mem_top_malloc"); return(FALSE); @@ -350,19 +350,19 @@ int machine_get_smpload(load_type *result, int *numcpus) load_type curr_load; size = sizeof(int); - if(sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0) + if (sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0) { perror("sysctl hw.ncpu"); return(FALSE); } - if(machine_get_load(&curr_load) == FALSE) + if (machine_get_load(&curr_load) == FALSE) return(FALSE); *numcpus = num; num = num > 8 ? 8 : num; /* Don't know how to get per-cpu-load values */ - for(i = 0; i < num; i++) + for (i = 0; i < num; i++) { result[i] = curr_load; } @@ -383,12 +383,12 @@ int machine_get_uptime(double *up, double *idle) size = sizeof(boottime); time(&now); - if(sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && + if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && boottime.tv_sec != 0) *up = (double)(now - boottime.tv_sec); - if(machine_get_load(&curr_load) == FALSE) + if (machine_get_load(&curr_load) == FALSE) *idle = 100.; else *idle = 100.*curr_load.idle/curr_load.total; diff --git a/clients/lcdproc/machine_FreeBSD.c b/clients/lcdproc/machine_FreeBSD.c index 3e0df13..63b4ea9 100644 --- a/clients/lcdproc/machine_FreeBSD.c +++ b/clients/lcdproc/machine_FreeBSD.c @@ -63,7 +63,7 @@ int machine_init() /* get the page size with "getpagesize" and calculate pageshift from it */ int pagesize = getpagesize(); pageshift = 0; - while(pagesize > 1) + while (pagesize > 1) { pageshift++; pagesize >>= 1; @@ -89,13 +89,13 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent) *battflag = LCDP_BATT_ABSENT; *percent = 100; - if((apmd = open("/dev/apm", O_RDONLY)) == -1) + if ((apmd = open("/dev/apm", O_RDONLY)) == -1) { perror("get_battstat_open"); return(TRUE); } - if(ioctl(apmd, APMIO_GETINFO, &aip) == -1) + if (ioctl(apmd, APMIO_GETINFO, &aip) == -1) { perror("get_battstat_ioctl"); return(FALSE); @@ -134,7 +134,7 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent) } *percent = aip.ai_batt_life; - if(*percent == 255) + if (*percent == 255) *percent = -1; close(apmd); @@ -149,14 +149,14 @@ int machine_get_fs(mounts_type fs[], int *cnt) int statcnt, fscnt, i; fscnt = getmntinfo(&mntbuf, MNT_WAIT); - if(fscnt == 0) + if (fscnt == 0) { perror("getmntinfo"); return(FALSE); } - for(statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) + for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) { - if( strcmp(pp->f_fstypename, "procfs") + if ( strcmp(pp->f_fstypename, "procfs") && strcmp(pp->f_fstypename, "kernfs") && strcmp(pp->f_fstypename, "linprocfs") #ifndef STAT_NFS @@ -172,7 +172,7 @@ int machine_get_fs(mounts_type fs[], int *cnt) snprintf(fs[statcnt].type, 255, "%s", pp->f_fstypename); fs[statcnt].blocks = pp->f_blocks; - if(fs[statcnt].blocks > 0) + if (fs[statcnt].blocks > 0) { fs[statcnt].bsize = pp->f_bsize; fs[statcnt].bfree = pp->f_bfree; @@ -197,7 +197,7 @@ int machine_get_load(load_type *curr_load) size_t size; size = sizeof(cp_time); - if(sysctlbyname("kern.cp_time", cp_time, &size, NULL, 0) < 0) + if (sysctlbyname("kern.cp_time", cp_time, &size, NULL, 0) < 0) { perror("sysctl kern.cp_time failed"); return(FALSE); @@ -209,7 +209,7 @@ int machine_get_load(load_type *curr_load) load.idle = (unsigned long) (cp_time[CP_IDLE]); load.total = load.user + load.nice + load.system + load.idle; - if(load.total != last_load.total) + if (load.total != last_load.total) { curr_load->user = load.user - last_load.user; curr_load->nice = load.nice - last_load.nice; @@ -231,7 +231,7 @@ int machine_get_loadavg(double *load) { double loadavg[1]; - if(getloadavg(loadavg, 1) == -1) + if (getloadavg(loadavg, 1) == -1) return(FALSE); *load = loadavg[0]; @@ -246,13 +246,13 @@ int machine_get_meminfo(meminfo_type *result) size = sizeof(int); - if(sysctlbyname("vm.stats.vm.v_page_count", &total_pages, &size, NULL, 0) < 0) + if (sysctlbyname("vm.stats.vm.v_page_count", &total_pages, &size, NULL, 0) < 0) { perror("sysctl vm.stats.vm.v_page_count"); return(FALSE); } - if(sysctlbyname("vm.stats.vm.v_free_count", &free_pages, &size, NULL, 0) < 0) + if (sysctlbyname("vm.stats.vm.v_free_count", &free_pages, &size, NULL, 0) < 0) { perror("sysctl vm.stats.vm.v_free_count"); return(FALSE); @@ -271,7 +271,7 @@ int machine_get_meminfo(meminfo_type *result) result[1].total = 0; result[1].free = 0; - if(swapmode(&total_pages, &free_pages) != -1) + if (swapmode(&total_pages, &free_pages) != -1) { result[1].total = total_pages; result[1].free = free_pages; @@ -287,24 +287,24 @@ int machine_get_procs(LinkedList *procs) procinfo_type *p; kvm_t *kvmd; - if((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) + if ((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) { perror("kvm_open"); return(FALSE); } kprocs = kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &nproc); - if(kprocs == NULL) + if (kprocs == NULL) { perror("kvm_getprocs"); kvm_close(kvmd); return(FALSE); } - for(i = 0; i < nproc; i++) + for (i = 0; i < nproc; i++) { p = malloc(sizeof(procinfo_type)); - if(!p) + if (!p) { perror("mem_top_malloc"); kvm_close(kvmd); @@ -340,19 +340,19 @@ int machine_get_smpload(load_type *result, int *numcpus) load_type curr_load; size = sizeof(int); - if(sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0) + if (sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0) { perror("sysctl hw.ncpu"); return(FALSE); } - if(machine_get_load(&curr_load) == FALSE) + if (machine_get_load(&curr_load) == FALSE) return(FALSE); *numcpus = num; num = num > 8 ? 8 : num; /* Don't know how to get per-cpu-load values */ - for(i = 0; i < num; i++) + for (i = 0; i < num; i++) { result[i] = curr_load; } @@ -369,7 +369,7 @@ int machine_get_uptime(double *up, double *idle) size = sizeof(boottime); time(&now); - if(sysctlbyname("kern.boottime", &boottime, &size, NULL, 0) < 0) + if (sysctlbyname("kern.boottime", &boottime, &size, NULL, 0) < 0) { perror("sysctl kern.cp_time failed"); return(FALSE); @@ -377,7 +377,7 @@ int machine_get_uptime(double *up, double *idle) *up = (double)(now - boottime.tv_sec); - if(machine_get_load(&curr_load) == FALSE) + if (machine_get_load(&curr_load) == FALSE) *idle = 100.; else *idle = 100.*curr_load.idle/curr_load.total; @@ -394,14 +394,14 @@ static int swapmode(int *retavail, int *retfree) *retavail = 0; *retfree = 0; - if((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) + if ((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) { perror("read kvm"); return(-1); } n = kvm_getswapinfo(kvmd, swapary, 1, 0); - if(n < 0 || swapary[0].ksw_total == 0) + if (n < 0 || swapary[0].ksw_total == 0) { /* strange */ } diff --git a/clients/lcdproc/machine_Linux.c b/clients/lcdproc/machine_Linux.c index 542b1dd..d82ff86 100644 --- a/clients/lcdproc/machine_Linux.c +++ b/clients/lcdproc/machine_Linux.c @@ -53,20 +53,20 @@ int machine_init() loadavg_fd = -1; meminfo_fd = -1; - if(uptime_fd == -1) + if (uptime_fd == -1) { uptime_fd = open("/proc/uptime", O_RDONLY); - if(uptime_fd < 0) + if (uptime_fd < 0) { perror("open /proc/uptime"); return(FALSE); } } - if(load_fd == -1) + if (load_fd == -1) { load_fd = open("/proc/stat", O_RDONLY); - if(load_fd < 0) + if (load_fd < 0) { perror("open /proc/stat"); return(FALSE); @@ -74,10 +74,10 @@ int machine_init() } #ifndef USE_GETLOADAVG - if(loadavg_fd == -1) + if (loadavg_fd == -1) { loadavg_fd = open("/proc/loadavg", O_RDONLY); - if(loadavg_fd < 0) + if (loadavg_fd < 0) { perror("open /proc/loadavg"); return(FALSE); @@ -85,20 +85,20 @@ int machine_init() } #endif - if(meminfo_fd == -1) + if (meminfo_fd == -1) { meminfo_fd = open("/proc/meminfo", O_RDONLY); - if(meminfo_fd < 0) + if (meminfo_fd < 0) { perror("open /proc/meminfo"); return(FALSE); } } - if(batt_fd == -1) + if (batt_fd == -1) { batt_fd = open("/proc/apm", O_RDONLY); - if(batt_fd < 0) + if (batt_fd < 0) { //perror("open /proc/apm"); batt_fd = -1; @@ -110,25 +110,25 @@ int machine_init() int machine_close() { - if(batt_fd != -1) + if (batt_fd != -1) close(batt_fd); batt_fd = -1; - if(load_fd != -1) + if (load_fd != -1) close(load_fd); load_fd = -1; #ifndef USE_GETLOADAVG - if(loadavg_fd != -1) + if (loadavg_fd != -1) close(loadavg_fd); loadavg_fd = -1; #endif - if(meminfo_fd != -1) + if (meminfo_fd != -1) close(meminfo_fd); meminfo_fd = -1; - if(uptime_fd != -1) + if (uptime_fd != -1) close(uptime_fd); uptime_fd = -1; @@ -170,7 +170,7 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent) char str[64]; int battstat; - if(batt_fd == -1) + if (batt_fd == -1) { *acstat = LCDP_AC_ON; *battflag = LCDP_BATT_ABSENT; @@ -178,28 +178,28 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent) return(TRUE); } - if(lseek(batt_fd, 0, 0) != 0) + if (lseek(batt_fd, 0, 0) != 0) return(FALSE); - if(read(batt_fd, str, sizeof(str) - 1) < 0) + if (read(batt_fd, str, sizeof(str) - 1) < 0) return(FALSE); - if(3 > sscanf(str + 13, "0x%x 0x%x 0x%x %d", acstat, &battstat, battflag, percent)) + if (3 > sscanf(str + 13, "0x%x 0x%x 0x%x %d", acstat, &battstat, battflag, percent)) return(FALSE); - if(*battflag == 0xff) + if (*battflag == 0xff) *battflag = LCDP_BATT_UNKNOWN; else { - if(*battflag & 1) + if (*battflag & 1) *battflag = LCDP_BATT_HIGH; - if(*battflag & 2) + if (*battflag & 2) *battflag = LCDP_BATT_LOW; - if(*battflag & 4) + if (*battflag & 4) *battflag = LCDP_BATT_CRITICAL; - if(*battflag & 8 || battstat == 3) + if (*battflag & 8 || battstat == 3) *battflag = LCDP_BATT_CHARGING; - if(*battflag & 128) + if (*battflag & 128) *battflag = LCDP_BATT_ABSENT; } @@ -241,9 +241,9 @@ int machine_get_fs(mounts_type fs[], int *cnt) // Get rid of old, unmounted filesystems... memset(fs, 0, sizeof(mounts_type) * 256); - while(x < 256) + while (x < 256) { - if(fgets(line, 256, mtab_fd) == NULL) + if (fgets(line, 256, mtab_fd) == NULL) { fclose (mtab_fd); *cnt = x; @@ -273,7 +273,7 @@ int machine_get_fs(mounts_type fs[], int *cnt) #endif fs[x].blocks = fsinfo.f_blocks; - if(fs[x].blocks > 0) + if (fs[x].blocks > 0) { fs[x].bsize = fsinfo.f_bsize; fs[x].bfree = fsinfo.f_bfree; @@ -313,7 +313,7 @@ int machine_get_loadavg(double *load) #ifdef USE_GETLOADAVG double loadavg[LOADAVG_NSTATS]; - if(getloadavg(loadavg, LOADAVG_NSTATS) < 0) + if (getloadavg(loadavg, LOADAVG_NSTATS) < 0) { perror("getloadavg"); *load = 1.; @@ -368,19 +368,19 @@ int machine_get_procs(LinkedList *procs) VmRSSLineLen = strlen(VmRSSLine); int threshold = 400, unique; - if((proc = opendir("/proc")) == NULL) + if ((proc = opendir("/proc")) == NULL) { perror("mem_top_screen: unable to open /proc"); return(FALSE); } - while((procdir = readdir(proc))) + while ((procdir = readdir(proc))) { - if(!index("1234567890", procdir->d_name[0])) + if (!index("1234567890", procdir->d_name[0])) continue; sprintf(buf, "/proc/%s/status", procdir->d_name); - if((StatusFile = fopen(buf, "r")) == NULL) + if ((StatusFile = fopen(buf, "r")) == NULL) { // Not a serious error; process has finished before we could // examine it: @@ -388,29 +388,29 @@ int machine_get_procs(LinkedList *procs) } procRSS = procSize = procData = procStk = procExe = 0; - while(fgets(buf, sizeof(buf), StatusFile)) + while (fgets(buf, sizeof(buf), StatusFile)) { - if(!strncmp(buf, NameLine, NameLineLen)) + if (!strncmp(buf, NameLine, NameLineLen)) { /* Name: procName */ sscanf(buf, "%*s %s", procName); - } else if(!strncmp(buf, VmSizeLine, VmSizeLineLen)) + } else if (!strncmp(buf, VmSizeLine, VmSizeLineLen)) { /* VmSize: procSize kB */ sscanf(buf, "%*s %d", &procSize); - } else if(!strncmp (buf, VmRSSLine, VmRSSLineLen)) + } else if (!strncmp (buf, VmRSSLine, VmRSSLineLen)) { /* VmRSS: procRSS kB */ sscanf(buf, "%*s %d", &procRSS); - } else if(!strncmp(buf, VmDataLine, VmDataLineLen)) + } else if (!strncmp(buf, VmDataLine, VmDataLineLen)) { /* VmData: procData kB */ sscanf(buf, "%*s %d", &procData); - } else if(!strncmp(buf, VmStkLine, VmStkLineLen)) + } else if (!strncmp(buf, VmStkLine, VmStkLineLen)) { /* VmStk: procStk kB */ sscanf(buf, "%*s %d", &procStk); - } else if(!strncmp(buf, VmExeLine, VmExeLineLen)) + } else if (!strncmp(buf, VmExeLine, VmExeLineLen)) { /* VmExe: procExe kB */ sscanf(buf, "%*s %d", &procExe); @@ -418,7 +418,7 @@ int machine_get_procs(LinkedList *procs) } fclose(StatusFile); - if(procSize > threshold) + if (procSize > threshold) { // Figure out if it's sharing any memory... unique = 1; @@ -426,22 +426,22 @@ int machine_get_procs(LinkedList *procs) do { p = LL_Get (procs); - if(p) + if (p) { - if(0 == strcmp(p->name, procName)) + if (0 == strcmp(p->name, procName)) { unique = 0; p->number++; p->totl += procData + procStk + procExe; } } - } while(LL_Next(procs) == 0); + } while (LL_Next(procs) == 0); // If this is the first one by this name... - if(unique) + if (unique) { p = malloc(sizeof(procinfo_type)); - if(!p) + if (!p) { perror("mem_top_screen: Error allocating process entry"); break; @@ -471,9 +471,9 @@ int machine_get_smpload(load_type *result, int *numcpus) // Look for lines starting with "cpu0", "cpu1", etc. token = strtok(procbuf, "\n"); - while(token) + while (token) { - if((strlen(token) > 3) && (!strncmp(token, "cpu", 3)) && isdigit(token[3])) + if ((strlen(token) > 3) && (!strncmp(token, "cpu", 3)) && isdigit(token[3])) { sscanf(token, "%*s %lu %lu %lu %lu", &curr_load[*numcpus].user, &curr_load[*numcpus].nice, &curr_load[*numcpus].system, &curr_load[*numcpus].idle); diff --git a/clients/lcdproc/machine_NetBSD.c b/clients/lcdproc/machine_NetBSD.c index 3a0044a..fd54760 100644 --- a/clients/lcdproc/machine_NetBSD.c +++ b/clients/lcdproc/machine_NetBSD.c @@ -71,7 +71,7 @@ int machine_init() /* get the page size with "getpagesize" and calculate pageshift from it */ int pagesize = getpagesize(); pageshift = 0; - while(pagesize > 1) + while (pagesize > 1) { pageshift++; pagesize >>= 1; @@ -93,7 +93,7 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent) int apmd; struct apm_power_info apmi; - if((apmd = open("/dev/apm", O_RDONLY)) == -1) + if ((apmd = open("/dev/apm", O_RDONLY)) == -1) { *acstat = LCDP_AC_ON; *battflag = LCDP_BATT_ABSENT; @@ -102,7 +102,7 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent) } memset(&apmi, 0, sizeof(apmi)); - if(ioctl(apmd, APM_IOC_GETPOWER, &apmi) == -1) + if (ioctl(apmd, APM_IOC_GETPOWER, &apmi) == -1) { perror("APM_IOC_GETPOWER failed in get_batt_stat()"); return(FALSE); @@ -144,14 +144,14 @@ int machine_get_fs(mounts_type fs[], int *cnt) int statcnt, fscnt, i; fscnt = getmntinfo(&mntbuf, MNT_WAIT); - if(fscnt == 0) + if (fscnt == 0) { perror("getmntinfo"); return(FALSE); } - for(statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) + for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) { - if(strcmp(pp->f_fstypename, "procfs") + if (strcmp(pp->f_fstypename, "procfs") && strcmp(pp->f_fstypename, "kernfs") && strcmp(pp->f_fstypename, "linprocfs") #ifndef STAT_NFS @@ -167,7 +167,7 @@ int machine_get_fs(mounts_type fs[], int *cnt) snprintf(fs[statcnt].type, 255, "%s", pp->f_fstypename); fs[statcnt].blocks = pp->f_blocks; - if(fs[statcnt].blocks > 0) + if (fs[statcnt].blocks > 0) { fs[statcnt].bsize = pp->f_bsize; fs[statcnt].bfree = pp->f_bfree; @@ -194,7 +194,7 @@ int machine_get_load(load_type *curr_load) mib[0] = CTL_KERN; mib[1] = KERN_CP_TIME; size = sizeof(cp_time); - if(sysctl(mib, 2, cp_time, &size, NULL, 0) < 0) + if (sysctl(mib, 2, cp_time, &size, NULL, 0) < 0) { perror("sysctl kern.cp_time failed"); return(FALSE); @@ -206,7 +206,7 @@ int machine_get_load(load_type *curr_load) load.idle = (unsigned long) (cp_time[CP_IDLE]); load.total = load.user + load.nice + load.system + load.idle; - if(load.total != last_load.total) + if (load.total != last_load.total) { curr_load->user = load.user - last_load.user; curr_load->nice = load.nice - last_load.nice; @@ -228,7 +228,7 @@ int machine_get_loadavg(double *load) { double loadavg[1]; - if(getloadavg(loadavg, 1) == -1) + if (getloadavg(loadavg, 1) == -1) return(FALSE); *load = loadavg[0]; @@ -245,7 +245,7 @@ int machine_get_meminfo(meminfo_type *result) mib[0] = CTL_VM; mib[1] = VM_UVMEXP2; size = sizeof(uvmexp); - if(sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) + if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) { perror("sysctl vm.uvmexp2 failed"); return(FALSE); @@ -276,23 +276,23 @@ int machine_get_procs(LinkedList *procs) procinfo_type *p; kprocs = NULL; - if((kvmd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, "kvm_open")) == NULL) + if ((kvmd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, "kvm_open")) == NULL) { perror("kvm_openfiles"); return(FALSE); } kprocs = kvm_getproc2(kvmd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), &nproc); - if(kprocs == NULL) + if (kprocs == NULL) { perror("kvm_getproc2"); return(FALSE); } - for(i = 0; i < nproc; i++) + for (i = 0; i < nproc; i++) { p = malloc(sizeof(procinfo_type)); - if(!p) + if (!p) { perror("mem_top_malloc"); kvm_close(kvmd); @@ -322,19 +322,19 @@ int machine_get_smpload(load_type *result, int *numcpus) mib[1] = HW_NCPU; size = sizeof(int); - if(sysctl(mib, 2, &num, &size, NULL, 0) < 0) + if (sysctl(mib, 2, &num, &size, NULL, 0) < 0) { perror("sysctl hw.ncpu"); return(FALSE); } - if(machine_get_load(&curr_load) == FALSE) + if (machine_get_load(&curr_load) == FALSE) return(FALSE); *numcpus = num; num = num > 8 ? 8 : num; /* Don't know how to get per-cpu-load values */ - for(i = 0; i < num; i++) + for (i = 0; i < num; i++) { result[i] = curr_load; } @@ -354,7 +354,7 @@ int machine_get_uptime(double *up, double *idle) mib[1] = KERN_BOOTTIME; size = sizeof(boottime); time(&now); - if(sysctl(mib, 2, &boottime, &size, NULL, 0) < 0) + if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0) { perror("sysctl kern.boottime failed"); return(FALSE); @@ -362,7 +362,7 @@ int machine_get_uptime(double *up, double *idle) *up = (double)(now - boottime.tv_sec); - if(machine_get_load(&curr_load) == FALSE) + if (machine_get_load(&curr_load) == FALSE) *idle = 100.; else *idle = 100.*curr_load.idle/curr_load.total; diff --git a/clients/lcdproc/machine_OpenBSD.c b/clients/lcdproc/machine_OpenBSD.c index 47f9027..6c60435 100644 --- a/clients/lcdproc/machine_OpenBSD.c +++ b/clients/lcdproc/machine_OpenBSD.c @@ -65,7 +65,7 @@ int machine_init() /* get the page size with "getpagesize" and calculate pageshift from it */ int pagesize = getpagesize(); pageshift = 0; - while(pagesize > 1) + while (pagesize > 1) { pageshift++; pagesize >>= 1; @@ -91,13 +91,13 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent) *battflag = LCDP_BATT_ABSENT; *percent = 100; - if((apmd = open("/dev/apm", O_RDONLY)) == -1) + if ((apmd = open("/dev/apm", O_RDONLY)) == -1) { perror("get_battstat_open"); return(TRUE); } - if(ioctl(apmd, APM_IOC_GETPOWER, &api) == -1) + if (ioctl(apmd, APM_IOC_GETPOWER, &api) == -1) { perror("get_battstat_ioctl"); return(FALSE); @@ -152,14 +152,14 @@ int machine_get_fs(mounts_type fs[], int *cnt) int statcnt, fscnt, i; fscnt = getmntinfo(&mntbuf, MNT_WAIT); - if(fscnt == 0) + if (fscnt == 0) { perror("getmntinfo"); return(FALSE); } - for(statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) + for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) { - if(strcmp(pp->f_fstypename, "procfs") + if (strcmp(pp->f_fstypename, "procfs") && strcmp(pp->f_fstypename, "kernfs") && strcmp(pp->f_fstypename, "linprocfs") #ifndef STAT_NFS @@ -175,7 +175,7 @@ int machine_get_fs(mounts_type fs[], int *cnt) snprintf(fs[statcnt].type, 255, "%s", pp->f_fstypename); fs[statcnt].blocks = pp->f_blocks; - if(fs[statcnt].blocks > 0) + if (fs[statcnt].blocks > 0) { fs[statcnt].bsize = pp->f_bsize; fs[statcnt].bfree = pp->f_bfree; @@ -202,7 +202,7 @@ int machine_get_load(load_type *curr_load) mib[0] = CTL_KERN; mib[1] = KERN_CPTIME; size = sizeof(cp_time); - if(sysctl(mib, 2, cp_time, &size, NULL, 0) < 0) + if (sysctl(mib, 2, cp_time, &size, NULL, 0) < 0) { perror("sysctl kern.cp_time failed"); return(FALSE); @@ -214,7 +214,7 @@ int machine_get_load(load_type *curr_load) load.idle = (unsigned long) (cp_time[CP_IDLE]); load.total = load.user + load.nice + load.system + load.idle; - if(load.total != last_load.total) + if (load.total != last_load.total) { curr_load->user = load.user - last_load.user; curr_load->nice = load.nice - last_load.nice; @@ -236,7 +236,7 @@ int machine_get_loadavg(double *load) { double loadavg[1]; - if(getloadavg(loadavg, 1) == -1) + if (getloadavg(loadavg, 1) == -1) return(FALSE); *load = loadavg[0]; @@ -254,7 +254,7 @@ int machine_get_meminfo(meminfo_type *result) mib[1] = VM_UVMEXP; size = sizeof(suvm); - if(sysctl(mib, 2, &suvm, &size, NULL, 0) < 0) + if (sysctl(mib, 2, &suvm, &size, NULL, 0) < 0) { perror("sysctl vm.uvmexp failed"); return(FALSE); @@ -284,24 +284,24 @@ int machine_get_procs(LinkedList *procs) procinfo_type *p; kvm_t *kvmd; - if((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) + if ((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) { perror("kvm_open"); return(FALSE); } kprocs = kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &nproc); - if(kprocs == NULL) + if (kprocs == NULL) { perror("kvm_getprocs"); kvm_close(kvmd); return(FALSE); } - for(i = 0; i < nproc; i++) + for (i = 0; i < nproc; i++) { p = malloc(sizeof(procinfo_type)); - if(!p) + if (!p) { perror("mem_top_malloc"); kvm_close(kvmd); @@ -330,19 +330,19 @@ int machine_get_smpload(load_type *result, int *numcpus) mib[1] = HW_NCPU; size = sizeof(int); - if(sysctl(mib, 2, &num, &size, NULL, 0) < 0) + if (sysctl(mib, 2, &num, &size, NULL, 0) < 0) { perror("sysctl hw.ncpu"); return(FALSE); } - if(machine_get_load(&curr_load) == FALSE) + if (machine_get_load(&curr_load) == FALSE) return(FALSE); *numcpus = num; num = num > 8 ? 8 : num; /* Don't know how to get per-cpu-load values */ - for(i = 0; i < num; i++) + for (i = 0; i < num; i++) { result[i] = curr_load; } @@ -362,7 +362,7 @@ int machine_get_uptime(double *up, double *idle) mib[1] = KERN_BOOTTIME; size = sizeof(boottime); time(&now); - if(sysctl(mib, 2, &boottime, &size, NULL, 0) < 0) + if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0) { perror("sysctl kern.boottime failed"); return(FALSE); @@ -370,7 +370,7 @@ int machine_get_uptime(double *up, double *idle) *up = (double)(now - boottime.tv_sec); - if(machine_get_load(&curr_load) == FALSE) + if (machine_get_load(&curr_load) == FALSE) *idle = 100.; else *idle = 100.*curr_load.idle/curr_load.total; diff --git a/clients/lcdproc/machine_SunOS.c b/clients/lcdproc/machine_SunOS.c index 5293e25..bd83d45 100644 --- a/clients/lcdproc/machine_SunOS.c +++ b/clients/lcdproc/machine_SunOS.c @@ -37,7 +37,7 @@ int machine_init() kc = NULL; kc = kstat_open(); - if(kc == NULL) + if (kc == NULL) { perror("kstat_open"); return(FALSE); @@ -48,7 +48,7 @@ int machine_init() int machine_close() { - if(kc != NULL) + if (kc != NULL) { kstat_close(kc); kc = NULL; @@ -87,9 +87,9 @@ int machine_get_fs(mounts_type fs[], int *cnt) // Get rid of old, unmounted filesystems... memset(fs, 0, sizeof(mounts_type) * 256); - while(x < 256) + while (x < 256) { - if(fgets(line, 256, mtab_fd) == NULL) + if (fgets(line, 256, mtab_fd) == NULL) { fclose(mtab_fd); *cnt = x; @@ -98,7 +98,7 @@ int machine_get_fs(mounts_type fs[], int *cnt) sscanf(line, "%s %s %s", fs[x].dev, fs[x].mpoint, fs[x].type); - if( strcmp(fs[x].type, "proc") + if ( strcmp(fs[x].type, "proc") #ifndef STAT_NFS && strcmp(fs[x].type, "nfs") #endif @@ -118,7 +118,7 @@ int machine_get_fs(mounts_type fs[], int *cnt) #endif fs[x].blocks = fsinfo.f_blocks; - if(fs[x].blocks > 0) + if (fs[x].blocks > 0) { fs[x].bsize = fsinfo.f_bsize; fs[x].bfree = fsinfo.f_bfree; @@ -144,25 +144,25 @@ int machine_get_load(load_type *curr_load) struct cpu_stat cinfo; k_space = kstat_lookup(kc, "cpu_stat", 0, "cpu_stat0"); - if(k_space == NULL) + if (k_space == NULL) { fprintf(stderr, "kstat lookup error\n"); return(FALSE); } - if(kstat_read(kc, k_space, NULL) == -1) + if (kstat_read(kc, k_space, NULL) == -1) { fprintf(stderr, "kstat read error\n"); return(FALSE); } k_space = kstat_lookup(kc, "cpu_stat", -1, "cpu_stat0"); - if(k_space == NULL) + if (k_space == NULL) { fprintf(stderr, "kstat lookup error\n"); return(FALSE); } - if(kstat_read(kc, k_space, &cinfo) == -1) + if (kstat_read(kc, k_space, &cinfo) == -1) { fprintf(stderr, "kstat read error\n"); return(FALSE); @@ -173,7 +173,7 @@ int machine_get_load(load_type *curr_load) load.nice = cinfo.cpu_sysinfo.cpu[CPU_WAIT]; load.total = load.user + load.nice + load.system + load.idle; - if(load.total != last_load.total) + if (load.total != last_load.total) { curr_load->user = load.user - last_load.user; curr_load->nice = load.nice - last_load.nice; @@ -195,7 +195,7 @@ int machine_get_loadavg(double *load) { double loadavg[1]; - if(getloadavg(loadavg, 1) == -1) + if (getloadavg(loadavg, 1) == -1) return(FALSE); *load = loadavg[0]; @@ -219,47 +219,47 @@ int machine_get_meminfo(meminfo_type *result) result[0].cache = 0; again: - if((num = swapctl(SC_GETNSWP, 0)) == -1) + if ((num = swapctl(SC_GETNSWP, 0)) == -1) { perror("swapctl: GETNSWP"); return(FALSE); } - if(num == 0) + if (num == 0) { fprintf(stderr, "No Swap Devices Configured\n"); return(FALSE); } /* allocate swaptable for num+1 entries */ - if((s = (swaptbl_t*)malloc(num * sizeof(swapent_t) + sizeof(struct swaptable))) == NULL) + if ((s = (swaptbl_t*)malloc(num * sizeof(swapent_t) + sizeof(struct swaptable))) == NULL) { perror("malloc swap"); return(FALSE); } /* allocate num+1 string holders */ - if((strtab = (char*)malloc((num + 1) * MAXSTRSIZE)) == NULL) + if ((strtab = (char*)malloc((num + 1) * MAXSTRSIZE)) == NULL) { perror("malloc string holder"); return(FALSE); } /* initialize string pointers */ - for(i = 0; i < (num + 1); i++) + for (i = 0; i < (num + 1); i++) { s->swt_ent[i].ste_path = strtab + (i * MAXSTRSIZE); } s->swt_n = num + 1; - if((n = swapctl(SC_LIST, s)) < 0) + if ((n = swapctl(SC_LIST, s)) < 0) { perror("swapctl"); return(FALSE); } /* more were added */ - if(n > num) + if (n > num) { free(s); free(strtab); @@ -269,7 +269,7 @@ again: result[1].total = 0; result[1].free = 0; - for(i = 0; i < n; i++) + for (i = 0; i < n; i++) { result[1].total = result[1].total + s->swt_ent[i].ste_pages * sysconf(_SC_PAGESIZE) / 1024; result[1].free = result[1].free + s->swt_ent[i].ste_free * sysconf(_SC_PAGESIZE) / 1024; @@ -290,21 +290,21 @@ int machine_get_procs(LinkedList *procs) int procSize, procRSS, procData, procStk, procExe; int threshold = 400, unique; - if((proc = opendir("/proc")) == NULL) + if ((proc = opendir("/proc")) == NULL) { perror("open /proc"); return(FALSE); } - while((procdir = readdir(proc))) + while ((procdir = readdir(proc))) { psinfo_t psinfo; - if(!index("1234567890", procdir->d_name[0])) + if (!index("1234567890", procdir->d_name[0])) continue; sprintf(buf, "/proc/%s/psinfo", procdir->d_name); - if((StatusFile = fopen(buf, "r")) == NULL) + if ((StatusFile = fopen(buf, "r")) == NULL) { // Not a serious error; process has finished before we could // examine it: @@ -324,7 +324,7 @@ int machine_get_procs(LinkedList *procs) fclose(StatusFile); - if(procSize > threshold) + if (procSize > threshold) { // Figure out if it's sharing any memory... unique = 1; @@ -332,22 +332,22 @@ int machine_get_procs(LinkedList *procs) do { p = LL_Get(procs); - if(p) + if (p) { - if(0 == strcmp(p->name, procName)) + if (0 == strcmp(p->name, procName)) { unique = 0; p->number++; p->totl += procData + procStk + procExe; } } - }while(LL_Next(procs) == 0); + } while (LL_Next(procs) == 0); // If this is the first one by this name... - if(unique) + if (unique) { p = malloc(sizeof(procinfo_type)); - if(p == NULL) + if (p == NULL) { perror("allocating process entry"); goto end; // Ack! I hate goto's! @@ -376,12 +376,12 @@ int machine_get_smpload(load_type *result, int *numcpus) char buffer[16]; *numcpus = sysconf(_SC_NPROCESSORS_CONF); - for(count = 0; count < MAX_CPUS; count++) + for (count = 0; count < MAX_CPUS; count++) { sprintf(buffer, "cpu_stat%d", count); k_space = kstat_lookup(kc, "cpu_stat", count, buffer); - if((k_space != NULL) && (kstat_read(kc, k_space, NULL) != -1)) + if ((k_space != NULL) && (kstat_read(kc, k_space, NULL) != -1)) { struct cpu_stat cinfo; @@ -426,12 +426,12 @@ int machine_get_uptime(double *up, double *idle) id.ut_type = BOOT_TIME; u = getutxid(&id); - if(u == NULL) + if (u == NULL) return(FALSE); *up = time(0) - u->ut_xtime; - if(machine_get_load(&curr_load) == FALSE) + if (machine_get_load(&curr_load) == FALSE) *idle = 100.; else *idle = 100.*curr_load.idle/curr_load.total; diff --git a/clients/lcdproc/main.c b/clients/lcdproc/main.c index d492474..5b01e43 100644 --- a/clients/lcdproc/main.c +++ b/clients/lcdproc/main.c @@ -45,25 +45,37 @@ static void HelpScreen(); static void exit_program(int val); static void main_loop(); -static mode *sequence = NULL; static int islow = -1; // 1/8th second is a single time unit... #define TIME_UNIT 125000 /* list of modes to run */ -static mode default_sequence[] = +#ifdef LCDPROC_MENUS +mode sequence[] = { - // longname which on off inv timer visible + // flags default ACTIVE will run by default + // longname which on off inv timer flags + { "CPU", 'C', 1, 2, 0, 0xffff, ACTIVE,}, // [C]PU + { "Memory", 'M', 4, 16, 0, 0xffff, ACTIVE,}, // [M]emory + { "Load", 'X', 64, 128, 1, 0xffff, ACTIVE,}, // [X]-load (load histogram) + { "TimeDate", 'T', 4, 64, 0, 0xffff, ACTIVE,}, // [T]ime/Date + { "About", 'A', 999, 9999, 0, 0xffff, ACTIVE,}, // [A]bout (credits) +#else +mode *sequence = NULL; + +mode default_sequence[] = +{ + // longname which on off inv timer visible/flags { "CPU", 'C', 1, 2, 0, 0xffff, 0,}, // [C]PU { "Memory", 'M', 4, 16, 0, 0xffff, 0,}, // [M]emory { "Load", 'X', 64, 128, 1, 0xffff, 0,}, // [X]-load (load histogram) { "TimeDate", 'T', 4, 64, 0, 0xffff, 0,}, // [T]ime/Date { "About", 'A', 999, 9999, 0, 0xffff, 0,}, // [A]bout (credits) - { NULL, 1, 0, 0, 0, 0, 0,}, // Modes after this line will not be run by default... // ... all non-default modes must be in here! // ... they will not show up otherwise. +#endif { "SMP-CPU", 'P', 1, 2, 0, 0xffff, 0,}, // CPU_SM[P] { "OldTime", 'O', 4, 64, 0, 0xffff, 0,}, // [O]ld Timescreen { "BigClock", 'K', 4, 64, 0, 0xffff, 0,}, // big cloc[K] @@ -76,6 +88,13 @@ static mode default_sequence[] = { NULL, 0, 0, 0, 0, 0,}, // No more.. all done. }; +#ifdef LCDPROC_MENUS +int seqlen = sizeof(sequence) / sizeof(mode); +#else +int seqlen = sizeof(default_sequence) / sizeof(mode); +#endif //LCDPROC_MENUS + + // TODO: Config file; not just command line const char *get_hostname() @@ -93,6 +112,38 @@ const char *get_sysrelease() return(unamebuf.release); } +#ifdef LCDPROC_MENUS //set_mode function +int set_mode(int shortname, char * longname, int state) +{ + int k; + + /* ignore already selected modes */ + for (k = 0; (k < seqlen) && (sequence[k].which != 0); k++) { + if (((sequence[k].longname != NULL) && + (0 == strcasecmp(longname, sequence[k].longname))) || + (shortname == sequence[k].which)) { + if (!state) { + sequence[k].flags &= (~ACTIVE & ~INITIALIZED); /* both the active and inititialized bits */ + sprintf (buffer, "screen_del %c\n", shortname ); + sock_send_string (sock, buffer); + } else + sequence[k].flags |= ACTIVE; + return 1; //found + } + } + return 0; //not found +} + +void clear_modes() +{ + int k; + /* ignore already selected modes */ + for (k = 0; (k < seqlen) && (sequence[k].which != 0); k++) { + sequence[k].flags &= (~ACTIVE); + } +} +#endif //LCDPROC_MENUS + int main(int argc, char **argv) { @@ -101,8 +152,6 @@ main(int argc, char **argv) char *server = NULL; int port = LCDPORT; int daemonize = FALSE; - /* determine length of default_sequence[] */ - int seqlen = sizeof(default_sequence) / sizeof(mode); /* get uname information */ if (uname(&unamebuf) == -1) { @@ -110,6 +159,9 @@ main(int argc, char **argv) return(EXIT_FAILURE); } +#ifdef LCDPROC_MENUS +// sequence = default_sequence; +#else /* allocate sequence */ sequence = (mode *) malloc(seqlen * sizeof(mode)); if (sequence == NULL) { @@ -122,6 +174,7 @@ main(int argc, char **argv) //sequence[i] = default_sequence[i]; memcpy(&sequence[i], &default_sequence[i], sizeof(mode)); } +#endif //LCDPROC_MENUS /* setup error handlers */ signal(SIGINT, exit_program); // Ctrl-C @@ -164,6 +217,14 @@ main(int argc, char **argv) } } +#ifdef LCDPROC_MENUS + /* parse arguments */ + if (argc > 1 ) //user specified some modes, so clear all defaults + clear_modes(); + for (i = (optind > 0) ? optind : 1; i < argc; i++) { + int shortname = (strlen(argv[i]) == 1) ? toupper(argv[i][0]) : '\0'; + int found = set_mode(shortname, argv[i], 1); +#else /* parse arguments */ for (i = (optind > 0) ? optind : 1, j = 0; i < argc; i++) { int shortname = (strlen(argv[i]) == 1) ? toupper(argv[i][0]) : '\0'; @@ -186,7 +247,7 @@ main(int argc, char **argv) continue; } - /* try to find the mode from the mode list */ + // try to find the mode from the mode list for (k = 0; k < seqlen; k++) { if (((default_sequence[k].longname != NULL) && (0 == strcasecmp(argv[i], default_sequence[k].longname))) || @@ -200,7 +261,7 @@ main(int argc, char **argv) break; } } - +#endif if (!found) { fprintf(stderr, "Invalid Mode: %c, ignoring\n", argv[i][0]); return(EXIT_FAILURE); @@ -255,7 +316,7 @@ HelpScreen () printf("Usage: lcdproc [-s server] [-p port] [-e islow] [-d] [modelist]\n"); printf("\tOptions in []'s are optional.\n"); printf("\tmodelist is \"mode [mode mode ...]\"\n"); - printf("\tMode letters: \t[C]pu [G]raph [T]ime [M]emory [X]load [D]isk [B]attery\n" + printf ("\tMode letters:\t[C]pu [G]raph [T]ime [M]emory [X]load [D]isk [B]attery\n" "\t\t\tproc_[S]izes [O]ld_time big_cloc[K] [E]ssential_clock\n" "\t\t\t[U]ptime CPU_SM[P] [A]bout\n"); printf("\n"); @@ -273,13 +334,63 @@ HelpScreen () void exit_program(int val) { + //printf("exit program\n"); Quit = 1; sock_close(sock); mode_close(); +#ifndef LCDPROC_MENUS free(sequence); +#endif exit(val); } +#ifdef LCDPROC_MENUS //menus_init +int +menus_init () +{ + int k; + + for (k = 0; sequence[k].which ; k++) { + if (sequence[k].longname) { + sprintf (buffer, "menu_add_item {} %c checkbox {%s} -value %s\n", sequence[k].which, sequence[k].longname, sequence[k].flags & ACTIVE ? "on" : "off"); + sock_send_string (sock, buffer); + } + } + +#ifdef TESTMENUS +// # to be entered on escape from test_menu (but overwritten +// # for test_{checkbox,ring} + sock_send_string (sock, "menu_add_item {} ask menu {Leave menus?} -is_hidden true\n"); + sock_send_string (sock, "menu_add_item {ask} ask_yes action {Yes} -next _quit_\n"); + sock_send_string (sock, "menu_add_item {ask} ask_no action {No} -next _close_\n"); + sock_send_string (sock, "menu_add_item {} test menu {Test}\n"); + sock_send_string (sock, "menu_add_item {test} test_action action {Action}\n"); + sock_send_string (sock, "menu_add_item {test} test_checkbox checkbox {Checkbox}\n"); + sock_send_string (sock, "menu_add_item {test} test_ring ring {Ring} -strings {one\ttwo\tthree}\n"); + sock_send_string (sock, "menu_add_item {test} test_slider slider {Slider} -mintext < -maxtext > -value 50\n"); + sock_send_string (sock, "menu_add_item {test} test_numeric numeric {Numeric} -value 42\n"); + sock_send_string (sock, "menu_add_item {test} test_alpha alpha {Alpha} -value abc\n"); + sock_send_string (sock, "menu_add_item {test} test_ip ip {IP} -v6 false -value 192.168.1.1\n"); + sock_send_string (sock, "menu_add_item {test} test_menu menu {Menu}\n"); + sock_send_string (sock, "menu_add_item {test_menu} test_menu_action action {Submenu's action}\n"); + +// # no successor for menus. Since test_checkbox and test_ring have their +// # own predecessors defined the "ask" rule will not work for them + sock_send_string (sock, "menu_set_item {} test -prev {ask}\n"); + + sock_send_string (sock, "menu_set_item {test} test_action -next {test_checkbox}\n"); + sock_send_string (sock, "menu_set_item {test} test_checkbox -next {test_ring} -prev test_action\n"); + sock_send_string (sock, "menu_set_item {test} test_ring -next {test_slider} -prev {test_checkbox}\n"); + sock_send_string (sock, "menu_set_item {test} test_slider -next {test_numeric} -prev {test_ring}\n"); + sock_send_string (sock, "menu_set_item {test} test_numeric -next {test_alpha} -prev {test_slider}\n"); + sock_send_string (sock, "menu_set_item {test} test_alpha -next {test_ip} -prev {test_numeric}\n"); + sock_send_string (sock, "menu_set_item {test} test_ip -next {test_menu} -prev {test_alpha}\n"); + sock_send_string (sock, "menu_set_item {test} test_menu_action -next {_close_}\n"); +#endif //TESTMENUS + + return 0; +} +#endif //LCDPROC_MENUS /////////////////////////////////////////////////////////////////// // Main program loop... // @@ -304,7 +415,7 @@ main_loop() while (len > 0) { // Now split the string into tokens... - //for(i=0; i 1; i++) + for (i = 0; sequence[i].which > 0; i++) { sequence[i].timer++; +#ifdef LCDPROC_MENUS + if ((sequence[i].flags & ACTIVE) == 0 ) + continue; + if (sequence[i].flags & VISIBLE) +#else if (sequence[i].visible) +#endif { if (sequence[i].timer >= sequence[i].on_time) { diff --git a/clients/lcdproc/main.h b/clients/lcdproc/main.h index 6caafb2..cfb4dab 100644 --- a/clients/lcdproc/main.h +++ b/clients/lcdproc/main.h @@ -38,8 +38,16 @@ typedef struct mode int off_time; // How often to get stats while not visible? int show_invisible; // Send stats while not visible? int timer; // Time since last update +#ifdef LCDPROC_MENUS //struct mode flags + int flags; //bit 1 visible, bit 2 selected for display, bit 3 first +#else int visible; // Can we be seen right now? +#endif //LCDPROC_MENUS } mode; +//mode flags +#define VISIBLE 0x00000001 //currently visible +#define ACTIVE 0x00000002 //selected for display +#define INITIALIZED 0x00000004 //replaces the first variable to indicate whether the update screens are initialized #define BLINK_ON 0x10 #define BLINK_OFF 0x11 diff --git a/clients/lcdproc/mem.c b/clients/lcdproc/mem.c index 5c88888..6e958d8 100644 --- a/clients/lcdproc/mem.c +++ b/clients/lcdproc/mem.c @@ -29,16 +29,26 @@ // +--------------------+ // int +#ifdef LCDPROC_MENUS +mem_screen (int rep, int display, int * flags_ptr) +#else mem_screen (int rep, int display) +#endif { - static int first = 1; static int which_title = 0; static int gauge_wid = 0; static int gauge_offs = 0; meminfo_type mem[2]; +#ifdef LCDPROC_MENUS + + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; if (first) { - first = 0; + first = FALSE; +#endif sock_send_string(sock, "screen_add M\n"); sprintf(buffer, "screen_set M -name {Memory & Swap: %s}\n", get_hostname()); @@ -136,7 +146,7 @@ mem_screen (int rep, int display) double value = 1.0 - (double) (mem[0].free + mem[0].buffers + mem[0].cache) / (double) mem[0].total; - // printf(".0f", val) only prints the integer part + //printf(".0f", val) only prints the integer part sprintf(buffer, "widget_set M memgauge 2 4 %.0f\n", lcd_cellwid * gauge_wid * value); if (display) @@ -147,7 +157,7 @@ mem_screen (int rep, int display) 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 sprintf(buffer, "widget_set M swapgauge %i 4 %.0f\n", lcd_wid - gauge_wid, lcd_cellwid * gauge_wid * value); if (display) @@ -175,7 +185,7 @@ mem_screen (int rep, int display) / (double) mem[0].total; if (gauge_wid > 0) { - // printf(".0f", val) only prints the integer part + //printf(".0f", val) only prints the integer part sprintf(buffer, "widget_set M memgauge %i 1 %.0f\n", gauge_offs, lcd_cellwid * gauge_wid * value); if (display) @@ -194,7 +204,7 @@ mem_screen (int rep, int display) 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 sprintf(buffer, "widget_set M swapgauge %i 2 %.0f\n", gauge_offs, lcd_cellwid * gauge_wid * value); if (display) @@ -238,14 +248,24 @@ sort_procs (void *a, void *b) // +--------------------+ // int +#ifdef LCDPROC_MENUS +mem_top_screen (int rep, int display, int * flags_ptr) +#else mem_top_screen (int rep, int display) +#endif { - static int first = 1; LinkedList *procs; int i; +#ifdef LCDPROC_MENUS + + if ((*flags_ptr & INITIALIZED) == 0) { + *flags_ptr |= INITIALIZED; +#else + static int first = TRUE; if (first) { - first = 0; + first = FALSE; +#endif sock_send_string(sock, "screen_add S\n"); sprintf(buffer, "screen_set S -name {Top Memory Use: %s}\n", get_hostname()); @@ -297,8 +317,8 @@ mem_top_screen (int rep, int display) if (display) sock_send_string(sock, buffer); } else { - // printf("Mem hog: none?\n"); - // sprintf(buffer, "widget_set S %i 1 %i {}\n", i, i); + //printf("Mem hog: none?\n"); + //sprintf(buffer, "widget_set S %i 1 %i {}\n", i, i); sprintf(buffer, "widget_set S %i 1 %i { }\n", i, i); if (display) sock_send_string(sock, buffer); diff --git a/clients/lcdproc/mem.h b/clients/lcdproc/mem.h index a3202d3..bb8b6de 100644 --- a/clients/lcdproc/mem.h +++ b/clients/lcdproc/mem.h @@ -1,7 +1,12 @@ #ifndef MEM_H #define MEM_H +#ifdef LCDPROC_MENUS +int mem_screen (int rep, int display, int * flags_ptr); +int mem_top_screen (int rep, int display, int * flags_ptr); +#else int mem_screen (int rep, int display); int mem_top_screen (int rep, int display); +#endif #endif diff --git a/clients/lcdproc/mode.c b/clients/lcdproc/mode.c index eca0f2c..4dbf0b7 100644 --- a/clients/lcdproc/mode.c +++ b/clients/lcdproc/mode.c @@ -36,13 +36,13 @@ char *buffer = NULL; int mode_init() { - if((buffer = malloc(1024)) == NULL) + if ((buffer = malloc(1024)) == NULL) { perror("malloc buffer"); return(0); } - if((tmp = malloc(1024)) == NULL) + if ((tmp = malloc(1024)) == NULL) { perror("malloc tmp"); return(0); @@ -58,13 +58,13 @@ mode_close() { machine_close(); - if(tmp != NULL) + if (tmp != NULL) { free(tmp); tmp = NULL; } - if(buffer != NULL) + if (buffer != NULL) { free(buffer); buffer = NULL; @@ -77,10 +77,68 @@ update_screen(mode *m, int display) static int status = -1; int old_status = status; - if(m) + if (m) { switch(m->which) { +#ifdef LCDPROC_MENUS + case 'g': + case 'G': + status = cpu_graph_screen(m->timer, display, &(m->flags)); + break; + case 'c': + case 'C': + status = cpu_screen(m->timer, display, &(m->flags)); + break; + case 'o': + case 'O': + status = clock_screen(m->timer, display, &(m->flags)); + break; + case 'k': + case 'K': + status = big_clock_screen(m->timer, display, &(m->flags)); + break; + case 'm': + case 'M': + status = mem_screen(m->timer, display, &(m->flags)); + break; + case 's': + case 'S': + status = mem_top_screen(m->timer, display, &(m->flags)); + break; + case 'u': + case 'U': + status = uptime_screen(m->timer, display, &(m->flags)); + break; + case 't': + case 'T': + status = time_screen(m->timer, display, &(m->flags)); + break; + case 'd': + case 'D': + status = disk_screen(m->timer, display, &(m->flags)); + break; + case 'x': + case 'X': + status = xload_screen(m->timer, display, &(m->flags)); + break; + case 'b': + case 'B': + status = battery_screen(m->timer, display, &(m->flags)); + break; + case 'a': + case 'A': + status = credit_screen(m->timer, display, &(m->flags)); + break; + case 'p': + case 'P': + status = cpu_smp_screen(m->timer, display, &(m->flags)); + break; + case 'e': + case 'E': + status = essential_clock_screen(m->timer, display, &(m->flags)); + break; +#else case 'g': case 'G': status = cpu_graph_screen(m->timer, display); @@ -137,18 +195,19 @@ update_screen(mode *m, int display) case 'E': status = essential_clock_screen(m->timer, display); break; +#endif default: break; } } - if(status != old_status) + if (status != old_status) { - if(status == BACKLIGHT_OFF) + if (status == BACKLIGHT_OFF) sock_send_string(sock, "backlight off\n"); - if(status == BACKLIGHT_ON) + if (status == BACKLIGHT_ON) sock_send_string(sock, "backlight on\n"); - if(status == BLINK_ON) + if (status == BLINK_ON) sock_send_string(sock, "backlight blink\n"); } @@ -164,11 +223,15 @@ update_screen(mode *m, int display) // Credit Screen shows who wrote this... // int +#ifdef LCDPROC_MENUS +credit_screen(int rep, int display, int * flags_ptr) +#else credit_screen(int rep, int display) +#endif { static int first = 1; - if(first) + if (first) { first = 0; @@ -177,7 +240,7 @@ credit_screen(int rep, int display) sock_send_string(sock, "widget_add A title title\n"); sprintf(buffer, "widget_set A title {LCDPROC %s}\n", version); sock_send_string(sock, buffer); - if(lcd_hgt >= 4) + if (lcd_hgt >= 4) { sock_send_string(sock, "widget_add A one string\n"); sock_send_string(sock, "widget_add A two string\n"); diff --git a/clients/lcdproc/mode.h b/clients/lcdproc/mode.h index 894d981..02b2baa 100644 --- a/clients/lcdproc/mode.h +++ b/clients/lcdproc/mode.h @@ -11,6 +11,10 @@ int mode_init (); void mode_close (); int update_screen (mode * m, int display); +#ifdef LCDPROC_MENUS +int credit_screen (int rep, int display, int * flags_ptr); +#else int credit_screen (int rep, int display); +#endif #endif