1 /* showfont.c - aeb, 940207 - updated 2001-02-06 */
2 /* renamed to showconsolefont.c to avoid clash with the X showfont */
17 * Showing the font is nontrivial mostly because testing whether
18 * we are in utf8 mode cannot be done in an easy and clean way.
19 * So, we set up things here in such a way that it does not matter
20 * whether we are in utf8 mode.
23 unsigned short obuf[E_TABSZ], nbuf[E_TABSZ];
24 struct unimapdesc ounimap, nunimap;
29 static void __attribute__ ((noreturn))
31 if (have_obuf && loaduniscrnmap(fd,obuf)) {
33 _("failed to restore original translation table\n"));
36 if (have_ounimap && loadunimap(fd,NULL,&ounimap)) {
38 _("failed to restore original unimap\n"));
45 settrivialscreenmap(void) {
48 if (getuniscrnmap(fd,obuf))
52 for(i=0; i<E_TABSZ; i++)
55 if (loaduniscrnmap(fd,nbuf)) {
56 fprintf(stderr, _("cannot change translation table\n"));
61 static void __attribute__ ((noreturn))
63 fprintf(stderr, _("%s: out of memory?\n"), progname);
68 getoldunicodemap(void) {
69 struct unimapdesc descr;
71 if (getunimap(fd, &descr))
77 #define BASE 041 /* ' '+1 */
80 setnewunicodemap(int *list, int cnt) {
83 if (!nunimap.entry_ct) {
84 nunimap.entry_ct = 512;
85 nunimap.entries = (struct unipair *)
86 malloc(nunimap.entry_ct * sizeof(struct unipair));
87 if (nunimap.entries == NULL)
90 for (i=0; i<512; i++) {
91 nunimap.entries[i].fontpos = i;
92 nunimap.entries[i].unicode = 0;
95 nunimap.entries[list[i]].unicode = BASE+i;
97 if (loadunimap(fd, NULL, &nunimap))
101 static void __attribute__ ((noreturn))
104 _("usage: showconsolefont -V|--version\n"
105 " showconsolefont [-C tty] [-v] [-i]\n"
106 "(probably after loading a font with `setfont font')\n"
108 "Valid options are:\n"
109 " -C tty Device to read the font from. Default: current tty.\n"
110 " -v Be more verbose.\n"
111 " -i Don't print out the font table, just show\n"
112 " ROWSxCOLSxCOUNT and exit.\n"));
117 main (int argc, char **argv) {
118 int c, n, cols, rows, nr, i, j, k;
120 char *space, *sep, *console = NULL;
121 int list[64], lth, info = 0, verbose = 0;
123 set_progname(argv[0]);
125 setlocale(LC_ALL, "");
126 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
127 textdomain(PACKAGE_NAME);
130 (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")))
131 print_version_and_exit();
133 while ((c = getopt(argc, argv, "ivC:")) != EOF) {
154 if (ioctl(fd, KDGKBMODE, &mode)) {
158 if (mode == K_UNICODE)
159 space = "\xef\x80\xa0"; /* U+F020 (direct-to-font space) */
164 nr = rows = cols = 0;
165 n = getfont(fd, NULL, &nr, &rows, &cols);
170 printf(_("Character count: %d\n"), nr);
171 printf(_("Font width : %d\n"), rows);
172 printf(_("Font height : %d\n"), cols);
175 printf("%dx%dx%d\n", rows, cols, nr);
179 settrivialscreenmap();
184 printf(_("Showing %d-char font\n\n"), n);
185 cols = ((n > 256) ? 32 : 16);
187 rows = (n+cols-1)/cols;
188 sep = ((cols == 16) ? "%1$s%1$s" : "%1$s");
190 for (i=0; i<rows; i++) {
193 for (k=i; k<i+nr; k++)
194 for (j=0; j < cols; j++)
195 list[lth++] = k+j*rows;
196 setnewunicodemap(list, lth);
198 printf("%1$s%1$s%1$s%1$s", space);
199 for(j=0; j < cols && i+j*rows < n; j++) {
200 putchar(BASE + (i%nr)*cols+j);
212 exit(0); /* make gcc happy */