[hackers] [dwmstatus] Initial commit of dwmstatus 1.2. || Christoph Lohmann

From: <git_AT_suckless.org>
Date: Sun, 02 Dec 2012 07:15:16 +0100

commit 670007723c801e08bd6a6124cd9d760f6682ca3c
Author: Christoph Lohmann <20h_AT_r-36.net>
Date: Sun Dec 2 06:44:55 2012 +0100

    Initial commit of dwmstatus 1.2.

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f07c787
--- /dev/null
+++ b/LICENSE
_AT_@ -0,0 +1,21 @@
+MIT/X Consortium License
+
+© 2011-12 Christoph Lohmann <20h_AT_r-36.net>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..f31d1c7
--- /dev/null
+++ b/Makefile
_AT_@ -0,0 +1,49 @@
+# See LICENSE file for copyright and license details.
+
+include config.mk
+
+SRC = ${NAME}.c
+OBJ = ${SRC:.c=.o}
+
+all: options ${NAME}
+
+options:
+ _AT_echo ${NAME} build options:
+ _AT_echo "CFLAGS = ${CFLAGS}"
+ _AT_echo "LDFLAGS = ${LDFLAGS}"
+ _AT_echo "CC = ${CC}"
+
+.c.o:
+ _AT_echo CC $<
+ _AT_${CC} -c ${CFLAGS} $<
+
+${OBJ}: config.mk
+
+${NAME}: ${OBJ}
+ _AT_echo CC -o $@
+ _AT_${CC} -o $@ ${OBJ} ${LDFLAGS}
+
+clean:
+ _AT_echo cleaning
+ _AT_rm -f ${NAME} ${OBJ} ${NAME}-${VERSION}.tar.gz
+
+dist: clean
+ _AT_echo creating dist tarball
+ _AT_mkdir -p ${NAME}-${VERSION}
+ _AT_cp -R Makefile config.mk LICENSE \
+ ${SRC} ${NAME}-${VERSION}
+ _AT_tar -cf ${NAME}-${VERSION}.tar ${NAME}-${VERSION}
+ _AT_gzip ${NAME}-${VERSION}.tar
+ _AT_rm -rf ${NAME}-${VERSION}
+
+install: all
+ _AT_echo installing executable file to ${DESTDIR}${PREFIX}/bin
+ _AT_mkdir -p ${DESTDIR}${PREFIX}/bin
+ _AT_cp -f ${NAME} ${DESTDIR}${PREFIX}/bin
+ _AT_chmod 755 ${DESTDIR}${PREFIX}/bin/${NAME}
+
+uninstall:
+ _AT_echo removing executable file from ${DESTDIR}${PREFIX}/bin
+ _AT_rm -f ${DESTDIR}${PREFIX}/bin/${NAME}
+
+.PHONY: all options clean dist install uninstall
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..8b0b5ec
--- /dev/null
+++ b/config.mk
_AT_@ -0,0 +1,30 @@
+NAME = dwmstatus
+VERSION = 1.2
+
+# Customize below to fit your system
+
+# paths
+PREFIX = /usr/local
+MANPREFIX = ${PREFIX}/share/man
+
+X11INC = /usr/X11R6/include
+X11LIB = /usr/X11R6/lib
+
+# includes and libs
+INCS = -I. -I/usr/include -I${X11INC}
+LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
+
+# flags
+CPPFLAGS = -DVERSION=\"${VERSION}\"
+CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
+#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
+LDFLAGS = -g ${LIBS}
+#LDFLAGS = -s ${LIBS}
+
+# Solaris
+#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
+#LDFLAGS = ${LIBS}
+
+# compiler and linker
+CC = cc
+
diff --git a/dwmstatus.c b/dwmstatus.c
new file mode 100644
index 0000000..9b2703b
--- /dev/null
+++ b/dwmstatus.c
_AT_@ -0,0 +1,129 @@
+#define _BSD_SOURCE
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/time.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <X11/Xlib.h>
+
+char *tzargentina = "America/Buenos_Aires";
+char *tzutc = "UTC";
+char *tzberlin = "Europe/Berlin";
+
+static Display *dpy;
+
+char *
+smprintf(char *fmt, ...)
+{
+ va_list fmtargs;
+ char *ret;
+ int len;
+
+ va_start(fmtargs, fmt);
+ len = vsnprintf(NULL, 0, fmt, fmtargs);
+ va_end(fmtargs);
+
+ ret = malloc(++len);
+ if (ret == NULL) {
+ perror("malloc");
+ exit(1);
+ }
+
+ va_start(fmtargs, fmt);
+ vsnprintf(ret, len, fmt, fmtargs);
+ va_end(fmtargs);
+
+ return ret;
+}
+
+void
+settz(char *tzname)
+{
+ setenv("TZ", tzname, 1);
+}
+
+char *
+mktimes(char *fmt, char *tzname)
+{
+ char buf[129];
+ time_t tim;
+ struct tm *timtm;
+
+ bzero(buf, sizeof(buf));
+ settz(tzname);
+ tim = time(NULL);
+ timtm = localtime(&tim);
+ if (timtm == NULL) {
+ perror("localtime");
+ exit(1);
+ }
+
+ if (!strftime(buf, sizeof(buf)-1, fmt, timtm)) {
+ fprintf(stderr, "strftime == 0
");
+ exit(1);
+ }
+
+ return smprintf("%s", buf);
+}
+
+void
+setstatus(char *str)
+{
+ XStoreName(dpy, DefaultRootWindow(dpy), str);
+ XSync(dpy, False);
+}
+
+char *
+loadavg(void)
+{
+ double avgs[3];
+
+ if (getloadavg(avgs, 3) < 0) {
+ perror("getloadavg");
+ exit(1);
+ }
+
+ return smprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]);
+}
+
+int
+main(void)
+{
+ char *status;
+ char *avgs;
+ char *tmar;
+ char *tmutc;
+ char *tmbln;
+
+ if (!(dpy = XOpenDisplay(NULL))) {
+ fprintf(stderr, "dwmstatus: cannot open display.
");
+ return 1;
+ }
+
+ for (;;sleep(90)) {
+ avgs = loadavg();
+ tmar = mktimes("%H:%M", tzargentina);
+ tmutc = mktimes("%H:%M", tzutc);
+ tmbln = mktimes("KW %W %a %d %b %H:%M %Z %Y", tzberlin);
+
+ status = smprintf("[L: %s|A: %s|U: %s|%s]",
+ avgs, tmar, tmutc, tmbln);
+ setstatus(status);
+ free(avgs);
+ free(tmar);
+ free(tmutc);
+ free(tmbln);
+ free(status);
+ }
+
+ XCloseDisplay(dpy);
+
+ return 0;
+}
+
Received on Sun Dec 02 2012 - 07:15:16 CET

This archive was generated by hypermail 2.3.0 : Sun Dec 02 2012 - 07:24:06 CET