From 59b705dcd992715db24599c79b66e096e605b9b3 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Tue, 6 Jan 2015 19:20:05 +0100 Subject: [PATCH] Move global variable to preamble This will be needed in the future, when I need to parse the preamble twice for detecting japanese encoding (bug #8218). --- src/tex2lyx/Preamble.cpp | 16 +++++++++++----- src/tex2lyx/Preamble.h | 6 ++++++ src/tex2lyx/table.cpp | 36 +++++++++++++----------------------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index b4c8adcf0a..94ab8f2b9e 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -39,9 +39,6 @@ using namespace lyx::support; namespace lyx { -// special columntypes -extern map special_columns; - Preamble preamble; namespace { @@ -402,6 +399,15 @@ Author const & Preamble::getAuthor(std::string const & name) const } +int Preamble::getSpecialTableColumnArguments(char c) const +{ + map::const_iterator it = special_columns_.find(c); + if (it == special_columns_.end()) + return -1; + return it->second; +} + + void Preamble::add_package(string const & name, vector & options) { // every package inherits the global options @@ -1240,7 +1246,7 @@ void Preamble::parse(Parser & p, string const & forceclass, TeX2LyXDocClass & tc) { // initialize fixed types - special_columns['D'] = 3; + special_columns_['D'] = 3; bool is_full_document = false; bool is_lyx_file = false; bool in_lyx_preamble = false; @@ -1705,7 +1711,7 @@ void Preamble::parse(Parser & p, string const & forceclass, istringstream is(string(opts, 1)); is >> nargs; } - special_columns[name[0]] = nargs; + special_columns_[name[0]] = nargs; h_preamble << "\\newcolumntype{" << name << "}"; if (nargs) h_preamble << "[" << nargs << "]"; diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h index ae5886e08e..ffc9bda03b 100644 --- a/src/tex2lyx/Preamble.h +++ b/src/tex2lyx/Preamble.h @@ -85,6 +85,9 @@ public: void registerAuthor(std::string const & name); /// Get author named \p name (must be registered first) Author const & getAuthor(std::string const & name) const; + /// Get number of arguments of special table column type \c or -1 + /// if no column type \p c exists + int getSpecialTableColumnArguments(char c) const; /// Parses the LaTeX preamble into internal data void parse(Parser & p, std::string const & forceclass, @@ -214,7 +217,10 @@ private: /// void handle_if(Parser & p, bool in_lyx_preamble); + /// AuthorList authors_; + /// special table column types + std::map special_columns_; }; diff --git a/src/tex2lyx/table.cpp b/src/tex2lyx/table.cpp index 75a0317465..6da3059a02 100644 --- a/src/tex2lyx/table.cpp +++ b/src/tex2lyx/table.cpp @@ -31,9 +31,6 @@ using namespace std; namespace lyx { -// filled in preamble.cpp -map special_columns; - namespace { @@ -420,29 +417,22 @@ void handle_colalign(Parser & p, vector & colinfo, next.special += t.character(); next.special += '{' + p.verbatim_item() + '}'; break; - default: + default: { // try user defined column types - if (special_columns.find(t.character()) != - special_columns.end()) { - ci2special(next); - next.special += t.character(); - int const nargs = - special_columns[t.character()]; - for (int i = 0; i < nargs; ++i) - next.special += '{' + - p.verbatim_item() + - '}'; - colinfo.push_back(next); - next = ColInfo(); - } else { - // unknown column specifier, assume no arguments - ci2special(next); - next.special += t.character(); - colinfo.push_back(next); - next = ColInfo(); - } + // unknown column types (nargs == -1) are + // assumed to consume no arguments + ci2special(next); + next.special += t.character(); + int const nargs = + preamble.getSpecialTableColumnArguments(t.character()); + for (int i = 0; i < nargs; ++i) + next.special += '{' + + p.verbatim_item() + '}'; + colinfo.push_back(next); + next = ColInfo(); break; } + } } // Maybe we have some column separators that need to be added to the -- 2.39.2