int main (int argc, char *argv[]) { using boost::lambda::_1; try { using utsushi::_; utsushi::run_time rt (argc, argv, utsushi::i18n); if (rt.count ("help")) { std::cout << rt.help (_("list available image acquisition devices")); return EXIT_SUCCESS; } if (rt.count ("version")) { std::cout << rt.version (); return EXIT_SUCCESS; } utsushi::monitor mon; std::for_each (mon.begin (), mon.end (), std::cout << boost::lambda::bind (&utsushi::scanner::info::udi, _1) << "\n"); } catch (std::exception& e) { std::cerr << e.what () << "\n"; return EXIT_FAILURE; } catch (...) { return EXIT_FAILURE; } exit (EXIT_SUCCESS); }
int main (int argc, char *argv[]) { namespace po = boost::program_options; namespace fs = boost::filesystem; using boost::lambda::constant; using boost::lambda::_1; using utsushi::_; const std::string cli_scan_utility ("scan-cli"); const std::string gui_scan_utility ("scan-gtkmm"); const std::string fallback_scan_utility (cli_scan_utility); try { using utsushi::_; utsushi::run_time rt (argc, argv, utsushi::i18n); bool interface (getenv ("DISPLAY")); po::variables_map cmd_vm; po::options_description cmd_opts (_("Command options")); cmd_opts .add_options () ("interface", (po::value< bool > (&interface) -> default_value (interface)), _("Start an interactive user interface\n" "The default behavior depends on the environment where one runs" " the command. A scan utility suitable for non-interactive use" " can be selected with the '--no-interface' option.")) ; if (rt.count ("help")) { std::cout << rt.help (_("acquire images with a suitable utility")) << "\n" << cmd_opts; } if (rt.count ("version")) { // Never mind our own version } po::parsed_options opts (po::command_line_parser (rt.arguments ()) .options (cmd_opts) .extra_parser (negating_prefix) .allow_unregistered () .run ()); po::store (opts, cmd_vm); po::notify (cmd_vm); std::vector< std::string > utility_opts (po::collect_unrecognized (opts.options, po::include_positional)); std::string cmd (interface ? rt.locate (gui_scan_utility) : rt.locate (cli_scan_utility)); if (cmd.empty ()) { cmd = rt.locate (fallback_scan_utility); if (cmd.empty ()) { // FIXME Now what!? } } if (rt.count ("help")) cmd += " --help"; if (rt.count ("version")) cmd += " --version"; std::for_each (utility_opts.begin (), utility_opts.end (), cmd += constant (" \"") + _1 + "\""); rt.execute (cmd); } catch (std::exception& e) { std::cerr << e.what () << "\n"; return EXIT_FAILURE; } catch (...) { return EXIT_FAILURE; } exit (EXIT_SUCCESS); }