1 /* $NetBSD: wsfontload.c,v 1.13 2008/05/26 12:15:42 drochner Exp $ */
5 * Matthias Drochner. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
35 #include <sys/ioctl.h>
39 #include <dev/wscons/wsconsio.h>
41 #define DEFDEV "/dev/wsfont"
44 #define DEFENC WSDISPLAY_FONTENC_ISO
45 #define DEFBITORDER WSDISPLAY_FONTORDER_L2R
46 #define DEFBYTEORDER WSDISPLAY_FONTORDER_L2R
48 static void usage(void);
49 static int getencoding(char *);
50 static const char *rgetencoding(int);
51 static const char *rgetfontorder(int);
57 { "known", WSDISPLAY_FONTORDER_KNOWN
},
58 { "l2r", WSDISPLAY_FONTORDER_L2R
},
59 { "r2l", WSDISPLAY_FONTORDER_R2L
},
66 {"iso", WSDISPLAY_FONTENC_ISO
},
67 {"ibm", WSDISPLAY_FONTENC_IBM
},
68 {"pcvt", WSDISPLAY_FONTENC_PCVT
},
69 {"iso7", WSDISPLAY_FONTENC_ISO7
},
70 {"iso2", WSDISPLAY_FONTENC_ISO2
},
78 "usage: %s [-f wsdev] [-w width] [-h height] [-e encoding]"
79 " [-N name] [-b] [-B] [fontfile]\n",
85 * map given fontorder to its string representation
88 rgetfontorder(int fontorder
)
92 for (i
= 0; i
< sizeof(fontorders
) / sizeof(fontorders
[0]); i
++)
93 if (fontorders
[i
].val
== fontorder
)
94 return (fontorders
[i
].name
);
100 * map given encoding to its string representation
103 rgetencoding(int enc
)
107 for (i
= 0; i
< sizeof(encodings
) / sizeof(encodings
[0]); i
++)
108 if (encodings
[i
].val
== enc
)
109 return (encodings
[i
].name
);
115 * map given encoding string to integer value
118 getencoding(char *name
)
123 for (i
= 0; i
< sizeof(encodings
) / sizeof(encodings
[0]); i
++)
124 if (!strcmp(name
, encodings
[i
].name
))
125 return (encodings
[i
].val
);
127 if (sscanf(name
, "%d", &j
) != 1)
128 errx(1, "invalid encoding");
133 main(int argc
, char **argv
)
136 struct wsdisplay_font f
;
137 int c
, res
, wsfd
, ffd
, verbose
= 0;
142 f
.fontwidth
= DEFWIDTH
;
143 f
.fontheight
= DEFHEIGHT
;
149 f
.bitorder
= DEFBITORDER
;
150 f
.byteorder
= DEFBYTEORDER
;
152 while ((c
= getopt(argc
, argv
, "f:w:h:e:N:bBv")) != -1) {
158 if (sscanf(optarg
, "%d", &f
.fontwidth
) != 1)
159 errx(1, "invalid font width");
162 if (sscanf(optarg
, "%d", &f
.fontheight
) != 1)
163 errx(1, "invalid font height");
166 f
.encoding
= getencoding(optarg
);
172 f
.bitorder
= WSDISPLAY_FONTORDER_R2L
;
175 f
.byteorder
= WSDISPLAY_FONTORDER_R2L
;
192 wsfd
= open(wsdev
, O_RDWR
, 0);
194 err(2, "open ws-device %s", wsdev
);
197 ffd
= open(argv
[0], O_RDONLY
, 0);
199 err(4, "open font %s", argv
[0]);
206 f
.stride
= (f
.fontwidth
+ 7) / 8;
207 len
= f
.fontheight
* f
.numchars
* f
.stride
;
209 errx(1, "invalid font size");
214 res
= read(ffd
, buf
, len
);
217 if ((size_t)res
!= len
)
218 errx(4, "short read");
223 printf("name: %s\n", f
.name
);
224 printf("firstchar: %d\n", f
.firstchar
);
225 printf("numchars: %d\n", f
.numchars
);
226 printf("encoding: %s (%d)\n",
227 rgetencoding(f
.encoding
), f
.encoding
);
228 printf("fontwidth: %d\n", f
.fontwidth
);
229 printf("fontheight: %d\n", f
.fontheight
);
230 printf("stride: %d\n", f
.stride
);
231 printf("bitorder: %s (%d)\n",
232 rgetfontorder(f
.bitorder
), f
.bitorder
);
233 printf("byteorder: %s (%d)\n",
234 rgetfontorder(f
.byteorder
), f
.byteorder
);
237 res
= ioctl(wsfd
, WSDISPLAYIO_LDFONT
, &f
);
239 err(3, "WSDISPLAYIO_LDFONT");