Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 2 | /* |
| 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.) |
| 9 | */ |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 10 | #include "libbb.h" |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 11 | #include <sys/kd.h> |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 12 | |
Denis Vlasenko | eef6077 | 2008-09-20 18:14:13 +0000 | [diff] [blame] | 13 | #ifndef KDFONTOP |
| 14 | #define KDFONTOP 0x4B72 |
| 15 | struct console_font_op { |
| 16 | unsigned op; /* KD_FONT_OP_* */ |
| 17 | unsigned flags; /* KD_FONT_FLAG_* */ |
| 18 | unsigned width, height; |
| 19 | unsigned charcount; |
| 20 | unsigned char *data; /* font data with height fixed to 32 */ |
| 21 | }; |
| 22 | |
| 23 | #define KD_FONT_OP_SET 0 /* Set font */ |
| 24 | #define KD_FONT_OP_GET 1 /* Get font */ |
| 25 | #define KD_FONT_OP_SET_DEFAULT 2 /* Set font to default, |
| 26 | data points to name / NULL */ |
| 27 | #define KD_FONT_OP_COPY 3 /* Copy from another console */ |
| 28 | |
| 29 | #define KD_FONT_FLAG_OLD 0x80000000 /* Invoked via old interface */ |
| 30 | #define KD_FONT_FLAG_DONT_RECALC 1 /* Don't call adjust_height() */ |
| 31 | /* (Used internally for PIO_FONT support) */ |
| 32 | #endif /* KDFONTOP */ |
| 33 | |
| 34 | |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 35 | enum { |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 36 | PSF_MAGIC1 = 0x36, |
| 37 | PSF_MAGIC2 = 0x04, |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 38 | |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 39 | PSF_MODE512 = 0x01, |
| 40 | PSF_MODEHASTAB = 0x02, |
| 41 | PSF_MAXMODE = 0x03, |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 42 | PSF_SEPARATOR = 0xffff |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 43 | }; |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 44 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 45 | struct psf_header { |
Denis Vlasenko | e8a0788 | 2007-06-10 15:08:44 +0000 | [diff] [blame] | 46 | unsigned char magic1, magic2; /* Magic number */ |
| 47 | unsigned char mode; /* PSF font mode */ |
| 48 | unsigned char charsize; /* Character size */ |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 51 | #define PSF_MAGIC_OK(x) ((x)->magic1 == PSF_MAGIC1 && (x)->magic2 == PSF_MAGIC2) |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 52 | |
Eric Andersen | 5e67887 | 2006-01-30 19:48:23 +0000 | [diff] [blame] | 53 | static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 54 | { |
Denis Vlasenko | e8a0788 | 2007-06-10 15:08:44 +0000 | [diff] [blame] | 55 | char *buf; |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 56 | int i; |
| 57 | |
Matt Kraai | ef5529b | 2000-10-25 17:00:36 +0000 | [diff] [blame] | 58 | if (unit < 1 || unit > 32) |
Denis Vlasenko | d3d004d | 2006-10-27 09:02:31 +0000 | [diff] [blame] | 59 | bb_error_msg_and_die("bad character size %d", unit); |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 60 | |
Denis Vlasenko | e8a0788 | 2007-06-10 15:08:44 +0000 | [diff] [blame] | 61 | buf = xzalloc(16 * 1024); |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 62 | for (i = 0; i < fontsize; i++) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 63 | memcpy(buf + (32 * i), inbuf + (unit * i), unit); |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 64 | |
Denis Vlasenko | eef6077 | 2008-09-20 18:14:13 +0000 | [diff] [blame] | 65 | { /* KDFONTOP */ |
| 66 | struct console_font_op cfo; |
| 67 | |
| 68 | cfo.op = KD_FONT_OP_SET; |
| 69 | cfo.flags = 0; |
| 70 | cfo.width = 8; |
| 71 | cfo.height = unit; |
| 72 | cfo.charcount = fontsize; |
| 73 | cfo.data = (void*)buf; |
| 74 | #if 0 |
| 75 | if (!ioctl_or_perror(fd, KDFONTOP, &cfo, "KDFONTOP ioctl failed (will try PIO_FONTX)")) |
| 76 | goto ret; /* success */ |
| 77 | #else |
| 78 | xioctl(fd, KDFONTOP, &cfo); |
| 79 | #endif |
| 80 | } |
| 81 | |
| 82 | #if 0 |
| 83 | /* These ones do not honour -C tty (they set font on current tty regardless) */ |
Denis Vlasenko | e8a0788 | 2007-06-10 15:08:44 +0000 | [diff] [blame] | 84 | #if defined(PIO_FONTX) && !defined(__sparc__) |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 85 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 86 | struct consolefontdesc cfd; |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 87 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 88 | cfd.charcount = fontsize; |
| 89 | cfd.charheight = unit; |
| 90 | cfd.chardata = buf; |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 91 | |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 92 | if (!ioctl_or_perror(fd, PIO_FONTX, &cfd, "PIO_FONTX ioctl failed (will try PIO_FONT)")) |
Denis Vlasenko | eef6077 | 2008-09-20 18:14:13 +0000 | [diff] [blame] | 93 | goto ret; /* success */ |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 94 | } |
| 95 | #endif |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 96 | xioctl(fd, PIO_FONT, buf); |
Denis Vlasenko | e8a0788 | 2007-06-10 15:08:44 +0000 | [diff] [blame] | 97 | ret: |
Denis Vlasenko | eef6077 | 2008-09-20 18:14:13 +0000 | [diff] [blame] | 98 | #endif /* 0 */ |
Denis Vlasenko | e8a0788 | 2007-06-10 15:08:44 +0000 | [diff] [blame] | 99 | free(buf); |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 102 | static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 103 | { |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 104 | struct unimapinit advice; |
| 105 | struct unimapdesc ud; |
| 106 | struct unipair *up; |
| 107 | int ct = 0, maxct; |
| 108 | int glyph; |
Denis Vlasenko | 2870301 | 2006-12-19 20:32:02 +0000 | [diff] [blame] | 109 | uint16_t unicode; |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 110 | |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 111 | maxct = tailsz; /* more than enough */ |
Denis Vlasenko | b95636c | 2006-12-19 23:36:04 +0000 | [diff] [blame] | 112 | up = xmalloc(maxct * sizeof(struct unipair)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 113 | |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 114 | for (glyph = 0; glyph < fontsize; glyph++) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 115 | while (tailsz >= 2) { |
Denis Vlasenko | 2870301 | 2006-12-19 20:32:02 +0000 | [diff] [blame] | 116 | unicode = (((uint16_t) inbuf[1]) << 8) + inbuf[0]; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 117 | tailsz -= 2; |
| 118 | inbuf += 2; |
| 119 | if (unicode == PSF_SEPARATOR) |
| 120 | break; |
| 121 | up[ct].unicode = unicode; |
| 122 | up[ct].fontpos = glyph; |
| 123 | ct++; |
| 124 | } |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP |
| 128 | this printf did not work on many kernels */ |
| 129 | |
| 130 | advice.advised_hashsize = 0; |
| 131 | advice.advised_hashstep = 0; |
| 132 | advice.advised_hashlevel = 0; |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 133 | xioctl(fd, PIO_UNIMAPCLR, &advice); |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 134 | ud.entry_ct = ct; |
| 135 | ud.entries = up; |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 136 | xioctl(fd, PIO_UNIMAP, &ud); |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 139 | static void do_load(int fd, struct psf_header *psfhdr, size_t len) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 140 | { |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 141 | int unit; |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 142 | int fontsize; |
| 143 | int hastable; |
| 144 | unsigned head0, head = head; |
| 145 | |
| 146 | /* test for psf first */ |
| 147 | if (len >= sizeof(struct psf_header) && PSF_MAGIC_OK(psfhdr)) { |
| 148 | if (psfhdr->mode > PSF_MAXMODE) |
| 149 | bb_error_msg_and_die("unsupported psf file mode"); |
| 150 | fontsize = ((psfhdr->mode & PSF_MODE512) ? 512 : 256); |
| 151 | #if !defined(PIO_FONTX) || defined(__sparc__) |
| 152 | if (fontsize != 256) |
| 153 | bb_error_msg_and_die("only fontsize 256 supported"); |
| 154 | #endif |
| 155 | hastable = (psfhdr->mode & PSF_MODEHASTAB); |
| 156 | unit = psfhdr->charsize; |
| 157 | head0 = sizeof(struct psf_header); |
| 158 | |
| 159 | head = head0 + fontsize * unit; |
| 160 | if (head > len || (!hastable && head != len)) |
| 161 | bb_error_msg_and_die("input file: bad length"); |
| 162 | } else { |
| 163 | /* file with three code pages? */ |
| 164 | if (len == 9780) { |
| 165 | head0 = 40; |
| 166 | unit = 16; |
| 167 | } else { |
| 168 | /* bare font */ |
| 169 | if (len & 0377) |
| 170 | bb_error_msg_and_die("input file: bad length"); |
| 171 | head0 = 0; |
| 172 | unit = len / 256; |
| 173 | } |
| 174 | fontsize = 256; |
| 175 | hastable = 0; |
| 176 | } |
| 177 | |
| 178 | do_loadfont(fd, (unsigned char *)psfhdr + head0, unit, fontsize); |
| 179 | if (hastable) |
| 180 | do_loadtable(fd, (unsigned char *)psfhdr + head, len - head, fontsize); |
| 181 | } |
| 182 | |
| 183 | #if ENABLE_LOADFONT |
| 184 | int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 185 | int loadfont_main(int argc UNUSED_PARAM, char **argv) |
| 186 | { |
| 187 | size_t len; |
| 188 | struct psf_header *psfhdr; |
| 189 | |
| 190 | // no arguments allowed! |
| 191 | opt_complementary = "=0"; |
| 192 | getopt32(argv, ""); |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 193 | |
| 194 | /* |
| 195 | * We used to look at the length of the input file |
| 196 | * with stat(); now that we accept compressed files, |
| 197 | * just read the entire file. |
| 198 | */ |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 199 | len = 32*1024; // can't be larger |
| 200 | psfhdr = (struct psf_header *) xmalloc_read(STDIN_FILENO, &len); |
| 201 | // xmalloc_open_zipped_read_close(filename, &len); |
| 202 | if (!psfhdr) |
Denis Vlasenko | d3d004d | 2006-10-27 09:02:31 +0000 | [diff] [blame] | 203 | bb_perror_msg_and_die("error reading input font"); |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 204 | do_load(get_console_fd_or_die(), psfhdr, len); |
Denis Vlasenko | e8a0788 | 2007-06-10 15:08:44 +0000 | [diff] [blame] | 205 | |
| 206 | return EXIT_SUCCESS; |
| 207 | } |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 208 | #endif |
| 209 | |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 210 | #if ENABLE_SETFONT |
| 211 | |
Denis Vlasenko | 2bc5c03 | 2008-09-13 18:27:32 +0000 | [diff] [blame] | 212 | /* |
| 213 | kbd-1.12: |
| 214 | |
| 215 | setfont [-O font+umap.orig] [-o font.orig] [-om cmap.orig] |
| 216 | [-ou umap.orig] [-N] [font.new ...] [-m cmap] [-u umap] [-C console] |
| 217 | [-hNN] [-v] [-V] |
| 218 | |
| 219 | -h NN Override font height |
| 220 | -o file |
| 221 | Save previous font in file |
| 222 | -O file |
| 223 | Save previous font and Unicode map in file |
| 224 | -om file |
| 225 | Store console map in file |
| 226 | -ou file |
| 227 | Save previous Unicode map in file |
| 228 | -m file |
| 229 | Load console map or Unicode console map from file |
| 230 | -u file |
| 231 | Load Unicode table describing the font from file |
| 232 | Example: |
| 233 | # cp866 |
| 234 | 0x00-0x7f idem |
| 235 | # |
| 236 | 0x80 U+0410 # CYRILLIC CAPITAL LETTER A |
| 237 | 0x81 U+0411 # CYRILLIC CAPITAL LETTER BE |
| 238 | 0x82 U+0412 # CYRILLIC CAPITAL LETTER VE |
| 239 | -C console |
| 240 | Set the font for the indicated console |
| 241 | -v Verbose |
| 242 | -V Version |
| 243 | */ |
| 244 | |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 245 | #if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP |
| 246 | static int ctoi(char *s) |
| 247 | { |
| 248 | if (s[0] == '\'' && s[1] != '\0' && s[2] == '\'' && s[3] == '\0') |
| 249 | return s[1]; |
| 250 | // U+ means 0x |
| 251 | if (s[0] == 'U' && s[1] == '+') { |
| 252 | s[0] = '0'; |
| 253 | s[1] = 'x'; |
| 254 | } |
| 255 | if (!isdigit(s[0])) |
| 256 | return -1; |
| 257 | return xstrtoul(s, 0); |
| 258 | } |
| 259 | #endif |
| 260 | |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 261 | int setfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 262 | int setfont_main(int argc UNUSED_PARAM, char **argv) |
| 263 | { |
| 264 | size_t len; |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 265 | unsigned opts; |
| 266 | int fd; |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 267 | struct psf_header *psfhdr; |
| 268 | char *mapfilename; |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 269 | const char *tty_name = CURRENT_TTY; |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 270 | |
| 271 | opt_complementary = "=1"; |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 272 | opts = getopt32(argv, "m:C:", &mapfilename, &tty_name); |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 273 | argv += optind; |
| 274 | |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 275 | fd = xopen(tty_name, O_NONBLOCK); |
| 276 | |
| 277 | if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not "" |
Denis Vlasenko | 72fa70a | 2008-09-18 01:01:02 +0000 | [diff] [blame] | 278 | if (*argv[0] != '/') { |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 279 | // goto default fonts location. don't die if doesn't exist |
| 280 | chdir(CONFIG_DEFAULT_SETFONT_DIR "/consolefonts"); |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 281 | } |
| 282 | } |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 283 | // load font |
| 284 | len = 32*1024; // can't be larger |
| 285 | psfhdr = (struct psf_header *) xmalloc_open_zipped_read_close(*argv, &len); |
Denis Vlasenko | 72fa70a | 2008-09-18 01:01:02 +0000 | [diff] [blame] | 286 | if (!psfhdr) |
| 287 | bb_simple_perror_msg_and_die(*argv); |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 288 | do_load(fd, psfhdr, len); |
| 289 | |
| 290 | // load the screen map, if any |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 291 | if (opts & 1) { // -m |
| 292 | unsigned mode = PIO_SCRNMAP; |
| 293 | void *map; |
| 294 | |
| 295 | if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not "" |
Denis Vlasenko | 72fa70a | 2008-09-18 01:01:02 +0000 | [diff] [blame] | 296 | if (mapfilename[0] != '/') { |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 297 | // goto default keymaps location |
| 298 | chdir(CONFIG_DEFAULT_SETFONT_DIR "/consoletrans"); |
| 299 | } |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 300 | } |
Denis Vlasenko | 53f219e | 2008-09-16 19:35:42 +0000 | [diff] [blame] | 301 | // fetch keymap |
| 302 | map = xmalloc_open_zipped_read_close(mapfilename, &len); |
| 303 | if (!map) |
| 304 | bb_simple_perror_msg_and_die(mapfilename); |
| 305 | // file size is 256 or 512 bytes? -> assume binary map |
| 306 | if (len == E_TABSZ || len == 2*E_TABSZ) { |
| 307 | if (len == 2*E_TABSZ) |
| 308 | mode = PIO_UNISCRNMAP; |
| 309 | } |
| 310 | #if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP |
| 311 | // assume textual Unicode console maps: |
| 312 | // 0x00 U+0000 # NULL (NUL) |
| 313 | // 0x01 U+0001 # START OF HEADING (SOH) |
| 314 | // 0x02 U+0002 # START OF TEXT (STX) |
| 315 | // 0x03 U+0003 # END OF TEXT (ETX) |
| 316 | else { |
| 317 | int i; |
| 318 | char *token[2]; |
| 319 | parser_t *parser; |
| 320 | |
| 321 | if (ENABLE_FEATURE_CLEAN_UP) |
| 322 | free(map); |
| 323 | map = xmalloc(E_TABSZ * sizeof(unsigned short)); |
| 324 | |
| 325 | #define unicodes ((unsigned short *)map) |
| 326 | // fill vanilla map |
| 327 | for (i = 0; i < E_TABSZ; i++) |
| 328 | unicodes[i] = 0xf000 + i; |
| 329 | |
| 330 | parser = config_open(mapfilename); |
| 331 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL | PARSE_MIN_DIE)) { |
| 332 | // parse code/value pair |
| 333 | int a = ctoi(token[0]); |
| 334 | int b = ctoi(token[1]); |
| 335 | if (a < 0 || a >= E_TABSZ |
| 336 | || b < 0 || b > 65535 |
| 337 | ) { |
| 338 | bb_error_msg_and_die("map format"); |
| 339 | } |
| 340 | // patch map |
| 341 | unicodes[a] = b; |
| 342 | // unicode character is met? |
| 343 | if (b > 255) |
| 344 | mode = PIO_UNISCRNMAP; |
| 345 | } |
| 346 | if (ENABLE_FEATURE_CLEAN_UP) |
| 347 | config_close(parser); |
| 348 | |
| 349 | if (mode != PIO_UNISCRNMAP) { |
| 350 | #define asciis ((unsigned char *)map) |
| 351 | for (i = 0; i < E_TABSZ; i++) |
| 352 | asciis[i] = unicodes[i]; |
| 353 | #undef asciis |
| 354 | } |
| 355 | #undef unicodes |
| 356 | } |
| 357 | #endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP |
| 358 | |
| 359 | // do set screen map |
| 360 | xioctl(fd, mode, map); |
| 361 | |
| 362 | if (ENABLE_FEATURE_CLEAN_UP) |
| 363 | free(map); |
Denis Vlasenko | c8d02aa | 2008-08-17 14:12:26 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | return EXIT_SUCCESS; |
| 367 | } |
| 368 | #endif |