- if (!esc) {
- int c; // getc() returns an int
- int i;
-
-
- status = 0;
- while (!feof(file) && !status) {
- c = getc(file);
- if (c=='#') {
- // Read rest of line (fast :-)
- fgets(buff, sizeof(buff), file);
- ++lineno;
- continue;
- }
-
- if (c=='\"') {
- i = -1;
- do {
- c = getc(file);
- if (c != '\r')
- buff[++i] = c;
- } while (c!='\"' && c!='\n' && !feof(file) &&
- 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 */
-
- if (c > ' ' && !feof(file)) {
- i = 0;
- do {
- buff[i++] = c;
- c = getc(file);
- } while (c > ' ' && c != ',' && !feof(file) &&
- (i != LEX_MAX_BUFF-1) );
- if (i == LEX_MAX_BUFF-1) {
- printError("Line too long");
- }
- buff[i] = '\0';
- status = LEX_TOKEN;
- }
-
- if (c== '\r' && !feof(file)) {
- // 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'
- c = getc(file);
- }
-
- if (c=='\n')
- ++lineno;
-
- }
- if (status) return true;
-
- status = (feof(file)) ? LEX_FEOF: LEX_UNDEF;
- buff[0] = '\0';
- return false;
- } else {
- int c; // getc() returns an int
- int i;
-
-
- status = 0;
- while (!feof(file) && !status) {
- c = getc(file);
-
- // skip ','s
- if (c==',') continue;
-
- if (c=='\\') {
- // escape
- i = 0;
- do {
- if (c == '\\') {
- // escape the next char
- c = getc(file);
- }
- buff[i++] = c;
- c = getc(file);
- } while (c > ' ' && c != ',' && !feof(file) &&
- (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 :-)
- fgets(buff, sizeof(buff), file);
- ++lineno;
- continue;
- }
-
- // string
- if (c=='\"') {
- i = -1;
- bool escaped = false;
- do {
- escaped = false;
- c = getc(file);
- if (c == '\r') continue;
- if (c == '\\') {
- // escape the next char
- c = getc(file);
- escaped = true;
- }
- buff[++i] = c;
-
- if (!escaped && c == '\"') break;
- } while (c!='\n' && !feof(file) &&
- 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 > ' ' && !feof(file)) {
- i = 0;
- do {
- if (c == '\\') {
- // escape the next char
- c = getc(file);
- //escaped = true;
- }
- buff[i++] = c;
- c = getc(file);
- } while (c > ' ' && c != ',' && !feof(file) &&
- (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 = (feof(file)) ? LEX_FEOF: LEX_UNDEF;
- buff[0] = '\0';
- return false;