diff --git a/mu/Makefile.am b/mu/Makefile.am index 896e9af3..14a8d57f 100644 --- a/mu/Makefile.am +++ b/mu/Makefile.am @@ -16,92 +16,92 @@ include $(top_srcdir)/gtest.mk -AM_CPPFLAGS= \ - -I${top_srcdir}/lib \ - $(GLIB_CFLAGS) \ +AM_CPPFLAGS= \ + -I${top_srcdir}/lib \ + $(GLIB_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) -AM_CXXFLAGS= \ - $(JSON_GLIB_CFLAGS) \ +AM_CXXFLAGS= \ + $(JSON_GLIB_CFLAGS) \ -DMU_SCRIPTS_DIR="\"$(pkgdatadir)/scripts/\"" - $(ASAN_CXXCFLAGS) \ - $(WARN_CXXFLAGS) \ - $(CODE_COVERAGE_CFLAGS) \ + $(ASAN_CXXCFLAGS) \ + $(WARN_CXXFLAGS) \ + $(CODE_COVERAGE_CFLAGS) \ -Wno-switch-enum -AM_LDFLAGS= \ +AM_LDFLAGS= \ $(ASAN_LDFLAGS) -bin_PROGRAMS= \ +bin_PROGRAMS= \ mu # note, mu.cc is only '.cc' and not '.c' because libmu must explicitly # be linked as c++, not c. -mu_SOURCES= \ - mu.cc \ - mu-cmd-cfind.cc \ - mu-config.cc \ - mu-config.hh \ - mu-cmd-extract.cc \ - mu-cmd-find.cc \ - mu-cmd-index.cc \ - mu-cmd-server.cc \ - mu-cmd-script.cc \ - mu-cmd.cc \ +mu_SOURCES= \ + mu.cc \ + mu-cmd-cfind.cc \ + mu-config.cc \ + mu-config.hh \ + mu-cmd-extract.cc \ + mu-cmd-find.cc \ + mu-cmd-index.cc \ + mu-cmd-server.cc \ + mu-cmd-script.cc \ + mu-cmd.cc \ mu-cmd.hh -BUILT_SOURCES= \ +BUILT_SOURCES= \ mu-help-strings.h mu-help-strings.h: mu-help-strings.txt mu-help-strings.awk $(AM_V_GEN) $(AWK) -f ${top_srcdir}/mu/mu-help-strings.awk < $< > $@ -mu_LDADD= \ - ${top_builddir}/lib/libmu.la \ - ${top_builddir}/lib/utils/libmu-utils.la \ - $(GLIB_LIBS) \ - $(READLINE_LIBS) \ +mu_LDADD= \ + ${top_builddir}/lib/libmu.la \ + ${top_builddir}/lib/utils/libmu-utils.la \ + $(GLIB_LIBS) \ + $(READLINE_LIBS) \ $(CODE_COVERAGE_LIBS) -EXTRA_DIST= \ - mu-help-strings.awk \ +EXTRA_DIST= \ + mu-help-strings.awk \ mu-help-strings.txt noinst_PROGRAMS= $(TEST_PROGS) -test_cxxflags= \ - ${AM_CXXFLAGS} \ - -DMU_TESTMAILDIR=\"${abs_top_srcdir}/lib/testdir\" \ - -DMU_TESTMAILDIR2=\"${abs_top_srcdir}/lib/testdir2\" \ - -DMU_TESTMAILDIR3=\"${abs_top_srcdir}/lib/testdir3\" \ - -DMU_TESTMAILDIR4=\"${abs_top_srcdir}/lib/testdir4\" \ - -DMU_PROGRAM=\"${abs_top_builddir}/mu/mu\" \ - -DABS_CURDIR=\"${abs_builddir}\" \ +test_cxxflags= \ + ${AM_CXXFLAGS} \ + -DMU_TESTMAILDIR=\"${abs_top_srcdir}/lib/testdir\" \ + -DMU_TESTMAILDIR2=\"${abs_top_srcdir}/lib/testdir2\" \ + -DMU_TESTMAILDIR3=\"${abs_top_srcdir}/lib/testdir3\" \ + -DMU_TESTMAILDIR4=\"${abs_top_srcdir}/lib/testdir4\" \ + -DMU_PROGRAM=\"${abs_top_builddir}/mu/mu\" \ + -DABS_CURDIR=\"${abs_builddir}\" \ -DABS_SRCDIR=\"${abs_srcdir}\" -TEST_PROGS += test-mu-query -test_mu_query_SOURCES= test-mu-query.cc -test_mu_query_CXXFLAGS=$(test_cxxflags) -test_mu_query_LDADD=${top_builddir}/lib/libtestmucommon.la $(CODE_COVERAGE_LIBS) +TEST_PROGS += test-query +test_query_SOURCES= test-mu-query.cc +test_query_CXXFLAGS=$(test_cxxflags) +test_query_LDADD=${top_builddir}/lib/libtestmucommon.la $(CODE_COVERAGE_LIBS) -TEST_PROGS += test-mu-cmd -test_mu_cmd_SOURCES= test-mu-cmd.cc -test_mu_cmd_CXXFLAGS=$(test_cxxflags) -test_mu_cmd_LDADD=${top_builddir}/lib/libtestmucommon.la $(CODE_COVERAGE_LIBS) +TEST_PROGS += test-cmd +test_cmd_SOURCES= test-mu-cmd.cc +test_cmd_CXXFLAGS=$(test_cxxflags) +test_cmd_LDADD=${top_builddir}/lib/libtestmucommon.la $(CODE_COVERAGE_LIBS) -TEST_PROGS += test-mu-cmd-cfind -test_mu_cmd_cfind_SOURCES= test-mu-cmd-cfind.cc -test_mu_cmd_cfind_CXXFLAGS=$(test_cxxflags) -test_mu_cmd_cfind_LDADD=${top_builddir}/lib/libtestmucommon.la $(CODE_COVERAGE_LIBS) +TEST_PROGS += test-cmd-cfind +test_cmd_cfind_SOURCES= test-mu-cmd-cfind.cc +test_cmd_cfind_CXXFLAGS=$(test_cxxflags) +test_cmd_cfind_LDADD=${top_builddir}/lib/libtestmucommon.la $(CODE_COVERAGE_LIBS) -TEST_PROGS += test-mu-threads -test_mu_threads_SOURCES= test-mu-threads.cc -test_mu_threads_CXXFLAGS=$(test_cxxflags) -test_mu_threads_LDADD=${top_builddir}/lib/libtestmucommon.la $(CODE_COVERAGE_LIBS) +TEST_PROGS += test-threads +test_threads_SOURCES= test-mu-threads.cc +test_threads_CXXFLAGS=$(test_cxxflags) +test_threads_LDADD=${top_builddir}/lib/libtestmucommon.la $(CODE_COVERAGE_LIBS) TESTS=$(TEST_PROGS) include $(top_srcdir)/aminclude_static.am -CLEANFILES= \ +CLEANFILES= \ $(BUILT_SOURCES) diff --git a/mu/mu-cmd-cfind.cc b/mu/mu-cmd-cfind.cc index 5b8c4c80..9b163e2a 100644 --- a/mu/mu-cmd-cfind.cc +++ b/mu/mu-cmd-cfind.cc @@ -35,6 +35,8 @@ #include "utils/mu-str.h" #include "utils/mu-date.h" +using namespace Mu; + /** * guess the last name for the given name; clearly, * this is just a rough guess for setting an initial value. @@ -404,7 +406,7 @@ cfind_params_valid (const MuConfig *opts) } MuError -mu_cmd_cfind (const Mu::Store& store, const MuConfig *opts, GError **err) +Mu::mu_cmd_cfind (const Mu::Store& store, const MuConfig *opts, GError **err) { g_return_val_if_fail (opts, MU_ERROR_INTERNAL); g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_CFIND, diff --git a/mu/mu-cmd-extract.cc b/mu/mu-cmd-extract.cc index 9e8aefd3..237dd24d 100644 --- a/mu/mu-cmd-extract.cc +++ b/mu/mu-cmd-extract.cc @@ -22,12 +22,14 @@ #include #include -#include "mu-msg.h" -#include "mu-msg-part.h" +#include "mu-msg.hh" +#include "mu-msg-part.hh" + #include "mu-cmd.hh" #include "utils/mu-util.h" #include "utils/mu-str.h" +using namespace Mu; static gboolean save_part (MuMsg *msg, const char *targetdir, guint partidx, const MuConfig *opts) @@ -393,7 +395,7 @@ check_params (const MuConfig *opts, GError **err) } MuError -mu_cmd_extract (const MuConfig *opts, GError **err) +Mu::mu_cmd_extract (const MuConfig *opts, GError **err) { int rv; diff --git a/mu/mu-cmd-find.cc b/mu/mu-cmd-find.cc index c6634991..0db2177a 100644 --- a/mu/mu-cmd-find.cc +++ b/mu/mu-cmd-find.cc @@ -28,10 +28,10 @@ #include #include -#include "mu-msg.h" -#include "mu-maildir.h" +#include "mu-msg.hh" +#include "mu-maildir.hh" +#include "mu-query-match-deciders.hh" #include "mu-query.hh" -#include "mu-msg-iter.h" #include "mu-bookmarks.hh" #include "mu-runtime.hh" @@ -40,16 +40,25 @@ #include "utils/mu-date.h" #include "mu-cmd.hh" -#include "mu-threader.hh" using namespace Mu; -typedef gboolean (OutputFunc) (MuMsg *msg, MuMsgIter *iter, - const MuConfig *opts, GError **err); +struct OutputInfo{ + Xapian::docid docid{}; + bool is_first{}; + bool is_last{}; + Option match_info; +}; + +constexpr auto FirstOutput{OutputInfo{0, true, false}}; +constexpr auto LastOutput{OutputInfo{0, false, true}}; + +using OutputFunc = std::function; static gboolean -print_internal (const Query& query, const gchar *expr, gboolean xapian, - gboolean warn, GError **err) +print_internal (const Query& query, const std::string& expr, gboolean xapian, + gboolean warn, GError **err) { std::cout << query.parse(expr, xapian) << "\n"; return TRUE; @@ -60,406 +69,376 @@ print_internal (const Query& query, const gchar *expr, gboolean xapian, static MuMsgFieldId sort_field_from_string (const char* fieldstr, GError **err) { - MuMsgFieldId mfid; + MuMsgFieldId mfid; - mfid = mu_msg_field_id_from_name (fieldstr, FALSE); + mfid = mu_msg_field_id_from_name (fieldstr, FALSE); - /* not found? try a shortcut */ - if (mfid == MU_MSG_FIELD_ID_NONE && - strlen(fieldstr) == 1) - mfid = mu_msg_field_id_from_shortcut(fieldstr[0], - FALSE); - if (mfid == MU_MSG_FIELD_ID_NONE) - g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_IN_PARAMETERS, - "not a valid sort field: '%s'\n", fieldstr); - return mfid; + /* not found? try a shortcut */ + if (mfid == MU_MSG_FIELD_ID_NONE && + strlen(fieldstr) == 1) + mfid = mu_msg_field_id_from_shortcut(fieldstr[0], + FALSE); + if (mfid == MU_MSG_FIELD_ID_NONE) + g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_IN_PARAMETERS, + "not a valid sort field: '%s'\n", fieldstr); + return mfid; } -static MuMsg* -get_message (MuMsgIter *iter, time_t after) -{ - MuMsg *msg; - if (mu_msg_iter_is_done (iter)) - return NULL; - - msg = mu_msg_iter_get_msg_floating (iter); - if (!msg) - return NULL; /* error */ - - if (!mu_msg_is_readable (msg)) { - mu_msg_iter_next (iter); - return get_message (iter, after); - } - - if (after != 0 && after > mu_msg_get_timestamp (msg)) { - mu_msg_iter_next (iter); - return get_message (iter, after); - } - - return msg; -} - -static MuMsgIter* +static Option run_query (const Query& q, const std::string& expr, const MuConfig *opts, GError **err) { - MuMsgIter *iter; - MuMsgFieldId sortid; + MuMsgFieldId sortid; - sortid = MU_MSG_FIELD_ID_NONE; - if (opts->sortfield) { - sortid = sort_field_from_string (opts->sortfield, err); - if (sortid == MU_MSG_FIELD_ID_NONE) /* error occurred? */ - return FALSE; - } + sortid = MU_MSG_FIELD_ID_NONE; + if (opts->sortfield) { + sortid = sort_field_from_string (opts->sortfield, err); + if (sortid == MU_MSG_FIELD_ID_NONE) /* error occurred? */ + return Nothing; + } - Mu::Query::Flags qflags{Query::Flags::None}; - if (opts->reverse) - qflags |= Query::Flags::Descending; - if (opts->skip_dups) - qflags |= Query::Flags::SkipDups; - if (opts->include_related) - qflags |= Query::Flags::IncludeRelated; - if (opts->threads) - qflags |= Query::Flags::Threading; + Mu::QueryFlags qflags{QueryFlags::None}; + if (opts->reverse) + qflags |= QueryFlags::Descending; + if (opts->skip_dups) + qflags |= QueryFlags::SkipDuplicates; + if (opts->include_related) + qflags |= QueryFlags::IncludeRelated; + if (opts->threads) + qflags |= QueryFlags::Threading; - return q.run(expr, sortid, qflags, opts->maxnum, err); + return q.run(expr, sortid, qflags, opts->maxnum); } static gboolean -exec_cmd (MuMsg *msg, MuMsgIter *iter, const MuConfig *opts, GError **err) +exec_cmd (MuMsg *msg, const OutputInfo& info, + const MuConfig *opts, GError **err) { - gint status; - char *cmdline, *escpath; - gboolean rv; + gint status; + char *cmdline, *escpath; + gboolean rv; - escpath = g_shell_quote (mu_msg_get_path (msg)); - cmdline = g_strdup_printf ("%s %s", opts->exec, escpath); + escpath = g_shell_quote (mu_msg_get_path (msg)); + cmdline = g_strdup_printf ("%s %s", opts->exec, escpath); - rv = g_spawn_command_line_sync (cmdline, NULL, NULL, &status, err); + rv = g_spawn_command_line_sync (cmdline, NULL, NULL, &status, err); - g_free (cmdline); - g_free (escpath); + g_free (cmdline); + g_free (escpath); - return rv; + return rv; } static gchar* resolve_bookmark (const MuConfig *opts, GError **err) { - MuBookmarks *bm; - char* val; - const gchar *bmfile; + MuBookmarks *bm; + char* val; + const gchar *bmfile; - bmfile = mu_runtime_path (MU_RUNTIME_PATH_BOOKMARKS); - bm = mu_bookmarks_new (bmfile); - if (!bm) { - g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_FILE_CANNOT_OPEN, - "failed to open bookmarks file '%s'", bmfile); - return FALSE; - } + bmfile = mu_runtime_path (MU_RUNTIME_PATH_BOOKMARKS); + bm = mu_bookmarks_new (bmfile); + if (!bm) { + g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_FILE_CANNOT_OPEN, + "failed to open bookmarks file '%s'", bmfile); + return FALSE; + } - val = (gchar*)mu_bookmarks_lookup (bm, opts->bookmark); - if (!val) - g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_NO_MATCHES, - "bookmark '%s' not found", opts->bookmark); - else - val = g_strdup (val); + val = (gchar*)mu_bookmarks_lookup (bm, opts->bookmark); + if (!val) + g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_NO_MATCHES, + "bookmark '%s' not found", opts->bookmark); + else + val = g_strdup (val); - mu_bookmarks_destroy (bm); - return val; + mu_bookmarks_destroy (bm); + return val; } -static gchar* +static Option get_query (const MuConfig *opts, GError **err) { - gchar *query, *bookmarkval; + gchar *query, *bookmarkval; - /* params[0] is 'find', actual search params start with [1] */ - if (!opts->bookmark && !opts->params[1]) { - g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_IN_PARAMETERS, - "error in parameters"); - return NULL; - } + /* params[0] is 'find', actual search params start with [1] */ + if (!opts->bookmark && !opts->params[1]) { + g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_IN_PARAMETERS, + "error in parameters"); + return Nothing; + } - bookmarkval = NULL; - if (opts->bookmark) { - bookmarkval = resolve_bookmark (opts, err); - if (!bookmarkval) - return NULL; - } + bookmarkval = NULL; + if (opts->bookmark) { + bookmarkval = resolve_bookmark (opts, err); + if (!bookmarkval) + return Nothing; + } - query = g_strjoinv (" ", &opts->params[1]); - if (bookmarkval) { - gchar *tmp; - tmp = g_strdup_printf ("%s %s", bookmarkval, query); - g_free (query); - query = tmp; - } + query = g_strjoinv (" ", &opts->params[1]); + if (bookmarkval) { + gchar *tmp; + tmp = g_strdup_printf ("%s %s", bookmarkval, query); + g_free (query); + query = tmp; + } - g_free (bookmarkval); + g_free (bookmarkval); - return query; + std::string q{query}; + g_free(query); + + return q; } static Mu::Query get_query_obj (const Store& store, GError **err) { - const auto count{store.size()}; + const auto count{store.size()}; - if (count == (unsigned)-1) + if (count == (unsigned)-1) throw Mu::Error(Error::Code::Store, "invalid store"); - if (count == 0) + if (count == 0) throw Mu::Error(Error::Code::Store, "store is empty"); - return Mu::Query{store}; + return Mu::Query{store}; } static gboolean prepare_links (const MuConfig *opts, GError **err) { - /* note, mu_maildir_mkdir simply ignores whatever part of the - * mail dir already exists */ + /* note, mu_maildir_mkdir simply ignores whatever part of the + * mail dir already exists */ - if (!mu_maildir_mkdir (opts->linksdir, 0700, TRUE, err)) { - mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_MKDIR, - "error creating %s", opts->linksdir); - return FALSE; - } + if (!mu_maildir_mkdir (opts->linksdir, 0700, TRUE, err)) { + mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_MKDIR, + "error creating %s", opts->linksdir); + return FALSE; + } - if (opts->clearlinks && - !mu_maildir_clear_links (opts->linksdir, err)) { - mu_util_g_set_error (err, MU_ERROR_FILE, - "error clearing links under %s", - opts->linksdir); - return FALSE; - } + if (opts->clearlinks && + !mu_maildir_clear_links (opts->linksdir, err)) { + mu_util_g_set_error (err, MU_ERROR_FILE, + "error clearing links under %s", + opts->linksdir); + return FALSE; + } - return TRUE; + return TRUE; } -static gboolean -output_link (MuMsg *msg, MuMsgIter *iter, const MuConfig *opts, GError **err) +static bool +output_link (MuMsg *msg, const OutputInfo& info, + const MuConfig *opts, GError **err) { - if (mu_msg_iter_is_first (iter) && !prepare_links (opts, err)) - return FALSE; + if (info.is_first && !prepare_links (opts, err)) + return FALSE; - return mu_maildir_link (mu_msg_get_path (msg), - opts->linksdir, err); + return mu_maildir_link (mu_msg_get_path (msg), + opts->linksdir, err); } static void ansi_color_maybe (MuMsgFieldId mfid, gboolean color) { - const char* ansi; + const char* ansi; - if (!color) - return; /* nothing to do */ + if (!color) + return; /* nothing to do */ - switch (mfid) { + switch (mfid) { - case MU_MSG_FIELD_ID_FROM: - ansi = MU_COLOR_CYAN; break; + case MU_MSG_FIELD_ID_FROM: + ansi = MU_COLOR_CYAN; break; - case MU_MSG_FIELD_ID_TO: - case MU_MSG_FIELD_ID_CC: - case MU_MSG_FIELD_ID_BCC: - ansi = MU_COLOR_BLUE; break; + case MU_MSG_FIELD_ID_TO: + case MU_MSG_FIELD_ID_CC: + case MU_MSG_FIELD_ID_BCC: + ansi = MU_COLOR_BLUE; break; - case MU_MSG_FIELD_ID_SUBJECT: - ansi = MU_COLOR_GREEN; break; + case MU_MSG_FIELD_ID_SUBJECT: + ansi = MU_COLOR_GREEN; break; - case MU_MSG_FIELD_ID_DATE: - ansi = MU_COLOR_MAGENTA; break; + case MU_MSG_FIELD_ID_DATE: + ansi = MU_COLOR_MAGENTA; break; - default: - if (mu_msg_field_type(mfid) == MU_MSG_FIELD_TYPE_STRING) - ansi = MU_COLOR_YELLOW; - else - ansi = MU_COLOR_RED; - } + default: + if (mu_msg_field_type(mfid) == MU_MSG_FIELD_TYPE_STRING) + ansi = MU_COLOR_YELLOW; + else + ansi = MU_COLOR_RED; + } - fputs (ansi, stdout); + fputs (ansi, stdout); } static void ansi_reset_maybe (MuMsgFieldId mfid, gboolean color) { - if (!color) - return; /* nothing to do */ + if (!color) + return; /* nothing to do */ - fputs (MU_COLOR_DEFAULT, stdout); + fputs (MU_COLOR_DEFAULT, stdout); } static const char* field_string_list (MuMsg *msg, MuMsgFieldId mfid) { - char *str; - const GSList *lst; - static char buf[80]; + char *str; + const GSList *lst; + static char buf[80]; - lst = mu_msg_get_field_string_list (msg, mfid); - if (!lst) - return NULL; + lst = mu_msg_get_field_string_list (msg, mfid); + if (!lst) + return NULL; - str = mu_str_from_list (lst, ','); - if (str) { - strncpy (buf, str, sizeof(buf)-1); - buf[sizeof(buf)-1]='\0'; - g_free (str); - return buf; - } + str = mu_str_from_list (lst, ','); + if (str) { + strncpy (buf, str, sizeof(buf)-1); + buf[sizeof(buf)-1]='\0'; + g_free (str); + return buf; + } - return NULL; + return NULL; } static const char* display_field (MuMsg *msg, MuMsgFieldId mfid) { - gint64 val; + gint64 val; - switch (mu_msg_field_type(mfid)) { - case MU_MSG_FIELD_TYPE_STRING: { - const gchar *str; - str = mu_msg_get_field_string (msg, mfid); - return str ? str : ""; - } - case MU_MSG_FIELD_TYPE_INT: + switch (mu_msg_field_type(mfid)) { + case MU_MSG_FIELD_TYPE_STRING: { + const gchar *str; + str = mu_msg_get_field_string (msg, mfid); + return str ? str : ""; + } + case MU_MSG_FIELD_TYPE_INT: - if (mfid == MU_MSG_FIELD_ID_PRIO) { - val = mu_msg_get_field_numeric (msg, mfid); - return mu_msg_prio_name ((MuMsgPrio)val); - } else if (mfid == MU_MSG_FIELD_ID_FLAGS) { - val = mu_msg_get_field_numeric (msg, mfid); - return mu_str_flags_s ((MuFlags)val); - } else /* as string */ - return mu_msg_get_field_string (msg, mfid); + if (mfid == MU_MSG_FIELD_ID_PRIO) { + val = mu_msg_get_field_numeric (msg, mfid); + return mu_msg_prio_name ((MuMsgPrio)val); + } else if (mfid == MU_MSG_FIELD_ID_FLAGS) { + val = mu_msg_get_field_numeric (msg, mfid); + return mu_str_flags_s ((MuFlags)val); + } else /* as string */ + return mu_msg_get_field_string (msg, mfid); - case MU_MSG_FIELD_TYPE_TIME_T: - val = mu_msg_get_field_numeric (msg, mfid); - return mu_date_str_s ("%c", (time_t)val); + case MU_MSG_FIELD_TYPE_TIME_T: + val = mu_msg_get_field_numeric (msg, mfid); + return mu_date_str_s ("%c", (time_t)val); - case MU_MSG_FIELD_TYPE_BYTESIZE: - val = mu_msg_get_field_numeric (msg, mfid); - return mu_str_size_s ((unsigned)val); - case MU_MSG_FIELD_TYPE_STRING_LIST: { - const char *str; - str = field_string_list (msg, mfid); - return str ? str : ""; - } - default: - g_return_val_if_reached (NULL); - } + case MU_MSG_FIELD_TYPE_BYTESIZE: + val = mu_msg_get_field_numeric (msg, mfid); + return mu_str_size_s ((unsigned)val); + case MU_MSG_FIELD_TYPE_STRING_LIST: { + const char *str; + str = field_string_list (msg, mfid); + return str ? str : ""; + } + default: + g_return_val_if_reached (NULL); + } } static void print_summary (MuMsg *msg, const MuConfig *opts) { - const char* body; - char *summ; - MuMsgOptions msgopts; + const char* body; + char *summ; + MuMsgOptions msgopts; - msgopts = mu_config_get_msg_options (opts); - body = mu_msg_get_body_text(msg, msgopts); + msgopts = mu_config_get_msg_options (opts); + body = mu_msg_get_body_text(msg, msgopts); - if (body) - summ = mu_str_summarize (body, (unsigned)opts->summary_len); - else - summ = NULL; + if (body) + summ = mu_str_summarize (body, (unsigned)opts->summary_len); + else + summ = NULL; - g_print ("Summary: "); - mu_util_fputs_encoded (summ ? summ : "", stdout); - g_print ("\n"); + g_print ("Summary: "); + mu_util_fputs_encoded (summ ? summ : "", stdout); + g_print ("\n"); - g_free (summ); + g_free (summ); } static void -thread_indent (MuMsgIter *iter) +thread_indent (const QueryMatch& info) { - const MuMsgIterThreadInfo *ti; - const char* threadpath; - int i; - gboolean is_root, first_child, empty_parent, is_dup; + const auto is_root{any_of(info.flags & QueryMatch::Flags::Root)}; + const auto first_child{any_of(info.flags & QueryMatch::Flags::First)}; + const auto last_child{any_of(info.flags & QueryMatch::Flags::Last)}; + const auto empty_parent{any_of(info.flags & QueryMatch::Flags::Orphan)}; + const auto is_dup{any_of(info.flags & QueryMatch::Flags::Duplicate)}; + const auto is_related{any_of(info.flags & QueryMatch::Flags::Related)}; - ti = mu_msg_iter_get_thread_info (iter); - if (!ti) { - g_printerr ("cannot get thread-info for message %u\n", - mu_msg_iter_get_docid (iter)); - return; - } + /* indent */ + for (auto i = info.thread_level; i > 1; --i) + ::fputs (" ", stdout); - threadpath = ti->threadpath; - /* fputs (threadpath, stdout); */ - /* fputs (" ", stdout); */ - - is_root = ti->prop & MU_MSG_ITER_THREAD_PROP_ROOT; - first_child = ti->prop & MU_MSG_ITER_THREAD_PROP_FIRST_CHILD; - empty_parent = ti->prop & MU_MSG_ITER_THREAD_PROP_EMPTY_PARENT; - is_dup = ti->prop & MU_MSG_ITER_THREAD_PROP_DUP; - - /* FIXME: count the colons... */ - for (i = 0; *threadpath; ++threadpath) - i += (*threadpath == ':') ? 1 : 0; - - /* indent */ - while (i --> 0) - fputs (" ", stdout); - - if (!is_root) { - fputs (first_child ? "`" : "|", stdout); - fputs (empty_parent ? "*> " : is_dup ? "=> " : "-> ", stdout); - } + if (!is_root) { + if (first_child) + ::fputs ("\\", stdout); + else if (last_child) + ::fputs ("/", stdout); + else + ::fputs (" ", stdout); + ::fputs (empty_parent ? "*> " : is_dup ? "=> " : "-> ", stdout); + } } static void output_plain_fields (MuMsg *msg, const char *fields, - gboolean color, gboolean threads) + gboolean color, gboolean threads) { - const char* myfields; - int nonempty; + const char* myfields; + int nonempty; - g_return_if_fail (fields); + g_return_if_fail (fields); - for (myfields = fields, nonempty = 0; *myfields; ++myfields) { + for (myfields = fields, nonempty = 0; *myfields; ++myfields) { - MuMsgFieldId mfid; - mfid = mu_msg_field_id_from_shortcut (*myfields, FALSE); + MuMsgFieldId mfid; + mfid = mu_msg_field_id_from_shortcut (*myfields, FALSE); - if (mfid == MU_MSG_FIELD_ID_NONE || - (!mu_msg_field_xapian_value (mfid) && - !mu_msg_field_xapian_contact (mfid))) - nonempty += printf ("%c", *myfields); + if (mfid == MU_MSG_FIELD_ID_NONE || + (!mu_msg_field_xapian_value (mfid) && + !mu_msg_field_xapian_contact (mfid))) + nonempty += printf ("%c", *myfields); - else { - ansi_color_maybe (mfid, color); - nonempty += mu_util_fputs_encoded - (display_field (msg, mfid), stdout); - ansi_reset_maybe (mfid, color); - } - } + else { + ansi_color_maybe (mfid, color); + nonempty += mu_util_fputs_encoded + (display_field (msg, mfid), stdout); + ansi_reset_maybe (mfid, color); + } + } - if (nonempty) - fputs ("\n", stdout); + if (nonempty) + fputs ("\n", stdout); } static gboolean -output_plain (MuMsg *msg, MuMsgIter *iter, const MuConfig *opts, GError **err) +output_plain (MuMsg *msg, const OutputInfo& info, const MuConfig *opts, GError **err) { - /* we reuse the color (whatever that may be) - * for message-priority for threads, too */ - ansi_color_maybe (MU_MSG_FIELD_ID_PRIO, !opts->nocolor); - if (opts->threads) - thread_indent (iter); + if (!msg) + return true; - output_plain_fields (msg, opts->fields, !opts->nocolor, opts->threads); + /* we reuse the color (whatever that may be) + * for message-priority for threads, too */ + ansi_color_maybe (MU_MSG_FIELD_ID_PRIO, !opts->nocolor); + if (opts->threads && info.match_info) + thread_indent (*info.match_info); - if (opts->summary_len > 0) - print_summary (msg, opts); + output_plain_fields (msg, opts->fields, !opts->nocolor, opts->threads); - return TRUE; + if (opts->summary_len > 0) + print_summary (msg, opts); + + return TRUE; } @@ -511,254 +490,238 @@ to_string (const Mu::Sexp& sexp, bool color, size_t level = 0) } -static gboolean -output_sexp (MuMsg *msg, MuMsgIter *iter, const MuConfig *opts, GError **err) +static bool +output_sexp (MuMsg *msg, const OutputInfo& info, const MuConfig *opts, GError **err) { - const auto *ti{opts->threads ? mu_msg_iter_get_thread_info (iter) : NULL}; - const auto sexp{Mu::msg_to_sexp(msg , mu_msg_iter_get_docid (iter), ti, - MU_MSG_OPTION_HEADERS_ONLY)}; - fputs (to_string(sexp, !opts->nocolor).c_str(), stdout); + fputs(msg_to_sexp(msg, 0, {}, MU_MSG_OPTION_HEADERS_ONLY) + .to_sexp_string().c_str(), stdout); fputs ("\n", stdout); - - return TRUE; + return true; } -static gboolean -output_json (MuMsg *msg, MuMsgIter *iter, const MuConfig *opts, GError **err) +static bool +output_json (MuMsg *msg, const OutputInfo& info, const MuConfig *opts, GError **err) { - const MuMsgIterThreadInfo *ti; - char *s; + if (info.is_first) { + g_print ("[\n"); + return true; + } - if (mu_msg_iter_is_first(iter)) - g_print ("[\n"); + if (info.is_last) { + g_print("]\n"); + return true; + } - ti = opts->threads ? mu_msg_iter_get_thread_info (iter) : NULL; - s = mu_msg_to_json (msg, mu_msg_iter_get_docid (iter), - ti, MU_MSG_OPTION_HEADERS_ONLY); - fputs (s, stdout); - g_free (s); + g_print("%s\n", msg_to_sexp(msg, info.docid, {}, MU_MSG_OPTION_HEADERS_ONLY) + .to_sexp_string().c_str()); - if (mu_msg_iter_is_last(iter)) - fputs("]\n", stdout); - else - fputs (",\n", stdout); - - return TRUE; + return true; } static void print_attr_xml (const char* elm, const char *str) { - gchar *esc; + gchar *esc; - if (mu_str_is_empty(str)) - return; /* empty: don't include */ + if (mu_str_is_empty(str)) + return; /* empty: don't include */ - esc = g_markup_escape_text (str, -1); - g_print ("\t\t<%s>%s\n", elm, esc, elm); - g_free (esc); + esc = g_markup_escape_text (str, -1); + g_print ("\t\t<%s>%s\n", elm, esc, elm); + g_free (esc); } -static gboolean -output_xml (MuMsg *msg, MuMsgIter *iter, const MuConfig *opts, GError **err) +static bool +output_xml (MuMsg *msg, const OutputInfo& info, const MuConfig *opts, GError **err) { - if (mu_msg_iter_is_first(iter)) { - g_print ("\n"); - g_print ("\n"); - } + if (info.is_first) { + g_print ("\n"); + g_print ("\n"); + return true; + } - g_print ("\t\n"); - print_attr_xml ("from", mu_msg_get_from (msg)); - print_attr_xml ("to", mu_msg_get_to (msg)); - print_attr_xml ("cc", mu_msg_get_cc (msg)); - print_attr_xml ("subject", mu_msg_get_subject (msg)); - g_print ("\t\t%u\n", - (unsigned)mu_msg_get_date (msg)); - g_print ("\t\t%u\n", (unsigned)mu_msg_get_size (msg)); - print_attr_xml ("msgid", mu_msg_get_msgid (msg)); - print_attr_xml ("path", mu_msg_get_path (msg)); - print_attr_xml ("maildir", mu_msg_get_maildir (msg)); - g_print ("\t\n"); + if (info.is_last) { + g_print ("\n"); + return true; + } - if (mu_msg_iter_is_last(iter)) - g_print ("\n"); + g_print ("\t\n"); + print_attr_xml ("from", mu_msg_get_from (msg)); + print_attr_xml ("to", mu_msg_get_to (msg)); + print_attr_xml ("cc", mu_msg_get_cc (msg)); + print_attr_xml ("subject", mu_msg_get_subject (msg)); + g_print ("\t\t%u\n", + (unsigned)mu_msg_get_date (msg)); + g_print ("\t\t%u\n", (unsigned)mu_msg_get_size (msg)); + print_attr_xml ("msgid", mu_msg_get_msgid (msg)); + print_attr_xml ("path", mu_msg_get_path (msg)); + print_attr_xml ("maildir", mu_msg_get_maildir (msg)); + g_print ("\t\n"); - return TRUE; + return true; } -static OutputFunc* +static OutputFunc get_output_func (const MuConfig *opts, GError **err) { - switch (opts->format) { - case MU_CONFIG_FORMAT_LINKS: return output_link; - case MU_CONFIG_FORMAT_EXEC: return exec_cmd; - case MU_CONFIG_FORMAT_PLAIN: return output_plain; - case MU_CONFIG_FORMAT_XML: return output_xml; - case MU_CONFIG_FORMAT_SEXP: return output_sexp; - case MU_CONFIG_FORMAT_JSON: return output_json; + switch (opts->format) { + case MU_CONFIG_FORMAT_LINKS: return output_link; + case MU_CONFIG_FORMAT_EXEC: return exec_cmd; + case MU_CONFIG_FORMAT_PLAIN: return output_plain; + case MU_CONFIG_FORMAT_XML: return output_xml; + case MU_CONFIG_FORMAT_SEXP: return output_sexp; + case MU_CONFIG_FORMAT_JSON: return output_json; - default: - g_return_val_if_reached (NULL); - return NULL; - } + default: + g_return_val_if_reached (NULL); + return NULL; + } +} + +static bool +output_query_results (const QueryResults& qres, const MuConfig *opts, GError **err) +{ + const auto output_func{get_output_func (opts, err)}; + if (!output_func) + return false; + + gboolean rv{true}; + output_func (NULL, FirstOutput, NULL, NULL); + + for (auto&& item: qres) { + + auto msg{item.floating_msg()}; + if (!msg) + continue; + + if (opts->after != 0 && mu_msg_get_timestamp(msg) < opts->after) + continue; + + rv = output_func (msg, {item.doc_id(), false, false, item.query_match()}, + opts, err); + if (!rv) + break; + } + output_func (NULL, LastOutput, NULL, NULL); + + return rv; } static gboolean -output_query_results (MuMsgIter *iter, const MuConfig *opts, GError **err) +process_query (const Query& q, const std::string& expr, const MuConfig *opts, GError **err) { - int count; - gboolean rv; - OutputFunc *output_func; + gboolean rv; - output_func = get_output_func (opts, err); - if (!output_func) - return FALSE; + auto qres{run_query (q, expr, opts, err)}; + if (!qres) + return FALSE; - for (count = 0, rv = TRUE; !mu_msg_iter_is_done(iter); - mu_msg_iter_next (iter)) { + if (qres->empty()) { + mu_util_g_set_error (err, MU_ERROR_NO_MATCHES, + "no matches for search expression"); + return false; + } - MuMsg *msg; - - if (count == opts->maxnum) - break; - msg = get_message (iter, opts->after); - if (!msg) - break; - /* { */ - /* const char* thread_id; */ - /* thread_id = mu_msg_iter_get_thread_id (iter); */ - /* g_print ("%s ", thread_id ? thread_id : ""); */ - - /* } */ - rv = output_func (msg, iter, opts, err); - if (!rv) - break; - else - ++count; - } - - if (rv && count == 0) { - mu_util_g_set_error (err, MU_ERROR_NO_MATCHES, - "no matches for search expression"); - return FALSE; - } - - return rv; -} - -static gboolean -process_query (const Query& q, const gchar *expr, const MuConfig *opts, GError **err) -{ - gboolean rv; - - auto iter = run_query (q, expr, opts, err); - if (!iter) - return FALSE; - - rv = output_query_results (iter, opts, err); - mu_msg_iter_destroy (iter); - - return rv; + return output_query_results (*qres, opts, err); } static gboolean execute_find (const Store& store, const MuConfig *opts, GError **err) { - auto q{get_query_obj (store, err)}; + auto q{get_query_obj (store, err)}; + auto expr{get_query (opts, err)}; + if (!expr) + return FALSE; - auto expr{get_query (opts, err)}; - if (!expr) - return FALSE; - - if (opts->format == MU_CONFIG_FORMAT_XQUERY) - return print_internal (q, expr, TRUE, FALSE, err); - else if (opts->format == MU_CONFIG_FORMAT_MQUERY) - return print_internal (q, expr, FALSE, - opts->verbose, err); - else - return process_query (q, expr, opts, err); + if (opts->format == MU_CONFIG_FORMAT_XQUERY) + return print_internal (q, *expr, TRUE, FALSE, err); + else if (opts->format == MU_CONFIG_FORMAT_MQUERY) + return print_internal (q, *expr, FALSE, + opts->verbose, err); + else + return process_query (q, *expr, opts, err); } static gboolean format_params_valid (const MuConfig *opts, GError **err) { - switch (opts->format) { - case MU_CONFIG_FORMAT_EXEC: - break; - case MU_CONFIG_FORMAT_PLAIN: - case MU_CONFIG_FORMAT_SEXP: - case MU_CONFIG_FORMAT_JSON: - case MU_CONFIG_FORMAT_LINKS: - case MU_CONFIG_FORMAT_XML: - case MU_CONFIG_FORMAT_XQUERY: - case MU_CONFIG_FORMAT_MQUERY: - if (opts->exec) { - mu_util_g_set_error - (err, MU_ERROR_IN_PARAMETERS, - "--exec and --format cannot be combined"); - return FALSE; - } - break; - default: mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, - "invalid output format %s", - opts->formatstr ? opts->formatstr : ""); - return FALSE; - } + switch (opts->format) { + case MU_CONFIG_FORMAT_EXEC: + break; + case MU_CONFIG_FORMAT_PLAIN: + case MU_CONFIG_FORMAT_SEXP: + case MU_CONFIG_FORMAT_JSON: + case MU_CONFIG_FORMAT_LINKS: + case MU_CONFIG_FORMAT_XML: + case MU_CONFIG_FORMAT_XQUERY: + case MU_CONFIG_FORMAT_MQUERY: + if (opts->exec) { + mu_util_g_set_error + (err, MU_ERROR_IN_PARAMETERS, + "--exec and --format cannot be combined"); + return FALSE; + } + break; + default: mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, + "invalid output format %s", + opts->formatstr ? opts->formatstr : ""); + return FALSE; + } - if (opts->format == MU_CONFIG_FORMAT_LINKS && !opts->linksdir) { - mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, - "missing --linksdir argument"); - return FALSE; - } + if (opts->format == MU_CONFIG_FORMAT_LINKS && !opts->linksdir) { + mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, + "missing --linksdir argument"); + return FALSE; + } - if (opts->linksdir && opts->format != MU_CONFIG_FORMAT_LINKS) { - mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, - "--linksdir is only valid with --format=links"); - return FALSE; - } + if (opts->linksdir && opts->format != MU_CONFIG_FORMAT_LINKS) { + mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, + "--linksdir is only valid with --format=links"); + return FALSE; + } - return TRUE; + return TRUE; } static gboolean query_params_valid (const MuConfig *opts, GError **err) { - const gchar *xpath; + const gchar *xpath; - if (!opts->params[1]) { - mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, - "missing query"); - return FALSE; - } + if (!opts->params[1]) { + mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, + "missing query"); + return FALSE; + } - xpath = mu_runtime_path (MU_RUNTIME_PATH_XAPIANDB); - if (mu_util_check_dir (xpath, TRUE, FALSE)) - return TRUE; + xpath = mu_runtime_path (MU_RUNTIME_PATH_XAPIANDB); + if (mu_util_check_dir (xpath, TRUE, FALSE)) + return TRUE; - mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_READ, - "'%s' is not a readable Xapian directory", - xpath); - return FALSE; + mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_READ, + "'%s' is not a readable Xapian directory", + xpath); + return FALSE; } MuError -mu_cmd_find (const Store& store, const MuConfig *opts, GError **err) +Mu::mu_cmd_find (const Store& store, const MuConfig *opts, GError **err) { - g_return_val_if_fail (opts, MU_ERROR_INTERNAL); - g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_FIND, - MU_ERROR_INTERNAL); + g_return_val_if_fail (opts, MU_ERROR_INTERNAL); + g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_FIND, + MU_ERROR_INTERNAL); MuConfig myopts{*opts}; - if (myopts.exec) - myopts.format = MU_CONFIG_FORMAT_EXEC; /* pseudo format */ + if (myopts.exec) + myopts.format = MU_CONFIG_FORMAT_EXEC; /* pseudo format */ - if (!query_params_valid (&myopts, err) || - !format_params_valid(&myopts, err)) - return MU_G_ERROR_CODE (err); + if (!query_params_valid (&myopts, err) || + !format_params_valid(&myopts, err)) + return MU_G_ERROR_CODE (err); - if (!execute_find (store, &myopts, err)) - return MU_G_ERROR_CODE(err); - else - return MU_OK; + if (!execute_find (store, &myopts, err)) + return MU_G_ERROR_CODE(err); + else + return MU_OK; } diff --git a/mu/mu-cmd-index.cc b/mu/mu-cmd-index.cc index f972974e..53665cde 100644 --- a/mu/mu-cmd-index.cc +++ b/mu/mu-cmd-index.cc @@ -30,7 +30,7 @@ #include #include -#include "mu-msg.h" +#include "mu-msg.hh" #include "index/mu-indexer.hh" #include "mu-store.hh" #include "mu-runtime.hh" @@ -81,7 +81,7 @@ print_stats (const Indexer::Progress& stats, bool color) MuError -mu_cmd_index (Mu::Store& store, const MuConfig *opts, GError **err) +Mu::mu_cmd_index (Mu::Store& store, const MuConfig *opts, GError **err) { g_return_val_if_fail (opts, MU_ERROR); g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_INDEX, MU_ERROR); diff --git a/mu/mu-cmd-script.cc b/mu/mu-cmd-script.cc index fefdbd3c..48170ee7 100644 --- a/mu/mu-cmd-script.cc +++ b/mu/mu-cmd-script.cc @@ -41,6 +41,8 @@ #define COL(C) ((color)?C:"") +using namespace Mu; + static void print_script (const char *name, const char *oneline, const char *descr, gboolean color, gboolean verbose) @@ -163,7 +165,7 @@ check_params (const MuConfig *opts, GError **err) MuError -mu_cmd_script (const MuConfig *opts, GError **err) +Mu::mu_cmd_script (const MuConfig *opts, GError **err) { MuScriptInfo *msi; GSList *scripts; diff --git a/mu/mu-cmd-server.cc b/mu/mu-cmd-server.cc index 0796761c..82c6095e 100644 --- a/mu/mu-cmd-server.cc +++ b/mu/mu-cmd-server.cc @@ -88,7 +88,7 @@ output_sexp_stdout (Sexp&& sexp) } MuError -mu_cmd_server (const MuConfig *opts, GError **err) try { +Mu::mu_cmd_server (const MuConfig *opts, GError **err) try { Store store{mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), false/*writable*/}; Server server{store, output_sexp_stdout}; diff --git a/mu/mu-cmd.cc b/mu/mu-cmd.cc index 3a65f21a..65457887 100644 --- a/mu/mu-cmd.cc +++ b/mu/mu-cmd.cc @@ -29,13 +29,13 @@ #include -#include "mu-msg.h" -#include "mu-msg-part.h" +#include "mu-msg.hh" +#include "mu-msg-part.hh" #include "mu-cmd.hh" -#include "mu-maildir.h" +#include "mu-maildir.hh" #include "mu-contacts.hh" #include "mu-runtime.hh" -#include "mu-flags.h" +#include "mu-flags.hh" #include "utils/mu-util.h" #include "utils/mu-str.h" @@ -45,15 +45,13 @@ #define VIEW_TERMINATOR '\f' /* form-feed */ +using namespace Mu; + static gboolean view_msg_sexp (MuMsg *msg, const MuConfig *opts) { - char *sexp; - - sexp = mu_msg_to_sexp (msg, 0, NULL, mu_config_get_msg_options(opts)); - fputs (sexp, stdout); - g_free (sexp); - + ::fputs(msg_to_sexp(msg,0,{}, mu_config_get_msg_options(opts)) + .to_sexp_string(). c_str(), stdout); return TRUE; } @@ -689,7 +687,7 @@ check_params (const MuConfig *opts, GError **err) } MuError -mu_cmd_execute (const MuConfig *opts, GError **err) try +Mu::mu_cmd_execute (const MuConfig *opts, GError **err) try { MuError merr; diff --git a/mu/mu-cmd.hh b/mu/mu-cmd.hh index 8f6b50df..403af3e1 100644 --- a/mu/mu-cmd.hh +++ b/mu/mu-cmd.hh @@ -17,15 +17,14 @@ ** */ -#ifndef __MU_CMD_H__ -#define __MU_CMD_H__ +#ifndef MU_CMD_HH__ +#define MU_CMD_HH__ #include #include #include -G_BEGIN_DECLS - +namespace Mu { /** * execute the 'find' command * @@ -107,6 +106,7 @@ MuError mu_cmd_index (Mu::Store& store, const MuConfig *opt, GError **err); */ MuError mu_cmd_server (const MuConfig *opts, GError **err); -G_END_DECLS + +} // namespace Mu #endif /*__MU_CMD_H__*/ diff --git a/mu/mu-config.cc b/mu/mu-config.cc index 0527b9d4..3a6a9b63 100644 --- a/mu/mu-config.cc +++ b/mu/mu-config.cc @@ -26,14 +26,13 @@ #include "mu-config.hh" #include "mu-cmd.hh" -#include "mu-msg.h" +using namespace Mu; static MuConfig MU_CONFIG; #define color_maybe(C) (MU_CONFIG.nocolor ? "" : (C)) - static MuConfigFormat get_output_format (const char *formatstr) { @@ -627,7 +626,7 @@ get_help_string (MuConfigCmd cmd, gboolean long_help) void -mu_config_show_help (MuConfigCmd cmd) +Mu::mu_config_show_help (MuConfigCmd cmd) { GOptionContext *ctx; GOptionGroup *group; @@ -725,15 +724,13 @@ parse_params (int *argcp, char ***argvp, GError **err) MuConfig* -mu_config_init (int *argcp, char ***argvp, GError **err) +Mu::mu_config_init (int *argcp, char ***argvp, GError **err) { g_return_val_if_fail (argcp && argvp, NULL); memset (&MU_CONFIG, 0, sizeof(MU_CONFIG)); - MU_CONFIG.maxnum = -1; /* By default, output all matching entries. */ - - if (!parse_cmd (argcp, argvp, err)) + if (!parse_cmd (argcp, argvp, err)) goto errexit; if (!parse_params(argcp, argvp, err)) @@ -757,7 +754,7 @@ errexit: void -mu_config_uninit (MuConfig *opts) +Mu::mu_config_uninit (MuConfig *opts) { if (!opts) return; @@ -782,7 +779,7 @@ mu_config_uninit (MuConfig *opts) } size_t -mu_config_param_num (const MuConfig *opts) +Mu::mu_config_param_num (const MuConfig *opts) { size_t n; @@ -794,7 +791,7 @@ mu_config_param_num (const MuConfig *opts) MuMsgOptions -mu_config_get_msg_options (const MuConfig *muopts) +Mu::mu_config_get_msg_options (const MuConfig *muopts) { int opts; diff --git a/mu/mu-config.hh b/mu/mu-config.hh index 84931033..93c465bf 100644 --- a/mu/mu-config.hh +++ b/mu/mu-config.hh @@ -17,21 +17,20 @@ ** */ -#ifndef __MU_CONFIG_H__ -#define __MU_CONFIG_H__ +#ifndef MU_CONFIG_HH__ +#define MU_CONFIG_HH__ #include #include /* for mode_t */ #include -#include +#include #include -G_BEGIN_DECLS +namespace Mu { /* env var; if non-empty, color are disabled */ #define MU_NOCOLOR "MU_NOCOLOR" - typedef enum { MU_CONFIG_FORMAT_UNKNOWN = 0, @@ -257,6 +256,6 @@ MuMsgOptions mu_config_get_msg_options (const MuConfig *opts); */ void mu_config_show_help (const MuConfigCmd cmd); -G_END_DECLS +} // namespace Mu. #endif /*__MU_CONFIG_H__*/