From 9ecc30174a108a606dfcad7f6b6156da64cc2b8b Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Wed, 28 Dec 2022 16:29:38 +0100 Subject: [PATCH] Factor out tex2lyx warnings and add -q option (#11328) --- src/tex2lyx/Context.cpp | 4 +- src/tex2lyx/Parser.cpp | 42 ++++----- src/tex2lyx/Preamble.cpp | 19 ++-- src/tex2lyx/dummy_impl.cpp | 3 +- src/tex2lyx/math.cpp | 3 +- src/tex2lyx/table.cpp | 174 ++++++++++++++++--------------------- src/tex2lyx/tex2lyx.1in | 3 + src/tex2lyx/tex2lyx.cpp | 42 ++++++--- src/tex2lyx/tex2lyx.h | 2 + src/tex2lyx/text.cpp | 139 ++++++++++++++--------------- 10 files changed, 212 insertions(+), 219 deletions(-) diff --git a/src/tex2lyx/Context.cpp b/src/tex2lyx/Context.cpp index c565a96085..9bce0502be 100644 --- a/src/tex2lyx/Context.cpp +++ b/src/tex2lyx/Context.cpp @@ -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 + '\''); } diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp index e7d2137291..499e31e967 100644 --- a/src/tex2lyx/Parser.cpp +++ b/src/tex2lyx/Parser.cpp @@ -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_) <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(c) << "\n"; + warning_message("ignoring a char: " + static_cast(c)); break; } default: push_back(Token(docstring(1, c), catcode(c))); } - //cerr << tokens_.back(); + //warning_message(tokens_.back()); } diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 63e6c63814..9fc6068d31 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -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); } diff --git a/src/tex2lyx/dummy_impl.cpp b/src/tex2lyx/dummy_impl.cpp index 17e97ed1b8..d6163ec91f 100644 --- a/src/tex2lyx/dummy_impl.cpp +++ b/src/tex2lyx/dummy_impl.cpp @@ -18,6 +18,7 @@ #include +#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 diff --git a/src/tex2lyx/math.cpp b/src/tex2lyx/math.cpp index 9fddeea16c..e99710fe7a 100644 --- a/src/tex2lyx/math.cpp +++ b/src/tex2lyx/math.cpp @@ -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 << "\\\\"; } diff --git a/src/tex2lyx/table.cpp b/src/tex2lyx/table.cpp index b162617af2..0036620150 100644 --- a/src/tex2lyx/table.cpp +++ b/src/tex2lyx/table.cpp @@ -346,9 +346,8 @@ void handle_colalign(Parser & p, vector & 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, // "%\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, 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, 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; @@ -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 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(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 cols; split(arg, cols, '-'); cols.resize(2); size_t from = convert(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(from + 1)); from = colinfo.size() - 1; } size_t to = convert(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(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(ncells) - << " columns while the table has only " - << convert(colinfo.size()) - << " columns!" - << " Therefore the surplus columns will be ignored." - << endl; + warning_message("The cell '" + + cells[cell] + + "' specifies " + + convert(ncells) + + " columns while the table has only " + + convert(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 << " 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) diff --git a/src/tex2lyx/tex2lyx.1in b/src/tex2lyx/tex2lyx.1in index 358a51fd2f..ea447fc8b3 100644 --- a/src/tex2lyx/tex2lyx.1in +++ b/src/tex2lyx/tex2lyx.1in @@ -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 diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 8e3b667fca..844471224a 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -57,12 +57,12 @@ string const trimSpaceAndEol(string const & a) void split(string const & s, vector & 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::const_iterator const vb = visited.begin(); vector::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() diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index 4152911bf3..1e29712148 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -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 diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 4648983794..ed80968f5d 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -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 << "]" < 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(-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 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::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 { -- 2.39.5