+ converter.readFlags();
+
+ if (converter.latex && (latex_command_.empty() || to == "dvi"))
+ latex_command_ = subst(command, token_from, "");
+ // If we have both latex & pdflatex, we set latex_command to latex.
+ // The latex_command is used to update the .aux file when running
+ // a converter that uses it.
+
+ if (it == converterlist_.end()) {
+ converterlist_.push_back(converter);
+ } else {
+ converter.From = it->From;
+ converter.To = it->To;
+ *it = converter;
+ }
+}
+
+
+void Converters::erase(string const & from, string const & to)
+{
+ ConverterList::iterator it = find_if(converterlist_.begin(),
+ converterlist_.end(),
+ compare_Converter(from, to));
+ if (it != converterlist_.end())
+ converterlist_.erase(it);
+}
+
+
+// This method updates the pointers From and To in all the converters.
+// The code is not very efficient, but it doesn't matter as the number
+// of formats and converters is small.
+// Furthermore, this method is called only on startup, or after
+// adding/deleting a format in FormPreferences (the latter calls can be
+// eliminated if the formats in the Formats class are stored using a map or
+// a list (instead of a vector), but this will cause other problems).
+void Converters::update(Formats const & formats)
+{
+ ConverterList::iterator it = converterlist_.begin();
+ ConverterList::iterator end = converterlist_.end();
+ for (; it != end; ++it) {
+ it->From = formats.getFormat(it->from);
+ it->To = formats.getFormat(it->to);
+ }
+}
+
+
+// This method updates the pointers From and To in the last converter.
+// It is called when adding a new converter in FormPreferences
+void Converters::updateLast(Formats const & formats)
+{
+ if (converterlist_.begin() != converterlist_.end()) {
+ ConverterList::iterator it = converterlist_.end() - 1;
+ it->From = formats.getFormat(it->from);
+ it->To = formats.getFormat(it->to);
+ }
+}
+
+
+void Converters::sort()
+{
+ std::sort(converterlist_.begin(), converterlist_.end());
+}
+
+
+int Converters::bfs_init(string const & start, bool clear_visited)
+{
+ int const s = formats.getNumber(start);
+ if (s < 0)
+ return s;
+
+ Q_ = queue<int>();
+ if (clear_visited)
+ fill(visited_.begin(), visited_.end(), false);
+ if (visited_[s] == false) {
+ Q_.push(s);
+ visited_[s] = true;
+ }
+ return s;
+}
+
+
+vector<Format const *> const
+Converters::getReachableTo(string const & target, bool clear_visited)
+{
+ vector<Format const *> result;
+ int const s = bfs_init(target, clear_visited);
+ if (s < 0)
+ return result;
+
+ while (!Q_.empty()) {
+ int const i = Q_.front();
+ Q_.pop();
+ if (i != s || target != "lyx") {
+ result.push_back(&formats.get(i));
+ }
+
+ vector<int>::iterator it = vertices_[i].in_vertices.begin();
+ vector<int>::iterator end = vertices_[i].in_vertices.end();
+ for (; it != end; ++it) {
+ if (!visited_[*it]) {
+ visited_[*it] = true;
+ Q_.push(*it);
+ }