From 73ec65a84d422fe4bd15a8d3572875f2413926e6 Mon Sep 17 00:00:00 2001 From: "Ali H. Fardan" Date: Sun, 21 Aug 2016 11:10:37 +0300 Subject: -Wextra --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config.mk') diff --git a/config.mk b/config.mk index cdb9656..f01bcdb 100644 --- a/config.mk +++ b/config.mk @@ -16,7 +16,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound # flags CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE -CFLAGS = -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} +CFLAGS = -std=c99 -pedantic -Wall -Wextra -O0 ${INCS} ${CPPFLAGS} #CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} LDFLAGS = ${LIBS} #LDFLAGS = -s ${LIBS} -- cgit v1.2.3-70-g09d2 From 6f31ca6ce3ea722c7d1ecfe2099108133ce4215c Mon Sep 17 00:00:00 2001 From: "Ali H. Fardan" Date: Sun, 21 Aug 2016 15:43:57 +0300 Subject: fixed compiler warnings in a better way --- config.mk | 2 +- slstatus.c | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) (limited to 'config.mk') diff --git a/config.mk b/config.mk index f01bcdb..8e404d6 100644 --- a/config.mk +++ b/config.mk @@ -16,7 +16,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound # flags CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE -CFLAGS = -std=c99 -pedantic -Wall -Wextra -O0 ${INCS} ${CPPFLAGS} +CFLAGS = -std=c99 -pedantic -Wno-unused-function -Wall -Wextra -O0 ${INCS} ${CPPFLAGS} #CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} LDFLAGS = ${LIBS} #LDFLAGS = -s ${LIBS} diff --git a/slstatus.c b/slstatus.c index b0e3eef..7bd3b8c 100644 --- a/slstatus.c +++ b/slstatus.c @@ -611,16 +611,6 @@ main(void) char *res, *element; struct arg argument; - /* get rid of unused functions warning */ - if (0) { setstatus(""); battery_perc(""); cpu_perc(); - datetime(""); disk_free(""); disk_perc(""); - disk_total(""); disk_used(""); entropy(); - gid(); hostname(); ip(""); load_avg(); - ram_free(); ram_perc(); ram_used(); ram_total(); - run_command(""); temp(""); uid(); uptime(); - username(); vol_perc(""); wifi_perc(""); - wifi_essid(""); } - if (!(dpy = XOpenDisplay(0x0))) { fprintf(stderr, "Cannot open display!\n"); exit(1); -- cgit v1.2.3-70-g09d2 From 1654efe1d67d0bec010792e8c6eb64a0f8e88a58 Mon Sep 17 00:00:00 2001 From: "Ali H. Fardan" Date: Mon, 5 Sep 2016 00:56:22 +0300 Subject: config.mk cleanup --- arg.h | 51 --------------------------------------------------- concat.h | 19 ------------------- config.mk | 8 -------- 3 files changed, 78 deletions(-) delete mode 100644 arg.h delete mode 100644 concat.h (limited to 'config.mk') diff --git a/arg.h b/arg.h deleted file mode 100644 index 6c4a528..0000000 --- a/arg.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copy me if you can. - * by 20h - */ - -#ifndef ARG_H__ -#define ARG_H__ - -extern char *argv0; - -/* use main(int argc, char *argv[]) */ -#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ - argv[0] && argv[0][1]\ - && argv[0][0] == '-';\ - argc--, argv++) {\ - char argc_;\ - char **argv_;\ - int brk_;\ - if (argv[0][1] == '-' && argv[0][2] == '\0') {\ - argv++;\ - argc--;\ - break;\ - }\ - for (brk_ = 0, argv[0]++, argv_ = argv;\ - argv[0][0] && !brk_;\ - argv[0]++) {\ - if (argv_ != argv)\ - break;\ - argc_ = argv[0][0];\ - switch (argc_) - -#define ARGEND }\ - } - -#define ARGC() argc_ - -#define ARGNUMF(base) (brk_ = 1, estrtol(argv[0], (base))) - -#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ - ((x), abort(), (char *)0) :\ - (brk_ = 1, (argv[0][1] != '\0')?\ - (&argv[0][1]) :\ - (argc--, argv++, argv[0]))) - -#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\ - (char *)0 :\ - (brk_ = 1, (argv[0][1] != '\0')?\ - (&argv[0][1]) :\ - (argc--, argv++, argv[0]))) - -#endif diff --git a/concat.h b/concat.h deleted file mode 100644 index 9f138d7..0000000 --- a/concat.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Thanks to lloyd for contribution - */ - -extern char concat[4096]; - -extern void -ccat(const unsigned short int count, ...) -{ - va_list ap; - unsigned short int i; - concat[0] = '\0'; - - va_start(ap, count); - for(i = 0; i < count; i++) - strlcat(concat, va_arg(ap, char *), sizeof(concat)); - va_end(ap); - return; -} diff --git a/config.mk b/config.mk index 8e404d6..704558a 100644 --- a/config.mk +++ b/config.mk @@ -3,9 +3,7 @@ VERSION = 1.0 # Customize below to fit your system -# paths PREFIX = /usr/local -MANPREFIX = ${PREFIX}/share/man X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib @@ -17,13 +15,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound # flags CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE CFLAGS = -std=c99 -pedantic -Wno-unused-function -Wall -Wextra -O0 ${INCS} ${CPPFLAGS} -#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} LDFLAGS = ${LIBS} -#LDFLAGS = -s ${LIBS} - -# Solaris -#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" -#LDFLAGS = ${LIBS} # compiler and linker CC = cc -- cgit v1.2.3-70-g09d2 From 9fa858daeafb5398cdf19af9483b2854fe6e9772 Mon Sep 17 00:00:00 2001 From: "Ali H. Fardan" Date: Mon, 5 Sep 2016 01:13:48 +0300 Subject: added a tool for resetting the status bar && worked around some issues && removed the makefile (we need a better one) --- Makefile | 53 --------------------- config.mk | 22 --------- config.sh | 17 +++++++ loop.sh | 7 +++ slstatus.c | 148 ++++++++++++++++++--------------------------------------- status_reset.c | 10 ++++ 6 files changed, 81 insertions(+), 176 deletions(-) delete mode 100644 Makefile delete mode 100644 config.mk create mode 100644 config.sh create mode 100755 loop.sh create mode 100644 status_reset.c (limited to 'config.mk') diff --git a/Makefile b/Makefile deleted file mode 100644 index d20ad8f..0000000 --- a/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# See LICENSE file for copyright and license details. - -include config.mk - -SRC = ${NAME}.c -OBJ = ${SRC:.c=.o} - -all: options ${NAME} - -options: - @echo ${NAME} build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "CC = ${CC}" - -.c.o: - @echo CC $< - @${CC} -c ${CFLAGS} $< - -${OBJ}: config.h config.mk - -config.h: config.def.h - @echo creating $@ from config.def.h - @cp config.def.h $@ - -${NAME}: ${OBJ} - @echo CC -o $@ - @${CC} -o $@ ${OBJ} ${LDFLAGS} - -clean: - @echo cleaning - @rm -f ${NAME} ${OBJ} ${NAME}-${VERSION}.tar.gz - -dist: clean - @echo creating dist tarball - @mkdir -p ${NAME}-${VERSION} - @cp -R Makefile config.mk LICENSE \ - ${SRC} ${NAME}-${VERSION} - @tar -cf ${NAME}-${VERSION}.tar ${NAME}-${VERSION} - @gzip ${NAME}-${VERSION}.tar - @rm -rf ${NAME}-${VERSION} - -install: all - @echo installing executable file to ${DESTDIR}${PREFIX}/bin - @mkdir -p ${DESTDIR}${PREFIX}/bin - @cp -f ${NAME} ${DESTDIR}${PREFIX}/bin - @chmod 755 ${DESTDIR}${PREFIX}/bin/${NAME} - -uninstall: - @echo removing executable file from ${DESTDIR}${PREFIX}/bin - @rm -f ${DESTDIR}${PREFIX}/bin/${NAME} - -.PHONY: all options clean dist install uninstall diff --git a/config.mk b/config.mk deleted file mode 100644 index 704558a..0000000 --- a/config.mk +++ /dev/null @@ -1,22 +0,0 @@ -NAME = slstatus -VERSION = 1.0 - -# Customize below to fit your system - -PREFIX = /usr/local - -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 -lasound - -# flags -CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE -CFLAGS = -std=c99 -pedantic -Wno-unused-function -Wall -Wextra -O0 ${INCS} ${CPPFLAGS} -LDFLAGS = ${LIBS} - -# compiler and linker -CC = cc - diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..c460bd9 --- /dev/null +++ b/config.sh @@ -0,0 +1,17 @@ +NAME="slstatus" +VERSION="1.0" + +PREFIX="/usr/local" + +X11INC="/usr/X11R6/include" +X11LIB="/usr/X11R6/lib" + +INCS="-I. -I/usr/include -I${X11INC}" +LIBS="-L/usr/lib -lc -L${X11LIB} -lX11 -lasound" + +CPPFLAGS="-DVERSION=\"${VERSION}\" -D_GNU_SOURCE" +CFLAGS="-std=c99 -pedantic -Wno-unused-function -Wall -Wextra -O0 ${INCS} ${CPPFLAGS}" +LDFLAGS="${LIBS}" + +CC = cc + diff --git a/loop.sh b/loop.sh new file mode 100755 index 0000000..be231cf --- /dev/null +++ b/loop.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +while true +do + slstatus + status_reset +done diff --git a/slstatus.c b/slstatus.c index 5c83a84..dae5e8a 100644 --- a/slstatus.c +++ b/slstatus.c @@ -24,15 +24,8 @@ #undef strlcat #undef strlcpy -#include "arg.h" #include "strlcat.h" #include "strlcpy.h" -#include "concat.h" - -char *argv0; -char concat[]; - -FILE *foutput; struct arg { char *(*func)(); @@ -114,7 +107,7 @@ battery_perc(const char *battery) fp = fopen(batterynowfile, "r"); if (fp == NULL ) { - fprintf(foutput, "Error opening battery file: %s: %s\n", + fprintf(stderr, "Error opening battery file: %s: %s\n", batterynowfile, strerror(errno)); return smprintf(UNKNOWN_STR); @@ -125,7 +118,7 @@ battery_perc(const char *battery) fp = fopen(batteryfullfile, "r"); if (fp == NULL) { - fprintf(foutput, "Error opening battery file: %s\n", + fprintf(stderr, "Error opening battery file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -146,7 +139,7 @@ cpu_perc(void) FILE *fp = fopen("/proc/stat","r"); if (fp == NULL) { - fprintf(foutput, "Error opening stat file: %s\n", + fprintf(stderr, "Error opening stat file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -158,7 +151,7 @@ cpu_perc(void) fp = fopen("/proc/stat","r"); if (fp == NULL) { - fprintf(foutput, "Error opening stat file: %s\n", + fprintf(stderr, "Error opening stat file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -188,7 +181,7 @@ disk_free(const char *mountpoint) struct statvfs fs; if (statvfs(mountpoint, &fs) < 0) { - fprintf(foutput, "Could not get filesystem info: %s\n", + fprintf(stderr, "Could not get filesystem info: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -202,7 +195,7 @@ disk_perc(const char *mountpoint) struct statvfs fs; if (statvfs(mountpoint, &fs) < 0) { - fprintf(foutput, "Could not get filesystem info: %s\n", + fprintf(stderr, "Could not get filesystem info: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -217,7 +210,7 @@ disk_total(const char *mountpoint) struct statvfs fs; if (statvfs(mountpoint, &fs) < 0) { - fprintf(foutput, "Could not get filesystem info: %s\n", + fprintf(stderr, "Could not get filesystem info: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -231,7 +224,7 @@ disk_used(const char *mountpoint) struct statvfs fs; if (statvfs(mountpoint, &fs) < 0) { - fprintf(foutput, "Could not get filesystem info: %s\n", + fprintf(stderr, "Could not get filesystem info: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -246,7 +239,7 @@ entropy(void) FILE *fp = fopen("/proc/sys/kernel/random/entropy_avail", "r"); if (fp == NULL) { - fprintf(foutput, "Could not open entropy file: %s\n", + fprintf(stderr, "Could not open entropy file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -269,7 +262,7 @@ hostname(void) FILE *fp = fopen("/proc/sys/kernel/hostname", "r"); if (fp == NULL) { - fprintf(foutput, "Could not open hostname file: %s\n", + fprintf(stderr, "Could not open hostname file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -290,7 +283,7 @@ ip(const char *interface) char host[NI_MAXHOST]; if (getifaddrs(&ifaddr) == -1) { - fprintf(foutput, "Error getting IP address: %s\n", + fprintf(stderr, "Error getting IP address: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -305,7 +298,7 @@ ip(const char *interface) if ((strcmp(ifa->ifa_name, interface) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) { if (s != 0) { - fprintf(foutput, "Error getting IP address.\n"); + fprintf(stderr, "Error getting IP address.\n"); return smprintf(UNKNOWN_STR); } return smprintf("%s", host); @@ -324,7 +317,7 @@ load_avg(void) double avgs[3]; if (getloadavg(avgs, 3) < 0) { - fprintf(foutput, "Error getting load avg.\n"); + fprintf(stderr, "Error getting load avg.\n"); return smprintf(UNKNOWN_STR); } @@ -338,7 +331,7 @@ ram_free(void) FILE *fp = fopen("/proc/meminfo", "r"); if (fp == NULL) { - fprintf(foutput, "Error opening meminfo file: %s\n", + fprintf(stderr, "Error opening meminfo file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -356,7 +349,7 @@ ram_perc(void) FILE *fp = fopen("/proc/meminfo", "r"); if (fp == NULL) { - fprintf(foutput, "Error opening meminfo file: %s\n", + fprintf(stderr, "Error opening meminfo file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -378,7 +371,7 @@ ram_total(void) FILE *fp = fopen("/proc/meminfo", "r"); if (fp == NULL) { - fprintf(foutput, "Error opening meminfo file: %s\n", + fprintf(stderr, "Error opening meminfo file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -395,7 +388,7 @@ ram_used(void) FILE *fp = fopen("/proc/meminfo", "r"); if (fp == NULL) { - fprintf(foutput, "Error opening meminfo file: %s\n", + fprintf(stderr, "Error opening meminfo file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -418,7 +411,7 @@ run_command(const char* command) char buffer[64]; if (fp == NULL) { - fprintf(foutput, "Could not get command output for: %s: %s\n", + fprintf(stderr, "Could not get command output for: %s: %s\n", command, strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -443,7 +436,7 @@ temp(const char *file) FILE *fp = fopen(file, "r"); if (fp == NULL) { - fprintf(foutput, "Could not open temperature file: %s\n", + fprintf(stderr, "Could not open temperature file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -476,7 +469,7 @@ username(void) if (pw == NULL) return smprintf("%s", pw->pw_name); - fprintf(foutput, "Could not get username: %s\n", + fprintf(stderr, "Could not get username: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -509,7 +502,7 @@ vol_perc(const char *soundcard) snd_mixer_selem_id_malloc(&vol_info); snd_mixer_selem_id_malloc(&mute_info); if (vol_info == NULL || mute_info == NULL) { - fprintf(foutput, "Could not get alsa volume.\n"); + fprintf(stderr, "Could not get alsa volume.\n"); return smprintf(UNKNOWN_STR); } snd_mixer_selem_id_set_name(vol_info, ALSA_CHANNEL); @@ -552,7 +545,7 @@ wifi_perc(const char *wificard) fp = fopen(path, "r"); if(fp == NULL) { - fprintf(foutput, "Error opening wifi operstate file: %s\n", + fprintf(stderr, "Error opening wifi operstate file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -564,7 +557,7 @@ wifi_perc(const char *wificard) fp = fopen("/proc/net/wireless", "r"); if (fp == NULL) { - fprintf(foutput, "Error opening wireless file: %s\n", + fprintf(stderr, "Error opening wireless file: %s\n", strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -596,13 +589,13 @@ wifi_essid(const char *wificard) wreq.u.essid.length = IW_ESSID_MAX_SIZE+1; sprintf(wreq.ifr_name, wificard); if(sockfd == -1) { - fprintf(foutput, "Cannot open socket for interface: %s: %s\n", + fprintf(stderr, "Cannot open socket for interface: %s: %s\n", wificard, strerror(errno)); return smprintf(UNKNOWN_STR); } wreq.u.essid.pointer = id; if (ioctl(sockfd,SIOCGIWESSID, &wreq) == -1) { - fprintf(foutput, "Get ESSID ioctl failed for interface %s: %s\n", + fprintf(stderr, "Get ESSID ioctl failed for interface %s: %s\n", wificard, strerror(errno)); return smprintf(UNKNOWN_STR); } @@ -613,84 +606,37 @@ wifi_essid(const char *wificard) return smprintf("%s", (char *)wreq.u.essid.pointer); } -void -usage(void) -{ - fprintf(stderr, "usage: %s [-d] [-l path]\n", argv0); - exit(0); -} - int -main(int argc, char *argv[]) +main(void) { - unsigned short int dflag, lflag; size_t i; - char status_string[4096], logpath[4096]; + char status_string[4096]; char *res, *element; struct arg argument; - foutput = stderr; - dpy = XOpenDisplay(0x0); - - ARGBEGIN { - case 'd': - dflag = 1; - break; - case 'l': - strlcpy(logpath, EARGF(usage()), sizeof(logpath)-1); - logpath[strlen(logpath)+1] = '\0'; - foutput = fopen(logpath, "a"); - if (foutput == NULL) { - fprintf(stderr, "failed to open log file at %s: %s\n", - logpath, strerror(errno)); - return (1); - } - lflag = 1; - break; - default: - usage(); - } ARGEND - - if (dflag && !lflag) { - ccat(2, getenv("HOME"), "/.slstatus_log"); - foutput = fopen(concat, "a"); - if (foutput == NULL) { - fprintf(stderr, "failed to open log file at %s: %s\n", - logpath, strerror(errno)); - return (1); + stderr = stderr; + dpy = XOpenDisplay(NULL); + + memset(status_string, 0, sizeof(status_string)); + for (i = 0; i < sizeof(args) / sizeof(args[0]); ++i) { + argument = args[i]; + if (argument.args == NULL) + res = argument.func(); + else + res = argument.func(argument.args); + element = smprintf(argument.format, res); + if (element == NULL) { + element = smprintf(UNKNOWN_STR); + fprintf(stderr, "Failed to format output.\n"); } + strlcat(status_string, element, sizeof(status_string)); + free(res); + free(element); } - if (dflag) - daemon(0, 0); - - for (;;) { - memset(status_string, 0, sizeof(status_string)); - for (i = 0; i < sizeof(args) / sizeof(args[0]); ++i) { - argument = args[i]; - if (argument.args == NULL) - res = argument.func(); - else - res = argument.func(argument.args); - element = smprintf(argument.format, res); - if (element == NULL) { - element = smprintf(UNKNOWN_STR); - fprintf(stderr, "Failed to format output.\n"); - } - strlcat(status_string, element, sizeof(status_string)); - free(res); - free(element); - } - - XStoreName(dpy, DefaultRootWindow(dpy), status_string); - XSync(dpy, False); - } - - /* NOT REACHED */ - /* - * TODO: find out a way to exit successfully - * to prevent memory leaks - */ + XStoreName(dpy, DefaultRootWindow(dpy), status_string); + XSync(dpy, False); XCloseDisplay(dpy); + return 0; } diff --git a/status_reset.c b/status_reset.c new file mode 100644 index 0000000..eebaac6 --- /dev/null +++ b/status_reset.c @@ -0,0 +1,10 @@ +#include + +int +main(void) +{ + Display *dpy = XOpenDisplay(NULL); + XStoreName(dpy, DefaultRootWindow(dpy), NULL); + XCloseDisplay(dpy); + return (0); +} -- cgit v1.2.3-70-g09d2 From b9b6486cda91051553c9f9d7be75468c64206eec Mon Sep 17 00:00:00 2001 From: "Ali H. Fardan" Date: Mon, 5 Sep 2016 01:40:47 +0300 Subject: bringed back the old config.mk --- config.mk | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 config.mk (limited to 'config.mk') diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..4745073 --- /dev/null +++ b/config.mk @@ -0,0 +1,19 @@ +VERSION = 1.0 + +PREFIX = /usr/local +MANPREFIX = ${PREFIX}/share/man + +X11INC = /usr/X11R6/include +X11LIB = /usr/X11R6/lib + +INCS = -I. -I/usr/include -I${X11INC} +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound + +# flags +CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE +CFLAGS = -std=c99 -pedantic -Wno-unused-function -Wall -Wextra -O0 ${INCS} ${CPPFLAGS} +LDFLAGS = ${LIBS} + +CC = cc +LD = ld + -- cgit v1.2.3-70-g09d2