- if (!esc) {
- unsigned char c; // getc() returns an int
-
- status = 0;
- while (is && !status) {
- is.get(c);
- if (c == '#') {
- // Read rest of line (fast :-)
- is.get(buff, sizeof(buff));
- lyxerr[Debug::LYXLEX] << "Comment read: " << c << buff << endl;
- ++lineno;
- continue;
- }
-
- if (c == '\"') {
- int i = -1;
- do {
- is.get(c);
- if (c != '\r')
- buff[++i] = c;
- } while (c != '\"' && c != '\n' && is &&
- i != (LEX_MAX_BUFF - 2));
-
- if (i == (LEX_MAX_BUFF - 2)) {
- printError("Line too long");
- c = '\"'; // Pretend we got a "
- ++i;
- }
-
- if (c != '\"') {
- printError("Missing quote");
- if (c == '\n')
- ++lineno;
- }
-
- buff[i] = '\0';
- status = LEX_DATA;
- break;
- }
-
- if (c == ',')
- continue; /* Skip ','s */
-
- // using relational operators with chars other
- // than == and != is not safe. And if it is done
- // the type _have_ to be unsigned. It usually a
- // lot better to use the functions from cctype
- if (c > ' ' && is) {
-#warning Verify this! (Lgb)
- //if (isalnum(static_cast<unsigned char>(c)) && is) {
- int i = 0;
- do {
- buff[i++] = c;
- is.get(c);
- } while (c > ' ' && c != ',' && is
- //} while (isalnum(static_cast<unsigned char>(c))
- //&& c != ',' && is
- && (i != LEX_MAX_BUFF - 1) );
- if (i == LEX_MAX_BUFF - 1) {
- printError("Line too long");
- }
- buff[i] = '\0';
- status = LEX_TOKEN;
- }
-
- if (c == '\r' && is) {
- // The Windows support has lead to the
- // possibility of "\r\n" at the end of
- // a line. This will stop LyX choking
- // when it expected to find a '\n'
- is.get(c);
- }
-
- if (c == '\n')
- ++lineno;
-
- }
- if (status) return true;
-
- status = is.eof() ? LEX_FEOF: LEX_UNDEF;
- buff[0] = '\0';
- return false;
- } else {
- unsigned char c; // getc() returns an int
-
- status = 0;
- while (is && !status) {
- is.get(c);
-
- // skip ','s
- if (c == ',') continue;
-
- if (c == '\\') {
- // escape
- int i = 0;
- do {
- if (c == '\\') {
- // escape the next char
- is.get(c);
- }
- buff[i++] = c;
- is.get(c);
- } while (c > ' ' && c != ',' && is
- //} while (isalnum(static_cast<unsigned char>(c))
- //&& c != ',' && is
- && (i != LEX_MAX_BUFF - 1) );
- if (i == LEX_MAX_BUFF - 1) {
- printError("Line too long");
- }
- buff[i] = '\0';
- status = LEX_TOKEN;
- continue;
- }
-
- if (c == '#') {
- // Read rest of line (fast :-)
- is.get(buff, sizeof(buff));
- lyxerr[Debug::LYXLEX] << "Comment read: " << c << buff << endl;
- ++lineno;
- continue;
- }
-
- // string
- if (c == '\"') {
- int i = -1;
- bool escaped = false;
- do {
- escaped = false;
- is.get(c);
- if (c == '\r') continue;
- if (c == '\\') {
- // escape the next char
- is.get(c);
- escaped = true;
- }
- buff[++i] = c;
-
- if (!escaped && c == '\"') break;
- } while (c != '\n' && is &&
- i != (LEX_MAX_BUFF - 2));
-
- if (i == (LEX_MAX_BUFF - 2)) {
- printError("Line too long");
- c = '\"'; // Pretend we got a "
- ++i;
- }
-
- if (c != '\"') {
- printError("Missing quote");
- if (c == '\n')
- ++lineno;
- }
-
- buff[i] = '\0';
- status = LEX_DATA;
- break;
- }
-
- if (c > ' ' && is) {
- //if (isalnum(static_cast<unsigned char>(c)) && is) {
- int i = 0;
- do {
- if (c == '\\') {
- // escape the next char
- is.get(c);
- //escaped = true;
- }
- buff[i++] = c;
- is.get(c);
- } while (c > ' ' && c != ',' && is
- //} while (isalnum(static_cast<unsigned char>(c))
- //!= ',' && is
- && (i != LEX_MAX_BUFF-1) );
- if (i == LEX_MAX_BUFF-1) {
- printError("Line too long");
- }
- buff[i] = '\0';
- status = LEX_TOKEN;
- }
- // new line
- if (c == '\n')
- ++lineno;
- }
-
- if (status) return true;
-
- status = is.eof() ? LEX_FEOF: LEX_UNDEF;
- buff[0] = '\0';
- return false;