put everything in logical order

This commit is contained in:
Aaron Marcher 2016-03-09 16:30:52 +01:00 committed by Aaron Marcher (drkhsh)
parent 8286bd8a37
commit 6a0ae11abc
1 changed files with 35 additions and 35 deletions

View File

@ -15,12 +15,12 @@
/* functions */ /* functions */
void setstatus(char *str); void setstatus(char *str);
char *smprintf(char *fmt, ...);
char *get_battery(); char *get_battery();
char *get_cpu_temperature(); char *get_cpu_temperature();
char *get_cpu_usage(); char *get_cpu_usage();
char *get_datetime(); char *get_datetime();
char *get_ram_usage(); char *get_ram_usage();
char *smprintf(char *fmt, ...);
char *get_volume(); char *get_volume();
char *get_wifi_signal(); char *get_wifi_signal();
@ -35,6 +35,31 @@ setstatus(char *str)
XSync(dpy, False); XSync(dpy, False);
} }
/* smprintf function */
char *
smprintf(char *fmt, ...)
{
va_list fmtargs;
char *ret;
int len;
va_start(fmtargs, fmt);
len = vsnprintf(NULL, 0, fmt, fmtargs);
va_end(fmtargs);
ret = malloc(++len);
if (ret == NULL) {
fprintf(stderr, "Malloc error.");
exit(1);
}
va_start(fmtargs, fmt);
vsnprintf(ret, len, fmt, fmtargs);
va_end(fmtargs);
return ret;
}
/* battery percentage */ /* battery percentage */
char * char *
get_battery() get_battery()
@ -187,31 +212,6 @@ get_ram_usage()
return smprintf("%d%%",ram_perc); return smprintf("%d%%",ram_perc);
} }
/* smprintf function */
char *
smprintf(char *fmt, ...)
{
va_list fmtargs;
char *ret;
int len;
va_start(fmtargs, fmt);
len = vsnprintf(NULL, 0, fmt, fmtargs);
va_end(fmtargs);
ret = malloc(++len);
if (ret == NULL) {
fprintf(stderr, "Malloc error.");
exit(1);
}
va_start(fmtargs, fmt);
vsnprintf(ret, len, fmt, fmtargs);
va_end(fmtargs);
return ret;
}
/* alsa volume percentage */ /* alsa volume percentage */
char * char *
get_volume() get_volume()
@ -318,13 +318,13 @@ int
main() main()
{ {
char status[1024]; char status[1024];
char *wifi_signal = NULL;
char *battery = NULL; char *battery = NULL;
char *cpu_usage = NULL;
char *cpu_temperature = NULL; char *cpu_temperature = NULL;
char *cpu_usage = NULL;
char *datetime = NULL;
char *ram_usage = NULL; char *ram_usage = NULL;
char *volume = NULL; char *volume = NULL;
char *datetime = NULL; char *wifi_signal = NULL;
/* open display */ /* open display */
if (!(dpy = XOpenDisplay(0x0))) { if (!(dpy = XOpenDisplay(0x0))) {
@ -335,26 +335,26 @@ main()
/* return status every second */ /* return status every second */
for (;;) { for (;;) {
/* assign the values */ /* assign the values */
wifi_signal = get_wifi_signal();
battery = get_battery(); battery = get_battery();
cpu_usage = get_cpu_usage();
cpu_temperature = get_cpu_temperature(); cpu_temperature = get_cpu_temperature();
cpu_usage = get_cpu_usage();
datetime = get_datetime();
ram_usage = get_ram_usage(); ram_usage = get_ram_usage();
volume = get_volume(); volume = get_volume();
datetime = get_datetime(); wifi_signal = get_wifi_signal();
/* return the status */ /* return the status */
sprintf(status, FORMATSTRING, ARGUMENTS); sprintf(status, FORMATSTRING, ARGUMENTS);
setstatus(status); setstatus(status);
/* free the values */ /* free the values */
free(wifi_signal);
free(battery); free(battery);
free(cpu_usage);
free(cpu_temperature); free(cpu_temperature);
free(cpu_usage);
free(datetime);
free(ram_usage); free(ram_usage);
free(volume); free(volume);
free(datetime); free(wifi_signal);
} }
/* close display */ /* close display */