I've just committed this; it seems to work for me. Lars, please review.

this is a pre-cursor to moving the basic paragraph-parsing into
paragraph_pimpl.C, which should clean up the changes API in paragraph.h a
lot.

regards
john


? .xvpics
? a
? a.diff
? anime.eps
? anime2.eps
? anime3.eps
? anime4.eps
? anime5.eps
? anime6.eps
? anime7.eps
? anime8.eps
? anime9.eps
? b
? b.diff
? blink.diff
? borderimage.png
? broken.eps
? c
? core.10020
? cvs.log
? lt.diff
? lyx-n
? lyx-o
? matrix.diff
? newfile1.lyx
? newfile2.lyx
? newfile3.lyx
? newfile4.lyx
? newfile5.lyx
? patch
? patch.diff
? pd.diff
? pi.diff
? qdocument.diff
? qtabular.diff
? qwrap.diff
? qwrap.tar.gz
? rball.diff
? rball2.diff
? ref.diff
? rpall.diff
? s
? scroll.png
? ss
? tabular.diff
? texput.log
? text.diff
? toc-1.diff
? ts.diff
? frontends/a.diff
? frontends/cvs.log
? frontends/controllers/ControlListing.bak.C
? frontends/controllers/cvs.log
? frontends/qt2/QLyXKeySym.patch
? frontends/qt2/a
? frontends/qt2/a.cpp
? frontends/qt2/a.diff
? frontends/qt2/a.h
? frontends/qt2/a.moc.cpp
? frontends/qt2/core.30079
? frontends/qt2/cvs.log
? frontends/qt2/elbow.diff
? frontends/qt2/fm2.diff
? frontends/qt2/lg.diff
? frontends/qt2/patch
? frontends/qt2/patch1
? frontends/qt2/qfont_metrics.bak.C
? frontends/qt2/qfont_metrics.map.C
? frontends/qt2/qp.diff
? frontends/qt2/qurl.diff
? frontends/qt2/tr.diff
? frontends/qt2/ui/.xvpics
? frontends/qt2/ui/a.diff
? frontends/qt2/ui/patch2
? frontends/qt2/ui/uisedall
Index: BufferView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v
retrieving revision 1.124
diff -u -p -r1.124 BufferView.C
--- BufferView.C        12 Mar 2003 02:39:10 -0000      1.124
+++ BufferView.C        12 Mar 2003 05:40:13 -0000
@@ -318,12 +318,13 @@ bool BufferView::insertLyXFile(string co
        bool res = true;
 
        if (c == '#') {
+               // FIXME: huh ? No we won't !
                lyxerr[Debug::INFO] << "Will insert file with header" << endl;
-               res = buffer()->readFile(lex, fname, text->cursor.par());
+               res = buffer()->readFile(lex, fname, 
ParagraphList::iterator(text->cursor.par()));
        } else {
                lyxerr[Debug::INFO] << "Will insert file without header"
                                    << endl;
-               res = buffer()->readBody(lex, text->cursor.par());
+               res = buffer()->readBody(lex, 
ParagraphList::iterator(text->cursor.par()));
        }
 
        resize();
Index: buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.428
diff -u -p -r1.428 buffer.C
--- buffer.C    12 Mar 2003 02:59:56 -0000      1.428
+++ buffer.C    12 Mar 2003 05:40:15 -0000
@@ -339,7 +339,7 @@ int Buffer::readHeader(LyXLex & lex)
 // if par = 0 normal behavior
 // else insert behavior
 // Returns false if "\the_end" is not read (Asger)
-bool Buffer::readBody(LyXLex & lex, Paragraph * par)
+bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
 {
        unknown_layouts = 0;
        int unknown_tokens = 0;
@@ -348,17 +348,9 @@ bool Buffer::readBody(LyXLex & lex, Para
        Paragraph::depth_type depth = 0;
        bool the_end_read = false;
 
-       Paragraph * first_par = 0;
        LyXFont font(LyXFont::ALL_INHERIT, params.language);
 
-       if (!par) {
-               // New document
-               par = new Paragraph;
-               par->layout(params.getLyXTextClass().defaultLayout());
-               // mark the first paragraph
-               if (params.tracking_changes)
-                       par->trackChanges();
-
+       if (paragraphs.empty()) {
                unknown_tokens += readHeader(lex);
 
                if (!params.getLyXTextClass().load()) {
@@ -378,7 +370,6 @@ bool Buffer::readBody(LyXLex & lex, Para
        } else {
                // We are inserting into an existing document
                users->text->breakParagraph(users, paragraphs);
-               first_par = users->text->ownerParagraph();
                pos = 0;
                markDirty();
 
@@ -405,15 +396,9 @@ bool Buffer::readBody(LyXLex & lex, Para
                        continue;
                }
 
-               unknown_tokens += readToken(lex, par, first_par,
-                                           token, pos, depth, font);
+               unknown_tokens += readToken(lex, paragraphs, pit, token, pos, depth, 
font);
        }
 
-       if (!first_par)
-               first_par = par;
-
-       paragraphs.set(first_par);
-
        if (unknown_layouts > 0) {
                string s = _("Couldn't set the layout for ");
                if (unknown_layouts == 1) {
@@ -453,12 +438,11 @@ bool Buffer::readBody(LyXLex & lex, Para
 
 
 int
-Buffer::readToken(LyXLex & lex, Paragraph *& par,
-                                  Paragraph *& first_par,
-                                  string const & token, int & pos,
-                                  Paragraph::depth_type & depth,
-                                  LyXFont & font
-       )
+Buffer::readToken(LyXLex & lex, ParagraphList & pars,
+                  ParagraphList::iterator & pit,
+                  string const & token, int & pos,
+                  Paragraph::depth_type & depth,
+                  LyXFont & font)
 {
        static Change current_change;
        int unknown = 0;
@@ -471,7 +455,7 @@ Buffer::readToken(LyXLex & lex, Paragrap
        if (token[0] != '\\') {
                for (string::const_iterator cit = token.begin();
                     cit != token.end(); ++cit) {
-                       par->insertChar(pos, (*cit), font, current_change);
+                       pit->insertChar(pos, (*cit), font, current_change);
                        ++pos;
                }
        } else if (token == "\\layout") {
@@ -547,18 +531,14 @@ Buffer::readToken(LyXLex & lex, Paragrap
                        tmplex.setStream(is);
                        Inset * inset = new InsetCaption;
                        inset->Read(this, tmplex);
-                       par->InsertInset(pos, inset, font);
+                       pit->InsertInset(pos, inset, font);
                        ++pos;
                } else {
 #endif
-                       if (!first_par)
-                               first_par = par;
-                       else {
-                               par = new Paragraph(par);
-                               par->layout(params.getLyXTextClass().defaultLayout());
-                               if (params.tracking_changes)
-                                       par->trackChanges();
-                       }
+                       Paragraph * par = new Paragraph();
+                       par->layout(params.getLyXTextClass().defaultLayout());
+                       if (params.tracking_changes)
+                               par->trackChanges();
                        pos = 0;
                        par->layout(params.getLyXTextClass()[layoutname]);
                        // Test whether the layout is obsolete.
@@ -566,6 +546,10 @@ Buffer::readToken(LyXLex & lex, Paragrap
                        if (!layout->obsoleted_by().empty())
                                
par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
                        par->params().depth(depth);
+                       // insert after
+                       if (pit != pars.end())
+                               ++pit;
+                       pit = pars.insert(pit, par);
 #if USE_CAPTION
                }
 #endif
@@ -578,7 +562,7 @@ Buffer::readToken(LyXLex & lex, Paragrap
                // But insets should read it, it is a part of
                // the inset isn't it? Lgb.
        } else if (token == "\\begin_inset") {
-               readInset(lex, par, pos, font, current_change);
+               readInset(lex, pit, pos, font, current_change);
        } else if (token == "\\family") {
                lex.next();
                font.setLyXFamily(lex.getString());
@@ -627,17 +611,17 @@ Buffer::readToken(LyXLex & lex, Paragrap
                lex.next();
                font.setLyXColor(lex.getString());
        } else if (token == "\\SpecialChar") {
-               LyXLayout_ptr const & layout = par->layout();
+               LyXLayout_ptr const & layout = pit->layout();
 
                // Insets don't make sense in a free-spacing context! ---Kayvan
-               if (layout->free_spacing || par->isFreeSpacing()) {
+               if (layout->free_spacing || pit->isFreeSpacing()) {
                        if (lex.isOK()) {
                                lex.next();
                                string const next_token = lex.getString();
                                if (next_token == "\\-") {
-                                       par->insertChar(pos, '-', font, 
current_change);
+                                       pit->insertChar(pos, '-', font, 
current_change);
                                } else if (next_token == "~") {
-                                       par->insertChar(pos, ' ', font, 
current_change);
+                                       pit->insertChar(pos, ' ', font, 
current_change);
                                } else {
                                        lex.printError("Token `$$Token' "
                                                       "is in free space "
@@ -648,16 +632,16 @@ Buffer::readToken(LyXLex & lex, Paragrap
                } else {
                        Inset * inset = new InsetSpecialChar;
                        inset->read(this, lex);
-                       par->insertInset(pos, inset, font, current_change);
+                       pit->insertInset(pos, inset, font, current_change);
                }
                ++pos;
        } else if (token == "\\i") {
                Inset * inset = new InsetLatexAccent;
                inset->read(this, lex);
-               par->insertInset(pos, inset, font, current_change);
+               pit->insertInset(pos, inset, font, current_change);
                ++pos;
        } else if (token == "\\backslash") {
-               par->insertChar(pos, '\\', font, current_change);
+               pit->insertChar(pos, '\\', font, current_change);
                ++pos;
        } else if (token == "\\begin_deeper") {
                ++depth;
@@ -669,37 +653,37 @@ Buffer::readToken(LyXLex & lex, Paragrap
                else
                        --depth;
        } else if (token == "\\noindent") {
-               par->params().noindent(true);
+               pit->params().noindent(true);
        } else if (token == "\\leftindent") {
                lex.nextToken();
                LyXLength value(lex.getString());
-               par->params().leftIndent(value);
+               pit->params().leftIndent(value);
        } else if (token == "\\fill_top") {
-               par->params().spaceTop(VSpace(VSpace::VFILL));
+               pit->params().spaceTop(VSpace(VSpace::VFILL));
        } else if (token == "\\fill_bottom") {
-               par->params().spaceBottom(VSpace(VSpace::VFILL));
+               pit->params().spaceBottom(VSpace(VSpace::VFILL));
        } else if (token == "\\line_top") {
-               par->params().lineTop(true);
+               pit->params().lineTop(true);
        } else if (token == "\\line_bottom") {
-               par->params().lineBottom(true);
+               pit->params().lineBottom(true);
        } else if (token == "\\pagebreak_top") {
-               par->params().pagebreakTop(true);
+               pit->params().pagebreakTop(true);
        } else if (token == "\\pagebreak_bottom") {
-               par->params().pagebreakBottom(true);
+               pit->params().pagebreakBottom(true);
        } else if (token == "\\start_of_appendix") {
-               par->params().startOfAppendix(true);
+               pit->params().startOfAppendix(true);
        } else if (token == "\\paragraph_spacing") {
                lex.next();
                string const tmp = rtrim(lex.getString());
                if (tmp == "single") {
-                       par->params().spacing(Spacing(Spacing::Single));
+                       pit->params().spacing(Spacing(Spacing::Single));
                } else if (tmp == "onehalf") {
-                       par->params().spacing(Spacing(Spacing::Onehalf));
+                       pit->params().spacing(Spacing(Spacing::Onehalf));
                } else if (tmp == "double") {
-                       par->params().spacing(Spacing(Spacing::Double));
+                       pit->params().spacing(Spacing(Spacing::Double));
                } else if (tmp == "other") {
                        lex.next();
-                       par->params().spacing(Spacing(Spacing::Other,
+                       pit->params().spacing(Spacing(Spacing::Other,
                                         lex.getFloat()));
                } else {
                        lex.printError("Unknown spacing token: '$$Token'");
@@ -709,7 +693,7 @@ Buffer::readToken(LyXLex & lex, Paragrap
                if (tmpret == -1)
                        ++tmpret;
                int const tmpret2 = int(pow(2.0, tmpret));
-               par->params().align(LyXAlignment(tmpret2));
+               pit->params().align(LyXAlignment(tmpret2));
        } else if (token == "\\added_space_top") {
                lex.nextToken();
                VSpace value = VSpace(lex.getString());
@@ -718,7 +702,7 @@ Buffer::readToken(LyXLex & lex, Paragrap
                if ((value.length().len().value() != 0) ||
                    value.keep() ||
                    (value.kind() != VSpace::LENGTH))
-                       par->params().spaceTop(value);
+                       pit->params().spaceTop(value);
        } else if (token == "\\added_space_bottom") {
                lex.nextToken();
                VSpace value = VSpace(lex.getString());
@@ -727,33 +711,33 @@ Buffer::readToken(LyXLex & lex, Paragrap
                if ((value.length().len().value() != 0) ||
                   value.keep() ||
                    (value.kind() != VSpace::LENGTH))
-                       par->params().spaceBottom(value);
+                       pit->params().spaceBottom(value);
        } else if (token == "\\labelwidthstring") {
                lex.eatLine();
-               par->params().labelWidthString(lex.getString());
+               pit->params().labelWidthString(lex.getString());
                // do not delete this token, it is still needed!
        } else if (token == "\\newline") {
-               par->insertChar(pos, Paragraph::META_NEWLINE, font, current_change);
+               pit->insertChar(pos, Paragraph::META_NEWLINE, font, current_change);
                ++pos;
        } else if (token == "\\LyXTable") {
                Inset * inset = new InsetTabular(*this);
                inset->read(this, lex);
-               par->insertInset(pos, inset, font, current_change);
+               pit->insertInset(pos, inset, font, current_change);
                ++pos;
        } else if (token == "\\bibitem") {  // ale970302
                InsetCommandParams p("bibitem", "dummy");
                InsetBibitem * inset = new InsetBibitem(p);
                inset->read(this, lex);
-               par->insertInset(pos, inset, font, current_change);
+               pit->insertInset(pos, inset, font, current_change);
                ++pos;
        } else if (token == "\\hfill") {
-               par->insertInset(pos, new InsetHFill(),
+               pit->insertInset(pos, new InsetHFill(),
                        LyXFont(LyXFont::ALL_INHERIT, params.language));
                ++pos;
        } else if (token == "\\change_unchanged") {
                // Hack ! Needed for empty paragraphs :/
                if (!pos)
-                       par->cleanChanges();
+                       pit->cleanChanges();
                current_change = Change(Change::UNCHANGED);
        } else if (token == "\\change_inserted") {
                lex.nextToken();
@@ -786,7 +770,7 @@ Buffer::readToken(LyXLex & lex, Paragrap
                // we can do this here this way because we're actually reading
                // the buffer and don't care about LyXText right now.
                InsetError * new_inset = new InsetError(s);
-               par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
+               pit->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
                                 params.language));
 
        }
@@ -854,7 +838,7 @@ void Buffer::insertStringAsLines(Paragra
 }
 
 
-void Buffer::readInset(LyXLex & lex, Paragraph *& par,
+void Buffer::readInset(LyXLex & lex, ParagraphList::iterator pit,
                       int & pos, LyXFont & font, Change current_change)
 {
        // consistency check
@@ -970,13 +954,19 @@ void Buffer::readInset(LyXLex & lex, Par
        }
 
        if (inset) {
-               par->insertInset(pos, inset, font, current_change);
+               pit->insertInset(pos, inset, font, current_change);
                ++pos;
        }
 }
 
 
-bool Buffer::readFile(LyXLex & lex, string const & filename, Paragraph * par)
+bool Buffer::readFile(LyXLex & lex, string const & filename)
+{
+       return readFile(lex, filename, paragraphs.begin());
+}
+
+
+bool Buffer::readFile(LyXLex & lex, string const & filename, ParagraphList::iterator 
pit)
 {
        if (lex.isOK()) {
                lex.next();
@@ -1031,7 +1021,7 @@ bool Buffer::readFile(LyXLex & lex, stri
                                        istringstream is(STRCONV(ret.second));
                                        LyXLex tmplex(0, 0);
                                        tmplex.setStream(is);
-                                       return readFile(tmplex, string(), par);
+                                       return readFile(tmplex, string(), pit);
                                } else {
                                        // This code is reached if lyx2lyx failed (for
                                        // some reason) to change the file format of
@@ -1040,7 +1030,7 @@ bool Buffer::readFile(LyXLex & lex, stri
                                        return false;
                                }
                        }
-                       bool the_end = readBody(lex, par);
+                       bool the_end = readBody(lex, pit);
                        params.setPaperStuff();
 
                        if (!the_end) {
Index: buffer.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.h,v
retrieving revision 1.128
diff -u -p -r1.128 buffer.h
--- buffer.h    12 Mar 2003 02:39:11 -0000      1.128
+++ buffer.h    12 Mar 2003 05:40:16 -0000
@@ -92,11 +92,15 @@ public:
        /// Load the autosaved file.
        void loadAutoSaveFile();
 
-       /** Reads a file.
+       /** Inserts a file into a document
            \param par if != 0 insert the file.
            \return \c false if method fails.
        */
-       bool readFile(LyXLex &, string const &, Paragraph * par = 0);
+       bool readFile(LyXLex &, string const &, ParagraphList::iterator pit);
+
+       // FIXME: it's very silly to pass a lex in here
+       /// load a new file
+       bool readFile(LyXLex &, string const &);
 
        /// read the header, returns number of unknown tokens
        int readHeader(LyXLex & lex);
@@ -105,11 +109,11 @@ public:
            \param par if != 0 insert the file.
            \return \c false if file is not completely read.
        */
-       bool readBody(LyXLex &, Paragraph * par = 0);
+       bool readBody(LyXLex &, ParagraphList::iterator pit);
 
        /// This parses a single token
-       int readToken(LyXLex &, Paragraph *& par,
-                     Paragraph *& return_par,
+       int readToken(LyXLex &, ParagraphList & pars,
+                     ParagraphList::iterator & pit,
                      string const & token, int & pos,
                      Paragraph::depth_type & depth,
                      LyXFont &);
@@ -119,9 +123,11 @@ public:
                                 LyXFont const &, string const &);
        ///
        Paragraph * getParFromID(int id) const;
+
 private:
        /// Parse a single inset.
-       void readInset(LyXLex &, Paragraph *& par, int & pos, LyXFont &);
+       void readInset(LyXLex &, ParagraphList::iterator pit, int & pos, LyXFont &, 
Change current_change);
+
 public:
        /** Save file.
            Takes care of auto-save files and backup file if requested.
Index: tabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tabular.C,v
retrieving revision 1.148
diff -u -p -r1.148 tabular.C
--- tabular.C   12 Mar 2003 02:39:11 -0000      1.148
+++ tabular.C   12 Mar 2003 05:40:19 -0000
@@ -1446,17 +1446,15 @@ void LyXTabular::OldFormatRead(BufferPar
        }
        set_row_column_number_info(true);
 
-       Paragraph * par = new Paragraph;
-       Paragraph * return_par = 0;
-
-       par->layout(bp.getLyXTextClass().defaultLayout());
-
        string tmptok;
        int pos = 0;
        Paragraph::depth_type depth = 0;
        LyXFont font(LyXFont::ALL_INHERIT);
        font.setLanguage(owner_->bufferOwner()->getLanguage());
 
+       ParagraphList parlist;
+       ParagraphList::iterator pit = parlist.begin();
+       
        while (lex.isOK()) {
                lex.nextToken();
                string const token = lex.getString();
@@ -1476,17 +1474,13 @@ void LyXTabular::OldFormatRead(BufferPar
                        break;
                }
 
-               owner_->bufferOwner()->readToken(lex, par, return_par,
+               owner_->bufferOwner()->readToken(lex, parlist, pit,
                                                 token, pos, depth, font);
 
-               if (return_par) {
-                       lex.printError("New Paragraph allocated! This should not 
happen!");
-                       lex.pushToken(token);
-                       delete par;
-                       par = return_par;
-                       break;
-               }
        }
+
+       Paragraph * par = &(*parlist.begin());
+
        // now we have the par we should fill the insets with this!
        int cell = 0;
        InsetText * inset = GetCellInset(cell);
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.352
diff -u -p -r1.352 insettext.C
--- insets/insettext.C  12 Mar 2003 02:39:12 -0000      1.352
+++ insets/insettext.C  12 Mar 2003 05:40:23 -0000
@@ -262,7 +262,6 @@ void InsetText::read(Buffer const * buf,
 {
        string token;
        int pos = 0;
-       Paragraph * return_par = 0;
        Paragraph::depth_type depth = 0;
        LyXFont font(LyXFont::ALL_INHERIT);
 
@@ -271,6 +270,10 @@ void InsetText::read(Buffer const * buf,
        if (buf->params.tracking_changes)
                paragraphs.begin()->trackChanges();
 
+       // delete the initial paragraph
+       paragraphs.clear();
+       ParagraphList::iterator pit = paragraphs.begin();
+
        while (lex.isOK()) {
                lex.nextToken();
                token = lex.getString();
@@ -280,24 +283,21 @@ void InsetText::read(Buffer const * buf,
                        break;
                }
 
-               Paragraph * tmp = &*(paragraphs.begin());
-
                if (token == "\\the_end") {
                        lex.printError("\\the_end read in inset! Error in document!");
                        return;
                }
 
-               const_cast<Buffer*>(buf)->readToken(lex, tmp, return_par,
+               // FIXME: ugly.
+
+               const_cast<Buffer*>(buf)->readToken(lex, paragraphs, pit,
                                                    token, pos, depth, font);
-               paragraphs.set(tmp);
-       }
-       if (!return_par)
-               return_par = &*(paragraphs.begin());
-       paragraphs.set(return_par);
-       while (return_par) {
-               return_par->setInsetOwner(this);
-               return_par = return_par->next();
        }
+
+       pit = paragraphs.begin();
+       ParagraphList::iterator const end = paragraphs.end();
+       for (; pit != end; ++pit)
+               pit->setInsetOwner(this);
 
        if (token != "\\end_inset") {
                lex.printError("Missing \\end_inset at this point. "

Reply via email to