File: fontdata.c

package info (click to toggle)
splat 1.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,332 kB
  • sloc: cpp: 8,650; ansic: 993; sh: 442; lisp: 244; makefile: 31
file content (92 lines) | stat: -rw-r--r-- 3,206 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/****************************************************************************
*                  FONTDATA:  A "fontdata.h" File Generator                 *
*                  Copyright John A. Magliacane, KD2BD 2002                 *
*                         Last update: 08-Jan-2014                          *
*****************************************************************************
*                                                                           *
* This utility reads gzip compressed font data, and generates a fontdata.h  *
* file required for compilation of SPLAT!.  Slackware Linux users may       *
* find compatible console font data files under /usr/lib/kbd/consolefonts   *
* (Slackware < version 8), or /usr/share/kbd/consolefonts (Slackware 8).    *
*                                                                           *
*                       Example: fontdata s.fnt.gz                          *
*   Writes s.fnt font data to "fontdata.h" in current working directory.    *
*                                                                           *
*****************************************************************************
*          To compile: gcc -Wall -O3 -s -lz fontdata.c -o fontdata          *
*****************************************************************************
*                                                                           *
* This program is free software; you can redistribute it and/or modify it   *
* under the terms of the GNU General Public License as published by the     *
* Free Software Foundation; either version 2 of the License or any later    *
* version.                                                                  *
*                                                                           *
* This program is distributed in the hope that it will useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     *
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License     *
* for more details.                                                         *
*                                                                           *
*****************************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <zlib.h>

int main(argc,argv)
int argc;
char *argv[];
{
	int x, input;
	unsigned char line;
	FILE *outfile;
	gzFile *infile=Z_NULL;
	
	if (argc==2)
		*infile=gzopen(argv[1],"rb");

	else
	{	
		fprintf(stderr,"Usage: fontdata fontfile.gz\n");
		exit(-1);
	}

	if (infile!=Z_NULL)
	{
		outfile=fopen("fontdata.h","wb");

		fprintf(outfile,"static unsigned char fontdata[] = {\n  ");

		for (x=0, line=0; x<4096; x++)
		{
			input=gzgetc((gzFile)infile);
			
			fprintf(outfile," 0x%.2x",(unsigned char)input);
	   		line++;

			if (x<4095)
				fprintf(outfile,",");

			if (line==12)
			{
				fprintf(outfile,"\n  ");
				line=0;
			}
		}

	 	fprintf(outfile," };\n");

		gzclose((gzFile)infile);
		fclose(outfile);

		printf("fontdata.h successfully written!\n");
	}

	else
	{
		fprintf(stderr,"%c*** Error: %c%s%c Not Found!\n",7,34,argv[1],34);
		exit(-1);
	}

	exit(0);
}