#include <fstream>
#include <iomanip>
-using std::ofstream;
-using std::ifstream;
-using std::fstream;
-using std::ios;
-using std::setw;
-
#include <cstdlib>
#include <unistd.h>
#include "lyxlex.h"
#include "tex-strings.h"
#include "layout.h"
-#include "lyx_cb.h"
+#include "bufferview_funcs.h"
#include "minibuffer.h"
#include "lyxfont.h"
#include "version.h"
#include "insets/insetert.h"
#include "insets/insetgraphics.h"
#include "insets/insetfoot.h"
+#include "insets/insettabular.h"
#include "support/filetools.h"
#include "support/path.h"
#include "LaTeX.h"
#include "gettext.h"
#include "language.h"
-// 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)
-// #define BREAK_BEFORE_INSET
-
-/* Lars, when changing this file sometime in the future to a list,
- * please check out the figinsets-sideeffects described at the
- * beginning of figinset.C Matthias (04.07.1996)
- */
+using std::ostream;
+using std::ofstream;
+using std::ifstream;
+using std::fstream;
+using std::ios;
+using std::setw;
+using std::endl;
+using std::pair;
// all these externs should eventually be removed.
extern int tex_code_break_column;
-extern void FreeUpdateTimer();
-
Buffer::Buffer(string const & file, bool ronly)
{
lyxvc.buffer(this);
if (read_only || (lyxrc.use_tempdir)) {
tmppath = CreateBufferTmpDir();
- } else tmppath.clear();
+ } else tmppath.erase();
}
}
+string Buffer::getLatexName(bool no_path) const
+{
+ return ChangeExtension(MakeLatexName(filename),
+ ".tex", no_path);
+}
+
+
+void Buffer::setReadonly(bool flag)
+{
+ if (read_only != flag) {
+ read_only = flag;
+ updateTitles();
+ updateAllVisibleBufferRelatedPopups();
+ }
+ if (read_only) {
+ WarnReadonly(filename);
+ }
+}
+
+
bool Buffer::saveParamsAsDefaults()
{
string fname = AddName(AddPath(user_lyxdir, "templates/"),
- "defaults.lyx");
+ "defaults.lyx");
Buffer defaults = Buffer(fname);
// Use the current buffer's parameters as default
bool the_end_read = false;
LyXParagraph * return_par = 0;
- LyXFont font(LyXFont::ALL_INHERIT,params.language_info);
+ LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
if (format < 2.16 && params.language == "hebrew")
font.setLanguage(default_language);
}
-bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
- LyXParagraph *& return_par,
- const string & token, int & pos,
- char & depth, LyXFont & font,
- LyXParagraph::footnote_flag & footnoteflag,
- LyXParagraph::footnote_kind & footnotekind)
+bool
+Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
+ LyXParagraph *& return_par,
+ string const & token, int & pos,
+ char & depth, LyXFont & font,
+ LyXParagraph::footnote_flag & footnoteflag,
+ LyXParagraph::footnote_kind & footnotekind)
{
- Inset * inset = 0;
- int tmpret, tmpret2;
- string tmptok;
bool the_end_read = false;
-
+
if (token[0] != '\\') {
- int n = token.length();
- for (int i = 0; i < n; ++i) {
- par->InsertChar(pos, token[i]);
+ for (string::const_iterator cit = token.begin();
+ cit != token.end(); ++cit) {
+ par->InsertChar(pos, (*cit));
par->SetFont(pos, font);
++pos;
}
} else if (token == "\\i") {
- inset = new InsetLatexAccent;
+ Inset * inset = new InsetLatexAccent;
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
if (pp.first) {
par->layout = pp.second;
} else { // layout not found
- // use default layout "Standard" (0)
+ // use default layout "Standard" (0)
par->layout = 0;
}
// Test whether the layout is obsolete.
par->footnoteflag = footnoteflag;
par->footnotekind = footnotekind;
par->depth = depth;
- font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
+ font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
if (format < 2.16 && params.language == "hebrew")
font.setLanguage(default_language);
} else if (token == "\\end_float") {
pos = 0;
lex.EatLine();
par->layout = LYX_DUMMY_LAYOUT;
- font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
+ font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
if (format < 2.16 && params.language == "hebrew")
font.setLanguage(default_language);
} else if (token == "\\begin_float") {
- tmpret = lex.FindToken(string_footnotekinds);
+ int tmpret = lex.FindToken(string_footnotekinds);
if (tmpret == -1) ++tmpret;
if (tmpret != LYX_LAYOUT_DEFAULT)
footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
} else if (token == "\\start_of_appendix") {
par->start_of_appendix = true;
} else if (token == "\\paragraph_separation") {
- tmpret = lex.FindToken(string_paragraph_separation);
+ int tmpret = lex.FindToken(string_paragraph_separation);
if (tmpret == -1) ++tmpret;
if (tmpret != LYX_LAYOUT_DEFAULT)
params.paragraph_separation =
} else if (token == "\\defskip") {
lex.nextToken();
params.defskip = VSpace(lex.GetString());
-#if 0
- } else if (token == "\\no_isolatin1") { // obsolete
- lex.nextToken();
- } else if (token == "\\no_babel") { // obsolete
- lex.nextToken();
- } else if (token == "\\no_epsfig") { // obsolete
- lex.nextToken();
-#endif
} else if (token == "\\epsfig") { // obsolete
// Indeed it is obsolete, but we HAVE to be backwards
// compatible until 0.14, because otherwise all figures
// in existing documents are irretrivably lost. (Asger)
params.readGraphicsDriver(lex);
} else if (token == "\\quotes_language") {
- tmpret = lex.FindToken(string_quotes_language);
+ int tmpret = lex.FindToken(string_quotes_language);
if (tmpret == -1) ++tmpret;
if (tmpret != LYX_LAYOUT_DEFAULT) {
InsetQuotes::quote_language tmpl =
break;
}
} else if (token == "\\papersize") {
- tmpret = lex.FindToken(string_papersize);
+ int tmpret = lex.FindToken(string_papersize);
if (tmpret == -1)
++tmpret;
else
params.papersize2 = tmpret;
} else if (token == "\\paperpackage") {
- tmpret = lex.FindToken(string_paperpackages);
+ int tmpret = lex.FindToken(string_paperpackages);
if (tmpret == -1) {
++tmpret;
params.paperpackage = BufferParams::PACKAGE_NONE;
lex.nextToken();
params.use_amsmath = lex.GetInteger();
} else if (token == "\\paperorientation") {
- tmpret = lex.FindToken(string_orientation);
+ int tmpret = lex.FindToken(string_orientation);
if (tmpret == -1) ++tmpret;
if (tmpret != LYX_LAYOUT_DEFAULT)
params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
} else if (token == "\\tocdepth") {
lex.nextToken();
params.tocdepth = lex.GetInteger();
+#if 0
} else if (token == "\\baselinestretch") { // obsolete
lex.nextToken(); // should not be used directly
// anymore.
// Will probably keep a kind of support just for
// compability.
params.spacing.set(Spacing::Other, lex.GetFloat());
+#endif
} else if (token == "\\spacing") {
+ lex.next();
+ string tmp = strip(lex.GetString());
+ Spacing::Space tmp_space = Spacing::Default;
+ float tmp_val = 0.0;
+ if (tmp == "single") {
+ tmp_space = Spacing::Single;
+ } else if (tmp == "onehalf") {
+ tmp_space = Spacing::Onehalf;
+ } else if (tmp == "double") {
+ tmp_space = Spacing::Double;
+ } else if (tmp == "other") {
+ lex.next();
+ tmp_space = Spacing::Other;
+ tmp_val = lex.GetFloat();
+ } else {
+ lex.printError("Unknown spacing token: '$$Token'");
+ }
+ // Small hack so that files written with klyx will be
+ // parsed correctly.
+ if (return_par) {
+ par->spacing.set(tmp_space, tmp_val);
+ } else {
+ params.spacing.set(tmp_space, tmp_val);
+ }
+ } else if (token == "\\paragraph_spacing") {
lex.next();
string tmp = strip(lex.GetString());
if (tmp == "single") {
- params.spacing.set(Spacing::Single);
+ par->spacing.set(Spacing::Single);
} else if (tmp == "onehalf") {
- params.spacing.set(Spacing::Onehalf);
+ par->spacing.set(Spacing::Onehalf);
} else if (tmp == "double") {
- params.spacing.set(Spacing::Double);
+ par->spacing.set(Spacing::Double);
} else if (tmp == "other") {
lex.next();
- params.spacing.set(Spacing::Other,
- lex.GetFloat());
+ par->spacing.set(Spacing::Other,
+ lex.GetFloat());
} else {
lex.printError("Unknown spacing token: '$$Token'");
}
} else if (token == "\\float_placement") {
lex.nextToken();
params.float_placement = lex.GetString();
+#if 0
} else if (token == "\\cursor") { // obsolete
// this is obsolete, so we just skip it.
lex.nextToken();
+#endif
} else if (token == "\\family") {
lex.next();
font.setLyXFamily(lex.GetString());
font.setLanguage(params.language_info);
lex.printError("Unknown language `$$Token'");
}
- } else if (token == "\\direction") { // obsolete
- if (format >= 2.16)
- lex.printError("Command \\direction is obsolete");
- lex.next();
- string tok = lex.GetString();
- if (tok == "rtl")
- font.setLanguage(&languages["hebrew"]);
- else if (tok == "default")
- if (params.language == "hebrew")
- font.setLanguage(default_language);
- else
- font.setLanguage(params.language_info);
- else
- lex.printError("Unknown direction `$$Token'");
} else if (token == "\\emph") {
lex.next();
font.setEmph(font.setLyXMisc(lex.GetString()));
lex.next();
font.setLyXColor(lex.GetString());
} else if (token == "\\align") {
- tmpret = lex.FindToken(string_align);
+ int tmpret = lex.FindToken(string_align);
if (tmpret == -1) ++tmpret;
if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
- tmpret2 = 1;
+ int tmpret2 = 1;
for (; tmpret > 0; --tmpret)
tmpret2 = tmpret2 * 2;
par->align = LyXAlignment(tmpret2);
}
} else if (token == "\\added_space_top") {
lex.nextToken();
- par->added_space_top = lex.GetString();
+ par->added_space_top = VSpace(lex.GetString());
} else if (token == "\\added_space_bottom") {
lex.nextToken();
- par->added_space_bottom = lex.GetString();
+ par->added_space_bottom = VSpace(lex.GetString());
} else if (token == "\\pextra_type") {
lex.nextToken();
par->pextra_type = lex.GetInteger();
} else if (token == "\\labelwidthstring") {
lex.EatLine();
par->labelwidthstring = lex.GetString();
- /* do not delete this token, it is still needed! */
+ // do not delete this token, it is still needed!
} else if (token == "\\end_inset") {
- /* simple ignore this. The insets do not have
- * to read this */
- // but insets should read it, it is a part of
- //the inset isn't it? Lgb.
+ // Simply ignore this. The insets do not have
+ // to read this.
+ // But insets should read it, it is a part of
+ // the inset isn't it? Lgb.
} else if (token == "\\begin_inset") {
+ // Should be moved out into its own function/method. (Lgb)
lex.next();
- tmptok = lex.GetString();
- /* test the different insets */
+ string tmptok = lex.GetString();
+ // test the different insets
if (tmptok == "Quotes") {
- inset = new InsetQuotes;
+ Inset * inset = new InsetQuotes;
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
+#if 0
} else if (tmptok == "\\i") {
- inset = new InsetLatexAccent;
+ Inset * inset = new InsetLatexAccent;
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
+#endif
} else if (tmptok == "FormulaMacro") {
- inset = new InsetFormulaMacro;
+ Inset * inset = new InsetFormulaMacro;
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
} else if (tmptok == "Formula") {
- inset = new InsetFormula;
+ Inset * inset = new InsetFormula;
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
} else if (tmptok == "Figure") {
- inset = new InsetFig(100, 100, this);
+ Inset * inset = new InsetFig(100, 100, this);
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
} else if (tmptok == "Info") {
- inset = new InsetInfo;
+ Inset * inset = new InsetInfo;
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
} else if (tmptok == "Include") {
- inset = new InsetInclude(string(), this);
+ Inset * inset = new InsetInclude(string(), this);
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
} else if (tmptok == "ERT") {
- inset = new InsetERT(this);
+ Inset * inset = new InsetERT(this);
+ inset->Read(lex);
+ par->InsertChar(pos, LyXParagraph::META_INSET);
+ par->InsertInset(pos, inset);
+ par->SetFont(pos, font);
+ ++pos;
+ } else if (tmptok == "Tabular") {
+ Inset * inset = new InsetTabular(this);
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
} else if (tmptok == "Text") {
- inset = new InsetText(this);
+ Inset * inset = new InsetText(this);
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
} else if (tmptok == "Foot") {
- inset = new InsetFoot(this);
+ Inset * inset = new InsetFoot(this);
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
} else if (tmptok == "GRAPHICS") {
- inset = new InsetGraphics;
+ Inset * inset = new InsetGraphics;
//inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
} else if (tmptok == "LatexCommand") {
InsetCommand inscmd;
inscmd.Read(lex);
+ Inset * inset = 0;
if (inscmd.getCmdName() == "cite") {
inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
} else if (inscmd.getCmdName() == "bibitem") {
if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
inset = new InsetRef(inscmd, this);
}
-#warning Verify that this else clause is still needed. (Lgb)
+ // CHECK if this else clause
+ //is still needed. (Lgb)
#if 0
// This condition comes from a
// temporary solution to the latexdel
++pos;
}
}
+#if 0
} else if (token == "\\InsetQuotes") {
- inset = new InsetQuotes;
+ lyxerr << "InsetQuotes" << endl;
+ Inset * inset = new InsetQuotes;
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
+#endif
+#if 0
} else if (token == "\\InsetFormula") {
- inset = new InsetFormula;
+ lyxerr << "InsetFormula" << endl;
+ Inset * inset = new InsetFormula;
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
+#endif
} else if (token == "\\SpecialChar") {
LyXLayout const & layout =
textclasslist.Style(params.textclass,
par->GetLayout());
// Insets don't make sense in a free-spacing context! ---Kayvan
- if (layout.free_spacing)
- {
+ if (layout.free_spacing) {
if (lex.IsOK()) {
string next_token;
lex.next();
lex.printError("Token `$$Token' "
"is in free space "
"paragraph layout!");
- pos--;
+ --pos;
}
}
- }
- else
- {
- inset = new InsetSpecialChar;
+ } else {
+ Inset * inset = new InsetSpecialChar;
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
}
++pos;
+#if 0
} else if (token == "\\Figure") {
- inset = new InsetFig(100, 100, this);
+ lyxerr << "Figure" << endl;
+ Inset * inset = new InsetFig(100, 100, this);
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
- } else if (token == "\\newline") { // soon obsolete
-#if 1
+#endif
+ } else if (token == "\\newline") {
par->InsertChar(pos, LyXParagraph::META_NEWLINE);
par->SetFont(pos, font);
-#else
- inset = new InsetSpecialChar(InsetSpecialChar::NEWLINE);
- par->InsertChar(pos, LyXParagraph::META_INSET);
- par->InsertInset(pos, inset);
- par->SetFont(pos, font);
-#endif
++pos;
} else if (token == "\\LyXTable") {
par->table = new LyXTable(lex);
par->SetFont(pos, font);
++pos;
} else if (token == "\\protected_separator") { // obsolete
-#if 1
+ // This is a backward compability thingie. (Lgb)
+ // Remove it later some time...introduced with fileformat
+ // 2.16. (Lgb)
LyXLayout const & layout =
textclasslist.Style(params.textclass,
par->GetLayout());
par->InsertChar(pos, ' ');
par->SetFont(pos, font);
} else {
- inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
+ Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
}
-#else
- par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
- par->SetFont(pos, font);
-#endif
++pos;
} else if (token == "\\bibitem") { // ale970302
if (!par->bibkey)
// This should be insurance for the future: (Asger)
lex.printError("Unknown token `$$Token'. "
"Inserting as text.");
- int n = token.length();
- for (int i = 0; i < n; ++i) {
- par->InsertChar(pos, token[i]);
+ for(string::const_iterator cit = token.begin();
+ cit != token.end(); ++cit) {
+ par->InsertChar(pos, (*cit));
par->SetFont(pos, font);
++pos;
}
// Should probably be moved to somewhere else: BufferView? LyXView?
-bool Buffer::save(bool makeBackup) const
+bool Buffer::save() const
{
// We don't need autosaves in the immediate future. (Asger)
resetAutosaveTimers();
// make a backup
- if (makeBackup) {
- string s = fileName() + '~';
+ string s;
+ if (lyxrc.make_backup) {
+ s = fileName() + '~';
+ if (!lyxrc.backupdir_path.empty())
+ s = AddName(lyxrc.backupdir_path,
+ subst(CleanupPath(s),'/','!'));
+
// Rename is the wrong way of making a backup,
// this is the correct way.
/* truss cp fil fil2:
FileInfo finfo(fileName());
if (finfo.exist()) {
mode_t fmode = finfo.getMode();
- struct utimbuf * times = new struct utimbuf;
+ struct utimbuf times = {
+ finfo.getAccessTime(),
+ finfo.getModificationTime() };
- times->actime = finfo.getAccessTime();
- times->modtime = finfo.getModificationTime();
ifstream ifs(fileName().c_str());
ofstream ofs(s.c_str(), ios::out|ios::trunc);
if (ifs && ofs) {
ofs.close();
::chmod(s.c_str(), fmode);
- if (::utime(s.c_str(), times)) {
+ if (::utime(s.c_str(), ×)) {
lyxerr << "utime error." << endl;
}
} else {
lyxerr << "LyX was not able to make "
"backupcopy. Beware." << endl;
}
- delete times;
}
}
}
} else {
// Saving failed, so backup is not backup
- if (makeBackup) {
- string s = fileName() + '~';
+ if (lyxrc.make_backup) {
::rename(s.c_str(), fileName().c_str());
}
return false;
/* noindent ? */
/* what about the alignment */
- }
- else {
+ } else {
/* dummy layout, that means a footnote ended */
footnoteflag = LyXParagraph::NO_FOOTNOTE;
ofs << ") ";
noparbreak = 1;
}
- LyXLayout const & layout =
- textclasslist.Style(params.textclass,
- par->GetLayout());
- bool free_spc = layout.free_spacing;
+ //LyXLayout const & layout =
+ // textclasslist.Style(params.textclass,
+ // par->GetLayout()); // unused
+ //bool free_spc = layout.free_spacing; //unused
/* It might be a table */
if (par->table){
c = par->GetChar(i);
if (c == LyXParagraph::META_INSET) {
if ((inset = par->GetInset(i))) {
-#if 1
#ifdef HAVE_SSTREAM
- ostringstream ost;
- inset->Latex(ost, -1, free_spc);
+ std::ostringstream ost;
+ inset->Ascii(ost);
h += ost.str().length();
#else
ostrstream ost;
- inset->Latex(ost, -1, free_spc);
+ inset->Ascii(ost);
ost << '\0';
char * tmp = ost.str();
string tstr(tmp);
h += tstr.length();
delete [] tmp;
-#endif
-#else
- ofstream fs(fname1.c_str());
- if (!fs) {
- WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
- return;
- }
- inset->Latex(fs, -1, free_spc);
- h += fs.tellp() - 1;
- ::remove(fname1.c_str());
#endif
}
} else if (c == LyXParagraph::META_NEWLINE) {
clen[j] = h;
}
- font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
+ font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
actcell = 0;
for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
if (!i && !footnoteflag && !noparbreak){
islatex = 0;
else
islatex = 1;
- }
- else {
+ } else {
islatex = 0;
}
c = par->GetChar(i);
case LyXParagraph::META_INSET:
if ((inset = par->GetInset(i))) {
fpos = ofs.tellp();
- inset->Latex(ofs, -1, free_spc);
+ inset->Ascii(ofs);
currlinelen += (ofs.tellp() - fpos);
actpos += (ofs.tellp() - fpos) - 1;
}
case LyXParagraph::META_HFILL:
ofs << "\t";
break;
-#if 0
- case LyXParagraph::META_PROTECTED_SEPARATOR:
- ofs << " ";
- break;
-#endif
case '\\':
ofs << "\\";
break;
// validate the buffer.
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
- LaTeXFeatures features(tclass.numLayouts());
+ LaTeXFeatures features(params, tclass.numLayouts());
validate(features);
lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
options += (*cit)->lang + ",";
}
if (default_language != params.language_info)
- options += default_language ->lang + ',';
+ options += default_language->lang + ',';
options += params.language_info->lang + ',';
}
texrow.newline();
}
- /* at the very beginning the text parameters */
+ // At the very beginning the text parameters.
if (params.paperpackage != BufferParams::PACKAGE_NONE) {
switch (params.paperpackage) {
case BufferParams::PACKAGE_A4:
string preamble, tmppreamble;
// The optional packages;
- preamble = features.getPackages(params);
+ preamble = features.getPackages();
// this might be useful...
preamble += "\n\\makeatletter\n\n";
// Some macros LyX will need
- tmppreamble = features.getMacros(params);
+ tmppreamble = features.getMacros();
if (!tmppreamble.empty()) {
preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
}
// the text class specific preamble
- tmppreamble = features.getTClassPreamble(params);
+ tmppreamble = features.getTClassPreamble();
if (!tmppreamble.empty()) {
preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
"Textclass specific LaTeX commands.\n"
texrow.newline();
}
+ latexParagraphs(ofs, paragraph, 0, texrow);
+
+ // add this just in case after all the paragraphs
+ ofs << endl;
+ texrow.newline();
+
+ if (!lyxrc.language_auto_end && params.language != "default") {
+ ofs << subst(lyxrc.language_command_end, "$$lang",
+ params.language)
+ << endl;
+ texrow.newline();
+ }
+
+ if (!only_body) {
+ ofs << "\\end{document}\n";
+ texrow.newline();
+
+ lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
+ } else {
+ lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
+ << endl;
+ }
+
+ // Just to be sure. (Asger)
+ texrow.newline();
+
+ // tex_code_break_column's value is used to decide
+ // if we are in batchmode or not (within mathed_write()
+ // in math_write.C) so we must set it to a non-zero
+ // value when we leave otherwise we save incorrect .lyx files.
+ tex_code_break_column = lyxrc.ascii_linelen;
+
+ ofs.close();
+ if (ofs.fail()) {
+ lyxerr << "File was not closed properly." << endl;
+ }
+
+ lyxerr.debug() << "Finished making latex file." << endl;
+}
+
+//
+// LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
+//
+void Buffer::latexParagraphs(ostream & ofs, LyXParagraph *par,
+ LyXParagraph *endpar, TexRow & texrow)
+{
bool was_title = false;
bool already_title = false;
#ifdef HAVE_SSTREAM
- ostringstream ftnote;
+ std::ostringstream ftnote;
#else
char * tmpholder = 0;
#endif
TexRow ft_texrow;
int ftcount = 0;
- LyXParagraph * par = paragraph;
-
// if only_body
- while (par) {
+ while (par != endpar) {
#ifndef HAVE_SSTREAM
ostrstream ftnote;
if (tmpholder) {
}
#endif
if (par->IsDummy())
- lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
+ lyxerr[Debug::LATEX] << "Error in latexParagraphs."
<< endl;
LyXLayout const & layout =
textclasslist.Style(params.textclass,
if (layout.intitle) {
if (already_title) {
- lyxerr <<"Error in MakeLatexFile: You"
+ lyxerr <<"Error in latexParagraphs: You"
" should not mix title layouts"
" with normal ones." << endl;
} else
ofs << "\\maketitle\n";
texrow.newline();
}
-
- if (!lyxrc.language_auto_end && params.language != "default") {
- ofs << subst(lyxrc.language_command_end, "$$lang",
- params.language)
- << endl;
- texrow.newline();
- }
-
- if (!only_body) {
- ofs << "\\end{document}\n";
- texrow.newline();
-
- lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
- } else {
- lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
- << endl;
- }
-
- // Just to be sure. (Asger)
- texrow.newline();
-
- // tex_code_break_column's value is used to decide
- // if we are in batchmode or not (within mathed_write()
- // in math_write.C) so we must set it to a non-zero
- // value when we leave otherwise we save incorrect .lyx files.
- tex_code_break_column = lyxrc.ascii_linelen;
-
- ofs.close();
- if (ofs.fail()) {
- lyxerr << "File was not closed properly." << endl;
- }
-
- lyxerr.debug() << "Finished making latex file." << endl;
}
-
bool Buffer::isLatex() const
{
return textclasslist.TextClass(params.textclass).outputType() == LATEX;
string environment_stack[10];
string item_name;
- int depth = 0; /* paragraph depth */
+ int depth = 0; // paragraph depth
ofstream ofs(fname.c_str());
}
while (par) {
- int desc_on = 0; /* description mode*/
+ int desc_on = 0; // description mode
LyXLayout const & style =
textclasslist.Style(users->buffer()->params.textclass,
par->layout);
par->AutoDeleteInsets();
- /* treat <toc> as a special case for compatibility with old code */
+ // treat <toc> as a special case for compatibility with old code
if (par->GetChar(0) == LyXParagraph::META_INSET) {
Inset * inset = par->GetInset(0);
char lyx_code = inset->LyxCode();
// environment tag closing
for( ; depth > par->depth; --depth) {
sgmlCloseTag(ofs, depth, environment_stack[depth]);
- environment_stack[depth].clear();
+ environment_stack[depth].erase();
}
// write opening SGML tags
if(depth == par->depth
&& !environment_stack[depth].empty()) {
sgmlCloseTag(ofs, depth, environment_stack[depth]);
- environment_stack[depth].clear();
+ environment_stack[depth].erase();
if(depth)
--depth;
else
case LATEX_COMMAND:
if (depth!= 0)
- LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
+ LinuxDocError(par, 0,
+ _("Error : Wrong depth for"
+ " LatexType Command.\n"));
if (!environment_stack[depth].empty()){
sgmlCloseTag(ofs, depth,
ofs << "</p>";
}
- environment_stack[depth].clear();
+ environment_stack[depth].erase();
sgmlOpenTag(ofs, depth, style.latexname());
break;
sgmlCloseTag(ofs, depth,
environment_stack[depth]);
- environment_stack[depth].clear();
+ environment_stack[depth].erase();
}
if (depth < par->depth) {
depth = par->depth;
- environment_stack[depth].clear();
+ environment_stack[depth].erase();
}
if (environment_stack[depth] != style.latexname()) {
if(depth == 0) {
sgmlOpenTag(ofs, depth, temp);
}
environment_stack[depth] = style.latexname();
- sgmlOpenTag(ofs, depth, environment_stack[depth]);
+ sgmlOpenTag(ofs, depth,
+ environment_stack[depth]);
}
if(style.latextype == LATEX_ENVIRONMENT) break;
while(par && par->IsDummy());
ofs << "\n";
- /* write closing SGML tags */
+ // write closing SGML tags
switch(style.latextype) {
case LATEX_COMMAND:
case LATEX_ENVIRONMENT:
}
}
- /* Close open tags */
+ // Close open tags
for(; depth > 0; --depth)
sgmlCloseTag(ofs, depth, environment_stack[depth]);
if(inner_span) {
if(!tmp_par.empty()) {
os << tmp_par;
- tmp_par.clear();
+ tmp_par.erase();
sgmlCloseTag(os, depth + 1, inner_tag);
sgmlOpenTag(os, depth + 1, inner_tag);
}
- }
- else
+ } else {
os << "\n";
+ }
} else {
os << tmp_par;
if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
inner_tag);
if(!extra_par.empty()) os << extra_par;
if(!tag.empty()) sgmlCloseTag(os, depth, tag);
- extra_par.clear();
+ extra_par.erase();
switch (par->footnotekind) {
case LyXParagraph::FOOTNOTE:
if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
DocBookHandleCaption(os, inner_tag, depth,
desc_on, par);
- inner_tag.clear();
+ inner_tag.erase();
} else {
sgmlOpenTag(os, depth + 1, inner_tag);
}
.NumberOfLayout(params.textclass,
"Caption").second) {
#ifdef HAVE_SSTREAM
- ostringstream ost;
+ std::ostringstream ost;
#else
ostrstream ost;
#endif
}
-/* push a tag in a style stack */
+// push a tag in a style stack
void Buffer::push_tag(ostream & os, char const * tag,
int & pos, char stack[5][3])
{
- /* pop all previous tags */
+ // pop all previous tags
for (int j = pos; j >= 0; --j)
os << "</" << stack[j] << ">";
- /* add new tag */
+ // add new tag
sprintf(stack[++pos], "%s", tag);
- /* push all tags */
+ // push all tags
for (int i = 0; i <= pos; ++i)
os << "<" << stack[i] << ">";
}
+
void Buffer::pop_tag(ostream & os, char const * tag,
int & pos, char stack[5][3])
{
}
-/* handle internal paragraph parsing -- layout already processed */
+// Handle internal paragraph parsing -- layout already processed.
// checks, if newcol chars should be put into this line
// writes newline, if necessary.
char shape_type = 0; // shape font flag
bool is_em = false; // emphasis (italic) font flag
- int stack_num = -1; // style stack position
+ int stack_num = -1; // style stack position
+ // Can this be rewritten to use a std::stack, please. (Lgb)
char stack[5][3]; // style stack
unsigned int char_line_count = 5; // Heuristic choice ;-)
else
main_body = par->BeginningOfMainBody();
- /* gets paragraph main font */
+ // gets paragraph main font
if (main_body > 0)
font1 = style.labelfont;
else
font1 = style.font;
- /* parsing main loop */
+ // parsing main loop
for (LyXParagraph::size_type i = 0;
i < par->size(); ++i) {
- /* handle quote tag */
+ // handle quote tag
if (i == main_body && !par->IsDummy()) {
if (main_body > 0)
font1 = style.font;
}
}
- /* handle bold face */
+ // handle bold face
if (font1.series() != font2.series()) {
if (font2.series() == LyXFont::BOLD_SERIES) {
push_tag(os, "bf", stack_num, stack);
}
}
- /* handle italic and slanted fonts */
+ // handle italic and slanted fonts
if (font1.shape() != font2.shape()) {
switch(shape_type) {
case 0:
}
}
}
- /* handle <em> tag */
+ // handle <em> tag
if (font1.emph() != font2.emph()) {
if (font2.emph() == LyXFont::ON) {
push_tag(os, "em", stack_num, stack);
font1 = font2;
}
- /* needed if there is an optional argument but no contents */
+ // needed if there is an optional argument but no contents
if (main_body > 0 && main_body == par->size()) {
font1 = style.font;
}
- /* pop all defined Styles */
+ // pop all defined Styles
for (j = stack_num; j >= 0; --j) {
linux_doc_line_break(os,
char_line_count,
os << "</" << stack[j] << ">";
}
- /* resets description flag correctly */
+ // resets description flag correctly
switch(desc_on){
case 1:
- /* <tag> not closed... */
+ // <tag> not closed...
linux_doc_line_break(os, char_line_count, 6);
os << "</tag>";
break;
case 2:
- /* fprintf(file, "</p>");*/
+ // fprintf(file, "</p>");
break;
}
}
-/* print an error message */
+// Print an error message.
void Buffer::LinuxDocError(LyXParagraph * par, int pos,
char const * message)
{
InsetError * new_inset;
- /* insert an error marker in text */
+ // insert an error marker in text
new_inset = new InsetError(message);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, new_inset);
LyXParagraph * par = paragraph;
string top_element= textclasslist.LatexnameOfClass(params.textclass);
+ // Please use a real stack.
string environment_stack[MAX_NEST_LEVEL];
string environment_inner[MAX_NEST_LEVEL];
+ // Please use a real stack.
string command_stack[MAX_NEST_LEVEL];
bool command_flag= false;
int command_depth= 0, command_base= 0, cmd_depth= 0;
string item_name, command_name;
string c_depth, c_params, tmps;
- int depth= 0; /* paragraph depth */
+ int depth = 0; // paragraph depth
tex_code_break_column = column;
}
while (par) {
- int desc_on = 0; /* description mode*/
+ int desc_on = 0; // description mode
LyXLayout const & style =
textclasslist.Style(users->buffer()->params.textclass,
par->layout);
par->AutoDeleteInsets();
- /* environment tag closing */
+ // environment tag closing
for( ; depth > par->depth; --depth) {
if(environment_inner[depth] != "!-- --") {
item_name= "listitem";
}
sgmlCloseTag(ofs, depth + command_depth,
environment_stack[depth]);
- environment_stack[depth].clear();
- environment_inner[depth].clear();
+ environment_stack[depth].erase();
+ environment_inner[depth].erase();
}
if(depth == par->depth
sgmlCloseTag(ofs, depth + command_depth,
environment_stack[depth]);
- environment_stack[depth].clear();
- environment_inner[depth].clear();
+ environment_stack[depth].erase();
+ environment_inner[depth].erase();
}
// Write opening SGML tags.
case LATEX_ITEM_ENVIRONMENT:
if (depth < par->depth) {
depth = par->depth;
- environment_stack[depth].clear();
+ environment_stack[depth].erase();
}
if (environment_stack[depth] != style.latexname()) {
while(par && par->IsDummy());
string end_tag;
- /* write closing SGML tags */
+ // write closing SGML tags
switch(style.latextype) {
case LATEX_COMMAND:
end_tag = "title";
main_body = par->BeginningOfMainBody();
// gets paragraph main font
- //if (main_body > 0)
- // font1 = style.labelfont;
- //else
- // font1 = style.font;
LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
int char_line_count = depth;
if (c == LyXParagraph::META_INSET) {
Inset * inset = par->GetInset(i);
#ifdef HAVE_SSTREAM
- ostringstream ost;
+ std::ostringstream ost;
inset->DocBook(ost);
string tmp_out = ost.str().c_str();
#else
if (c != '\0')
os << c;
++char_line_count;
- }
- else {
+ } else {
string sgml_string;
if (par->linuxDocConvertChar(c, sgml_string)
&& !style.free_spacing) { // in freespacing
++char_line_count;
os << "\n</term><listitem><para>";
desc_on = 2;
- }
- else {
+ } else {
os << c;
}
- }
- else {
+ } else {
os << sgml_string;
}
}
font1 = font2;
}
- /* needed if there is an optional argument but no contents */
+ // needed if there is an optional argument but no contents
if (main_body > 0 && main_body == par->size()) {
font1 = style.font;
}
os << "</emphasis>";
}
- /* resets description flag correctly */
+ // resets description flag correctly
switch(desc_on){
case 1:
- /* <term> not closed... */
+ // <term> not closed...
os << "</term>";
break;
}
{
if (!users->text) return 0;
- ProhibitInput();
+ ProhibitInput(users);
// get LaTeX-Filename
string name = getLatexName();
if (a || (res & LaTeX::ERRORS)){
users->redraw();
users->fitCursor();
- users->updateScrollbar();
+ //users->updateScrollbar();
}
- AllowInput();
+ AllowInput(users);
return latex.getNumErrors();
}
{
if (!users->text) return 0;
- ProhibitInput();
+ ProhibitInput(users);
// get LaTeX-Filename
string name = getLatexName();
if (a || (res & Literate::ERRORS)){
users->redraw();
users->fitCursor();
- users->updateScrollbar();
+ //users->updateScrollbar();
}
- AllowInput();
+ AllowInput(users);
return literate.getNumErrors();
}
{
if (!users->text) return 0;
- ProhibitInput();
+ ProhibitInput(users);
// get LaTeX-Filename
string name = getLatexName();
markNwClean();
}
- // if we removed error insets before we ran Literate/Build or if we inserted
- // error insets after we ran Literate/Build this must be run:
+ // if we removed error insets before we ran Literate/Build or
+ // if we inserted error insets after we ran Literate/Build this
+ // must be run:
if (a || (res & Literate::ERRORS)){
users->redraw();
users->fitCursor();
- users->updateScrollbar();
+ //users->updateScrollbar();
}
- AllowInput();
+ AllowInput(users);
return literate.getNumErrors();
}
{
if (!users->text) return 0;
- ProhibitInput();
+ ProhibitInput(users);
// get LaTeX-Filename
string name = getLatexName();
if (a || res){
users->redraw();
users->fitCursor();
- users->updateScrollbar();
+ //users->updateScrollbar();
}
- AllowInput();
+ AllowInput(users);
return res;
}
switch (c) {
case LyXParagraph::META_INSET:
if ((inset = par->GetInset(i))) {
-#if 1
#ifdef HAVE_SSTREAM
stringstresm ss(ios::in | ios::out);
- inset->Latex(ss, -1);
+ inset->Ascii(ss);
ss.seekp(0);
ss.get(c);
while (!ss) {
}
#else
strstream ss;
- inset->Latex(ss, -1);
+ inset->Ascii(ss);
ss.seekp(0);
ss.get(c);
while (!ss) {
ss.get(c);
}
delete [] ss.str();
-#endif
-#else
- fstream fs(fname2.c_str(), ios::in|ios::out);
- if (!fs) {
- WriteAlert(_("LYX_ERROR:"),
- _("Cannot open temporary file:"), fname2);
- ofs.close();
- remove(fname1.c_str());
- return;
- }
- inset->Latex(fs, -1);
- fs.seekp(0);
- fs.get(c);
- while(!fs) {
- if (c == '\\')
- ofs << "\\\\";
- else
- ofs << c;
- fs >> c;
- }
- fs.close();
#endif
}
break;
break;
case LyXParagraph::META_HFILL:
break;
-#if 0
- case LyXParagraph::META_PROTECTED_SEPARATOR:
- break;
-#endif
case '\\':
ofs << "\\\\";
break;
}
if (lyxerr.debugging(Debug::LATEX)) {
- features.showStruct(params);
+ features.showStruct();
}
}
}
-void Buffer::Dispatch(string const & command)
+bool Buffer::Dispatch(string const & command)
{
// Split command string into command and argument
string cmd, line = frontStrip(command);
string arg = strip(frontStrip(split(line, cmd, ' ')));
- Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
+ return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
}
-void Buffer::Dispatch(int action, string const & argument)
+bool Buffer::Dispatch(int action, string const & argument)
{
+ bool dispatched = true;
switch (action) {
case LFUN_EXPORT:
MenuExport(this, argument);
break;
default:
- lyxerr << "A truly unknown func!" << endl;
- break;
+ dispatched = false;
+ }
+ return dispatched;
+}
+
- } // end of switch
+void Buffer::ChangeLanguage(Language const * from, Language const * to)
+{
+
+ LyXParagraph * par = paragraph;
+ while (par) {
+ par->ChangeLanguage(from, to);
+ par = par->next;
+ }
+}
+
+
+bool Buffer::isMultiLingual()
+{
+
+ LyXParagraph * par = paragraph;
+ while (par) {
+ if (par->isMultiLingual())
+ return true;
+ par = par->next;
+ }
+ return false;
}