diff options
author | Michael Stapelberg <michael@stapelberg.de> | 2009-10-11 22:11:09 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2009-10-11 22:14:29 +0200 |
commit | f947d0a446b1b99020722cbc71127fc0c06086b2 (patch) | |
tree | 87b75e70a7e2c0d162685221c66beed5f6b6a9e6 /src/print_load.c | |
parent | 1d122f32e6d2b0ae1f964dd755d769885c7bf1c2 (diff) |
Breaks configfiles! Major refactoring of i3status, see below
We finally switched to libconfuse for a configuration file format
which does not require much work for the programmer nor for the user.
Plus, it avoids the Not-Invented-Here syndrome of yet another config
file format.
Furthermore, as a consequence of providing format strings for every
"module" (ipv6, wireless, …), we directly print the output and thus
we needed to drop support for wmii. This allowed us to get rid of
quite some complexity.
Documentation about the new configuration file and options will
follow. This commit is the beginning of what will be i3status v2.0.
Diffstat (limited to 'src/print_load.c')
-rw-r--r-- | src/print_load.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/print_load.c b/src/print_load.c new file mode 100644 index 0000000..c0d9494 --- /dev/null +++ b/src/print_load.c @@ -0,0 +1,39 @@ +// vim:ts=8:expandtab +#include "i3status.h" +#include <err.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +void print_load(const char *format) { +/* Get load */ +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(sun) + double loadavg[3]; + const char *walk; + + if (getloadavg(loadavg, 3) == -1) + errx(-1, "getloadavg() failed\n"); + + for (walk = format; *walk != '\0'; walk++) { + if (*walk != '%') { + putchar(*walk); + continue; + } + + if (BEGINS_WITH(walk+1, "5min")) { + (void)printf("%1.2f", loadavg[0]); + walk += strlen("5min"); + } + + if (BEGINS_WITH(walk+1, "10min")) { + (void)printf("%1.2f", loadavg[1]); + walk += strlen("10min"); + } + + if (BEGINS_WITH(walk+1, "15min")) { + (void)printf("%1.2f", loadavg[2]); + walk += strlen("15min"); + } + } +#endif +} |