|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
/*
* A possible workaround for broken "consolechars". Edrx, 2001feb06.
* (find-es "console" "RH_consolechar_bug")
*
* (find-angg "MTA/vtutilsh.c" "setfont")
* (find-node "(gcc)Macro Varargs")
* (find-node "(libc)Error Messages")
* (find-fline "/usr/doc/console-tools/file-formats/psf" "psf_header =")
* (find-fline "/usr/include/")
*/
/* #include <sys/types.h> */
/* #include <sys/stat.h> */
#include <sys/ioctl.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/kd.h>
#include <errno.h>
#include <stdio.h>
#define errmsg strerror(errno)
#define errorif(cond, format, args...) \
((cond) && (fprintf(stderr,format"\n",##args), exit(1)))
int main(int argc, char **argv) {
unsigned char b[256 * 32 + 4 + 1], buffer[512 * 32];
struct consolefontdesc cfd;
int nbytes, height, i, fd = open(argv[1], O_RDONLY);
errorif(fd==-1, "Can't open %s: %s", argv[1], errmsg);
nbytes = read(fd, b, 256 * 32 + 4 + 1); close(fd);
errorif(b[0]!=0x36 || b[1]!=4 || b[2]!=0 || nbytes!=((height=b[3])*256+4),
"Bad magic of file size: %02x %02x %02x %02x %d (=0x%x) bytes or more",
b[0], b[1], b[2], b[3], nbytes, nbytes);
memset(buffer, 0, 512 * 32);
for(i=0; i<256; ++i)
memcpy(buffer + i*32, b + 4 + i*height, height);
cfd.charheight = height;
cfd.charcount = 256;
cfd.chardata = buffer;
errorif(ioctl(STDIN_FILENO, PIO_FONTX, &cfd), "PIO_FONTX error: %s", errmsg);
return 0;
}