2000-02-09 01:28:47 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
1999-10-19 11:32:44 +05:30
|
|
|
/*
|
|
|
|
* loadfont.c - Eugene Crosser & Andries Brouwer
|
|
|
|
*
|
|
|
|
* Version 0.96bb
|
|
|
|
*
|
|
|
|
* Loads the console font, and possibly the corresponding screen map(s).
|
|
|
|
* (Adapted for busybox by Matej Vela.)
|
2008-12-07 06:22:58 +05:30
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2, see file LICENSE in this source tree.
|
1999-10-19 11:32:44 +05:30
|
|
|
*/
|
2016-11-23 15:09:27 +05:30
|
|
|
//config:config LOADFONT
|
2018-12-28 07:50:17 +05:30
|
|
|
//config: bool "loadfont (5.2 kb)"
|
2016-11-23 15:09:27 +05:30
|
|
|
//config: default y
|
|
|
|
//config: select PLATFORM_LINUX
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: This program loads a console font from standard input.
|
2016-11-23 15:09:27 +05:30
|
|
|
//config:
|
|
|
|
//config:config SETFONT
|
2018-12-28 07:50:17 +05:30
|
|
|
//config: bool "setfont (24 kb)"
|
2016-11-23 15:09:27 +05:30
|
|
|
//config: default y
|
|
|
|
//config: select PLATFORM_LINUX
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: Allows to load console screen map. Useful for i18n.
|
2016-11-23 15:09:27 +05:30
|
|
|
//config:
|
|
|
|
//config:config FEATURE_SETFONT_TEXTUAL_MAP
|
|
|
|
//config: bool "Support reading textual screen maps"
|
|
|
|
//config: default y
|
|
|
|
//config: depends on SETFONT
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: Support reading textual screen maps.
|
2016-11-23 15:09:27 +05:30
|
|
|
//config:
|
|
|
|
//config:config DEFAULT_SETFONT_DIR
|
|
|
|
//config: string "Default directory for console-tools files"
|
|
|
|
//config: default ""
|
|
|
|
//config: depends on SETFONT
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: Directory to use if setfont's params are simple filenames
|
|
|
|
//config: (not /path/to/file or ./file). Default is "" (no default directory).
|
2016-11-23 15:09:27 +05:30
|
|
|
//config:
|
|
|
|
//config:comment "Common options for loadfont and setfont"
|
|
|
|
//config: depends on LOADFONT || SETFONT
|
|
|
|
//config:
|
|
|
|
//config:config FEATURE_LOADFONT_PSF2
|
2017-01-10 19:28:54 +05:30
|
|
|
//config: bool "Support PSF2 console fonts"
|
2016-11-23 15:09:27 +05:30
|
|
|
//config: default y
|
|
|
|
//config: depends on LOADFONT || SETFONT
|
|
|
|
//config:
|
|
|
|
//config:config FEATURE_LOADFONT_RAW
|
2017-01-10 19:28:54 +05:30
|
|
|
//config: bool "Support old (raw) console fonts"
|
2016-11-23 15:09:27 +05:30
|
|
|
//config: default y
|
|
|
|
//config: depends on LOADFONT || SETFONT
|
|
|
|
|
2017-08-06 22:35:45 +05:30
|
|
|
//applet:IF_LOADFONT(APPLET_NOEXEC(loadfont, loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP, loadfont))
|
|
|
|
//applet:IF_SETFONT(APPLET_NOEXEC(setfont, setfont, BB_DIR_USR_SBIN, BB_SUID_DROP, setfont))
|
2016-11-23 15:09:27 +05:30
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_LOADFONT) += loadfont.o
|
|
|
|
//kbuild:lib-$(CONFIG_SETFONT) += loadfont.o
|
2011-03-28 03:12:28 +05:30
|
|
|
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.h"
|
2006-08-03 21:11:12 +05:30
|
|
|
#include <sys/kd.h>
|
1999-10-19 11:32:44 +05:30
|
|
|
|
2008-09-20 23:44:13 +05:30
|
|
|
#ifndef KDFONTOP
|
2010-02-21 17:40:26 +05:30
|
|
|
# define KDFONTOP 0x4B72
|
2008-09-20 23:44:13 +05:30
|
|
|
struct console_font_op {
|
|
|
|
unsigned op; /* KD_FONT_OP_* */
|
|
|
|
unsigned flags; /* KD_FONT_FLAG_* */
|
|
|
|
unsigned width, height;
|
|
|
|
unsigned charcount;
|
|
|
|
unsigned char *data; /* font data with height fixed to 32 */
|
|
|
|
};
|
2010-02-21 17:40:26 +05:30
|
|
|
# define KD_FONT_OP_SET 0 /* Set font */
|
|
|
|
# define KD_FONT_OP_GET 1 /* Get font */
|
|
|
|
# define KD_FONT_OP_SET_DEFAULT 2 /* Set font to default, data points to name / NULL */
|
|
|
|
# define KD_FONT_OP_COPY 3 /* Copy from another console */
|
|
|
|
# define KD_FONT_FLAG_OLD 0x80000000 /* Invoked via old interface */
|
|
|
|
# define KD_FONT_FLAG_DONT_RECALC 1 /* Don't call adjust_height() */
|
2008-09-20 23:44:13 +05:30
|
|
|
/* (Used internally for PIO_FONT support) */
|
|
|
|
#endif /* KDFONTOP */
|
|
|
|
|
|
|
|
|
2006-11-16 07:57:24 +05:30
|
|
|
enum {
|
2010-02-21 17:40:26 +05:30
|
|
|
PSF1_MAGIC0 = 0x36,
|
|
|
|
PSF1_MAGIC1 = 0x04,
|
|
|
|
PSF1_MODE512 = 0x01,
|
|
|
|
PSF1_MODEHASTAB = 0x02,
|
|
|
|
PSF1_MODEHASSEQ = 0x04,
|
|
|
|
PSF1_MAXMODE = 0x05,
|
|
|
|
PSF1_STARTSEQ = 0xfffe,
|
|
|
|
PSF1_SEPARATOR = 0xffff,
|
2006-03-11 00:52:06 +05:30
|
|
|
};
|
1999-10-19 11:32:44 +05:30
|
|
|
|
2010-02-21 17:40:26 +05:30
|
|
|
struct psf1_header {
|
|
|
|
unsigned char magic[2]; /* Magic number */
|
2007-06-10 20:38:44 +05:30
|
|
|
unsigned char mode; /* PSF font mode */
|
|
|
|
unsigned char charsize; /* Character size */
|
1999-10-19 11:32:44 +05:30
|
|
|
};
|
|
|
|
|
2010-02-21 17:40:26 +05:30
|
|
|
#define psf1h(x) ((struct psf1_header*)(x))
|
|
|
|
|
|
|
|
#define PSF1_MAGIC_OK(x) ( \
|
|
|
|
(x)->magic[0] == PSF1_MAGIC0 \
|
|
|
|
&& (x)->magic[1] == PSF1_MAGIC1 \
|
|
|
|
)
|
|
|
|
|
|
|
|
#if ENABLE_FEATURE_LOADFONT_PSF2
|
|
|
|
enum {
|
|
|
|
PSF2_MAGIC0 = 0x72,
|
|
|
|
PSF2_MAGIC1 = 0xb5,
|
|
|
|
PSF2_MAGIC2 = 0x4a,
|
|
|
|
PSF2_MAGIC3 = 0x86,
|
|
|
|
PSF2_HAS_UNICODE_TABLE = 0x01,
|
|
|
|
PSF2_MAXVERSION = 0,
|
|
|
|
PSF2_STARTSEQ = 0xfe,
|
|
|
|
PSF2_SEPARATOR = 0xff
|
|
|
|
};
|
|
|
|
|
|
|
|
struct psf2_header {
|
|
|
|
unsigned char magic[4];
|
|
|
|
unsigned int version;
|
|
|
|
unsigned int headersize; /* offset of bitmaps in file */
|
|
|
|
unsigned int flags;
|
|
|
|
unsigned int length; /* number of glyphs */
|
|
|
|
unsigned int charsize; /* number of bytes for each character */
|
|
|
|
unsigned int height; /* max dimensions of glyphs */
|
|
|
|
unsigned int width; /* charsize = height * ((width + 7) / 8) */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define psf2h(x) ((struct psf2_header*)(x))
|
|
|
|
|
|
|
|
#define PSF2_MAGIC_OK(x) ( \
|
|
|
|
(x)->magic[0] == PSF2_MAGIC0 \
|
|
|
|
&& (x)->magic[1] == PSF2_MAGIC1 \
|
|
|
|
&& (x)->magic[2] == PSF2_MAGIC2 \
|
|
|
|
&& (x)->magic[3] == PSF2_MAGIC3 \
|
|
|
|
)
|
|
|
|
#endif /* ENABLE_FEATURE_LOADFONT_PSF2 */
|
1999-10-19 11:32:44 +05:30
|
|
|
|
2010-02-21 17:40:26 +05:30
|
|
|
|
|
|
|
static void do_loadfont(int fd, unsigned char *inbuf, int height, int width, int charsize, int fontsize)
|
2000-02-09 01:28:47 +05:30
|
|
|
{
|
2010-02-21 17:40:26 +05:30
|
|
|
unsigned char *buf;
|
|
|
|
int charwidth = 32 * ((width+7)/8);
|
1999-10-19 11:32:44 +05:30
|
|
|
int i;
|
|
|
|
|
2010-02-21 17:40:26 +05:30
|
|
|
if (height < 1 || height > 32 || width < 1 || width > 32)
|
|
|
|
bb_error_msg_and_die("bad character size %dx%d", height, width);
|
1999-10-19 11:32:44 +05:30
|
|
|
|
2010-02-21 17:40:26 +05:30
|
|
|
buf = xzalloc(charwidth * ((fontsize < 128) ? 128 : fontsize));
|
1999-10-19 11:32:44 +05:30
|
|
|
for (i = 0; i < fontsize; i++)
|
2010-02-21 17:40:26 +05:30
|
|
|
memcpy(buf + (i*charwidth), inbuf + (i*charsize), charsize);
|
1999-10-19 11:32:44 +05:30
|
|
|
|
2008-09-20 23:44:13 +05:30
|
|
|
{ /* KDFONTOP */
|
|
|
|
struct console_font_op cfo;
|
|
|
|
cfo.op = KD_FONT_OP_SET;
|
|
|
|
cfo.flags = 0;
|
2010-02-21 17:40:26 +05:30
|
|
|
cfo.width = width;
|
|
|
|
cfo.height = height;
|
2008-09-20 23:44:13 +05:30
|
|
|
cfo.charcount = fontsize;
|
2010-02-21 17:40:26 +05:30
|
|
|
cfo.data = buf;
|
2008-09-20 23:44:13 +05:30
|
|
|
xioctl(fd, KDFONTOP, &cfo);
|
|
|
|
}
|
|
|
|
|
2007-06-10 20:38:44 +05:30
|
|
|
free(buf);
|
1999-10-19 11:32:44 +05:30
|
|
|
}
|
|
|
|
|
2010-02-21 17:40:26 +05:30
|
|
|
/*
|
|
|
|
* Format of the Unicode information:
|
|
|
|
*
|
|
|
|
* For each font position <uc>*<seq>*<term>
|
|
|
|
* where <uc> is a 2-byte little endian Unicode value (PSF1)
|
|
|
|
* or an UTF-8 coded value (PSF2),
|
|
|
|
* <seq> = <ss><uc><uc>*, <ss> = psf1 ? 0xFFFE : 0xFE,
|
|
|
|
* <term> = psf1 ? 0xFFFF : 0xFF.
|
|
|
|
* and * denotes zero or more occurrences of the preceding item.
|
|
|
|
*
|
|
|
|
* Semantics:
|
|
|
|
* The leading <uc>* part gives Unicode symbols that are all
|
|
|
|
* represented by this font position. The following sequences
|
|
|
|
* are sequences of Unicode symbols - probably a symbol
|
|
|
|
* together with combining accents - also represented by
|
|
|
|
* this font position.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* At the font position for a capital A-ring glyph, we
|
|
|
|
* may have:
|
2010-10-29 15:16:52 +05:30
|
|
|
* 00C5,212B,FFFE,0041,030A,FFFF
|
2010-02-21 17:40:26 +05:30
|
|
|
* Some font positions may be described by sequences only,
|
|
|
|
* namely when there is no precomposed Unicode value for the glyph.
|
|
|
|
*/
|
|
|
|
#if !ENABLE_FEATURE_LOADFONT_PSF2
|
|
|
|
#define do_loadtable(fd, inbuf, tailsz, fontsize, psf2) \
|
|
|
|
do_loadtable(fd, inbuf, tailsz, fontsize)
|
|
|
|
#endif
|
|
|
|
static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize, int psf2)
|
2000-02-09 01:28:47 +05:30
|
|
|
{
|
2010-02-21 17:40:26 +05:30
|
|
|
#if !ENABLE_FEATURE_LOADFONT_PSF2
|
|
|
|
/* gcc 4.3.1 code size: */
|
|
|
|
# define psf2 0 /* +0 bytes */
|
|
|
|
// const int psf2 = 0; /* +8 bytes */
|
|
|
|
// enum { psf2 = 0 }; /* +13 bytes */
|
|
|
|
#endif
|
1999-10-19 11:32:44 +05:30
|
|
|
struct unimapinit advice;
|
|
|
|
struct unimapdesc ud;
|
|
|
|
struct unipair *up;
|
|
|
|
int ct = 0, maxct;
|
|
|
|
int glyph;
|
2006-12-20 02:02:02 +05:30
|
|
|
uint16_t unicode;
|
1999-10-19 11:32:44 +05:30
|
|
|
|
2010-10-29 15:16:52 +05:30
|
|
|
maxct = tailsz; /* more than enough */
|
2010-02-21 17:40:26 +05:30
|
|
|
up = xmalloc(maxct * sizeof(*up));
|
2000-02-09 01:28:47 +05:30
|
|
|
|
1999-10-19 11:32:44 +05:30
|
|
|
for (glyph = 0; glyph < fontsize; glyph++) {
|
2010-02-21 17:40:26 +05:30
|
|
|
while (tailsz > 0) {
|
|
|
|
if (!psf2) { /* PSF1 */
|
|
|
|
unicode = (((uint16_t) inbuf[1]) << 8) + inbuf[0];
|
|
|
|
tailsz -= 2;
|
|
|
|
inbuf += 2;
|
|
|
|
if (unicode == PSF1_SEPARATOR)
|
|
|
|
break;
|
|
|
|
} else { /* PSF2 */
|
|
|
|
#if ENABLE_FEATURE_LOADFONT_PSF2
|
|
|
|
--tailsz;
|
|
|
|
unicode = *inbuf++;
|
|
|
|
if (unicode == PSF2_SEPARATOR) {
|
|
|
|
break;
|
|
|
|
} else if (unicode == PSF2_STARTSEQ) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("unicode sequences not implemented");
|
2010-02-21 17:40:26 +05:30
|
|
|
} else if (unicode >= 0xC0) {
|
|
|
|
if (unicode >= 0xFC)
|
|
|
|
unicode &= 0x01, maxct = 5;
|
|
|
|
else if (unicode >= 0xF8)
|
|
|
|
unicode &= 0x03, maxct = 4;
|
|
|
|
else if (unicode >= 0xF0)
|
|
|
|
unicode &= 0x07, maxct = 3;
|
|
|
|
else if (unicode >= 0xE0)
|
|
|
|
unicode &= 0x0F, maxct = 2;
|
|
|
|
else
|
|
|
|
unicode &= 0x1F, maxct = 1;
|
|
|
|
do {
|
|
|
|
if (tailsz <= 0 || *inbuf < 0x80 || *inbuf > 0xBF)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("illegal UTF-8 character");
|
2010-02-21 17:40:26 +05:30
|
|
|
--tailsz;
|
|
|
|
unicode = (unicode << 6) + (*inbuf++ & 0x3F);
|
|
|
|
} while (--maxct > 0);
|
|
|
|
} else if (unicode >= 0x80) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("illegal UTF-8 character");
|
2010-02-21 17:40:26 +05:30
|
|
|
}
|
|
|
|
#else
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
2000-02-09 01:28:47 +05:30
|
|
|
up[ct].unicode = unicode;
|
|
|
|
up[ct].fontpos = glyph;
|
|
|
|
ct++;
|
|
|
|
}
|
1999-10-19 11:32:44 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP
|
2013-01-15 18:28:01 +05:30
|
|
|
* this printf did not work on many kernels */
|
1999-10-19 11:32:44 +05:30
|
|
|
|
|
|
|
advice.advised_hashsize = 0;
|
|
|
|
advice.advised_hashstep = 0;
|
|
|
|
advice.advised_hashlevel = 0;
|
2007-07-15 03:37:14 +05:30
|
|
|
xioctl(fd, PIO_UNIMAPCLR, &advice);
|
1999-10-19 11:32:44 +05:30
|
|
|
ud.entry_ct = ct;
|
|
|
|
ud.entries = up;
|
2007-07-15 03:37:14 +05:30
|
|
|
xioctl(fd, PIO_UNIMAP, &ud);
|
2010-02-21 17:40:26 +05:30
|
|
|
#undef psf2
|
1999-10-19 11:32:44 +05:30
|
|
|
}
|
|
|
|
|
2010-02-21 17:40:26 +05:30
|
|
|
static void do_load(int fd, unsigned char *buffer, size_t len)
|
2000-02-09 01:28:47 +05:30
|
|
|
{
|
2010-02-21 17:40:26 +05:30
|
|
|
int height;
|
|
|
|
int width = 8;
|
|
|
|
int charsize;
|
|
|
|
int fontsize = 256;
|
|
|
|
int has_table = 0;
|
|
|
|
unsigned char *font = buffer;
|
|
|
|
unsigned char *table;
|
|
|
|
|
|
|
|
if (len >= sizeof(struct psf1_header) && PSF1_MAGIC_OK(psf1h(buffer))) {
|
|
|
|
if (psf1h(buffer)->mode > PSF1_MAXMODE)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("unsupported psf file mode");
|
2010-02-21 17:40:26 +05:30
|
|
|
if (psf1h(buffer)->mode & PSF1_MODE512)
|
|
|
|
fontsize = 512;
|
|
|
|
if (psf1h(buffer)->mode & PSF1_MODEHASTAB)
|
|
|
|
has_table = 1;
|
|
|
|
height = charsize = psf1h(buffer)->charsize;
|
|
|
|
font += sizeof(struct psf1_header);
|
|
|
|
} else
|
|
|
|
#if ENABLE_FEATURE_LOADFONT_PSF2
|
|
|
|
if (len >= sizeof(struct psf2_header) && PSF2_MAGIC_OK(psf2h(buffer))) {
|
|
|
|
if (psf2h(buffer)->version > PSF2_MAXVERSION)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("unsupported psf file version");
|
2010-02-21 17:40:26 +05:30
|
|
|
fontsize = psf2h(buffer)->length;
|
|
|
|
if (psf2h(buffer)->flags & PSF2_HAS_UNICODE_TABLE)
|
|
|
|
has_table = 2;
|
|
|
|
charsize = psf2h(buffer)->charsize;
|
|
|
|
height = psf2h(buffer)->height;
|
|
|
|
width = psf2h(buffer)->width;
|
|
|
|
font += psf2h(buffer)->headersize;
|
|
|
|
} else
|
1999-10-19 11:32:44 +05:30
|
|
|
#endif
|
2010-02-21 17:40:26 +05:30
|
|
|
#if ENABLE_FEATURE_LOADFONT_RAW
|
2010-10-29 15:16:52 +05:30
|
|
|
if (len == 9780) { /* file with three code pages? */
|
2010-02-21 17:40:26 +05:30
|
|
|
charsize = height = 16;
|
|
|
|
font += 40;
|
2010-10-29 15:16:52 +05:30
|
|
|
} else if ((len & 0377) == 0) { /* bare font */
|
2010-02-21 17:40:26 +05:30
|
|
|
charsize = height = len / 256;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("input file: bad length or unsupported font type");
|
1999-10-19 11:32:44 +05:30
|
|
|
}
|
2008-08-17 19:42:26 +05:30
|
|
|
|
2010-02-21 17:40:26 +05:30
|
|
|
#if !defined(PIO_FONTX) || defined(__sparc__)
|
|
|
|
if (fontsize != 256)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("only fontsize 256 supported");
|
2010-02-21 17:40:26 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
table = font + fontsize * charsize;
|
|
|
|
buffer += len;
|
|
|
|
|
|
|
|
if (table > buffer || (!has_table && table != buffer))
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("input file: bad length");
|
2010-02-21 17:40:26 +05:30
|
|
|
|
|
|
|
do_loadfont(fd, font, height, width, charsize, fontsize);
|
|
|
|
|
|
|
|
if (has_table)
|
|
|
|
do_loadtable(fd, table, buffer - table, fontsize, has_table - 1);
|
1999-10-19 11:32:44 +05:30
|
|
|
}
|
2007-06-10 20:38:44 +05:30
|
|
|
|
2010-02-21 17:40:26 +05:30
|
|
|
|
2008-08-17 19:42:26 +05:30
|
|
|
#if ENABLE_LOADFONT
|
2017-08-06 22:35:45 +05:30
|
|
|
//usage:#define loadfont_trivial_usage
|
|
|
|
//usage: "< font"
|
|
|
|
//usage:#define loadfont_full_usage "\n\n"
|
|
|
|
//usage: "Load a console font from stdin"
|
|
|
|
/* //usage: "\n -C TTY Affect TTY instead of /dev/tty" */
|
|
|
|
//usage:
|
|
|
|
//usage:#define loadfont_example_usage
|
|
|
|
//usage: "$ loadfont < /etc/i18n/fontname\n"
|
2007-10-11 15:35:36 +05:30
|
|
|
int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-08-17 19:42:26 +05:30
|
|
|
int loadfont_main(int argc UNUSED_PARAM, char **argv)
|
2007-06-10 20:38:44 +05:30
|
|
|
{
|
2008-08-17 19:42:26 +05:30
|
|
|
size_t len;
|
2010-02-21 17:40:26 +05:30
|
|
|
unsigned char *buffer;
|
2008-08-17 19:42:26 +05:30
|
|
|
|
|
|
|
// no arguments allowed!
|
2017-08-09 01:25:02 +05:30
|
|
|
getopt32(argv, "^" "" "\0" "=0");
|
2008-08-17 19:42:26 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* We used to look at the length of the input file
|
|
|
|
* with stat(); now that we accept compressed files,
|
|
|
|
* just read the entire file.
|
2016-11-04 01:27:37 +05:30
|
|
|
* Len was 32k, but latarcyrheb-sun32.psfu is 34377 bytes
|
|
|
|
* (it has largish Unicode map).
|
2008-08-17 19:42:26 +05:30
|
|
|
*/
|
2016-11-04 01:27:37 +05:30
|
|
|
len = 128*1024;
|
2010-02-21 17:40:26 +05:30
|
|
|
buffer = xmalloc_read(STDIN_FILENO, &len);
|
2008-08-17 19:42:26 +05:30
|
|
|
// xmalloc_open_zipped_read_close(filename, &len);
|
2010-02-21 17:40:26 +05:30
|
|
|
if (!buffer)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_perror_msg_and_die("error reading input font");
|
2010-02-21 17:40:26 +05:30
|
|
|
do_load(get_console_fd_or_die(), buffer, len);
|
2008-08-17 19:42:26 +05:30
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-09-13 23:57:32 +05:30
|
|
|
|
2017-08-06 22:35:45 +05:30
|
|
|
#if ENABLE_SETFONT
|
|
|
|
/* kbd-1.12:
|
2008-09-13 23:57:32 +05:30
|
|
|
setfont [-O font+umap.orig] [-o font.orig] [-om cmap.orig]
|
|
|
|
[-ou umap.orig] [-N] [font.new ...] [-m cmap] [-u umap] [-C console]
|
|
|
|
[-hNN] [-v] [-V]
|
|
|
|
|
|
|
|
-h NN Override font height
|
|
|
|
-o file
|
|
|
|
Save previous font in file
|
|
|
|
-O file
|
|
|
|
Save previous font and Unicode map in file
|
|
|
|
-om file
|
|
|
|
Store console map in file
|
|
|
|
-ou file
|
|
|
|
Save previous Unicode map in file
|
|
|
|
-m file
|
|
|
|
Load console map or Unicode console map from file
|
|
|
|
-u file
|
|
|
|
Load Unicode table describing the font from file
|
|
|
|
Example:
|
|
|
|
# cp866
|
|
|
|
0x00-0x7f idem
|
|
|
|
#
|
|
|
|
0x80 U+0410 # CYRILLIC CAPITAL LETTER A
|
|
|
|
0x81 U+0411 # CYRILLIC CAPITAL LETTER BE
|
|
|
|
0x82 U+0412 # CYRILLIC CAPITAL LETTER VE
|
|
|
|
-C console
|
|
|
|
Set the font for the indicated console
|
|
|
|
-v Verbose
|
|
|
|
-V Version
|
|
|
|
*/
|
2017-08-06 22:35:45 +05:30
|
|
|
//usage:#define setfont_trivial_usage
|
|
|
|
//usage: "FONT [-m MAPFILE] [-C TTY]"
|
|
|
|
//usage:#define setfont_full_usage "\n\n"
|
|
|
|
//usage: "Load a console font\n"
|
|
|
|
//usage: "\n -m MAPFILE Load console screen map"
|
|
|
|
//usage: "\n -C TTY Affect TTY instead of /dev/tty"
|
|
|
|
//usage:
|
|
|
|
//usage:#define setfont_example_usage
|
|
|
|
//usage: "$ setfont -m koi8-r /etc/i18n/fontname\n"
|
2008-09-13 23:57:32 +05:30
|
|
|
|
2017-08-06 22:35:45 +05:30
|
|
|
# if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
2008-09-17 01:05:42 +05:30
|
|
|
static int ctoi(char *s)
|
|
|
|
{
|
|
|
|
if (s[0] == '\'' && s[1] != '\0' && s[2] == '\'' && s[3] == '\0')
|
|
|
|
return s[1];
|
|
|
|
// U+ means 0x
|
|
|
|
if (s[0] == 'U' && s[1] == '+') {
|
|
|
|
s[0] = '0';
|
|
|
|
s[1] = 'x';
|
|
|
|
}
|
|
|
|
if (!isdigit(s[0]))
|
|
|
|
return -1;
|
|
|
|
return xstrtoul(s, 0);
|
|
|
|
}
|
2017-08-06 22:35:45 +05:30
|
|
|
# endif
|
2008-09-17 01:05:42 +05:30
|
|
|
|
2008-08-17 19:42:26 +05:30
|
|
|
int setfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
int setfont_main(int argc UNUSED_PARAM, char **argv)
|
|
|
|
{
|
|
|
|
size_t len;
|
2008-09-17 01:05:42 +05:30
|
|
|
unsigned opts;
|
|
|
|
int fd;
|
2010-02-21 17:40:26 +05:30
|
|
|
unsigned char *buffer;
|
2008-08-17 19:42:26 +05:30
|
|
|
char *mapfilename;
|
2008-09-17 01:05:42 +05:30
|
|
|
const char *tty_name = CURRENT_TTY;
|
2007-06-10 20:38:44 +05:30
|
|
|
|
2017-08-09 01:25:02 +05:30
|
|
|
opts = getopt32(argv, "^" "m:C:" "\0" "=1", &mapfilename, &tty_name);
|
2008-08-17 19:42:26 +05:30
|
|
|
argv += optind;
|
2007-06-10 20:38:44 +05:30
|
|
|
|
2009-10-27 03:57:08 +05:30
|
|
|
fd = xopen_nonblocking(tty_name);
|
2008-09-17 01:05:42 +05:30
|
|
|
|
|
|
|
if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
|
2008-09-18 06:31:02 +05:30
|
|
|
if (*argv[0] != '/') {
|
2008-09-17 01:05:42 +05:30
|
|
|
// goto default fonts location. don't die if doesn't exist
|
|
|
|
chdir(CONFIG_DEFAULT_SETFONT_DIR "/consolefonts");
|
|
|
|
}
|
|
|
|
}
|
2008-08-17 19:42:26 +05:30
|
|
|
// load font
|
2016-11-04 01:27:37 +05:30
|
|
|
len = 128*1024;
|
2010-02-21 17:40:26 +05:30
|
|
|
buffer = xmalloc_open_zipped_read_close(*argv, &len);
|
|
|
|
if (!buffer)
|
2008-09-18 06:31:02 +05:30
|
|
|
bb_simple_perror_msg_and_die(*argv);
|
2010-02-21 17:40:26 +05:30
|
|
|
do_load(fd, buffer, len);
|
2008-08-17 19:42:26 +05:30
|
|
|
|
|
|
|
// load the screen map, if any
|
2008-09-17 01:05:42 +05:30
|
|
|
if (opts & 1) { // -m
|
|
|
|
unsigned mode = PIO_SCRNMAP;
|
|
|
|
void *map;
|
|
|
|
|
|
|
|
if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
|
2008-09-18 06:31:02 +05:30
|
|
|
if (mapfilename[0] != '/') {
|
2008-09-17 01:05:42 +05:30
|
|
|
// goto default keymaps location
|
|
|
|
chdir(CONFIG_DEFAULT_SETFONT_DIR "/consoletrans");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fetch keymap
|
|
|
|
map = xmalloc_open_zipped_read_close(mapfilename, &len);
|
|
|
|
if (!map)
|
|
|
|
bb_simple_perror_msg_and_die(mapfilename);
|
|
|
|
// file size is 256 or 512 bytes? -> assume binary map
|
2008-08-17 19:42:26 +05:30
|
|
|
if (len == E_TABSZ || len == 2*E_TABSZ) {
|
2008-09-17 01:05:42 +05:30
|
|
|
if (len == 2*E_TABSZ)
|
|
|
|
mode = PIO_UNISCRNMAP;
|
2008-08-17 19:42:26 +05:30
|
|
|
}
|
2017-08-06 22:35:45 +05:30
|
|
|
# if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
2008-09-17 01:05:42 +05:30
|
|
|
// assume textual Unicode console maps:
|
|
|
|
// 0x00 U+0000 # NULL (NUL)
|
|
|
|
// 0x01 U+0001 # START OF HEADING (SOH)
|
|
|
|
// 0x02 U+0002 # START OF TEXT (STX)
|
|
|
|
// 0x03 U+0003 # END OF TEXT (ETX)
|
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
char *token[2];
|
|
|
|
parser_t *parser;
|
|
|
|
|
|
|
|
if (ENABLE_FEATURE_CLEAN_UP)
|
|
|
|
free(map);
|
|
|
|
map = xmalloc(E_TABSZ * sizeof(unsigned short));
|
|
|
|
|
|
|
|
#define unicodes ((unsigned short *)map)
|
|
|
|
// fill vanilla map
|
|
|
|
for (i = 0; i < E_TABSZ; i++)
|
|
|
|
unicodes[i] = 0xf000 + i;
|
|
|
|
|
|
|
|
parser = config_open(mapfilename);
|
|
|
|
while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL | PARSE_MIN_DIE)) {
|
|
|
|
// parse code/value pair
|
|
|
|
int a = ctoi(token[0]);
|
|
|
|
int b = ctoi(token[1]);
|
|
|
|
if (a < 0 || a >= E_TABSZ
|
|
|
|
|| b < 0 || b > 65535
|
|
|
|
) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("map format");
|
2008-09-17 01:05:42 +05:30
|
|
|
}
|
|
|
|
// patch map
|
|
|
|
unicodes[a] = b;
|
|
|
|
// unicode character is met?
|
|
|
|
if (b > 255)
|
|
|
|
mode = PIO_UNISCRNMAP;
|
|
|
|
}
|
|
|
|
if (ENABLE_FEATURE_CLEAN_UP)
|
|
|
|
config_close(parser);
|
|
|
|
|
|
|
|
if (mode != PIO_UNISCRNMAP) {
|
|
|
|
#define asciis ((unsigned char *)map)
|
|
|
|
for (i = 0; i < E_TABSZ; i++)
|
|
|
|
asciis[i] = unicodes[i];
|
|
|
|
#undef asciis
|
|
|
|
}
|
|
|
|
#undef unicodes
|
|
|
|
}
|
2017-08-06 22:35:45 +05:30
|
|
|
# endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
2008-09-17 01:05:42 +05:30
|
|
|
|
|
|
|
// do set screen map
|
|
|
|
xioctl(fd, mode, map);
|
|
|
|
|
|
|
|
if (ENABLE_FEATURE_CLEAN_UP)
|
|
|
|
free(map);
|
2008-08-17 19:42:26 +05:30
|
|
|
}
|
2007-06-10 20:38:44 +05:30
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2008-08-17 19:42:26 +05:30
|
|
|
#endif
|