From 52e730a501e9eb2def023365ec31ebfcaba879cb Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 12 Aug 2009 11:17:33 +0200 Subject: [PATCH] Implemented the "list property names" function. --- src/propedit/propedit_cli_parser.cpp | 30 ++++++++++++++++++++++++++-- src/propedit/propedit_cli_parser.h | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/propedit/propedit_cli_parser.cpp b/src/propedit/propedit_cli_parser.cpp index ef52b77b7..66c75380b 100644 --- a/src/propedit/propedit_cli_parser.cpp +++ b/src/propedit/propedit_cli_parser.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -57,17 +58,41 @@ propedit_cli_parser_c::add_change() { : (m_current_arg == "-s") || (m_current_arg == "--set") ? change_c::ct_set : change_c::ct_delete; m_target->add_change(type, m_next_arg); - } catch (const char *message) { - mxerror(boost::format(Y("Invalid change spec (%3%) in '%1% %2%'.\n")) % m_current_arg % m_next_arg % message); + } catch (std::runtime_error &error) { + mxerror(boost::format(Y("Invalid change spec (%3%) in '%1% %2%'.\n")) % m_current_arg % m_next_arg % error.what()); } } void propedit_cli_parser_c::list_property_names() { mxinfo(Y("All known property names and their meaning:\n")); + + list_property_names_for_table(property_element_c::get_table_for(KaxInfo::ClassInfos, NULL, true), Y("Segment information"), "info"); + list_property_names_for_table(property_element_c::get_table_for(KaxTracks::ClassInfos, NULL, true), Y("Track header"), "track:..."); + mxexit(0); } +void +propedit_cli_parser_c::list_property_names_for_table(const std::vector &table, + const std::string &title, + const std::string &edit_spec) { + size_t max_name_len = 0; + std::vector::const_iterator table_it; + mxforeach(table_it, table) + max_name_len = std::max(max_name_len, table_it->m_name.length()); + + static boost::regex s_newline_re("\\s*\\n\\s*", boost::regex::perl); + boost::format format((boost::format(" %%|1$-%1%s| | %%2%%: %%3%%\n") % max_name_len).str()); + + mxinfo("\n"); + mxinfo(boost::format(Y(" Elements in the category '%1%' ('--edit %2%')\n")) % title % edit_spec); + + mxforeach(table_it, table) + mxinfo(format % table_it->m_name % table_it->m_title.get_translated() + % boost::regex_replace(table_it->m_description.get_translated(), s_newline_re, " ", boost::match_default | boost::match_single_line)); +} + void propedit_cli_parser_c::set_file_name() { m_options->set_file_name(m_current_arg); @@ -113,3 +138,4 @@ propedit_cli_parser_c::run() { return m_options; } + diff --git a/src/propedit/propedit_cli_parser.h b/src/propedit/propedit_cli_parser.h index 884b86f2b..eee24ffda 100644 --- a/src/propedit/propedit_cli_parser.h +++ b/src/propedit/propedit_cli_parser.h @@ -36,7 +36,9 @@ protected: void add_change(); void set_parse_mode(); void set_file_name(); + void list_property_names(); + void list_property_names_for_table(const std::vector &table, const std::string &title, const std::string &edit_spec); }; #endif // __PROPEDIT_PROPEDIT_CLI_PARSER_H