showconsolefont: Print adequate space chars
authorMichael Schutte <michi@uiae.at>
Mon, 18 May 2009 17:47:00 +0000 (19:47 +0200)
committerAlexey Gladkov <legion@altlinux.org>
Mon, 18 May 2009 22:32:42 +0000 (02:32 +0400)
Figure out whether the console is in Unicode or XLATE mode to decide
whether to use a direct-to-font (U+F020) or a simple ASCII space
character, respectively.  This avoids showconsolefont’s output becoming
a mess, cf. <http://bugs.debian.org/528357>.

Signed-off-by: Michael Schutte <michi@uiae.at>
src/showconsolefont.c

index c0b58d6..733e634 100644 (file)
@@ -116,7 +116,8 @@ usage(void) {
 int
 main (int argc, char **argv) {
        int c, n, cols, rows, nr, i, j, k;
-       char *sep, *console = NULL;
+       int mode;
+       char *space, *sep, *console = NULL;
        int list[64], lth, info = 0, verbose = 0;
 
        set_progname(argv[0]);
@@ -148,6 +149,17 @@ main (int argc, char **argv) {
        if (optind != argc)
                usage();
 
+       fd = getfd(console);
+
+       if (ioctl(fd, KDGKBMODE, &mode)) {
+               perror("KDGKBMODE");
+               leave(1);
+       }
+       if (mode == K_UNICODE)
+               space = "\xef\x80\xa0"; /* U+F020 (direct-to-font space) */
+       else
+               space = " ";
+
         if (info) {
            nr = rows = cols = 0;
            n = getfont(fd, NULL, &nr, &rows, &cols);
@@ -164,8 +176,6 @@ main (int argc, char **argv) {
            leave(0);
          }
 
-       fd = getfd(console);
-
        settrivialscreenmap();
        getoldunicodemap();
 
@@ -175,7 +185,7 @@ main (int argc, char **argv) {
        cols = ((n > 256) ? 32 : 16);
        nr = 64/cols;
        rows = (n+cols-1)/cols;
-       sep = ((cols == 16) ? "  " : " ");
+       sep = ((cols == 16) ? "%1$s%1$s" : "%1$s");
 
        for (i=0; i<rows; i++) {
                if (i % nr == 0) {
@@ -185,12 +195,12 @@ main (int argc, char **argv) {
                                        list[lth++] = k+j*rows;
                        setnewunicodemap(list, lth);
                }
-               printf("    ");
+               printf("%1$s%1$s%1$s%1$s", space);
                for(j=0; j < cols && i+j*rows < n; j++) {
                        putchar(BASE + (i%nr)*cols+j);
-                       printf("%s", sep);
+                       printf(sep, space);
                        if (j%8 == 7)
-                               printf("%s", sep);
+                               printf(sep, space);
                }
                putchar('\n');
                if (i%8 == 7)