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