tAdd count files plugin - spoon - dwm status utility (2f30 fork)
 (HTM) git clone git://src.adamsgaard.dk/spoon
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit 208a0a20dc55c2b37db0fcf6326703d96369bc75
 (DIR) parent e3980ef0a7422351304ffe3b87a4fa8192a87c83
 (HTM) Author: Christoph Polcin <labs@polcin.de>
       Date:   Wed, 14 Mar 2018 09:06:44 +0100
       
       Add count files plugin
       
       Signed-off-by: Christoph Polcin <labs@polcin.de>
       
       Diffstat:
         M Makefile                            |       4 ++--
         M config.def.h                        |       1 +
         A count.c                             |      29 +++++++++++++++++++++++++++++
         M spoon.c                             |       1 +
         M stub.c                              |       7 +++++++
       
       5 files changed, 40 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       t@@ -1,8 +1,8 @@
        VERSION = 0.5
        PREFIX = /usr/local
       -SRC = spoon.c batt.c wifi.c cpu.c temp.c date.c load.c file.c key.c\
       +SRC = spoon.c batt.c wifi.c cpu.c count.c temp.c date.c load.c file.c key.c\
              netspeed.c strlcpy.c strlcat.c stub.c mix.c xkblayout.c mpd.c brightness.c
       -OBJ = spoon.o batt.o wifi.o cpu.o temp.o date.o load.o file.o key.o\
       +OBJ = spoon.o batt.o wifi.o cpu.o count.o temp.o date.o load.o file.o key.o\
              netspeed.o strlcpy.o strlcat.o stub.o brightness.o
        BIN = spoon
        DISTFILES = $(SRC) types.h util.h config.def.h Makefile LICENSE configure
 (DIR) diff --git a/config.def.h b/config.def.h
       t@@ -4,6 +4,7 @@ int delay = 1;
        struct ent ents[] = {
                /* reorder/remove these as you see fit */
                { .fmt = "[%s] ",        .read = mpdread,        .arg = &(struct mpdarg){ .host = NULL, .port = 0 } },
       +        { .fmt = "[%s] ",        .read = countread,        .arg = (char []){"/home/USER/Maildir/INBOX/new"} },
                { .fmt = "[%s] ",        .read = mixread,        .arg = NULL },
                { .fmt = "[%s] ",        .read = loadread,        .arg = NULL },
                { .fmt = "[%s] ",        .read = cpuread,        .arg = NULL },
 (DIR) diff --git a/count.c b/count.c
       t@@ -0,0 +1,29 @@
       +#include <dirent.h>
       +#include <err.h>
       +#include <stdio.h>
       +#include <string.h>
       +
       +int
       +countread(void *arg, char *buf, size_t len)
       +{
       +        char *path = arg;
       +        unsigned long count = 0;
       +        struct dirent *e;
       +        DIR *d;
       +
       +        if ((d = opendir(path)) == NULL) {
       +                warn("open %s", path);
       +                return -1;
       +        }
       +
       +        while ((e = readdir(d)) != NULL) {
       +                if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, ".."))
       +                        continue;
       +                ++count;
       +        }
       +        closedir(d);
       +
       +        snprintf(buf, len, "%lu", count);
       +
       +        return 0;
       +}
 (DIR) diff --git a/spoon.c b/spoon.c
       t@@ -22,6 +22,7 @@ int fileread(void *, char *, size_t);
        int keyread(void *, char *, size_t);
        int netspeedread(void *, char *, size_t);
        int brightnessread(void *, char *, size_t);
       +int countread(void *, char *, size_t);
        
        struct ent {
                char *fmt;
 (DIR) diff --git a/stub.c b/stub.c
       t@@ -76,3 +76,10 @@ brightnessread(void *arg, char *buf, size_t len)
        {
                return -1;
        }
       +
       +#pragma weak countread
       +int
       +countread(void *arg, char *buf, size_t len)
       +{
       +        return -1;
       +}