t* dwmstatus for OpenBSD
       
   URI git clone git://git.codevoid.de/dwmstatus-sdk
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
   DIR commit abbd44de441b7dc0e666dae0c5f162f701d53480
   DIR parent 8d73323fbabab911e9fc12c40d6367c9e762d3a4
   URI Author: Stefan Hagen <sh+git[at]codevoid[dot]de>
       Date:   Sun,  3 Jun 2018 12:03:16 +0200
       
       remove unneeded files, add getfreespace()
       
       Diffstat:
         M config.mk                           |       4 ++--
         D dwmstatus-temperature.c             |      15 ---------------
         M dwmstatus.c                         |      29 +++++++++++++++++++++++++----
         D new-acpi-battery.c                  |      55 -------------------------------
       
       4 files changed, 27 insertions(+), 76 deletions(-)
       ---
   DIR diff --git a/config.mk b/config.mk
       t@@ -20,9 +20,9 @@ LIBS = -L/usr/local/lib -lc -L${X11LIB} -lX11
        
        # flags
        CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE
       -CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
       +CFLAGS = -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
        #CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
       -LDFLAGS = -g ${LIBS}
       +LDFLAGS = ${LIBS}
        #LDFLAGS = -s ${LIBS}
        
        # Solaris
   DIR diff --git a/dwmstatus-temperature.c b/dwmstatus-temperature.c
       t@@ -1,15 +0,0 @@
       -/*
       - * gettemperature("/sys/class/hwmon/hwmon0/device", "temp1_input");
       - */
       -
       -char *
       -gettemperature(char *base, char *sensor)
       -{
       -        char *co;
       -
       -        co = readfile(base, sensor);
       -        if (co == NULL)
       -                return smprintf("");
       -        return smprintf("%02.0f°C", atof(co) / 1000);
       -}
       -
   DIR diff --git a/dwmstatus.c b/dwmstatus.c
       t@@ -23,6 +23,15 @@
        
        #include <X11/Xlib.h>
        
       +// getfreespace
       +#include <sys/param.h>
       +#include <sys/mount.h>
       +
       +
       +
       +// configuration
       +#define UPDATE_INTERVAL 1
       +
        // conversation presets
        #define ZEROCTOC(x) ((x)-2731) / 10
        #define BTOMB(x) ((x)*1048576
       t@@ -56,6 +65,14 @@ smprintf(char *fmt, ...)
            return ret;
        }
        
       +/* Free space by path */
       +char *
       +getfreespace(const char *path) {
       +    struct statfs vfs;
       +    statfs(path, &vfs);
       +    return smprintf("%ld", (vfs.f_bavail * vfs.f_bsize) / 1024 / 1024);
       +}
       +
        /* Use FreeBSDs sysctl to retrieve information
         * Sysctl may return different types, so you want
         * to call the appropriate smprintf() in main();
       t@@ -244,9 +261,12 @@ void update() {
            char *cpufreq;
            char *battery;
            char *volume;
       +    char *freespace;
        
            // cpu temperature
            cputemp  = smprintf("%i", ZEROCTOC((int)getsysctl("hw.acpi.thermal.tz0.temperature")));
       +
       +    // cpu frequency
            cpufreq  = smprintf("%i", getsysctl("dev.cpu.0.freq"));
        
            // battery
       t@@ -259,15 +279,16 @@ void update() {
            // TBD
        
            // free disk space (root/home)
       -    // TBD
       +    freespace = smprintf("%s", getfreespace("/"));
        
            // date and time
            datetime = mktimes("%d.%m.%Y %H:%M", tzberlin);
        
            // assemble and display
       -    status   = smprintf(" LOAD:%s TEMP:%s°C FREQ:%sMhz BAT:%s%% VOL:%s | %s ", loadavg(), cputemp, cpufreq, battery, volume, datetime);
       +    status   = smprintf("/:%sMB LOAD:%s TEMP:%s°C FREQ:%sMhz BAT:%s%% VOL:%s | %s ", freespace, loadavg(), cputemp, cpufreq, battery, volume, datetime);
            setstatus(status);
        
       +    free(freespace);
            free(volume);
            free(battery);
            free(cputemp);
       t@@ -296,10 +317,10 @@ main(void)
        
            // register signal handler
            if (signal(SIGUSR1, sig_handler) == SIG_ERR)
       -        fprintf(stderr, "Err: can't register SIGUSR1\n");
       +        fprintf(stderr, "Err: can't register update signal (SIGUSR1)\n");
        
            // update status
       -    for (;;sleep(60)) {
       +    for (;;sleep(UPDATE_INTERVAL)) {
                update();
            }
        
   DIR diff --git a/new-acpi-battery.c b/new-acpi-battery.c
       t@@ -1,55 +0,0 @@
       -char *
       -readfile(char *base, char *file)
       -{
       -        char *path, line[513];
       -        FILE *fd;
       -
       -        memset(line, 0, sizeof(line));
       -
       -        path = smprintf("%s/%s", base, file);
       -        fd = fopen(path, "r");
       -        if (fd == NULL) {
       -                perror("fopen");
       -                exit(1);
       -        }
       -        free(path);
       -
       -        if (fgets(line, sizeof(line)-1, fd) == NULL) {
       -                perror("fgets");
       -                exit(1);
       -        }
       -        fclose(fd);
       -
       -        return smprintf("%s", line);
       -}
       -
       -char *
       -getbattery(char *base)
       -{
       -        char *co;
       -        int descap, remcap;
       -
       -        descap = -1;
       -        remcap = -1;
       -
       -        co = readfile(base, "present");
       -        if (co[0] != '1') {
       -                free(co);
       -                return smprintf("not present");
       -        }
       -        free(co);
       -
       -        co = readfile(base, "charge_full_design");
       -        sscanf(co, "%d", &descap);
       -        free(co);
       -
       -        co = readfile(base, "charge_now");
       -        sscanf(co, "%d", &remcap);
       -        free(co);
       -
       -        if (remcap < 0 || descap < 0)
       -                return smprintf("invalid");
       -
       -        return smprintf("%.0f", ((float)remcap / (float)descap) * 100);
       -}
       -