//
// Lexer.cc
//
-// Copyright 1996 Derek B. Noonburg
+// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
-#ifdef __GNUC__
+#include <aconf.h>
+
+#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif
// Lexer
//------------------------------------------------------------------------
-Lexer::Lexer(Stream *str) {
+Lexer::Lexer(XRef *xref, Stream *str) {
Object obj;
curStr.initStream(str);
- streams = new Array();
+ streams = new Array(xref);
streams->add(curStr.copy(&obj));
strPtr = 0;
freeArray = gTrue;
curStr.streamReset();
}
-Lexer::Lexer(Object *obj) {
+Lexer::Lexer(XRef *xref, Object *obj) {
Object obj2;
if (obj->isStream()) {
- streams = new Array();
+ streams = new Array(xref);
freeArray = gTrue;
streams->add(obj->copy(&obj2));
} else {
curStr.streamReset();
}
}
+static int illegalChars = 0;
Lexer::~Lexer() {
if (!curStr.isNone()) {
if (freeArray) {
delete streams;
}
+ if(illegalChars)
+ error(0, "Illegal characters in hex string (%d)", illegalChars);
+ illegalChars = 0;
}
int Lexer::getChar() {
scale = 0.1;
while (1) {
c = lookChar();
+ if (c == '-') {
+ // ignore minus signs in the middle of numbers to match
+ // Adobe's behavior
+ error(getPos(), "Badly formatted number");
+ getChar();
+ continue;
+ }
if (!isdigit(c)) {
break;
}
case '(':
++numParen;
+ c2 = c;
break;
case ')':
- if (--numParen == 0)
+ if (--numParen == 0) {
done = gTrue;
+ } else {
+ c2 = c;
+ }
break;
case '\\':
} else if (c2 >= 'a' && c2 <= 'f') {
c += c2 - 'a' + 10;
} else {
- error(getPos(), "Illegal digit in hex char in name");
+ illegalChars++;
+ //error(getPos(), "Illegal digit in hex char in name");
}
}
notEscChar:
c2 += c - 'A' + 10;
else if (c >= 'a' && c <= 'f')
c2 += c - 'a' + 10;
- else
- error(getPos(), "Illegal character <%02x> in hex string", c);
+ else {
+ illegalChars++;
+ //error(getPos(), "Illegal character <%02x> in hex string", c);
+ }
if (++m == 2) {
if (n == tokBufSize) {
if (!s)
tokBuf[2] = '\0';
obj->initCmd(tokBuf);
} else {
- error(getPos(), "Illegal character '>'");
+ illegalChars++;
+ //error(getPos(), "Illegal character '>'");
obj->initError();
}
break;
case ')':
case '{':
case '}':
- error(getPos(), "Illegal character '%c'", c);
+ //error(getPos(), "Illegal character '%c'", c);
+ illegalChars++;
obj->initError();
break;
}
break;
}
-
return obj;
}
}
}
}
+
+GBool Lexer::isSpace(int c) {
+ return c >= 0 && c <= 0xff && specialChars[c] == 1;
+}