diff --git a/src/mu-bookmarks.c b/src/mu-bookmarks.c index 0211efad..1bbdbd15 100644 --- a/src/mu-bookmarks.c +++ b/src/mu-bookmarks.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 2010 Dirk-Jan C. Binnema +** Copyright (C) 2010-2011 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the @@ -23,8 +23,8 @@ #define MU_BOOKMARK_GROUP "mu" struct _MuBookmarks { - char *_bmpath; - GHashTable *_hash; + char *_bmpath; + GHashTable *_hash; }; @@ -73,7 +73,7 @@ create_hash_from_key_file (const gchar *bmpath) -MuBookmarks * +MuBookmarks* mu_bookmarks_new (const gchar *bmpath) { MuBookmarks *bookmarks; @@ -138,7 +138,7 @@ mu_bookmarks_foreach (MuBookmarks *bm, MuBookmarksForeachFunc func, g_return_if_fail (bm); g_return_if_fail (func); - bmdata._func = func; + bmdata._func = func; bmdata._user_data = user_data; g_hash_table_foreach (bm->_hash, (GHFunc)each_bookmark, &bmdata); diff --git a/src/mu-log.c b/src/mu-log.c index 440bae50..c76e487a 100644 --- a/src/mu-log.c +++ b/src/mu-log.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 2008-2010 Dirk-Jan C. Binnema +** Copyright (C) 2008-2011 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ ** */ -#ifdef HAVE_CONFIG_H +#if HAVE_CONFIG_H #include #endif /*HAVE_CONFIG_H*/ @@ -35,10 +35,11 @@ #include "mu-util.h" +#define MU_MAX_LOG_FILE_SIZE 1000 * 1000 /* 1 MB (SI units) */ #define MU_LOG_FILE "mu.log" struct _MuLog { - int _fd; /* log file descriptor */ + int _fd; /* log file descriptor */ gboolean _own; /* close _fd with log_destroy? */ gboolean _debug; /* add debug-level stuff? */ @@ -48,8 +49,10 @@ struct _MuLog { }; typedef struct _MuLog MuLog; +/* we use globals, because logging is a global operation as it + * globally modifies the behaviour of g_warning and friends + */ static MuLog* MU_LOG = NULL; - static void log_write (const char* domain, GLogLevelFlags level, const gchar *msg); @@ -61,7 +64,7 @@ try_close (int fd) if (close (fd) < 0) g_printerr ("%s: close() of fd %d failed: %s\n", - __FUNCTION__, fd, strerror(errno)); + __FUNCTION__, fd, strerror(errno)); } static void @@ -99,7 +102,7 @@ log_handler (const gchar* log_domain, GLogLevelFlags log_level, gboolean mu_log_init_with_fd (int fd, gboolean doclose, - gboolean quiet, gboolean debug) + gboolean quiet, gboolean debug) { g_return_val_if_fail (!MU_LOG, FALSE); @@ -145,7 +148,8 @@ log_file_backup_maybe (const char *logfile) if (errno == ENOENT) return TRUE; /* it did not exist yet, no problem */ else { - g_warning ("failed to stat(2) %s", logfile); + g_warning ("failed to stat(2) %s: %s", + logfile, strerror(errno)); return FALSE; } } @@ -207,6 +211,7 @@ mu_log_uninit (void) try_close (MU_LOG->_fd); g_free (MU_LOG); + MU_LOG = NULL; } @@ -215,13 +220,13 @@ static const char* pfx (GLogLevelFlags level) { switch (level) { - case G_LOG_LEVEL_WARNING: return "WARN"; - case G_LOG_LEVEL_ERROR : return "ERR "; - case G_LOG_LEVEL_DEBUG: return "DBG "; - case G_LOG_LEVEL_CRITICAL : return "CRIT"; - case G_LOG_LEVEL_MESSAGE: return "MSG "; - case G_LOG_LEVEL_INFO : return "INFO"; - default: return "LOG "; + case G_LOG_LEVEL_WARNING: return "WARN"; + case G_LOG_LEVEL_ERROR : return "ERR "; + case G_LOG_LEVEL_DEBUG: return "DBG "; + case G_LOG_LEVEL_CRITICAL: return "CRIT"; + case G_LOG_LEVEL_MESSAGE: return "MSG "; + case G_LOG_LEVEL_INFO : return "INFO"; + default: return "LOG "; } } diff --git a/src/mu-log.h b/src/mu-log.h index dcd6bd8b..5a90c499 100644 --- a/src/mu-log.h +++ b/src/mu-log.h @@ -26,8 +26,6 @@ G_BEGIN_DECLS -#define MU_MAX_LOG_FILE_SIZE 1000 * 1000 /* 1 MB (SI units) */ - /** * write logging information to a log file * @@ -41,7 +39,8 @@ G_BEGIN_DECLS * @return TRUE if initialization succeeds, FALSE otherwise */ gboolean mu_log_init (const char* muhome, gboolean backup, - gboolean quiet, gboolean debug); + gboolean quiet, gboolean debug) + G_GNUC_WARN_UNUSED_RESULT; /** * write logging information to a file descriptor @@ -54,7 +53,7 @@ gboolean mu_log_init (const char* muhome, gboolean backup, * @return TRUE if initialization succeeds, FALSE otherwise */ gboolean mu_log_init_with_fd (int fd, gboolean doclose, gboolean quiet, - gboolean debug); + gboolean debug) G_GNUC_WARN_UNUSED_RESULT; /** * be absolutely silent, except for runtime errors, which will be @@ -62,8 +61,7 @@ gboolean mu_log_init_with_fd (int fd, gboolean doclose, gboolean quiet, * * @return TRUE if initialization succeeds, FALSE otherwise */ -gboolean mu_log_init_silence (void); - +gboolean mu_log_init_silence (void) G_GNUC_WARN_UNUSED_RESULT; /** * unitialize the logging system, and free all resources diff --git a/src/mu-msg-flags.h b/src/mu-msg-flags.h index af4be638..a343f77a 100644 --- a/src/mu-msg-flags.h +++ b/src/mu-msg-flags.h @@ -59,11 +59,11 @@ enum _MuMsgFlags { /* these we get from the contents */ /* "Z"->signed message */ - MU_MSG_FLAG_SIGNED = 1 << 7, + MU_MSG_FLAG_SIGNED = 1 << 7, /* "X"->encrypted message */ - MU_MSG_FLAG_ENCRYPTED = 1 << 8, + MU_MSG_FLAG_ENCRYPTED = 1 << 8, /* "A"->message has attachment */ - MU_MSG_FLAG_HAS_ATTACH = 1 << 9 + MU_MSG_FLAG_HAS_ATTACH = 1 << 9 }; typedef enum _MuMsgFlags MuMsgFlags; diff --git a/src/mu-output-plain.c b/src/mu-output-plain.c deleted file mode 100644 index 9727b6f0..00000000 --- a/src/mu-output-plain.c +++ /dev/null @@ -1,126 +0,0 @@ -/* -** Copyright (C) 2008-2011 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#if HAVE_CONFIG_H -#include "config.h" -#endif /*HAVE_CONFIG_H*/ - -#include -#include -#include -#include - -#include "mu-msg.h" -#include "mu-maildir.h" -#include "mu-index.h" -#include "mu-msg-iter.h" -#include "mu-str.h" - -#include "mu-output-plain.h" - - -static const gchar* -display_field (MuMsgIter *iter, MuMsgFieldId mfid) -{ - gint64 val; - - switch (mu_msg_field_type(mfid)) { - case MU_MSG_FIELD_TYPE_STRING: - return mu_msg_iter_get_field (iter, mfid); - - case MU_MSG_FIELD_TYPE_INT: - - if (mfid == MU_MSG_FIELD_ID_PRIO) { - val = mu_msg_iter_get_field_numeric (iter, mfid); - return mu_msg_prio_name ((MuMsgPrio)val); - } else if (mfid == MU_MSG_FIELD_ID_FLAGS) { - val = mu_msg_iter_get_field_numeric (iter, mfid); - return mu_str_flags_s ((MuMsgFlags)val); - } else /* as string */ - return mu_msg_iter_get_field (iter, mfid); - - case MU_MSG_FIELD_TYPE_TIME_T: - val = mu_msg_iter_get_field_numeric (iter, mfid); - return mu_str_date_s ("%c", (time_t)val); - - case MU_MSG_FIELD_TYPE_BYTESIZE: - val = mu_msg_iter_get_field_numeric (iter, mfid); - return mu_str_size_s ((unsigned)val); - default: - g_return_val_if_reached (NULL); - } -} - - -static void -print_summary (MuMsgIter *iter, size_t summary_len) -{ - GError *err; - const char *summ; - MuMsg *msg; - - err = NULL; - msg = mu_msg_iter_get_msg (iter, &err); - if (!msg) { - g_warning ("error get message: %s", err->message); - g_error_free (err); - return; - } - - summ = mu_msg_get_summary (msg, summary_len); - g_print ("Summary: %s\n", summ ? summ : ""); - - mu_msg_destroy (msg); -} - - - -gboolean -mu_output_plain_row (MuMsgIter *iter, const char *fields, size_t summary_len) -{ - const char* myfields; - int len = 0; - - g_return_val_if_fail (iter, FALSE); - g_return_val_if_fail (fields, FALSE); - g_return_val_if_fail (!mu_msg_iter_is_done(iter), FALSE); - - myfields = fields; - while (*myfields) { - 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))) - len += printf ("%c", *myfields); - else - len += printf ("%s", - display_field(iter, mfid)); - ++myfields; - } - - if (len > 0) - g_print ("\n"); - - if (summary_len > 0) - print_summary (iter, summary_len); - - return TRUE; -} - diff --git a/src/mu-output-plain.h b/src/mu-output-plain.h deleted file mode 100644 index 3d3abdab..00000000 --- a/src/mu-output-plain.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -** Copyright (C) 2008-2010 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#ifndef __MU_OUTPUT_PLAIN_H__ -#define __MU_OUTPUT_PLAIN_H__ - -/** - * print a row (message) to standard output - * - * @param iter iterator pointing to a message row - * @param fields the fields to print (see MuMsgFields) - * @param summary_len number of lines to include in message summary - * - * @return TRUE if the printing succeeded, FALSE in case of error - */ -gboolean mu_output_plain_row (MuMsgIter *iter, const char *fields, - size_t summary_len); - -#endif /*__MU_OUTPUT_PLAIN_H__*/ diff --git a/src/mu-str.h b/src/mu-str.h index 2b68abfa..715d3168 100644 --- a/src/mu-str.h +++ b/src/mu-str.h @@ -150,7 +150,6 @@ char* mu_str_normalize (const char *str, gboolean downcase) * optionally, downcase it. this happen by changing the string; if * that is not desired, use mu_str_normalize. Works for accented chars * in Unicode Blocks 'Latin-1 Supplement' and 'Latin Extended-A' - * * * @param str a valid utf8 string or NULL * @param downcase if TRUE, convert the string to lowercase @@ -188,7 +187,8 @@ char* mu_str_ascii_xapian_escape_in_place (char *query); * * @return the escaped string (free with g_free) or NULL in case of error */ -char* mu_str_ascii_xapian_escape (const char *query); +char* mu_str_ascii_xapian_escape (const char *query) + G_GNUC_WARN_UNUSED_RESULT; /** * @@ -227,7 +227,6 @@ time_t mu_str_date_parse_hdwmy (const char* str); */ guint64 mu_str_size_parse_kmg (const char* str); - /** * create a full path from a path + a filename. function is _not_ * reentrant. @@ -248,7 +247,8 @@ const char* mu_str_fullpath_s (const char* path, const char* name); * * @return the escaped string, newly allocated (free with g_free) */ -char* mu_str_escape_c_literal (const gchar* str); +char* mu_str_escape_c_literal (const gchar* str) + G_GNUC_WARN_UNUSED_RESULT; G_END_DECLS