Change the translation of the "Help" menu item to "?", so that the menu can be displa...
[reactos.git] / rosapps / smartpdf / poppler / poppler / PSTokenizer.cc
1 //========================================================================
2 //
3 // PSTokenizer.cc
4 //
5 // Copyright 2002-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #include <config.h>
10
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include "PSTokenizer.h"
18
19 //------------------------------------------------------------------------
20
21 // A '1' in this array means the character is white space. A '1' or
22 // '2' means the character ends a name or command.
23 static char specialChars[256] = {
24 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
25 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
26 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
27 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
28 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
29 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
33 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
34 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
35 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
40 };
41
42 //------------------------------------------------------------------------
43
44 PSTokenizer::PSTokenizer(int (*getCharFuncA)(void *), void *dataA) {
45 getCharFunc = getCharFuncA;
46 data = dataA;
47 charBuf = -1;
48 }
49
50 PSTokenizer::~PSTokenizer() {
51 }
52
53 GBool PSTokenizer::getToken(char *buf, int size, int *length) {
54 GBool comment, backslash;
55 int c;
56 int i;
57
58 // skip leading whitespace and comments
59 comment = gFalse;
60 while (1) {
61 if ((c = getChar()) == EOF) {
62 buf[0] = '\0';
63 *length = 0;
64 return gFalse;
65 }
66 if (comment) {
67 if (c == '\x0a' || c == '\x0d') {
68 comment = gFalse;
69 }
70 } else if (c == '%') {
71 comment = gTrue;
72 } else if (specialChars[c] != 1) {
73 break;
74 }
75 }
76
77 // Reserve room for terminating '\0'
78 size--;
79
80 // read a token
81 i = 0;
82 buf[i++] = c;
83 if (c == '(') {
84 backslash = gFalse;
85 while ((c = lookChar()) != EOF) {
86 consumeChar();
87 if (i < size) {
88 buf[i++] = c;
89 }
90 if (c == '\\') {
91 backslash = gTrue;
92 } else if (!backslash && c == ')') {
93 break;
94 } else {
95 backslash = gFalse;
96 }
97 }
98 } else if (c == '<') {
99 while ((c = lookChar()) != EOF) {
100 consumeChar();
101 if (i < size) {
102 buf[i++] = c;
103 }
104 if (c == '>') {
105 break;
106 }
107 }
108 } else if (c != '[' && c != ']') {
109 while ((c = lookChar()) != EOF && !specialChars[c]) {
110 consumeChar();
111 if (i < size) {
112 buf[i++] = c;
113 }
114 }
115 }
116 // Zero terminate token string
117 buf[i] = '\0';
118 // Return length of token
119 *length = i;
120
121 return gTrue;
122 }
123
124 int PSTokenizer::lookChar() {
125 if (charBuf < 0) {
126 charBuf = (*getCharFunc)(data);
127 }
128 return charBuf;
129 }
130
131 void PSTokenizer::consumeChar() {
132 charBuf = -1;
133 }
134
135 int PSTokenizer::getChar() {
136 int c = charBuf;
137
138 if (c < 0) {
139 c = (*getCharFunc)(data);
140 } else {
141 charBuf = -1;
142 }
143 return c;
144 }