blob: 9e887f2566a72083c67f083f525daf3ce6780284 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen3e0fbae1999-10-19 06:02:44 +00002/*
3 * loadfont.c - Eugene Crosser & Andries Brouwer
4 *
5 * Version 0.96bb
6 *
7 * Loads the console font, and possibly the corresponding screen map(s).
8 * (Adapted for busybox by Matej Vela.)
Denis Vlasenkodb12d1d2008-12-07 00:52:58 +00009 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +020010 * Licensed under GPLv2, see file LICENSE in this source tree.
Eric Andersen3e0fbae1999-10-19 06:02:44 +000011 */
Pere Orga55068c42011-03-27 23:42:28 +020012
13//usage:#define loadfont_trivial_usage
14//usage: "< font"
15//usage:#define loadfont_full_usage "\n\n"
16//usage: "Load a console font from stdin"
17/* //usage: "\n -C TTY Affect TTY instead of /dev/tty" */
18//usage:
19//usage:#define loadfont_example_usage
20//usage: "$ loadfont < /etc/i18n/fontname\n"
Pere Orga5bc8c002011-04-11 03:29:49 +020021//usage:
22//usage:#define setfont_trivial_usage
23//usage: "FONT [-m MAPFILE] [-C TTY]"
24//usage:#define setfont_full_usage "\n\n"
25//usage: "Load a console font\n"
Pere Orga5bc8c002011-04-11 03:29:49 +020026//usage: "\n -m MAPFILE Load console screen map"
27//usage: "\n -C TTY Affect TTY instead of /dev/tty"
28//usage:
29//usage:#define setfont_example_usage
30//usage: "$ setfont -m koi8-r /etc/i18n/fontname\n"
Pere Orga55068c42011-03-27 23:42:28 +020031
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000032#include "libbb.h"
Rob Landleyd921b2e2006-08-03 15:41:12 +000033#include <sys/kd.h>
Eric Andersen3e0fbae1999-10-19 06:02:44 +000034
Denis Vlasenkoeef60772008-09-20 18:14:13 +000035#ifndef KDFONTOP
Harald Becker8ce1dc02010-02-21 13:10:26 +010036# define KDFONTOP 0x4B72
Denis Vlasenkoeef60772008-09-20 18:14:13 +000037struct console_font_op {
38 unsigned op; /* KD_FONT_OP_* */
39 unsigned flags; /* KD_FONT_FLAG_* */
40 unsigned width, height;
41 unsigned charcount;
42 unsigned char *data; /* font data with height fixed to 32 */
43};
Harald Becker8ce1dc02010-02-21 13:10:26 +010044# define KD_FONT_OP_SET 0 /* Set font */
45# define KD_FONT_OP_GET 1 /* Get font */
46# define KD_FONT_OP_SET_DEFAULT 2 /* Set font to default, data points to name / NULL */
47# define KD_FONT_OP_COPY 3 /* Copy from another console */
48# define KD_FONT_FLAG_OLD 0x80000000 /* Invoked via old interface */
49# define KD_FONT_FLAG_DONT_RECALC 1 /* Don't call adjust_height() */
Denis Vlasenkoeef60772008-09-20 18:14:13 +000050 /* (Used internally for PIO_FONT support) */
51#endif /* KDFONTOP */
52
53
Denis Vlasenko83ea6432006-11-16 02:27:24 +000054enum {
Harald Becker8ce1dc02010-02-21 13:10:26 +010055 PSF1_MAGIC0 = 0x36,
56 PSF1_MAGIC1 = 0x04,
57 PSF1_MODE512 = 0x01,
58 PSF1_MODEHASTAB = 0x02,
59 PSF1_MODEHASSEQ = 0x04,
60 PSF1_MAXMODE = 0x05,
61 PSF1_STARTSEQ = 0xfffe,
62 PSF1_SEPARATOR = 0xffff,
Rob Landleybc68cd12006-03-10 19:22:06 +000063};
Eric Andersen3e0fbae1999-10-19 06:02:44 +000064
Harald Becker8ce1dc02010-02-21 13:10:26 +010065struct psf1_header {
66 unsigned char magic[2]; /* Magic number */
Denis Vlasenkoe8a07882007-06-10 15:08:44 +000067 unsigned char mode; /* PSF font mode */
68 unsigned char charsize; /* Character size */
Eric Andersen3e0fbae1999-10-19 06:02:44 +000069};
70
Harald Becker8ce1dc02010-02-21 13:10:26 +010071#define psf1h(x) ((struct psf1_header*)(x))
Eric Andersen3e0fbae1999-10-19 06:02:44 +000072
Harald Becker8ce1dc02010-02-21 13:10:26 +010073#define PSF1_MAGIC_OK(x) ( \
74 (x)->magic[0] == PSF1_MAGIC0 \
75 && (x)->magic[1] == PSF1_MAGIC1 \
76)
77
78#if ENABLE_FEATURE_LOADFONT_PSF2
79enum {
80 PSF2_MAGIC0 = 0x72,
81 PSF2_MAGIC1 = 0xb5,
82 PSF2_MAGIC2 = 0x4a,
83 PSF2_MAGIC3 = 0x86,
84 PSF2_HAS_UNICODE_TABLE = 0x01,
85 PSF2_MAXVERSION = 0,
86 PSF2_STARTSEQ = 0xfe,
87 PSF2_SEPARATOR = 0xff
88};
89
90struct psf2_header {
91 unsigned char magic[4];
92 unsigned int version;
93 unsigned int headersize; /* offset of bitmaps in file */
94 unsigned int flags;
95 unsigned int length; /* number of glyphs */
96 unsigned int charsize; /* number of bytes for each character */
97 unsigned int height; /* max dimensions of glyphs */
98 unsigned int width; /* charsize = height * ((width + 7) / 8) */
99};
100
101#define psf2h(x) ((struct psf2_header*)(x))
102
103#define PSF2_MAGIC_OK(x) ( \
104 (x)->magic[0] == PSF2_MAGIC0 \
105 && (x)->magic[1] == PSF2_MAGIC1 \
106 && (x)->magic[2] == PSF2_MAGIC2 \
107 && (x)->magic[3] == PSF2_MAGIC3 \
108)
109#endif /* ENABLE_FEATURE_LOADFONT_PSF2 */
110
111
112static void do_loadfont(int fd, unsigned char *inbuf, int height, int width, int charsize, int fontsize)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000113{
Harald Becker8ce1dc02010-02-21 13:10:26 +0100114 unsigned char *buf;
115 int charwidth = 32 * ((width+7)/8);
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000116 int i;
117
Harald Becker8ce1dc02010-02-21 13:10:26 +0100118 if (height < 1 || height > 32 || width < 1 || width > 32)
119 bb_error_msg_and_die("bad character size %dx%d", height, width);
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000120
Harald Becker8ce1dc02010-02-21 13:10:26 +0100121 buf = xzalloc(charwidth * ((fontsize < 128) ? 128 : fontsize));
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000122 for (i = 0; i < fontsize; i++)
Harald Becker8ce1dc02010-02-21 13:10:26 +0100123 memcpy(buf + (i*charwidth), inbuf + (i*charsize), charsize);
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000124
Denis Vlasenkoeef60772008-09-20 18:14:13 +0000125 { /* KDFONTOP */
126 struct console_font_op cfo;
Denis Vlasenkoeef60772008-09-20 18:14:13 +0000127 cfo.op = KD_FONT_OP_SET;
128 cfo.flags = 0;
Harald Becker8ce1dc02010-02-21 13:10:26 +0100129 cfo.width = width;
130 cfo.height = height;
Denis Vlasenkoeef60772008-09-20 18:14:13 +0000131 cfo.charcount = fontsize;
Harald Becker8ce1dc02010-02-21 13:10:26 +0100132 cfo.data = buf;
Denis Vlasenkoeef60772008-09-20 18:14:13 +0000133 xioctl(fd, KDFONTOP, &cfo);
Denis Vlasenkoeef60772008-09-20 18:14:13 +0000134 }
135
Denis Vlasenkoe8a07882007-06-10 15:08:44 +0000136 free(buf);
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000137}
138
Harald Becker8ce1dc02010-02-21 13:10:26 +0100139/*
140 * Format of the Unicode information:
141 *
142 * For each font position <uc>*<seq>*<term>
143 * where <uc> is a 2-byte little endian Unicode value (PSF1)
144 * or an UTF-8 coded value (PSF2),
145 * <seq> = <ss><uc><uc>*, <ss> = psf1 ? 0xFFFE : 0xFE,
146 * <term> = psf1 ? 0xFFFF : 0xFF.
147 * and * denotes zero or more occurrences of the preceding item.
148 *
149 * Semantics:
150 * The leading <uc>* part gives Unicode symbols that are all
151 * represented by this font position. The following sequences
152 * are sequences of Unicode symbols - probably a symbol
153 * together with combining accents - also represented by
154 * this font position.
155 *
156 * Example:
157 * At the font position for a capital A-ring glyph, we
158 * may have:
Denys Vlasenkofb132e42010-10-29 11:46:52 +0200159 * 00C5,212B,FFFE,0041,030A,FFFF
Harald Becker8ce1dc02010-02-21 13:10:26 +0100160 * Some font positions may be described by sequences only,
161 * namely when there is no precomposed Unicode value for the glyph.
162 */
163#if !ENABLE_FEATURE_LOADFONT_PSF2
164#define do_loadtable(fd, inbuf, tailsz, fontsize, psf2) \
165 do_loadtable(fd, inbuf, tailsz, fontsize)
166#endif
167static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize, int psf2)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000168{
Harald Becker8ce1dc02010-02-21 13:10:26 +0100169#if !ENABLE_FEATURE_LOADFONT_PSF2
170/* gcc 4.3.1 code size: */
171# define psf2 0 /* +0 bytes */
172// const int psf2 = 0; /* +8 bytes */
173// enum { psf2 = 0 }; /* +13 bytes */
174#endif
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000175 struct unimapinit advice;
176 struct unimapdesc ud;
177 struct unipair *up;
178 int ct = 0, maxct;
179 int glyph;
Denis Vlasenko28703012006-12-19 20:32:02 +0000180 uint16_t unicode;
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000181
Denys Vlasenkofb132e42010-10-29 11:46:52 +0200182 maxct = tailsz; /* more than enough */
Harald Becker8ce1dc02010-02-21 13:10:26 +0100183 up = xmalloc(maxct * sizeof(*up));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000184
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000185 for (glyph = 0; glyph < fontsize; glyph++) {
Harald Becker8ce1dc02010-02-21 13:10:26 +0100186 while (tailsz > 0) {
187 if (!psf2) { /* PSF1 */
188 unicode = (((uint16_t) inbuf[1]) << 8) + inbuf[0];
189 tailsz -= 2;
190 inbuf += 2;
191 if (unicode == PSF1_SEPARATOR)
192 break;
193 } else { /* PSF2 */
194#if ENABLE_FEATURE_LOADFONT_PSF2
195 --tailsz;
196 unicode = *inbuf++;
197 if (unicode == PSF2_SEPARATOR) {
198 break;
199 } else if (unicode == PSF2_STARTSEQ) {
200 bb_error_msg_and_die("unicode sequences not implemented");
201 } else if (unicode >= 0xC0) {
202 if (unicode >= 0xFC)
203 unicode &= 0x01, maxct = 5;
204 else if (unicode >= 0xF8)
205 unicode &= 0x03, maxct = 4;
206 else if (unicode >= 0xF0)
207 unicode &= 0x07, maxct = 3;
208 else if (unicode >= 0xE0)
209 unicode &= 0x0F, maxct = 2;
210 else
211 unicode &= 0x1F, maxct = 1;
212 do {
213 if (tailsz <= 0 || *inbuf < 0x80 || *inbuf > 0xBF)
214 bb_error_msg_and_die("illegal UTF-8 character");
215 --tailsz;
216 unicode = (unicode << 6) + (*inbuf++ & 0x3F);
217 } while (--maxct > 0);
218 } else if (unicode >= 0x80) {
219 bb_error_msg_and_die("illegal UTF-8 character");
220 }
221#else
222 return;
223#endif
224 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000225 up[ct].unicode = unicode;
226 up[ct].fontpos = glyph;
227 ct++;
228 }
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000229 }
230
231 /* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP
232 this printf did not work on many kernels */
233
234 advice.advised_hashsize = 0;
235 advice.advised_hashstep = 0;
236 advice.advised_hashlevel = 0;
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000237 xioctl(fd, PIO_UNIMAPCLR, &advice);
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000238 ud.entry_ct = ct;
239 ud.entries = up;
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000240 xioctl(fd, PIO_UNIMAP, &ud);
Harald Becker8ce1dc02010-02-21 13:10:26 +0100241#undef psf2
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000242}
243
Harald Becker8ce1dc02010-02-21 13:10:26 +0100244static void do_load(int fd, unsigned char *buffer, size_t len)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000245{
Harald Becker8ce1dc02010-02-21 13:10:26 +0100246 int height;
247 int width = 8;
248 int charsize;
249 int fontsize = 256;
250 int has_table = 0;
251 unsigned char *font = buffer;
252 unsigned char *table;
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000253
Harald Becker8ce1dc02010-02-21 13:10:26 +0100254 if (len >= sizeof(struct psf1_header) && PSF1_MAGIC_OK(psf1h(buffer))) {
255 if (psf1h(buffer)->mode > PSF1_MAXMODE)
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000256 bb_error_msg_and_die("unsupported psf file mode");
Harald Becker8ce1dc02010-02-21 13:10:26 +0100257 if (psf1h(buffer)->mode & PSF1_MODE512)
258 fontsize = 512;
259 if (psf1h(buffer)->mode & PSF1_MODEHASTAB)
260 has_table = 1;
261 height = charsize = psf1h(buffer)->charsize;
262 font += sizeof(struct psf1_header);
263 } else
264#if ENABLE_FEATURE_LOADFONT_PSF2
265 if (len >= sizeof(struct psf2_header) && PSF2_MAGIC_OK(psf2h(buffer))) {
266 if (psf2h(buffer)->version > PSF2_MAXVERSION)
267 bb_error_msg_and_die("unsupported psf file version");
268 fontsize = psf2h(buffer)->length;
269 if (psf2h(buffer)->flags & PSF2_HAS_UNICODE_TABLE)
270 has_table = 2;
271 charsize = psf2h(buffer)->charsize;
272 height = psf2h(buffer)->height;
273 width = psf2h(buffer)->width;
274 font += psf2h(buffer)->headersize;
275 } else
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000276#endif
Harald Becker8ce1dc02010-02-21 13:10:26 +0100277#if ENABLE_FEATURE_LOADFONT_RAW
Denys Vlasenkofb132e42010-10-29 11:46:52 +0200278 if (len == 9780) { /* file with three code pages? */
Harald Becker8ce1dc02010-02-21 13:10:26 +0100279 charsize = height = 16;
280 font += 40;
Denys Vlasenkofb132e42010-10-29 11:46:52 +0200281 } else if ((len & 0377) == 0) { /* bare font */
Harald Becker8ce1dc02010-02-21 13:10:26 +0100282 charsize = height = len / 256;
283 } else
284#endif
285 {
286 bb_error_msg_and_die("input file: bad length or unsupported font type");
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000287 }
288
Harald Becker8ce1dc02010-02-21 13:10:26 +0100289#if !defined(PIO_FONTX) || defined(__sparc__)
290 if (fontsize != 256)
291 bb_error_msg_and_die("only fontsize 256 supported");
292#endif
293
294 table = font + fontsize * charsize;
295 buffer += len;
296
297 if (table > buffer || (!has_table && table != buffer))
298 bb_error_msg_and_die("input file: bad length");
299
300 do_loadfont(fd, font, height, width, charsize, fontsize);
301
302 if (has_table)
303 do_loadtable(fd, table, buffer - table, fontsize, has_table - 1);
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000304}
305
Harald Becker8ce1dc02010-02-21 13:10:26 +0100306
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000307#if ENABLE_LOADFONT
308int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
309int loadfont_main(int argc UNUSED_PARAM, char **argv)
310{
311 size_t len;
Harald Becker8ce1dc02010-02-21 13:10:26 +0100312 unsigned char *buffer;
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000313
314 // no arguments allowed!
315 opt_complementary = "=0";
316 getopt32(argv, "");
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000317
318 /*
319 * We used to look at the length of the input file
320 * with stat(); now that we accept compressed files,
321 * just read the entire file.
322 */
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000323 len = 32*1024; // can't be larger
Harald Becker8ce1dc02010-02-21 13:10:26 +0100324 buffer = xmalloc_read(STDIN_FILENO, &len);
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000325 // xmalloc_open_zipped_read_close(filename, &len);
Harald Becker8ce1dc02010-02-21 13:10:26 +0100326 if (!buffer)
Denis Vlasenkod3d004d2006-10-27 09:02:31 +0000327 bb_perror_msg_and_die("error reading input font");
Harald Becker8ce1dc02010-02-21 13:10:26 +0100328 do_load(get_console_fd_or_die(), buffer, len);
Denis Vlasenkoe8a07882007-06-10 15:08:44 +0000329
330 return EXIT_SUCCESS;
331}
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000332#endif
333
Denis Vlasenko53f219e2008-09-16 19:35:42 +0000334#if ENABLE_SETFONT
335
Denis Vlasenko2bc5c032008-09-13 18:27:32 +0000336/*
337kbd-1.12:
338
339setfont [-O font+umap.orig] [-o font.orig] [-om cmap.orig]
340[-ou umap.orig] [-N] [font.new ...] [-m cmap] [-u umap] [-C console]
341[-hNN] [-v] [-V]
342
343-h NN Override font height
344-o file
345 Save previous font in file
346-O file
347 Save previous font and Unicode map in file
348-om file
349 Store console map in file
350-ou file
351 Save previous Unicode map in file
352-m file
353 Load console map or Unicode console map from file
354-u file
355 Load Unicode table describing the font from file
356 Example:
357 # cp866
358 0x00-0x7f idem
359 #
360 0x80 U+0410 # CYRILLIC CAPITAL LETTER A
361 0x81 U+0411 # CYRILLIC CAPITAL LETTER BE
362 0x82 U+0412 # CYRILLIC CAPITAL LETTER VE
363-C console
364 Set the font for the indicated console
365-v Verbose
366-V Version
367*/
368
Denis Vlasenko53f219e2008-09-16 19:35:42 +0000369#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
370static int ctoi(char *s)
371{
372 if (s[0] == '\'' && s[1] != '\0' && s[2] == '\'' && s[3] == '\0')
373 return s[1];
374 // U+ means 0x
375 if (s[0] == 'U' && s[1] == '+') {
376 s[0] = '0';
377 s[1] = 'x';
378 }
379 if (!isdigit(s[0]))
380 return -1;
381 return xstrtoul(s, 0);
382}
383#endif
384
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000385int setfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
386int setfont_main(int argc UNUSED_PARAM, char **argv)
387{
388 size_t len;
Denis Vlasenko53f219e2008-09-16 19:35:42 +0000389 unsigned opts;
390 int fd;
Harald Becker8ce1dc02010-02-21 13:10:26 +0100391 unsigned char *buffer;
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000392 char *mapfilename;
Denis Vlasenko53f219e2008-09-16 19:35:42 +0000393 const char *tty_name = CURRENT_TTY;
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000394
395 opt_complementary = "=1";
Denis Vlasenko53f219e2008-09-16 19:35:42 +0000396 opts = getopt32(argv, "m:C:", &mapfilename, &tty_name);
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000397 argv += optind;
398
Bernhard Reutner-Fischera4830872009-10-26 23:27:08 +0100399 fd = xopen_nonblocking(tty_name);
Denis Vlasenko53f219e2008-09-16 19:35:42 +0000400
401 if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
Denis Vlasenko72fa70a2008-09-18 01:01:02 +0000402 if (*argv[0] != '/') {
Denis Vlasenko53f219e2008-09-16 19:35:42 +0000403 // goto default fonts location. don't die if doesn't exist
404 chdir(CONFIG_DEFAULT_SETFONT_DIR "/consolefonts");
Denis Vlasenko53f219e2008-09-16 19:35:42 +0000405 }
406 }
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000407 // load font
408 len = 32*1024; // can't be larger
Harald Becker8ce1dc02010-02-21 13:10:26 +0100409 buffer = xmalloc_open_zipped_read_close(*argv, &len);
410 if (!buffer)
Denis Vlasenko72fa70a2008-09-18 01:01:02 +0000411 bb_simple_perror_msg_and_die(*argv);
Harald Becker8ce1dc02010-02-21 13:10:26 +0100412 do_load(fd, buffer, len);
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000413
414 // load the screen map, if any
Denis Vlasenko53f219e2008-09-16 19:35:42 +0000415 if (opts & 1) { // -m
416 unsigned mode = PIO_SCRNMAP;
417 void *map;
418
419 if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
Denis Vlasenko72fa70a2008-09-18 01:01:02 +0000420 if (mapfilename[0] != '/') {
Denis Vlasenko53f219e2008-09-16 19:35:42 +0000421 // goto default keymaps location
422 chdir(CONFIG_DEFAULT_SETFONT_DIR "/consoletrans");
423 }
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000424 }
Denis Vlasenko53f219e2008-09-16 19:35:42 +0000425 // fetch keymap
426 map = xmalloc_open_zipped_read_close(mapfilename, &len);
427 if (!map)
428 bb_simple_perror_msg_and_die(mapfilename);
429 // file size is 256 or 512 bytes? -> assume binary map
430 if (len == E_TABSZ || len == 2*E_TABSZ) {
431 if (len == 2*E_TABSZ)
432 mode = PIO_UNISCRNMAP;
433 }
434#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
435 // assume textual Unicode console maps:
436 // 0x00 U+0000 # NULL (NUL)
437 // 0x01 U+0001 # START OF HEADING (SOH)
438 // 0x02 U+0002 # START OF TEXT (STX)
439 // 0x03 U+0003 # END OF TEXT (ETX)
440 else {
441 int i;
442 char *token[2];
443 parser_t *parser;
444
445 if (ENABLE_FEATURE_CLEAN_UP)
446 free(map);
447 map = xmalloc(E_TABSZ * sizeof(unsigned short));
448
449#define unicodes ((unsigned short *)map)
450 // fill vanilla map
451 for (i = 0; i < E_TABSZ; i++)
452 unicodes[i] = 0xf000 + i;
453
454 parser = config_open(mapfilename);
455 while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL | PARSE_MIN_DIE)) {
456 // parse code/value pair
457 int a = ctoi(token[0]);
458 int b = ctoi(token[1]);
459 if (a < 0 || a >= E_TABSZ
460 || b < 0 || b > 65535
461 ) {
462 bb_error_msg_and_die("map format");
463 }
464 // patch map
465 unicodes[a] = b;
466 // unicode character is met?
467 if (b > 255)
468 mode = PIO_UNISCRNMAP;
469 }
470 if (ENABLE_FEATURE_CLEAN_UP)
471 config_close(parser);
472
473 if (mode != PIO_UNISCRNMAP) {
474#define asciis ((unsigned char *)map)
475 for (i = 0; i < E_TABSZ; i++)
476 asciis[i] = unicodes[i];
477#undef asciis
478 }
479#undef unicodes
480 }
481#endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
482
483 // do set screen map
484 xioctl(fd, mode, map);
485
486 if (ENABLE_FEATURE_CLEAN_UP)
487 free(map);
Denis Vlasenkoc8d02aa2008-08-17 14:12:26 +0000488 }
489
490 return EXIT_SUCCESS;
491}
492#endif