+ // use the compare_ascii_no_case instead of compare_no_case,
+ // because in turkish, 'i' is not the lowercase version of 'I',
+ // and thus turkish locale breaks parsing of tags.
+ int const i = compare_ascii_no_case(a.From->prettyname(),
+ b.From->prettyname());
+ if (i == 0)
+ return compare_ascii_no_case(a.To->prettyname(), b.To->prettyname())
+ < 0;
+ else
+ return i < 0;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+class compare_Converter {
+public:
+ compare_Converter(string const & f, string const & t)
+ : from(f), to(t) {}
+ bool operator()(Converter const & c) {
+ return c.from == from && c.to == to;
+ }
+private:
+ string const & from;
+ string const & to;
+};
+
+
+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::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());
+}
+