e00231e2622ed3ae4f3469f0650caa999b21460d
[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 "defs.h"
25 #include <glib.h>
26
27 #if HAVE_LOCALE_H
28 #  include <locale.h>
29 #endif
30
31 #include "sylpheed.h"
32 #include "intl.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 static gchar *startup_dir;
40
41 /**
42  * Parse program parameters and remove all parameters
43  * that have been processed. Arguments are pointers to
44  * original passed programm arguments and these will
45  * be modified leaving only unknown parameters for
46  * further processing
47  *
48  * \param argc pointer to number of parameters
49  * \param argv pointer to array of parameter strings
50  */
51 static void parse_parameter(int *argc, char ***argv)
52 {
53         gint i, j, k;
54
55         g_return_if_fail(argc != NULL);
56         g_return_if_fail(argv != NULL);
57
58         for (i = 1; i < *argc;) {
59                 if (strcmp("--debug", (*argv)[i]) == 0) {
60                         debug_set_mode(TRUE);
61
62                         (*argv)[i] = NULL;
63                 }
64
65                 i += 1;
66         }
67
68         /* Remove NULL args from argv[] for further processing */
69         for (i = 1; i < *argc; i++) {
70                 for (k = i; k < *argc; k++)
71                         if ((*argv)[k] != NULL)
72                                 break;
73
74                 if (k > i) {
75                         k -= i;
76                         for (j = i + k; j < *argc; j++)
77                                 (*argv)[j - k] = (*argv)[j];
78                         *argc -= k;
79                 }
80         }
81 }
82
83 gboolean sylpheed_init(int *argc, char ***argv)
84 {
85         if (sylpheed_initialized)
86                 return TRUE;
87
88         startup_dir = g_get_current_dir();
89
90         parse_parameter(argc, argv);
91
92         debug_print("Starting sylpheed version %08x\n", VERSION_NUMERIC);
93
94         setlocale(LC_ALL, "");
95         bindtextdomain(PACKAGE, LOCALEDIR);
96         textdomain(PACKAGE);
97
98         /* backup if old rc file exists */
99         if (is_file_exist(RC_DIR)) {
100                 if (rename(RC_DIR, RC_DIR ".bak") < 0) {
101                         FILE_OP_ERROR(RC_DIR, "rename");
102                         return FALSE;
103                 }
104         }
105
106         srandom((gint)time(NULL));
107
108 #if USE_OPENSSL
109         ssl_init();
110 #endif
111
112         plugin_load_all("Common");
113
114         sylpheed_initialized = TRUE;
115
116         return TRUE;
117 }
118
119 void sylpheed_done(void)
120 {
121         plugin_unload_all("Common");
122
123 #if USE_OPENSSL
124         ssl_done();
125 #endif
126 }
127
128 const gchar *sylpheed_get_startup_dir(void)
129 {
130         return startup_dir;
131 }
132
133 guint sylpheed_get_version(void)
134 {
135         return VERSION_NUMERIC;
136 }