tex2lyx currently deals with DOS line endings (\r\n) by ignoring \r. MAC line endings are not recognized at all. The attached patch changes this so that \r\n and \r are both read as \n. This enables tex2lyx to read files with MAC line endings, even mixed line endings are possible. tex itself does this, too. I'll apply this if nobody complains.
Georg
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/tex2lyx/ChangeLog lyx-1.4-cvs/src/tex2lyx/ChangeLog --- lyx-1.4-clean/src/tex2lyx/ChangeLog 2004-10-29 20:07:14.000000000 +0200 +++ lyx-1.4-cvs/src/tex2lyx/ChangeLog 2004-11-07 09:59:08.000000000 +0100 @@ -1,3 +1,9 @@ +2004-11-07 Georg Baum <[EMAIL PROTECTED]> + + * texparser.C (getNewline): new + * texparser.C (tokenize): fix bug 1730 by handling MAC line endings + correctly + 2004-10-29 Georg Baum <[EMAIL PROTECTED]> * tex2lyx.C (formats): new, needed for libsupport.a diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/tex2lyx/texparser.C lyx-1.4-cvs/src/tex2lyx/texparser.C --- lyx-1.4-clean/src/tex2lyx/texparser.C 2004-06-18 08:36:10.000000000 +0200 +++ lyx-1.4-cvs/src/tex2lyx/texparser.C 2004-11-07 09:43:04.000000000 +0100 @@ -39,14 +39,14 @@ void catInit() theCatcode[int('}')] = catEnd; theCatcode[int('$')] = catMath; theCatcode[int('&')] = catAlign; - theCatcode[10] = catNewline; + theCatcode[10] = catNewline; theCatcode[int('#')] = catParameter; theCatcode[int('^')] = catSuper; theCatcode[int('_')] = catSub; - theCatcode[0x7f] = catIgnore; + theCatcode[0x7f] = catIgnore; theCatcode[int(' ')] = catSpace; theCatcode[int('\t')] = catSpace; - theCatcode[13] = catIgnore; + theCatcode[13] = catNewline; theCatcode[int('~')] = catActive; theCatcode[int('%')] = catComment; @@ -54,6 +54,30 @@ void catInit() theCatcode[int('@')] = catLetter; } + +/*! + * Translate a line ending to '\n'. + * \p c must have catcode catNewline, and it must be the last character read + * from \p is. + */ +char getNewline(istream & is, char c) +{ + // we have to handle 3 different line endings: + // - UNIX (\n) + // - MAC (\r) + // - DOS (\r\n) + if (c == 13) { + // MAC or DOS + if (is.get(c) && c != 10) { + // MAC + is.putback(c); + } + return 10; + } + // UNIX + return c; +} + } @@ -309,10 +333,10 @@ void Parser::tokenize(istream & is) case catNewline: { ++lineno_; - string s(1, c); + string s(1, getNewline(is, c)); while (is.get(c) && catcode(c) == catNewline) { ++lineno_; - s += c; + s += getNewline(is, c); } if (catcode(c) != catNewline) is.putback(c); @@ -326,6 +350,9 @@ void Parser::tokenize(istream & is) string s; while (is.get(c) && catcode(c) != catNewline) s += c; + // handle possible DOS line ending + if (catcode(c) == catNewline) + c = getNewline(is, c); // Note: The '%' at the beginning and the '\n' at the end // of the comment are not stored. ++lineno_; @@ -352,8 +378,7 @@ void Parser::tokenize(istream & is) } case catIgnore: { - if (c != 13) - cerr << "ignoring a char: " << int(c) << "\n"; + cerr << "ignoring a char: " << int(c) << "\n"; break; }