Ping. (Michael Witten wanted to update the page text but let's at least fix the example code first.) 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. --- man4/vcs.4 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/man4/vcs.4 b/man4/vcs.4 index aebe8cfda..f695b956c 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; + 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