APM Clean-up Patch
Liam J. Foy
liamfoy at sepulcrum.org
Sun Jul 11 08:25:32 PDT 2004
Hey,
The follow patch contains some cleans for apm. I currently
have no dragonfly machine due to having no more machines. Would it possible
for me to have an account on leaf@ for testing?
Patch:
--- apm.c~ Sun Jul 11 15:00:19 2004
+++ apm/apm.c Sun Jul 11 15:32:30 2004
@@ -143,11 +143,56 @@
}
}
+static void
+print_batt_time(int batt_time)
+{
+ printf("Remaining battery time: ");
+ if (batt_time == -1)
+ printf("unknown\n");
+ else {
+ int h, m, s;
+
+ h = batt_time;
+ s = h % 60;
+ h /= 60;
+ m = h % 60;
+ h /= 60;
+ printf("%2d:%02d:%02d\n", h, m, s);
+ }
+}
+
+static void
+print_batt_life(u_int batt_life)
+{
+ printf("Remaining battery life: ");
+ if (batt_life >= 255)
+ printf("unknown\n");
+ else if (batt_life <= 100)
+ printf("%d%%\n", batt_life);
+ else
+ printf("invalid value (0x%x)\n", batt_life);
+}
+
+static void
+print_batt_stat(u_int batt_stat)
+{
+ const char *batt_msg[] = { "high", "low", "critical", "charging" };
+
+ printf("Battery Status: ");
+ if (batt_stat >= 255)
+ printf("unknown\n");
+ else if (batt_stat > 3)
+ printf("invalid value (0x%x)\n", batt_stat);
+ else
+ printf("%s\n", batt_msg[batt_stat]);
+}
+
void
print_all_info(int fd, apm_info_t aip, int bioscall_available)
{
struct apm_bios_arg args;
int apmerr;
+ char *line_msg[] = { "off-line", "on-line" };
printf("APM version: %d.%d\n", aip->ai_major, aip->ai_minor);
printf("APM Management: %s\n", (aip->ai_status ? "Enabled" : "Disabled"));
@@ -156,42 +201,13 @@
printf("unknown");
else if (aip->ai_acline > 1)
printf("invalid value (0x%x)", aip->ai_acline);
- else {
- char *messages[] = { "off-line", "on-line" };
- printf("%s", messages[aip->ai_acline]);
- }
- printf("\n");
- printf("Battery status: ");
- if (aip->ai_batt_stat == 255)
- printf("unknown");
- else if (aip->ai_batt_stat > 3)
- printf("invalid value (0x%x)", aip->ai_batt_stat);
- else {
- char *messages[] = { "high", "low", "critical", "charging" };
- printf("%s", messages[aip->ai_batt_stat]);
- }
- printf("\n");
- printf("Remaining battery life: ");
- if (aip->ai_batt_life == 255)
- printf("unknown\n");
- else if (aip->ai_batt_life <= 100)
- printf("%d%%\n", aip->ai_batt_life);
- else
- printf("invalid value (0x%x)\n", aip->ai_batt_life);
- printf("Remaining battery time: ");
- if (aip->ai_batt_time == -1)
- printf("unknown\n");
- else {
- int t, h, m, s;
+ else
+ printf("%s", line_msg[aip->ai_acline]);
+
+ print_batt_stat(aip->ai_batt_stat);
+ print_batt_life(aip->ai_batt_life);
+ print_batt_time(aip->ai_batt_time);
- t = aip->ai_batt_time;
- s = t % 60;
- t /= 60;
- m = t % 60;
- t /= 60;
- h = t;
- printf("%2d:%02d:%02d\n", h, m, s);
- }
if (aip->ai_infoversion >= 1) {
printf("Number of batteries: ");
if (aip->ai_batteries == (u_int) -1)
@@ -207,47 +223,18 @@
if (ioctl(fd, APMIO_GETPWSTATUS, &aps) == -1)
continue;
printf("Battery %d:\n", i);
- printf("\tBattery status: ");
if (aps.ap_batt_flag != 255 &&
(aps.ap_batt_flag & APM_BATT_NOT_PRESENT)) {
printf("not present\n");
continue;
}
- if (aps.ap_batt_stat == 255)
- printf("unknown\n");
- else if (aps.ap_batt_stat > 3)
- printf("invalid value (0x%x)\n",
- aps.ap_batt_stat);
- else {
- char *messages[] = { "high",
- "low",
- "critical",
- "charging" };
- printf("%s\n",
- messages[aps.ap_batt_stat]);
- }
- printf("\tRemaining battery life: ");
- if (aps.ap_batt_life == 255)
- printf("unknown\n");
- else if (aps.ap_batt_life <= 100)
- printf("%d%%\n", aps.ap_batt_life);
- else
- printf("invalid value (0x%x)\n",
- aps.ap_batt_life);
- printf("\tRemaining battery time: ");
- if (aps.ap_batt_time == -1)
- printf("unknown\n");
- else {
- int t, h, m, s;
-
- t = aps.ap_batt_time;
- s = t % 60;
- t /= 60;
- m = t % 60;
- t /= 60;
- h = t;
- printf("%2d:%02d:%02d\n", h, m, s);
- }
+
+ printf("\t");
+ print_batt_stat(aps.ap_batt_stat);
+ printf("\t");
+ print_batt_life(aps.ap_batt_life);
+ printf("\t");
+ print_batt_time(aps.ap_batt_time);
}
}
}
Thanks,
Liam J. Foy
liamfoy at xxxxxxxxxxxx
More information about the Commits
mailing list