4 Copyright (C) 1999-2000 Timo Sirainen
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.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "module-formats.h"
23 #include "modules-load.h"
31 #include "printtext.h"
32 #include "fe-common-core.h"
33 #include "fe-common-silc.h"
37 #include "gui-entry.h"
38 #include "mainwindows.h"
39 #include "gui-printtext.h"
40 #include "gui-readline.h"
41 #include "statusbar.h"
42 #include "gui-windows.h"
43 #include "textbuffer-reformat.h"
48 #ifdef HAVE_STATIC_PERL
49 void perl_core_init(void);
50 void perl_core_deinit(void);
52 void fe_perl_init(void);
53 void fe_perl_deinit(void);
57 void silc_deinit(void);
59 void gui_expandos_init(void);
60 void gui_expandos_deinit(void);
62 void textbuffer_commands_init(void);
63 void textbuffer_commands_deinit(void);
65 void lastlog_init(void);
66 void lastlog_deinit(void);
68 void mainwindow_activity_init(void);
69 void mainwindow_activity_deinit(void);
71 void mainwindows_layout_init(void);
72 void mainwindows_layout_deinit(void);
74 void term_dummy_init(void);
75 void term_dummy_deinit(void);
77 static int dirty, full_redraw, dummy;
79 static GMainLoop *main_loop;
82 static const char *firsttimer_text =
83 "Looks like this is the first time you've run irssi.\n"
84 "This is just a reminder that you really should go read\n"
85 "startup-HOWTO if you haven't already. You can find it\n"
86 "and more irssi beginner info at http://irssi.org/help/\n"
88 "For the truly impatient people who don't like any automatic\n"
89 "window creation or closing, just type: /MANUAL-WINDOWS";
90 static int display_firsttimer = FALSE;
93 static void sig_exit(void)
98 /* redraw irssi's screen.. */
99 void irssi_redraw(void)
105 void irssi_set_dirty(void)
110 static void dirty_check(void)
120 /* first clear the screen so curses will be
121 forced to redraw the screen */
125 mainwindows_redraw();
126 statusbar_redraw(NULL, TRUE);
129 mainwindows_redraw_dirty();
130 statusbar_redraw_dirty();
136 static void textui_init(void)
139 struct sigaction act;
141 sigemptyset(&act.sa_mask);
143 act.sa_handler = SIG_IGN;
144 sigaction(SIGTRAP, &act, NULL);
147 irssi_gui = IRSSI_GUI_TEXT;
150 fe_common_core_init();
153 theme_register(gui_text_formats);
154 signal_add_last("gui exit", (SIGNAL_FUNC) sig_exit);
157 static void textui_finish_init(void)
164 term_refresh_freeze();
166 textbuffer_view_init();
167 textbuffer_commands_init();
168 textbuffer_reformat_init();
170 gui_printtext_init();
174 mainwindow_activity_init();
175 mainwindows_layout_init();
180 /* don't check settings with dummy mode */
184 module_register("core", "fe-text");
186 #ifdef HAVE_STATIC_PERL
193 fe_common_core_finish_init();
194 signal_emit("irssi init finished", 0);
197 if (display_firsttimer) {
198 printtext_window(active_win, MSGLEVEL_CLIENTNOTICE,
199 "%s", firsttimer_text);
204 static void textui_deinit(void)
206 signal(SIGINT, SIG_DFL);
208 term_refresh_freeze();
209 while (modules != NULL)
210 module_unload(modules->data);
212 #ifdef HAVE_STATIC_PERL
217 dirty_check(); /* one last time to print any quit messages */
218 signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
225 gui_printtext_deinit();
226 gui_readline_deinit();
227 gui_windows_deinit();
228 mainwindows_layout_deinit();
229 mainwindow_activity_deinit();
230 mainwindows_deinit();
231 gui_expandos_deinit();
232 textbuffer_reformat_deinit();
233 textbuffer_commands_deinit();
234 textbuffer_view_deinit();
244 fe_common_core_deinit();
249 static void check_oldcrap(void)
252 char *path, str[256];
255 /* check that default.theme is up-to-date */
256 path = g_strdup_printf("%s/default.theme", get_irssi_dir());
257 f = fopen(path, "r+");
263 while (!found && fgets(str, sizeof(str), f) != NULL)
264 found = strstr(str, "abstracts = ") != NULL;
272 printf("\nYou seem to have old default.theme in "IRSSI_DIR_SHORT"/ directory.\n");
273 printf("Themeing system has changed a bit since last irssi release,\n");
274 printf("you should either delete your old default.theme or manually\n");
275 printf("merge it with the new default.theme.\n\n");
276 printf("Do you want to delete the old theme now? (Y/n)\n");
279 fgets(str, sizeof(str), stdin);
280 if (i_toupper(str[0]) == 'Y' || str[0] == '\n' || str[0] == '\0')
285 static void check_files(void)
289 if (stat(get_irssi_dir(), &statbuf) != 0) {
290 /* ~/.irssi doesn't exist, first time running irssi */
291 display_firsttimer = TRUE;
298 static void winsock_init(void)
300 WORD wVersionRequested;
303 wVersionRequested = MAKEWORD(2, 2);
305 if (WSAStartup(wVersionRequested, &wsaData) != 0) {
306 printf("Error initializing winsock\n");
319 GMemVTable gc_mem_table = {
328 int main(int argc, char **argv)
330 static struct poptOption options[] = {
331 #if 0 /* --dummy is not available in SILC Client */
332 { "dummy", 'd', POPT_ARG_NONE, &dummy, 0, "Use the dummy terminal mode", NULL },
334 { NULL, '\0', 0, NULL }
338 g_mem_set_vtable(&gc_mem_table);
345 core_init_paths(argc, argv);
356 /* initialize the i18n stuff */
357 bindtextdomain(PACKAGE, LOCALEDIR);
361 /* setlocale() must be called at the beginning before any calls that
362 affect it, especially regexps seem to break if they're generated
365 locales aren't actually used for anything else than autodetection
368 furthermore to get the users's charset with g_get_charset() properly
369 you have to call setlocale(LC_ALL, "") */
370 setlocale(LC_ALL, "");
373 args_register(options);
374 args_execute(argc, argv);
376 if (!dummy && !term_init()) {
377 fprintf(stderr, "Can't initialize screen handling, quitting.\n");
378 fprintf(stderr, "You can still use the dummy mode with -d parameter\n");
382 textui_finish_init();
383 main_loop = g_main_new(TRUE);
385 /* Does the same as g_main_run(main_loop), except we
386 can call our dirty-checker after each iteration */
389 GC_collect_a_little();
391 if (!dummy) term_refresh_freeze();
392 g_main_iteration(TRUE);
393 if (!dummy) term_refresh_thaw();
396 /* SIGHUP received, do /RELOAD */
397 reload_config = FALSE;
398 signal_emit("command reload", 1, "");
404 g_main_destroy(main_loop);
407 session_upgrade(); /* if we /UPGRADEd, start the new process */