Factor out tex2lyx warnings and add -q option (#11328)

This commit is contained in:
Juergen Spitzmueller 2022-12-28 16:29:38 +01:00
parent 9047d60c5a
commit 9ecc30174a
10 changed files with 212 additions and 219 deletions

View File

@ -98,8 +98,8 @@ Context::Context(bool need_layout_,
Context::~Context()
{
if (!par_extra_stuff.empty())
cerr << "Bug: Ignoring par-level extra stuff '"
<< par_extra_stuff << '\'' << endl;
warning_message("Bug: Ignoring par-level extra stuff '"
+ par_extra_stuff + '\'');
}

View File

@ -12,6 +12,8 @@
#include "Parser.h"
#include "tex2lyx.h"
#include "Encoding.h"
#include "support/lstrings.h"
#include "support/textutils.h"
@ -142,7 +144,7 @@ iparserdocstream & iparserdocstream::get(char_type &c)
if (s_.empty())
is_.get(c);
else {
//cerr << "unparsed: " << to_utf8(s_) <<endl;
//warning_message("unparsed: " + to_utf8(s_));
c = s_[0];
s_.erase(0,1);
}
@ -206,7 +208,7 @@ bool Parser::setEncoding(std::string const & e, int p)
// instead. Therefore, we cannot misparse high bytes as {, } or \\.
Encoding const * const enc = encodings.fromLaTeXName(e, p, true);
if (!enc) {
cerr << "Unknown encoding " << e << ". Ignoring." << std::endl;
warning_message("Unknown encoding " + e + ". Ignoring.");
return false;
}
return setEncoding(enc->iconvName());
@ -268,7 +270,7 @@ void Parser::setCatcodes(cat_type t)
bool Parser::setEncoding(std::string const & e)
{
//cerr << "setting encoding to " << e << std::endl;
//warning_message("setting encoding to " + e);
encoding_iconv_ = e;
// If the encoding is fixed, we must not change the stream encoding
// (because the whole input uses that encoding, e.g. if it comes from
@ -341,8 +343,8 @@ Token const Parser::get_token()
if (pos_ >= tokens_.size())
return dummy;
}
// cerr << "looking at token " << tokens_[pos_]
// << " pos: " << pos_ << '\n';
// warning_message("looking at token " + tokens_[pos_]
// + " pos: " + pos_ <<);
return tokens_[pos_++];
}
@ -387,8 +389,7 @@ bool Parser::skip_spaces(bool skip_comments)
// If positions_ is not empty we are doing some kind
// of look ahead
if (!positions_.empty())
cerr << " Ignoring comment: "
<< curr_token().asInput();
warning_message("Ignoring comment: " + curr_token().asInput());
} else {
putback();
break;
@ -409,8 +410,7 @@ void Parser::unskip_spaces(bool skip_comments)
// If positions_ is not empty we are doing some kind
// of look ahead
if (!positions_.empty())
cerr << "Unignoring comment: "
<< curr_token().asInput();
warning_message("Unignoring comment: " + curr_token().asInput());
putback();
}
else
@ -555,7 +555,7 @@ Parser::Arg Parser::getFullArg(char left, char right, bool allow_escaping, char
// Ignore comments
if (t.cat() == catComment) {
if (!t.cs().empty())
cerr << "Ignoring comment: " << t.asInput();
warning_message("Ignoring comment: " + t.asInput());
continue;
}
if (allow_escaping) {
@ -657,14 +657,14 @@ string const Parser::ertEnvironment(string const & name)
} else if (t.asInput() == "\\end") {
string const end = getArg('{', '}');
if (end != name)
cerr << "\\end{" << end
<< "} does not match \\begin{" << name
<< "}." << endl;
warning_message("\\end{" + end
+ "} does not match \\begin{"
+ name + "}.");
return os.str();
} else
os << t.asInput();
}
cerr << "unexpected end of input" << endl;
warning_message("unexpected end of input");
return os.str();
}
@ -685,7 +685,7 @@ string const Parser::plainEnvironment(string const & name)
} else
os << t.asInput();
}
cerr << "unexpected end of input" << endl;
warning_message("unexpected end of input");
return os.str();
}
@ -697,7 +697,7 @@ string const Parser::plainCommand(char left, char right, string const & name)
// check if first token is really the start character
Token tok = get_token();
if (tok.character() != left) {
cerr << "first character does not match start character of command \\" << name << endl;
warning_message("first character does not match start character of command \\" + name);
return string();
}
ostringstream os;
@ -707,7 +707,7 @@ string const Parser::plainCommand(char left, char right, string const & name)
} else
os << t.asInput();
}
cerr << "unexpected end of input" << endl;
warning_message("unexpected end of input");
return os.str();
}
@ -751,7 +751,7 @@ Parser::Arg Parser::verbatimStuff(string const & end_string, bool const allow_li
break;
} else {
if (!allow_linebreak && t.asInput() == "\n") {
cerr << "unexpected end of input" << endl;
warning_message("unexpected end of input");
popPosition();
setCatcodes(NORMAL_CATCODES);
return Arg(false, string());
@ -766,7 +766,7 @@ Parser::Arg Parser::verbatimStuff(string const & end_string, bool const allow_li
}
if (!good()) {
cerr << "unexpected end of input" << endl;
warning_message("unexpected end of input");
popPosition();
setCatcodes(NORMAL_CATCODES);
return Arg(false, string());
@ -895,14 +895,14 @@ void Parser::tokenize_one()
}
case catIgnore: {
cerr << "ignoring a char: " << static_cast<uint32_t>(c) << "\n";
warning_message("ignoring a char: " + static_cast<uint32_t>(c));
break;
}
default:
push_back(Token(docstring(1, c), catcode(c)));
}
//cerr << tokens_.back();
//warning_message(tokens_.back());
}

View File

@ -1696,8 +1696,7 @@ void Preamble::handle_package(Parser &p, string const & name,
encoding, Encoding::inputenc, true);
if (!enc) {
if (!detectEncoding)
cerr << "Unknown encoding " << encoding
<< ". Ignoring." << std::endl;
warning_message("Unknown encoding " + encoding + ". Ignoring.");
} else {
if (!enc->unsafe() && options.size() == 1 && one_language == true) {
h_inputencoding = enc->name();
@ -1833,8 +1832,7 @@ void Preamble::handle_package(Parser &p, string const & name,
|| opt == "subsection")
h_multibib = opt;
else
cerr << "Ignoring unknown refsection value '"
<< opt << "'.";
warning_message("Ignoring unknown refsection value '" + opt + "'.");
}
opt = process_keyval_opt(options, "bibencoding");
if (!opt.empty())
@ -1908,8 +1906,8 @@ void Preamble::handle_package(Parser &p, string const & name,
// We need to do something with the options...
if (!options.empty() && !detectEncoding)
cerr << "Ignoring options '" << join(options, ",")
<< "' of package " << name << '.' << endl;
warning_message("Ignoring options '" + join(options, ",")
+ "' of package " + name + '.');
// remove the whitespace
p.skip_spaces();
@ -2236,7 +2234,7 @@ void Preamble::parse(Parser & p, string const & forceclass,
&& comment.substr(0, magicXeLaTeX.size()) == magicXeLaTeX
&& h_inputencoding == "auto-legacy") {
if (!detectEncoding)
cerr << "XeLaTeX comment found, switching to UTF8\n";
warning_message("XeLaTeX comment found, switching to UTF8");
h_inputencoding = "utf8";
}
smatch sub;
@ -2829,8 +2827,7 @@ void Preamble::parse(Parser & p, string const & forceclass,
encoding, Encoding::inputenc, true);
if (!enc) {
if (!detectEncoding)
cerr << "Unknown encoding " << encoding
<< ". Ignoring." << std::endl;
warning_message("Unknown encoding " + encoding + ". Ignoring.");
} else {
if (!enc->unsafe())
h_inputencoding = enc->name();
@ -3064,8 +3061,8 @@ void Preamble::parse(Parser & p, string const & forceclass,
if (makeAbsPath(filename, path).exists())
fix_child_filename(filename);
else
cerr << "Warning: Could not find included file '"
<< filename << "'." << endl;
warning_message("Warning: Could not find included file '"
+ filename + "'.");
outname = changeExtension(filename, "lyx");
h_includeonlys.push_back(outname);
}

View File

@ -18,6 +18,7 @@
#include <config.h>
#include "tex2lyx.h"
#include "LaTeXFeatures.h"
#include "LyXRC.h"
#include "output_xhtml.h"
@ -40,7 +41,7 @@ namespace frontend {
namespace Alert {
void warning(docstring const & title, docstring const & message, bool)
{
cerr << to_utf8(title) << "\n" << to_utf8(message) << endl;
warning_message(to_utf8(title) + "\n" + to_utf8(message));
}
} // namespace Alert
} // namespace frontend

View File

@ -227,8 +227,7 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
else if (t.cs() == "cr") {
// lyx can't handle \\cr
cerr << "Warning: Converting TeX '\\cr' to LaTeX '\\\\'."
<< endl;
warning_message("Converting TeX '\\cr' to LaTeX '\\\\'.");
os << "\\\\";
}

View File

@ -346,9 +346,8 @@ void handle_colalign(Parser & p, vector<ColInfo> & colinfo,
ColInfo const & start)
{
if (p.get_token().cat() != catBegin)
cerr << "Wrong syntax for table column alignment.\n"
"Expected '{', got '" << p.curr_token().asInput()
<< "'.\n";
warning_message("Wrong syntax for table column alignment.\n"
"Expected '{', got '" + p.curr_token().asInput()+ "'");
ColInfo next = start;
for (Token t = p.get_token(); p.good() && t.cat() != catEnd;
@ -363,7 +362,7 @@ void handle_colalign(Parser & p, vector<ColInfo> & colinfo,
// "%\n" combination
p.skip_spaces();
} else
cerr << "Ignoring comment: " << t.asInput();
warning_message("Ignoring comment: " + t.asInput());
continue;
}
@ -472,8 +471,7 @@ void handle_colalign(Parser & p, vector<ColInfo> & colinfo,
string const s = trimSpaceAndEol(p.verbatim_item());
if (colinfo.empty())
// This is not possible in LaTeX.
cerr << "Ignoring separator '<{"
<< s << "}'." << endl;
warning_message("Ignoring separator '<{" + s + "}'.");
else {
ColInfo & ci = colinfo.back();
ci2special(ci);
@ -497,9 +495,8 @@ void handle_colalign(Parser & p, vector<ColInfo> & colinfo,
handle_colalign(p2, colinfo, next);
next = ColInfo();
} else {
cerr << "Ignoring column specification"
" '*{" << num << "}{"
<< arg << "}'." << endl;
warning_message("Ignoring column specification"
" '*{" + num + "}{" + arg + "}'.");
}
break;
}
@ -734,13 +731,12 @@ void parse_table(Parser & p, ostream & os, bool is_long_tabular,
t.cs() == "\\" ||
t.cs() == "cr") {
if (t.cs() == "cr")
cerr << "Warning: Converting TeX "
"'\\cr' to LaTeX '\\\\'."
<< endl;
warning_message("Warning: Converting TeX "
"'\\cr' to LaTeX '\\\\'.");
// stuff before the line break
os << comments << HLINE << hlines << HLINE
<< LINE;
//cerr << "hlines: " << hlines << endl;
//warning_message("hlines: " + hlines);
hlines.erase();
comments.erase();
pos = ROW_START;
@ -798,8 +794,7 @@ void parse_table(Parser & p, ostream & os, bool is_long_tabular,
if (support::contains(hlines, "\\hline") ||
support::contains(hlines, "\\cline") ||
support::contains(hlines, "\\newpage"))
cerr << "Ignoring '" << hlines
<< "' in a cell" << endl;
warning_message("Ignoring '" + hlines + "' in a cell");
else
os << hlines;
hlines.erase();
@ -853,7 +848,7 @@ void parse_table(Parser & p, ostream & os, bool is_long_tabular,
else if (t.cat() == catEnd) {
if (flags & FLAG_BRACE_LAST)
return;
cerr << "unexpected '}'\n";
warning_message("unexpected '}'");
}
else if (t.cat() == catAlign) {
@ -912,8 +907,7 @@ void parse_table(Parser & p, ostream & os, bool is_long_tabular,
// We can have hline stuff if the last line is incomplete
if (!hlines.empty()) {
// this does not work in LaTeX, so we ignore it
cerr << "Ignoring '" << hlines << "' at end of tabular"
<< endl;
warning_message("Ignoring '" + hlines + "' at end of tabular");
}
}
@ -1013,8 +1007,8 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
else if (posopts == "[b]")
tabularvalignment = "bottom";
else
cerr << "vertical tabular positioning '"
<< posopts << "' ignored\n";
warning_message("vertical tabular positioning '"
+ posopts + "' ignored");
}
vector<ColInfo> colinfo;
@ -1040,7 +1034,7 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
ltType endlastfoot;
// split into rows
//cerr << "// split into rows\n";
//warning_message("// split into rows");
for (size_t row = 0; row < rowinfo.size();) {
// init row
@ -1049,7 +1043,7 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
// split row
vector<string> dummy;
//cerr << "\n########### LINE: " << lines[row] << "########\n";
//warning_message("########### LINE: " << lines[row] << "########");
split(lines[row], dummy, HLINE);
// handle horizontal line fragments
@ -1057,22 +1051,22 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
if (dummy.size() != 3) {
if ((dummy.size() != 1 && dummy.size() != 2) ||
row != rowinfo.size() - 1)
cerr << "unexpected dummy size: " << dummy.size()
<< " content: " << lines[row] << "\n";
warning_message("unexpected dummy size: " + convert<string>(dummy.size())
+ " content: " + lines[row]);
dummy.resize(3);
}
lines[row] = dummy[1];
//cerr << "line: " << row << " above 0: " << dummy[0] << "\n";
//cerr << "line: " << row << " below 2: " << dummy[2] << "\n";
//cerr << "line: " << row << " cells 1: " << dummy[1] << "\n";
//warning_message("line: " + row + " above 0: " + dummy[0]);
//warning_message("line: " + row + " below 2: " + dummy[2]);
//warning_message("line: " + row + " cells 1: " + dummy[1]);
for (int i = 0; i <= 2; i += 2) {
//cerr << " reading from line string '" << dummy[i] << "'\n";
//warning_message(" reading from line string '" + dummy[i]);
Parser p1(dummy[size_type(i)]);
while (p1.good()) {
Token t = p1.get_token();
//cerr << "read token: " << t << "\n";
//warning_message("read token: " + t);
if (t.cs() == "hline" || t.cs() == "toprule" ||
t.cs() == "midrule" ||
t.cs() == "bottomrule") {
@ -1083,15 +1077,14 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
if (row > 0) // extra bottomline above
handle_hline_below(rowinfo[row - 1], cellinfo[row - 1]);
else
cerr << "dropping extra "
<< t.cs() << '\n';
//cerr << "below row: " << row-1 << endl;
warning_message("dropping extra " + t.cs());
//warning_message("below row: " + row-1);
} else {
handle_hline_above(rowinfo[row], cellinfo[row]);
//cerr << "above row: " << row << endl;
//warning_message("above row: " + row);
}
} else {
//cerr << "below row: " << row << endl;
//warning_message("below row: " + row);
handle_hline_below(rowinfo[row], cellinfo[row]);
}
} else if (t.cs() == "cline" || t.cs() == "cmidrule") {
@ -1101,40 +1094,34 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
trim = p1.getFullParentheseArg();
}
string arg = p1.verbatim_item();
//cerr << "read " << t.cs() << " arg: '" << arg << "', trim: '" << trim << "'\n";
//warning_message("read " + t.cs() + " arg: '" + arg + "', trim: '" + trim);
vector<string> cols;
split(arg, cols, '-');
cols.resize(2);
size_t from = convert<unsigned int>(cols[0]);
if (from == 0)
cerr << "Could not parse "
<< t.cs() << " start column."
<< endl;
warning_message("Could not parse " + t.cs() + " start column.");
else
// 1 based index -> 0 based
--from;
if (from >= colinfo.size()) {
cerr << t.cs() << " starts at "
"non existing column "
<< (from + 1) << endl;
warning_message(t.cs() + " starts at "
"non existing column " + convert<string>(from + 1));
from = colinfo.size() - 1;
}
size_t to = convert<unsigned int>(cols[1]);
if (to == 0)
cerr << "Could not parse "
<< t.cs() << " end column."
<< endl;
warning_message("Could not parse " + t.cs() + " end column.");
else
// 1 based index -> 0 based
--to;
if (to >= colinfo.size()) {
cerr << t.cs() << " ends at "
"non existing column "
<< (to + 1) << endl;
warning_message(t.cs() + " ends at non existing column "
+ convert<string>(to + 1));
to = colinfo.size() - 1;
}
for (size_t col = from; col <= to; ++col) {
//cerr << "row: " << row << " col: " << col << " i: " << i << endl;
//warning_message("row: " + row + " col: " + col + " i: " + i);
if (i == 0) {
rowinfo[row].topline = true;
cellinfo[row][col].topline = true;
@ -1233,14 +1220,13 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
rowinfo[row - 1].newpage = true;
else
// This does not work in LaTeX
cerr << "Ignoring "
"'\\newpage' "
"before rows."
<< endl;
warning_message("Ignoring "
"'\\newpage' "
"before rows.");
} else
rowinfo[row].newpage = true;
} else {
cerr << "unexpected line token: " << t << endl;
warning_message("unexpected line token: " + t.cs());
}
}
}
@ -1292,11 +1278,10 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
split(lines[row], cells, TAB);
for (size_t col = 0, cell = 0; cell < cells.size();
++col, ++cell) {
//cerr << "cell content: '" << cells[cell] << "'\n";
//warning_message("cell content: '" + cells[cell]);
if (col >= colinfo.size()) {
// This does not work in LaTeX
cerr << "Ignoring extra cell '"
<< cells[cell] << "'." << endl;
warning_message("Ignoring extra cell '" + cells[cell] + "'.");
continue;
}
string cellcont = cells[cell];
@ -1312,8 +1297,8 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
if (parse.hasOpt()) {
string const vpos = parse.getArg('[', ']');
parse.skip_spaces(true);
cerr << "Ignoring multirow's vpos arg '"
<< vpos << "'!" << endl;
warning_message("Ignoring multirow's vpos arg '"
+ vpos + "'!");
}
// how many cells?
parse.get_token();
@ -1323,8 +1308,8 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
if (parse.hasOpt()) {
string const bs = parse.getArg('[', ']');
parse.skip_spaces(true);
cerr << "Ignoring multirow's bigstrut arg '"
<< bs << "'!" << endl;
warning_message("Ignoring multirow's bigstrut arg '"
+ bs + "'!");
}
// the width argument
string const width = parse.getArg('{', '}');
@ -1354,11 +1339,10 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
// This may or may not work in LaTeX,
// but it does not work in LyX.
// FIXME: Handle it correctly!
cerr << "Moving cell content '"
<< cells[cell]
<< "' into a multirow cell. "
"This will probably not work."
<< endl;
warning_message("Moving cell content '"
+ cells[cell]
+ "' into a multirow cell. "
"This will probably not work.");
}
cellinfo[row][col].content += os2.str();
} else if (parse.next_token().cs() == "multicolumn") {
@ -1395,11 +1379,10 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
// This may or may not work in LaTeX,
// but it does not work in LyX.
// FIXME: Handle it correctly!
cerr << "Moving cell content '"
<< cells[cell]
<< "' into a multicolumn cell. "
"This will probably not work."
<< endl;
warning_message("Moving cell content '"
+ cells[cell]
+ "' into a multicolumn cell. "
"This will probably not work.");
}
cellinfo[row][col].content += os2.str();
@ -1407,15 +1390,14 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
for (size_t i = 0; i < ncells - 1; ++i) {
++col;
if (col >= colinfo.size()) {
cerr << "The cell '"
<< cells[cell]
<< "' specifies "
<< convert<string>(ncells)
<< " columns while the table has only "
<< convert<string>(colinfo.size())
<< " columns!"
<< " Therefore the surplus columns will be ignored."
<< endl;
warning_message("The cell '"
+ cells[cell]
+ "' specifies "
+ convert<string>(ncells)
+ " columns while the table has only "
+ convert<string>(colinfo.size())
+ " columns!"
+ " Therefore the surplus columns will be ignored.");
break;
}
cellinfo[row][col].multi = CELL_PART_OF_MULTICOLUMN;
@ -1436,11 +1418,10 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
rowinfo[row].caption = true;
for (size_t c = 1; c < cells.size(); ++c) {
if (!cells[c].empty()) {
cerr << "Moving cell content '"
<< cells[c]
<< "' into the caption cell. "
"This will probably not work."
<< endl;
warning_message("Moving cell content '"
+ cells[c]
+ "' into the caption cell. "
"This will probably not work.");
cells[0] += cells[c];
}
}
@ -1467,11 +1448,10 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
rowinfo[row].caption = true;
for (size_t c = 1; c < cells.size(); ++c) {
if (!cells[c].empty()) {
cerr << "Moving cell content '"
<< cells[c]
<< "' into the caption cell. "
"This will probably not work."
<< endl;
warning_message("Moving cell content '"
+ cells[c]
+ "' into the caption cell. "
"This will probably not work.");
cells[0] += cells[c];
}
}
@ -1496,10 +1476,10 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
}
}
//cerr << "// handle almost empty last row what we have\n";
//warning_message("// handle almost empty last row what we have");
// handle almost empty last row
if (row && lines[row].empty() && row + 1 == rowinfo.size()) {
//cerr << "remove empty last line\n";
//warning_message("remove empty last line");
if (rowinfo[row].topline)
rowinfo[row - 1].bottomline = true;
for (size_t col = 0; col < colinfo.size(); ++col)
@ -1584,7 +1564,7 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
else if (name == "tabularx")
preamble.registerAutomaticallyLoadedPackage("tabularx");
//cerr << "// output what we have\n";
//warning_message("output what we have");
// output what we have
size_type cols = colinfo.size();
for (auto const & col : colinfo) {
@ -1615,7 +1595,7 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
os << write_attribute("tabularwidth", tabularwidth) << ">\n";
//cerr << "// after header\n";
//warning_message("after header");
for (auto const & col : colinfo) {
if (col.decimal_point != '\0' && col.align != 'd')
continue;
@ -1630,7 +1610,7 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
<< write_attribute("varwidth", col.varwidth)
<< ">\n";
}
//cerr << "// after cols\n";
//warning_message("after cols");
for (size_t row = 0; row < rowinfo.size(); ++row) {
os << "<row"
@ -1675,11 +1655,11 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
<< write_attribute("rightline", cell.rightlines > 0)
<< write_attribute("rotate", cell.rotate)
<< write_attribute("mroffset", cell.mroffset);
//cerr << "\nrow: " << row << " col: " << col;
//warning_message("\nrow: " + row + " col: " + col);
//if (cell.topline)
// cerr << " topline=\"true\"";
// warning_message(" topline=\"true\"");
//if (cell.bottomline)
// cerr << " bottomline=\"true\"";
// warning_message(" bottomline=\"true\"");
os << " usebox=\"none\""
<< write_attribute("width", translate_len(cell.width));
if (cell.multi != CELL_NORMAL)

View File

@ -64,6 +64,9 @@ changing commands in the input.
Specify the encoding using the LaTeX name as defined in the encodings file.
\fBtex2lyx\fR will ignore any encoding changing commands in the input.
.TP
.BI \-q
Quite mode. \fBtex2lyx\fR will not output any warning messages.
.TP
.BI \-n
Noweb. Translate a noweb (aka literate programming) file. This should be
(almost?) equivalent to running \*[lq]noweb2lyx foo.tex foo.lyx\*[rq]. This option

View File

@ -57,12 +57,12 @@ string const trimSpaceAndEol(string const & a)
void split(string const & s, vector<string> & result, char delim)
{
//cerr << "split 1: '" << s << "'\n";
//warning_message("split 1: '" + s + "'");
istringstream is(s);
string t;
while (getline(is, t, delim))
result.push_back(t);
//cerr << "split 2\n";
//warning_message("split 2");
}
@ -215,12 +215,12 @@ bool addModule(string const & module, LayoutFile const & baseClass, LayoutModule
vector<string>::const_iterator const vb = visited.begin();
vector<string>::const_iterator const ve = visited.end();
if (find(vb, ve, module) != ve) {
cerr << "Circular dependency detected for module " << module << '\n';
warning_message("Circular dependency detected for module " + module);
return false;
}
LyXModule const * const lm = theModuleList[module];
if (!lm) {
cerr << "Could not find module " << module << " in module list.\n";
warning_message("Could not find module " + module + " in module list.");
return false;
}
bool foundone = false;
@ -260,7 +260,7 @@ bool addModule(string const & module, LayoutFile const & baseClass, LayoutModule
}
}
if (!foundone) {
cerr << "Could not add required modules for " << module << ".\n";
warning_message("Could not add required modules for " + module + ".");
return false;
}
if (!m.moduleCanBeAdded(module, &baseClass))
@ -556,8 +556,8 @@ bool read_syntaxfile(FileName const & file_name)
{
ifdocstream is(file_name.toFilesystemEncoding().c_str());
if (!is.good()) {
cerr << "Could not open syntax file \"" << file_name
<< "\" for reading." << endl;
cerr << "Could not open syntax file \""
<< file_name << "\" for reading." << std::endl;
return false;
}
// We can use our TeX parser, since the syntax of the layout file is
@ -594,6 +594,7 @@ bool fixed_encoding = false;
string syntaxfile;
bool copy_files = false;
bool overwrite_files = false;
bool no_warnings = false;
bool skip_children = false;
int error_code = 0;
@ -650,10 +651,11 @@ int parse_help(string const &, string const &)
"\t-fixedenc encoding Like -e, but ignore encoding changing commands while parsing.\n"
"\t-f Force overwrite of .lyx files.\n"
"\t-help Print this message and quit.\n"
"\t-n translate literate programming (noweb, sweave,... ) file.\n"
"\t-n Translate literate programming (noweb, sweave,... ) file.\n"
"\t-q Omit warnings.\n"
"\t-roundtrip Re-export created .lyx file infile.lyx.lyx to infile.lyx.tex.\n"
"\t-skipchildren Do not translate included child documents.\n"
"\t-roundtrip re-export created .lyx file infile.lyx.lyx to infile.lyx.tex.\n"
"\t-s syntaxfile read additional syntax file.\n"
"\t-s syntaxfile Read additional syntax file.\n"
"\t-sysdir SYSDIR Set system directory to SYSDIR.\n"
"\t Default: " << package().system_support() << "\n"
"\t-userdir USERDIR Set user directory to USERDIR.\n"
@ -763,6 +765,13 @@ int parse_force(string const &, string const &)
}
int parse_quite(string const &, string const &)
{
no_warnings = true;
return 0;
}
int parse_noweb(string const &, string const &)
{
noweb_mode = true;
@ -811,6 +820,7 @@ void TeX2LyXApp::easyParse()
cmdmap["-skipchildren"] = parse_skipchildren;
cmdmap["-sysdir"] = parse_sysdir;
cmdmap["-userdir"] = parse_userdir;
cmdmap["-q"] = parse_quite;
cmdmap["-roundtrip"] = parse_roundtrip;
cmdmap["-copyfiles"] = parse_copyfiles;
@ -1053,15 +1063,14 @@ bool tex2lyx(string const & infilename, FileName const & outfilename,
}
if (outfilename.isReadableFile()) {
if (overwrite_files) {
cerr << "Overwriting existing file "
<< outfilename << endl;
warning_message("Overwriting existing file " + outfilename.absFileName());
} else {
cerr << "Not overwriting existing file "
<< outfilename << endl;
return false;
}
} else {
cerr << "Creating file " << outfilename << endl;
warning_message("Creating file " + outfilename.absFileName());
}
ofstream os(outfilename.toFilesystemEncoding().c_str());
if (!os.good()) {
@ -1103,6 +1112,13 @@ bool tex2tex(string const & infilename, FileName const & outfilename,
}
void warning_message(string const & message)
{
if (!no_warnings)
cerr << "tex2lyx warning: " << message << endl;
}
namespace {
int TeX2LyXApp::run()

View File

@ -215,6 +215,8 @@ bool tex2lyx(std::string const & infilename,
support::FileName const & outfilename,
std::string const & encoding);
/// A general warning message that can be silenced with -q
void warning_message(std::string const & message);
} // namespace lyx

View File

@ -1129,8 +1129,8 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
position = "t";
}
if (position != "t" && position != "c" && position != "b") {
cerr << "invalid position " << position << " for "
<< inner_type << endl;
warning_message("invalid position " + position
+ " for " + inner_type);
position = "c";
}
if (p.hasOpt()) {
@ -1143,8 +1143,9 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
hor_pos = opt;
if (hor_pos != "l" && hor_pos != "c" &&
hor_pos != "r" && hor_pos != "s") {
cerr << "invalid hor_pos " << hor_pos
<< " for " << inner_type << endl;
warning_message("invalid hor_pos "
+ hor_pos + " for "
+ inner_type);
hor_pos = "c";
}
}
@ -1154,9 +1155,9 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
inner_pos = p.getArg('[', ']');
if (inner_pos != "c" && inner_pos != "t" &&
inner_pos != "b" && inner_pos != "s") {
cerr << "invalid inner_pos "
<< inner_pos << " for "
<< inner_type << endl;
warning_message("invalid inner_pos "
+ inner_pos + " for "
+ inner_type);
inner_pos = position;
}
}
@ -1176,8 +1177,9 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
hor_pos = opt;
if (hor_pos != "l" && hor_pos != "c" &&
hor_pos != "r" && hor_pos != "s") {
cerr << "invalid hor_pos " << hor_pos
<< " for " << outer_type << endl;
warning_message("invalid hor_pos "
+ hor_pos + " for "
+ outer_type);
hor_pos = "c";
}
} else {
@ -1451,8 +1453,8 @@ void parse_outer_box(Parser & p, ostream & os, unsigned flags, bool outer,
if (p.next_token().cat() == catBegin)
p.get_token();
else
cerr << "Warning: Ignoring missing '{' after \\"
<< outer_type << '.' << endl;
warning_message("Ignoring missing '{' after \\"
+ outer_type + '.');
eat_whitespace(p, os, parent_context, false);
}
string inner;
@ -2808,24 +2810,24 @@ void copy_file(FileName const & src, string const & dstname)
return;
if (!dstpath.isDirectory()) {
if (!dstpath.createPath()) {
cerr << "Warning: Could not create directory for file `"
<< dst.absFileName() << "´." << endl;
warning_message("Could not create directory for file `"
+ dst.absFileName() + "´.");
return;
}
}
if (dst.isReadableFile()) {
if (overwriteFiles())
cerr << "Warning: Overwriting existing file `"
<< dst.absFileName() << "´." << endl;
warning_message("Overwriting existing file `"
+ dst.absFileName() + "´.");
else {
cerr << "Warning: Not overwriting existing file `"
<< dst.absFileName() << "´." << endl;
warning_message("Not overwriting existing file `"
+ dst.absFileName() + "´.");
return;
}
}
if (!src.copyTo(dst))
cerr << "Warning: Could not copy file `" << src.absFileName()
<< "´ to `" << dst.absFileName() << "´." << endl;
warning_message("Could not copy file `" + src.absFileName()
+ "´ to `" + dst.absFileName() + "´.");
}
@ -2860,7 +2862,7 @@ bool parse_chunk(Parser & p, ostream & os, Context & context)
p.putback();
p.deparse();
//cerr << "params=[" << params.second << "], code=[" << code.second << "]" <<endl;
//warning_message("params=[" + params.second + "], code=[" + code.second + "]");
// We must have a valid layout before outputting the Chunk inset.
context.check_layout(os);
Context chunkcontext(true, context.textclass);
@ -3261,7 +3263,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
}
if (t.cat() == catSuper || t.cat() == catSub) {
cerr << "catcode " << t << " illegal in text mode\n";
string const cc = (t.cat() == catSuper) ? "catSuper" : "catSub";
warning_message("catcode " + cc + " illegal in text mode");
continue;
}
@ -3363,8 +3366,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
if (p.next_token().character() == ']')
p.get_token();
else
cerr << "Warning: Inserting missing ']' in '"
<< s << "'." << endl;
warning_message("Inserting missing ']' in '" + s + "'.");
output_ert_inset(os, s, context);
continue;
}
@ -3556,7 +3558,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
if (flags & FLAG_BRACE_LAST) {
return;
}
cerr << "stray '}' in text\n";
warning_message("stray '}' in text");
output_ert_inset(os, "}", context);
continue;
}
@ -3598,8 +3600,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
// eat environment name
string const name = p.getArg('{', '}');
if (name != active_environment())
cerr << "\\end{" + name + "} does not match \\begin{"
+ active_environment() + "}\n";
warning_message("\\end{" + name + "} does not match \\begin{"
+ active_environment() + "}");
return;
}
p.error("found 'end' unexpectedly");
@ -3724,8 +3726,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
fix_child_filename(name);
copy_file(absname, name);
} else
cerr << "Warning: Could not find file '"
<< name << "'." << endl;
warning_message("Could not find file '" + name + "'.");
context.check_layout(os);
begin_inset(os, "External\n\ttemplate ");
os << "GnumericSpreadsheet\n\tfilename "
@ -3959,19 +3960,17 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
known_pdftex_graphics_formats);
if (!dvips_name.empty()) {
if (!pdftex_name.empty()) {
cerr << "This file contains the "
"latex snippet\n"
"\"\\includegraphics{"
<< name << "}\".\n"
"However, files\n\""
<< dvips_name << "\" and\n\""
<< pdftex_name << "\"\n"
"both exist, so I had to make a "
"choice and took the first one.\n"
"Please move the unwanted one "
"someplace else and try again\n"
"if my choice was wrong."
<< endl;
warning_message("This file contains the "
"latex snippet\n"
"\"\\includegraphics{" + name + "}\".\n"
"However, files\n\""
+ dvips_name + "\" and\n\""
+ pdftex_name + "\"\n"
"both exist, so I had to make a "
"choice and took the first one.\n"
"Please move the unwanted one "
"someplace else and try again\n"
"if my choice was wrong.");
}
name = dvips_name;
} else if (!pdftex_name.empty()) {
@ -3985,8 +3984,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
fix_child_filename(name);
copy_file(absname, name);
} else
cerr << "Warning: Could not find graphics file '"
<< name << "'." << endl;
warning_message("Could not find graphics file '" + name + "'.");
context.check_layout(os);
begin_inset(os, "Graphics ");
@ -4030,7 +4028,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
if (!ss.str().empty())
os << "\trotateOrigin " << ss.str() << '\n';
else
cerr << "Warning: Ignoring unknown includegraphics origin argument '" << opt << "'\n";
warning_message("Ignoring unknown includegraphics origin argument '" + opt + "'");
}
if (opts.find("keepaspectratio") != opts.end())
os << "\tkeepAspectRatio\n";
@ -4055,7 +4053,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
<< opts["bbllx"] << " " << opts["bblly"] << " "
<< opts["bburx"] << " " << opts["bbury"] << '\n';
else if (numberOfbbOptions > 0)
cerr << "Warning: Ignoring incomplete includegraphics boundingbox arguments.\n";
warning_message("Ignoring incomplete includegraphics boundingbox arguments.");
numberOfbbOptions = 0;
if (opts.find("natwidth") != opts.end())
numberOfbbOptions++;
@ -4065,7 +4063,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
os << "\tBoundingBox 0bp 0bp "
<< opts["natwidth"] << " " << opts["natheight"] << '\n';
else if (numberOfbbOptions > 0)
cerr << "Warning: Ignoring incomplete includegraphics boundingbox arguments.\n";
warning_message("Ignoring incomplete includegraphics boundingbox arguments.");
ostringstream special;
if (opts.find("hiresbb") != opts.end())
special << "hiresbb,";
@ -4327,8 +4325,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
// time in the text language.
time_t ptime = from_asctime_utc(localtime);
if (ptime == static_cast<time_t>(-1)) {
cerr << "Warning: Could not parse time `" << localtime
<< "´ for change tracking, using current time instead.\n";
warning_message("Could not parse time `" + localtime
+ "´ for change tracking, using current time instead.");
ptime = current_time();
}
if (t.cs() == "lyxadded")
@ -4877,13 +4875,13 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
string const citation = p.verbatim_item();
if (!before.empty() && argumentOrder == '\0') {
cerr << "Warning: Assuming argument order "
"of jurabib version 0.6 for\n'"
<< command << before << after << '{'
<< citation << "}'.\n"
"Add 'jurabiborder' to the jurabib "
"package options if you used an\n"
"earlier jurabib version." << endl;
warning_message("Assuming argument order "
"of jurabib version 0.6 for\n'"
+ command + before + after + '{'
+ citation + "}'.\n"
"Add 'jurabiborder' to the jurabib "
"package options if you used an\n"
"earlier jurabib version.");
}
bool literal = false;
pair<bool, string> aft;
@ -5297,7 +5295,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
output_ert_inset(os, "\\verb" + delim
+ arg.second + delim, context);
else
cerr << "invalid \\verb command. Skipping" << endl;
warning_message("invalid \\verb command. Skipping");
continue;
}
@ -5493,8 +5491,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
copy_file(abssrc, outname);
}
} else {
cerr << "Warning: Could not find included file '"
<< filename << "'." << endl;
warning_message("Could not find included file '" + filename + "'.");
outname = filename;
}
if (external) {
@ -5615,8 +5612,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
Encoding const * const enc = encodings.fromIconvName(
p.getEncoding(), Encoding::inputenc, true);
if (!enc) {
cerr << "Unknown bib encoding " << p.getEncoding()
<< ". Ignoring." << std::endl;
warning_message("Unknown bib encoding " + p.getEncoding()
+ ". Ignoring.");
} else
os << "encoding " << '"' << enc->name() << '"' << "\n";
}
@ -5664,8 +5661,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
Encoding const * const enc = encodings.fromLaTeXName(
preamble.bibencoding, Encoding::inputenc, true);
if (!enc) {
cerr << "Unknown bib encoding " << preamble.bibencoding
<< ". Ignoring." << std::endl;
warning_message("Unknown bib encoding " + preamble.bibencoding
+ ". Ignoring.");
} else
os << "encoding " << '"' << enc->name() << '"' << "\n";
}
@ -6142,7 +6139,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
p.setCatcodes(VERBATIM_CATCODES);
string delim = p.get_token().asInput();
if (delim != "{")
cerr << "Warning: bad delimiter for command " << t.asInput() << endl;
warning_message("bad delimiter for command " + t.asInput());
//FIXME: handle error condition
string const arg = p.verbatimStuff("}").second;
Context newcontext(true, context.textclass);
@ -6190,7 +6187,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
p.setCatcodes(VERBATIM_CATCODES);
string delim = p.get_token().asInput();
if (delim != "{")
cerr << "Warning: bad delimiter for command " << t.asInput() << endl;
warning_message("bad delimiter for command " + t.asInput());
//FIXME: handle error condition
string const arg = p.verbatimStuff("}").second;
Context newcontext(true, context.textclass);
@ -6235,8 +6232,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
fix_child_filename(name);
copy_file(absname, name);
} else
cerr << "Warning: Could not find file '"
<< name << "'." << endl;
warning_message("Could not find file '" + name + "'.");
// write output
context.check_layout(os);
begin_inset(os, "External\n\ttemplate ");
@ -6265,7 +6261,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
if (!ss.str().empty())
os << "\trotateOrigin " << ss.str() << '\n';
else
cerr << "Warning: Ignoring unknown includegraphics origin argument '" << opt << "'\n";
warning_message("Ignoring unknown includegraphics origin argument '" + opt + "'");
}
if (opts.find("width") != opts.end())
os << "\twidth "
@ -6302,8 +6298,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
fix_child_filename(name);
copy_file(absname, name);
} else
cerr << "Warning: Could not find file '"
<< name << "'." << endl;
warning_message("Could not find file '" + name + "'.");
context.check_layout(os);
begin_inset(os, "External\n\ttemplate ");
os << "ChessDiagram\n\tfilename "
@ -6431,17 +6426,17 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
for (set<string>::const_iterator it = req.begin(); it != req.end(); ++it)
preamble.registerAutomaticallyLoadedPackage(*it);
}
//cerr << "#: " << t << " mode: " << mode << endl;
//warning_message("#: " + t + " mode: " + mode);
// heuristic: read up to next non-nested space
/*
string s = t.asInput();
string z = p.verbatim_item();
while (p.good() && z != " " && !z.empty()) {
//cerr << "read: " << z << endl;
//warning_message("read: " + z);
s += z;
z = p.verbatim_item();
}
cerr << "found ERT: " << s << endl;
warning_message("found ERT: " + s);
output_ert_inset(os, s + ' ', context);
*/
else {