summaryrefslogtreecommitdiff
path: root/src/mu.cc
blob: a69a00c4c773b657328421956b903c51405fbebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** 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.
**
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/

#include <glib.h>
#include <stdio.h> /* for fileno() */

#include "mu-util.h"
#include "mu-config.h"
#include "mu-cmd.h"
#include "mu-log.h"

static gboolean
init_log (MuConfigOptions *opts)
{
	gboolean rv;
	
	if (opts->log_stderr)
		rv = mu_log_init_with_fd (fileno(stderr), FALSE,
					  opts->quiet, opts->debug);
	else
		rv = mu_log_init (opts->muhome, TRUE, opts->quiet,
				  opts->debug);

	/* we use g_printerr here because g_warning does not give
	 * the desired result when log initialization failed */
	if (!rv)
		g_printerr ("error: failed to initialize log\n");
	
	return rv;
}

int
main (int argc, char *argv[])
{
	MuConfigOptions config;
	gboolean rv;

	if (!mu_util_init_system()) 
		return 1;
	
	if (!mu_config_init (&config, &argc, &argv))
		return 1;

	if (!init_log (&config)) {
		mu_config_uninit (&config);
		return 1;
	}
			
	rv = mu_cmd_execute (&config);

	mu_log_uninit();

	mu_config_uninit (&config);
	
	return rv ? 0 : 1;
}