]> git.lyx.org Git - features.git/commitdiff
fix bug 1730
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 8 Nov 2004 08:24:43 +0000 (08:24 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 8 Nov 2004 08:24:43 +0000 (08:24 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9203 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/ChangeLog
src/tex2lyx/texparser.C

index 43a069f19c8969254ee4afe22108da3e6fff6569..3dfd8ff984e36ecba51fd14f6b2162d26b303ff2 100644 (file)
@@ -1,3 +1,9 @@
+2004-11-07  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * texparser.C (getNewline): new
+       * texparser.C (tokenize): fix bug 1730 by handling MAC line endings
+       correctly
+
 2004-10-29  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * tex2lyx.C (formats): new, needed for libsupport.a
index ea69d460d49c311960521319a3610ea385fbb50a..014c9a798f06edad9d82f01af3b8ae0881f79e2e 100644 (file)
@@ -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;
                        }