File: | fe-common/core/fe-common-core.c |
Location: | line 318, column 17 |
Description: | Value stored to 'window' is never read |
1 | /* |
2 | fe-common-core.c : irssi |
3 | |
4 | Copyright (C) 1999-2000 Timo Sirainen |
5 | |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. |
10 | |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU General Public License along |
17 | with this program; if not, write to the Free Software Foundation, Inc., |
18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 | */ |
20 | |
21 | #include "module.h" |
22 | #include "module-formats.h" |
23 | #include "args.h" |
24 | #include "misc.h" |
25 | #include "levels.h" |
26 | #include "settings.h" |
27 | |
28 | #include "servers.h" |
29 | #include "channels.h" |
30 | #include "servers-setup.h" |
31 | |
32 | #include "special-vars.h" |
33 | #include "fe-core-commands.h" |
34 | #include "fe-queries.h" |
35 | #include "hilight-text.h" |
36 | #include "command-history.h" |
37 | #include "completion.h" |
38 | #include "keyboard.h" |
39 | #include "printtext.h" |
40 | #include "formats.h" |
41 | #include "themes.h" |
42 | #include "fe-channels.h" |
43 | #include "fe-windows.h" |
44 | #include "window-activity.h" |
45 | #include "window-items.h" |
46 | #include "windows-layout.h" |
47 | #include "fe-recode.h" |
48 | |
49 | #include <signal.h> |
50 | |
51 | static char *autocon_server; |
52 | static char *autocon_password; |
53 | static int autocon_port; |
54 | static int no_autoconnect; |
55 | static char *cmdline_nick; |
56 | static char *cmdline_hostname; |
57 | |
58 | void fe_core_log_init(void); |
59 | void fe_core_log_deinit(void); |
60 | |
61 | void fe_exec_init(void); |
62 | void fe_exec_deinit(void); |
63 | |
64 | void fe_expandos_init(void); |
65 | void fe_expandos_deinit(void); |
66 | |
67 | void fe_help_init(void); |
68 | void fe_help_deinit(void); |
69 | |
70 | void fe_ignore_init(void); |
71 | void fe_ignore_deinit(void); |
72 | |
73 | void fe_ignore_messages_init(void); |
74 | void fe_ignore_messages_deinit(void); |
75 | |
76 | void fe_log_init(void); |
77 | void fe_log_deinit(void); |
78 | |
79 | void fe_messages_init(void); |
80 | void fe_messages_deinit(void); |
81 | |
82 | void fe_modules_init(void); |
83 | void fe_modules_deinit(void); |
84 | |
85 | void fe_server_init(void); |
86 | void fe_server_deinit(void); |
87 | |
88 | void fe_settings_init(void); |
89 | void fe_settings_deinit(void); |
90 | |
91 | void window_commands_init(void); |
92 | void window_commands_deinit(void); |
93 | |
94 | static void sig_setup_changed(void); |
95 | |
96 | static void sig_connected(SERVER_REC *server) |
97 | { |
98 | MODULE_DATA_SET(server, g_new0(MODULE_SERVER_REC, 1))g_hash_table_insert((server)->module_data, "fe-common/core" , ((MODULE_SERVER_REC *) g_malloc0 (((gsize) sizeof (MODULE_SERVER_REC )) * ((gsize) (1))))); |
99 | } |
100 | |
101 | static void sig_disconnected(SERVER_REC *server) |
102 | { |
103 | void *data = MODULE_DATA(server)g_hash_table_lookup((server)->module_data, "fe-common/core" ); |
104 | g_free(data); |
105 | MODULE_DATA_UNSET(server)g_hash_table_remove((server)->module_data, "fe-common/core" ); |
106 | } |
107 | |
108 | static void sig_channel_created(CHANNEL_REC *channel) |
109 | { |
110 | MODULE_DATA_SET(channel, g_new0(MODULE_CHANNEL_REC, 1))g_hash_table_insert((channel)->module_data, "fe-common/core" , ((MODULE_CHANNEL_REC *) g_malloc0 (((gsize) sizeof (MODULE_CHANNEL_REC )) * ((gsize) (1))))); |
111 | } |
112 | |
113 | static void sig_channel_destroyed(CHANNEL_REC *channel) |
114 | { |
115 | void *data = MODULE_DATA(channel)g_hash_table_lookup((channel)->module_data, "fe-common/core" ); |
116 | |
117 | g_free(data); |
118 | MODULE_DATA_UNSET(channel)g_hash_table_remove((channel)->module_data, "fe-common/core" ); |
119 | } |
120 | |
121 | void fe_common_core_register_options(void) |
122 | { |
123 | static GOptionEntry options[] = { |
124 | { "connect", 'c', 0, G_OPTION_ARG_STRING, &autocon_server, "Automatically connect to server/network", "SERVER" }, |
125 | { "password", 'w', 0, G_OPTION_ARG_STRING, &autocon_password, "Autoconnect password", "PASSWORD" }, |
126 | { "port", 'p', 0, G_OPTION_ARG_INT, &autocon_port, "Autoconnect port", "PORT" }, |
127 | { "noconnect", '!', 0, G_OPTION_ARG_NONE, &no_autoconnect, "Disable autoconnecting", NULL((void *)0) }, |
128 | { "nick", 'n', 0, G_OPTION_ARG_STRING, &cmdline_nick, "Specify nick to use", NULL((void *)0) }, |
129 | { "hostname", 'h', 0, G_OPTION_ARG_STRING, &cmdline_hostname, "Specify host name to use", NULL((void *)0) }, |
130 | { NULL((void *)0) } |
131 | }; |
132 | |
133 | autocon_server = NULL((void *)0); |
134 | autocon_password = NULL((void *)0); |
135 | autocon_port = 0; |
136 | no_autoconnect = FALSE(0); |
137 | cmdline_nick = NULL((void *)0); |
138 | cmdline_hostname = NULL((void *)0); |
139 | args_register(options); |
140 | } |
141 | |
142 | void fe_common_core_init(void) |
143 | { |
144 | const char *str; |
145 | |
146 | settings_add_bool("lookandfeel", "timestamps", TRUE)settings_add_bool_module("fe-common/core", "lookandfeel", "timestamps" , (!(0))); |
147 | settings_add_level("lookandfeel", "timestamp_level", "ALL")settings_add_level_module("fe-common/core", "lookandfeel", "timestamp_level" , "ALL"); |
148 | settings_add_time("lookandfeel", "timestamp_timeout", "0")settings_add_time_module("fe-common/core", "lookandfeel", "timestamp_timeout" , "0"); |
149 | |
150 | settings_add_bool("lookandfeel", "bell_beeps", FALSE)settings_add_bool_module("fe-common/core", "lookandfeel", "bell_beeps" , (0)); |
151 | settings_add_level("lookandfeel", "beep_msg_level", "")settings_add_level_module("fe-common/core", "lookandfeel", "beep_msg_level" , ""); |
152 | settings_add_bool("lookandfeel", "beep_when_window_active", TRUE)settings_add_bool_module("fe-common/core", "lookandfeel", "beep_when_window_active" , (!(0))); |
153 | settings_add_bool("lookandfeel", "beep_when_away", TRUE)settings_add_bool_module("fe-common/core", "lookandfeel", "beep_when_away" , (!(0))); |
154 | |
155 | settings_add_bool("lookandfeel", "hide_text_style", FALSE)settings_add_bool_module("fe-common/core", "lookandfeel", "hide_text_style" , (0)); |
156 | settings_add_bool("lookandfeel", "hide_colors", FALSE)settings_add_bool_module("fe-common/core", "lookandfeel", "hide_colors" , (0)); |
157 | settings_add_bool("lookandfeel", "hide_server_tags", FALSE)settings_add_bool_module("fe-common/core", "lookandfeel", "hide_server_tags" , (0)); |
158 | |
159 | settings_add_bool("lookandfeel", "use_status_window", TRUE)settings_add_bool_module("fe-common/core", "lookandfeel", "use_status_window" , (!(0))); |
160 | settings_add_bool("lookandfeel", "use_msgs_window", FALSE)settings_add_bool_module("fe-common/core", "lookandfeel", "use_msgs_window" , (0)); |
161 | g_get_charset(&str); |
162 | settings_add_str("lookandfeel", "term_charset", str)settings_add_str_module("fe-common/core", "lookandfeel", "term_charset" , str); |
163 | themes_init(); |
164 | theme_register(fecommon_core_formats)theme_register_module("fe-common/core", fecommon_core_formats ); |
165 | |
166 | command_history_init(); |
167 | completion_init(); |
168 | keyboard_init(); |
169 | printtext_init(); |
170 | formats_init(); |
171 | #ifndef WIN32 |
172 | fe_exec_init(); |
173 | #endif |
174 | fe_expandos_init(); |
175 | fe_help_init(); |
176 | fe_ignore_init(); |
177 | fe_log_init(); |
178 | fe_modules_init(); |
179 | fe_server_init(); |
180 | fe_settings_init(); |
181 | windows_init(); |
182 | window_activity_init(); |
183 | window_commands_init(); |
184 | window_items_init(); |
185 | windows_layout_init(); |
186 | fe_core_commands_init(); |
187 | |
188 | fe_channels_init(); |
189 | fe_queries_init(); |
190 | |
191 | fe_messages_init(); |
192 | hilight_text_init(); |
193 | fe_ignore_messages_init(); |
194 | fe_recode_init(); |
195 | |
196 | settings_check()settings_check_module("fe-common/core"); |
197 | |
198 | signal_add_first("server connected", (SIGNAL_FUNC) sig_connected)signal_add_full("fe-common/core", -100, ("server connected"), (SIGNAL_FUNC) ((SIGNAL_FUNC) sig_connected), ((void *)0)); |
199 | signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected)signal_add_full("fe-common/core", 100, ("server disconnected" ), (SIGNAL_FUNC) ((SIGNAL_FUNC) sig_disconnected), ((void *)0 )); |
200 | signal_add_first("channel created", (SIGNAL_FUNC) sig_channel_created)signal_add_full("fe-common/core", -100, ("channel created"), ( SIGNAL_FUNC) ((SIGNAL_FUNC) sig_channel_created), ((void *)0) ); |
201 | signal_add_last("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed)signal_add_full("fe-common/core", 100, ("channel destroyed"), (SIGNAL_FUNC) ((SIGNAL_FUNC) sig_channel_destroyed), ((void * )0)); |
202 | |
203 | module_register("core", "fe")module_register_full("core", "fe", "fe-common/core"); |
204 | } |
205 | |
206 | void fe_common_core_deinit(void) |
207 | { |
208 | hilight_text_deinit(); |
209 | command_history_deinit(); |
210 | completion_deinit(); |
211 | keyboard_deinit(); |
212 | printtext_deinit(); |
213 | formats_deinit(); |
214 | #ifndef WIN32 |
215 | fe_exec_deinit(); |
216 | #endif |
217 | fe_expandos_deinit(); |
218 | fe_help_deinit(); |
219 | fe_ignore_deinit(); |
220 | fe_log_deinit(); |
221 | fe_modules_deinit(); |
222 | fe_server_deinit(); |
223 | fe_settings_deinit(); |
224 | windows_deinit(); |
225 | window_activity_deinit(); |
226 | window_commands_deinit(); |
227 | window_items_deinit(); |
228 | windows_layout_deinit(); |
229 | fe_core_commands_deinit(); |
230 | |
231 | fe_channels_deinit(); |
232 | fe_queries_deinit(); |
233 | |
234 | fe_messages_deinit(); |
235 | fe_ignore_messages_deinit(); |
236 | fe_recode_deinit(); |
237 | |
238 | theme_unregister()theme_unregister_module("fe-common/core"); |
239 | themes_deinit(); |
240 | |
241 | signal_remove("setup changed", (SIGNAL_FUNC) sig_setup_changed)signal_remove_full(("setup changed"), (SIGNAL_FUNC) ((SIGNAL_FUNC ) sig_setup_changed), ((void *)0)); |
242 | signal_remove("server connected", (SIGNAL_FUNC) sig_connected)signal_remove_full(("server connected"), (SIGNAL_FUNC) ((SIGNAL_FUNC ) sig_connected), ((void *)0)); |
243 | signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected)signal_remove_full(("server disconnected"), (SIGNAL_FUNC) ((SIGNAL_FUNC ) sig_disconnected), ((void *)0)); |
244 | signal_remove("channel created", (SIGNAL_FUNC) sig_channel_created)signal_remove_full(("channel created"), (SIGNAL_FUNC) ((SIGNAL_FUNC ) sig_channel_created), ((void *)0)); |
245 | signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed)signal_remove_full(("channel destroyed"), (SIGNAL_FUNC) ((SIGNAL_FUNC ) sig_channel_destroyed), ((void *)0)); |
246 | } |
247 | |
248 | void glog_func(const char *log_domain, GLogLevelFlags log_level, |
249 | const char *message) |
250 | { |
251 | const char *reason; |
252 | |
253 | switch (log_level) { |
254 | case G_LOG_LEVEL_WARNING: |
255 | reason = "warning"; |
256 | break; |
257 | case G_LOG_LEVEL_CRITICAL: |
258 | reason = "critical"; |
259 | break; |
260 | default: |
261 | reason = "error"; |
262 | break; |
263 | } |
264 | |
265 | if (windows == NULL((void *)0)) |
266 | fprintf(stderr__stderrp, "GLib %s: %s\n", reason, message); |
267 | else { |
268 | printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,printformat_module("fe-common/core", ((void *)0), ((void *)0) , MSGLEVEL_CLIENTERROR, TXT_GLIB_ERROR, reason, message) |
269 | TXT_GLIB_ERROR, reason, message)printformat_module("fe-common/core", ((void *)0), ((void *)0) , MSGLEVEL_CLIENTERROR, TXT_GLIB_ERROR, reason, message); |
270 | } |
271 | } |
272 | |
273 | #define MSGS_WINDOW_LEVELS(MSGLEVEL_MSGS|MSGLEVEL_ACTIONS|MSGLEVEL_DCCMSGS) (MSGLEVEL_MSGS|MSGLEVEL_ACTIONS|MSGLEVEL_DCCMSGS) |
274 | |
275 | static void create_windows(void) |
276 | { |
277 | WINDOW_REC *window; |
278 | int have_status = settings_get_bool("use_status_window"); |
279 | |
280 | window = window_find_name("(status)"); |
281 | if (have_status) { |
282 | if (window == NULL((void *)0)) { |
283 | window = window_create(NULL((void *)0), TRUE(!(0))); |
284 | window_set_refnum(window, 1); |
285 | window_set_name(window, "(status)"); |
286 | window_set_level(window, MSGLEVEL_ALL ^ |
287 | (settings_get_bool("use_msgs_window") ? |
288 | MSGS_WINDOW_LEVELS(MSGLEVEL_MSGS|MSGLEVEL_ACTIONS|MSGLEVEL_DCCMSGS) : 0)); |
289 | window_set_immortal(window, TRUE(!(0))); |
290 | } |
291 | } else { |
292 | if (window != NULL((void *)0)) { |
293 | window_set_name(window, NULL((void *)0)); |
294 | window_set_level(window, 0); |
295 | window_set_immortal(window, FALSE(0)); |
296 | } |
297 | } |
298 | |
299 | window = window_find_name("(msgs)"); |
300 | if (settings_get_bool("use_msgs_window")) { |
301 | if (window == NULL((void *)0)) { |
302 | window = window_create(NULL((void *)0), TRUE(!(0))); |
303 | window_set_refnum(window, have_status ? 2 : 1); |
304 | window_set_name(window, "(msgs)"); |
305 | window_set_level(window, MSGS_WINDOW_LEVELS(MSGLEVEL_MSGS|MSGLEVEL_ACTIONS|MSGLEVEL_DCCMSGS)); |
306 | window_set_immortal(window, TRUE(!(0))); |
307 | } |
308 | } else { |
309 | if (window != NULL((void *)0)) { |
310 | window_set_name(window, NULL((void *)0)); |
311 | window_set_level(window, 0); |
312 | window_set_immortal(window, FALSE(0)); |
313 | } |
314 | } |
315 | |
316 | if (windows == NULL((void *)0)) { |
317 | /* we have to have at least one window.. */ |
318 | window = window_create(NULL((void *)0), TRUE(!(0))); |
Value stored to 'window' is never read | |
319 | } |
320 | } |
321 | |
322 | static void autoconnect_servers(void) |
323 | { |
324 | GSList *tmp, *chatnets; |
325 | char *str; |
326 | |
327 | if (autocon_server != NULL((void *)0)) { |
328 | /* connect to specified server */ |
329 | str = g_strdup_printf(autocon_password == NULL((void *)0) ? "%s %d" : "%s %d %s", |
330 | autocon_server, autocon_port, autocon_password); |
331 | signal_emit("command connect", 1, str); |
332 | g_free(str); |
333 | return; |
334 | } |
335 | |
336 | if (no_autoconnect) { |
337 | /* don't autoconnect */ |
338 | return; |
339 | } |
340 | |
341 | /* connect to autoconnect servers */ |
342 | chatnets = NULL((void *)0); |
343 | for (tmp = setupservers; tmp != NULL((void *)0); tmp = tmp->next) { |
344 | SERVER_SETUP_REC *rec = tmp->data; |
345 | |
346 | if (rec->autoconnect && |
347 | (rec->chatnet == NULL((void *)0) || |
348 | gslist_find_icase_string(chatnets, rec->chatnet) == NULL((void *)0))) { |
349 | if (rec->chatnet != NULL((void *)0)) |
350 | chatnets = g_slist_append(chatnets, rec->chatnet); |
351 | |
352 | str = g_strdup_printf("%s %d", rec->address, rec->port); |
353 | signal_emit("command connect", 1, str); |
354 | g_free(str); |
355 | } |
356 | } |
357 | |
358 | g_slist_free(chatnets); |
359 | } |
360 | |
361 | static void sig_setup_changed(void) |
362 | { |
363 | static int firsttime = TRUE(!(0)); |
364 | static int status_window = FALSE(0), msgs_window = FALSE(0); |
365 | int changed = FALSE(0); |
366 | |
367 | if (settings_get_bool("use_status_window") != status_window) { |
368 | status_window = !status_window; |
369 | changed = TRUE(!(0)); |
370 | } |
371 | if (settings_get_bool("use_msgs_window") != msgs_window) { |
372 | msgs_window = !msgs_window; |
373 | changed = TRUE(!(0)); |
374 | } |
375 | |
376 | if (firsttime) { |
377 | firsttime = FALSE(0); |
378 | changed = TRUE(!(0)); |
379 | |
380 | windows_layout_restore(); |
381 | if (windows != NULL((void *)0)) |
382 | return; |
383 | } |
384 | |
385 | if (changed) |
386 | create_windows(); |
387 | } |
388 | |
389 | static void autorun_startup(void) |
390 | { |
391 | char *path; |
392 | GIOChannel *handle; |
393 | GString *buf; |
394 | gsize tpos; |
395 | |
396 | /* open ~/.irssi/startup and run all commands in it */ |
397 | path = g_strdup_printf("%s/startup", get_irssi_dir()); |
398 | handle = g_io_channel_new_file(path, "r", NULL((void *)0)); |
399 | g_free(path); |
400 | if (handle == NULL((void *)0)) { |
401 | /* file not found */ |
402 | return; |
403 | } |
404 | |
405 | g_io_channel_set_encoding(handle, NULL((void *)0), NULL((void *)0)); |
406 | buf = g_string_sized_new(512); |
407 | while (g_io_channel_read_line_string(handle, buf, &tpos, NULL((void *)0)) == G_IO_STATUS_NORMAL) { |
408 | buf->str[tpos] = '\0'; |
409 | if (buf->str[0] != '#') { |
410 | eval_special_string(buf->str, "", |
411 | active_win->active_server, |
412 | active_win->active); |
413 | } |
414 | } |
415 | g_string_free(buf, TRUE(!(0))); |
416 | |
417 | g_io_channel_unref(handle); |
418 | } |
419 | |
420 | void fe_common_core_finish_init(void) |
421 | { |
422 | int setup_changed; |
423 | |
424 | signal_emit("irssi init read settings", 0); |
425 | |
426 | #ifdef SIGPIPE13 |
427 | signal(SIGPIPE13, SIG_IGN((__sighandler_t *)1)); |
428 | #endif |
429 | |
430 | setup_changed = FALSE(0); |
431 | if (cmdline_nick != NULL((void *)0) && *cmdline_nick != '\0') { |
432 | /* override nick found from setup */ |
433 | settings_set_str("nick", cmdline_nick); |
434 | setup_changed = TRUE(!(0)); |
435 | } |
436 | |
437 | if (cmdline_hostname != NULL((void *)0)) { |
438 | /* override host name found from setup */ |
439 | settings_set_str("hostname", cmdline_hostname); |
440 | setup_changed = TRUE(!(0)); |
441 | } |
442 | |
443 | sig_setup_changed(); |
444 | signal_add_first("setup changed", (SIGNAL_FUNC) sig_setup_changed)signal_add_full("fe-common/core", -100, ("setup changed"), (SIGNAL_FUNC ) ((SIGNAL_FUNC) sig_setup_changed), ((void *)0)); |
445 | |
446 | /* _after_ windows are created.. */ |
447 | #if GLIB_CHECK_VERSION(2,6,0)(2 > (2) || (2 == (2) && 18 > (6)) || (2 == (2) && 18 == (6) && 4 >= (0))) |
448 | g_log_set_default_handler((GLogFunc) glog_func, NULL((void *)0)); |
449 | #else |
450 | g_log_set_handler(G_LOG_DOMAIN((gchar*) 0), |
451 | (GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | |
452 | G_LOG_LEVEL_WARNING), |
453 | (GLogFunc) glog_func, NULL((void *)0)); |
454 | g_log_set_handler("GLib", |
455 | (GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | |
456 | G_LOG_LEVEL_WARNING), |
457 | (GLogFunc) glog_func, NULL((void *)0)); /* send glib errors to the same place */ |
458 | #endif |
459 | |
460 | if (setup_changed) |
461 | signal_emit("setup changed", 0); |
462 | |
463 | autorun_startup(); |
464 | autoconnect_servers(); |
465 | } |
466 | |
467 | gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) |
468 | { |
469 | g_return_val_if_fail(array != NULL, FALSE)do{ if (array != ((void *)0)) { } else { g_return_if_fail_warning (((gchar*) 0), __PRETTY_FUNCTION__, "array != NULL"); return ((0)); }; }while (0); |
470 | |
471 | if (strarray_find(array, dest->target) != -1) |
472 | return TRUE(!(0)); |
473 | |
474 | if (dest->server_tag != NULL((void *)0)) { |
475 | char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, dest->target); |
476 | int ret = strarray_find(array, tagtarget); |
477 | g_free(tagtarget); |
478 | if (ret != -1) |
479 | return TRUE(!(0)); |
480 | } |
481 | return FALSE(0); |
482 | } |