File: mkminifont.c

package info (click to toggle)
kon2 0.3.9b-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 624 kB
  • ctags: 809
  • sloc: ansic: 6,919; makefile: 222; sh: 190
file content (56 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <errno.h>
#include <interface.h>
#include <fnld.h>

struct _fontent {
    unsigned short code;
    unsigned char bitmap[32];
} fent[65535];

int
main(int argc, char *argv[])
{
    bool all=FALSE;
    unsigned short code, max=0;
    unsigned int fnt, i, num=0;
    unsigned char line[10], *path, *font, bytes, high;
    struct fontRegs *freg=&fDRegs[1];
    extern struct fontInfo fi;

    path = NULL;
    for (i = 1; i < argc; i ++) {
  	if (*argv[i] == '-') {
	    if (*(argv[i] + 1) == 'a') all = TRUE;
	} else path = argv[i];
    }
    if (!path) {
	printf("usage: %s [minix font file]\n");
	exit(1);
    }
    if ((font = LoadFontFile(path, "minix", 0)) == NULL) {
	perror(argv[1]);
	exit(1);
    }
    high = fi.high;
    bytes = sizeof(fent[0].code) + high * 2;
    if (all) for (num = 0x2121; num < 0x7474; num ++) {
        code = num & 0x7F7F;
	if (code > max) max = code;
	fnt = freg->addr((code >> 8) & 0x7F, code & 0x7F);
	fent[code].code = code;
	memcpy(fent[code].bitmap, font + fnt, 32);
    } else while (fgets(line, sizeof(line), stdin)) {
	code = ((line[0] << 8) & 0x7F00) | (line[1] & 0x7F);
	if (code > max) max = code;
	fnt = freg->addr(line[0] & 0x7F, line[1] & 0x7F);
	fent[num].code = code;
	memcpy(fent[num].bitmap, font + fnt, 32);
	num ++;
    }
    fwrite(&high, sizeof(high), 1, stdout);
    fwrite(&max, sizeof(max), 1, stdout);
    for (i = 0; i < num; i ++) if (fent[i].code)
	fwrite(&fent[i], bytes, 1, stdout);
    return(0);
}