From 2b393ed7c56f3be731058bc60c8cb9ac48b23de6 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 30 Nov 2010 09:02:29 +0200 Subject: [PATCH] * make error messages more consistent --- src/mu-cmd-extract.c | 17 ++++++++++------- src/mu-cmd-find.c | 18 +++++++++--------- src/mu-cmd-index.c | 18 +++++++++++++----- src/mu-cmd-mkdir.c | 4 ++-- src/mu-cmd-view.c | 2 +- src/mu-config.c | 2 +- src/mu-str-normalize.c | 1 - 7 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/mu-cmd-extract.c b/src/mu-cmd-extract.c index 4627cb11..22016882 100644 --- a/src/mu-cmd-extract.c +++ b/src/mu-cmd-extract.c @@ -17,7 +17,7 @@ ** */ -#ifdef HAVE_CONFIG_H +#if HAVE_CONFIG_H #include "config.h" #endif /*HAVE_CONFIG_H*/ @@ -84,7 +84,8 @@ save_part_if (MuMsgPart *part, SaveData *sd) * the attachment check may be a bit too strict */ if (sd->attachments_only) if (!part->disposition || - ((g_ascii_strcasecmp (part->disposition, "attachment") != 0) && + ((g_ascii_strcasecmp (part->disposition, + "attachment") != 0) && g_ascii_strcasecmp (part->disposition, "inline"))) return; @@ -103,8 +104,8 @@ save_part_if (MuMsgPart *part, SaveData *sd) } static gboolean -save_certain_parts (MuMsg *msg, gboolean attachments_only, const gchar *targetdir, - gboolean overwrite) +save_certain_parts (MuMsg *msg, gboolean attachments_only, + const gchar *targetdir, gboolean overwrite) { SaveData sd; @@ -204,17 +205,19 @@ static gboolean check_params (MuConfigOptions *opts) { if (!opts->params[1]) { - g_warning ("missing mail file to extract something from"); + g_warning ("usage: mu extract [options] "); return FALSE; } if (!mu_util_check_dir(opts->targetdir, FALSE, TRUE)) { - g_warning ("target '%s' is not a writable directory", opts->targetdir); + g_warning ("target '%s' is not a writable directory", + opts->targetdir); return FALSE; } if (opts->save_attachments && opts->save_all) { - g_warning ("only one of --save-attachments and --save-all is allowed"); + g_warning ("only one of --save-attachments and" + " --save-all is allowed"); return FALSE; } diff --git a/src/mu-cmd-find.c b/src/mu-cmd-find.c index b00c3070..24dd069c 100644 --- a/src/mu-cmd-find.c +++ b/src/mu-cmd-find.c @@ -64,7 +64,7 @@ print_xapian_query (MuQuery *xapian, const gchar *query) err = NULL; querystr = mu_query_as_string (xapian, query, &err); if (!querystr) { - g_warning ("Error: %s", err->message); + g_warning ("error: %s", err->message); g_error_free (err); return FALSE; } @@ -156,7 +156,7 @@ run_query (MuQuery *xapian, const gchar *query, MuConfigOptions *opts) iter = mu_query_run (xapian, query, sortid, opts->descending ? FALSE : TRUE, 0, &err); if (!iter) { - g_warning ("Error: %s", err->message); + g_warning ("error: %s", err->message); g_error_free (err); return FALSE; } @@ -169,7 +169,7 @@ run_query (MuQuery *xapian, const gchar *query, MuConfigOptions *opts) opts->summary_len); if (matches == 0) - g_printerr ("No matches found\n"); + g_warning ("No matches found"); mu_msg_iter_destroy (iter); @@ -184,7 +184,7 @@ query_params_valid (MuConfigOptions *opts) if (opts->linksdir) if (opts->xquery) { - g_printerr ("Invalid option for '--linksdir'\n"); + g_warning ("invalid option for --linksdir"); return FALSE; } @@ -209,13 +209,13 @@ resolve_bookmark (MuConfigOptions *opts) bmfile = mu_runtime_bookmarks_file(); bm = mu_bookmarks_new (bmfile); if (!bm) { - g_warning ("Failed to open bookmarks file '%s'", bmfile); + g_warning ("failed to open bookmarks file '%s'", bmfile); return FALSE; } val = (gchar*)mu_bookmarks_lookup (bm, opts->bookmark); if (!val) - g_warning ("Bookmark '%s' not found", opts->bookmark); + g_warning ("bookmark '%s' not found", opts->bookmark); else val = g_strdup (val); @@ -232,7 +232,7 @@ get_query (MuConfigOptions *opts) /* params[0] is 'find', actual search params start with [1] */ if (!opts->bookmark && !opts->params[1]) { - g_warning ("Empty search query"); + g_warning ("usage: mu find [options] search-expression"); return FALSE; } @@ -260,7 +260,7 @@ static gboolean db_is_ready (const char *xpath) { if (mu_util_db_is_empty (xpath)) { - g_warning ("Database is empty; use 'mu index' to " + g_warning ("database is empty; use 'mu index' to " "add messages"); return FALSE; } @@ -301,7 +301,7 @@ mu_cmd_find (MuConfigOptions *opts) err = NULL; xapian = mu_query_new (xpath, &err); if (!xapian) { - g_warning ("Error: %s", err->message); + g_warning ("error: %s", err->message); g_error_free (err); return FALSE; } diff --git a/src/mu-cmd-index.c b/src/mu-cmd-index.c index ddc17e8a..24d5b663 100644 --- a/src/mu-cmd-index.c +++ b/src/mu-cmd-index.c @@ -78,8 +78,15 @@ install_sig_handler (void) static gboolean -check_index_params (MuConfigOptions *opts) +check_index_or_cleanup_params (MuConfigOptions *opts) { + /* param[0] == 'index' or 'cleanup', there should be no + * param[1] */ + if (opts->params[1]) { + g_warning ("usage: mu %s [options]", opts->params[0]); + return FALSE; + } + if (opts->linksdir || opts->xquery) { g_warning ("invalid option(s) for command"); return FALSE; @@ -223,10 +230,10 @@ cmd_index (MuIndex *midx, MuConfigOptions *opts, MuIndexStats *stats, g_message ("Indexing messages under %s [%s]", opts->maildir, mu_runtime_xapian_dir()); - + t = time (NULL); rv = mu_index_run (midx, opts->maildir, opts->reindex, stats, - show_progress ? index_msg_cb : index_msg_silent_cb, + show_progress ? index_msg_cb:index_msg_silent_cb, NULL, NULL); if (!opts->quiet) { @@ -241,7 +248,8 @@ cmd_index (MuIndex *midx, MuConfigOptions *opts, MuIndexStats *stats, } if (rv == MU_OK || rv == MU_STOP) { - MU_WRITE_LOG ("processed: %u; updated/new: %u, cleaned-up: %u", + MU_WRITE_LOG ("processed: %u; updated/new: %u, " + "cleaned-up: %u", stats->_processed, stats->_updated, stats->_cleaned_up); return TRUE; @@ -265,7 +273,7 @@ cmd_index_or_cleanup (MuConfigOptions *opts) g_return_val_if_fail (mu_cmd_equals (opts, "index") || mu_cmd_equals (opts, "cleanup"), FALSE); - if (!check_index_params (opts) || + if (!check_index_or_cleanup_params (opts) || !database_version_check_and_update(opts)) return FALSE; diff --git a/src/mu-cmd-mkdir.c b/src/mu-cmd-mkdir.c index fa29e5ba..7cff0a3d 100644 --- a/src/mu-cmd-mkdir.c +++ b/src/mu-cmd-mkdir.c @@ -39,9 +39,9 @@ mu_cmd_mkdir (MuConfigOptions *opts) g_return_val_if_fail (mu_cmd_equals (opts, "mkdir"), FALSE); if (!opts->params[1]) { - g_printerr ( + g_warning ( "usage: mu mkdir [-u,--mode=] " - " [more dirs]\n"); + " [more dirs]"); return FALSE; } diff --git a/src/mu-cmd-view.c b/src/mu-cmd-view.c index c40559e7..fd00c11a 100644 --- a/src/mu-cmd-view.c +++ b/src/mu-cmd-view.c @@ -73,7 +73,7 @@ mu_cmd_view (MuConfigOptions *opts) /* note: params[0] will be 'view' */ if (!opts->params[0] || !opts->params[1]) { - g_printerr ("Missing files to view\n"); + g_warning ("usage: mu view [options] []"); return FALSE; } diff --git a/src/mu-config.c b/src/mu-config.c index 8f18f011..9df5559e 100644 --- a/src/mu-config.c +++ b/src/mu-config.c @@ -256,7 +256,7 @@ parse_params (MuConfigOptions *opts, int *argcp, char ***argvp) err = NULL; rv = g_option_context_parse (context, argcp, argvp, &err); if (!rv) { - g_printerr ("error in options: %s\n", err->message); + g_warning ("error in options: %s\n", err->message); g_error_free (err); } diff --git a/src/mu-str-normalize.c b/src/mu-str-normalize.c index f35d2986..d5fa8018 100644 --- a/src/mu-str-normalize.c +++ b/src/mu-str-normalize.c @@ -81,7 +81,6 @@ mu_str_normalize_in_place (char *str, gboolean downcase) case 0x89: case 0x8a: case 0x8b: - g_printerr ("<%c>", downcase ? 'e' : 'E'); str[i++] = downcase ? 'e' : 'E'; break;