]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
fix "make dist" target
[lyx.git] / src / buffer.C
index b5ff03380eda6139fcddcdd9898d335367a18e0c..b70fca7b6316e2449268764dc939c4c51b639386 100644 (file)
 #include "insets/insettabular.h"
 #include "insets/insettheorem.h"
 #include "insets/insetcaption.h"
+#include "insets/insetfloatlist.h"
 #include "support/filetools.h"
 #include "support/path.h"
+#include "support/os.h"
 #include "LaTeX.h"
 #include "Chktex.h"
 #include "LyXView.h"
@@ -1181,40 +1183,44 @@ void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
                InsetCommandParams inscmd;
                inscmd.Read(lex);
 
-               if (inscmd.getCmdName() == "cite") {
+               string const cmdName = inscmd.getCmdName();
+               
+               if (cmdName == "cite") {
                        inset = new InsetCitation(inscmd);
-               } else if (inscmd.getCmdName() == "bibitem") {
+               } else if (cmdName == "bibitem") {
                        lex.printError("Wrong place for bibitem");
                        inset = new InsetBibKey(inscmd);
-               } else if (inscmd.getCmdName() == "BibTeX") {
+               } else if (cmdName == "BibTeX") {
                        inset = new InsetBibtex(inscmd);
-               } else if (inscmd.getCmdName() == "index") {
+               } else if (cmdName == "index") {
                        inset = new InsetIndex(inscmd);
-               } else if (inscmd.getCmdName() == "include") {
+               } else if (cmdName == "include") {
                        inset = new InsetInclude(inscmd, *this);
-               } else if (inscmd.getCmdName() == "label") {
+               } else if (cmdName == "label") {
                        inset = new InsetLabel(inscmd);
-               } else if (inscmd.getCmdName() == "url"
-                          || inscmd.getCmdName() == "htmlurl") {
+               } else if (cmdName == "url"
+                          || cmdName == "htmlurl") {
                        inset = new InsetUrl(inscmd);
-               } else if (inscmd.getCmdName() == "ref"
-                          || inscmd.getCmdName() == "pageref"
-                          || inscmd.getCmdName() == "vref"
-                          || inscmd.getCmdName() == "vpageref"
-                          || inscmd.getCmdName() == "prettyref") {
+               } else if (cmdName == "ref"
+                          || cmdName == "pageref"
+                          || cmdName == "vref"
+                          || cmdName == "vpageref"
+                          || cmdName == "prettyref") {
                        if (!inscmd.getOptions().empty()
                            || !inscmd.getContents().empty()) {
                                inset = new InsetRef(inscmd, *this);
                        }
-               } else if (inscmd.getCmdName() == "tableofcontents"
-                          || inscmd.getCmdName() == "listofalgorithms"
-                          || inscmd.getCmdName() == "listoffigures"
-                          || inscmd.getCmdName() == "listoftables"
-                          || inscmd.getCmdName() == "listof{algorithm}{List of Algorithms}") {
+               } else if (cmdName == "tableofcontents") {
                        inset = new InsetTOC(inscmd);
-               } else if (inscmd.getCmdName() == "printindex") {
+               } else if (cmdName == "listofalgorithms") {
+                       inset = new InsetFloatList("algorithm");
+               } else if (cmdName == "listoffigures") {
+                       inset = new InsetFloatList("figure");
+               } else if (cmdName == "listoftables") {
+                       inset = new InsetFloatList("table");
+               } else if (cmdName == "printindex") {
                        inset = new InsetPrintIndex(inscmd);
-               } else if (inscmd.getCmdName() == "lyxparent") {
+               } else if (cmdName == "lyxparent") {
                        inset = new InsetParent(inscmd, *this);
                }
        } else {
@@ -1257,6 +1263,8 @@ void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
                        inset = new InsetCaption;
                } else if (tmptok == "GRAPHICS") {
                        inset = new InsetGraphics;
+               } else if (tmptok == "FloatList") {
+                       inset = new InsetFloatList;
                }
                
                if (inset) inset->Read(this, lex);
@@ -1334,7 +1342,7 @@ bool Buffer::save() const
                s = fileName() + '~';
                if (!lyxrc.backupdir_path.empty())
                        s = AddName(lyxrc.backupdir_path,
-                                   subst(CleanupPath(s),'/','!'));
+                                   subst(os::slashify_path(s),'/','!'));
 
                // Rename is the wrong way of making a backup,
                // this is the correct way.
@@ -1457,12 +1465,11 @@ bool Buffer::writeFile(string const & fname, bool flag) const
        // now write out the buffer paramters.
        params.writeFile(ofs);
 
-       char footnoteflag = 0;
        char depth = 0;
 
        // this will write out all the paragraphs
        // using recursive descent.
-       paragraph->writeFile(this, ofs, params, footnoteflag, depth);
+       paragraph->writeFile(this, ofs, params, depth);
 
        // Write marker that shows file is complete
        ofs << "\n\\the_end" << endl;
@@ -1498,10 +1505,6 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
                                    unsigned int linelen) const
 {
        ostringstream buffer;
-       LyXFont font1;
-       LyXFont font2;
-       Inset const * inset;
-       char c;
        char depth = 0;
        int ltype = 0;
        int ltype_depth = 0;
@@ -1511,7 +1514,7 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
        int noparbreak = 0;
        int islatex = 0;
        if (!par->previous()) {
-               /* begins or ends a deeper area ?*/ 
+               // begins or ends a deeper area ?
                if (depth != par->params.depth()) {
                        if (par->params.depth() > depth) {
                                while (par->params.depth() > depth) {
@@ -1524,7 +1527,7 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
                        }
                }
                
-               /* First write the layout */
+               // First write the layout
                string const tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
                if (tmp == "Itemize") {
                        ltype = 1;
@@ -1567,7 +1570,7 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
                lyxerr << "Should this ever happen?" << endl;
        }
       
-       font1 = LyXFont(LyXFont::ALL_INHERIT, params.language);
+       LyXFont const font1 = LyXFont(LyXFont::ALL_INHERIT, params.language);
        for (LyXParagraph::size_type i = 0; i < par->size(); ++i) {
                if (!i && !noparbreak) {
                        if (linelen > 0)
@@ -1576,17 +1579,17 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
                                buffer << "  ";
                        currlinelen = depth * 2;
                        switch (ltype) {
-                       case 0: /* Standard */
-                       case 4: /* (Sub)Paragraph */
-                       case 5: /* Description */
+                       case 0: // Standard
+                       case 4: // (Sub)Paragraph
+                       case 5: // Description
                                break;
-                       case 6: /* Abstract */
+                       case 6: // Abstract
                                if (linelen > 0)
                                        buffer << "Abstract\n\n";
                                else
                                        buffer << "Abstract: ";
                                break;
-                       case 7: /* Bibliography */
+                       case 7: // Bibliography
                                if (!ref_printed) {
                                        if (linelen > 0)
                                                buffer << "References\n\n";
@@ -1605,7 +1608,7 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
                                currlinelen += (ltype_depth-depth)*2;
                        }
                }
-               font2 = par->GetFontSettings(params, i);
+               LyXFont const font2 = par->GetFontSettings(params, i);
                if (font1.latex() != font2.latex()) {
                        if (font2.latex() == LyXFont::OFF)
                                islatex = 0;
@@ -1614,23 +1617,29 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
                } else {
                        islatex = 0;
                }
-               c = par->GetUChar(params, i);
+               
+               char c = par->GetUChar(params, i);
                if (islatex)
                        continue;
                switch (c) {
                case LyXParagraph::META_INSET:
-                       if ((inset = par->GetInset(i))) {
+               {
+                       Inset const * inset = par->GetInset(i);
+                       if (inset) {
                                if (!inset->Ascii(this, buffer)) {
                                        string dummy;
-                                       string s = rsplit(buffer.str().c_str(),
-                                                         dummy, '\n');
+                                       string const s =
+                                               rsplit(buffer.str().c_str(),
+                                                      dummy, '\n');
                                        currlinelen += s.length();
                                } else {
                                        // to be sure it breaks paragraph
                                        currlinelen += linelen;
                                }
                        }
-                       break;
+               }
+               break;
+               
                case LyXParagraph::META_NEWLINE:
                        if (linelen > 0) {
                                buffer << "\n";
@@ -1645,12 +1654,15 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
                                currlinelen += (ltype_depth - depth) * 2;
                        }
                        break;
+                       
                case LyXParagraph::META_HFILL: 
                        buffer << "\t";
                        break;
+                       
                case '\\':
                        buffer << "\\";
                        break;
+                       
                default:
                        if ((linelen > 0) && (currlinelen > (linelen - 10)) &&
                            (c == ' ') && ((i + 2) < par->size()))
@@ -1758,7 +1770,7 @@ void Buffer::makeLaTeXFile(string const & fname,
                if (!original_path.empty()) {
                        ofs << "\\makeatletter\n"
                            << "\\def\\input@path{{"
-                           << original_path << "/}}\n"
+                           << os::external_path(original_path) << "/}}\n"
                            << "\\makeatother\n";
                        texrow.newline();
                        texrow.newline();
@@ -1767,13 +1779,12 @@ void Buffer::makeLaTeXFile(string const & fname,
                
                ofs << "\\documentclass";
                
-               string options; // the document class options.
+               ostringstream options; // the document class options.
                
                if (tokenPos(tclass.opt_fontsize(),
                             '|', params.fontsize) >= 0) {
                        // only write if existing in list (and not default)
-                       options += params.fontsize;
-                       options += "pt,";
+                       options << params.fontsize << "pt,";
                }
                
                
@@ -1781,22 +1792,22 @@ void Buffer::makeLaTeXFile(string const & fname,
                    (params.paperpackage == BufferParams::PACKAGE_NONE)) {
                        switch (params.papersize) {
                        case BufferParams::PAPER_A4PAPER:
-                               options += "a4paper,";
+                               options << "a4paper,";
                                break;
                        case BufferParams::PAPER_USLETTER:
-                               options += "letterpaper,";
+                               options << "letterpaper,";
                                break;
                        case BufferParams::PAPER_A5PAPER:
-                               options += "a5paper,";
+                               options << "a5paper,";
                                break;
                        case BufferParams::PAPER_B5PAPER:
-                               options += "b5paper,";
+                               options << "b5paper,";
                                break;
                        case BufferParams::PAPER_EXECUTIVEPAPER:
-                               options += "executivepaper,";
+                               options << "executivepaper,";
                                break;
                        case BufferParams::PAPER_LEGALPAPER:
-                               options += "legalpaper,";
+                               options << "legalpaper,";
                                break;
                        }
                }
@@ -1805,30 +1816,29 @@ void Buffer::makeLaTeXFile(string const & fname,
                if (params.sides != tclass.sides()) {
                        switch (params.sides) {
                        case LyXTextClass::OneSide:
-                               options += "oneside,";
+                               options << "oneside,";
                                break;
                        case LyXTextClass::TwoSides:
-                               options += "twoside,";
+                               options << "twoside,";
                                break;
                        }
-
                }
 
                // if needed
                if (params.columns != tclass.columns()) {
                        if (params.columns == 2)
-                               options += "twocolumn,";
+                               options << "twocolumn,";
                        else
-                               options += "onecolumn,";
+                               options << "onecolumn,";
                }
 
                if (!params.use_geometry 
                    && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
-                       options += "landscape,";
+                       options << "landscape,";
                
                // language should be a parameter to \documentclass
                use_babel = false;
-               string language_options;
+               ostringstream language_options;
                if (params.language->babel() == "hebrew"
                    && default_language->babel() != "hebrew")
                         // This seems necessary
@@ -1841,20 +1851,21 @@ void Buffer::makeLaTeXFile(string const & fname,
                        for (LaTeXFeatures::LanguageList::const_iterator cit =
                                     features.UsedLanguages.begin();
                             cit != features.UsedLanguages.end(); ++cit)
-                               language_options += (*cit)->babel() + ',';
-                       language_options += params.language->babel();
+                               language_options << (*cit)->babel() << ',';
+                       language_options << params.language->babel();
                        if (lyxrc.language_global_options)
-                               options += language_options + ',';
+                               options << language_options.str() << ',';
                }
 
                // the user-defined options
                if (!params.options.empty()) {
-                       options += params.options + ',';
+                       options << params.options << ',';
                }
-               
-               if (!options.empty()){
-                       options = strip(options, ',');
-                       ofs << '[' << options << ']';
+
+               string strOptions(options.str().c_str());
+               if (!strOptions.empty()){
+                       strOptions = strip(strOptions, ',');
+                       ofs << '[' << strOptions << ']';
                }
                
                ofs << '{'
@@ -2030,8 +2041,9 @@ void Buffer::makeLaTeXFile(string const & fname,
                        string tmp = lyxrc.language_package;
                        if (!lyxrc.language_global_options
                            && tmp == "\\usepackage{babel}")
-                               tmp = "\\usepackage[" +
-                                       language_options + "]{babel}";
+                               tmp = string("\\usepackage[") +
+                                       language_options.str().c_str() +
+                                       "]{babel}";
                        ofs << tmp << "\n";
                        texrow.newline();
                }
@@ -2212,9 +2224,6 @@ void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
 {
        bool was_title = false;
        bool already_title = false;
-       std::ostringstream ftnote;
-       TexRow ft_texrow;
-       int ftcount = 0;
 
        // if only_body
        while (par != endpar) {
@@ -2235,32 +2244,12 @@ void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
                        already_title = true;
                        was_title = false;                  
                }
-               // We are at depth 0 so we can just use
-               // ordinary \footnote{} generation
-               // flag this with ftcount
-               ftcount = -1;
+               
                if (layout.isEnvironment()) {
                        par = par->TeXEnvironment(this, params, ofs, texrow);
                } else {
                        par = par->TeXOnePar(this, params, ofs, texrow, false);
                }
-
-               // Write out what we've generated...
-               if (ftcount >= 1) {
-                       if (ftcount > 1) {
-                               ofs << "\\addtocounter{footnote}{-"
-                                   << ftcount - 1
-                                   << '}';
-                       }
-                       ofs << ftnote.str();
-                       texrow += ft_texrow;
-
-                       // The extra .c_str() is needed when we use
-                       // lyxstring instead of the STL string class. 
-                       ftnote.str(string().c_str());
-                       ft_texrow.reset();
-                       ftcount = 0;
-               }
        }
        // It might be that we only have a title in this document
        if (was_title && !already_title) {
@@ -3362,54 +3351,54 @@ Buffer::Lists const Buffer::getLists() const
                .NumberOfLayout(params.textclass, "Caption");
 
        while (par) {
-                       char const labeltype =
-                               textclasslist.Style(params.textclass, 
-                                                   par->GetLayout()).labeltype;
-      
-                       if (labeltype >= LABEL_COUNTER_CHAPTER
-                           && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
+               char const labeltype =
+                       textclasslist.Style(params.textclass, 
+                                           par->GetLayout()).labeltype;
+               
+               if (labeltype >= LABEL_COUNTER_CHAPTER
+                   && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
                                // insert this into the table of contents
-                               SingleList & item = l["TOC"];
-                               int depth = max(0,
-                                               labeltype - 
-                                               textclasslist.TextClass(params.textclass).maxcounter());
-                               item.push_back(TocItem(par, depth, par->String(this, true)));
-                       }
-                       // For each paragrph, traverse its insets and look for
-                       // FLOAT_CODE
+                       SingleList & item = l["TOC"];
+                       int depth = max(0,
+                                       labeltype - 
+                                       textclasslist.TextClass(params.textclass).maxcounter());
+                       item.push_back(TocItem(par, depth, par->String(this, true)));
+               }
+               // For each paragrph, traverse its insets and look for
+               // FLOAT_CODE
+               
+               if (found) {
+                       LyXParagraph::inset_iterator it =
+                               par->inset_iterator_begin();
+                       LyXParagraph::inset_iterator end =
+                               par->inset_iterator_end();
                        
-                       if (found) {
-                               LyXParagraph::inset_iterator it =
-                                       par->inset_iterator_begin();
-                               LyXParagraph::inset_iterator end =
-                                       par->inset_iterator_end();
-
-                               for (; it != end; ++it) {
-                                       if ((*it)->LyxCode() == Inset::FLOAT_CODE) {
-                                               InsetFloat * il =
-                                                       static_cast<InsetFloat*>(*it);
-                                               
-                                               string const type = il->type();
-                                               
-                                               // Now find the caption in the float...
-                                               // We now tranverse the paragraphs of
-                                               // the inset...
-                                               LyXParagraph * tmp = il->inset.par;
-                                               while (tmp) {
-                                                       if (tmp->layout == cap) {
-                                                               SingleList & item = l[type];
-                                                               string const str =
-                                                                       tostr(item.size()+1) + ". " + tmp->String(this, false);
-                                                               item.push_back(TocItem(tmp, 0 , str));
-                                                       }
-                                                       tmp = tmp->next();
+                       for (; it != end; ++it) {
+                               if ((*it)->LyxCode() == Inset::FLOAT_CODE) {
+                                       InsetFloat * il =
+                                               static_cast<InsetFloat*>(*it);
+                                       
+                                       string const type = il->type();
+                                       
+                                       // Now find the caption in the float...
+                                       // We now tranverse the paragraphs of
+                                       // the inset...
+                                       LyXParagraph * tmp = il->inset.par;
+                                       while (tmp) {
+                                               if (tmp->layout == cap) {
+                                                       SingleList & item = l[type];
+                                                       string const str =
+                                                               tostr(item.size()+1) + ". " + tmp->String(this, false);
+                                                       item.push_back(TocItem(tmp, 0 , str));
                                                }
+                                               tmp = tmp->next();
                                        }
                                }
-                       } else {
-                               lyxerr << "caption not found" << endl;
                        }
-                       
+               } else {
+                       lyxerr << "caption not found" << endl;
+               }
+               
                par = par->next();
        }
        return l;