w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

parse.c
Go to the documentation of this file.
1 /*
2  * parse.c
3  *
4  * This file is part of the ttf2pk package.
5  *
6  * Copyright 1997-1999, 2000 by
7  * Frederic Loyer <loyer@ensta.fr>
8  * Werner Lemberg <wl@gnu.org>
9  */
10 
11 #ifdef HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <stddef.h> /* for size_t */
18 #include <ctype.h>
19 #include <string.h>
20 
21 #include "ttf2tfm.h"
22 #include "errormsg.h"
23 #include "newobj.h"
24 #include "ligkern.h"
25 #include "texenc.h"
26 #include "parse.h"
27 #include "filesrch.h"
28 
29 
30 /*
31  * Here we get a token from the encoding file. We parse just as much
32  * PostScript as we expect to find in an encoding file. We allow
33  * commented lines and names like 0, .notdef, _foo_. We do not allow
34  * //abc.
35  *
36  * `bufferp' is a pointer to the current line; the offset of the beginning
37  * of the token to be parsed relative to `bufferp' will be returned in
38  * `offsetp'. On the first call of gettoken() `init' must be set to 1 and
39  * to 0 on the following calls.
40  *
41  * If `ignoreligkern' is `True', no LIGKERN data will be extracted from the
42  * encoding file.
43  *
44  * Don't modify `bufferp'!
45  *
46  * The memory management of `bufferp' will be done by gettoken() itself;
47  * nevertheless, it returns a pointer to the current token which should be
48  * freed after it has been used.
49  */
50 
51 static char *
52 gettoken(char **bufferp, size_t *offsetp, FILE *f, Font *fnt,
54 {
55  char *p, *q;
56  char tempchar;
57  static char *curp;
58 
59 
60  if (init)
61  curp = NULL;
62 
63  while (1)
64  {
65  while (curp == NULL || *curp == '\0')
66  {
67  if (*bufferp)
68  free(*bufferp);
69 
70  if (texlive_getline(bufferp, f) == False)
71  oops("Premature end in encoding file.");
72 
73  curp = *bufferp;
74 
75  for (p = *bufferp; *p; p++)
76  if (*p == '%')
77  {
78  if (ignoreligkern == False)
79  checkligkern(p, fnt);
80  *p = '\0';
81  break;
82  }
83  }
84 
85  while (isspace((unsigned char)*curp))
86  curp++;
87 
88  *offsetp = curp - *bufferp;
89 
90  if (*curp)
91  {
92  if (*curp == '[' || *curp == ']' ||
93  *curp == '{' || *curp == '}')
94  q = curp++;
95  else if (*curp == '/' ||
96  *curp == '-' || *curp == '_' || *curp == '.' ||
97  ('0' <= *curp && *curp <= '9') ||
98  ('a' <= *curp && *curp <= 'z') ||
99  ('A' <= *curp && *curp <= 'Z'))
100  {
101  q = curp++;
102  while (*curp == '-' || *curp == '_' || *curp == '.' ||
103  ('0' <= *curp && *curp <= '9') ||
104  ('a' <= *curp && *curp <= 'z') ||
105  ('A' <= *curp && *curp <= 'Z'))
106  curp++;
107  }
108  else
109  q = curp;
110 
111  tempchar = *curp;
112  *curp = '\0';
113  p = newstring(q);
114  *curp = tempchar;
115  return p;
116  }
117  }
118 }
119 
120 
121 /*
122  * This routine reads in an encoding file, given the name. It returns
123  * the final total structure. It performs a number of consistency checks.
124  */
125 
126 encoding *
128 {
129  char *real_encname;
130  FILE *enc_file;
131  char *p, *q, c;
132  char *buffer;
133  char numbuf[11];
134  size_t offset;
135  int i;
136  long l;
137  encoding *e = (encoding *)mymalloc(sizeof (encoding));
138 
139 
140  if (enc && *enc)
141  {
142  real_encname = TeX_search_encoding_file(enc);
143  if (!real_encname)
144  oops("Cannot find encoding file `%s'.", *enc);
145 
146  enc_file = fopen(real_encname, "rt");
147  if (enc_file == NULL)
148  oops("Cannot open encoding file `%s'.", real_encname);
149 
150  buffer = NULL;
152  if (*p != '/' || p[1] == '\0')
154  "First token in encoding must be literal encoding name.");
155  e->name = newstring(p + 1);
156  free(p);
157 
159  if (strcmp(p, "["))
161  "Second token in encoding must be mark ([) token.");
162  free(p);
163 
164  for (i = 0; i < 256; i++)
165  {
167  if (*p != '/' || p[1] == 0)
169  "Tokens 3 to 257 in encoding must be literal names.");
170 
171  /* now we test for a generic code point resp. glyph index value */
172 
173  c = p[2];
174  if (p[1] == '.' && (c == 'c' || c == 'g') && '0' <= p[3] && p[3] <= '9')
175  {
176  l = strtol(p + 3, &q, 0);
177  if (*q != '\0' || l < 0 || l > 0x16FFFF)
178  boops(buffer, offset, "Invalid encoding token.");
179  sprintf(numbuf, ".%c0x%lx", c, l);
180  e->vec[i] = newstring(numbuf);
181  }
182  else
183  e->vec[i] = newstring(p + 1);
184 
185  free(p);
186  }
187 
189  if (strcmp(p, "]"))
191  "Token 258 in encoding must be make-array (]).");
192  free(p);
193 
194  while (texlive_getline(&buffer, enc_file))
195  {
196  for (p = buffer; *p; p++)
197  if (*p == '%')
198  {
199  if (ignoreligkern == False)
200  checkligkern(p, fnt);
201  *p = '\0';
202  break;
203  }
204  }
205 
206  fclose(enc_file);
207 
208  if (ignoreligkern == False && fnt->sawligkern == False)
210  }
211  else
212  {
213  if (ignoreligkern == False)
214  {
215  e = &staticencoding;
217  }
218  else
219  e = NULL;
220  }
221 
222  return e;
223 }
224 
225 
226 /*
227  * We scan a glyph replacement file.
228  * `%' is the comment character.
229  */
230 
231 void
233 {
234  char *real_replacement_name;
235  FILE *replacement_file;
236  char *buffer = NULL, *oldbuffer = NULL;
237  char *p;
238  char *old_name, *new_name;
239  stringlist *sl;
240 
241 
242  if (!fnt->replacementname)
243  return;
244 
245  real_replacement_name = TeX_search_replacement_file(&fnt->replacementname);
246  if (!real_replacement_name)
247  oops("Cannot find replacement file `%s'.", fnt->replacementname);
248 
249  replacement_file = fopen(real_replacement_name, "rt");
250  if (replacement_file == NULL)
251  oops("Cannot open replacement file `%s'.", real_replacement_name);
252 
253  while (texlive_getline(&buffer, replacement_file))
254  {
255  for (p = buffer; *p; p++)
256  if (*p == '%')
257  {
258  *p = '\0';
259  break;
260  }
261 
262  if (oldbuffer)
263  free(oldbuffer);
264  oldbuffer = newstring(buffer);
265 
266  p = buffer;
267 
268  while (isspace((unsigned char)*p))
269  p++;
270  if (!*p)
271  continue;
272 
273  old_name = p;
274 
275  while (*p && !isspace((unsigned char)*p))
276  p++;
277  if (*p)
278  *p++ = '\0';
279 
280  while (*p && isspace((unsigned char)*p))
281  p++;
282  if (!*p)
283  boops(oldbuffer, old_name - oldbuffer, "Replacement glyph missing.");
284 
285  new_name = p;
286 
287  while (*p && !isspace((unsigned char)*p))
288  p++;
289  if (*p)
290  *p++ = '\0';
291 
292  while (*p && isspace((unsigned char)*p))
293  p++;
294  if (*p)
295  boops(oldbuffer, p - oldbuffer, "Invalid replacement syntax.");
296 
297  sl = newstringlist();
298  sl->new_name = newstring(new_name);
299  sl->old_name = newstring(old_name);
300  sl->next = fnt->replacements;
301  fnt->replacements = sl;
302  }
303 
304  fclose(replacement_file);
305 }
306 
307 
308 /* end */
long __cdecl strtol(char const *_String, char **_EndPtr, int _Radix)
static void checkligkern(char *s, int isencfile)
Definition: afm2pl.c:1344
q
Definition: afm2pl.c:2287
static int texlive_getline(void)
Definition: afm2pl.c:339
static char * newstring(const char *s)
Definition: afm2pl.c:282
static void getligkerndefaults(void)
Definition: afm2tfm.c:2021
struct encoding staticencoding
Definition: afm2tfm.c:82
int ignoreligkern
Definition: afm2tfm.c:170
Definition: Font.hpp:55
#define free(a)
Definition: decNumber.cpp:310
op_table fnt
Definition: dt2dv.c:217
#define fopen
Definition: xxstdio.h:21
int strcmp()
Definition: coll.cpp:143
void boops(const char *buffer, size_t offset, const char *message,...)
Definition: errormsg.c:53
char * TeX_search_encoding_file(char **name)
Definition: filesrch.c:443
char * TeX_search_replacement_file(char **name)
Definition: filesrch.c:451
mpz_t * f
Definition: gen-fib.c:34
#define c(n)
Definition: gpos-common.c:150
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
static FILE * enc_file
Definition: writet1.c:226
#define fclose
Definition: debug.h:100
encoding * readencoding(char **enc, Font *fnt, Boolean ignoreligkern)
Definition: parse.c:127
static char * gettoken(char **bufferp, size_t *offsetp, FILE *f, Font *fnt, Boolean ignoreligkern, Boolean init)
Definition: parse.c:52
void get_replacements(Font *fnt)
Definition: parse.c:232
#define sprintf
Definition: snprintf.c:44
stringlist * newstringlist(void)
Definition: newobj.c:282
int Boolean
Definition: pgmcrater.c:64
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld init[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld_src SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
static int offset
Definition: ppmtogif.c:642
#define mymalloc
Definition: pscolor.c:28
#define isspace(ch)
Definition: utype.h:87
ShellFileEnvironment e
Definition: sh6.c:388
void oops(const char *message,...)
Definition: stackenv.c:90
Definition: utils.c:300
#define FILE
Definition: t1stdio.h:34
@ True
Definition: ttf2tfm.h:20
@ False
Definition: ttf2tfm.h:19
#define buffer
Definition: xmlparse.c:611