#include "buffer_funcs.h"
#include "bufferlist.h"
#include "bufferparams.h"
+#include "counters.h"
#include "Bullet.h"
#include "Chktex.h"
#include "debug.h"
#include "lyxrc.h"
#include "lyxvc.h"
#include "messages.h"
+#include "output.h"
+#include "output_docbook.h"
+#include "output_latex.h"
+#include "output_linuxdoc.h"
#include "paragraph.h"
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
+#include "PosIterator.h"
#include "sgml.h"
#include "texrow.h"
#include "undo.h"
using lyx::pos_type;
using lyx::support::AddName;
-using lyx::support::ascii_lowercase;
using lyx::support::atoi;
using lyx::support::bformat;
using lyx::support::ChangeExtension;
using lyx::support::cmd_ret;
-using lyx::support::compare_ascii_no_case;
-using lyx::support::compare_no_case;
-using lyx::support::contains;
using lyx::support::CreateBufferTmpDir;
using lyx::support::destroyDir;
using lyx::support::FileInfo;
const int LYX_FORMAT = 225;
-bool openFileWrite(ofstream & ofs, string const & fname)
-{
- ofs.open(fname.c_str());
- if (!ofs) {
- string const file = MakeDisplayPath(fname, 50);
- string text = bformat(_("Could not open the specified "
- "document\n%1$s."), file);
- Alert::error(_("Could not open file"), text);
- return false;
- }
- return true;
-}
-
} // namespace anon
}
-namespace {
-
-pair<int, string> const addDepth(int depth, int ldepth)
-{
- int d = depth * 2;
- if (ldepth > depth)
- d += (ldepth - depth) * 2;
- return make_pair(d, string(d, ' '));
-}
-
-}
-
-
-string const Buffer::asciiParagraph(Paragraph const & par,
- unsigned int linelen,
- bool noparbreak) const
-{
- ostringstream buffer;
- int ltype = 0;
- Paragraph::depth_type ltype_depth = 0;
- bool ref_printed = false;
- Paragraph::depth_type depth = par.params().depth();
-
- // First write the layout
- string const & tmp = par.layout()->name();
- if (compare_no_case(tmp, "itemize") == 0) {
- ltype = 1;
- ltype_depth = depth + 1;
- } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
- ltype = 2;
- ltype_depth = depth + 1;
- } else if (contains(ascii_lowercase(tmp), "ection")) {
- ltype = 3;
- ltype_depth = depth + 1;
- } else if (contains(ascii_lowercase(tmp), "aragraph")) {
- ltype = 4;
- ltype_depth = depth + 1;
- } else if (compare_ascii_no_case(tmp, "description") == 0) {
- ltype = 5;
- ltype_depth = depth + 1;
- } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
- ltype = 6;
- ltype_depth = 0;
- } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
- ltype = 7;
- ltype_depth = 0;
- } else {
- ltype = 0;
- ltype_depth = 0;
- }
-
- /* maybe some vertical spaces */
-
- /* the labelwidthstring used in lists */
-
- /* some lines? */
-
- /* some pagebreaks? */
-
- /* noindent ? */
-
- /* what about the alignment */
-
- // linelen <= 0 is special and means we don't have paragraph breaks
-
- string::size_type currlinelen = 0;
-
- if (!noparbreak) {
- if (linelen > 0)
- buffer << "\n\n";
-
- buffer << string(depth * 2, ' ');
- currlinelen += depth * 2;
-
- //--
- // we should probably change to the paragraph language in the
- // gettext here (if possible) so that strings are outputted in
- // the correct language! (20012712 Jug)
- //--
- switch (ltype) {
- case 0: // Standard
- case 4: // (Sub)Paragraph
- case 5: // Description
- break;
- case 6: // Abstract
- if (linelen > 0) {
- buffer << _("Abstract") << "\n\n";
- currlinelen = 0;
- } else {
- string const abst = _("Abstract: ");
- buffer << abst;
- currlinelen += abst.length();
- }
- break;
- case 7: // Bibliography
- if (!ref_printed) {
- if (linelen > 0) {
- buffer << _("References") << "\n\n";
- currlinelen = 0;
- } else {
- string const refs = _("References: ");
- buffer << refs;
- currlinelen += refs.length();
- }
-
- ref_printed = true;
- }
- break;
- default:
- {
- string const parlab = par.params().labelString();
- buffer << parlab << ' ';
- currlinelen += parlab.length() + 1;
- }
- break;
-
- }
- }
-
- if (!currlinelen) {
- pair<int, string> p = addDepth(depth, ltype_depth);
- buffer << p.second;
- currlinelen += p.first;
- }
-
- // this is to change the linebreak to do it by word a bit more
- // intelligent hopefully! (only in the case where we have a
- // max linelength!) (Jug)
-
- string word;
-
- for (pos_type i = 0; i < par.size(); ++i) {
- char c = par.getUChar(params(), i);
- switch (c) {
- case Paragraph::META_INSET:
- {
- InsetOld const * inset = par.getInset(i);
- if (inset) {
- if (linelen > 0) {
- buffer << word;
- currlinelen += word.length();
- word.erase();
- }
- if (inset->ascii(*this, buffer, linelen)) {
- // to be sure it breaks paragraph
- currlinelen += linelen;
- }
- }
- }
- break;
-
- default:
- if (c == ' ') {
- if (linelen > 0 &&
- currlinelen + word.length() > linelen - 10) {
- buffer << "\n";
- pair<int, string> p = addDepth(depth, ltype_depth);
- buffer << p.second;
- currlinelen = p.first;
- }
-
- buffer << word << ' ';
- currlinelen += word.length() + 1;
- word.erase();
-
- } else {
- if (c != '\0') {
- word += c;
- } else {
- lyxerr[Debug::INFO] <<
- "writeAsciiFile: NULL char in structure." << endl;
- }
- if ((linelen > 0) &&
- (currlinelen + word.length()) > linelen)
- {
- buffer << "\n";
-
- pair<int, string> p =
- addDepth(depth, ltype_depth);
- buffer << p.second;
- currlinelen = p.first;
- }
- }
- break;
- }
- }
- buffer << word;
- return buffer.str();
-}
-
-
-void Buffer::writeFileAscii(string const & fname, int linelen)
-{
- ofstream ofs;
- if (!::openFileWrite(ofs, fname))
- return;
- writeFileAscii(ofs, linelen);
-}
-
-
-void Buffer::writeFileAscii(ostream & os, int linelen)
-{
- ParagraphList::iterator beg = paragraphs().begin();
- ParagraphList::iterator end = paragraphs().end();
- ParagraphList::iterator it = beg;
- for (; it != end; ++it) {
- os << asciiParagraph(*it, linelen, it == beg);
- }
- os << "\n";
-}
-
-
void Buffer::makeLaTeXFile(string const & fname,
string const & original_path,
- LatexRunParams const & runparams,
+ OutputParams const & runparams,
bool output_preamble, bool output_body)
{
lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
ofstream ofs;
- if (!::openFileWrite(ofs, fname))
+ if (!openFileWrite(ofs, fname))
return;
makeLaTeXFile(ofs, original_path,
void Buffer::makeLaTeXFile(ostream & os,
string const & original_path,
- LatexRunParams const & runparams_in,
+ OutputParams const & runparams_in,
bool output_preamble, bool output_body)
{
- LatexRunParams runparams = runparams_in;
+ OutputParams runparams = runparams_in;
niceFile() = runparams.nice; // this will be used by Insetincludes.
// validate the buffer.
}
-void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
+void Buffer::makeLinuxDocFile(string const & fname,
+ OutputParams const & runparams,
+ bool body_only )
{
ofstream ofs;
- if (!::openFileWrite(ofs, fname))
+ if (!openFileWrite(ofs, fname))
return;
- niceFile() = nice; // this will be used by included files.
+ niceFile() = runparams.nice; // this will be used by included files.
LaTeXFeatures features(*this, params());
ofs << "<!doctype linuxdoc system";
string preamble = params().preamble;
- string const name = nice ? ChangeExtension(pimpl_->filename, ".sgml")
+ string const name = runparams.nice ? ChangeExtension(pimpl_->filename, ".sgml")
: fname;
preamble += features.getIncludedFiles(name);
preamble += features.getLyXSGMLEntities();
<< " created this file. For more info see http://www.lyx.org/"
<< " -->\n";
- linuxdocParagraphs(*this, paragraphs(), ofs);
+ linuxdocParagraphs(*this, paragraphs(), ofs, runparams);
if (!body_only) {
ofs << "\n\n";
}
-void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
+void Buffer::makeDocBookFile(string const & fname,
+ OutputParams const & runparams,
+ bool only_body)
{
ofstream ofs;
- if (!::openFileWrite(ofs, fname))
+ if (!openFileWrite(ofs, fname))
return;
- niceFile() = nice; // this will be used by Insetincludes.
+ niceFile() = runparams.nice; // this will be used by Insetincludes.
LaTeXFeatures features(*this, params());
validate(features);
<< " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
string preamble = params().preamble;
- string const name = nice ? ChangeExtension(pimpl_->filename, ".sgml")
+ string const name = runparams.nice ? ChangeExtension(pimpl_->filename, ".sgml")
: fname;
preamble += features.getIncludedFiles(name);
preamble += features.getLyXSGMLEntities();
ofs << "<!-- DocBook file was created by LyX " << lyx_version
<< "\n See http://www.lyx.org/ for more information -->\n";
- docbookParagraphs(*this, paragraphs(), ofs);
+ params().getLyXTextClass().counters().reset();
+ docbookParagraphs(*this, paragraphs(), ofs, runparams);
ofs << "\n\n";
sgml::closeTag(ofs, 0, false, top_element);
message(_("Running chktex..."));
// Generate the LaTeX file if neccessary
- LatexRunParams runparams;
- runparams.flavor = LatexRunParams::LATEX;
+ OutputParams runparams;
+ runparams.flavor = OutputParams::LATEX;
runparams.nice = false;
makeLaTeXFile(name, org_path, runparams);
}
-InsetOld * Buffer::getInsetFromID(int id_arg) const
-{
- for (inset_iterator it = inset_const_iterator_begin();
- it != inset_const_iterator_end(); ++it)
- {
- if (it->id() == id_arg)
- return &(*it);
- InsetOld * in = it->getInsetFromID(id_arg);
- if (in)
- return in;
- }
- return 0;
-}
-
-
ParIterator Buffer::getParFromID(int id) const
{
#warning FIXME: const correctness! (Andre)
}
+PosIterator Buffer::pos_iterator_begin()
+{
+ return PosIterator(¶graphs(), paragraphs().begin(), 0);
+}
+
+
+PosIterator Buffer::pos_iterator_end()
+{
+ return PosIterator(¶graphs(), paragraphs().end(), 0);
+}
+
+
ParIterator Buffer::par_iterator_begin()
{
return ParIterator(paragraphs().begin(), paragraphs());