+static char *
+battery_perc(const char *battery)
+{
+ int now, full, perc;
+ char batterynowfile[64];
+ char batteryfullfile[64];
+ FILE *fp;
+
+ strlcpy(batterynowfile, BATTERY_PATH, sizeof(batterynowfile));
+ strlcat(batterynowfile, battery, sizeof(batterynowfile));
+ strlcat(batterynowfile, "/", sizeof(batterynowfile));
+ strlcat(batterynowfile, BATTERY_NOW, sizeof(batterynowfile));
+
+ strlcpy(batteryfullfile, BATTERY_PATH, sizeof(batteryfullfile));
+ strlcat(batteryfullfile, battery, sizeof(batteryfullfile));
+ strlcat(batteryfullfile, "/", sizeof(batteryfullfile));
+ strlcat(batteryfullfile, BATTERY_FULL, sizeof(batteryfullfile));
+
+ fp = fopen(batterynowfile, "r");
+ if (fp == NULL ) {
+ fprintf(stderr, "Error opening battery file: %s: %s\n",
+ batterynowfile,
+ strerror(errno));
+ return smprintf(UNKNOWN_STR);
+ }
+
+ fscanf(fp, "%i", &now);
+ fclose(fp);
+
+ fp = fopen(batteryfullfile, "r");
+ if (fp == NULL) {
+ fprintf(stderr, "Error opening battery file: %s\n",
+ strerror(errno));
+ return smprintf(UNKNOWN_STR);
+ }
+
+ fscanf(fp, "%i", &full);
+ fclose(fp);
+
+ perc = now / (full / 100);
+
+ return smprintf("%d%%", perc);
+}
+
+static char *
+cpu_perc(void)
+{
+ int perc;
+ long double a[4], b[4];
+ FILE *fp = fopen("/proc/stat","r");
+
+ if (fp == NULL) {
+ fprintf(stderr, "Error opening stat file: %s\n",
+ strerror(errno));
+ return smprintf(UNKNOWN_STR);
+ }
+
+ fscanf(fp, "%*s %Lf %Lf %Lf %Lf", &a[0], &a[1], &a[2], &a[3]);
+ fclose(fp);
+
+ /* wait a second (for avg values) */
+ sleep(1);
+
+ fp = fopen("/proc/stat","r");
+ if (fp == NULL) {
+ fprintf(stderr, "Error opening stat file: %s\n",
+ strerror(errno));
+ return smprintf(UNKNOWN_STR);
+ }
+
+ fscanf(fp, "%*s %Lf %Lf %Lf %Lf", &b[0], &b[1], &b[2], &b[3]);
+ fclose(fp);
+ perc = 100 * ((b[0]+b[1]+b[2]) - (a[0]+a[1]+a[2])) / ((b[0]+b[1]+b[2]+b[3]) - (a[0]+a[1]+a[2]+a[3]));
+ return smprintf("%d%%", perc);
+}
+
+static char *
+datetime(const char *timeformat)