]> git.lyx.org Git - features.git/commitdiff
Fix reading of old format templates
authorDekel Tsur <dekelts@tau.ac.il>
Wed, 25 Sep 2002 12:19:13 +0000 (12:19 +0000)
committerDekel Tsur <dekelts@tau.ac.il>
Wed, 25 Sep 2002 12:19:13 +0000 (12:19 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5342 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.C
src/ChangeLog
src/buffer.C
src/buffer.h
src/bufferlist.C

index cf61629c17c3a855c9dfc1bd5e88374847a29138..514026d7f5b0ade64d3bd2f08ecdd6a27138768b 100644 (file)
@@ -315,7 +315,7 @@ bool BufferView::insertLyXFile(string const & filen)
 
        if (c == '#') {
                lyxerr[Debug::INFO] << "Will insert file with header" << endl;
-               res = buffer()->readFile(lex, text->cursor.par());
+               res = buffer()->readFile(lex, fname, text->cursor.par());
        } else {
                lyxerr[Debug::INFO] << "Will insert file without header"
                                    << endl;
index c00f0420a73e9798a6bfced4f0b3c71d05aa4fc4..754975a056d215c7c15d2393d0d3d52534f5983a 100644 (file)
@@ -1,3 +1,8 @@
+2002-09-25  Dekel Tsur  <dekelts@tau.ac.il>
+
+       * buffer.h (readFile): Add a new argument to the method, to allow
+       reading of old-format templates.
+
 2002-09-24  Dekel Tsur  <dekelts@tau.ac.il>
 
        * toc.C (getTocList): Get TOC from InsetWrap.
index 610f3dd2cdd26f48568e5a50813ff9e74fadba6e..0acfd71a7430df0f4c855a9318b6c2b751effeb1 100644 (file)
@@ -1143,7 +1143,7 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
 }
 
 
-bool Buffer::readFile(LyXLex & lex, Paragraph * par)
+bool Buffer::readFile(LyXLex & lex, string const & filename, Paragraph * par)
 {
        if (lex.isOK()) {
                lex.next();
@@ -1174,7 +1174,7 @@ bool Buffer::readFile(LyXLex & lex, Paragraph * par)
                                                   _("Old LyX file format found. "
                                                     "Use LyX 0.10.x to read this!"));
                                        return false;
-                               } else {
+                               } else if (!filename.empty()) {
                                        string command =
                                                LibFileSearch("lyx2lyx", "lyx2lyx");
                                        if (command.empty()) {
@@ -1184,7 +1184,9 @@ bool Buffer::readFile(LyXLex & lex, Paragraph * par)
                                        }
                                        command += " -t"
                                                +tostr(LYX_FORMAT)+" "
-                                               + QuoteName(filename_);
+                                               + QuoteName(filename);
+                                       lyxerr[Debug::INFO] << "Running '"
+                                                           << command << "'" << endl;
                                        cmd_ret const ret = RunCommand(command);
                                        if (ret.first) {
                                                Alert::alert(_("ERROR!"),
@@ -1195,7 +1197,13 @@ bool Buffer::readFile(LyXLex & lex, Paragraph * par)
                                        istringstream is(ret.second);
                                        LyXLex tmplex(0, 0);
                                        tmplex.setStream(is);
-                                       return readFile(tmplex);
+                                       return readFile(tmplex, string());
+                               } else {
+                                       // This code is reached if lyx2lyx failed (for
+                                       // some reason) to change the file format of
+                                       // the file.
+                                       lyx::Assert(false);
+                                       return false;
                                }
                        }
                        bool the_end = readLyXformat2(lex, par);
index 6e5a97c29e8442664d94340b0d8dcb951c949ac6..bae622f9e890559dd3ac1bd1e7906b3d7cfe9066 100644 (file)
@@ -108,7 +108,7 @@ public:
            \param par if != 0 insert the file.
            \return \c false if method fails.
        */
-       bool readFile(LyXLex &, Paragraph * par = 0);
+       bool readFile(LyXLex &, string const &, Paragraph * par = 0);
 
        /** Reads a file without header.
            \param par if != 0 insert the file.
index 51e042724c84f111cb0fb1aa807cdd7589a420dc..fc7609c0f7c69fdfdd446244007f4efad624b5da 100644 (file)
@@ -421,7 +421,7 @@ Buffer * BufferList::readFile(string const & s, bool ronly)
        // not sure if this is the correct place to begin LyXLex
        LyXLex lex(0, 0);
        lex.setFile(ts);
-       if (b->readFile(lex))
+       if (b->readFile(lex, ts))
                return b;
        else {
                bstore.release(b);
@@ -471,7 +471,7 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
                LyXLex lex(0, 0);
                lex.setFile(tname);
                if (lex.isOK()) {
-                       if (b->readFile(lex)) {
+                       if (b->readFile(lex, tname)) {
                                templateok = true;
                        }
                }