From: Georg Baum Date: Mon, 8 Nov 2004 08:24:43 +0000 (+0000) Subject: fix bug 1730 X-Git-Tag: 1.6.10~14849 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=246b54496ec19d087b503f048edbde04c97ff755;p=features.git fix bug 1730 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9203 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/tex2lyx/ChangeLog b/src/tex2lyx/ChangeLog index 43a069f19c..3dfd8ff984 100644 --- a/src/tex2lyx/ChangeLog +++ b/src/tex2lyx/ChangeLog @@ -1,3 +1,9 @@ +2004-11-07 Georg Baum + + * texparser.C (getNewline): new + * texparser.C (tokenize): fix bug 1730 by handling MAC line endings + correctly + 2004-10-29 Georg Baum * tex2lyx.C (formats): new, needed for libsupport.a diff --git a/src/tex2lyx/texparser.C b/src/tex2lyx/texparser.C index ea69d460d4..014c9a798f 100644 --- a/src/tex2lyx/texparser.C +++ b/src/tex2lyx/texparser.C @@ -39,14 +39,14 @@ void catInit() theCatcode[int('}')] = catEnd; theCatcode[int('$')] = catMath; theCatcode[int('&')] = catAlign; - theCatcode[10] = catNewline; + theCatcode[int('\n')] = 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[int('\r')] = 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 == '\r') { + // MAC or DOS + if (is.get(c) && c != '\n') { + // MAC + is.putback(c); + } + return '\n'; + } + // 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 +379,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; }