[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-man
Subject: [patch] vcs.4: broken example code
From: Mattias =?ISO-8859-1?Q?Engdeg=E5rd?= <mattiase () acm ! org>
Date: 2018-06-25 15:56:21
Message-ID: b48cb8b5ef9b06aba98c2b5b7609c8189a111a0c.camel () acm ! org
[Download RAW message or body]
Fix broken example code in the vcs.4 man page:
- use of wrong variable (attrib, which is uninitialised, instead of s)
- variable ch too narrow
- printing a font char index with %c, as if it were ASCII (it's not)
- removing the high font bit while changing the background colour
Also be friendly and use SEEK_* instead of numbers.
diff --git a/man4/vcs.4 b/man4/vcs.4
index aebe8cfda..c8b8cf361 100644
--- a/man4/vcs.4
+++ b/man4/vcs.4
@@ -140,7 +140,8 @@ main(void)
struct {unsigned char lines, cols, x, y;} scrn;
unsigned short s;
unsigned short mask;
- unsigned char ch, attrib;
+ unsigned char attrib, a;
+ int ch;
fd = open(console, O_RDWR);
if (fd < 0) {
@@ -158,16 +159,16 @@ main(void)
exit(EXIT_FAILURE);
}
(void) read(fd, &scrn, 4);
- (void) lseek(fd, 4 + 2*(scrn.y*scrn.cols + scrn.x), 0);
+ (void) lseek(fd, 4 + 2*(scrn.y*scrn.cols + scrn.x), SEEK_SET);
(void) read(fd, &s, 2);
ch = s & 0xff;
- if (attrib & mask)
+ if (s & mask)
ch |= 0x100;
attrib = ((s & ~mask) >> 8);
- printf("ch=\(aq%c\(aq attrib=0x%02x\\n", ch, attrib);
- attrib ^= 0x10;
- (void) lseek(fd, \-1, 1);
- (void) write(fd, &attrib, 1);
+ printf("ch=0x%03x attrib=0x%02x\\n", ch, attrib);
+ a = (s >> 8) ^ 0x10;
+ (void) lseek(fd, \-1, SEEK_CUR);
+ (void) write(fd, &a, 1);
exit(EXIT_SUCCESS);
}
.EE
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic