+Converter const * Converters::GetConverter(string const & from,
+ string const & to)
+{
+ ConverterList::const_iterator cit =
+ find_if(converterlist.begin(), converterlist.end(),
+ compare_Converter(from, to));
+ if (cit != converterlist.end())
+ return &(*cit);
+ else
+ return 0;
+}
+
+
+int Converters::GetNumber(string const & from, string const & to)
+{
+ ConverterList::const_iterator cit =
+ find_if(converterlist.begin(), converterlist.end(),
+ compare_Converter(from, to));
+ if (cit != converterlist.end())
+ return cit - converterlist.begin();
+ else
+ return -1;
+}
+
+
+void Converters::Add(string const & from, string const & to,
+ string const & command, string const & flags)
+{
+ formats.Add(from);
+ formats.Add(to);
+ ConverterList::iterator it = find_if(converterlist.begin(),
+ converterlist.end(),
+ compare_Converter(from, to));
+
+ Converter converter(from, to, command, flags);
+ if (it != converterlist.end() && !flags.empty() && flags[0] == '*') {
+ converter = *it;
+ converter.command = command;
+ converter.flags = flags;
+ }
+ 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::Delete(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)
+{
+ for (ConverterList::iterator it = converterlist.begin();
+ it != converterlist.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()
+{
+ 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;