author | sandman <sandman> | 2002-05-23 23:51:52 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-05-23 23:51:52 (UTC) |
commit | 2f3bb7b07f833273d966d41813e68bfe8b9d8d76 (patch) (unidiff) | |
tree | 00beb1bd9e7f4ba79e22334a0d258269b28f4564 /noncore/unsupported/qpdf/xpdf/PSTokenizer.cc | |
parent | 6e82b45dd416ceeba78765717b700e853c96a137 (diff) | |
download | opie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.zip opie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.tar.gz opie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.tar.bz2 |
Port to xpdf 1.01
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/PSTokenizer.cc') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/PSTokenizer.cc | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/PSTokenizer.cc b/noncore/unsupported/qpdf/xpdf/PSTokenizer.cc new file mode 100644 index 0000000..8d654bd --- a/dev/null +++ b/noncore/unsupported/qpdf/xpdf/PSTokenizer.cc | |||
@@ -0,0 +1,133 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // PSTokenizer.cc | ||
4 | // | ||
5 | // Copyright 2002 Glyph & Cog, LLC | ||
6 | // | ||
7 | //======================================================================== | ||
8 | |||
9 | #ifdef __GNUC__ | ||
10 | #pragma implementation | ||
11 | #endif | ||
12 | |||
13 | #include <stdio.h> | ||
14 | #include <stdlib.h> | ||
15 | #include "PSTokenizer.h" | ||
16 | |||
17 | //------------------------------------------------------------------------ | ||
18 | |||
19 | // A '1' in this array means the character is white space. A '1' or | ||
20 | // '2' means the character ends a name or command. | ||
21 | static char specialChars[256] = { | ||
22 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x | ||
23 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x | ||
24 | 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x | ||
25 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x | ||
26 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x | ||
27 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x | ||
28 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x | ||
29 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x | ||
30 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x | ||
31 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x | ||
32 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax | ||
33 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx | ||
34 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx | ||
35 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx | ||
36 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex | ||
37 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx | ||
38 | }; | ||
39 | |||
40 | //------------------------------------------------------------------------ | ||
41 | |||
42 | PSTokenizer::PSTokenizer(int (*getCharFuncA)(void *), void *dataA) { | ||
43 | getCharFunc = getCharFuncA; | ||
44 | data = dataA; | ||
45 | charBuf = -1; | ||
46 | } | ||
47 | |||
48 | PSTokenizer::~PSTokenizer() { | ||
49 | } | ||
50 | |||
51 | GBool PSTokenizer::getToken(char *buf, int size, int *length) { | ||
52 | GBool comment, backslash; | ||
53 | int c; | ||
54 | int i; | ||
55 | |||
56 | // skip whitespace and comments | ||
57 | comment = gFalse; | ||
58 | while (1) { | ||
59 | if ((c = getChar()) == EOF) { | ||
60 | buf[0] = '\0'; | ||
61 | *length = 0; | ||
62 | return gFalse; | ||
63 | } | ||
64 | if (comment) { | ||
65 | if (c == '\x0a' || c == '\x0d') { | ||
66 | comment = gFalse; | ||
67 | } | ||
68 | } else if (c == '%') { | ||
69 | comment = gTrue; | ||
70 | } else if (specialChars[c] != 1) { | ||
71 | break; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | // read a token | ||
76 | i = 0; | ||
77 | buf[i++] = c; | ||
78 | if (c == '(') { | ||
79 | backslash = gFalse; | ||
80 | while ((c = lookChar()) != EOF) { | ||
81 | if (i < size - 1) { | ||
82 | buf[i++] = c; | ||
83 | } | ||
84 | getChar(); | ||
85 | if (c == '\\') { | ||
86 | backslash = gTrue; | ||
87 | } else if (!backslash && c == ')') { | ||
88 | break; | ||
89 | } else { | ||
90 | backslash = gFalse; | ||
91 | } | ||
92 | } | ||
93 | } else if (c == '<') { | ||
94 | while ((c = lookChar()) != EOF) { | ||
95 | getChar(); | ||
96 | if (i < size - 1) { | ||
97 | buf[i++] = c; | ||
98 | } | ||
99 | if (c == '>') { | ||
100 | break; | ||
101 | } | ||
102 | } | ||
103 | } else if (c != '[' && c != ']') { | ||
104 | while ((c = lookChar()) != EOF && !specialChars[c]) { | ||
105 | getChar(); | ||
106 | if (i < size - 1) { | ||
107 | buf[i++] = c; | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | buf[i] = '\0'; | ||
112 | *length = i; | ||
113 | |||
114 | return gTrue; | ||
115 | } | ||
116 | |||
117 | int PSTokenizer::lookChar() { | ||
118 | if (charBuf < 0) { | ||
119 | charBuf = (*getCharFunc)(data); | ||
120 | } | ||
121 | return charBuf; | ||
122 | } | ||
123 | |||
124 | int PSTokenizer::getChar() { | ||
125 | int c; | ||
126 | |||
127 | if (charBuf < 0) { | ||
128 | charBuf = (*getCharFunc)(data); | ||
129 | } | ||
130 | c = charBuf; | ||
131 | charBuf = -1; | ||
132 | return c; | ||
133 | } | ||