mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-12 16:50:39 +00:00
streamline NEWS file (like in trunk)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_5_X@25517 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
a12ced96f5
commit
a229ba95df
@ -22,6 +22,8 @@
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@ -29,6 +31,8 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
using boost::regex;
|
||||
using boost::smatch;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
@ -237,7 +241,8 @@ string const scale_as_percentage(string const & scale)
|
||||
}
|
||||
|
||||
|
||||
void handle_package(string const & name, string const & opts)
|
||||
void handle_package(string const & name, string const & opts,
|
||||
bool in_lyx_preamble)
|
||||
{
|
||||
vector<string> options = split_options(opts);
|
||||
add_package(name, options);
|
||||
@ -378,13 +383,16 @@ void handle_package(string const & name, string const & opts)
|
||||
}
|
||||
else if (name == "jurabib")
|
||||
h_cite_engine = "jurabib";
|
||||
|
||||
else if (options.empty())
|
||||
h_preamble << "\\usepackage{" << name << "}\n";
|
||||
else {
|
||||
h_preamble << "\\usepackage[" << opts << "]{" << name << "}\n";
|
||||
options.clear();
|
||||
else if (!in_lyx_preamble) {
|
||||
if (options.empty())
|
||||
h_preamble << "\\usepackage{" << name << "}\n";
|
||||
else {
|
||||
h_preamble << "\\usepackage[" << opts << "]{"
|
||||
<< name << "}\n";
|
||||
options.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// We need to do something with the options...
|
||||
if (!options.empty())
|
||||
cerr << "Ignoring options '" << join(options, ",")
|
||||
@ -446,6 +454,8 @@ TextClass const parse_preamble(Parser & p, ostream & os, string const & forcecla
|
||||
// initialize fixed types
|
||||
special_columns['D'] = 3;
|
||||
bool is_full_document = false;
|
||||
bool is_lyx_file = false;
|
||||
bool in_lyx_preamble = true;
|
||||
|
||||
// determine whether this is a full document or a fragment for inclusion
|
||||
while (p.good()) {
|
||||
@ -468,35 +478,57 @@ TextClass const parse_preamble(Parser & p, ostream & os, string const & forcecla
|
||||
//
|
||||
// cat codes
|
||||
//
|
||||
if (t.cat() == catLetter ||
|
||||
t.cat() == catSuper ||
|
||||
t.cat() == catSub ||
|
||||
t.cat() == catOther ||
|
||||
t.cat() == catMath ||
|
||||
t.cat() == catActive ||
|
||||
t.cat() == catBegin ||
|
||||
t.cat() == catEnd ||
|
||||
t.cat() == catAlign ||
|
||||
t.cat() == catParameter)
|
||||
h_preamble << t.character();
|
||||
if (!in_lyx_preamble &&
|
||||
(t.cat() == catLetter ||
|
||||
t.cat() == catSuper ||
|
||||
t.cat() == catSub ||
|
||||
t.cat() == catOther ||
|
||||
t.cat() == catMath ||
|
||||
t.cat() == catActive ||
|
||||
t.cat() == catBegin ||
|
||||
t.cat() == catEnd ||
|
||||
t.cat() == catAlign ||
|
||||
t.cat() == catParameter))
|
||||
h_preamble << t.character();
|
||||
|
||||
else if (t.cat() == catSpace || t.cat() == catNewline)
|
||||
else if (!in_lyx_preamble &&
|
||||
(t.cat() == catSpace || t.cat() == catNewline))
|
||||
h_preamble << t.asInput();
|
||||
|
||||
else if (t.cat() == catComment)
|
||||
h_preamble << t.asInput();
|
||||
else if (t.cat() == catComment) {
|
||||
// regex to parse comments
|
||||
static regex const islyxfile("%% LyX .* created this file");
|
||||
static regex const usercommands("User specified LaTeX commands");
|
||||
|
||||
string const comment = t.asInput();
|
||||
cerr << "Seen comment: " << comment << std::endl;
|
||||
smatch sub;
|
||||
if (regex_search(comment, sub, islyxfile))
|
||||
is_lyx_file = true;
|
||||
else if (is_lyx_file
|
||||
&& regex_search(comment, sub, usercommands))
|
||||
in_lyx_preamble = false;
|
||||
else if (!in_lyx_preamble)
|
||||
h_preamble << t.asInput();
|
||||
cerr << "lyx_file: " << is_lyx_file << ", lyx_preamble "
|
||||
<< in_lyx_preamble << std::endl;
|
||||
}
|
||||
|
||||
else if (t.cs() == "pagestyle")
|
||||
h_paperpagestyle = p.verbatim_item();
|
||||
|
||||
else if (t.cs() == "makeatletter") {
|
||||
if (!is_lyx_file || !in_lyx_preamble
|
||||
|| p.getCatCode('@') != catLetter)
|
||||
h_preamble << "\\makeatletter";
|
||||
p.setCatCode('@', catLetter);
|
||||
h_preamble << "\\makeatletter";
|
||||
}
|
||||
|
||||
|
||||
else if (t.cs() == "makeatother") {
|
||||
if (!is_lyx_file || !in_lyx_preamble
|
||||
|| p.getCatCode('@') != catOther)
|
||||
h_preamble << "\\makeatother";
|
||||
p.setCatCode('@', catOther);
|
||||
h_preamble << "\\makeatother";
|
||||
}
|
||||
|
||||
else if (t.cs() == "newcommand" || t.cs() == "renewcommand"
|
||||
@ -529,19 +561,7 @@ TextClass const parse_preamble(Parser & p, ostream & os, string const & forcecla
|
||||
h_font_default_family = family.erase(0,1);
|
||||
}
|
||||
// only non-lyxspecific stuff
|
||||
if ( name != "\\noun"
|
||||
&& name != "\\tabularnewline"
|
||||
&& name != "\\LyX"
|
||||
&& name != "\\lyxline"
|
||||
&& name != "\\lyxaddress"
|
||||
&& name != "\\lyxrightaddress"
|
||||
&& name != "\\lyxdot"
|
||||
&& name != "\\boldsymbol"
|
||||
&& name != "\\lyxarrow"
|
||||
&& name != "\\rmdefault"
|
||||
&& name != "\\sfdefault"
|
||||
&& name != "\\ttdefault"
|
||||
&& name != "\\familydefault") {
|
||||
if (!in_lyx_preamble) {
|
||||
ostringstream ss;
|
||||
ss << '\\' << t.cs();
|
||||
if (star)
|
||||
@ -624,9 +644,10 @@ TextClass const parse_preamble(Parser & p, ostream & os, string const & forcecla
|
||||
vector<string>::const_iterator it = vecnames.begin();
|
||||
vector<string>::const_iterator end = vecnames.end();
|
||||
for (; it != end; ++it)
|
||||
handle_package(trim(*it), string());
|
||||
handle_package(trim(*it), string(),
|
||||
in_lyx_preamble);
|
||||
} else {
|
||||
handle_package(name, options);
|
||||
handle_package(name, options, in_lyx_preamble);
|
||||
}
|
||||
}
|
||||
|
||||
@ -638,9 +659,7 @@ TextClass const parse_preamble(Parser & p, ostream & os, string const & forcecla
|
||||
ss << p.getOpt();
|
||||
ss << '{' << p.verbatim_item() << '}';
|
||||
ss << '{' << p.verbatim_item() << '}';
|
||||
if (name != "lyxcode" && name != "lyxlist" &&
|
||||
name != "lyxrightadress" &&
|
||||
name != "lyxaddress" && name != "lyxgreyedout")
|
||||
if (!in_lyx_preamble)
|
||||
h_preamble << ss.str();
|
||||
}
|
||||
|
||||
@ -648,8 +667,9 @@ TextClass const parse_preamble(Parser & p, ostream & os, string const & forcecla
|
||||
string name = p.get_token().cs();
|
||||
while (p.next_token().cat() != catBegin)
|
||||
name += p.get_token().asString();
|
||||
h_preamble << "\\def\\" << name << '{'
|
||||
<< p.verbatim_item() << "}";
|
||||
if (!in_lyx_preamble)
|
||||
h_preamble << "\\def\\" << name << '{'
|
||||
<< p.verbatim_item() << "}";
|
||||
}
|
||||
|
||||
else if (t.cs() == "newcolumntype") {
|
||||
@ -726,7 +746,7 @@ TextClass const parse_preamble(Parser & p, ostream & os, string const & forcecla
|
||||
}
|
||||
}
|
||||
|
||||
else if (!t.cs().empty())
|
||||
else if (!t.cs().empty() && !in_lyx_preamble)
|
||||
h_preamble << '\\' << t.cs();
|
||||
}
|
||||
p.skip_spaces();
|
||||
|
Loading…
Reference in New Issue
Block a user