commit b5813a7f677303c4f3701bb938f98e592f869a7a
parent 8894244cb8ad92569a1cbe9854ba3a7b97102e20
Author: Aaron Marcher <info@nulltime.net>
Date: Wed, 9 Mar 2016 11:21:35 +0100
changed to easier variable names
Diffstat:
M | config.def.h | | | 2 | +- |
M | slstatus.c | | | 76 | ++++++++++++++++++++++++++++++++++++++++------------------------------------ |
2 files changed, 41 insertions(+), 37 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -19,4 +19,4 @@ static const char timeformat[] = "%y-%m-%d %H:%M:%S";
/* statusbar */
#define FORMATSTRING "wifi %4s | bat %4s | cpu %4s %3s | ram %3s | vol %4s | %3s"
-#define ARGUMENTS pWifi_signal, pBattery, pCpu_usage, pCpu_temperature, pRam_usage, pVolume, pDatetime
+#define ARGUMENTS wifi_signal, battery, cpu_usage, cpu_temperature, ram_usage, volume, datetime
diff --git a/slstatus.c b/slstatus.c
@@ -15,14 +15,14 @@
/* functions */
void setstatus(char *str);
-char *battery();
-char *cpu_temperature();
-char *cpu_usage();
-char *datetime();
-char *ram_usage();
+char *get_battery();
+char *get_cpu_temperature();
+char *get_cpu_usage();
+char *get_datetime();
+char *get_ram_usage();
char *smprintf(char *fmt, ...);
-char *volume();
-char *wifi_signal();
+char *get_volume();
+char *get_wifi_signal();
/* global variables */
static Display *dpy;
@@ -37,7 +37,7 @@ setstatus(char *str)
/* battery percentage */
char *
-battery()
+get_battery()
{
int battery_now, battery_full, battery_perc;
FILE *fp;
@@ -75,7 +75,7 @@ battery()
/* cpu temperature */
char *
-cpu_temperature()
+get_cpu_temperature()
{
int temperature;
FILE *fp;
@@ -98,7 +98,7 @@ cpu_temperature()
/* cpu percentage */
char *
-cpu_usage()
+get_cpu_usage()
{
int cpu_perc;
long double a[4], b[4];
@@ -140,7 +140,7 @@ cpu_usage()
/* date and time */
char *
-datetime()
+get_datetime()
{
time_t tm;
size_t bufsize = 19;
@@ -159,7 +159,7 @@ datetime()
/* ram percentage */
char *
-ram_usage()
+get_ram_usage()
{
int ram_perc;
long total, free, available;
@@ -213,7 +213,7 @@ smprintf(char *fmt, ...)
/* alsa volume percentage */
char *
-volume()
+get_volume()
{
int mute = 0;
long vol = 0, max = 0, min = 0;
@@ -251,7 +251,7 @@ volume()
/* wifi percentage */
char *
-wifi_signal()
+get_wifi_signal()
{
int bufsize = 255;
int strength;
@@ -317,6 +317,13 @@ int
main()
{
char status[1024];
+ char *wifi_signal = NULL;
+ char *battery = NULL;
+ char *cpu_usage = NULL;
+ char *cpu_temperature = NULL;
+ char *ram_usage = NULL;
+ char *volume = NULL;
+ char *datetime = NULL;
/* open display */
if (!(dpy = XOpenDisplay(0x0))) {
@@ -324,32 +331,29 @@ main()
exit(1);
}
- char *pWifi_signal = NULL;
- char *pBattery = NULL;
- char *pCpu_usage = NULL;
- char *pCpu_temperature = NULL;
- char *pRam_usage = NULL;
- char *pVolume = NULL;
- char *pDatetime = NULL;
-
/* return status every second */
for (;;) {
- pWifi_signal = wifi_signal();
- pBattery = battery();
- pCpu_usage = cpu_usage();
- pCpu_temperature = cpu_temperature();
- pRam_usage = ram_usage();
- pVolume = volume();
- pDatetime = datetime();
+ /* assign the values */
+ wifi_signal = get_wifi_signal();
+ battery = get_battery();
+ cpu_usage = get_cpu_usage();
+ cpu_temperature = get_cpu_temperature();
+ ram_usage = get_ram_usage();
+ volume = get_volume();
+ datetime = get_datetime();
+
+ /* return the status */
sprintf(status, FORMATSTRING, ARGUMENTS);
setstatus(status);
- free(pWifi_signal);
- free(pBattery);
- free(pCpu_usage);
- free(pCpu_temperature);
- free(pRam_usage);
- free(pVolume);
- free(pDatetime);
+
+ /* free the values */
+ free(wifi_signal);
+ free(battery);
+ free(cpu_usage);
+ free(cpu_temperature);
+ free(ram_usage);
+ free(volume);
+ free(datetime);
}
/* close display */