Replace current verbose GPL stuff in libbb/*.c with one-line GPL boilerplate.
[oweals/busybox.git] / console-tools / loadfont.c
index d6650019554dd59cfb99d0d7a146cafdec38c2aa..2421cadcfd5e7b48eb05501800cb536ae4b8d271 100644 (file)
@@ -10,7 +10,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <fcntl.h>
-#include <memory.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <endian.h>
 #include "busybox.h"
 
-static const int PSF_MAGIC1 = 0x36;
-static const int PSF_MAGIC2 = 0x04;
+enum{
+       PSF_MAGIC1 = 0x36,
+       PSF_MAGIC2 = 0x04,
 
-static const int PSF_MODE512 = 0x01;
-static const int PSF_MODEHASTAB = 0x02;
-static const int PSF_MAXMODE = 0x03;
-static const int PSF_SEPARATOR = 0xFFFF;
+       PSF_MODE512 = 0x01,
+       PSF_MODEHASTAB = 0x02,
+       PSF_MAXMODE = 0x03,
+       PSF_SEPARATOR = 0xFFFF
+};
 
 struct psf_header {
        unsigned char magic1, magic2;   /* Magic number */
@@ -39,22 +40,20 @@ struct psf_header {
 
 static void loadnewfont(int fd);
 
-extern int loadfont_main(int argc, char **argv)
+int loadfont_main(int argc, char **argv)
 {
        int fd;
 
        if (argc != 1)
-               show_usage();
+               bb_show_usage();
 
-       fd = open(CURRENT_VC, O_RDWR);
-       if (fd < 0)
-               perror_msg_and_die("Error opening " CURRENT_VC);
+       fd = bb_xopen(CURRENT_VC, O_RDWR);
        loadnewfont(fd);
 
        return EXIT_SUCCESS;
 }
 
-static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
+static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
 {
        char buf[16384];
        int i;
@@ -62,7 +61,7 @@ static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
        memset(buf, 0, sizeof(buf));
 
        if (unit < 1 || unit > 32)
-               error_msg_and_die("Bad character size %d", unit);
+               bb_error_msg_and_die("Bad character size %d", unit);
 
        for (i = 0; i < fontsize; i++)
                memcpy(buf + (32 * i), inbuf + (unit * i), unit);
@@ -77,11 +76,11 @@ static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
 
                if (ioctl(fd, PIO_FONTX, &cfd) == 0)
                        return;                         /* success */
-               perror_msg("PIO_FONTX ioctl error (trying PIO_FONT)");
+               bb_perror_msg("PIO_FONTX ioctl error (trying PIO_FONT)");
        }
 #endif
        if (ioctl(fd, PIO_FONT, buf))
-               perror_msg_and_die("PIO_FONT ioctl error");
+               bb_perror_msg_and_die("PIO_FONT ioctl error");
 }
 
 static void
@@ -119,28 +118,23 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
        if (ioctl(fd, PIO_UNIMAPCLR, &advice)) {
 #ifdef ENOIOCTLCMD
                if (errno == ENOIOCTLCMD) {
-                       error_msg("It seems this kernel is older than 1.1.92");
-                       error_msg_and_die("No Unicode mapping table loaded.");
+                       bb_error_msg("It seems this kernel is older than 1.1.92");
+                       bb_error_msg_and_die("No Unicode mapping table loaded.");
                } else
 #endif
-                       perror_msg_and_die("PIO_UNIMAPCLR");
+                       bb_perror_msg_and_die("PIO_UNIMAPCLR");
        }
        ud.entry_ct = ct;
        ud.entries = up;
        if (ioctl(fd, PIO_UNIMAP, &ud)) {
-#if 0
-               if (errno == ENOMEM) {
-                       /* change advice parameters */
-               }
-#endif
-               perror_msg_and_die("PIO_UNIMAP");
+               bb_perror_msg_and_die("PIO_UNIMAP");
        }
 }
 
 static void loadnewfont(int fd)
 {
        int unit;
-       char inbuf[32768];                      /* primitive */
+       unsigned char inbuf[32768];                     /* primitive */
        unsigned int inputlth, offset;
 
        /*
@@ -150,13 +144,13 @@ static void loadnewfont(int fd)
         */
        inputlth = fread(inbuf, 1, sizeof(inbuf), stdin);
        if (ferror(stdin))
-               perror_msg_and_die("Error reading input font");
+               bb_perror_msg_and_die("Error reading input font");
        /* use malloc/realloc in case of giant files;
           maybe these do not occur: 16kB for the font,
           and 16kB for the map leaves 32 unicode values
           for each font position */
        if (!feof(stdin))
-               perror_msg_and_die("Font too large");
+               bb_perror_msg_and_die("Font too large");
 
        /* test for psf first */
        {
@@ -174,11 +168,11 @@ static void loadnewfont(int fd)
                        goto no_psf;
 
                if (psfhdr.mode > PSF_MAXMODE)
-                       error_msg_and_die("Unsupported psf file mode");
+                       bb_error_msg_and_die("Unsupported psf file mode");
                fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
 #if !defined( PIO_FONTX ) || defined( __sparc__ )
                if (fontsize != 256)
-                       error_msg_and_die("Only fontsize 256 supported");
+                       bb_error_msg_and_die("Only fontsize 256 supported");
 #endif
                hastable = (psfhdr.mode & PSF_MODEHASTAB);
                unit = psfhdr.charsize;
@@ -186,7 +180,7 @@ static void loadnewfont(int fd)
 
                head = head0 + fontsize * unit;
                if (head > inputlth || (!hastable && head != inputlth))
-                       error_msg_and_die("Input file: bad length");
+                       bb_error_msg_and_die("Input file: bad length");
                do_loadfont(fd, inbuf + head0, unit, fontsize);
                if (hastable)
                        do_loadtable(fd, inbuf + head, inputlth - head, fontsize);
@@ -201,7 +195,7 @@ static void loadnewfont(int fd)
        } else {
                /* bare font */
                if (inputlth & 0377)
-                       error_msg_and_die("Bad input file size");
+                       bb_error_msg_and_die("Bad input file size");
                offset = 0;
                unit = inputlth / 256;
        }