1
/* $Id: plhershey-unicode-gen.c,v 1.6 2006/05/27 18:13:31 hbabcock Exp $
3
This file is part of PLplot.
5
PLplot is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Library Public License as published
7
by the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
PLplot is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with PLplot; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
* Program for generating data structures used for translating
23
* between unicode and hershey
25
* The program is pretty dumb, because it does no command line parsing;
26
* instead it assumes that argv[1] will be the input file, and argv[2]
36
/*--------------------------------------------------------------------------*\
37
* Function-like macro definitions
38
\*--------------------------------------------------------------------------*/
40
#define MemError1(a) do {fprintf(stderr,"MEMORY ERROR %d\n" a "\n",__LINE__);exit(__LINE__);}while(0)
42
const char header[]=""\
44
" This file is part of PLplot.\n"\
46
" PLplot is free software; you can redistribute it and/or modify\n"\
47
" it under the terms of the GNU General Library Public License as published\n"\
48
" by the Free Software Foundation; either version 2 of the License, or\n"\
49
" (at your option) any later version.\n"\
51
" PLplot is distributed in the hope that it will be useful,\n"\
52
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"\
53
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"\
54
" GNU Library General Public License for more details.\n"\
56
" You should have received a copy of the GNU Library General Public License\n"\
57
" along with PLplot; if not, write to the Free Software\n"\
58
" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"\
61
" This header file contains the lookup tables used for converting between\n"\
62
" hershey and unicode. It is an automatically generated file, so please do\n"\
63
" not edit it directly. Make any changes to plhershey-unicode.csv, then use\n"\
64
" plhershey-unicode-gen.c to recreate this header file.\n"\
66
" plhershey-unicode.csv consists of three fields: the first field is the\n"\
67
" hershey code, and is in decimal; the second is the unicode value, and is\n"\
68
" in hex; and the final field is font index. There are five possible font\n"\
70
" 0 undefined/unknown\n"\
76
" Font indices are used for approximating the appearence of the original\n"\
79
" Unicode values of 0x0000 signify unknowns.\n"\
85
int main (int argc, char *argv[])
93
int number_of_lines=0;
95
if ((fr=fopen(argv[1],"r"))!=NULL)
98
* Work out how many lines we have all up
101
while((fgets(readbuffer,255,fr)!=NULL))
107
* Allocate memory to the arrays which will hold the data
110
if ((Hershey=(int *)calloc(number_of_lines, (size_t)sizeof(int)))==NULL)
111
MemError1("Allocating memory to the hershey table");
113
if ((Unicode=(int *)calloc(number_of_lines, (size_t)sizeof(int)))==NULL)
114
MemError1("Allocating memory to the unicode table");
116
if ((Font=(char *)calloc(number_of_lines, (size_t)sizeof(char)))==NULL)
117
MemError1("Allocating memory to the font table");
119
rewind(fr); /* Go back to the start of the file */
122
* Read in line by line, and copy the numbers into our arrays
125
while((fgets(readbuffer,255,fr)!=NULL))
127
sscanf(readbuffer,"%x,%d,%c",(int *)&Unicode[i],(int *)&Hershey[i],(char *)&Font[i]);
135
* Write the data out to file ready to be included in our source
139
if ((fw=fopen(argv[2],"w"))!=NULL)
141
fprintf(fw,"%s\n",header);
143
fprintf(fw, "const int number_of_entries_in_hershey_to_unicode_table=%d;\n\n",number_of_lines);
145
fprintf(fw, "typedef struct {\n\tunsigned int Hershey;\n\tPLUNICODE Unicode;\n\tchar Font;\n} Hershey_to_Unicode_table;\n\n");
146
fprintf(fw, "const Hershey_to_Unicode_table hershey_to_unicode_lookup_table[%d] = {\n",number_of_lines);
148
for (i=0;i<number_of_lines;i++)
150
if (((i%4)==0)&&(i>0)) fprintf(fw,"\n");
151
fprintf(fw,"{%d,0x%04x,%c}", (int)Hershey[i],(int)Unicode[i],(char)Font[i]);
152
if (i<(number_of_lines-1)) fprintf(fw,", ");
155
fprintf(fw,"\n};\n");