0.8.10claws50
[claws.git] / src / common / sylpheed.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999,2000 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <glib.h>
25
26 #if HAVE_LOCALE_H
27 #  include <locale.h>
28 #endif
29
30 #include "sylpheed.h"
31 #include "intl.h"
32 #include "defs.h"
33 #include "utils.h"
34 #include "ssl.h"
35 #include "version.h"
36 #include "plugin.h"
37
38 static gboolean sylpheed_initialized = FALSE;
39
40 /**
41  * Parse program parameters and remove all parameters
42  * that have been processed. Arguments are pointers to
43  * original passed programm arguments and these will
44  * be modified leaving only unknown parameters for
45  * further processing
46  *
47  * \param argc pointer to number of parameters
48  * \param argv pointer to array of parameter strings
49  */
50 static void parse_parameter(int *argc, char ***argv)
51 {
52         gint i, j, k;
53
54         g_return_if_fail(argc != NULL);
55         g_return_if_fail(argv != NULL);
56
57         for (i = 1; i < *argc;) {
58                 if (strcmp("--debug", (*argv)[i]) == 0) {
59                         debug_set_mode(TRUE);
60
61                         (*argv)[i] = NULL;
62                 }
63
64                 i += 1;
65         }
66
67         /* Remove NULL args from argv[] for further processing */
68         for (i = 1; i < *argc; i++) {
69                 for (k = i; k < *argc; k++)
70                         if ((*argv)[k] != NULL)
71                                 break;
72
73                 if (k > i) {
74                         k -= i;
75                         for (j = i + k; j < *argc; j++)
76                                 (*argv)[j - k] = (*argv)[j];
77                         *argc -= k;
78                 }
79         }
80 }
81
82 gboolean sylpheed_init(int *argc, char ***argv)
83 {
84         if (sylpheed_initialized)
85                 return TRUE;
86
87         parse_parameter(argc, argv);
88
89         setlocale(LC_ALL, "");
90         bindtextdomain(PACKAGE, LOCALEDIR);
91         textdomain(PACKAGE);
92
93         /* backup if old rc file exists */
94         if (is_file_exist(RC_DIR)) {
95                 if (rename(RC_DIR, RC_DIR ".bak") < 0) {
96                         FILE_OP_ERROR(RC_DIR, "rename");
97                         return FALSE;
98                 }
99         }
100
101         srandom((gint)time(NULL));
102
103 #if USE_OPENSSL
104         ssl_init();
105 #endif
106
107         plugin_load_all();
108
109         sylpheed_initialized = TRUE;
110
111         return TRUE;
112 }
113
114 void sylpheed_done()
115 {
116         plugin_unload_all();
117
118 #if USE_OPENSSL
119         ssl_done();
120 #endif
121 }