Commits

Thomas Dahms  committed e943f1b

useful output on no-battery computer

  • Participants
  • Parent commits 0456cd0

Comments (0)

Files changed (1)

 		exit(1);
 	}
 
-	sprintf(str, "%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]);
+	sprintf(str, "%.2f %.2f %.2f, ", avgs[0], avgs[1], avgs[2]);
 }
 
 void
 
 	descap = -1.;
 	remcap = -1.;
+	strcpy(str, "");
 
 	readfile(co, base, "present");
-	if (co[0] != '1') {
-		strcpy(str, "not present");
+	if (co[0] != '1')
 		return;
-	}
 
 	readfile(co, base, "charge_full_design");
 	if (strlen(co) == 0) {
 		readfile(co, base, "energy_full_design");
-		if (strlen(co) == 0) {
-			strcpy(str, "");
+		if (strlen(co) == 0)
 			return;
-		}
 	}
 	sscanf(co, "%f", &descap);
 
 	readfile(co, base, "charge_now");
 	if (strlen(co) == 0) {
 		readfile(co, base, "energy_now");
-		if (strlen(co) == 0) {
-			strcpy(str, "");
+		if (strlen(co) == 0)
 			return;
-		}
 	}
 	sscanf(co, "%f", &remcap);
 
-	if (remcap < 0 || descap < 0) {
-		strcpy(str, "invalid");
+	if (remcap < 0 || descap < 0)
 		return;
-	}
 
-	sprintf(str, "%.0f%%", (remcap / descap) * 100);
+	sprintf(str, "battery %.0f%%, ", (remcap / descap) * 100);
 }
 
 int
 		loadavg(avgs);
 		mktimes(tmbln, "%a %d %b %T");
 		getbattery(bttry, "/sys/class/power_supply/BAT0");
-		sprintf(status, "battery %s, load %s, %s", bttry, avgs, tmbln);
+		sprintf(status, "%s%s%s", bttry, avgs, tmbln);
 		XStoreName(dpy, DefaultRootWindow(dpy), status);
 		XSync(dpy, False);
 	}