bdfload.c revision 426ebb7f
1426ebb7fSmacallan/* $NetBSD: bdfload.c,v 1.9 2022/08/23 18:11:43 macallan Exp $ */ 2d5f9d0dbSmacallan 3d5f9d0dbSmacallan/* 4d5f9d0dbSmacallan * Copyright (c) 2018 Michael Lorenz 5d5f9d0dbSmacallan * All rights reserved. 6d5f9d0dbSmacallan * 7d5f9d0dbSmacallan * Redistribution and use in source and binary forms, with or without 8d5f9d0dbSmacallan * modification, are permitted provided that the following conditions 9d5f9d0dbSmacallan * are met: 10d5f9d0dbSmacallan * 1. Redistributions of source code must retain the above copyright 11d5f9d0dbSmacallan * notice, this list of conditions and the following disclaimer. 12d5f9d0dbSmacallan * 2. Redistributions in binary form must reproduce the above copyright 13d5f9d0dbSmacallan * notice, this list of conditions and the following disclaimer in the 14d5f9d0dbSmacallan * documentation and/or other materials provided with the distribution. 15d5f9d0dbSmacallan * 16d5f9d0dbSmacallan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17d5f9d0dbSmacallan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18d5f9d0dbSmacallan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19d5f9d0dbSmacallan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20d5f9d0dbSmacallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21d5f9d0dbSmacallan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22d5f9d0dbSmacallan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23d5f9d0dbSmacallan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24d5f9d0dbSmacallan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25d5f9d0dbSmacallan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26d5f9d0dbSmacallan */ 27d5f9d0dbSmacallan 28d5f9d0dbSmacallan/* 29d5f9d0dbSmacallan * a crude BDF loader for wsdisplay 30d5f9d0dbSmacallan */ 31d5f9d0dbSmacallan 32d5f9d0dbSmacallan#include <stdlib.h> 33d5f9d0dbSmacallan#include <stdio.h> 34d5f9d0dbSmacallan#include <fcntl.h> 35d5f9d0dbSmacallan#include <unistd.h> 36d5f9d0dbSmacallan#include <string.h> 37d5f9d0dbSmacallan#include <errno.h> 38d5f9d0dbSmacallan#include <ctype.h> 39d5f9d0dbSmacallan#include <sys/ioctl.h> 40d5f9d0dbSmacallan#include <err.h> 41d5f9d0dbSmacallan 42d5f9d0dbSmacallan#include <dev/wscons/wsconsio.h> 43d5f9d0dbSmacallan 442b154882Suwe/* 452b154882Suwe * wsdisplay_font but with strings embedded and integer fields in 462b154882Suwe * little endian 472b154882Suwe */ 482b154882Suwestruct wsfthdr { 492b154882Suwe char magic[4]; /* "WSFT" */ 502b154882Suwe char name[64]; 512b154882Suwe uint32_t firstchar; 522b154882Suwe uint32_t numchars; 532b154882Suwe uint32_t encoding; 542b154882Suwe uint32_t fontwidth; 552b154882Suwe uint32_t fontheight; 562b154882Suwe uint32_t stride; 572b154882Suwe uint32_t bitorder; 582b154882Suwe uint32_t byteorder; 592b154882Suwe}; 602b154882Suwe 612b154882Suwe 622b154882Suweconst struct encmap { 632b154882Suwe const char *name; 642b154882Suwe int encoding; 652b154882Suwe} encmap[] = { 662b154882Suwe { "cp437", WSDISPLAY_FONTENC_IBM }, 672b154882Suwe { "ibm", WSDISPLAY_FONTENC_IBM }, 682b154882Suwe { "iso", WSDISPLAY_FONTENC_ISO }, 692b154882Suwe { "iso-8859-1", WSDISPLAY_FONTENC_ISO }, 702b154882Suwe { "iso-8859-2", WSDISPLAY_FONTENC_ISO2 }, 712b154882Suwe { "iso-8859-7", WSDISPLAY_FONTENC_ISO7 }, 722b154882Suwe { "iso2", WSDISPLAY_FONTENC_ISO2 }, 732b154882Suwe { "iso7", WSDISPLAY_FONTENC_ISO7 }, 742b154882Suwe { "iso8859-1", WSDISPLAY_FONTENC_ISO }, 752b154882Suwe { "iso8859-2", WSDISPLAY_FONTENC_ISO2 }, 762b154882Suwe { "iso8859-7", WSDISPLAY_FONTENC_ISO7 }, 772b154882Suwe { "koi8-r", WSDISPLAY_FONTENC_KOI8_R }, 782b154882Suwe { "koi8r", WSDISPLAY_FONTENC_KOI8_R }, 792b154882Suwe { "latin-1", WSDISPLAY_FONTENC_ISO }, 802b154882Suwe { "latin-2", WSDISPLAY_FONTENC_ISO2 }, 812b154882Suwe { "latin1", WSDISPLAY_FONTENC_ISO }, 822b154882Suwe { "latin2", WSDISPLAY_FONTENC_ISO2 }, 832b154882Suwe { "pcvt", WSDISPLAY_FONTENC_PCVT }, 842b154882Suwe { NULL, -1 } 852b154882Suwe}; 862b154882Suwe 872b154882Suweconst char * const encname[] = { 882b154882Suwe#define _ENC(_e) [_e] = #_e 892b154882Suwe _ENC(WSDISPLAY_FONTENC_ISO), 902b154882Suwe _ENC(WSDISPLAY_FONTENC_IBM), 912b154882Suwe _ENC(WSDISPLAY_FONTENC_PCVT), 922b154882Suwe _ENC(WSDISPLAY_FONTENC_ISO7), 932b154882Suwe _ENC(WSDISPLAY_FONTENC_ISO2), 942b154882Suwe _ENC(WSDISPLAY_FONTENC_KOI8_R), 952b154882Suwe}; 962b154882Suwe 972b154882Suwe 982b154882Suweconst char *ofile = NULL; 992b154882Suweint encoding = -1; 10061348eb3Smacallanint verbose = 0; 101554a5d78Smacallanint dump = 0; 1022d60533cSmacallanint header = 0; 1032b154882Suwe 104554a5d78Smacallanvoid 105554a5d78Smacallandump_line(char *gptr, int stride) 106554a5d78Smacallan{ 107554a5d78Smacallan int i, j, msk, c; 108554a5d78Smacallan 109554a5d78Smacallan for (i = 0; i < stride; i++) { 110554a5d78Smacallan c = gptr[i]; 111554a5d78Smacallan msk = 0x80; 112554a5d78Smacallan for (j = 0; j < 8; j++) { 113554a5d78Smacallan putchar((c & msk) != 0 ? '#' : ' '); 114554a5d78Smacallan msk = msk >> 1; 115554a5d78Smacallan } 116554a5d78Smacallan } 117ec211365Smacallan printf("\n"); 118554a5d78Smacallan} 119554a5d78Smacallan 1202d60533cSmacallanvoid 1212d60533cSmacallanwrite_wsf(const char *oname, struct wsdisplay_font *f, char *buffer, int buflen) 1222d60533cSmacallan{ 1232d60533cSmacallan struct wsfthdr h; 1242d60533cSmacallan 1252d60533cSmacallan memset(&h, 0, sizeof(h)); 1262d60533cSmacallan strncpy(h.magic, "WSFT", sizeof(h.magic)); 1272d60533cSmacallan strncpy(h.name, f->name, sizeof(h.name)); 1282d60533cSmacallan h.firstchar = htole32(f->firstchar); 1292d60533cSmacallan h.numchars = htole32(f->numchars); 1302d60533cSmacallan h.encoding = htole32(f->encoding); 1312d60533cSmacallan h.fontwidth = htole32(f->fontwidth); 1322d60533cSmacallan h.fontheight = htole32(f->fontheight); 1332d60533cSmacallan h.stride = htole32(f->stride); 1342d60533cSmacallan h.bitorder = htole32(f->bitorder); 1352d60533cSmacallan h.byteorder = htole32(f->byteorder); 1362d60533cSmacallan 1372d60533cSmacallan int wsfd = open(ofile, O_WRONLY | O_CREAT | O_TRUNC, 0644); 1382d60533cSmacallan if (wsfd < 0) 1392d60533cSmacallan err(EXIT_FAILURE, "%s", ofile); 1402d60533cSmacallan 1412d60533cSmacallan ssize_t nwritten; 1422d60533cSmacallan nwritten = write(wsfd, &h, sizeof(h)); 1432d60533cSmacallan if (nwritten < 0) 1442d60533cSmacallan err(EXIT_FAILURE, "%s", ofile); 1452d60533cSmacallan if (nwritten != sizeof(h)) 1462d60533cSmacallan errx(EXIT_FAILURE, "%s: partial write", ofile); 1472d60533cSmacallan 1482d60533cSmacallan nwritten = write(wsfd, buffer, buflen); 1492d60533cSmacallan if (nwritten < 0) 1502d60533cSmacallan err(EXIT_FAILURE, "%s", ofile); 1512d60533cSmacallan if (nwritten != buflen) 1522d60533cSmacallan errx(EXIT_FAILURE, "%s: partial write", ofile); 1532d60533cSmacallan close(wsfd); 1542d60533cSmacallan} 1552d60533cSmacallan 1562d60533cSmacallanint 1572d60533cSmacallanwrite_header(const char *filename, struct wsdisplay_font *f, char *name, 1582d60533cSmacallan char *buffer, int buflen) 1592d60533cSmacallan{ 1602d60533cSmacallan FILE *output; 1612d60533cSmacallan int i, j, x, y, idx; 1622d60533cSmacallan char fontname[64], c, msk; 1632d60533cSmacallan 1642d60533cSmacallan /* now output as a header file */ 1652d60533cSmacallan snprintf(fontname, sizeof(fontname), "%s_%dx%d", name, 1662d60533cSmacallan f->fontwidth, f->fontheight); 1672d60533cSmacallan for (i = 0; i < strlen(fontname); i++) { 1682d60533cSmacallan if (isblank((int)fontname[i])) 1692d60533cSmacallan fontname[i]='_'; 1702d60533cSmacallan } 1712d60533cSmacallan if ((output = fopen(filename, "w")) == NULL) { 1722d60533cSmacallan fprintf(stderr, "Can't open output file %s\n", filename); 1732d60533cSmacallan return -1; 1742d60533cSmacallan } 1752d60533cSmacallan fprintf(output, "static u_char %s_data[];\n", fontname); 1762d60533cSmacallan fprintf(output, "\n"); 1772d60533cSmacallan fprintf(output, "static struct wsdisplay_font %s = {\n", fontname); 1782d60533cSmacallan fprintf(output, "\t\"%s\",\t\t\t/* typeface name */\n", name); 1792d60533cSmacallan fprintf(output, "\t%d,\t\t\t\t/* firstchar */\n", f->firstchar); 1802d60533cSmacallan fprintf(output, "\t%d,\t\t\t\t/* numchars */\n", f->numchars); 1812d60533cSmacallan fprintf(output, "\t%d,\t\t\t\t/* encoding */\n", f->encoding); 1822d60533cSmacallan fprintf(output, "\t%d,\t\t\t\t/* fontwidth */\n", f->fontwidth); 1832d60533cSmacallan fprintf(output, "\t%d,\t\t\t\t/* fontheight */\n", f->fontheight); 1842d60533cSmacallan fprintf(output, "\t%d,\t\t\t\t/* stride */\n", f->stride); 1852d60533cSmacallan fprintf(output, "\tWSDISPLAY_FONTORDER_L2R,\t/* bit order */\n"); 1862d60533cSmacallan fprintf(output, "\tWSDISPLAY_FONTORDER_L2R,\t/* byte order */\n"); 1872d60533cSmacallan fprintf(output, "\t%s_data\t\t/* data */\n", fontname); 1882d60533cSmacallan fprintf(output, "};\n\n"); 1892d60533cSmacallan fprintf(output, "static u_char %s_data[] = {\n", fontname); 1902d60533cSmacallan for (i = f->firstchar; i < f->firstchar + f->numchars; i++) { 1912d60533cSmacallan fprintf(output, "\t/* %d */\n", i); 1922d60533cSmacallan idx = i * f->stride * f->fontheight; 1932d60533cSmacallan for (y = 0; y < f->fontheight; y++) { 1942d60533cSmacallan for (x = 0; x < f->stride; x++) { 1952d60533cSmacallan fprintf(output, "0x%02x, ",buffer[idx + x]); 1962d60533cSmacallan } 1972d60533cSmacallan fprintf(output, "/* "); 1982d60533cSmacallan for (x = 0; x < f->stride; x++) { 1992d60533cSmacallan c = buffer[idx + x]; 2002d60533cSmacallan msk = 0x80; 2012d60533cSmacallan for (j = 0; j < 8; j++) { 202426ebb7fSmacallan fprintf(output, "%s", 203426ebb7fSmacallan (c & msk) != 0 ? "[]" : ". "); 2042d60533cSmacallan msk = msk >> 1; 2052d60533cSmacallan } 2062d60533cSmacallan } 2072d60533cSmacallan fprintf(output, " */\n"); 2082d60533cSmacallan 2092d60533cSmacallan idx += f->stride; 2102d60533cSmacallan } 2112d60533cSmacallan } 2122d60533cSmacallan fprintf(output, "};\n"); 2132d60533cSmacallan fclose(output); 2142d60533cSmacallan return 0; 2152d60533cSmacallan} 2162d60533cSmacallan 217d5f9d0dbSmacallanvoid 218d5f9d0dbSmacallaninterpret(FILE *foo) 219d5f9d0dbSmacallan{ 2202b154882Suwe char line[128], *arg, name[64] = "foop", *buffer; 2212b154882Suwe int buflen = -1; 222d5f9d0dbSmacallan int len, in_char = 0, current = -1, stride = 0, charsize = 0; 223d5f9d0dbSmacallan int width, height, x, y, num; 224d5f9d0dbSmacallan int first = 255, last = 0; 225d5f9d0dbSmacallan int left, top, lines; 226d5f9d0dbSmacallan int bl = 255, bt = 255, br = -1, bb = -1; 227d5f9d0dbSmacallan struct wsdisplay_font f; 2282b154882Suwe int status; 229d5f9d0dbSmacallan 230d5f9d0dbSmacallan while (fgets(line, sizeof(line), foo) != NULL) { 231d5f9d0dbSmacallan int i = 0; 232d5f9d0dbSmacallan /* separate keyword from parameters */ 233d5f9d0dbSmacallan len = strlen(line); 234d5f9d0dbSmacallan while (!isspace(line[i]) && (i < len)) i++; 235d5f9d0dbSmacallan line[i] = 0; 236d5f9d0dbSmacallan arg = &line[i + 1]; 237d5f9d0dbSmacallan i = 0; 238d5f9d0dbSmacallan len = strlen(arg); 239d5f9d0dbSmacallan /* get rid of garbage */ 240d5f9d0dbSmacallan while ((!iscntrl(arg[i])) && (arg[i] != 0)) { 241d5f9d0dbSmacallan i++; 242d5f9d0dbSmacallan } 243d5f9d0dbSmacallan arg[i] = 0; 244d5f9d0dbSmacallan if (strcmp(line, "FAMILY_NAME") == 0) { 245d5f9d0dbSmacallan /* cut off quotation marks */ 246d5f9d0dbSmacallan strncpy(name, arg + 1, 64); 247d5f9d0dbSmacallan name[strlen(name) - 1] = 0; 24861348eb3Smacallan if (verbose) printf("name: %s\n", name); 249d5f9d0dbSmacallan } else if (strcmp(line, "FONTBOUNDINGBOX") == 0) { 250d5f9d0dbSmacallan int res; 251d5f9d0dbSmacallan res = sscanf(arg, "%d %d %d %d", 252d5f9d0dbSmacallan &width, &height, &x, &y); 253d5f9d0dbSmacallan stride = (width + 7) >> 3; 25461348eb3Smacallan if (verbose) printf("box %d x %d\n", width, height); 255d5f9d0dbSmacallan if (stride > 2) { 25661348eb3Smacallan err(EXIT_FAILURE, 25761348eb3Smacallan "no fonts wider than 16 work for now\n"); 258d5f9d0dbSmacallan } 259d5f9d0dbSmacallan charsize = height * stride; 260d5f9d0dbSmacallan buflen = 256 * charsize; 2612b154882Suwe buffer = calloc(1, buflen); 262d5f9d0dbSmacallan if (buffer == NULL) { 26361348eb3Smacallan err(EXIT_FAILURE, 26461348eb3Smacallan "failed to allocate %dKB for glyphs\n", 265d5f9d0dbSmacallan buflen); 266ce18d260Suwe } 267d5f9d0dbSmacallan } else if (strcmp(line, "CHARS") == 0) { 268d5f9d0dbSmacallan if (sscanf(arg, "%d", &num) == 1) 26961348eb3Smacallan if (verbose) 27061348eb3Smacallan printf("number of characters: %d\n", num); 271d5f9d0dbSmacallan } else if (strcmp(line, "STARTCHAR") == 0) { 272d5f9d0dbSmacallan in_char = 1; 273d5f9d0dbSmacallan } else if (strcmp(line, "ENDCHAR") == 0) { 274d5f9d0dbSmacallan in_char = 0; 275d5f9d0dbSmacallan current = -1; 276d5f9d0dbSmacallan } else if (strcmp(line, "ENCODING") == 0) { 277d5f9d0dbSmacallan if (sscanf(arg, "%d", ¤t) == 1) { 278d5f9d0dbSmacallan if (current >= 0 && current < 256) { 279d5f9d0dbSmacallan if (current < first) first = current; 280d5f9d0dbSmacallan if (current > last) last = current; 281554a5d78Smacallan if (dump) printf("glyph %d\n", current); 282d5f9d0dbSmacallan } 283d5f9d0dbSmacallan } 284d5f9d0dbSmacallan } else if (strcmp(line, "BBX") == 0) { 285d5f9d0dbSmacallan int cx, cy, cwi, che; 286d5f9d0dbSmacallan if (sscanf(arg, "%d %d %d %d", &cwi, &che, &cx, &cy) 287d5f9d0dbSmacallan == 4) { 288d5f9d0dbSmacallan left = cx; 289d5f9d0dbSmacallan lines = che; 290d5f9d0dbSmacallan top = height + y - che - cy; 291d5f9d0dbSmacallan if (left < bl) bl = left; 292d5f9d0dbSmacallan if (top < bt) bt = top; 293d5f9d0dbSmacallan if ((left + cwi) > br) br = left + cwi; 294d5f9d0dbSmacallan if ((top + che) > bb) bb = top + che; 295554a5d78Smacallan if(dump && verbose) printf("top %d left %d\n", top, left); 296d5f9d0dbSmacallan } 297d5f9d0dbSmacallan } else if (strcmp(line, "BITMAP") == 0) { 298d5f9d0dbSmacallan int i, j, k, l; 299d5f9d0dbSmacallan char num[32]; 300d5f9d0dbSmacallan char *gptr = &buffer[charsize * current]; 301d5f9d0dbSmacallan char *bptr = gptr + top; 302d5f9d0dbSmacallan uint16_t *bptr16 = (uint16_t *)gptr; 303d5f9d0dbSmacallan bptr16 += top; 304d5f9d0dbSmacallan /* see if the character is in range */ 305d5f9d0dbSmacallan if ((current < 0) || (current > 255)) continue; 306d5f9d0dbSmacallan /* now we read & render the character */ 307d5f9d0dbSmacallan for (i = 0; i < lines; i++) { 308d5f9d0dbSmacallan fgets(num, 32, foo); 309d5f9d0dbSmacallan sscanf(num, "%x", &l); 310d5f9d0dbSmacallan if ((stride) == 2 && (strlen(num) < 4)) 311d5f9d0dbSmacallan l = l << 8; 312d5f9d0dbSmacallan l = l >> left; 313d5f9d0dbSmacallan if (stride == 1) { 314b9e0dc8cSmacallan *bptr = l; 315b9e0dc8cSmacallan bptr++; 316d5f9d0dbSmacallan } else { 317d5f9d0dbSmacallan *bptr16 = htobe16(l); 318d5f9d0dbSmacallan bptr16++; 319ce18d260Suwe } 320d5f9d0dbSmacallan } 321554a5d78Smacallan if (dump) { 322554a5d78Smacallan gptr = &buffer[charsize * current]; 323554a5d78Smacallan for (i = 0; i < height; i++) { 324554a5d78Smacallan dump_line(gptr, stride); 325554a5d78Smacallan gptr += stride; 326554a5d78Smacallan } 327554a5d78Smacallan } 328d5f9d0dbSmacallan } 329d5f9d0dbSmacallan } 33061348eb3Smacallan if (verbose) { 33161348eb3Smacallan printf("range %d to %d\n", first, last); 33261348eb3Smacallan printf("encoding: %s\n", encname[encoding]); 33361348eb3Smacallan printf("actual box: %d %d %d %d\n", bl, bt, br, bb); 33461348eb3Smacallan } 3352b154882Suwe 336d5f9d0dbSmacallan /* now stuff it into a something wsfont understands */ 337d5f9d0dbSmacallan f.fontwidth = width /*(width + 3) & ~3*/; 338d5f9d0dbSmacallan f.fontheight = height; 339d5f9d0dbSmacallan f.firstchar = first; 3402b154882Suwe f.numchars = last - first + 1; 341d5f9d0dbSmacallan f.stride = stride; 3422b154882Suwe f.encoding = encoding; 343d5f9d0dbSmacallan f.name = name; 344d5f9d0dbSmacallan f.bitorder = WSDISPLAY_FONTORDER_L2R; 345d5f9d0dbSmacallan f.byteorder = WSDISPLAY_FONTORDER_L2R; 346d5f9d0dbSmacallan f.data = &buffer[first * charsize]; 347d5f9d0dbSmacallan 3482b154882Suwe if (ofile == NULL) { 3492b154882Suwe int fdev = open("/dev/wsfont", O_RDWR, 0); 3502b154882Suwe if (fdev < 0) 3512b154882Suwe err(EXIT_FAILURE, "/dev/wsfont"); 3522b154882Suwe status = ioctl(fdev, WSDISPLAYIO_LDFONT, &f); 3532b154882Suwe if (status != 0) 3542b154882Suwe err(EXIT_FAILURE, "WSDISPLAYIO_LDFONT"); 3552b154882Suwe close(fdev); 3562b154882Suwe } 3572b154882Suwe else { 3582d60533cSmacallan if (header == 0) { 3592d60533cSmacallan write_wsf(ofile, &f, buffer, buflen); 3602d60533cSmacallan } else 3612d60533cSmacallan write_header(ofile, &f, name, buffer, buflen); 3622b154882Suwe } 363d5f9d0dbSmacallan} 364d5f9d0dbSmacallan 3652b154882Suwe__dead void 3662b154882Suweusage() 3672b154882Suwe{ 3682d60533cSmacallan fprintf(stderr, "usage: bdfload [-vdh] [-e encoding] [-o ofile.wsf] font.bdf\n"); 3692b154882Suwe exit(EXIT_FAILURE); 3702b154882Suwe} 3712b154882Suwe 3722b154882Suweint 373d5f9d0dbSmacallanmain(int argc, char *argv[]) 374d5f9d0dbSmacallan{ 375d5f9d0dbSmacallan FILE *foo; 3762b154882Suwe const char *encname = NULL; 3772b154882Suwe 3782b154882Suwe int c; 3792d60533cSmacallan while ((c = getopt(argc, argv, "e:o:vdh")) != -1) { 3802b154882Suwe switch (c) { 3812b154882Suwe 3822b154882Suwe /* font encoding */ 3832b154882Suwe case 'e': 3842b154882Suwe if (encname != NULL) 3852b154882Suwe usage(); 3862b154882Suwe encname = optarg; 3872b154882Suwe break; 3882b154882Suwe 3892b154882Suwe /* output file name */ 3902b154882Suwe case 'o': 3912b154882Suwe if (ofile != NULL) 3922b154882Suwe usage(); 3932b154882Suwe ofile = optarg; 3942b154882Suwe break; 3952b154882Suwe 39661348eb3Smacallan case 'v': 39761348eb3Smacallan verbose = 1; 39861348eb3Smacallan break; 39961348eb3Smacallan 400554a5d78Smacallan case 'd': 401554a5d78Smacallan dump = 1; 402554a5d78Smacallan break; 403554a5d78Smacallan 4042d60533cSmacallan case 'h': 4052d60533cSmacallan header = 1; 4062d60533cSmacallan break; 4072d60533cSmacallan 4082b154882Suwe case '?': /* FALLTHROUGH */ 4092b154882Suwe default: 4102b154882Suwe usage(); 411d5f9d0dbSmacallan } 412d5f9d0dbSmacallan } 4132b154882Suwe 4142b154882Suwe argc -= optind; 4152b154882Suwe argv += optind; 4162b154882Suwe 4172b154882Suwe if (encname == NULL) { 4182b154882Suwe encoding = WSDISPLAY_FONTENC_ISO; 4192b154882Suwe } 4202b154882Suwe else { 4212b154882Suwe for (const struct encmap *e = encmap; e->name; ++e) { 4222b154882Suwe if (strcmp(e->name, encname) == 0) { 4232b154882Suwe encoding = e->encoding; 4242b154882Suwe break; 4252b154882Suwe } 4262b154882Suwe } 4272b154882Suwe } 4282b154882Suwe 4292b154882Suwe /* get encoding from the bdf file? */ 4302b154882Suwe if (encoding == -1) 4312b154882Suwe encoding = WSDISPLAY_FONTENC_ISO; 4322b154882Suwe 4332b154882Suwe if (argc == 0) 4342b154882Suwe usage(); 4352b154882Suwe 4362b154882Suwe const char *bdfname = argv[0]; 4372b154882Suwe foo = fopen(bdfname, "r"); 4382b154882Suwe if (foo == NULL) 4392b154882Suwe err(EXIT_FAILURE, "%s", bdfname); 4402b154882Suwe 4412b154882Suwe interpret(foo); 4422b154882Suwe return EXIT_SUCCESS; 443d5f9d0dbSmacallan} 444