11d822237679acba271a21182662bf92bc86c2fb
[platform/upstream/kbd.git] / src / outpsfheader.c
1 /* outpsfheader - auxiliary fn - not to be installed */
2 /* assumes a little-endian machine */
3 #include "config.h"
4
5 #include <stdio.h>
6 #include <stdlib.h> /* exit */
7 #include "kbd.h"
8 #include "psf.h"
9
10 static void __attribute__((noreturn))
11 usage(void)
12 {
13         fprintf(stderr, "call: outpsfheader psftype fontsize charsize hastable\n");
14         exit(1);
15 }
16
17 int main(int argc, char **argv)
18 {
19         int psftype, fontsize, charsize, hastable;
20
21         if (argc != 5)
22                 usage();
23         psftype  = atoi(argv[1]);
24         fontsize = atoi(argv[2]);
25         charsize = atoi(argv[3]);
26         hastable = atoi(argv[4]);
27
28         if (psftype == 1) {
29                 struct psf1_header h1;
30
31                 if (fontsize != 256 && fontsize != 512)
32                         usage();
33                 h1.magic[0] = PSF1_MAGIC0;
34                 h1.magic[1] = PSF1_MAGIC1;
35                 h1.mode     = (fontsize == 256) ? 0 : PSF1_MODE512;
36                 if (hastable)
37                         h1.mode |= PSF1_MODEHASTAB;
38                 h1.charsize = charsize;
39                 if (fwrite(&h1, sizeof(h1), 1, stdout) != 1) {
40                         fprintf(stderr, "write error\n");
41                         exit(1);
42                 }
43         } else if (psftype == 2) {
44                 struct psf2_header h2;
45
46                 h2.magic[0]   = PSF2_MAGIC0;
47                 h2.magic[1]   = PSF2_MAGIC1;
48                 h2.magic[2]   = PSF2_MAGIC2;
49                 h2.magic[3]   = PSF2_MAGIC3;
50                 h2.version    = 0;
51                 h2.headersize = sizeof(h2);
52                 h2.flags      = (hastable ? PSF2_HAS_UNICODE_TABLE : 0);
53                 h2.length     = fontsize;
54                 h2.charsize   = charsize;
55                 h2.width      = 8;
56                 h2.height     = charsize;
57                 if (fwrite(&h2, sizeof(h2), 1, stdout) != 1) {
58                         fprintf(stderr, "write error\n");
59                         exit(1);
60                 }
61         } else
62                 usage();
63         return 0;
64 }