Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Jan 2000 01:02:17 -0500 (EST)
From:      Brian Fundakowski Feldman <green@FreeBSD.org>
To:        Mike Smith <msmith@freebsd.org>
Cc:        cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/usr.sbin/apm apm.8 apm.c 
Message-ID:  <Pine.BSF.4.10.10001180101280.1103-100000@green.dyndns.org>
In-Reply-To: <200001172320.PAA01112@mass.cdrom.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 17 Jan 2000, Mike Smith wrote:

> Please just merge 'apmconf' and 'apm'.

If you can find someone to clean up the manpage's writing a little
bit, here you go :)

> 
> -- 
> \\ Give a man a fish, and you feed him for a day. \\  Mike Smith
> \\ Tell him he should learn how to fish himself,  \\  msmith@freebsd.org
> \\ and he'll hate you for a lifetime.             \\  msmith@cdrom.com

-- 
 Brian Fundakowski Feldman           \  FreeBSD: The Power to Serve!  /
 green@FreeBSD.org                    `------------------------------'

cvs diff: Diffing .
Index: apm.8
===================================================================
RCS file: /usr2/ncvs/src/usr.sbin/apm/apm.8,v
retrieving revision 1.13
diff -u -r1.13 apm.8
--- apm.8	2000/01/16 20:25:57	1.13
+++ apm.8	2000/01/18 06:00:13
@@ -19,8 +19,10 @@
 .Nd control the APM BIOS and display its information
 .Sh SYNOPSIS
 .Nm apm
-.Op Fl abelstzZ
-.Op Fl d Ar 1|0
+.Op Fl ablstzZ
+.Op Fl d Ar enable
+.Op Fl e Ar enable
+.Op Fl h Ar enable
 .Op Fl r Ar delta
 .Pp
 .Nm zzz
@@ -60,17 +62,32 @@
 status,
 .Dq charging
 status respectively.
-.It Fl d
+.It Fl d Ar enable
 Disable/enable suspending of the display separately from a normal suspend
-using the values
-.Ar 1
-or
-.Ar 0
-respectively.  This argument seems to not work on many different
-laptops, including the Libretto 30CT and 50CT.
-.It Fl e
-Enable APM if it is currently not enabled, or disable APM if it is currently
-enabled.
+using the boolean value for
+.Ar enable .
+Strings evaluated to the boolean true value are "true", "yes", "enable", or
+a non-0 number, all case-insensitive.  Conversely, boolean false strings
+are "false", "no", "disable", or 0.
+This feature seems to not work on many different laptops, including the
+Libretto 30CT and 50CT.
+.It Fl e Ar enable
+Enable or disable APM functions of the computer, depending on the boolean
+.Ar enable
+argument.
+.It Fl h Ar enable
+Depending on the boolean value of
+.Ar enable ,
+enable or disable the HLT instruction in the kernel context switch routine.
+These options are not necessary for almost all APM implementations,
+but for some implementations whose
+.Dq Pa Idle CPU
+call executes both CPU clock slowdown and HLT instruction,
+.Fl t
+is necessary to prevent the system from reducing its peak performance.
+See
+.Xr apm 4
+for details.
 .It Fl l
 Display the remaining battery percentage.  If your laptop does not 
 support this function, 255 is displayed.
Index: apm.c
===================================================================
RCS file: /usr2/ncvs/src/usr.sbin/apm/apm.c,v
retrieving revision 1.21
diff -u -r1.21 apm.c
--- apm.c	2000/01/16 20:25:57	1.21
+++ apm.c	2000/01/18 05:58:15
@@ -46,11 +46,38 @@
 usage()
 {
 	fprintf(stderr, "%s\n%s\n",
-		"usage: apm [-ablstzZ] [-d 1|0] [-r delta]",
+		"usage: apm [-ablstzZ] [-d enable ] [ -e enable ] "
+		"[ -h enable ] [-r delta]",
 		"       zzz");
 	exit(1);
 }
 
+/*
+ * Return 1 for boolean true, and 0 for false, according to the
+ * interpretation of the string argument given.
+ */
+int
+is_true(const char *boolean) {
+	char *endp;
+	long val;
+
+	val = strtoul(boolean, &endp, 0);
+	if (*endp == '\0')
+		return (val != 0 ? 1 : 0);
+	if (strcasecmp(boolean, "true") == 0 ||
+	    strcasecmp(boolean, "yes") == 0 ||
+	    strcasecmp(boolean, "enable") == 0)
+		return (1);
+	if (strcasecmp(boolean, "false") == 0 ||
+	    strcasecmp(boolean, "no") == 0 ||
+	    strcasecmp(boolean, "disable") == 0)
+		return (0);
+	/* Well, I have no idea what the user wants, so... */
+	warnx("invalid boolean argument \"%s\"", boolean);
+	usage();
+	/* NOTREACHED */
+}
+
 int
 int2bcd(int i)
 {
@@ -89,31 +116,33 @@
 apm_suspend(int fd)
 {
 	if (ioctl(fd, APMIO_SUSPEND, NULL) == -1)
-		err(1, NULL);
+		err(1, "ioctl(APMIO_SUSPEND)");
 }
 
 void 
 apm_standby(int fd)
 {
 	if (ioctl(fd, APMIO_STANDBY, NULL) == -1)
-		err(1, NULL);
+		err(1, "ioctl(APMIO_STANDBY)");
 }
 
 void 
 apm_getinfo(int fd, apm_info_t aip)
 {
 	if (ioctl(fd, APMIO_GETINFO, aip) == -1)
-		err(1, NULL);
+		err(1, "ioctl(APMIO_GETINFO)");
 }
 
 void 
-apm_enable(int fd)
-{
-	struct apm_info info;
+apm_enable(int fd, int enable) {
 
-	apm_getinfo(fd, &info);
-	if (ioctl(fd, info.ai_status ? APMIO_DISABLE : APMIO_ENABLE) == -1)
-		err(1, NULL);
+	if (enable) {
+		if (ioctl(fd, APMIO_ENABLE) == -1)
+			err(1, "ioctl(APMIO_ENABLE)");
+	} else {
+		if (ioctl(fd, APMIO_DISABLE) == -1)
+			err(1, "ioctl(APMIO_DISABLE)");
+	}
 }
 
 void 
@@ -130,7 +159,7 @@
 	else if (aip->ai_acline > 1)
 		printf("invalid value (0x%x)", aip->ai_acline);
 	else {
-		char messages[][10] = {"off-line", "on-line"};
+		char *messages[] = { "off-line", "on-line" };
 		printf("%s", messages[aip->ai_acline]);
 	}
 	printf("\n");
@@ -140,21 +169,20 @@
 	else if (aip->ai_batt_stat > 3)
 			printf("invalid value (0x%x)", aip->ai_batt_stat);
 	else {
-		char messages[][10] = {"high", "low", "critical", "charging"};
+		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");
+		printf("unknown\n");
 	else if (aip->ai_batt_life <= 100)
-		printf("%d%%", aip->ai_batt_life);
+		printf("%d%%\n", aip->ai_batt_life);
 	else
-		printf("invalid value (0x%x)", aip->ai_batt_life);
-	printf("\n");
+		printf("invalid value (0x%x)\n", aip->ai_batt_life);
 	printf("Remaining battery time: ");
 	if (aip->ai_batt_time == -1)
-		printf("unknown");
+		printf("unknown\n");
 	else {
 		int t, h, m, s;
 
@@ -164,9 +192,8 @@
 		m = t % 60;
 		t /= 60;
 		h = t;
-		printf("%2d:%02d:%02d", h, m, s);
+		printf("%2d:%02d:%02d\n", h, m, s);
 	}
-	printf("\n");
 	if (aip->ai_infoversion >= 1) {
 		printf("Number of batteries: ");
 		if (aip->ai_batteries == (u_int) -1)
@@ -265,10 +292,21 @@
 apm_display(int fd, int newstate)
 {
 	if (ioctl(fd, APMIO_DISPLAY, &newstate) == -1)
-		err(1, NULL);
+		err(1, "ioctl(APMIO_DISPLAY)");
 }
 
+void
+apm_haltcpu(int fd, int enable) {
 
+	if (enable) {
+		if (ioctl(fd, APMIO_HALTCPU, NULL) == -1)
+			err(1, "ioctl(APMIO_HALTCPU)");
+	} else {
+		if (ioctl(fd, APMIO_NOTHALTCPU, NULL) == -1)
+			err(1, "ioctl(APMIO_NOTHALTCPU)");
+	}
+}
+
 void
 apm_set_timer(int fd, int delta)
 {
@@ -302,8 +340,8 @@
 {
 	int	c, fd;
 	int     sleep = 0, all_info = 1, apm_status = 0, batt_status = 0;
-	int     display = 0, batt_life = 0, ac_status = 0, standby = 0;
-	int	batt_time = 0, delta = 0, enable = 0;
+	int     display = -1, batt_life = 0, ac_status = 0, standby = 0;
+	int	batt_time = 0, delta = 0, enable = -1, haltcpu = -1;
 	char	*cmdname;
 	size_t	cmos_wall_len = sizeof(cmos_wall);
 
@@ -320,7 +358,7 @@
 		all_info = 0;
 		goto finish_option;
 	}
-	while ((c = getopt(argc, argv, "abelRr:stzd:Z")) != -1) {
+	while ((c = getopt(argc, argv, "abe:h:lRr:stzd:Z")) != -1) {
 		switch (c) {
 		case 'a':
 			ac_status = 1;
@@ -331,12 +369,7 @@
 			all_info = 0;
 			break;
 		case 'd':
-			display = *optarg - '0';
-			if (display < 0 || display > 1) {
-				warnx("argument of option '-%c' is invalid", c);
-				usage();
-			}
-			display++;
+			display = is_true(optarg);
 			all_info = 0;
 			break;
 		case 'l':
@@ -354,8 +387,11 @@
 			all_info = 0;
 			break;
 		case 'e':
-			enable = 1;
+			enable = is_true(optarg);
 			break;
+		case 'h':
+			haltcpu = is_true(optarg);
+			break;
 		case 't':
 			batt_time = 1;
 			all_info = 0;
@@ -377,12 +413,12 @@
 	}
 finish_option:
 	fd = open(APMDEV, O_RDWR);
-	if (fd == -1) {
-		warn("can't open %s", APMDEV);
-		return 1;
-	}
-	if (enable)
-		apm_enable(fd);
+	if (fd == -1)
+		err(1, "can't open %s", APMDEV);
+	if (enable != -1)
+		apm_enable(fd, enable);
+	if (haltcpu != -1)
+		apm_haltcpu(fd, haltcpu);
 	if (delta)
 		apm_set_timer(fd, delta);
 	if (sleep)
@@ -405,9 +441,9 @@
 			printf("%d\n", info.ai_status);
 		if (batt_time)
 			printf("%d\n", info.ai_batt_time);
-		if (display)
-			apm_display(fd, display - 1);
+		if (display != -1)
+			apm_display(fd, display);
 	}
 	close(fd);
-	return 0;
+	exit(0);
 }



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.10001180101280.1103-100000>