1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 // Copyright 2006 Krzysztof Kowalczyk (http://blog.kowalczyk.info)
8 //========================================================================
13 #ifdef USE_GCC_PRAGMAS
23 #define tokBufSize 128 // size of token buffer
25 //------------------------------------------------------------------------
27 //------------------------------------------------------------------------
32 // Construct a lexer for a single stream. Deletes the stream when
34 Lexer(XRef
*xrefA
, Stream
*str
);
36 // Construct a lexer for a stream or array of streams (assumes obj
37 // is either a stream or array of streams).
38 Lexer(XRef
*xrefA
, Object
*obj
);
43 // Get the next object from the input stream.
44 Object
*getObj(Object
*obj
, int objNum
= -1);
46 // Skip to the beginning of the next line in the input stream.
47 void skipToNextLine();
49 // Skip over one character.
54 // Get current position in file. This is only used for error
55 // messages, so it returns an int instead of a Guint.
58 // Set position in file.
59 void setPos(Guint pos
, int dir
= 0);
61 // Returns true if <c> is a whitespace character.
62 static GBool
isSpace(int c
);
66 // we really want lookChar() and getChar() to be inlined
68 if (LOOK_VALUE_NOT_CACHED
!= lookCharLastValueCached
) {
69 return lookCharLastValueCached
;
71 lookCharLastValueCached
= getChar();
72 return lookCharLastValueCached
;
79 if (LOOK_VALUE_NOT_CACHED
!= lookCharLastValueCached
) {
80 c
= lookCharLastValueCached
;
81 lookCharLastValueCached
= LOOK_VALUE_NOT_CACHED
;
82 assert( (c
>= LOOK_VALUE_NOT_CACHED
) && (c
< 256));
86 while (curStrHasGetBuf
) {
88 c
= *bufCurPos
++ & 0xff;
92 hasMoreData
= fillBuf();
98 while (!curStr
.isNone() && (c
= curStr
.streamGetChar()) == EOF
) {
107 Array
* streams
; // array of input streams
108 int strPtr
; // index of current stream
109 Object curStr
; // current stream
110 GBool freeArray
; // should lexer free the streams array?
111 char tokBuf
[tokBufSize
]; // temporary token buffer
114 // often (e.g. ~30% on PDF Refernce 1.6 pdf file from Adobe site) getChar
115 // is called right after lookChar. In order to avoid expensive re-doing
116 // getChar() of underlying stream, we cache the last value found by
117 // lookChar() in lookCharLastValueCached. A special value
118 // LOOK_VALUE_NOT_CACHED that should never be part of stream indicates
119 // that no value was cached
120 static const int LOOK_VALUE_NOT_CACHED
= -3;
121 int lookCharLastValueCached
;
123 GBool curStrHasGetBuf
; // does current stream support GetBuf() ?