diff --git a/guile/mu-guile.cc b/guile/mu-guile.cc index 5d0a6850..077b8911 100644 --- a/guile/mu-guile.cc +++ b/guile/mu-guile.cc @@ -149,14 +149,14 @@ SCM_DEFINE_PUBLIC(mu_initialize, muhome = scm_to_utf8_string(MUHOME); rv = mu_guile_init_instance(muhome); - free(muhome); - - if (!rv) - return mu_guile_error(FUNC_NAME, 0, "Failed to initialize mu", SCM_UNSPECIFIED); + if (!rv) { + free(muhome); + mu_guile_error(FUNC_NAME, 0, "Failed to initialize mu", SCM_UNSPECIFIED); + } g_debug("mu-guile: initialized @ %s (%p)", - muhome ? muhome : "", - StoreSingleton.get()); + muhome ? muhome : "", StoreSingleton.get()); + free(muhome); /* cleanup when we're exiting */ atexit(mu_guile_uninit_instance); diff --git a/lib/mu-msg.cc b/lib/mu-msg.cc index 229527b8..107b7a80 100644 --- a/lib/mu-msg.cc +++ b/lib/mu-msg.cc @@ -282,20 +282,15 @@ get_str_field(MuMsg* self, MuMsgFieldId mfid) static gint64 get_num_field(MuMsg* self, MuMsgFieldId mfid) { - guint64 val; - - val = -1; if (self->_doc && mu_msg_field_xapian_value(mfid)) - val = mu_msg_doc_get_num_field(self->_doc, mfid); - else { - /* if we don't have a file object yet, we need to - * create it from the file on disk */ - if (!mu_msg_load_msg_file(self, NULL)) - return -1; - val = mu_msg_file_get_num_field(self->_file, mfid); - } + return mu_msg_doc_get_num_field(self->_doc, mfid); - return val; + /* if we don't have a file object yet, we need to + * create it from the file on disk */ + if (!mu_msg_load_msg_file(self, NULL)) + return -1; + + return mu_msg_file_get_num_field(self->_file, mfid); } const char* diff --git a/lib/mu-script.cc b/lib/mu-script.cc index ea9000af..aa35db9c 100644 --- a/lib/mu-script.cc +++ b/lib/mu-script.cc @@ -306,10 +306,6 @@ mu_script_guile_run(MuScriptInfo* msi, const char* muhome, const char** args, GE g_return_val_if_fail(msi, FALSE); g_return_val_if_fail(muhome, FALSE); - argv = g_new0(char*, 6); - argv[0] = g_strdup(GUILE_BINARY); - argv[1] = g_strdup("-l"); - if (access(mu_script_info_path(msi), R_OK) != 0) { mu_util_g_set_error(err, MU_ERROR_FILE_CANNOT_READ, @@ -318,13 +314,17 @@ mu_script_guile_run(MuScriptInfo* msi, const char* muhome, const char** args, GE return FALSE; } + argv = g_new0(char*, 6); + argv[0] = g_strdup(GUILE_BINARY); + argv[1] = g_strdup("-l"); + s = mu_script_info_path(msi); argv[2] = g_strdup(s ? s : ""); mainargs = mu_str_quoted_from_strv(args); expr = g_strdup_printf("(main '(\"%s\" \"--muhome=%s\" %s))", - mu_script_info_name(msi), - muhome, + mu_script_info_name(msi), + muhome, mainargs ? mainargs : ""); g_free(mainargs); diff --git a/lib/tests/test-mu-msg.cc b/lib/tests/test-mu-msg.cc index 75110dac..8bd6e488 100644 --- a/lib/tests/test-mu-msg.cc +++ b/lib/tests/test-mu-msg.cc @@ -283,7 +283,6 @@ test_mu_msg_references(void) g_assert_cmpstr((char*)refs->data, ==, "non-exist-03@msg.id"); refs = g_slist_next(refs); g_assert_cmpstr((char*)refs->data, ==, "non-exist-04@msg.id"); - refs = g_slist_next(refs); mu_msg_unref(msg); } @@ -313,7 +312,6 @@ test_mu_msg_references_dups(void) g_assert_cmpstr((char*)refs->data, ==, "439A1E03.3090604@euler.org"); refs = g_slist_next(refs); g_assert_cmpstr((char*)refs->data, ==, "20051211184308.GB13513@gauss.org"); - refs = g_slist_next(refs); mlist = mu_msg_get_mailing_list(msg); g_assert_cmpstr(mlist, ==, "Example of List Id"); diff --git a/lib/utils/tests/test-mu-util.c b/lib/utils/tests/test-mu-util.c index 05c37a6e..477ae415 100644 --- a/lib/utils/tests/test-mu-util.c +++ b/lib/utils/tests/test-mu-util.c @@ -31,216 +31,205 @@ #include "mu-util.h" static void -test_mu_util_dir_expand_00 (void) +test_mu_util_dir_expand_00(void) { #ifdef HAVE_WORDEXP_H gchar *got, *expected; - got = mu_util_dir_expand ("~/IProbablyDoNotExist"); - expected = g_strdup_printf ("%s%cIProbablyDoNotExist", - getenv("HOME"), G_DIR_SEPARATOR); + got = mu_util_dir_expand("~/IProbablyDoNotExist"); + expected = g_strdup_printf("%s%cIProbablyDoNotExist", + getenv("HOME"), G_DIR_SEPARATOR); - g_assert_cmpstr (got,==,expected); + g_assert_cmpstr(got, ==, expected); - g_free (got); - g_free (expected); + g_free(got); + g_free(expected); #endif /*HAVE_WORDEXP_H*/ } static void -test_mu_util_dir_expand_01 (void) +test_mu_util_dir_expand_01(void) { /* XXXX: the testcase does not work when using some dir * setups; (see issue #585), although the code should still * work. Turn of the test for now */ return; - #ifdef HAVE_WORDEXP_H { - gchar *got, *expected; + gchar *got, *expected; - got = mu_util_dir_expand ("~/Desktop"); - expected = g_strdup_printf ("%s%cDesktop", - getenv("HOME"), G_DIR_SEPARATOR); + got = mu_util_dir_expand("~/Desktop"); + expected = g_strdup_printf("%s%cDesktop", + getenv("HOME"), G_DIR_SEPARATOR); - g_assert_cmpstr (got,==,expected); + g_assert_cmpstr(got, ==, expected); - g_free (got); - g_free (expected); + g_free(got); + g_free(expected); } #endif /*HAVE_WORDEXP_H*/ } - - static void -test_mu_util_guess_maildir_01 (void) +test_mu_util_guess_maildir_01(void) { - char *got; - const char *expected; + char* got; + const char* expected; /* skip the test if there's no /tmp */ - if (access ("/tmp", F_OK)) + if (access("/tmp", F_OK)) return; - g_setenv ("MAILDIR", "/tmp", TRUE); + g_setenv("MAILDIR", "/tmp", TRUE); - got = mu_util_guess_maildir (); + got = mu_util_guess_maildir(); expected = "/tmp"; - g_assert_cmpstr (got,==,expected); - g_free (got); + g_assert_cmpstr(got, ==, expected); + g_free(got); } - static void -test_mu_util_guess_maildir_02 (void) +test_mu_util_guess_maildir_02(void) { char *got, *mdir; - g_unsetenv ("MAILDIR"); + g_unsetenv("MAILDIR"); - mdir = g_strdup_printf ("%s%cMaildir", - getenv("HOME"), G_DIR_SEPARATOR); - got = mu_util_guess_maildir (); + mdir = g_strdup_printf("%s%cMaildir", + getenv("HOME"), G_DIR_SEPARATOR); + got = mu_util_guess_maildir(); - if (access (mdir, F_OK) == 0) - g_assert_cmpstr (got, ==, mdir); + if (access(mdir, F_OK) == 0) + g_assert_cmpstr(got, ==, mdir); else - g_assert_cmpstr (got, == , NULL); + g_assert_cmpstr(got, ==, NULL); - g_free (got); - g_free (mdir); + g_free(got); + g_free(mdir); } - static void -test_mu_util_check_dir_01 (void) +test_mu_util_check_dir_01(void) { - if (g_access ("/usr/bin", F_OK) == 0) { - g_assert_cmpuint ( - mu_util_check_dir ("/usr/bin", TRUE, FALSE) == TRUE, - ==, - g_access ("/usr/bin", R_OK) == 0); + if (g_access("/usr/bin", F_OK) == 0) { + g_assert_cmpuint( + mu_util_check_dir("/usr/bin", TRUE, FALSE) == TRUE, + ==, + g_access("/usr/bin", R_OK) == 0); } } - static void -test_mu_util_check_dir_02 (void) +test_mu_util_check_dir_02(void) { - if (g_access ("/tmp", F_OK) == 0) { - g_assert_cmpuint ( - mu_util_check_dir ("/tmp", FALSE, TRUE) == TRUE, - ==, - g_access ("/tmp", W_OK) == 0); + if (g_access("/tmp", F_OK) == 0) { + g_assert_cmpuint( + mu_util_check_dir("/tmp", FALSE, TRUE) == TRUE, + ==, + g_access("/tmp", W_OK) == 0); } } - static void -test_mu_util_check_dir_03 (void) +test_mu_util_check_dir_03(void) { - if (g_access (".", F_OK) == 0) { - g_assert_cmpuint ( - mu_util_check_dir (".", TRUE, TRUE) == TRUE, - ==, - g_access (".", W_OK | R_OK) == 0); + if (g_access(".", F_OK) == 0) { + g_assert_cmpuint( + mu_util_check_dir(".", TRUE, TRUE) == TRUE, + ==, + g_access(".", W_OK | R_OK) == 0); } } - static void -test_mu_util_check_dir_04 (void) +test_mu_util_check_dir_04(void) { /* not a dir, so it must be false */ - g_assert_cmpuint ( - mu_util_check_dir ("test-util.c", TRUE, TRUE), - ==, - FALSE); + g_assert_cmpuint( + mu_util_check_dir("test-util.c", TRUE, TRUE), + ==, + FALSE); } static void -test_mu_util_get_dtype_with_lstat (void) +test_mu_util_get_dtype_with_lstat(void) { - g_assert_cmpuint ( - mu_util_get_dtype (MU_TESTMAILDIR, TRUE), ==, DT_DIR); - g_assert_cmpuint ( - mu_util_get_dtype (MU_TESTMAILDIR2, TRUE), ==, DT_DIR); - g_assert_cmpuint ( - mu_util_get_dtype (MU_TESTMAILDIR2 "/Foo/cur/mail5", TRUE), - ==, DT_REG); + g_assert_cmpuint( + mu_util_get_dtype(MU_TESTMAILDIR, TRUE), ==, DT_DIR); + g_assert_cmpuint( + mu_util_get_dtype(MU_TESTMAILDIR2, TRUE), ==, DT_DIR); + g_assert_cmpuint( + mu_util_get_dtype(MU_TESTMAILDIR2 "/Foo/cur/mail5", TRUE), + ==, DT_REG); } - static void -test_mu_util_supports (void) +test_mu_util_supports(void) { gboolean has_guile; - gchar *path; + gchar* path; - has_guile = FALSE; #ifdef BUILD_GUILE has_guile = TRUE; +#else + has_guile = FALSE; #endif /*BUILD_GUILE*/ - g_assert_cmpuint (mu_util_supports (MU_FEATURE_GUILE), == ,has_guile); + g_assert_cmpuint(mu_util_supports(MU_FEATURE_GUILE), ==, has_guile); - path = g_find_program_in_path ("gnuplot"); - g_free (path); + path = g_find_program_in_path("gnuplot"); + g_free(path); - g_assert_cmpuint (mu_util_supports (MU_FEATURE_GNUPLOT),==, - path ? TRUE : FALSE); + g_assert_cmpuint(mu_util_supports(MU_FEATURE_GNUPLOT), ==, + path ? TRUE : FALSE); - g_assert_cmpuint ( - mu_util_supports (MU_FEATURE_GNUPLOT|MU_FEATURE_GUILE), - ==, - has_guile && path ? TRUE : FALSE); + g_assert_cmpuint( + mu_util_supports(MU_FEATURE_GNUPLOT | MU_FEATURE_GUILE), + ==, + has_guile && path ? TRUE : FALSE); } - static void -test_mu_util_program_in_path (void) +test_mu_util_program_in_path(void) { - g_assert_cmpuint (mu_util_program_in_path("ls"),==,TRUE); + g_assert_cmpuint(mu_util_program_in_path("ls"), ==, TRUE); } - - int -main (int argc, char *argv[]) +main(int argc, char* argv[]) { - g_test_init (&argc, &argv, NULL); + g_test_init(&argc, &argv, NULL); /* mu_util_dir_expand */ - g_test_add_func ("/mu-util/mu-util-dir-expand-00", - test_mu_util_dir_expand_00); - g_test_add_func ("/mu-util/mu-util-dir-expand-01", - test_mu_util_dir_expand_01); + g_test_add_func("/mu-util/mu-util-dir-expand-00", + test_mu_util_dir_expand_00); + g_test_add_func("/mu-util/mu-util-dir-expand-01", + test_mu_util_dir_expand_01); /* mu_util_guess_maildir */ - g_test_add_func ("/mu-util/mu-util-guess-maildir-01", - test_mu_util_guess_maildir_01); - g_test_add_func ("/mu-util/mu-util-guess-maildir-02", - test_mu_util_guess_maildir_02); + g_test_add_func("/mu-util/mu-util-guess-maildir-01", + test_mu_util_guess_maildir_01); + g_test_add_func("/mu-util/mu-util-guess-maildir-02", + test_mu_util_guess_maildir_02); /* mu_util_check_dir */ - g_test_add_func ("/mu-util/mu-util-check-dir-01", - test_mu_util_check_dir_01); - g_test_add_func ("/mu-util/mu-util-check-dir-02", - test_mu_util_check_dir_02); - g_test_add_func ("/mu-util/mu-util-check-dir-03", - test_mu_util_check_dir_03); - g_test_add_func ("/mu-util/mu-util-check-dir-04", - test_mu_util_check_dir_04); + g_test_add_func("/mu-util/mu-util-check-dir-01", + test_mu_util_check_dir_01); + g_test_add_func("/mu-util/mu-util-check-dir-02", + test_mu_util_check_dir_02); + g_test_add_func("/mu-util/mu-util-check-dir-03", + test_mu_util_check_dir_03); + g_test_add_func("/mu-util/mu-util-check-dir-04", + test_mu_util_check_dir_04); - g_test_add_func ("/mu-util/mu-util-get-dtype-with-lstat", - test_mu_util_get_dtype_with_lstat); + g_test_add_func("/mu-util/mu-util-get-dtype-with-lstat", + test_mu_util_get_dtype_with_lstat); - g_test_add_func ("/mu-util/mu-util-supports", test_mu_util_supports); - g_test_add_func ("/mu-util/mu-util-program-in-path", - test_mu_util_program_in_path); + g_test_add_func("/mu-util/mu-util-supports", test_mu_util_supports); + g_test_add_func("/mu-util/mu-util-program-in-path", + test_mu_util_program_in_path); - return g_test_run (); + return g_test_run(); } diff --git a/mu/mu-config.cc b/mu/mu-config.cc index 0b99ff29..05ceb722 100644 --- a/mu/mu-config.cc +++ b/mu/mu-config.cc @@ -62,14 +62,14 @@ get_output_format(const char* formatstr) return MU_CONFIG_FORMAT_UNKNOWN; } -#define expand_dir(D) \ - if ((D)) { \ - char* exp; \ - exp = mu_util_dir_expand((D)); \ - if (exp) { \ - g_free((D)); \ - (D) = exp; \ - } \ +#define expand_dir(D) \ + if ((D)) { \ + char* exp; \ + exp = mu_util_dir_expand((D)); \ + if (exp) { \ + g_free((D)); \ + (D) = exp; \ + } \ } static void @@ -612,7 +612,7 @@ config_options_group_extract() "try to 'play' (open) the extracted parts", NULL}, {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}}; - og = g_option_group_new("extract", "Options for the 'extract' command", "", NULL, NULL); + og = g_option_group_new("extract", "Options for the 'extract' command", "", NULL, NULL); g_option_group_add_entries(og, entries); g_option_group_add_entries(og, crypto_option_entries()); @@ -758,7 +758,7 @@ massage_help(const char* help) GRegex* rx; char* str; - rx = g_regex_new("^Usage:.*\n.*\n", (GRegexCompileFlags)0, G_REGEX_MATCH_NEWLINE_ANY, NULL); + rx = g_regex_new("^Usage:.*\n.*\n", (GRegexCompileFlags)0, G_REGEX_MATCH_NEWLINE_ANY, NULL); str = g_regex_replace(rx, help, -1, 0, "", G_REGEX_MATCH_NEWLINE_ANY, NULL); g_regex_unref(rx); return str; @@ -841,8 +841,6 @@ parse_params(int* argcp, char*** argvp, GError** err) context = g_option_context_new("- mu general options"); g_option_context_set_help_enabled(context, TRUE); - rv = TRUE; - g_option_context_set_main_group(context, config_options_group_mu()); g_option_context_set_ignore_unknown_options(context, FALSE);