4 static inline int iswhite(int ch
)
14 static inline int isdelim(int ch
)
16 return ch
== '(' || ch
== ')' ||
17 ch
== '<' || ch
== '>' ||
18 ch
== '[' || ch
== ']' ||
19 ch
== '{' || ch
== '}' ||
24 static inline int isregular(int ch
)
26 return !isdelim(ch
) && !iswhite(ch
) && ch
!= EOF
;
29 static inline int isnumber(int ch
)
31 return ch
== '+' || ch
== '-' || ch
== '.' || (ch
>= '0' && ch
<= '9');
34 static inline int ishex(int ch
)
36 return (ch
>= '0' && ch
<= '9') ||
37 (ch
>= 'A' && ch
<= 'F') ||
38 (ch
>= 'a' && ch
<= 'f');
41 static inline int fromhex(int ch
)
43 if (ch
>= '0' && ch
<= '9')
45 else if (ch
>= 'A' && ch
<= 'F')
46 return ch
- 'A' + 0xA;
47 else if (ch
>= 'a' && ch
<= 'f')
48 return ch
- 'a' + 0xA;
53 lexwhite(fz_stream
*f
)
66 lexcomment(fz_stream
*f
)
72 if (c
== '\012') break;
73 if (c
== '\015') break;
79 lexnumber(fz_stream
*f
, unsigned char *s
, int n
)
83 if (!isnumber(fz_peekbyte(f
)))
85 *s
++ = fz_readbyte(f
);
92 lexname(fz_stream
*f
, unsigned char *s
, int n
)
99 if (!isregular(fz_peekbyte(f
)))
101 *s
++ = fz_readbyte(f
);
108 if (p
[0] == '#' && p
[1] != 0 && p
[2] != 0)
110 *q
++ = fromhex(p
[1]) * 16 + fromhex(p
[2]);
120 lexstring(fz_stream
*f
, unsigned char *buf
, int n
)
122 unsigned char *s
= buf
;
123 unsigned char *e
= buf
+ n
;
146 if (c
== 'n') *s
++ = '\n';
147 else if (c
== 'r') *s
++ = '\r';
148 else if (c
== 't') *s
++ = '\t';
149 else if (c
== 'b') *s
++ = '\b';
150 else if (c
== 'f') *s
++ = '\f';
151 else if (c
== '(') *s
++ = '(';
152 else if (c
== ')') *s
++ = ')';
153 else if (c
== '\\') *s
++ = '\\';
155 else if (c
>= '0' && c
<= '9')
159 if (c
>= '0' && c
<= '9')
162 oct
= oct
* 8 + (c
- '0');
164 if (c
>= '0' && c
<= '9')
167 oct
= oct
* 8 + (c
- '0');
193 lexhexstring(fz_stream
*f
, unsigned char *buf
, int n
)
195 unsigned char *s
= buf
;
196 unsigned char *e
= buf
+ n
;
211 *s
++ = a
* 16 + fromhex(c
);
228 tokenfromkeyword(char *key
)
230 if (!strcmp(key
, "R")) return PDF_TR
;
231 if (!strcmp(key
, "true")) return PDF_TTRUE
;
232 if (!strcmp(key
, "false")) return PDF_TFALSE
;
233 if (!strcmp(key
, "null")) return PDF_TNULL
;
235 if (!strcmp(key
, "obj")) return PDF_TOBJ
;
236 if (!strcmp(key
, "endobj")) return PDF_TENDOBJ
;
237 if (!strcmp(key
, "stream")) return PDF_TSTREAM
;
238 if (!strcmp(key
, "endstream")) return PDF_TENDSTREAM
;
240 if (!strcmp(key
, "xref")) return PDF_TXREF
;
241 if (!strcmp(key
, "trailer")) return PDF_TTRAILER
;
242 if (!strcmp(key
, "startxref")) return PDF_TSTARTXREF
;
248 pdf_lex(fz_stream
*f
, unsigned char *buf
, int n
, int *sl
)
277 *sl
= lexstring(f
, buf
, n
);
292 *sl
= lexhexstring(f
, buf
, n
);
330 else if (isnumber(c
))
332 lexnumber(f
, buf
, n
);
334 if (strchr(buf
, '.'))
339 else if (isregular(c
))
343 return tokenfromkeyword(buf
);