-/* local headers */
-#include "slstatus.h"
-#include "config.h"
-
-/* set statusbar */
-void
-setstatus(const char *str)
-{
- /* set WM_NAME via X11 */
- XStoreName(dpy, DefaultRootWindow(dpy), str);
- XSync(dpy, False);
-}
-
-/* smprintf function */
-char *
-smprintf(const char *fmt, ...)
-{
- va_list fmtargs;
- char *ret = NULL;
-
- va_start(fmtargs, fmt);
- if (vasprintf(&ret, fmt, fmtargs) < 0)
- return NULL;
- va_end(fmtargs);
-
- return ret;
-}
-
-/* battery percentage */
-char *
-get_battery(const char *battery)
-{
- int now, full, perc;
- char batterynowfile[64] = "";
- char batteryfullfile[64] = "";
- FILE *fp;
-
- /* generate battery nowfile path */
- strcat(batterynowfile, batterypath);
- strcat(batterynowfile, battery);
- strcat(batterynowfile, "/");
- strcat(batterynowfile, batterynow);
-
- /* generate battery fullfile path */
- strcat(batteryfullfile, batterypath);
- strcat(batteryfullfile, battery);
- strcat(batteryfullfile, "/");
- strcat(batteryfullfile, batteryfull);
-
- /* open battery now file */
- if (!(fp = fopen(batterynowfile, "r"))) {
- fprintf(stderr, "Error opening battery file.%s",batterynowfile);
- return smprintf("n/a");
- }
-
- /* read value */
- fscanf(fp, "%i", &now);
-
- /* close battery now file */
- fclose(fp);
-
- /* open battery full file */
- if (!(fp = fopen(batteryfullfile, "r"))) {
- fprintf(stderr, "Error opening battery file.");
- return smprintf("n/a");
- }
-
- /* read value */
- fscanf(fp, "%i", &full);
-
- /* close battery full file */
- fclose(fp);
-
- /* calculate percent */
- perc = now / (full / 100);
-
- /* return perc as string */
- return smprintf("%d%%", perc);
-}
-
-/* cpu temperature */
-char *
-get_cpu_temperature(const char *file)
-{
- int temperature;
- FILE *fp;
-
- /* open temperature file */
- if (!(fp = fopen(file, "r"))) {
- fprintf(stderr, "Could not open temperature file.\n");
- return smprintf("n/a");
- }
-
- /* extract temperature */
- fscanf(fp, "%d", &temperature);
-
- /* close temperature file */
- fclose(fp);
-
- /* return temperature in degrees */
- return smprintf("%d°C", temperature / 1000);
-}
-
-/* cpu percentage */
-char *
-get_cpu_usage(const char *null)
-{
- int perc;
- long double a[4], b[4];
- FILE *fp;
-
- /* open stat file */
- if (!(fp = fopen("/proc/stat","r"))) {
- fprintf(stderr, "Error opening stat file.");
- return smprintf("n/a");
- }
-
- /* read values */
- fscanf(fp, "%*s %Lf %Lf %Lf %Lf", &a[0], &a[1], &a[2], &a[3]);
-
- /* close stat file */
- fclose(fp);
-
- /* wait a second (for avg values) */
- sleep(1);
-
- /* open stat file */
- if (!(fp = fopen("/proc/stat","r"))) {
- fprintf(stderr, "Error opening stat file.");
- return smprintf("n/a");
- }
-
- /* read values */
- fscanf(fp, "%*s %Lf %Lf %Lf %Lf", &b[0], &b[1], &b[2], &b[3]);
+#include "arg.h"
+#include "util.h"
+
+struct arg {
+ const char *(*func)();
+ const char *fmt;
+ const char *args;
+};
+
+static const char *battery_perc(const char *bat);
+static const char *battery_power(const char *bat);
+static const char *battery_state(const char *bat);
+static const char *cpu_freq(void);
+static const char *cpu_perc(void);
+static const char *cpu_iowait(void);
+static const char *datetime(const char *fmt);
+static const char *disk_free(const char *mnt);
+static const char *disk_perc(const char *mnt);
+static const char *disk_total(const char *mnt);
+static const char *disk_used(const char *mnt);
+static const char *entropy(void);
+static const char *gid(void);
+static const char *hostname(void);
+static const char *ipv4(const char *iface);
+static const char *ipv6(const char *iface);
+static const char *kernel_release(void);
+static const char *keyboard_indicators(void);
+static const char *load_avg(const char *fmt);
+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 *ram_total(void);
+static const char *run_command(const char *cmd);
+static const char *swap_free(void);
+static const char *swap_perc(void);
+static const char *swap_used(void);
+static const char *swap_total(void);
+static const char *temp(const char *file);
+static const char *uid(void);
+static const char *uptime(void);
+static const char *username(void);
+static const char *vol_perc(const char *card);
+static const char *wifi_perc(const char *iface);
+static const char *wifi_essid(const char *iface);
+
+char *argv0;
+static unsigned short int done;
+static Display *dpy;