Imported Debian patch 1.1.0-1
[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 #include <stdlib.h>
36
37 int main(argc,argv)
38 int argc;
39 char *argv[];
40 {
41         int x;
42         unsigned char line, input;
43         FILE *infile, *outfile;
44         
45         if (argc==2)
46                 infile=gzopen(argv[1],"rb");
47
48         else
49         {       
50                 fprintf(stderr,"Usage: fontdata fontfile.gz\n");
51                 exit(-1);
52         }
53
54         if (infile!=NULL)
55         {
56                 outfile=fopen("fontdata.h","wb");
57
58                 fprintf(outfile,"static char fontdata[] = {\n  ");
59
60                 for (x=0, line=0; x<4096; x++)
61                 {
62                         input=gzgetc(infile);
63                         
64                         fprintf(outfile," 0x%.2x",input);
65                         line++;
66
67                         if (x<4095)
68                                 fprintf(outfile,",");
69
70                         if (line==12)
71                         {
72                                 fprintf(outfile,"\n  ");
73                                 line=0;
74                         }
75                 }
76
77                 fprintf(outfile," };\n");
78
79                 gzclose(infile);
80                 fclose(outfile);
81
82                 printf("fontdata.h successfully written!\n");
83         }
84
85         else
86         {
87                 fprintf(stderr,"%c*** Error: %c%s%c Not Found!\n",7,34,argv[1],34);
88                 exit(-1);
89         }
90
91         exit(0);
92 }