/* See LICENSE file for copyright and license details. */
+#include <dirent.h>
#include <err.h>
#include <fcntl.h>
#include <ifaddrs.h>
static const char *kernel_release(void);
static const char *keyboard_indicators(void);
static const char *load_avg(void);
+static const char *num_files(const char *dir);
static const char *ram_free(void);
static const char *ram_perc(void);
static const char *ram_used(void);
static const char *wifi_perc(const char *iface);
static const char *wifi_essid(const char *iface);
static void sighandler(const int signo);
-static void usage(const int eval);
+static void usage(void);
char *argv0;
static unsigned short int delay = 0;
static unsigned short int done;
-static unsigned short int dflag, oflag, nflag;
static Display *dpy;
#include "config.h"
return bprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]);
}
+static const char *
+num_files(const char *dir)
+{
+ struct dirent *dp;
+ DIR *fd;
+ int num = 0;
+
+ if ((fd = opendir(dir)) == NULL) {
+ warn("Failed to get number of files in directory %s", dir);
+ return UNKNOWN_STR;
+ }
+
+ while ((dp = readdir(fd)) != NULL) {
+ if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
+ continue; /* skip self and parent */
+ num++;
+ }
+
+ closedir(fd);
+
+ return bprintf("%d", num);
+}
+
static const char *
ram_free(void)
{
}
static void
-usage(const int eval)
+usage(void)
{
- fprintf(stderr, "usage: %s [-d] [-o] [-n] [-v] [-h]\n", argv0);
- exit(eval);
+ fprintf(stderr, "usage: %s [-s]\n", argv0);
+ exit(1);
}
int
main(int argc, char *argv[])
{
- unsigned short int i;
- char status_string[MAXLEN];
- char *element;
struct arg argument;
struct sigaction act;
- size_t len;
+ size_t i, len;
+ int sflag = 0;
+ char status_string[MAXLEN];
+ char *element;
ARGBEGIN {
- case 'd':
- dflag = 1;
- break;
- case 'o':
- oflag = 1;
+ case 's':
+ sflag = 1;
break;
- case 'n':
- nflag = 1;
- break;
- case 'v':
- printf("slstatus (C) 2016-2017 slstatus engineers\n");
- return 0;
- case 'h':
- usage(0);
default:
- usage(1);
+ usage();
} ARGEND
- if ((dflag && oflag) || (dflag && nflag) || (oflag && nflag)) {
- usage(1);
- }
- if (dflag && daemon(1, 1) < 0) {
- err(1, "daemon");
- }
-
memset(&act, 0, sizeof(act));
act.sa_handler = sighandler;
sigaction(SIGINT, &act, 0);
sigaction(SIGTERM, &act, 0);
- if (!oflag) {
+ if (!sflag) {
dpy = XOpenDisplay(NULL);
}
}
}
- if (oflag) {
- printf("%s\n", status_string);
- } else if (nflag) {
+ if (sflag) {
printf("%s\n", status_string);
- done = 1;
} else {
XStoreName(dpy, DefaultRootWindow(dpy), status_string);
XSync(dpy, False);
}
}
- if (!oflag) {
+ if (!sflag) {
XStoreName(dpy, DefaultRootWindow(dpy), NULL);
XCloseDisplay(dpy);
}