+namespace {
+
+string fixCommand(string const & cmd, string const & ext,
+ os::auto_open_mode mode)
+{
+ // configure.py says we do not want a viewer/editor
+ if (cmd.empty())
+ return cmd;
+
+ // Does the OS manage this format?
+ if (os::canAutoOpenFile(ext, mode))
+ return "auto";
+
+ // if configure.py found nothing, clear the command
+ if (token(cmd, ' ', 0) == "auto")
+ return string();
+
+ // use the command found by configure.py
+ return cmd;
+}
+
+}
+
+void Formats::setAutoOpen()
+{
+ FormatList::iterator fit = formatlist.begin();
+ FormatList::iterator const fend = formatlist.end();
+ for ( ; fit != fend ; ++fit) {
+ fit->setViewer(fixCommand(fit->viewer(), fit->extension(), os::VIEW));
+ fit->setEditor(fixCommand(fit->editor(), fit->extension(), os::EDIT));
+ }
+}
+