Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (17 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/console-tools/loadfont.c

    r821 r1765  
    88 * (Adapted for busybox by Matej Vela.)
    99 */
    10 #include <stdio.h>
    11 #include <string.h>
    12 #include <fcntl.h>
    13 #include <stdlib.h>
    14 #include <unistd.h>
    15 #include <sys/types.h>
    16 #include <dirent.h>
    17 #include <errno.h>
    18 #include <sys/ioctl.h>
     10#include "libbb.h"
    1911#include <sys/kd.h>
    20 #include <endian.h>
    21 #include "busybox.h"
    2212
    23 enum{
     13enum {
    2414    PSF_MAGIC1 = 0x36,
    2515    PSF_MAGIC2 = 0x04,
     
    3222
    3323struct psf_header {
    34     unsigned char magic1, magic2;   /* Magic number */
    35     unsigned char mode;         /* PSF font mode */
    36     unsigned char charsize;     /* Character size */
     24    unsigned char magic1, magic2;   /* Magic number */
     25    unsigned char mode;             /* PSF font mode */
     26    unsigned char charsize;         /* Character size */
    3727};
    3828
    3929#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
    4030
    41 static void loadnewfont(int fd);
    42 
    43 int loadfont_main(int argc, char **argv)
    44 {
    45     int fd;
    46 
    47     if (argc != 1)
    48         bb_show_usage();
    49 
    50     fd = bb_xopen(CURRENT_VC, O_RDWR);
    51     loadnewfont(fd);
    52 
    53     return EXIT_SUCCESS;
    54 }
    55 
    5631static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
    5732{
    58     char buf[16384];
     33    char *buf;
    5934    int i;
    6035
    61     memset(buf, 0, sizeof(buf));
     36    if (unit < 1 || unit > 32)
     37        bb_error_msg_and_die("bad character size %d", unit);
    6238
    63     if (unit < 1 || unit > 32)
    64         bb_error_msg_and_die("Bad character size %d", unit);
    65 
     39    buf = xzalloc(16 * 1024);
     40    /*memset(buf, 0, 16 * 1024);*/
    6641    for (i = 0; i < fontsize; i++)
    6742        memcpy(buf + (32 * i), inbuf + (unit * i), unit);
    6843
    69 #if defined( PIO_FONTX ) && !defined( __sparc__ )
     44#if defined(PIO_FONTX) && !defined(__sparc__)
    7045    {
    7146        struct consolefontdesc cfd;
     
    7550        cfd.chardata = buf;
    7651
    77         if (ioctl(fd, PIO_FONTX, &cfd) == 0)
    78             return;             /* success */
    79         bb_perror_msg("PIO_FONTX ioctl error (trying PIO_FONT)");
     52        if (!ioctl_or_perror(fd, PIO_FONTX, &cfd, "PIO_FONTX ioctl failed (will try PIO_FONT)"))
     53            goto ret;           /* success */
    8054    }
    8155#endif
    82     if (ioctl(fd, PIO_FONT, buf))
    83         bb_perror_msg_and_die("PIO_FONT ioctl error");
     56    xioctl(fd, PIO_FONT, buf);
     57 ret:
     58    free(buf);
    8459}
    8560
     
    9267    int ct = 0, maxct;
    9368    int glyph;
    94     u_short unicode;
     69    uint16_t unicode;
    9570
    9671    maxct = tailsz;             /* more than enough */
    97     up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
     72    up = xmalloc(maxct * sizeof(struct unipair));
    9873
    9974    for (glyph = 0; glyph < fontsize; glyph++) {
    10075        while (tailsz >= 2) {
    101             unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
     76            unicode = (((uint16_t) inbuf[1]) << 8) + inbuf[0];
    10277            tailsz -= 2;
    10378            inbuf += 2;
     
    11691    advice.advised_hashstep = 0;
    11792    advice.advised_hashlevel = 0;
    118     if (ioctl(fd, PIO_UNIMAPCLR, &advice)) {
    119 #ifdef ENOIOCTLCMD
    120         if (errno == ENOIOCTLCMD) {
    121             bb_error_msg("It seems this kernel is older than 1.1.92");
    122             bb_error_msg_and_die("No Unicode mapping table loaded.");
    123         } else
    124 #endif
    125             bb_perror_msg_and_die("PIO_UNIMAPCLR");
    126     }
     93    xioctl(fd, PIO_UNIMAPCLR, &advice);
    12794    ud.entry_ct = ct;
    12895    ud.entries = up;
    129     if (ioctl(fd, PIO_UNIMAP, &ud)) {
    130 #if 0
    131         if (errno == ENOMEM) {
    132             /* change advice parameters */
    133         }
    134 #endif
    135         bb_perror_msg_and_die("PIO_UNIMAP");
    136     }
     96    xioctl(fd, PIO_UNIMAP, &ud);
    13797}
    13898
    13999static void loadnewfont(int fd)
    140100{
     101    enum { INBUF_SIZE = 32*1024 + 1 };
     102
    141103    int unit;
    142     unsigned char inbuf[32768];         /* primitive */
    143     unsigned int inputlth, offset;
     104    unsigned inputlth, offset;
     105    /* Was on stack, but 32k is a bit too much: */
     106    unsigned char *inbuf = xmalloc(INBUF_SIZE);
    144107
    145108    /*
     
    148111     * just read the entire file.
    149112     */
    150     inputlth = fread(inbuf, 1, sizeof(inbuf), stdin);
    151     if (ferror(stdin))
    152         bb_perror_msg_and_die("Error reading input font");
    153     /* use malloc/realloc in case of giant files;
    154        maybe these do not occur: 16kB for the font,
    155        and 16kB for the map leaves 32 unicode values
    156        for each font position */
    157     if (!feof(stdin))
    158         bb_perror_msg_and_die("Font too large");
     113    inputlth = full_read(STDIN_FILENO, inbuf, INBUF_SIZE);
     114    if (inputlth < 0)
     115        bb_perror_msg_and_die("error reading input font");
     116    if (inputlth >= INBUF_SIZE)
     117        bb_error_msg_and_die("font too large");
    159118
    160119    /* test for psf first */
     
    163122        int fontsize;
    164123        int hastable;
    165         unsigned int head0, head;
     124        unsigned head0, head;
    166125
    167126        if (inputlth < sizeof(struct psf_header))
     
    174133
    175134        if (psfhdr.mode > PSF_MAXMODE)
    176             bb_error_msg_and_die("Unsupported psf file mode");
     135            bb_error_msg_and_die("unsupported psf file mode");
    177136        fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
    178 #if !defined( PIO_FONTX ) || defined( __sparc__ )
     137#if !defined(PIO_FONTX) || defined(__sparc__)
    179138        if (fontsize != 256)
    180             bb_error_msg_and_die("Only fontsize 256 supported");
     139            bb_error_msg_and_die("only fontsize 256 supported");
    181140#endif
    182141        hastable = (psfhdr.mode & PSF_MODEHASTAB);
     
    186145        head = head0 + fontsize * unit;
    187146        if (head > inputlth || (!hastable && head != inputlth))
    188             bb_error_msg_and_die("Input file: bad length");
     147            bb_error_msg_and_die("input file: bad length");
    189148        do_loadfont(fd, inbuf + head0, unit, fontsize);
    190149        if (hastable)
     
    192151        return;
    193152    }
    194   no_psf:
    195153
     154 no_psf:
    196155    /* file with three code pages? */
    197156    if (inputlth == 9780) {
     
    201160        /* bare font */
    202161        if (inputlth & 0377)
    203             bb_error_msg_and_die("Bad input file size");
     162            bb_error_msg_and_die("bad input file size");
    204163        offset = 0;
    205164        unit = inputlth / 256;
     
    207166    do_loadfont(fd, inbuf + offset, unit, 256);
    208167}
     168
     169int loadfont_main(int argc, char **argv);
     170int loadfont_main(int argc, char **argv)
     171{
     172    int fd;
     173
     174    if (argc != 1)
     175        bb_show_usage();
     176
     177    fd = xopen(CURRENT_VC, O_RDWR);
     178    loadnewfont(fd);
     179
     180    return EXIT_SUCCESS;
     181}
Note: See TracChangeset for help on using the changeset viewer.