int main(int argc, char *argv[]) { int fd, c; char *console = NULL; char *outfnam = NULL; char *infnam = "def.uni"; set_progname(argv[0]); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE_NAME, LOCALEDIR); textdomain(PACKAGE_NAME); if (argc == 2 && (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) print_version_and_exit(); while ((c = getopt(argc, argv, "C:o:")) != EOF) { switch (c) { case 'C': console = optarg; break; case 'o': outfnam = optarg; break; default: usage(); } } if (argc > optind+1 || (argc == optind && !outfnam)) usage(); fd = getfd(console); if (outfnam) { saveunicodemap(fd, outfnam); if (argc == optind) exit(0); } if (argc == optind+1) infnam = argv[optind]; loadunicodemap(fd, infnam); exit(0); }
static void loadnewfont(int fd, char *ifil, int iunit, int hwunit, int no_m, int no_u) { lkfile_t fp; char defname[20]; int height, width, bytewidth, def = 0; char *inbuf, *fontbuf; int inputlth, fontbuflth, fontsize, offset; struct unicode_list *uclistheads; if (!*ifil) { /* try to find some default file */ def = 1; /* maybe also load default unimap */ if (iunit < 0 || iunit > 32) iunit = 0; if (iunit == 0) { if (findfont(ifil = "default", &fp) && findfont(ifil = "default8x16", &fp) && findfont(ifil = "default8x14", &fp) && findfont(ifil = "default8x8", &fp)) { fprintf(stderr, _("Cannot find default font\n")); exit(EX_NOINPUT); } } else { sprintf(defname, "default8x%d", iunit); if (findfont(ifil = defname, &fp) && findfont(ifil = "default", &fp)) { fprintf(stderr, _("Cannot find %s font\n"), ifil); exit(EX_NOINPUT); } } } else { if (findfont(ifil, &fp)) { fprintf(stderr, _("Cannot open font file %s\n"), ifil); exit(EX_NOINPUT); } } if (verbose > 1) printf(_("Reading font file %s\n"), ifil); inbuf = fontbuf = NULL; inputlth = fontbuflth = fontsize = 0; width = 8; uclistheads = NULL; if(readpsffont(fp.fd, &inbuf, &inputlth, &fontbuf, &fontbuflth, &width, &fontsize, 0, no_u ? NULL : &uclistheads) == 0) { lk_fpclose(&fp); /* we've got a psf font */ bytewidth = (width+7) / 8; height = fontbuflth / (bytewidth * fontsize); do_loadfont(fd, fontbuf, width, height, hwunit, fontsize, fp.pathname); if (uclistheads && !no_u) do_loadtable(fd, uclistheads, fontsize); #if 1 if (!uclistheads && !no_u && def) loadunicodemap(fd, "def.uni"); #endif return; } lk_fpclose(&fp); // avoid zombies, [email protected] (#88501) /* instructions to combine fonts? */ { char *combineheader = "# combine partial fonts\n"; int chlth = strlen(combineheader); char *p, *q; if (inputlth >= chlth && !strncmp(inbuf, combineheader, chlth)) { char *ifiles[MAXIFILES]; int ifilct = 0; q = inbuf + chlth; while(q < inbuf + inputlth) { p = q; while (q < inbuf+inputlth && *q != '\n') q++; if (q == inbuf+inputlth) { fprintf(stderr, _("No final newline in combine file\n")); exit(EX_DATAERR); } *q++ = 0; if (ifilct == MAXIFILES) { fprintf(stderr, _("Too many files to combine\n")); exit(EX_DATAERR); } ifiles[ifilct++] = p; } /* recursive call */ loadnewfonts(fd, ifiles, ifilct, iunit, hwunit, no_m, no_u); return; } } /* file with three code pages? */ if (inputlth == 9780) { offset = position_codepage(iunit); height = iunit; fontsize = 256; width = 8; } else if (inputlth == 32768) { /* restorefont -w writes a SVGA font to file restorefont -r restores it These fonts have size 32768, for two 512-char fonts. In fact, when BROKEN_GRAPHICS_PROGRAMS is defined, and it always is, there is no default font that is saved, so probably the second half is always garbage. */ fprintf(stderr, _("Hmm - a font from restorefont? " "Using the first half.\n")); inputlth = 16384; /* ignore rest */ fontsize = 512; offset = 0; width = 8; height = 32; if (!hwunit) hwunit = 16; } else { int rem = (inputlth % 256); if (rem == 0 || rem == 40) { /* 0: bare code page bitmap */ /* 40: preceded by .cp header */ /* we might check some header details */ offset = rem; } else { fprintf(stderr, _("Bad input file size\n")); exit(EX_DATAERR); } fontsize = 256; width = 8; height = inputlth/256; } do_loadfont(fd, inbuf+offset, width, height, hwunit, fontsize, fp.pathname); }
int main(int argc, char *argv[]) { char *ifiles[MAXIFILES]; char *mfil, *ufil, *Ofil, *ofil, *omfil, *oufil, *console; int ifilct = 0, fd, i, iunit, hwunit, no_m, no_u; int restore = 0; set_progname(argv[0]); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE_NAME, LOCALEDIR); textdomain(PACKAGE_NAME); ifiles[0] = mfil = ufil = Ofil = ofil = omfil = oufil = NULL; iunit = hwunit = 0; no_m = no_u = 0; console = NULL; /* * No getopt() here because of the -om etc options. */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-V")) { print_version_and_exit(); } else if (!strcmp(argv[i], "-v")) { verbose++; } else if (!strcmp(argv[i], "-R")) { restore = 1; } else if (!strcmp(argv[i], "-C")) { if (++i == argc || console) usage(); console = argv[i]; } else if (!strcmp(argv[i], "-O")) { if (++i == argc || Ofil) usage(); Ofil = argv[i]; } else if (!strcmp(argv[i], "-o")) { if (++i == argc || ofil) usage(); ofil = argv[i]; } else if (!strcmp(argv[i], "-om")) { if (++i == argc || omfil) usage(); omfil = argv[i]; } else if (!strcmp(argv[i], "-ou")) { if (++i == argc || oufil) usage(); oufil = argv[i]; } else if (!strcmp(argv[i], "-m")) { if (++i == argc || mfil) usage(); if (!strcmp(argv[i], "none")) no_m = 1; else mfil = argv[i]; } else if (!strcmp(argv[i], "-u")) { if (++i == argc || ufil) usage(); if (!strcmp(argv[i], "none")) no_u = 1; else ufil = argv[i]; } else if (!strcmp(argv[i], "-f")) { force = 1; } else if (!strncmp(argv[i], "-h", 2)) { hwunit = atoi(argv[i]+2); if (hwunit <= 0 || hwunit > 32) usage(); } else if (argv[i][0] == '-') { iunit = atoi(argv[i]+1); if(iunit <= 0 || iunit > 32) usage(); } else { if (ifilct == MAXIFILES) { fprintf(stderr, _("setfont: too many input files\n")); exit(EX_USAGE); } ifiles[ifilct++] = argv[i]; } } if (ifilct && restore) { fprintf(stderr, _("setfont: cannot both restore from character ROM" " and from file. Font unchanged.\n")); exit(EX_USAGE); } fd = getfd(console); int kd_mode = -1; if (!ioctl(fd, KDGETMODE, &kd_mode) && (kd_mode == KD_GRAPHICS)) { /* * PIO_FONT will fail on a console which is in foreground and in KD_GRAPHICS mode. * 2005-03-03, [email protected]. */ if (verbose) printf("setfont: graphics console %s skipped\n", console?console:""); close(fd); return 0; } if (!ifilct && !mfil && !ufil && !Ofil && !ofil && !omfil && !oufil && !restore) /* reset to some default */ ifiles[ifilct++] = ""; if (Ofil) saveoldfontplusunicodemap(fd, Ofil); if (ofil) saveoldfont(fd, ofil); if (omfil) saveoldmap(fd, omfil); if (oufil) saveunicodemap(fd, oufil); if (mfil) { loadnewmap(fd, mfil); activatemap(fd); no_m = 1; } if (ufil) no_u = 1; if (restore) restorefont(fd); if (ifilct) loadnewfonts(fd, ifiles, ifilct, iunit, hwunit, no_m, no_u); if (ufil) loadunicodemap(fd, ufil); return 0; }