]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
Remove the headers, since I added cheaders/CVS by mistake :(
[lyx.git] / src / buffer.C
index 2d9e0a19a5243d36d8f8d3ef703c3ff4a15603c9..6ac2a892f03fa0fc4f2bf3517f1304b4977a0242 100644 (file)
@@ -3,13 +3,13 @@
  * 
  *           LyX, The Document Processor
  *
- *          Copyright (C) 1995 Matthias Ettrich
- *           Copyright (C) 1995-1998 The LyX Team.
+ *          Copyright 1995 Matthias Ettrich
+ *           Copyright 1995-1999 The LyX Team.
  *
- *           This file is Copyright (C) 1996-1998
+ *           This file is Copyright 1996-1999
  *           Lars Gullik Bjønnes
  *
- *======================================================
+ * ======================================================
  */
 
 // Change Log:
@@ -23,7 +23,7 @@
 
 #include <config.h>
 
-#include <stdlib.h>
+#include <cstdlib>
 #include <unistd.h>
 
 #ifdef __GNUG__
 #include "insets/insetparent.h"
 #include "insets/insetspecialchar.h"
 #include "insets/figinset.h"
-#include "filetools.h"
-#include "pathstack.h"
+#include "support/filetools.h"
+#include "support/path.h"
 #include "LaTeX.h"
 #include "Literate.h"
 #include "Chktex.h"
 #include "LyXView.h"
-#include "error.h"
+#include "debug.h"
 #include "LaTeXFeatures.h"
-#include "syscall.h"
-#include "lyxlib.h"
-#include "FileInfo.h"
+#include "support/syscall.h"
+#include "support/lyxlib.h"
+#include "support/FileInfo.h"
 #include "lyxtext.h"
 #include "gettext.h"
 
-
-//     $Id: buffer.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $    
-
-#if !defined(lint) && !defined(WITH_WARNINGS)
-static char vcid[] = "$Id: buffer.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $";
-#endif /* lint */
-
-
 // Uncomment this line to enable a workaround for the weird behaviour
 // of the cursor between a displayed inset and last character
 // at the upper line. (Alejandro 20.9.96)
@@ -108,32 +100,32 @@ extern int tex_code_break_column;
 extern void FreeUpdateTimer();
 
 
-Buffer::Buffer(LString const & file, LyXRC *lyxrc, bool ronly)
+Buffer::Buffer(string const & file, LyXRC *lyxrc, bool ronly)
 {
        filename = file;
        filepath = OnlyPath(file);
-       paragraph = NULL;
-       text = NULL;
-       the_locking_inset = NULL;
+       paragraph = 0;
+       text = 0;
+       the_locking_inset = 0;
        lyx_clean = true;
        bak_clean = true;
        dvi_clean_orgd = false;  // Heinrich Bauer, 23/03/98
        dvi_clean_tmpd = false;  // Heinrich Bauer, 23/03/98
-       dep_clean = NULL;
+       dep_clean = 0;
        read_only = ronly;
        inset_slept = false;
        users = 0;
        lyxvc.setBuffer(this);
-       lyxerr.debug("Buffer::Buffer()");
+       lyxerr.debug() << "Buffer::Buffer()" << endl;
        if (read_only || (lyxrc && lyxrc->use_tempdir)) {
                tmppath = CreateBufferTmpDir();
-       } else tmppath.clean();
+       } else tmppath.erase();
 }
 
 
 Buffer::~Buffer()
 {
-       lyxerr.debug("Buffer::~Buffer()");
+       lyxerr.debug() << "Buffer::~Buffer()" << endl;
        // here the buffer should take care that it is
        // saved properly, before it goes into the void.
 
@@ -153,14 +145,14 @@ Buffer::~Buffer()
                delete par;
                par = tmppar;
        }
-       paragraph = NULL;
+       paragraph = 0;
        delete text;
 }
 
 
 bool Buffer::saveParamsAsDefaults()
 {
-       LString fname = AddName(AddPath(user_lyxdir, "templates/"),
+       string fname = AddName(AddPath(user_lyxdir, "templates/"),
                                "defaults.lyx");
        Buffer defaults = Buffer(fname);
        
@@ -189,7 +181,7 @@ void Buffer::resetAutosaveTimers()
 }
 
 
-void Buffer::setFileName(LString const & newfile)
+void Buffer::setFileName(string const & newfile)
 {
        filename = MakeAbsPath(newfile);
        filepath = OnlyPath(filename);
@@ -201,7 +193,7 @@ void Buffer::InsetUnlock()
 {
        if (the_locking_inset) {
                if (!inset_slept) the_locking_inset->InsetUnlock();
-               the_locking_inset = NULL;
+               the_locking_inset = 0;
                text->FinishUndo();
                inset_slept = false;
        }
@@ -209,7 +201,7 @@ void Buffer::InsetUnlock()
 
 
 // Inserts a file into current document
-bool Buffer::insertLyXFile(LString const & filen)
+bool Buffer::insertLyXFile(string const & filen)
        //
        // (c) CHT Software Service GmbH
        // Uwe C. Schroeder
@@ -220,7 +212,7 @@ bool Buffer::insertLyXFile(LString const & filen)
 {
        if (filen.empty()) return false;
 
-       LString filename = MakeAbsPath(filen);
+       string filename = MakeAbsPath(filen);
 
        // check if file exist
        FileInfo fi(filename);
@@ -241,7 +233,7 @@ bool Buffer::insertLyXFile(LString const & filen)
                           MakeDisplayPath(filename,50));
                return false;
        }
-       LyXLex lex(NULL, 0);
+       LyXLex lex(0, 0);
        lex.setFile(myfile);
        int c = fgetc(myfile());
        ungetc(c, myfile);
@@ -249,10 +241,10 @@ bool Buffer::insertLyXFile(LString const & filen)
        bool res = true;
 
        if (c=='#') {
-               lyxerr.debug("Will insert file with header");
+               lyxerr.debug() << "Will insert file with header" << endl;
                res = readFile(lex, text->cursor.par);
        } else {
-               lyxerr.debug("Will insert file without header");
+               lyxerr.debug() << "Will insert file without header" << endl;
                res = readLyXformat2(lex, text->cursor.par);
        }
        resize();
@@ -263,12 +255,12 @@ bool Buffer::insertLyXFile(LString const & filen)
 //
 // Uwe C. Schroeder
 // changed to be public and have one parameter
-// if par = NULL normal behavior
+// if par = 0 normal behavior
 // else insert behavior
 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
 bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
 {
-       LString tmptok;
+       string tmptok;
        Inset *inset = 0;
        int pos = 0;
        int tmpret, tmpret2;
@@ -277,12 +269,12 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
        LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
        bool the_end_read = false;
 
-       LyXParagraph *return_par = NULL;
+       LyXParagraph *return_par = 0;
        LyXFont font = LyXFont(LyXFont::ALL_INHERIT);
 
        // If we are inserting, we cheat and get a token in advance
        bool has_token = false;
-       LString pretoken;
+       string pretoken;
 
        if(!par) {
                par = new LyXParagraph();
@@ -312,7 +304,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                }
 
                // Profiling show this should give a lot: (Asger)
-               LString const token = pretoken;
+               string const token = pretoken;
 
                if (token.empty())
                        continue;
@@ -401,7 +393,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                                // I can substitute but I don't see how I can
                                // stop loading... ideas??  ARRae980418
                                WriteAlert(_("Textclass Loading Error!"),
-                                          LString(_("Can't load textclass ")) +
+                                          string(_("Can't load textclass ")) +
                                           lyxstyle.NameOfClass(params.textclass),
                                           _("-- substituting default"));
                                params.textclass = 0;
@@ -550,8 +542,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                        params.footskip = lex.GetString();
                } else if (token == "\\paperfontsize") {
                        lex.nextToken();
-                       params.fontsize = lex.GetString();
-                       params.fontsize.strip();
+                       params.fontsize = strip(lex.GetString());
                } else if (token == "\\papercolumns") {
                        lex.nextToken();
                        params.columns = lex.GetInteger();
@@ -560,8 +551,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                        params.sides = lex.GetInteger();
                } else if (token == "\\paperpagestyle") {
                        lex.nextToken();
-                       params.pagestyle = lex.GetString();
-                       params.pagestyle.strip();
+                       params.pagestyle = strip(lex.GetString());
                } else if (token == "\\bullet") {
                        lex.nextToken();
                        int index = lex.GetInteger();
@@ -578,7 +568,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                        params.user_defined_bullets[index].setSize(temp_int);
                        params.temp_bullets[index].setSize(temp_int);
                        lex.nextToken();
-                       LString temp_str = lex.GetString();
+                       string temp_str = lex.GetString();
                        if (temp_str != "\\end_bullet") {
                                // this element isn't really necessary for
                                // parsing but is easier for humans
@@ -591,7 +581,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                        lex.nextToken();
                        int index = lex.GetInteger();
                        lex.next();
-                       LString temp_str = lex.GetString(), sum_str;
+                       string temp_str = lex.GetString(), sum_str;
                        while (temp_str != "\\end_bullet") {
                                // this loop structure is needed when user
                                // enters an empty string since the first
@@ -619,7 +609,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                        params.spacing.set(Spacing::Other, lex.GetFloat());
                } else if (token == "\\spacing") {
                        lex.next();
-                       LString tmp = lex.GetString().strip();
+                       string tmp = strip(lex.GetString());
                        if (tmp == "single") {
                                params.spacing.set(Spacing::Single);
                        } else if (tmp == "onehalf") {
@@ -653,7 +643,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                        font.setLyXSize(lex.GetString());
                } else if (token == "\\latex") {
                        lex.next();
-                       LString tok = lex.GetString();
+                       string tok = lex.GetString();
                        // This is dirty, but gone with LyX3. (Asger)
                        if (tok == "no_latex")
                                font.setLatex(LyXFont::OFF);
@@ -669,7 +659,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                        font.setEmph(font.setLyXMisc(lex.GetString()));
                } else if (token == "\\bar") {
                        lex.next();
-                       LString tok = lex.GetString();
+                       string tok = lex.GetString();
                        // This is dirty, but gone with LyX3. (Asger)
                        if (tok == "under")
                                font.setUnderbar(LyXFont::ON);
@@ -742,8 +732,8 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                        } else if (tmptok == "Latex") {
                                // This one is on its way out
                                lex.EatLine();
-                               tmptok = lex.GetString().strip();
-                               //lyxerr.print(LString(tmptok[0]));
+                               tmptok = strip(lex.GetString());
+                               //lyxerr <<string(tmptok[0]));
                                if (tmptok[0] == '\\') {
                                        // then this latex is a
                                        // latex command
@@ -764,8 +754,8 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                        } else if (tmptok == "LatexDel") {
                                // This one is on its way out...
                                lex.EatLine();
-                               tmptok = lex.GetString().strip();
-                               //lyxerr.print(LString(tmptok[0]));
+                               tmptok = strip(lex.GetString());
+                               //lyxerr <<string(tmptok[0]));
                                if (tmptok == "\\tableofcontents") {
                                        inset = new InsetTOC(this);
                                } else if (tmptok == "\\listoffigures") {
@@ -774,12 +764,12 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                                        inset = new InsetLOT(this);
                                } else if (tmptok == "\\listofalgorithms") {
                                        inset = new InsetLOA(this);
-                               } else if (tmptok.contains("\\ref{")
-                                          || tmptok.contains("\\pageref{")) {
+                               } else if (contains(tmptok, "\\ref{")
+                                          || contains(tmptok, "\\pageref{")) {
                                        inset = new InsetRef(tmptok, this);
-                               } else if (tmptok.contains("\\url{")
-                                          || tmptok.contains("\\htmlurl{")) {
-                                       LString cont,opt,tmptmptok,cmdname;
+                               } else if (contains(tmptok, "\\url{")
+                                          || contains(tmptok, "\\htmlurl{")) {
+                                       string cont,opt,tmptmptok,cmdname;
                                        lex.next();
                                        while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
                                                lex.next();
@@ -818,12 +808,12 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                                        while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
                                                lex.next();
                                        }
-                                       if(tmptok.contains("\\url{"))
-                                               cmdname = LString("url");
+                                       if(contains(tmptok, "\\url{"))
+                                               cmdname = string("url");
                                        else
-                                               cmdname = LString("htmlurl");
-                                       cont.strip();
-                                       opt.strip();
+                                               cmdname = string("htmlurl");
+                                       cont = strip(cont);
+                                       opt = strip(opt);
                                        inset = new InsetUrl(cmdname,cont,opt);
                                } else if (tmptok[0] == '\\') {
                                        // then this latex del is a
@@ -868,7 +858,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                        } else if (tmptok == "Label") {
                                // Kept for compability. Remove in 0.13.
                                if (lex.EatLine()) {
-                                       LString tmp;
+                                       string tmp;
                                        tmp += "\\label{";
                                        tmp += lex.GetString();
                                        tmp += '}';
@@ -886,7 +876,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                                par->SetFont(pos, font);
                                pos++;
                        } else if (tmptok == "Include") {
-                               inset = new InsetInclude(LString(), this);
+                               inset = new InsetInclude(string(), this);
                                inset->Read(lex);
                                par->InsertChar(pos, LYX_META_INSET); 
                                par->InsertInset(pos, inset);
@@ -920,7 +910,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                                           to the latexdel ref inset that was transformed to an empty ref
                                           inset plus the body surronded by latexdel insets */
                                        else {
-                                               LString cont,opt,tmptmptok,cmdname;
+                                               string cont,opt,tmptmptok,cmdname;
                                                lex.next();
                                                while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
                                                        lex.next();
@@ -960,8 +950,8 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
                                                        lex.next();
                                                }
 
-                                               cont.strip();
-                                               opt.strip();
+                                               cont = strip(cont);
+                                               opt = strip(opt);
                                                cmdname =  "\\" + inscmd.getCmdName();
                                                cmdname += "["  + cont  + "]";
                                                cmdname += "{"  + opt + "}";
@@ -1082,7 +1072,7 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
 
 bool Buffer::readFile(LyXLex &lex, LyXParagraph *par)
 {
-       LString token;
+       string token;
 
        if (lex.IsOK()) {
                lex.next();
@@ -1134,17 +1124,18 @@ bool Buffer::readFile(LyXLex &lex, LyXParagraph *par)
                    
 
 // Returns false if unsuccesful
-bool Buffer::writeFile(LString const & filename, bool flag)
+bool Buffer::writeFile(string const & filename, bool flag)
 {
        // if flag is false writeFile will not create any GUI
-       // warnings, only stderr.
+       // warnings, only cerr.
        // Needed for autosave in background or panic save (Matthias 120496)
 
        if (read_only && (filename == this->filename)) {
                // Here we should come with a question if we should
                // perform the write anyway.
                if (flag)
-                       lyxerr.print(_("Error! Document is read-only: ") + filename);
+                       lyxerr << _("Error! Document is read-only: ")
+                              << filename << endl;
                else
                        WriteAlert(_("Error! Document is read-only: "), filename);
                return false;
@@ -1155,7 +1146,8 @@ bool Buffer::writeFile(LString const & filename, bool flag)
                // Here we should come with a question if we should
                // try to do the save anyway. (i.e. do a chmod first)
                if (flag)
-                       lyxerr.print(_("Error! Cannot write file: ") + filename);
+                       lyxerr << _("Error! Cannot write file: ")
+                              << filename << endl;
                else
                        WriteFSAlert(_("Error! Cannot write file: "), filename);
                return false;
@@ -1164,14 +1156,15 @@ bool Buffer::writeFile(LString const & filename, bool flag)
        FilePtr file(filename, FilePtr::truncate);
        if (!file()) {
                if (flag)
-                       lyxerr.print(_("Error! Cannot write file: ") + filename);
+                       lyxerr << _("Error! Cannot write file: ")
+                              << filename << endl;
                else
                        WriteFSAlert(_("Error! Cannot write file: "), filename);
                return false;
        }
        // The top of the file should not be written by params.
        // collect some very important information
-       LString userName(getUserName()) ;
+       string userName(getUserName()) ;
 
        // write out a comment in the top of the file
        fprintf(file,
@@ -1198,8 +1191,8 @@ bool Buffer::writeFile(LString const & filename, bool flag)
        fprintf(file, "\n\\the_end\n");
        if (file.close()) {
                if (flag)
-                       lyxerr.print(_("Error! Could not close file properly: ")
-                                    +  filename);
+                       lyxerr << _("Error! Could not close file properly: ")
+                              << filename << endl;
                else
                        WriteFSAlert(_("Error! Could not close file properly: "),
                                     filename);
@@ -1209,7 +1202,7 @@ bool Buffer::writeFile(LString const & filename, bool flag)
 }
 
 
-void Buffer::writeFileAscii(LString const & filename, int linelen) 
+void Buffer::writeFileAscii(string const & filename, int linelen) 
 {
        FilePtr file(filename, FilePtr::write);
        LyXFont
@@ -1223,7 +1216,7 @@ void Buffer::writeFileAscii(LString const & filename, int linelen)
                footnoteflag = 0,
                depth = 0;
 
-       LString
+       string
                fname1,
                tmp;
        
@@ -1233,7 +1226,7 @@ void Buffer::writeFileAscii(LString const & filename, int linelen)
                ltype_depth=0,
                noparbreak=0,
                islatex=0,
-               *clen=NULL,
+               *clen=0,
                actcell=0,
                actpos=0,
                cell=0,
@@ -1515,7 +1508,7 @@ void Buffer::writeFileAscii(LString const & filename, int linelen)
                                } else if (c != '\0')
                                        fprintf(file, "%c", c);
                                else if (c == '\0')
-                                       lyxerr.debug("writeAsciiFile: NULL char in structure.");
+                                       lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
                                currlinelen++;
                                break;
                        }
@@ -1547,11 +1540,11 @@ void Buffer::writeFileAscii(LString const & filename, int linelen)
 }
 
 
-void Buffer::makeLaTeXFile(LString const & filename, 
-                          LString const & original_path,
+void Buffer::makeLaTeXFile(string const & filename, 
+                          string const & original_path,
                           bool nice, bool only_body)
 {
-       lyxerr.debug("makeLaTeXFile...", Error::LATEX);
+       lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
        params.textclass = GetCurrentTextClass();
        niceFile = nice; // this will be used by Insetincludes.
 
@@ -1566,18 +1559,18 @@ void Buffer::makeLaTeXFile(LString const & filename,
        }
 
        // validate the buffer.
-       lyxerr.debug("  Validating buffer...", Error::LATEX);
+       lyxerr[Debug::LATEX] << "  Validating buffer..." << endl;
        LaTeXFeatures features(tclass->number_of_defined_layouts);
        validate(features);
-       lyxerr.debug("  Buffer validation done.", Error::LATEX);
+       lyxerr[Debug::LATEX] << "  Buffer validation done." << endl;
        
        texrow.reset();
        // The starting paragraph of the coming rows is the 
        // first paragraph of the document. (Asger)
        texrow.start(paragraph, 0);
 
-       LString userName(getUserName());
-       LString LFile;
+       string userName(getUserName());
+       string LFile;
        
        if (!only_body && nice) {
                LFile += "%% This LaTeX-file was created by <";
@@ -1589,7 +1582,7 @@ void Buffer::makeLaTeXFile(LString const & filename,
                texrow.newline();
                texrow.newline();
        }
-       lyxerr.debug("lyx header finished");
+       lyxerr.debug() << "lyx header finished" << endl;
        // There are a few differences between nice LaTeX and usual files:
        // usual is \batchmode, uses \listfiles and has a 
        // special input@path to allow the including of figures
@@ -1621,9 +1614,9 @@ void Buffer::makeLaTeXFile(LString const & filename,
                
                LFile += "\\documentclass";
                
-               LString options; // the document class options.
+               string options; // the document class options.
                
-               if (tclass->opt_fontsize.tokenPos('|',params.fontsize) >= 0) {
+               if (tokenPos(tclass->opt_fontsize, '|',params.fontsize) >= 0) {
                        // only write if existing in list (and not default)
                        options += params.fontsize;
                        options += "pt,";
@@ -1684,7 +1677,7 @@ void Buffer::makeLaTeXFile(LString const & filename,
                }
                
                if (!options.empty()){
-                       options.strip(',');
+                       options = strip(options, ',');
                        LFile += '[';
                        LFile += options;
                        LFile += ']';
@@ -1817,11 +1810,11 @@ void Buffer::makeLaTeXFile(LString const & filename,
                        texrow.newline();
                }
                if (params.use_amsmath
-                   && !lyxstyle.LatexnameOfClass(params.textclass).prefixIs("ams")) {
+                   && !prefixIs(lyxstyle.LatexnameOfClass(params.textclass), "ams")) {
                        LFile += "\\usepackage{amsmath}\n";
                }
 
-               if (tclass->opt_pagestyle.tokenPos('|',params.pagestyle) >= 0) {
+               if (tokenPos(tclass->opt_pagestyle, '|',params.pagestyle) >= 0) {
                        if (params.pagestyle == "fancy") {
                                LFile += "\\usepackage{fancyhdr}\n";
                                texrow.newline();
@@ -1878,10 +1871,10 @@ void Buffer::makeLaTeXFile(LString const & filename,
 
                // Write out what we've generated so far...and reset LFile
                fwrite(LFile.c_str(), sizeof(char), LFile.length(), file);
-               LFile.clean(); 
+               LFile.erase(); 
 
                // Now insert the LyX specific LaTeX commands...
-               LString preamble, tmppreamble;
+               string preamble, tmppreamble;
 
                // The optional packages;
                preamble = features.getPackages(params);
@@ -1939,7 +1932,7 @@ void Buffer::makeLaTeXFile(LString const & filename,
                        }
                }
 
-               for (int j = preamble.countChar('\n'); j-- ;) {
+               for (int j = countChar(preamble, '\n'); j-- ;) {
                        texrow.newline();
                }
 
@@ -1952,11 +1945,11 @@ void Buffer::makeLaTeXFile(LString const & filename,
                texrow.newline();
                texrow.newline();
        } // only_body
-       lyxerr.debug("preamble finished, now the body.");
+       lyxerr.debug() << "preamble finished, now the body." << endl;
        
        bool was_title = false;
        bool already_title = false;
-       LString ftnote;
+       string ftnote;
        TexRow ft_texrow;
        int ftcount = 0;
        int loop_count = 0;
@@ -1967,15 +1960,16 @@ void Buffer::makeLaTeXFile(LString const & filename,
        while (par) {
                ++loop_count;
                if (par->IsDummy())
-                       lyxerr.debug("Error in MakeLateXFile.", Error::LATEX);
+                       lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
+                                            << endl;
                LyXLayout * layout = lyxstyle.Style(params.textclass,
                                                    par->layout);
            
                if (layout->intitle) {
                        if (already_title) {
-                               lyxerr.print("Error in MakeLatexFile: You"
-                                            " should not mix title layouts"
-                                            " with normal ones.");
+                               lyxerr <<"Error in MakeLatexFile: You"
+                                       " should not mix title layouts"
+                                       " with normal ones." << endl;
                        } else
                                was_title = true;
                } else if (was_title && !already_title) {
@@ -2006,7 +2000,7 @@ void Buffer::makeLaTeXFile(LString const & filename,
                        }
                        LFile += ftnote;
                        texrow += ft_texrow;
-                       ftnote.clean();
+                       ftnote.erase();
                        ft_texrow.reset();
                        ftcount = 0;
                }
@@ -2017,7 +2011,7 @@ void Buffer::makeLaTeXFile(LString const & filename,
                        // LFile.length() in a future revision.  ARRae
                        fwrite(LFile.c_str(), sizeof(char),
                               LFile.length(), file);
-                       LFile.clean();
+                       LFile.erase();
                        loop_count = 0;
                }
        }
@@ -2032,9 +2026,10 @@ void Buffer::makeLaTeXFile(LString const & filename,
                LFile += "\\end{document}\n";
                texrow.newline();
        
-               lyxerr.debug("makeLaTeXFile...done", Error::LATEX);
+               lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
        } else {
-               lyxerr.debug("LaTeXFile for inclusion made.", Error::LATEX);
+               lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
+                                    << endl;
        }
 
        // Just to be sure. (Asger)
@@ -2042,7 +2037,7 @@ void Buffer::makeLaTeXFile(LString const & filename,
 
        // Write out what we've generated...and reset LFile
        fwrite(LFile.c_str(), sizeof(char), LFile.length(), file);
-       LFile.clean();
+       LFile.erase();
 
        // tex_code_break_column's value is used to decide
        // if we are in batchmode or not (within mathed_write()
@@ -2053,7 +2048,7 @@ void Buffer::makeLaTeXFile(LString const & filename,
        if (file.close()) {
                WriteFSAlert(_("Error! Could not close file properly:"), filename);
        }
-       lyxerr.debug("Finished making latex file.");
+       lyxerr.debug() << "Finished making latex file." << endl;
 }
 
 
@@ -2088,7 +2083,7 @@ bool Buffer::isSGML()
 }
 
 
-void Buffer::sgmlOpenTag(FILE * file,int depth,LString & latexname)
+void Buffer::sgmlOpenTag(FILE * file,int depth,string & latexname)
 {
        static char *space[] = {" ","  ","   ","    ","     ","      ","       ",
                         "        ","         ","          ","          "};
@@ -2097,7 +2092,7 @@ void Buffer::sgmlOpenTag(FILE * file,int depth,LString & latexname)
 }
 
 
-void Buffer::sgmlCloseTag(FILE * file,int depth,LString & latexname)
+void Buffer::sgmlCloseTag(FILE * file,int depth,string & latexname)
 {
        static char *space[] = {" ","  ","   ","    ","     ","      ","       ",
                         "        ","         ","          ","          "};
@@ -2106,13 +2101,13 @@ void Buffer::sgmlCloseTag(FILE * file,int depth,LString & latexname)
 }
 
 
-void Buffer::makeLinuxDocFile(LString const & filename, int column)
+void Buffer::makeLinuxDocFile(string const & filename, int column)
 {
        LyXParagraph *par = paragraph;
 
-       LString top_element=lyxstyle.LatexnameOfClass(params.textclass);
-       LString environment_stack[10];
-        LString item_name;
+       string top_element=lyxstyle.LatexnameOfClass(params.textclass);
+       string environment_stack[10];
+        string item_name;
 
        int depth=0;              /* paragraph depth */
 
@@ -2135,14 +2130,14 @@ void Buffer::makeLinuxDocFile(LString const & filename, int column)
                        params.preamble.c_str() );
        }
 
-        LString userName(getUserName());
+        string userName(getUserName());
        fprintf(file, "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 ");
        fprintf(file, "by <%s> %s -->\n", userName.c_str(), (char *)date());
 
        if(params.options.empty())
                sgmlOpenTag(file,0,top_element);
        else {
-               LString top = top_element;
+               string top = top_element;
                top += " ";
                top += params.options;
                sgmlOpenTag(file,0,top);
@@ -2158,7 +2153,7 @@ void Buffer::makeLinuxDocFile(LString const & filename, int column)
                        Inset *inset = par->GetInset(0);
                        char  lyx_code = inset->LyxCode();
                        if (lyx_code ==Inset::TOC_CODE){
-                               LString temp= "toc";
+                               string temp= "toc";
                                sgmlOpenTag(file, depth, temp);
 
                                par = par->next;
@@ -2170,7 +2165,7 @@ void Buffer::makeLinuxDocFile(LString const & filename, int column)
                /* environment tag closing */
                for( ;depth > par->depth; depth--) {
                        sgmlCloseTag(file,depth,environment_stack[depth]);
-                       environment_stack[depth].clean();
+                       environment_stack[depth].erase();
                }
 
                /* write opening SGML tags */
@@ -2179,7 +2174,7 @@ void Buffer::makeLinuxDocFile(LString const & filename, int column)
                        if(depth == par->depth 
                           && !environment_stack[depth].empty()) {
                                sgmlCloseTag(file,depth,environment_stack[depth]);
-                               environment_stack[depth].clean();
+                               environment_stack[depth].erase();
                                if(depth) 
                                        depth--;
                                else
@@ -2197,7 +2192,7 @@ void Buffer::makeLinuxDocFile(LString const & filename, int column)
                                fprintf(file, "</p>");
                        }
 
-                       environment_stack[depth].clean();
+                       environment_stack[depth].erase();
                        sgmlOpenTag(file,depth, style->latexname);
                        break;
 
@@ -2208,15 +2203,15 @@ void Buffer::makeLinuxDocFile(LString const & filename, int column)
                           && !environment_stack[depth].empty()) {
 
                                sgmlCloseTag(file,depth,environment_stack[depth]);
-                               environment_stack[depth].clean();
+                               environment_stack[depth].erase();
                        }
                        if (depth < par->depth) {
                               depth = par->depth;
-                              environment_stack[depth].clean();
+                              environment_stack[depth].erase();
                        }
                        if (environment_stack[depth] != style->latexname) {
                                if(depth==0) {
-                                       LString temp="p";
+                                       string temp="p";
                                        sgmlOpenTag(file,depth,temp);
                                }
                                environment_stack[depth]= style->latexname;
@@ -2281,7 +2276,7 @@ void Buffer::makeLinuxDocFile(LString const & filename, int column)
 
 void Buffer::linuxDocHandleFootnote(FILE *file,LyXParagraph* &par, int const depth)
 {
-       LString tag="footnote";
+       string tag="footnote";
 
        while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
                sgmlOpenTag(file,depth+1,tag);
@@ -2291,12 +2286,12 @@ void Buffer::linuxDocHandleFootnote(FILE *file,LyXParagraph* &par, int const dep
        }
 }
 
-void Buffer::DocBookHandleCaption(FILE *file, LString &inner_tag,
+void Buffer::DocBookHandleCaption(FILE *file, string &inner_tag,
                                  int const depth, int desc_on,
                                  LyXParagraph* &par)
 {
        LyXParagraph *tpar = par;
-       LString tmp_par, extra_par;
+       string tmp_par, extra_par;
        while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
               (tpar->layout != lyxstyle.NumberOfLayout(params.textclass,"Caption")))
                tpar = tpar->next;
@@ -2304,8 +2299,8 @@ void Buffer::DocBookHandleCaption(FILE *file, LString &inner_tag,
            tpar->layout==lyxstyle.NumberOfLayout(params.textclass,"Caption")) {
                sgmlOpenTag(file,depth+1,inner_tag);
            SimpleDocBookOnePar(tmp_par,extra_par,tpar,desc_on,depth+2);
-               tmp_par.strip();
-               tmp_par.frontStrip();
+               tmp_par = strip(tmp_par);
+               tmp_par = frontStrip(tmp_par);
                fprintf(file,"%s",tmp_par.c_str());
                sgmlCloseTag(file,depth+1,inner_tag);
                if(!extra_par.empty())
@@ -2315,9 +2310,9 @@ void Buffer::DocBookHandleCaption(FILE *file, LString &inner_tag,
 
 void Buffer::DocBookHandleFootnote(FILE *file,LyXParagraph* &par, int const depth)
 {
-       LString tag,inner_tag;
-       LString tmp_par,extra_par;
-       bool inner_span;
+       string tag,inner_tag;
+       string tmp_par,extra_par;
+       bool inner_span = false;
        int desc_on=4;
 
        // This is not how I like to see enums. They should not be anonymous
@@ -2336,7 +2331,7 @@ void Buffer::DocBookHandleFootnote(FILE *file,LyXParagraph* &par, int const dept
                        if(inner_span) {
                                if(!tmp_par.empty()) {
                                        fprintf(file,"%s",tmp_par.c_str());
-                                       tmp_par.clean();
+                                       tmp_par.erase();
                                        sgmlCloseTag(file,depth+1,inner_tag);
                                        sgmlOpenTag(file,depth+1,inner_tag);
                                }
@@ -2348,7 +2343,7 @@ void Buffer::DocBookHandleFootnote(FILE *file,LyXParagraph* &par, int const dept
                        if(!inner_tag.empty()) sgmlCloseTag(file,depth+1,inner_tag);
                        if(!extra_par.empty()) fprintf(file,"%s",extra_par.c_str());
                        if(!tag.empty()) sgmlCloseTag(file,depth,tag);
-                       extra_par.clean();
+                       extra_par.erase();
 
                        switch (par->footnotekind) {
                        case LyXParagraph::FOOTNOTE:
@@ -2383,7 +2378,7 @@ void Buffer::DocBookHandleFootnote(FILE *file,LyXParagraph* &par, int const dept
                        if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
                                DocBookHandleCaption(file, inner_tag, depth,
                                                     desc_on, par);
-                               inner_tag.clean();
+                               inner_tag.erase();
                        } else {
                                sgmlOpenTag(file,depth+1,inner_tag);
                        }
@@ -2394,8 +2389,7 @@ void Buffer::DocBookHandleFootnote(FILE *file,LyXParagraph* &par, int const dept
                        SimpleDocBookOnePar(tmp_par,extra_par,par,
                                            desc_on,depth+2);
                }
-               tmp_par.strip();
-               tmp_par.frontStrip();
+               tmp_par = frontStrip(strip(tmp_par));
 
                last=present;
                par = par->next;
@@ -2604,12 +2598,12 @@ void Buffer::SimpleLinuxDocOnePar(FILE *file, LyXParagraph *par, int desc_on, in
                        char_line_count++;
                } else if (c == LYX_META_INSET) {
                        inset = par->GetInset(i);
-                       LString tmp_out;
+                       string tmp_out;
                        inset->Linuxdoc(tmp_out);
                        fprintf(file,"%s",tmp_out.c_str());
                }
                else {
-                       LString sgml_string;
+                       string sgml_string;
                        if (par->linuxDocConvertChar(c, sgml_string)
                            && !style->free_spacing) { // in freespacing
                                                     // mode, spaces are
@@ -2681,19 +2675,19 @@ void Buffer::LinuxDocError(LyXParagraph *par, int pos,
 
 enum { MAX_NEST_LEVEL = 25};
 
-void Buffer::makeDocBookFile(LString const & filename, int column)
+void Buffer::makeDocBookFile(string const & filename, int column)
 {
        LyXParagraph *par = paragraph;
 
-       LString top_element=lyxstyle.LatexnameOfClass(params.textclass);
-       LString environment_stack[MAX_NEST_LEVEL];
-       LString environment_inner[MAX_NEST_LEVEL];
-       LString command_stack[MAX_NEST_LEVEL];
+       string top_element=lyxstyle.LatexnameOfClass(params.textclass);
+       string environment_stack[MAX_NEST_LEVEL];
+       string environment_inner[MAX_NEST_LEVEL];
+       string command_stack[MAX_NEST_LEVEL];
        bool command_flag=false;
-       int command_depth=0,command_base,cmd_depth;
+       int command_depth=0,command_base=0,cmd_depth=0;
 
-        LString item_name,command_name;
-       LString c_depth,c_params,tmps;
+        string item_name,command_name;
+       string c_depth,c_params,tmps;
 
        int depth=0;              /* paragraph depth */
 
@@ -2715,7 +2709,7 @@ void Buffer::makeDocBookFile(LString const & filename, int column)
        else
                fprintf(file, "\n [ %s \n]>\n\n",params.preamble.c_str() );
 
-        LString userName(getUserName());
+        string userName(getUserName());
        fprintf(file,
                "<!-- DocBook file was created by LyX 1.0 (C) 1995-1999\n");
        fprintf(file, "by <%s> %s -->\n", userName.c_str(), (char *)date());
@@ -2723,7 +2717,7 @@ void Buffer::makeDocBookFile(LString const & filename, int column)
        if(params.options.empty())
                sgmlOpenTag(file,0,top_element);
        else {
-               LString top = top_element;
+               string top = top_element;
                top += " ";
                top += params.options;
                sgmlOpenTag(file,0,top);
@@ -2747,8 +2741,8 @@ void Buffer::makeDocBookFile(LString const & filename, int column)
                        }
                        sgmlCloseTag(file,depth+command_depth,
                                     environment_stack[depth]);
-                       environment_stack[depth].clean();
-                       environment_inner[depth].clean();
+                       environment_stack[depth].erase();
+                       environment_inner[depth].erase();
                }
 
                if(depth == par->depth
@@ -2766,8 +2760,8 @@ void Buffer::makeDocBookFile(LString const & filename, int column)
                        sgmlCloseTag(file,depth+command_depth,
                                     environment_stack[depth]);
                        
-                       environment_stack[depth].clean();
-                       environment_inner[depth].clean();
+                       environment_stack[depth].erase();
+                       environment_inner[depth].erase();
                 }
 
                // Write opening SGML tags.
@@ -2787,7 +2781,7 @@ void Buffer::makeDocBookFile(LString const & filename, int column)
                        command_name=style->latexname;
                        
                        tmps=style->latexparam;
-                       c_params=tmps.split(c_depth,'|');
+                       c_params= split(tmps, c_depth,'|');
                        
                        cmd_depth=atoi(c_depth.c_str());
                        
@@ -2838,7 +2832,7 @@ void Buffer::makeDocBookFile(LString const & filename, int column)
                case LATEX_ITEM_ENVIRONMENT:
                        if (depth < par->depth) {
                                depth = par->depth;
-                               environment_stack[depth].clean();
+                               environment_stack[depth].erase();
                        }
 
                        if (environment_stack[depth] != style->latexname) {
@@ -2893,7 +2887,7 @@ void Buffer::makeDocBookFile(LString const & filename, int column)
                }
 
                do {
-                       LString tmp_par,extra_par;
+                       string tmp_par,extra_par;
 
                        SimpleDocBookOnePar(tmp_par,extra_par, par, desc_on,
                                            depth+1+command_depth);
@@ -2904,7 +2898,7 @@ void Buffer::makeDocBookFile(LString const & filename, int column)
                }
                while(par && par->IsDummy());
 
-               LString end_tag;
+               string end_tag;
                /* write closing SGML tags */
                switch(style->latextype) {
                case LATEX_COMMAND:
@@ -2934,14 +2928,22 @@ void Buffer::makeDocBookFile(LString const & filename, int column)
        }
 
        // Close open tags
-       for(;depth>0;depth--)
-               sgmlCloseTag(file,depth+command_depth,
-                            environment_stack[depth]);
-
-       if(!environment_stack[depth].empty())
-               sgmlCloseTag(file,depth+command_depth,
-                            environment_stack[depth]);
-
+       for(;depth>=0;depth--) {
+               if(!environment_stack[depth].empty()) {
+                       if(environment_inner[depth] != "!-- --") {
+                               item_name="listitem";
+                               sgmlCloseTag(file,command_depth+depth,
+                                            item_name);
+                               if( environment_inner[depth] == "varlistentry")
+                                      sgmlCloseTag(file,depth+command_depth,
+                                                   environment_inner[depth]);
+                       }
+                       
+                       sgmlCloseTag(file,depth+command_depth,
+                                    environment_stack[depth]);
+               }
+       }
+       
        for(int j=command_depth;j>=command_base;j--)
                if(!command_stack[j].empty())
                        sgmlCloseTag(file,j,command_stack[j]);
@@ -2956,7 +2958,7 @@ void Buffer::makeDocBookFile(LString const & filename, int column)
 }
 
 
-void Buffer::SimpleDocBookOnePar(LString & file, LString & extra,
+void Buffer::SimpleDocBookOnePar(string & file, string & extra,
                                 LyXParagraph * par, int & desc_on,
                                 int const depth) 
 {
@@ -2968,7 +2970,7 @@ void Buffer::SimpleDocBookOnePar(LString & file, LString & extra,
        char c;
        Inset *inset;
        int main_body, j;
-       LString emph="emphasis";
+       string emph="emphasis";
        bool emph_flag=false;
        int char_line_count=0;
 
@@ -3010,7 +3012,7 @@ void Buffer::SimpleDocBookOnePar(LString & file, LString & extra,
 
                if (c == LYX_META_INSET) {
                        inset = par->GetInset(i);
-                       LString tmp_out;
+                       string tmp_out;
                        inset->DocBook(tmp_out);
                        //
                        // This code needs some explanation:
@@ -3025,9 +3027,9 @@ void Buffer::SimpleDocBookOnePar(LString & file, LString & extra,
                        if(desc_on!=3 || i!=0) {
                                if(tmp_out[0]=='@') {
                                        if(desc_on==4)
-                                               extra += tmp_out.frontStrip('@');
+                                               extra += frontStrip(tmp_out, '@');
                                        else
-                                               file += tmp_out.frontStrip('@');
+                                               file += frontStrip(tmp_out, '@');
                                }
                                else
                                        file += tmp_out;
@@ -3039,7 +3041,7 @@ void Buffer::SimpleDocBookOnePar(LString & file, LString & extra,
                        char_line_count++;
                }
                else {
-                       LString sgml_string;
+                       string sgml_string;
                        if (par->linuxDocConvertChar(c, sgml_string)
                            && !style->free_spacing) { // in freespacing
                                                     // mode, spaces are
@@ -3121,16 +3123,16 @@ int Buffer::runLaTeX()
        ProhibitInput();
 
        // get LaTeX-Filename
-       LString name = SpaceLess(ChangeExtension (filename, ".tex", true));
+       string name = SpaceLess(ChangeExtension (filename, ".tex", true));
 
-       LString path = OnlyPath(filename);
+       string path = OnlyPath(filename);
 
-       LString org_path = path;
+       string org_path = path;
        if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
                path = tmppath;  
        }
 
-       PathPush(path); // path to LaTeX file
+       Path p(path); // path to LaTeX file
        users->getOwner()->getMiniBuffer()->Set(_("Running LaTeX..."));   
 
        // Remove all error insets
@@ -3177,7 +3179,6 @@ int Buffer::runLaTeX()
                 users->updateScrollbar();
         }
         AllowInput();
-        PathPop(); // path to LaTeX file
  
         return latex.getNumErrors();
 }
@@ -3190,18 +3191,18 @@ int Buffer::runLiterate()
        ProhibitInput();
 
        // get LaTeX-Filename
-       LString name = SpaceLess(ChangeExtension (filename, ".tex", true));
+       string name = SpaceLess(ChangeExtension (filename, ".tex", true));
         // get Literate-Filename
-        LString lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true));
+        string lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true));
 
-       LString path = OnlyPath(filename);
+       string path = OnlyPath(filename);
 
-       LString org_path = path;
+       string org_path = path;
        if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
                path = tmppath;  
        }
 
-       PathPush(path); // path to Literate file
+       Path p(path); // path to Literate file
        users->getOwner()->getMiniBuffer()->Set(_("Running Literate..."));   
 
        // Remove all error insets
@@ -3246,7 +3247,6 @@ int Buffer::runLiterate()
                 users->updateScrollbar();
         }
         AllowInput();
-        PathPop(); // path to LaTeX file
  
         return literate.getNumErrors();
 }
@@ -3259,18 +3259,18 @@ int Buffer::buildProgram()
         ProhibitInput();
  
         // get LaTeX-Filename
-        LString name = SpaceLess(ChangeExtension (filename, ".tex", true));
+        string name = SpaceLess(ChangeExtension (filename, ".tex", true));
         // get Literate-Filename
-        LString lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true));
+        string lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true));
  
-        LString path = OnlyPath(filename);
+        string path = OnlyPath(filename);
  
-        LString org_path = path;
+        string org_path = path;
         if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
                 path = tmppath;  
         }
  
-        PathPush(path); // path to Literate file
+        Path p(path); // path to Literate file
         users->getOwner()->getMiniBuffer()->Set(_("Building Program..."));   
  
         // Remove all error insets
@@ -3314,7 +3314,6 @@ int Buffer::buildProgram()
                users->updateScrollbar();
        }
        AllowInput();
-       PathPop(); // path to LaTeX file
 
        return literate.getNumErrors();
 }
@@ -3330,15 +3329,15 @@ int Buffer::runChktex()
        ProhibitInput();
 
        // get LaTeX-Filename
-       LString name = SpaceLess(ChangeExtension (filename, ".tex", true));
-       LString path = OnlyPath(filename);
+       string name = SpaceLess(ChangeExtension (filename, ".tex", true));
+       string path = OnlyPath(filename);
 
-       LString org_path = path;
+       string org_path = path;
        if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
                path = tmppath;  
        }
 
-       PathPush(path); // path to LaTeX file
+       Path p(path); // path to LaTeX file
        users->getOwner()->getMiniBuffer()->Set(_("Running chktex..."));
 
        // Remove all error insets
@@ -3370,7 +3369,6 @@ int Buffer::runChktex()
                users->updateScrollbar();
        }
        AllowInput();
-       PathPop(); // path to LaTeX file
 
        return res;
 }
@@ -3393,7 +3391,7 @@ void Buffer::insertErrors(TeXErrors &terr)
        AllFloats(1,1);
 
        while (more) {
-               LString errortext;
+               string errortext;
                int errorrow = 0;
 
                if (firsterror) {
@@ -3466,14 +3464,14 @@ void Buffer::RoffAsciiTable(FILE *file, LyXParagraph *par)
                cell = 0;
        char
                c;
-       LString
+       string
                fname1,
                fname2;
        FILE
                *fp,*fp2;
        
-       fname1 = TmpFileName(LString(),"RAT1");
-       fname2 = TmpFileName(LString(),"RAT2");
+       fname1 = TmpFileName(string(),"RAT1");
+       fname2 = TmpFileName(string(),"RAT2");
        if (!(fp=fopen(fname1.c_str(),"w"))) {
                WriteAlert(_("LYX_ERROR:"),
                           _("Cannot open temporary file:"), fname1);
@@ -3532,17 +3530,18 @@ void Buffer::RoffAsciiTable(FILE *file, LyXParagraph *par)
                        if (c != '\0')
                                fprintf(fp, "%c", c);
                        else if (c == '\0')
-                               lyxerr.debug("RoffAsciiTable:"
-                                            " NULL char in structure.");
+                               lyxerr.debug()
+                                       << "RoffAsciiTable:"
+                                       " NULL char in structure." << endl;
                        break;
                }
        }
        par->table->RoffEndOfCell(fp, cell);
        fclose(fp);
-       LString cmd = lyxrc->ascii_roff_command + " >" + fname2;
-       cmd.subst("$$FName",fname1);
+       string cmd = lyxrc->ascii_roff_command + " >" + fname2;
+       subst(cmd, "$$FName",fname1);
        Systemcalls one(Systemcalls::System, cmd);
-       if (!(lyxerr.debugging(Error::ROFF))) {
+       if (!(lyxerr.debugging(Debug::ROFF))) {
                remove(fname1.c_str());
        }
        if (!(fp=fopen(fname2.c_str(),"r"))) {
@@ -3642,8 +3641,8 @@ void Buffer::validate(LaTeXFeatures &features)
     
        while (par) {
                // We don't use "lyxerr.debug" because of speed. (Asger)
-               if (lyxerr.debugging(Error::LATEX))
-                       lyxerr.print(LString("Paragraph: ") + long(par));
+               if (lyxerr.debugging(Debug::LATEX))
+                       lyxerr << "Paragraph: " <<  par << endl;
 
                // Now just follow the list of paragraphs and run
                // validate on each of them.
@@ -3677,7 +3676,7 @@ void Buffer::validate(LaTeXFeatures &features)
                }
        }
        
-       if (lyxerr.debugging(Error::LATEX)) {
+       if (lyxerr.debugging(Debug::LATEX)) {
                features.showStruct(params);
        }
 }
@@ -3741,7 +3740,7 @@ void Buffer::setOldPaperStuff()
 }
 
 
-void Buffer::insertInset(Inset *inset, LString const &lout,
+void Buffer::insertInset(Inset *inset, string const &lout,
                         bool no_table)
 {
        // check for table/list in tables
@@ -3779,7 +3778,7 @@ void Buffer::insertInset(Inset *inset, LString const &lout,
                                   0, 0,
                                   VSpace(VSpace::NONE), VSpace(VSpace::NONE),
                                   LYX_ALIGN_LAYOUT, 
-                                  LString(),
+                                  string(),
                                   0);
                update(-1);
                
@@ -3811,9 +3810,9 @@ void Buffer::open_new_inset(UpdatableInset* new_inset)
 
 
 /* This function should be in Buffer because it's a buffer's property (ale) */
-LString Buffer::getIncludeonlyList(char delim)
+string Buffer::getIncludeonlyList(char delim)
 {
-       LString list;
+       string list;
        LyXParagraph *par = paragraph;
        int pos;
        Inset* inset;
@@ -3826,20 +3825,20 @@ LString Buffer::getIncludeonlyList(char delim)
                                    && insetinc->isNoLoad()) {
                                        if (!list.empty())
                                                list += delim;
-                                       list += ChangeExtension(insetinc->getContents(), LString(), true);
+                                       list += ChangeExtension(insetinc->getContents(), string(), true);
                                }
                        }
                        pos++;
                } 
                par = par->next;
        }
-       lyxerr.debug(LString("Includeonly(") + list + ')');
+       lyxerr.debug() << "Includeonly(" << list << ')' << endl;
        return list;
 }
 
 
 /* This is also a buffer property (ale) */ 
-LString Buffer::getReferenceList(char delim)
+string Buffer::getReferenceList(char delim)
 {
        /// if this is a child document and the parent is already loaded
        /// Use the parent's list instead  [ale990407]
@@ -3852,7 +3851,7 @@ LString Buffer::getReferenceList(char delim)
        LyXParagraph *par = paragraph;
        int pos;
        Inset* inset;
-        LString list;
+        string list;
        while (par){
                pos = -1;
                while ((inset = par->ReturnNextInsetPointer(pos))){     
@@ -3865,13 +3864,13 @@ LString Buffer::getReferenceList(char delim)
                } 
                par = par->next;
        }
-       lyxerr.debug(LString("References(") + list + LString(')'));
+       lyxerr.debug() << "References(" <<  list << ")" << endl;
        return list;
 }
 
 
 /* This is also a buffer property (ale) */ 
-LString Buffer::getBibkeyList(char delim)
+string Buffer::getBibkeyList(char delim)
 {
        /// if this is a child document and the parent is already loaded
        /// Use the parent's list instead  [ale990412]
@@ -3881,7 +3880,7 @@ LString Buffer::getBibkeyList(char delim)
                        return tmp->getBibkeyList(delim);
        }
 
-       LString bibkeys;
+       string bibkeys;
        LyXParagraph *par = paragraph;
        while (par) {
                if (par->bibkey) {
@@ -3906,7 +3905,7 @@ LString Buffer::getBibkeyList(char delim)
                                                bibkeys += delim;
                                        bibkeys += ((InsetBibtex*)inset)->getKeys();
                                } else if (inset-> LyxCode()==Inset::INCLUDE_CODE) {
-                                       LString bk = ((InsetInclude*)inset)->getKeys();
+                                       string bk = ((InsetInclude*)inset)->getKeys();
                                        if (!bk.empty()) {
                                                if (!bibkeys.empty())
                                                        bibkeys += delim;
@@ -3919,7 +3918,7 @@ LString Buffer::getBibkeyList(char delim)
                }
        }
  
-       lyxerr.debug(LString("Bibkeys(") + bibkeys + LString(')'));
+       lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
        return bibkeys;
 }
 
@@ -3929,13 +3928,13 @@ LString Buffer::getBibkeyList(char delim)
 // think how this will work in a multiwindo/buffer environment, all the
 // cursors in all the views showing this buffer will move. (Lgb)
 // OK, then no cursor action should be allowed in buffer. (ale)
-bool Buffer::gotoLabel(const LString &label)
+bool Buffer::gotoLabel(const string &label)
 
 {
         LyXParagraph *par = paragraph;
         int pos;
         Inset* inset;
-       LString list;
+       string list;
         while (par) {
                 pos = -1;
                 while ((inset = par->ReturnNextInsetPointer(pos))){     
@@ -3956,7 +3955,7 @@ bool Buffer::gotoLabel(const LString &label)
 }
 
 
-bool Buffer::isDepClean(LString const & name) const
+bool Buffer::isDepClean(string const & name) const
 {
        DEPCLEAN* item = dep_clean;
        while (item && item->master != name)
@@ -3966,13 +3965,13 @@ bool Buffer::isDepClean(LString const & name) const
 }
 
 
-void Buffer::markDepClean(LString const & name)
+void Buffer::markDepClean(string const & name)
 {
        if (!dep_clean) {
                dep_clean = new DEPCLEAN;
                dep_clean->clean = true;
                dep_clean->master = name;
-               dep_clean->next = NULL;
+               dep_clean->next = 0;
        } else {
                DEPCLEAN* item = dep_clean;
                while (item && item->master != name)
@@ -3983,7 +3982,7 @@ void Buffer::markDepClean(LString const & name)
                        item = new DEPCLEAN;
                        item->clean = true;
                        item->master = name;
-                       item->next = NULL;;
+                       item->next = 0;;
                }
        }
        //return false; // why use that in a void method??