X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/46b6876d7ec6e17bb51ee647f77bd238c864ca25..447283fda1505124f68f0cf74833f307cb630fa3:/slstatus.c diff --git a/slstatus.c b/slstatus.c index c03a1d2..60b5bbb 100644 --- a/slstatus.c +++ b/slstatus.c @@ -29,7 +29,7 @@ #include "strlcat.h" #include "strlcpy.h" -typedef char *(*op_fun) (const char *); +typedef char *(*op_fun)(); struct arg { op_fun func; const char *format; @@ -39,26 +39,26 @@ struct arg { static void setstatus(const char *); static char *smprintf(const char *, ...); static char *battery_perc(const char *); -static char *cpu_perc(const char *); +static char *cpu_perc(void); static char *datetime(const char *); static char *disk_free(const char *); static char *disk_perc(const char *); static char *disk_total(const char *); static char *disk_used(const char *); -static char *entropy(const char *); -static char *gid(const char *); -static char *hostname(const char *); +static char *entropy(void); +static char *gid(void); +static char *hostname(void); static char *ip(const char *); -static char *load_avg(const char *); -static char *ram_free(const char *); -static char *ram_perc(const char *); -static char *ram_used(const char *); -static char *ram_total(const char *); +static char *load_avg(void); +static char *ram_free(void); +static char *ram_perc(void); +static char *ram_used(void); +static char *ram_total(void); static char *run_command(const char *); static char *temp(const char *); -static char *uid(const char *); -static char *uptime(const char *); -static char *username(const char *); +static char *uid(void); +static char *uptime(void); +static char *username(void); static char *vol_perc(const char *); static char *wifi_perc(const char *); static char *wifi_essid(const char *); @@ -129,7 +129,7 @@ battery_perc(const char *battery) } static char * -cpu_perc(const char *null) +cpu_perc(void) { int perc; long double a[4], b[4]; @@ -237,7 +237,7 @@ disk_used(const char *mountpoint) } static char * -entropy(const char *null) +entropy(void) { int entropy = 0; FILE *fp; @@ -253,20 +253,14 @@ entropy(const char *null) } static char * -gid(const char *null) +gid(void) { - gid_t gid; - - if ((gid = getgid()) < 0) { - fprintf(stderr, "Could no get gid.\n"); - return smprintf(unknowntext); - } else - return smprintf("%d", gid); - return smprintf(unknowntext); + gid_t gid = getgid(); + return smprintf("%d", gid); } static char * -hostname(const char *null) +hostname(void) { char hostname[HOST_NAME_MAX]; FILE *fp; @@ -316,7 +310,7 @@ ip(const char *interface) } static char * -load_avg(const char *null) +load_avg(void) { double avgs[3]; @@ -329,7 +323,7 @@ load_avg(const char *null) } static char * -ram_free(const char *null) +ram_free(void) { long free; FILE *fp; @@ -345,7 +339,7 @@ ram_free(const char *null) } static char * -ram_perc(const char *null) +ram_perc(void) { int perc; long total, free, buffers, cached; @@ -367,7 +361,7 @@ ram_perc(const char *null) } static char * -ram_total(const char *null) +ram_total(void) { long total; FILE *fp; @@ -383,7 +377,7 @@ ram_total(const char *null) } static char * -ram_used(const char *null) +ram_used(void) { long free, total, buffers, cached, used; FILE *fp; @@ -445,7 +439,7 @@ temp(const char *file) } static char * -uptime(const char *null) +uptime(void) { struct sysinfo info; int hours = 0; @@ -459,7 +453,7 @@ uptime(const char *null) } static char * -username(const char *null) +username(void) { register struct passwd *pw; register uid_t uid; @@ -478,7 +472,7 @@ username(const char *null) } static char * -uid(const char *null) +uid(void) { register uid_t uid; @@ -612,7 +606,9 @@ wifi_essid(const char *wificard) int main(void) { - char status_string[1024]; + size_t i; + char status_string[4096]; + char *res, *element; struct arg argument; if (!(dpy = XOpenDisplay(0x0))) { @@ -622,10 +618,13 @@ main(void) for (;;) { memset(status_string, 0, sizeof(status_string)); - for (size_t i = 0; i < sizeof(args) / sizeof(args[0]); ++i) { + for (i = 0; i < sizeof(args) / sizeof(args[0]); ++i) { argument = args[i]; - char *res = argument.func(argument.args); - char *element = smprintf(argument.format, res); + if (argument.args == NULL) + res = argument.func(); + else + res = argument.func(argument.args); + element = smprintf(argument.format, res); if (element == NULL) { element = smprintf(unknowntext); fprintf(stderr, "Failed to format output.\n");