~ubuntu-branches/ubuntu/intrepid/plplot/intrepid

« back to all changes in this revision

Viewing changes to fonts/plhershey-unicode-gen.c

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2006-11-04 10:19:34 UTC
  • mfrom: (2.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061104101934-mlirvdg4gpwi6i5q
Tags: 5.6.1-10
* Orphaning the package
* debian/control: Changed the maintainer to the Debian QA Group

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Id: plhershey-unicode-gen.c,v 1.6 2006/05/27 18:13:31 hbabcock Exp $
 
2
 
 
3
   This file is part of PLplot.
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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
 
18
 
 
19
*/
 
20
 
 
21
/*
 
22
 *   Program for generating data structures used for translating
 
23
 *   between unicode and hershey
 
24
 *
 
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]
 
27
 *  the output file.
 
28
 *
 
29
 */
 
30
 
 
31
#include <stdio.h>
 
32
#include <stdlib.h>
 
33
#include <strings.h>
 
34
 
 
35
 
 
36
/*--------------------------------------------------------------------------*\
 
37
 *   Function-like macro definitions
 
38
\*--------------------------------------------------------------------------*/
 
39
 
 
40
#define MemError1(a) do {fprintf(stderr,"MEMORY ERROR %d\n" a "\n",__LINE__);exit(__LINE__);}while(0)
 
41
 
 
42
const char header[]=""\
 
43
"/*\n"\
 
44
"  This file is part of PLplot.\n"\
 
45
"  \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"\
 
50
"  \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"\
 
55
"  \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"\
 
59
"  \n"\
 
60
"  \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"\
 
65
"  \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"\
 
69
"  indices:\n"\
 
70
"       0        undefined/unknown\n"\
 
71
"       1        normal\n"\
 
72
"       2        roman\n"\
 
73
"       3        italic-roman\n"\
 
74
"       4        script\n"\
 
75
"  \n"\
 
76
"  Font indices are used for approximating the appearence of the original\n"\
 
77
"  hershey glyphs.\n"\
 
78
"  \n"\
 
79
"  Unicode values of 0x0000 signify unknowns.\n"\
 
80
"  \n"\
 
81
"*/";
 
82
 
 
83
 
 
84
 
 
85
int main (int argc, char *argv[])
 
86
{
 
87
FILE *fr, *fw;
 
88
char readbuffer[256];
 
89
int *Hershey=NULL;
 
90
int *Unicode=NULL;
 
91
char *Font=NULL;
 
92
int i=0;
 
93
int number_of_lines=0;
 
94
 
 
95
if ((fr=fopen(argv[1],"r"))!=NULL)
 
96
  {
 
97
    /*
 
98
     *   Work out how many lines we have all up
 
99
     */
 
100
 
 
101
    while((fgets(readbuffer,255,fr)!=NULL))
 
102
      {
 
103
        ++number_of_lines;
 
104
      }
 
105
 
 
106
    /*
 
107
     *   Allocate memory to the arrays which will hold the data
 
108
     */
 
109
 
 
110
    if ((Hershey=(int *)calloc(number_of_lines, (size_t)sizeof(int)))==NULL)
 
111
      MemError1("Allocating memory to the hershey table");
 
112
 
 
113
    if ((Unicode=(int *)calloc(number_of_lines, (size_t)sizeof(int)))==NULL)
 
114
      MemError1("Allocating memory to the unicode table");
 
115
 
 
116
    if ((Font=(char *)calloc(number_of_lines, (size_t)sizeof(char)))==NULL)
 
117
      MemError1("Allocating memory to the font table");
 
118
 
 
119
    rewind(fr);   /* Go back to the start of the file */
 
120
 
 
121
    /*
 
122
     *    Read in line by line, and copy the numbers into our arrays
 
123
     */
 
124
 
 
125
    while((fgets(readbuffer,255,fr)!=NULL))
 
126
      {
 
127
       sscanf(readbuffer,"%x,%d,%c",(int *)&Unicode[i],(int *)&Hershey[i],(char *)&Font[i]);
 
128
       i++;
 
129
      }
 
130
 
 
131
    fclose(fr);
 
132
  }
 
133
 
 
134
/*
 
135
 *   Write the data out to file ready to be included in our source
 
136
 */
 
137
 
 
138
 
 
139
if ((fw=fopen(argv[2],"w"))!=NULL)
 
140
  {
 
141
  fprintf(fw,"%s\n",header);
 
142
 
 
143
  fprintf(fw, "const int number_of_entries_in_hershey_to_unicode_table=%d;\n\n",number_of_lines);
 
144
 
 
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);
 
147
 
 
148
  for (i=0;i<number_of_lines;i++)
 
149
    {
 
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,", ");
 
153
    }
 
154
 
 
155
  fprintf(fw,"\n};\n");
 
156
 
 
157
  fclose(fw);
 
158
}
 
159
free(Unicode);
 
160
free(Hershey);
 
161
free(Font);
 
162
 
 
163
return(0);
 
164
}
 
165