Merge commit 'upstream/1.3.0'
[debian/splat] / utils / fontdata.c
1 /****************************************************************************
2 *                  FONTDATA:  A "fontdata.h" File Generator                 *
3 *                  Copyright John A. Magliacane, KD2BD 2002                 *
4 *                         Last update: 13-Apr-2002                          *
5 *****************************************************************************
6 *                                                                           *
7 * This utility reads gzip compressed font data, and generates a fontdata.h  *
8 * file required for compilation of SPLAT!.  Slackware Linux users may       *
9 * find compatible console font data files under /usr/lib/kbd/consolefonts   *
10 * (Slackware < version 8), or /usr/share/kbd/consolefonts (Slackware 8).    *
11 *                                                                           *
12 *                       Example: fontdata s.fnt.gz                          *
13 *   Writes s.fnt font data to "fontdata.h" in current working directory.    *
14 *                                                                           *
15 *****************************************************************************
16 *          To compile: gcc -Wall -O6 -s -lz fontdata.c -o fontdata          *
17 *****************************************************************************
18 *                                                                           *
19 * This program is free software; you can redistribute it and/or modify it   *
20 * under the terms of the GNU General Public License as published by the     *
21 * Free Software Foundation; either version 2 of the License or any later    *
22 * version.                                                                  *
23 *                                                                           *
24 * This program is distributed in the hope that it will useful, but WITHOUT  *
25 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     *
26 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License     *
27 * for more details.                                                         *
28 *                                                                           *
29 *****************************************************************************/
30
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdlib.h>
34 #include <zlib.h>
35
36 int main(argc,argv)
37 int argc;
38 char *argv[];
39 {
40         int x;
41         unsigned char line, input;
42         FILE *infile, *outfile;
43         
44         if (argc==2)
45                 infile=gzopen(argv[1],"rb");
46
47         else
48         {       
49                 fprintf(stderr,"Usage: fontdata fontfile.gz\n");
50                 exit(-1);
51         }
52
53         if (infile!=NULL)
54         {
55                 outfile=fopen("fontdata.h","wb");
56
57                 fprintf(outfile,"static char fontdata[] = {\n  ");
58
59                 for (x=0, line=0; x<4096; x++)
60                 {
61                         input=gzgetc(infile);
62                         
63                         fprintf(outfile," 0x%.2x",input);
64                         line++;
65
66                         if (x<4095)
67                                 fprintf(outfile,",");
68
69                         if (line==12)
70                         {
71                                 fprintf(outfile,"\n  ");
72                                 line=0;
73                         }
74                 }
75
76                 fprintf(outfile," };\n");
77
78                 gzclose(infile);
79                 fclose(outfile);
80
81                 printf("fontdata.h successfully written!\n");
82         }
83
84         else
85         {
86                 fprintf(stderr,"%c*** Error: %c%s%c Not Found!\n",7,34,argv[1],34);
87                 exit(-1);
88         }
89
90         exit(0);
91 }