~ubuntu-branches/ubuntu/quantal/maildir-utils/quantal

« back to all changes in this revision

Viewing changes to toys/muile/muile.c

  • Committer: Package Import Robot
  • Author(s): Norbert Preining
  • Date: 2012-03-15 08:45:56 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20120315084556-vqdvw8sgodo24aji
Tags: 0.9.8.2-1
* several new upstream versions
* b-d on libgmime-2.6-dev (Closes: #664001, #664006)
* bump standards version to 3.9.3, no changes necessary
* switch to source format 3.0 (quilt): debian/control, debian/rules
* maildir-utils depends on dpkg/install-info (lintian warning)
* fix man page lintian warnings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
3
 
**
4
 
** This program is free software; you can redistribute it and/or modify it
5
 
** under the terms of the GNU General Public License as published by the
6
 
** Free Software Foundation; either version 3, or (at your option) any
7
 
** later version.
8
 
**
9
 
** This program is distributed in the hope that it will be useful,
10
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
** GNU General Public License for more details.
13
 
**
14
 
** You should have received a copy of the GNU General Public License
15
 
** along with this program; if not, write to the Free Software Foundation,
16
 
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
 
**
18
 
*/
19
 
#if HAVE_CONFIG_H
20
 
#include <config.h>
21
 
#endif /*HAVE_CONFIG_H*/
22
 
 
23
 
#include <mu-runtime.h>
24
 
#include <glib-object.h>
25
 
 
26
 
#include <libmuguile/mu-guile-common.h>
27
 
#include <libmuguile/mu-guile-msg.h>
28
 
 
29
 
struct _MuileConfig {
30
 
        const char *muhome;
31
 
        char *msgpath;
32
 
};
33
 
typedef struct _MuileConfig MuileConfig;
34
 
 
35
 
 
36
 
static MuileConfig *
37
 
muile_config_new (int *argcp, char ***argvp)
38
 
{
39
 
        GOptionContext *octx;
40
 
        MuileConfig *opts = g_new0 (MuileConfig, 1);
41
 
        GOptionEntry entries[] = {
42
 
                {"muhome", 0, 0, G_OPTION_ARG_FILENAME, &opts->muhome,
43
 
                 "specify an alternative mu directory", NULL},
44
 
                {"msg", 0, 0, G_OPTION_ARG_FILENAME, &opts->msgpath,
45
 
                 "specify path to a message to load as mu:current-msg)", NULL},
46
 
                {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}/* sentinel */
47
 
        };
48
 
 
49
 
        octx = g_option_context_new ("- muile options");
50
 
        g_option_context_add_main_entries (octx, entries, "Muile");
51
 
 
52
 
        if (!g_option_context_parse (octx, argcp, argvp, NULL)) {
53
 
                g_option_context_free (octx);
54
 
                g_printerr ("muile: error in options\n");
55
 
                return NULL;
56
 
        }
57
 
 
58
 
        if (opts->msgpath)
59
 
                opts->msgpath = mu_util_dir_expand (opts->msgpath);
60
 
        
61
 
        g_option_context_free (octx);
62
 
 
63
 
        return opts;    
64
 
}
65
 
 
66
 
static void
67
 
muile_config_destroy (MuileConfig *conf)
68
 
{
69
 
        g_free (conf->msgpath);
70
 
        g_free (conf);
71
 
}
72
 
 
73
 
 
74
 
static void
75
 
usage (void)
76
 
{
77
 
        g_print ("usage: muile [--muhome=<dir>] [msgfile]\n");  
78
 
}
79
 
 
80
 
 
81
 
int
82
 
main (int argc, char *argv[])
83
 
{
84
 
        MuileConfig *opts;
85
 
 
86
 
        g_type_init ();
87
 
        
88
 
#ifdef HAVE_PRE2_GUILE  
89
 
        g_warning ("Note: muile will not function correctly unless you have a "
90
 
                   "UTF-8 locale.");
91
 
#endif /* HAVE_PRE2_GUILE */
92
 
 
93
 
        opts = muile_config_new (&argc, &argv);
94
 
        if (!opts) {
95
 
                usage ();
96
 
                goto error;
97
 
        }
98
 
                
99
 
        if (!mu_runtime_init (opts->muhome /* NULL is okay */,
100
 
                              "muile")) {
101
 
                usage ();
102
 
                goto error;
103
 
        }
104
 
 
105
 
        mu_guile_init (); /* initialize mu guile modules */
106
 
        
107
 
        if (opts->msgpath) {
108
 
                if (!(gboolean)scm_with_guile
109
 
                    ((MuGuileFunc*)&mu_guile_msg_load_current, opts->msgpath))
110
 
                        goto error;
111
 
        }
112
 
 
113
 
        
114
 
        scm_shell (argc, argv);
115
 
 
116
 
        mu_runtime_uninit ();
117
 
        muile_config_destroy (opts);
118
 
        
119
 
        return 0;
120
 
 
121
 
error:
122
 
        muile_config_destroy (opts);
123
 
        return 1;
124
 
        
125
 
}