* mu-config.[ch]: better option checking, default setting, fix some small leaks

This commit is contained in:
Dirk-Jan C. Binnema 2010-01-06 01:24:37 +02:00
parent d0592a2aa9
commit 8262f2c4d8
2 changed files with 31 additions and 8 deletions

View File

@ -62,7 +62,7 @@ mu_config_options_group_index (MuConfigOptions *opts)
{"maildir", 'm', 0, G_OPTION_ARG_FILENAME, &opts->maildir, {"maildir", 'm', 0, G_OPTION_ARG_FILENAME, &opts->maildir,
"top of the maildir", NULL}, "top of the maildir", NULL},
{"reindex", 'r', 0, G_OPTION_ARG_NONE, &opts->reindex, {"reindex", 'r', 0, G_OPTION_ARG_NONE, &opts->reindex,
"index alread indexed messages too", NULL}, "index already indexed messages too", NULL},
{"cleanup", 'u', 0, G_OPTION_ARG_NONE, &opts->cleanup, {"cleanup", 'u', 0, G_OPTION_ARG_NONE, &opts->cleanup,
"cleanup database after indexing", NULL}, "cleanup database after indexing", NULL},
{ NULL, 0, 0, 0, NULL, NULL, NULL } { NULL, 0, 0, 0, NULL, NULL, NULL }
@ -114,27 +114,48 @@ mu_config_init (MuConfigOptions *opts)
memset (opts, 0, sizeof(MuConfigOptions)); memset (opts, 0, sizeof(MuConfigOptions));
} }
static gchar*
_guess_muhome (void)
{
const char* home;
home = g_getenv ("HOME");
if (!home)
home = g_get_home_dir ();
if (!home)
MU_WRITE_LOG ("failed to determine homedir");
return g_strdup_printf ("%s%c%s", home ? home : ".", G_DIR_SEPARATOR,
".mu");
}
void void
mu_config_set_defaults (MuConfigOptions *opts) mu_config_set_defaults (MuConfigOptions *opts)
{ {
gchar *old;
g_return_if_fail (opts); g_return_if_fail (opts);
if (!opts->muhome) if (!opts->muhome)
opts->muhome = "~/.mu"; opts->muhome = _guess_muhome ();
opts->muhome = mu_util_dir_expand ("~/.mu");
opts->log_stderr = FALSE; /* note: xpath is is *not* settable from the cmdline */
opts->xpath = g_strdup_printf ("%s%c%s", opts->muhome,G_DIR_SEPARATOR,
MU_XAPIAN_DIR_NAME);
/* indexing */ /* indexing */
old = opts->maildir;
if (opts->maildir) if (opts->maildir)
opts->maildir = mu_util_dir_expand (opts->maildir); opts->maildir = mu_util_dir_expand (opts->maildir);
else else
opts->maildir = mu_util_guess_maildir(); opts->maildir = mu_util_guess_maildir();
g_free (old);
/* querying */ /* querying */
/* note, when no fields are specified, we use /* note, when no fields are specified, we use
* date-from-subject, and sort descending by date. If fiels * date-from-subject, and sort descending by date. If fields
* *are* specified, we sort in ascending order. */ * *are* specified, we sort in ascending order. */
if (!opts->fields) { if (!opts->fields) {
opts->descending = TRUE; opts->descending = TRUE;
@ -156,6 +177,7 @@ mu_config_uninit (MuConfigOptions *opts)
g_return_if_fail (opts); g_return_if_fail (opts);
g_free (opts->muhome); g_free (opts->muhome);
g_free (opts->xpath);
g_free (opts->maildir); g_free (opts->maildir);
g_free (opts->linksdir); g_free (opts->linksdir);

View File

@ -34,6 +34,7 @@ struct _MuConfigOptions {
gboolean quiet; /* don't give any output */ gboolean quiet; /* don't give any output */
gboolean debug; /* spew out debug info */ gboolean debug; /* spew out debug info */
char *muhome; /* the House of Mu */ char *muhome; /* the House of Mu */
char *xpath; /* path to the Xapian dir */
gboolean version; /* request mu version */ gboolean version; /* request mu version */
gboolean log_stderr; /* log to stderr (not logfile) */ gboolean log_stderr; /* log to stderr (not logfile) */
gchar** params; /* parameters (for querying) */ gchar** params; /* parameters (for querying) */