2000-04-26 08:03:38 +00:00
|
|
|
/*
|
|
|
|
irssi.c : irssi
|
|
|
|
|
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
2000-05-15 08:25:45 +00:00
|
|
|
#include "module-formats.h"
|
2001-08-14 00:41:59 +00:00
|
|
|
#include "modules-load.h"
|
2000-04-26 08:03:38 +00:00
|
|
|
#include "args.h"
|
|
|
|
#include "signals.h"
|
2000-12-03 05:47:50 +00:00
|
|
|
#include "levels.h"
|
2000-04-26 08:03:38 +00:00
|
|
|
#include "core.h"
|
2000-12-17 05:44:45 +00:00
|
|
|
#include "settings.h"
|
2001-11-20 01:47:29 +00:00
|
|
|
#include "session.h"
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-12-03 05:47:50 +00:00
|
|
|
#include "printtext.h"
|
2000-04-26 08:03:38 +00:00
|
|
|
#include "fe-common-core.h"
|
2000-05-15 08:25:45 +00:00
|
|
|
#include "themes.h"
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2001-10-28 11:30:26 +00:00
|
|
|
#include "term.h"
|
2000-04-26 08:03:38 +00:00
|
|
|
#include "gui-entry.h"
|
2000-05-04 10:32:42 +00:00
|
|
|
#include "mainwindows.h"
|
2000-04-26 08:03:38 +00:00
|
|
|
#include "gui-printtext.h"
|
|
|
|
#include "gui-readline.h"
|
2000-05-04 10:32:42 +00:00
|
|
|
#include "statusbar.h"
|
2000-04-26 08:03:38 +00:00
|
|
|
#include "gui-windows.h"
|
2001-07-15 00:39:48 +00:00
|
|
|
#include "textbuffer-reformat.h"
|
2000-04-26 08:03:38 +00:00
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
2000-10-03 22:57:14 +00:00
|
|
|
#ifdef HAVE_STATIC_PERL
|
2001-02-17 10:35:35 +00:00
|
|
|
void perl_core_init(void);
|
|
|
|
void perl_core_deinit(void);
|
2001-07-29 09:17:53 +00:00
|
|
|
|
|
|
|
void fe_perl_init(void);
|
|
|
|
void fe_perl_deinit(void);
|
2000-10-03 22:57:14 +00:00
|
|
|
#endif
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
void irc_init(void);
|
|
|
|
void irc_deinit(void);
|
|
|
|
|
2001-11-02 01:05:14 +00:00
|
|
|
void fe_common_irc_init(void);
|
|
|
|
void fe_common_irc_deinit(void);
|
|
|
|
|
2000-12-05 00:53:04 +00:00
|
|
|
void gui_expandos_init(void);
|
|
|
|
void gui_expandos_deinit(void);
|
|
|
|
|
2001-04-14 22:24:56 +00:00
|
|
|
void textbuffer_commands_init(void);
|
|
|
|
void textbuffer_commands_deinit(void);
|
2000-12-05 00:53:04 +00:00
|
|
|
|
2001-02-19 06:23:04 +00:00
|
|
|
void lastlog_init(void);
|
|
|
|
void lastlog_deinit(void);
|
|
|
|
|
2000-08-12 16:40:39 +00:00
|
|
|
void mainwindow_activity_init(void);
|
|
|
|
void mainwindow_activity_deinit(void);
|
|
|
|
|
2001-08-07 12:41:10 +00:00
|
|
|
void mainwindows_layout_init(void);
|
|
|
|
void mainwindows_layout_deinit(void);
|
2001-02-10 07:26:54 +00:00
|
|
|
|
2001-10-28 18:40:12 +00:00
|
|
|
static int dirty, full_redraw;
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
static GMainLoop *main_loop;
|
|
|
|
int quitting;
|
|
|
|
|
2000-12-03 05:47:50 +00:00
|
|
|
static const char *firsttimer_text =
|
|
|
|
"Looks like this is the first time you run irssi.\n"
|
|
|
|
"This is just a reminder that you really should go read\n"
|
|
|
|
"startup-HOWTO if you haven't already. Irssi's default\n"
|
|
|
|
"settings aren't probably what you've used to, and you\n"
|
|
|
|
"shouldn't judge the whole client as crap based on them.\n\n"
|
|
|
|
"You can find startup-HOWTO and more irssi beginner info at\n"
|
|
|
|
"http://irssi.org/beginner/";
|
|
|
|
static int display_firsttimer = FALSE;
|
|
|
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
static void sig_exit(void)
|
|
|
|
{
|
2001-10-28 18:40:12 +00:00
|
|
|
quitting = TRUE;
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* redraw irssi's screen.. */
|
|
|
|
void irssi_redraw(void)
|
|
|
|
{
|
2001-10-28 18:40:12 +00:00
|
|
|
dirty = TRUE;
|
|
|
|
full_redraw = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void irssi_set_dirty(void)
|
|
|
|
{
|
|
|
|
dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dirty_check(void)
|
|
|
|
{
|
|
|
|
if (!dirty)
|
|
|
|
return;
|
|
|
|
|
2001-10-28 21:17:34 +00:00
|
|
|
term_resize_dirty();
|
|
|
|
|
2001-10-28 18:40:12 +00:00
|
|
|
if (full_redraw) {
|
|
|
|
full_redraw = FALSE;
|
|
|
|
|
|
|
|
/* first clear the screen so curses will be
|
|
|
|
forced to redraw the screen */
|
|
|
|
term_clear();
|
|
|
|
term_refresh(NULL);
|
|
|
|
|
|
|
|
mainwindows_redraw();
|
|
|
|
statusbar_redraw(NULL, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
mainwindows_redraw_dirty();
|
|
|
|
statusbar_redraw_dirty();
|
2001-10-28 11:30:26 +00:00
|
|
|
term_refresh(NULL);
|
2000-05-04 10:32:42 +00:00
|
|
|
|
2001-10-28 18:40:12 +00:00
|
|
|
dirty = FALSE;
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void textui_init(void)
|
|
|
|
{
|
2000-05-04 10:32:42 +00:00
|
|
|
irssi_gui = IRSSI_GUI_TEXT;
|
|
|
|
core_init();
|
|
|
|
irc_init();
|
|
|
|
fe_common_core_init();
|
|
|
|
fe_common_irc_init();
|
2000-05-15 08:25:45 +00:00
|
|
|
|
2000-08-26 15:39:44 +00:00
|
|
|
theme_register(gui_text_formats);
|
2000-05-04 10:32:42 +00:00
|
|
|
signal_add("gui exit", (SIGNAL_FUNC) sig_exit);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void textui_finish_init(void)
|
|
|
|
{
|
2000-05-04 10:32:42 +00:00
|
|
|
quitting = FALSE;
|
|
|
|
|
2001-10-28 11:30:26 +00:00
|
|
|
term_refresh_freeze();
|
2001-04-14 22:24:56 +00:00
|
|
|
textbuffer_init();
|
|
|
|
textbuffer_view_init();
|
|
|
|
textbuffer_commands_init();
|
2001-07-15 00:39:48 +00:00
|
|
|
textbuffer_reformat_init();
|
2000-12-05 00:53:04 +00:00
|
|
|
gui_expandos_init();
|
2000-05-04 10:32:42 +00:00
|
|
|
gui_printtext_init();
|
|
|
|
gui_readline_init();
|
2001-02-19 06:23:04 +00:00
|
|
|
lastlog_init();
|
2000-05-15 08:25:45 +00:00
|
|
|
mainwindows_init();
|
2000-08-12 16:40:39 +00:00
|
|
|
mainwindow_activity_init();
|
2001-08-07 12:41:10 +00:00
|
|
|
mainwindows_layout_init();
|
2000-05-04 10:32:42 +00:00
|
|
|
gui_windows_init();
|
|
|
|
statusbar_init();
|
2001-10-28 11:30:26 +00:00
|
|
|
term_refresh_thaw();
|
2000-05-04 10:32:42 +00:00
|
|
|
|
2000-12-17 05:44:45 +00:00
|
|
|
settings_check();
|
2001-08-14 00:41:59 +00:00
|
|
|
module_register("core", "fe-text");
|
2000-12-17 05:44:45 +00:00
|
|
|
|
2000-10-03 22:57:14 +00:00
|
|
|
#ifdef HAVE_STATIC_PERL
|
2001-02-17 10:35:35 +00:00
|
|
|
perl_core_init();
|
2001-07-29 09:17:53 +00:00
|
|
|
fe_perl_init();
|
2000-10-03 22:57:14 +00:00
|
|
|
#endif
|
2000-08-24 01:49:10 +00:00
|
|
|
|
2001-11-19 16:57:19 +00:00
|
|
|
dirty_check();
|
2001-11-19 17:31:33 +00:00
|
|
|
|
|
|
|
fe_common_core_finish_init();
|
2001-10-21 09:25:29 +00:00
|
|
|
signal_emit("irssi init finished", 0);
|
|
|
|
|
2000-12-03 05:47:50 +00:00
|
|
|
if (display_firsttimer) {
|
|
|
|
printtext_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
"%s", firsttimer_text);
|
|
|
|
}
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void textui_deinit(void)
|
|
|
|
{
|
2000-05-04 10:32:42 +00:00
|
|
|
signal(SIGINT, SIG_DFL);
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2001-10-28 11:30:26 +00:00
|
|
|
term_refresh_freeze();
|
2000-11-26 09:22:18 +00:00
|
|
|
while (modules != NULL)
|
|
|
|
module_unload(modules->data);
|
|
|
|
|
2001-10-21 10:31:03 +00:00
|
|
|
#ifdef HAVE_STATIC_PERL
|
|
|
|
perl_core_deinit();
|
|
|
|
fe_perl_deinit();
|
|
|
|
#endif
|
|
|
|
|
2001-10-28 18:40:12 +00:00
|
|
|
dirty_check(); /* one last time to print any quit messages */
|
2000-05-04 10:32:42 +00:00
|
|
|
signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
|
2001-02-05 01:06:42 +00:00
|
|
|
|
2001-02-19 06:23:04 +00:00
|
|
|
lastlog_deinit();
|
2000-05-04 10:32:42 +00:00
|
|
|
statusbar_deinit();
|
|
|
|
gui_printtext_deinit();
|
|
|
|
gui_readline_deinit();
|
|
|
|
gui_windows_deinit();
|
2001-08-07 12:41:10 +00:00
|
|
|
mainwindows_layout_deinit();
|
2000-08-12 16:40:39 +00:00
|
|
|
mainwindow_activity_deinit();
|
2000-05-15 08:25:45 +00:00
|
|
|
mainwindows_deinit();
|
2000-12-05 00:53:04 +00:00
|
|
|
gui_expandos_deinit();
|
2001-07-15 00:39:48 +00:00
|
|
|
textbuffer_reformat_deinit();
|
2001-04-14 22:24:56 +00:00
|
|
|
textbuffer_commands_deinit();
|
|
|
|
textbuffer_view_deinit();
|
|
|
|
textbuffer_deinit();
|
2001-02-05 01:06:42 +00:00
|
|
|
|
2001-10-28 11:30:26 +00:00
|
|
|
term_refresh_thaw();
|
|
|
|
term_deinit();
|
2000-05-04 10:32:42 +00:00
|
|
|
|
2000-05-15 08:25:45 +00:00
|
|
|
theme_unregister();
|
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
fe_common_irc_deinit();
|
|
|
|
fe_common_core_deinit();
|
|
|
|
irc_deinit();
|
|
|
|
core_deinit();
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
2000-12-03 05:23:26 +00:00
|
|
|
static void check_oldcrap(void)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char *path, str[256];
|
|
|
|
int found;
|
|
|
|
|
|
|
|
/* check that default.theme is up-to-date */
|
2001-07-15 00:39:48 +00:00
|
|
|
path = g_strdup_printf("%s/default.theme", get_irssi_dir());
|
2000-12-03 05:23:26 +00:00
|
|
|
f = fopen(path, "r+");
|
|
|
|
if (f == NULL) {
|
|
|
|
g_free(path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
found = FALSE;
|
|
|
|
while (!found && fgets(str, sizeof(str), f) != NULL)
|
|
|
|
found = strstr(str, "abstracts = ") != NULL;
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
g_free(path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-15 00:39:48 +00:00
|
|
|
printf("\nYou seem to have old default.theme in "IRSSI_DIR_SHORT"/ directory.\n");
|
2000-12-03 05:23:26 +00:00
|
|
|
printf("Themeing system has changed a bit since last irssi release,\n");
|
|
|
|
printf("you should either delete your old default.theme or manually\n");
|
|
|
|
printf("merge it with the new default.theme.\n\n");
|
|
|
|
printf("Do you want to delete the old theme now? (Y/n)\n");
|
|
|
|
|
|
|
|
str[0] = '\0';
|
|
|
|
fgets(str, sizeof(str), stdin);
|
|
|
|
if (toupper(str[0]) == 'Y' || str[0] == '\n' || str[0] == '\0')
|
|
|
|
remove(path);
|
|
|
|
g_free(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_files(void)
|
|
|
|
{
|
|
|
|
struct stat statbuf;
|
|
|
|
|
2001-07-15 00:39:48 +00:00
|
|
|
if (stat(get_irssi_dir(), &statbuf) != 0) {
|
2000-12-03 05:23:26 +00:00
|
|
|
/* ~/.irssi doesn't exist, first time running irssi */
|
2000-12-03 05:47:50 +00:00
|
|
|
display_firsttimer = TRUE;
|
2000-12-03 05:23:26 +00:00
|
|
|
} else {
|
|
|
|
check_oldcrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-05 19:43:12 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
static void winsock_init(void)
|
|
|
|
{
|
|
|
|
WORD wVersionRequested;
|
|
|
|
WSADATA wsaData;
|
|
|
|
|
|
|
|
wVersionRequested = MAKEWORD(2, 2);
|
|
|
|
|
|
|
|
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
|
|
|
|
printf("Error initializing winsock\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2001-10-28 18:40:12 +00:00
|
|
|
quitting = FALSE;
|
2001-07-15 00:39:48 +00:00
|
|
|
core_init_paths(argc, argv);
|
|
|
|
|
2000-12-03 05:23:26 +00:00
|
|
|
check_files();
|
2000-12-05 19:43:12 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
winsock_init();
|
|
|
|
#endif
|
2000-04-26 08:03:38 +00:00
|
|
|
#ifdef HAVE_SOCKS
|
2000-05-04 10:32:42 +00:00
|
|
|
SOCKSinit(argv[0]);
|
2000-04-26 08:03:38 +00:00
|
|
|
#endif
|
2000-08-13 23:15:05 +00:00
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
/* initialize the i18n stuff */
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
#endif
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
textui_init();
|
|
|
|
args_execute(argc, argv);
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2001-10-28 11:30:26 +00:00
|
|
|
if (!term_init())
|
2001-05-17 20:13:59 +00:00
|
|
|
g_error("Can't initialize screen handling, quitting.\n");
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
textui_finish_init();
|
|
|
|
main_loop = g_main_new(TRUE);
|
2001-10-28 18:40:12 +00:00
|
|
|
|
|
|
|
/* Does the same as g_main_run(main_loop), except we
|
|
|
|
can call our dirty-checker after each iteration */
|
|
|
|
while (!quitting) {
|
|
|
|
g_main_iteration(TRUE);
|
|
|
|
dirty_check();
|
|
|
|
}
|
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
g_main_destroy(main_loop);
|
|
|
|
textui_deinit();
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2001-11-20 01:47:29 +00:00
|
|
|
session_upgrade(); /* if we /UPGRADEd, start the new process */
|
2000-05-04 10:32:42 +00:00
|
|
|
return 0;
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|