+2004-08-14 José Matos <jamatos@lyx.org>
+ * lyx_1_4.py:
+ * parser_tools.py: up the format to 236.
+
2004-08-05 José Matos <jamatos@lyx.org>
* lyx_1.4.py (remove_color_default): move
header.insert(i, "\\use_natbib " + use_natbib)
+##
+# Paper package
+#
def convert_paperpackage(header, opt):
i = find_token(header, "\\paperpackage", 0)
if i == -1:
##
-# Convertion hub
+# Bullets
+#
+def convert_bullets(header, opt):
+ i = 0
+ while 1:
+ i = find_token(header, "\\bullet", i)
+ if i == -1:
+ return
+ if header[i][:12] == '\\bulletLaTeX':
+ header[i] = header[i] + ' ' + strip(header[i+1])
+ n = 3
+ else:
+ header[i] = header[i] + ' ' + strip(header[i+1]) +\
+ ' ' + strip(header[i+2]) + ' ' + strip(header[i+3])
+ n = 5
+ del header[i+1:i + n]
+ i = i + 1
+
+
+def revert_bullets(header, opt):
+ i = 0
+ while 1:
+ i = find_token(header, "\\bullet", i)
+ if i == -1:
+ return
+ if header[i][:12] == '\\bulletLaTeX':
+ n = find(header[i], '"')
+ if n == -1:
+ opt.warn("Malformed header")
+ return
+ else:
+ header[i:i+1] = [header[i][:n-1],'\t' + header[i][n:], '\\end_bullet']
+ i = i + 3
+ else:
+ frag = split(header[i])
+ if len(frag) != 5:
+ opt.warn("Malformed header")
+ return
+ else:
+ header[i:i+1] = [frag[0] + ' ' + frag[1],
+ '\t' + frag[2],
+ '\t' + frag[3],
+ '\t' + frag[4],
+ '\\end_bullet']
+ i = i + 5
+
+
+##
+# \begin_header and \begin_document
#
+def add_begin_header(header, opt):
+ i = find_token(header, '\\lyxformat', 0)
+ header.insert(i+1, '\\begin_header')
+ header.insert(i+1, '\\begin_document')
+
+
+def remove_begin_header(header, opt):
+ i = find_token(header, "\\begin_header", 0)
+ if i != -1:
+ del header[i]
+ i = find_token(header, "\\begin_document", 0)
+ if i != -1:
+ del header[i]
+
+##
+# \begin_body and \end_body
+#
+def add_begin_body(body, opt):
+ body.insert(0, '\\begin_body')
+ i = find_token(body, "\\end_document", 0)
+ body.insert(i, '\\end_body')
+
+def remove_begin_body(body, opt):
+ i = find_token(body, "\\begin_body", 0)
+ if i != -1:
+ del body[i]
+ i = find_token(body, "\\end_body", 0)
+ if i != -1:
+ del body[i]
+
+
+##
+# Convertion hub
+#
def convert(header, body, opt):
if opt.format < 223:
insert_tracking_changes(header)
if opt.format < 235:
convert_paperpackage(header, opt)
opt.format = 235
+ if opt.end == opt.format: return
+
+ if opt.format < 236:
+ convert_bullets(header, opt)
+ add_begin_header(header, opt)
+ add_begin_body(body, opt)
+ opt.format = 236
def revert(header, body, opt):
+ if opt.format > 235:
+ remove_begin_body(body, opt)
+ remove_begin_header(header, opt)
+ revert_bullets(header, opt)
+ opt.format = 235
+ if opt.end == opt.format: return
+
if opt.format > 234:
revert_paperpackage(header, opt)
opt.format = 234
format_re = re.compile(r"(\d)[\.,]?(\d\d)")
fileformat = re.compile(r"\\lyxformat\s*(\S*)")
lst_ft = [210, 215, 216, 217, 218, 220, 221, 223, 224, 225, 226, 227, 228, 229,
- 230, 231, 232, 233, 234, 235]
+ 230, 231, 232, 233, 234, 235, 236]
format_relation = [("0_10", [210], ["0.10.7","0.10"]),
("0_12", [215], ["0.12","0.12.1","0.12"]),
("1_1_6fix3", [218], ["1.1.6fix3","1.1.6fix4","1.1"]),
("1_2", [220], ["1.2.0","1.2.1","1.2.3","1.2.4","1.2"]),
("1_3", [221], ["1.3.0","1.3.1","1.3.2","1.3.3","1.3.4","1.3"]),
- ("1_4", [223,224,225,226,227,228,229,230,231,232,233,234,235], ["1.4.0cvs","1.4"])]
+ ("1_4", [223,224,225,226,227,228,229,230,231,232,233,234,235, 236], ["1.4.0cvs","1.4"])]
def lyxformat(format, opt):
+2004-08-14 José Matos <jamatos@lyx.org>
+
+ * Buffer.[Ch] (readDocument): new name for old readBody.
+ * Buffer.C: new file format, new keywords: \begin_document,
+ \begin_header, \begin_body, \end_body.
+
+ * bufferparams.C (readToken): replace all calls to lex.nextToken
+ by lex.next(). Do the same to eatLine except where really needed.
+
+ * lyxfont.C (lyxWriteChanges): remove whitespaces in the end of
+ line when writing to the lyx file.
+
+ * output_plaintext.C (asciiParagraph): fix Bibliography style
+ handling.
+
+ * text.C (read): fix end of file handling.
+
2004-08-14 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* MenuBackend.C (Menu::operator[]): new method to access
namespace {
-const int LYX_FORMAT = 235;
+const int LYX_FORMAT = 236;
} // namespace anon
int Buffer::readHeader(LyXLex & lex)
{
int unknown_tokens = 0;
+ int line = -1;
+ int begin_header_line = -1;
while (lex.isOK()) {
- lex.nextToken();
+ lex.next();
string const token = lex.getString();
if (token.empty())
if (token == "\\end_header")
break;
+ ++line;
+ if (token == "\\begin_header") {
+ begin_header_line = line;
+ continue;
+ }
+
lyxerr[Debug::PARSER] << "Handling header token: `"
<< token << '\'' << endl;
-
string unknown = params().readToken(lex, token);
if (!unknown.empty()) {
- if (unknown[0] != '\\') {
+ if (unknown[0] != '\\' and token == "\\textclass") {
unknownClass(unknown);
} else {
++unknown_tokens;
}
}
}
+ if (begin_header_line) {
+ string const s = _("\\begin_header is missing");
+ error(ErrorItem(_("Header error"), s, -1, 0, 0));
+ }
return unknown_tokens;
}
// Uwe C. Schroeder
// changed to be public and have one parameter
// Returns false if "\end_document" is not read (Asger)
-bool Buffer::readBody(LyXLex & lex)
+bool Buffer::readDocument(LyXLex & lex)
{
+ lex.next();
+ string const token = lex.getString();
+ if (token != "\\begin_document") {
+ string const s = _("\\begin_document is missing");
+ error(ErrorItem(_("Header error"), s, -1, 0, 0));
+ }
+
if (paragraphs().empty()) {
readHeader(lex);
if (!params().getLyXTextClass().load()) {
return false;
}
- lex.eatLine();
+ lex.next();
string tmp_format = lex.getString();
//lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
// if present remove ".," from string.
int file_format = strToInt(tmp_format);
//lyxerr << "format: " << file_format << endl;
- if (file_format > LYX_FORMAT) {
- Alert::warning(_("Document format failure"),
- bformat(_("%1$s was created with a newer"
- " version of LyX. This is likely to"
- " cause problems."),
- filename));
- } else if (file_format < LYX_FORMAT) {
+ if (file_format != LYX_FORMAT) {
string const tmpfile = tempName();
if (tmpfile.empty()) {
Alert::error(_("Conversion failed"),
}
- bool the_end = readBody(lex);
- //lyxerr << "removing " << MacroTable::localMacros().size()
- // << " temporary macro entries" << endl;
- //MacroTable::localMacros().clear();
- params().setPaperStuff();
-
-#ifdef WITH_WARNINGS
-#warning Look here!
-#endif
-#if 0
- if (token == "\\end_document")
- the_end_read = true;
-
- if (!the_end) {
+ if (readDocument(lex)) {
Alert::error(_("Document format failure"),
bformat(_("%1$s ended unexpectedly, which means"
" that it is probably corrupted."),
filename));
}
-#endif
+
+ //lyxerr << "removing " << MacroTable::localMacros().size()
+ // << " temporary macro entries" << endl;
+ //MacroTable::localMacros().clear();
+ params().setPaperStuff();
+
pimpl_->file_fully_loaded = true;
return true;
}
// write out a comment in the top of the file
ofs << "#LyX " << lyx_version
<< " created this file. For more info see http://www.lyx.org/\n"
- << "\\lyxformat " << LYX_FORMAT << "\n";
+ << "\\lyxformat " << LYX_FORMAT << "\n"
+ << "\\begin_document\n";
// now write out the buffer parameters.
+ ofs << "\n\\begin_header\n";
params().writeFile(ofs);
-
ofs << "\\end_header\n";
-
+
// write the text
+ ofs << "\n\\begin_body\n";
text().write(*this, ofs);
+ ofs << "\n\\end_body\n";
// Write marker that shows file is complete
- ofs << "\n\\end_document" << endl;
+ ofs << "\\end_document" << endl;
// Shouldn't really be needed....
//ofs.close();
\param par if != 0 insert the file.
\return \c false if file is not completely read.
*/
- bool readBody(LyXLex &);
+ bool readDocument(LyXLex &);
///
void insertStringAsLines(ParagraphList & plist,
string const BufferParams::readToken(LyXLex & lex, string const & token)
{
if (token == "\\textclass") {
- lex.eatLine();
+ lex.next();
string const classname = lex.getString();
pair<bool, lyx::textclass_type> pp =
textclasslist.NumberOfClass(classname);
} else if (token == "\\language") {
readLanguage(lex);
} else if (token == "\\inputencoding") {
- lex.eatLine();
+ lex.next();
inputenc = lex.getString();
} else if (token == "\\graphics") {
readGraphicsDriver(lex);
} else if (token == "\\fontscheme") {
- lex.eatLine();
+ lex.next();
fonts = lex.getString();
} else if (token == "\\paragraph_separation") {
int tmpret = lex.findToken(string_paragraph_separation);
paragraph_separation =
static_cast<PARSEP>(tmpret);
} else if (token == "\\defskip") {
- lex.nextToken();
+ lex.next();
pimpl_->defskip = VSpace(lex.getString());
} else if (token == "\\quotes_language") {
// FIXME: should be params.readQuotes()
quotes_language = tmpl;
} else if (token == "\\quotes_times") {
// FIXME: should be params.readQuotes()
- lex.nextToken();
+ lex.next();
switch (lex.getInteger()) {
case 1:
quotes_times = InsetQuotes::SingleQ;
} else
paperpackage = PAPER_PACKAGES(tmpret);
} else if (token == "\\use_geometry") {
- lex.nextToken();
+ lex.next();
use_geometry = lex.getInteger();
} else if (token == "\\use_amsmath") {
- lex.nextToken();
+ lex.next();
use_amsmath = static_cast<AMS>(
lex.getInteger());
} else if (token == "\\cite_engine") {
- lex.nextToken();
+ lex.next();
string const engine = lex.getString();
cite_engine = biblio::ENGINE_BASIC;
cite_engine = biblio::ENGINE_JURABIB;
} else if (token == "\\use_bibtopic") {
- lex.nextToken();
+ lex.next();
use_bibtopic = lex.getInteger();
} else if (token == "\\tracking_changes") {
- lex.nextToken();
+ lex.next();
tracking_changes = lex.getInteger();
} else if (token == "\\branch") {
- lex.nextToken();
+ lex.next();
string branch = lex.getString();
branchlist().add(branch);
while (true) {
- lex.nextToken();
+ lex.next();
string const tok = lex.getString();
if (tok == "\\end_branch")
break;
Branch * branch_ptr = branchlist().find(branch);
if (tok == "\\selected") {
- lex.nextToken();
+ lex.next();
if (branch_ptr)
branch_ptr->setSelected(lex.getInteger());
}
// not yet operational
if (tok == "\\color") {
- lex.nextToken();
+ lex.eatLine();
string color = lex.getString();
if (branch_ptr)
branch_ptr->setColor(color);
}
}
} else if (token == "\\author") {
- lex.nextToken();
+ lex.next();
istringstream ss(lex.getString());
Author a;
ss >> a;
lex.next();
footskip = lex.getString();
} else if (token == "\\paperfontsize") {
- lex.nextToken();
- fontsize = rtrim(lex.getString());
+ lex.next();
+ fontsize = lex.getString();
} else if (token == "\\papercolumns") {
- lex.nextToken();
+ lex.next();
columns = lex.getInteger();
} else if (token == "\\papersides") {
- lex.nextToken();
+ lex.next();
switch (lex.getInteger()) {
default:
case 1: sides = LyXTextClass::OneSide; break;
case 2: sides = LyXTextClass::TwoSides; break;
}
} else if (token == "\\paperpagestyle") {
- lex.nextToken();
- pagestyle = rtrim(lex.getString());
+ lex.next();
+ pagestyle = lex.getString();
} else if (token == "\\bullet") {
// FIXME: should be params.readBullets()
- lex.nextToken();
+ lex.next();
int const index = lex.getInteger();
- lex.nextToken();
+ lex.next();
int temp_int = lex.getInteger();
user_defined_bullet(index).setFont(temp_int);
temp_bullet(index).setFont(temp_int);
- lex.nextToken();
+ lex.next();
temp_int = lex.getInteger();
user_defined_bullet(index).setCharacter(temp_int);
temp_bullet(index).setCharacter(temp_int);
- lex.nextToken();
+ lex.next();
temp_int = lex.getInteger();
user_defined_bullet(index).setSize(temp_int);
temp_bullet(index).setSize(temp_int);
- lex.nextToken();
- string const temp_str = lex.getString();
- if (temp_str != "\\end_bullet") {
- // this element isn't really necessary for
- // parsing but is easier for humans
- // to understand bullets. Put it back and
- // set a debug message?
- lex.printError("\\end_bullet expected, got" + temp_str);
- //how can I put it back?
- }
} else if (token == "\\bulletLaTeX") {
// The bullet class should be able to read this.
- lex.nextToken();
- int const index = lex.getInteger();
lex.next();
+ int const index = lex.getInteger();
+ lex.next(true);
string temp_str = lex.getString();
- string sum_str;
- while (temp_str != "\\end_bullet") {
- // this loop structure is needed when user
- // enters an empty string since the first
- // thing returned will be the \\end_bullet
- // OR
- // if the LaTeX entry has spaces. Each element
- // therefore needs to be read in turn
- sum_str += temp_str;
- lex.next();
- temp_str = lex.getString();
- }
- user_defined_bullet(index).setText(sum_str);
- temp_bullet(index).setText(sum_str);
+ user_defined_bullet(index).setText(temp_str);
+ temp_bullet(index).setText(temp_str);
} else if (token == "\\secnumdepth") {
- lex.nextToken();
+ lex.next();
secnumdepth = lex.getInteger();
} else if (token == "\\tocdepth") {
- lex.nextToken();
+ lex.next();
tocdepth = lex.getInteger();
} else if (token == "\\spacing") {
lex.next();
- string const tmp = rtrim(lex.getString());
+ string const tmp = lex.getString();
Spacing::Space tmp_space = Spacing::Default;
float tmp_val = 0.0;
if (tmp == "single") {
} else {
lex.printError("Unknown spacing token: '$$Token'");
}
-#if 0 // FIXME: Handled in lyx2lyx ?
- // Small hack so that files written with klyx will be
- // parsed correctly.
- if (first_par)
- par->params().spacing(Spacing(tmp_space, tmp_val));
-#endif
spacing().set(tmp_space, tmp_val);
} else if (token == "\\float_placement") {
- lex.nextToken();
+ lex.next();
float_placement = lex.getString();
} else {
return token;
for (int i = 0; i < 4; ++i) {
if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
if (user_defined_bullet(i).getFont() != -1) {
- os << "\\bullet " << i
- << "\n\t"
- << user_defined_bullet(i).getFont()
- << "\n\t"
- << user_defined_bullet(i).getCharacter()
- << "\n\t"
- << user_defined_bullet(i).getSize()
- << "\n\\end_bullet\n";
+ os << "\\bullet " << i << " "
+ << user_defined_bullet(i).getFont() << " "
+ << user_defined_bullet(i).getCharacter() << " "
+ << user_defined_bullet(i).getSize() << "\n";
}
else {
- os << "\\bulletLaTeX " << i
- << "\n\t\""
+ os << "\\bulletLaTeX " << i << " \""
<< user_defined_bullet(i).getText()
- << "\"\n\\end_bullet\n";
+ << "\"\n";
}
}
}
+2004-08-14 José Matos <jamatos@lyx.org>
+
+ * insetbibitem.[Ch] (plaintext): added.
+
+ * insetcite.[Ch]: fix plaintext export.
+
2004-08-14 Lars Gullik Bjonnes <larsbj@lyx.org>
* insettext.[Ch] (setDrawFrame): take a bool, get rid of the
#include "frontends/font_metrics.h"
#include "support/lstrings.h"
+#include "support/std_ostream.h"
#include "support/tostr.h"
using lyx::support::prefixIs;
using std::max;
using std::string;
using std::auto_ptr;
-
+using std::ostream;
int InsetBibitem::key_counter = 0;
string const key_prefix = "key-";
return getContents() + " [" + getBibLabel() + ']';
}
+int InsetBibitem::plaintext(Buffer const &, ostream & os,
+ OutputParams const &) const
+{
+ os << '[' << getCounter() << "] ";
+ return 0;
+}
// ale070405 This function maybe shouldn't be here. We'll fix this at 0.13.
int bibitemMaxWidth(BufferView * bv, LyXFont const &)
#include "insetcommand.h"
-class Buffer;
-
/** Used to insert bibitem's information (key and label)
Must be automatically inserted as the first object in a
int getCounter() const { return counter; }
///
std::string const getBibLabel() const;
+ ///
+ int plaintext(Buffer const &, std::ostream &,
+ OutputParams const &) const;
protected:
///
virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
}
-int InsetCitation::plaintext(Buffer const & buffer, ostream & os, int) const
+int InsetCitation::plaintext(Buffer const & buffer, ostream & os, OutputParams const &) const
{
if (cache.params == params() &&
cache.engine == biblio::getEngine(buffer))
///
InsetOld::Code lyxCode() const { return InsetOld::CITE_CODE; }
///
- int plaintext(Buffer const &, std::ostream &, int linelen) const;
+ int plaintext(Buffer const &, std::ostream &, OutputParams const &) const;
///
int latex(Buffer const &, std::ostream &,
OutputParams const &) const;
{
os << "\n";
if (orgfont.family() != family()) {
- os << "\\family " << LyXFamilyNames[family()] << " \n";
+ os << "\\family " << LyXFamilyNames[family()] << "\n";
}
if (orgfont.series() != series()) {
- os << "\\series " << LyXSeriesNames[series()] << " \n";
+ os << "\\series " << LyXSeriesNames[series()] << "\n";
}
if (orgfont.shape() != shape()) {
- os << "\\shape " << LyXShapeNames[shape()] << " \n";
+ os << "\\shape " << LyXShapeNames[shape()] << "\n";
}
if (orgfont.size() != size()) {
- os << "\\size " << LyXSizeNames[size()] << " \n";
+ os << "\\size " << LyXSizeNames[size()] << "\n";
}
if (orgfont.emph() != emph()) {
- os << "\\emph " << LyXMiscNames[emph()] << " \n";
+ os << "\\emph " << LyXMiscNames[emph()] << "\n";
}
if (orgfont.number() != number()) {
- os << "\\numeric " << LyXMiscNames[number()] << " \n";
+ os << "\\numeric " << LyXMiscNames[number()] << "\n";
}
if (orgfont.underbar() != underbar()) {
// This is only for backwards compatibility
switch (underbar()) {
- case OFF: os << "\\bar no \n"; break;
- case ON: os << "\\bar under \n"; break;
+ case OFF: os << "\\bar no\n"; break;
+ case ON: os << "\\bar under\n"; break;
case TOGGLE: lyxerr << "LyXFont::lyxWriteFontChanges: "
"TOGGLE should not appear here!"
<< endl;
break;
- case INHERIT: os << "\\bar default \n"; break;
+ case INHERIT: os << "\\bar default\n"; break;
case IGNORE: lyxerr << "LyXFont::lyxWriteFontChanges: "
"IGNORE should not appear here!"
<< endl;
}
}
if (orgfont.noun() != noun()) {
- os << "\\noun " << LyXMiscNames[noun()] << " \n";
+ os << "\\noun " << LyXMiscNames[noun()] << "\n";
}
if (orgfont.color() != color()) {
// To make us file compatible with older
{
int ltype = 0;
Paragraph::depth_type ltype_depth = 0;
- bool ref_printed = false;
+ static bool ref_printed = false;
Paragraph::depth_type depth = par.params().depth();
// First write the layout
{
static Change current_change;
- bool the_end_read = false;
Paragraph::depth_type depth = 0;
while (lex.isOK()) {
continue;
if (token == "\\end_inset") {
- the_end_read = true;
break;
}
if (token == "\\end_document") {
-#ifdef WITH_WARNINGS
-#warning Look here!
-#endif
-#if 0
- lex.printError("\\end_document read in inset! Error in document!");
-#endif
return false;
}
}
}
- return the_end_read;
+ return true;
}