1 //========================================================================
5 // Copyright 2002-2003 Glyph & Cog, LLC
7 //========================================================================
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
17 #include "PSTokenizer.h"
19 //------------------------------------------------------------------------
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
42 //------------------------------------------------------------------------
44 PSTokenizer::PSTokenizer(int (*getCharFuncA)(void *), void *dataA) {
45 getCharFunc = getCharFuncA;
50 PSTokenizer::~PSTokenizer() {
53 GBool PSTokenizer::getToken(char *buf, int size, int *length) {
54 GBool comment, backslash;
58 // skip whitespace and comments
61 if ((c = getChar()) == EOF) {
67 if (c == '\x0a' || c == '\x0d') {
70 } else if (c == '%') {
72 } else if (specialChars[c] != 1) {
82 while ((c = lookChar()) != EOF) {
89 } else if (!backslash && c == ')') {
95 } else if (c == '<') {
96 while ((c = lookChar()) != EOF) {
105 } else if (c != '[' && c != ']') {
106 while ((c = lookChar()) != EOF && !specialChars[c]) {
119 int PSTokenizer::lookChar() {
121 charBuf = (*getCharFunc)(data);
126 int PSTokenizer::getChar() {
130 charBuf = (*getCharFunc)(data);