1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Create arrays for initializing the kernel folded tables (using a hash
6 * table turned out to be to limiting...) Unfortunately we can't simply
7 * preinitialize the tables at compile time since kfree() cannot accept
8 * memory not allocated by kmalloc(), and doing our own memory management
9 * just for this seems like massive overkill.
11 * Copyright (C) 1995-1997 H. Peter Anvin
20 #define MAX_FONTLEN 256
22 typedef unsigned short unicode
;
24 static void usage(char *argv0
)
26 fprintf(stderr
, "Usage: \n"
27 " %s chartable [hashsize] [hashstep] [maxhashlevel]\n", argv0
);
31 static int getunicode(char **p0
)
35 while (*p
== ' ' || *p
== '\t')
37 if (*p
!= 'U' || p
[1] != '+' ||
38 !isxdigit(p
[2]) || !isxdigit(p
[3]) || !isxdigit(p
[4]) ||
39 !isxdigit(p
[5]) || isxdigit(p
[6]))
42 return strtol(p
+2,0,16);
45 unicode unitable
[MAX_FONTLEN
][255];
46 /* Massive overkill, but who cares? */
47 int unicount
[MAX_FONTLEN
];
49 static void addpair(int fp
, int un
)
55 /* Check it isn't a duplicate */
57 for ( i
= 0 ; i
< unicount
[fp
] ; i
++ )
58 if ( unitable
[fp
][i
] == un
)
63 if ( unicount
[fp
] > 254 )
65 fprintf(stderr
, "ERROR: Only 255 unicodes/glyph permitted!\n");
69 unitable
[fp
][unicount
[fp
]] = un
;
73 /* otherwise: ignore */
76 int main(int argc
, char *argv
[])
83 int fp0
, fp1
, un0
, un1
;
86 if ( argc
< 2 || argc
> 5 )
89 if ( !strcmp(argv
[1],"-") )
96 ctbl
= fopen(tblname
= argv
[1], "r");
104 /* For now we assume the default font is always 256 characters. */
107 /* Initialize table */
109 for ( i
= 0 ; i
< fontlen
; i
++ )
112 /* Now we come to the tricky part. Parse the input table. */
114 while ( fgets(buffer
, sizeof(buffer
), ctbl
) != NULL
)
116 if ( (p
= strchr(buffer
, '\n')) != NULL
)
119 fprintf(stderr
, "%s: Warning: line too long\n", tblname
);
125 * <fontpos> <unicode> <unicode> ...
127 * <range> <unicode range>
129 * where <range> ::= <fontpos>-<fontpos>
130 * and <unicode> ::= U+<h><h><h><h>
131 * and <h> ::= <hexadecimal digit>
134 while (*p
== ' ' || *p
== '\t')
136 if (!*p
|| *p
== '#')
137 continue; /* skip comment or blank line */
139 fp0
= strtol(p
, &p1
, 0);
142 fprintf(stderr
, "Bad input line: %s\n", buffer
);
147 while (*p
== ' ' || *p
== '\t')
152 fp1
= strtol(p
, &p1
, 0);
155 fprintf(stderr
, "Bad input line: %s\n", buffer
);
163 if ( fp0
< 0 || fp0
>= fontlen
)
166 "%s: Glyph number (0x%x) larger than font length\n",
170 if ( fp1
&& (fp1
< fp0
|| fp1
>= fontlen
) )
173 "%s: Bad end of range (0x%x)\n",
180 /* we have a range; expect the word "idem" or a Unicode range of the
182 while (*p
== ' ' || *p
== '\t')
184 if (!strncmp(p
, "idem", 4))
186 for (i
=fp0
; i
<=fp1
; i
++)
192 un0
= getunicode(&p
);
193 while (*p
== ' ' || *p
== '\t')
198 "%s: Corresponding to a range of font positions, there should be a Unicode range\n",
203 un1
= getunicode(&p
);
204 if (un0
< 0 || un1
< 0)
207 "%s: Bad Unicode range corresponding to font position range 0x%x-0x%x\n",
211 if (un1
- un0
!= fp1
- fp0
)
214 "%s: Unicode range U+%x-U+%x not of the same length as font position range 0x%x-0x%x\n",
215 tblname
, un0
, un1
, fp0
, fp1
);
218 for(i
=fp0
; i
<=fp1
; i
++)
219 addpair(i
,un0
-fp0
+i
);
224 /* no range; expect a list of unicode values for a single font position */
226 while ( (un0
= getunicode(&p
)) >= 0 )
229 while (*p
== ' ' || *p
== '\t')
232 fprintf(stderr
, "%s: trailing junk (%s) ignored\n", tblname
, p
);
235 /* Okay, we hit EOF, now output hash table */
240 /* Compute total size of Unicode list */
242 for ( i
= 0 ; i
< fontlen
; i
++ )
247 * Do not edit this file; it was automatically generated by\n\
249 * conmakehash %s > [this file]\n\
253 #include <linux/types.h>\n\
255 u8 dfont_unicount[%d] = \n\
256 {\n\t", argv
[1], fontlen
);
258 for ( i
= 0 ; i
< fontlen
; i
++ )
260 printf("%3d", unicount
[i
]);
261 if ( i
== fontlen
-1 )
263 else if ( i
% 8 == 7 )
269 printf("\nu16 dfont_unitable[%d] = \n{\n\t", nuni
);
273 for ( i
= 0 ; i
< nuni
; i
++ )
275 while ( nent
>= unicount
[fp0
] )
280 printf("0x%04x", unitable
[fp0
][nent
++]);
283 else if ( i
% 8 == 7 )