vcs.4: Broken example code

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
- unwarranted assumption of little-endian byte order

Also be friendly and use SEEK_* instead of numbers.

Reported-by: Michael Witten <mfwitten@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Mattias Engdegård 2018-10-30 16:12:48 +01:00 committed by Michael Kerrisk
parent 7734ee11e1
commit 40b1bfaa48
1 changed files with 8 additions and 7 deletions

View File

@ -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;
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);
s ^= 0x1000;
(void) lseek(fd, \-2, SEEK_CUR);
(void) write(fd, &s, 2);
exit(EXIT_SUCCESS);
}
.EE