Change the translation of the "Help" menu item to "?", so that the menu can be displa...
[reactos.git] / rosapps / smartpdf / poppler / poppler / Lexer.h
1 //========================================================================
2 //
3 // Lexer.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 // Copyright 2006 Krzysztof Kowalczyk (http://blog.kowalczyk.info)
7 //
8 //========================================================================
9
10 #ifndef LEXER_H
11 #define LEXER_H
12
13 #ifdef USE_GCC_PRAGMAS
14 #pragma interface
15 #endif
16
17 #include <assert.h>
18 #include "Object.h"
19 #include "Stream.h"
20
21 class XRef;
22
23 #define tokBufSize 128 // size of token buffer
24
25 //------------------------------------------------------------------------
26 // Lexer
27 //------------------------------------------------------------------------
28
29 class Lexer {
30 public:
31
32 // Construct a lexer for a single stream. Deletes the stream when
33 // lexer is deleted.
34 Lexer(XRef *xrefA, Stream *str);
35
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);
39
40 // Destructor.
41 ~Lexer();
42
43 // Get the next object from the input stream.
44 Object *getObj(Object *obj, int objNum = -1);
45
46 // Skip to the beginning of the next line in the input stream.
47 void skipToNextLine();
48
49 // Skip over one character.
50 void skipChar();
51
52 Stream *getStream();
53
54 // Get current position in file. This is only used for error
55 // messages, so it returns an int instead of a Guint.
56 int getPos();
57
58 // Set position in file.
59 void setPos(Guint pos, int dir = 0);
60
61 // Returns true if <c> is a whitespace character.
62 static GBool isSpace(int c);
63
64 private:
65
66 // we really want lookChar() and getChar() to be inlined
67 int lookChar() {
68 if (LOOK_VALUE_NOT_CACHED != lookCharLastValueCached) {
69 return lookCharLastValueCached;
70 }
71 lookCharLastValueCached = getChar();
72 return lookCharLastValueCached;
73 }
74
75 int getChar() {
76 int c;
77 GBool hasMoreData;
78
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));
83 return c;
84 }
85
86 while (curStrHasGetBuf) {
87 if (bufLeft > 0) {
88 c = *bufCurPos++ & 0xff;
89 bufLeft--;
90 return c;
91 }
92 hasMoreData = fillBuf();
93 if (!hasMoreData)
94 nextStream();
95 }
96
97 c = EOF;
98 while (!curStr.isNone() && (c = curStr.streamGetChar()) == EOF) {
99 nextStream();
100 }
101 return c;
102 }
103
104 void nextStream();
105 GBool fillBuf();
106
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
112 XRef * xref;
113
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;
122
123 GBool curStrHasGetBuf; // does current stream support GetBuf() ?
124 char * buf;
125 char * bufCurPos;
126 int bufSize;
127 int bufLeft;
128 };
129
130 #endif