Introduction
Introduction Statistics Contact Development Disclaimer Help
tAdd count files plugin - spoon - dwm status utility (2f30 fork)
git clone git://src.adamsgaard.dk/spoon
Log
Files
Refs
LICENSE
---
commit 208a0a20dc55c2b37db0fcf6326703d96369bc75
parent e3980ef0a7422351304ffe3b87a4fa8192a87c83
Author: Christoph Polcin <[email protected]>
Date: Wed, 14 Mar 2018 09:06:44 +0100
Add count files plugin
Signed-off-by: Christoph Polcin <[email protected]>
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(-)
---
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…
-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
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 mpdar…
+ { .fmt = "[%s] ", .read = countread, .arg = (char []){"/…
{ .fmt = "[%s] ", .read = mixread, .arg = NULL },
{ .fmt = "[%s] ", .read = loadread, .arg = NULL },
{ .fmt = "[%s] ", .read = cpuread, .arg = NULL },
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;
+}
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;
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;
+}
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.