File: outpsfheader.c

package info (click to toggle)
kbd 2.0.4-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 14,136 kB
  • sloc: sh: 12,838; ansic: 12,531; pascal: 472; lex: 466; makefile: 394; yacc: 356; perl: 126; sed: 16
file content (64 lines) | stat: -rw-r--r-- 1,472 bytes parent folder | download
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
57
58
59
60
61
62
63
64
/* outpsfheader - auxiliary fn - not to be installed */
/* assumes a little-endian machine */
#include "config.h"

#include <stdio.h>
#include <stdlib.h> /* exit */
#include "kbd.h"
#include "psf.h"

static void __attribute__((noreturn))
usage(void)
{
	fprintf(stderr, "call: outpsfheader psftype fontsize charsize hastable\n");
	exit(1);
}

int main(int argc, char **argv)
{
	int psftype, fontsize, charsize, hastable;

	if (argc != 5)
		usage();
	psftype  = atoi(argv[1]);
	fontsize = atoi(argv[2]);
	charsize = atoi(argv[3]);
	hastable = atoi(argv[4]);

	if (psftype == 1) {
		struct psf1_header h1;

		if (fontsize != 256 && fontsize != 512)
			usage();
		h1.magic[0] = PSF1_MAGIC0;
		h1.magic[1] = PSF1_MAGIC1;
		h1.mode     = (fontsize == 256) ? 0 : PSF1_MODE512;
		if (hastable)
			h1.mode |= PSF1_MODEHASTAB;
		h1.charsize = charsize;
		if (fwrite(&h1, sizeof(h1), 1, stdout) != 1) {
			fprintf(stderr, "write error\n");
			exit(1);
		}
	} else if (psftype == 2) {
		struct psf2_header h2;

		h2.magic[0]   = PSF2_MAGIC0;
		h2.magic[1]   = PSF2_MAGIC1;
		h2.magic[2]   = PSF2_MAGIC2;
		h2.magic[3]   = PSF2_MAGIC3;
		h2.version    = 0;
		h2.headersize = sizeof(h2);
		h2.flags      = (hastable ? PSF2_HAS_UNICODE_TABLE : 0);
		h2.length     = fontsize;
		h2.charsize   = charsize;
		h2.width      = 8;
		h2.height     = charsize;
		if (fwrite(&h2, sizeof(h2), 1, stdout) != 1) {
			fprintf(stderr, "write error\n");
			exit(1);
		}
	} else
		usage();
	return 0;
}