xref: /netbsd-src/sys/arch/x68k/usr.bin/loadfont/loadfont.c (revision a216f4df59304d0e4ea6232bc595619d795a1fcc)
1 /*
2  * loadfont - load ascii font (for NetBSD/X680x0)
3  * from: amiga/stand/loadkmap/loadkmap.c
4  * Copyright 1993 by Masaru Oki
5  *
6  *	$NetBSD: loadfont.c,v 1.8 2011/05/19 03:22:27 christos Exp $
7  */
8 
9 #include <sys/cdefs.h>
10 __RCSID("$NetBSD: loadfont.c,v 1.8 2011/05/19 03:22:27 christos Exp $");
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <fcntl.h>
15 #include <unistd.h>
16 #include <sys/ioctl.h>
17 #define ITEKANJI 1 /* XXX */
18 #include <machine/iteioctl.h>
19 
20 void load_font(const char *);
21 
22 int
main(int argc,char * argv[])23 main(int argc, char *argv[])
24 {
25 
26 	if (argc != 2) {
27 		fprintf(stderr, "Usage: %s fontfile\n", argv[0]);
28 		exit (1);
29 	}
30 
31 	load_font(argv[1]);
32 	exit(0);
33 }
34 
35 void
load_font(const char * file)36 load_font(const char *file)
37 {
38 	unsigned char buf[4096];
39 	int fd;
40 
41 	if ((fd = open(file, O_RDONLY)) >= 0) {
42 		if (read (fd, buf, sizeof(buf)) == sizeof (buf)) {
43 			if (ioctl(0, ITELOADFONT, buf) == 0)
44 				return;
45 			else
46 				perror("ITELOADFONT");
47 		} else {
48 			perror("read font");
49 		}
50 
51 		close(fd);
52 	} else {
53 		perror("open font");
54 	}
55 }
56