示例#1
0
static void
load_scrnmap(const char *filename)
{
	FILE *fd;
	int size;
	char *name;
	scrmap_t scrnmap;
	const char *a[] = {"", SCRNMAP_PATH, NULL};
	const char *b[] = {filename, NULL};
	const char *c[] = {"", ".scm", NULL};
	const char *d[] = {"", NULL};

	fd = openguess(a, b, c, d, &name);

	if (fd == NULL) {
		revert();
		errx(1, "screenmap file not found");
	}

	size = sizeof(scrnmap);

	if (decode(fd, (char *)&scrnmap, size) != size) {
		rewind(fd);

		if (fread(&scrnmap, 1, size, fd) != (size_t)size) {
			warnx("bad screenmap file");
			fclose(fd);
			revert();
			errx(1, "bad screenmap file");
		}
	}

	if (ioctl(0, PIO_SCRNMAP, &scrnmap) == -1) {
		revert();
		errc(1, errno, "loading screenmap");
	}

	fclose(fd);
}
示例#2
0
static void
load_font(char *type, char *filename)
{
    FILE *fd;
    int h, i, size, w;
    unsigned long io = 0;	/* silence stupid gcc(1) in the Wall mode */
    char *name, *fontmap, size_sufx[6];
    const char *a[] = {"", FONT_PATH, NULL};
    const char *b[] = {filename, NULL};
    const char *c[] = {"", size_sufx, NULL};
    const char *d[] = {"", ".fnt", NULL};
    vid_info_t vinfo;

    struct sizeinfo {
        int w;
        int h;
        unsigned long io;
    } sizes[] = {{8, 16, PIO_FONT8x16},
        {8, 14, PIO_FONT8x14},
        {8,  8, PIO_FONT8x8},
        {0,  0, 0}
    };

    vinfo.size = sizeof(vinfo);

    if (ioctl(0, CONS_GETINFO, &vinfo) == -1) {
        revert();
        errc(1, errno, "obtaining current video mode parameters");
    }

    snprintf(size_sufx, sizeof(size_sufx), "-8x%d", vinfo.font_size);

    fd = openguess(a, b, c, d, &name);

    if (fd == NULL) {
        revert();
        errx(1, "%s: can't load font file", filename);
    }

    if (type != NULL) {
        size = 0;
        if (sscanf(type, "%dx%d", &w, &h) == 2) {
            for (i = 0; sizes[i].w != 0; i++) {
                if (sizes[i].w == w && sizes[i].h == h) {
                    size = DATASIZE(sizes[i]);
                    io = sizes[i].io;
                    font_height = sizes[i].h;
                }
            }
        }
        if (size == 0) {
            fclose(fd);
            revert();
            errx(1, "%s: bad font size specification", type);
        }
    } else {
        /* Apply heuristics */

        int j;
        int dsize[2];

        size = DATASIZE(sizes[0]);
        fontmap = (char*) malloc(size);
        dsize[0] = decode(fd, fontmap, size);
        dsize[1] = fsize(fd);
        free(fontmap);

        size = 0;
        for (j = 0; j < 2; j++) {
            for (i = 0; sizes[i].w != 0; i++) {
                if (DATASIZE(sizes[i]) == dsize[j]) {
                    size = dsize[j];
                    io = sizes[i].io;
                    font_height = sizes[i].h;
                    j = 2;	/* XXX */
                    break;
                }
            }
        }

        if (size == 0) {
            fclose(fd);
            revert();
            errx(1, "%s: can't guess font size", filename);
        }

        rewind(fd);
    }

    fontmap = (char*) malloc(size);

    if (decode(fd, fontmap, size) != size) {
        rewind(fd);
        if (fsize(fd) != size ||
                fread(fontmap, 1, size, fd) != (size_t)size) {
            fclose(fd);
            free(fontmap);
            revert();
            errx(1, "%s: bad font file", filename);
        }
    }

    if (ioctl(0, io, fontmap) == -1) {
        revert();
        errc(1, errno, "loading font");
    }

    fclose(fd);
    free(fontmap);
}