libc: rename struct FTW quit to __quit
[unleashed/lotheac.git] / tools / bdf_to_c.awk
blob5365d41bce9918c47f610bbcf2eeefd1737ab1c9
1 #! /bin/awk -f
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
8 # with the License.
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
21 # CDDL HEADER END
24 # Copyright (c) 1998-1999 by Sun Microsystems, Inc.
25 # All rights reserved.
28 BEGIN {
29 pats["0"]=" ";
30 pats["1"]=" X";
31 pats["2"]=" X ";
32 pats["3"]=" XX";
33 pats["4"]=" X ";
34 pats["5"]=" X X";
35 pats["6"]=" XX ";
36 pats["7"]=" XXX";
37 pats["8"]="X ";
38 pats["9"]="X X";
39 pats["a"]="X X "; pats["A"] = pats["a"];
40 pats["b"]="X XX"; pats["B"] = pats["b"];
41 pats["c"]="XX "; pats["C"] = pats["c"];
42 pats["d"]="XX X"; pats["D"] = pats["d"];
43 pats["e"]="XXX "; pats["E"] = pats["e"];
44 pats["f"]="XXXX"; pats["F"] = pats["f"];
47 $1=="ENDCHAR" {
48 in_bitmap = 0;
49 next;
52 in_bitmap != 0 {
53 if (ignoring) next;
55 for (c = 0; c < byteswide; c++)
56 printf "0x%s, ", substr($0,c*2+1,2);
57 s="";
58 for (c = 0; c < byteswide*2; c++)
59 s = s pats[substr($0,c+1,1)];
60 s = substr(s, 1, bitswide);
61 printf "/* %s */\n", s;
63 offset += length($0)/2;
64 next;
67 $1=="STARTFONT" {
68 if ($2 != "2.1") {
69 printf "Unknown BDF version number %s!\n", $2;
70 exit 1;
72 in_bitmap = 0;
73 ignoring = 1;
74 first = 1;
75 offset = 0;
77 for (i = 0; i < 256; i++)
78 encoding[i] = -1;
80 next;
83 $1=="COMMENT" {
84 if (NF > 1) {
85 printf "/*";
86 for (i = 2; i < NF; i++)
87 printf " %s",$i;
88 printf " */";
90 printf "\n";
91 next;
94 $1=="FONT" {
95 font = $2;
96 printf "#include <sys/types.h>\n"
97 printf "#include <sys/font.h>\n\n"
98 printf "/* %s */\n", $0;
99 next;
102 $1=="SIZE" {
103 next;
106 $1=="FONTBOUNDINGBOX" {
107 rows = $3;
108 byteswide = int(($2 + 7)/8);
109 bitswide = $2;
110 next;
113 $1=="STARTPROPERTIES" {
114 next;
117 $1=="FONTNAME_REGISTRY" {
118 next;
121 $1=="FOUNDRY" {
122 next;
125 $1=="FAMILY_NAME" {
126 next;
129 $1=="WEIGHT_NAME" {
130 next;
133 $1=="SLANT" {
134 next;
137 $1=="SETWIDTH_NAME" {
138 next;
141 $1=="ADD_STYLE_NAME" {
142 next;
145 $1=="PIXEL_SIZE" {
146 next;
149 $1=="POINT_SIZE" {
150 next;
153 $1=="RESOLUTION_X" {
154 next;
157 $1=="RESOLUTION_Y" {
158 next;
162 $1=="SPACING" {
163 if ($2 != "\"C\"") printf "Unsupported format %s!\n",$2;
164 next;
167 $1=="AVERAGE_WIDTH" {
168 next;
171 $1=="CHARSET_REGISTRY" {
172 next;
175 $1=="CHARSET_ENCODING" {
176 next;
180 $1=="DEFAULT_CHAR" {
181 default_char = $2;
182 next;
185 $1=="FONT_DESCENT" {
186 next;
189 $1=="FONT_ASCENT" {
190 next;
194 $1=="COPYRIGHT" {
195 printf "/* Copyright notice from .bdf file: */\n";
196 printf "/* %s */\n", $0;
197 next;
200 $1=="ENDPROPERTIES" {
201 next;
204 $1=="CHARS" {
205 next;
209 $1=="STARTCHAR" {
210 if (first) {
211 printf "static unsigned char FONTDATA_%s[] = {\n", font;
212 first = 0;
214 ignoring = 1;
215 row = 0;
216 next;
219 $1=="ENCODING" {
220 encoding[$2] = offset;
221 ignoring = 0;
222 got[$2] = 1;
223 printf "\n";
224 if ($2 >= 32 && $2 < 127) printf "/* '%c' */\n", $2;
225 else printf "/* 0x%2.2x */\n", $2;
226 next;
229 $1=="SWIDTH" {
230 next;
233 $1=="DWIDTH" {
234 next;
237 $1=="BBX" {
238 next;
241 $1=="BITMAP" {
242 in_bitmap = 1;
243 next;
246 $1=="ENDFONT" {
247 printf "};\n";
248 printf "\n";
249 printf "static unsigned char *ENCODINGS_%s[256] = {\n", font;
251 for (i = 0; i < 256; i++) {
252 if (encoding[i] == -1) encoding[i] = encoding[default_char];
253 printf "\tFONTDATA_%s+%d,\n", font, encoding[i];
255 printf "};\n\n";
256 printf "bitmap_data_t font_data_%s = {\n", font;
257 printf "\t%s, %s,\n", bitswide, rows;
258 printf "\tFONTDATA_%s,\n", font;
259 printf "\tENCODINGS_%s\n", font;
260 printf "};\n";
261 next;
265 printf "?!? %s\n", $0;