2000-04-26 04:03:38 -04: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.
|
|
|
|
|
2007-05-08 14:41:10 -04:00
|
|
|
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.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2000-04-26 04:03:38 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
2000-05-15 04:25:45 -04:00
|
|
|
#include "module-formats.h"
|
2001-08-13 20:41:59 -04:00
|
|
|
#include "modules-load.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "args.h"
|
|
|
|
#include "signals.h"
|
2000-12-03 00:47:50 -05:00
|
|
|
#include "levels.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "core.h"
|
2000-12-17 00:44:45 -05:00
|
|
|
#include "settings.h"
|
2001-11-19 20:47:29 -05:00
|
|
|
#include "session.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-12-03 00:47:50 -05:00
|
|
|
#include "printtext.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "fe-common-core.h"
|
2000-05-15 04:25:45 -04:00
|
|
|
#include "themes.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
#include "term.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "gui-entry.h"
|
2000-05-04 06:32:42 -04:00
|
|
|
#include "mainwindows.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "gui-printtext.h"
|
|
|
|
#include "gui-readline.h"
|
2000-05-04 06:32:42 -04:00
|
|
|
#include "statusbar.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "gui-windows.h"
|
2001-07-14 20:39:48 -04:00
|
|
|
#include "textbuffer-reformat.h"
|
2007-05-23 20:44:29 -04:00
|
|
|
#include "irssi-version.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
#include <signal.h>
|
2002-07-01 13:32:05 -04:00
|
|
|
#include <locale.h>
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-03 18:57:14 -04:00
|
|
|
#ifdef HAVE_STATIC_PERL
|
2001-02-17 05:35:35 -05:00
|
|
|
void perl_core_init(void);
|
|
|
|
void perl_core_deinit(void);
|
2001-07-29 05:17:53 -04:00
|
|
|
|
|
|
|
void fe_perl_init(void);
|
|
|
|
void fe_perl_deinit(void);
|
2000-10-03 18:57:14 -04:00
|
|
|
#endif
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
void irc_init(void);
|
|
|
|
void irc_deinit(void);
|
|
|
|
|
2001-11-01 20:05:14 -05:00
|
|
|
void fe_common_irc_init(void);
|
|
|
|
void fe_common_irc_deinit(void);
|
|
|
|
|
2000-12-04 19:53:04 -05:00
|
|
|
void gui_expandos_init(void);
|
|
|
|
void gui_expandos_deinit(void);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
void textbuffer_commands_init(void);
|
|
|
|
void textbuffer_commands_deinit(void);
|
2000-12-04 19:53:04 -05:00
|
|
|
|
2001-02-19 01:23:04 -05:00
|
|
|
void lastlog_init(void);
|
|
|
|
void lastlog_deinit(void);
|
|
|
|
|
2000-08-12 12:40:39 -04:00
|
|
|
void mainwindow_activity_init(void);
|
|
|
|
void mainwindow_activity_deinit(void);
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
void mainwindows_layout_init(void);
|
|
|
|
void mainwindows_layout_deinit(void);
|
2001-02-10 02:26:54 -05:00
|
|
|
|
2001-12-17 13:41:06 -05:00
|
|
|
void term_dummy_init(void);
|
|
|
|
void term_dummy_deinit(void);
|
|
|
|
|
|
|
|
static int dirty, full_redraw, dummy;
|
2001-10-28 13:40:12 -05:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
static GMainLoop *main_loop;
|
|
|
|
int quitting;
|
|
|
|
|
2000-12-03 00:47:50 -05:00
|
|
|
static const char *firsttimer_text =
|
2002-11-09 18:05:22 -05:00
|
|
|
"Looks like this is the first time you've run irssi.\n"
|
2000-12-03 00:47:50 -05:00
|
|
|
"This is just a reminder that you really should go read\n"
|
2004-07-11 10:41:46 -04:00
|
|
|
"startup-HOWTO if you haven't already. You can find it\n"
|
|
|
|
"and more irssi beginner info at http://irssi.org/help/\n"
|
|
|
|
"\n"
|
|
|
|
"For the truly impatient people who don't like any automatic\n"
|
|
|
|
"window creation or closing, just type: /MANUAL-WINDOWS";
|
2000-12-03 00:47:50 -05:00
|
|
|
static int display_firsttimer = FALSE;
|
|
|
|
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
static void sig_exit(void)
|
|
|
|
{
|
2001-10-28 13:40:12 -05:00
|
|
|
quitting = TRUE;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* redraw irssi's screen.. */
|
|
|
|
void irssi_redraw(void)
|
|
|
|
{
|
2001-10-28 13:40:12 -05:00
|
|
|
dirty = TRUE;
|
|
|
|
full_redraw = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void irssi_set_dirty(void)
|
|
|
|
{
|
|
|
|
dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dirty_check(void)
|
|
|
|
{
|
2001-12-17 13:41:06 -05:00
|
|
|
if (!dirty || dummy)
|
2001-10-28 13:40:12 -05:00
|
|
|
return;
|
|
|
|
|
2001-10-28 16:17:34 -05:00
|
|
|
term_resize_dirty();
|
|
|
|
|
2001-10-28 13:40:12 -05: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 06:30:26 -05:00
|
|
|
term_refresh(NULL);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
dirty = FALSE;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void textui_init(void)
|
|
|
|
{
|
2002-02-02 14:55:33 -05:00
|
|
|
#ifdef SIGTRAP
|
|
|
|
struct sigaction act;
|
|
|
|
|
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
sigaction(SIGTRAP, &act, NULL);
|
|
|
|
#endif
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
irssi_gui = IRSSI_GUI_TEXT;
|
|
|
|
core_init();
|
|
|
|
irc_init();
|
|
|
|
fe_common_core_init();
|
|
|
|
fe_common_irc_init();
|
2000-05-15 04:25:45 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
theme_register(gui_text_formats);
|
2001-12-03 08:06:31 -05:00
|
|
|
signal_add_last("gui exit", (SIGNAL_FUNC) sig_exit);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void textui_finish_init(void)
|
|
|
|
{
|
2000-05-04 06:32:42 -04:00
|
|
|
quitting = FALSE;
|
|
|
|
|
2001-12-17 13:41:06 -05:00
|
|
|
if (dummy)
|
|
|
|
term_dummy_init();
|
|
|
|
else {
|
|
|
|
term_refresh_freeze();
|
|
|
|
textbuffer_init();
|
|
|
|
textbuffer_view_init();
|
|
|
|
textbuffer_commands_init();
|
|
|
|
textbuffer_reformat_init();
|
|
|
|
gui_expandos_init();
|
|
|
|
gui_printtext_init();
|
|
|
|
gui_readline_init();
|
|
|
|
lastlog_init();
|
|
|
|
mainwindows_init();
|
|
|
|
mainwindow_activity_init();
|
|
|
|
mainwindows_layout_init();
|
|
|
|
gui_windows_init();
|
|
|
|
statusbar_init();
|
|
|
|
term_refresh_thaw();
|
2002-06-07 11:52:16 -04:00
|
|
|
|
|
|
|
/* don't check settings with dummy mode */
|
|
|
|
settings_check();
|
2001-12-17 13:41:06 -05:00
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-08-13 20:41:59 -04:00
|
|
|
module_register("core", "fe-text");
|
2000-12-17 00:44:45 -05:00
|
|
|
|
2000-10-03 18:57:14 -04:00
|
|
|
#ifdef HAVE_STATIC_PERL
|
2001-02-17 05:35:35 -05:00
|
|
|
perl_core_init();
|
2001-07-29 05:17:53 -04:00
|
|
|
fe_perl_init();
|
2000-10-03 18:57:14 -04:00
|
|
|
#endif
|
2000-08-23 21:49:10 -04:00
|
|
|
|
2001-11-19 11:57:19 -05:00
|
|
|
dirty_check();
|
2001-11-19 12:31:33 -05:00
|
|
|
|
|
|
|
fe_common_core_finish_init();
|
2001-10-21 05:25:29 -04:00
|
|
|
signal_emit("irssi init finished", 0);
|
|
|
|
|
2000-12-03 00:47:50 -05:00
|
|
|
if (display_firsttimer) {
|
|
|
|
printtext_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
"%s", firsttimer_text);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void textui_deinit(void)
|
|
|
|
{
|
2000-05-04 06:32:42 -04:00
|
|
|
signal(SIGINT, SIG_DFL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
term_refresh_freeze();
|
2000-11-26 04:22:18 -05:00
|
|
|
while (modules != NULL)
|
|
|
|
module_unload(modules->data);
|
|
|
|
|
2001-10-21 06:31:03 -04:00
|
|
|
#ifdef HAVE_STATIC_PERL
|
|
|
|
perl_core_deinit();
|
|
|
|
fe_perl_deinit();
|
|
|
|
#endif
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
dirty_check(); /* one last time to print any quit messages */
|
2000-05-04 06:32:42 -04:00
|
|
|
signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
|
2001-02-04 20:06:42 -05:00
|
|
|
|
2001-12-17 13:41:06 -05:00
|
|
|
if (dummy)
|
|
|
|
term_dummy_deinit();
|
|
|
|
else {
|
|
|
|
lastlog_deinit();
|
|
|
|
statusbar_deinit();
|
|
|
|
gui_printtext_deinit();
|
|
|
|
gui_readline_deinit();
|
|
|
|
gui_windows_deinit();
|
|
|
|
mainwindows_layout_deinit();
|
|
|
|
mainwindow_activity_deinit();
|
|
|
|
mainwindows_deinit();
|
|
|
|
gui_expandos_deinit();
|
|
|
|
textbuffer_reformat_deinit();
|
|
|
|
textbuffer_commands_deinit();
|
|
|
|
textbuffer_view_deinit();
|
|
|
|
textbuffer_deinit();
|
|
|
|
|
|
|
|
term_refresh_thaw();
|
|
|
|
term_deinit();
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
theme_unregister();
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
fe_common_irc_deinit();
|
|
|
|
fe_common_core_deinit();
|
|
|
|
irc_deinit();
|
|
|
|
core_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-12-03 00:23:26 -05:00
|
|
|
static void check_oldcrap(void)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char *path, str[256];
|
|
|
|
int found;
|
|
|
|
|
|
|
|
/* check that default.theme is up-to-date */
|
2001-07-14 20:39:48 -04:00
|
|
|
path = g_strdup_printf("%s/default.theme", get_irssi_dir());
|
2000-12-03 00:23:26 -05: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;
|
|
|
|
}
|
|
|
|
|
2007-02-14 05:43:34 -05:00
|
|
|
printf("\nYou seem to have an old default.theme in %s/ directory.\n", get_irssi_dir());
|
2000-12-03 00:23:26 -05: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);
|
2002-01-27 15:45:59 -05:00
|
|
|
if (i_toupper(str[0]) == 'Y' || str[0] == '\n' || str[0] == '\0')
|
2000-12-03 00:23:26 -05:00
|
|
|
remove(path);
|
|
|
|
g_free(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_files(void)
|
|
|
|
{
|
|
|
|
struct stat statbuf;
|
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
if (stat(get_irssi_dir(), &statbuf) != 0) {
|
2000-12-03 00:23:26 -05:00
|
|
|
/* ~/.irssi doesn't exist, first time running irssi */
|
2000-12-03 00:47:50 -05:00
|
|
|
display_firsttimer = TRUE;
|
2000-12-03 00:23:26 -05:00
|
|
|
} else {
|
|
|
|
check_oldcrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-05 14:43:12 -05: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
|
|
|
|
|
2003-01-24 22:19:40 -05:00
|
|
|
#ifdef USE_GC
|
2003-01-10 19:24:30 -05:00
|
|
|
#ifdef HAVE_GC_H
|
|
|
|
# include <gc.h>
|
|
|
|
#else
|
|
|
|
# include <gc/gc.h>
|
|
|
|
#endif
|
2003-01-24 22:19:40 -05:00
|
|
|
|
2002-12-23 01:06:14 -05:00
|
|
|
GMemVTable gc_mem_table = {
|
|
|
|
GC_malloc,
|
|
|
|
GC_realloc,
|
|
|
|
GC_free,
|
|
|
|
|
|
|
|
NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2007-05-23 20:44:29 -04:00
|
|
|
static int version = 0;
|
2001-12-17 13:41:06 -05:00
|
|
|
static struct poptOption options[] = {
|
|
|
|
{ "dummy", 'd', POPT_ARG_NONE, &dummy, 0, "Use the dummy terminal mode", NULL },
|
2007-05-23 20:44:29 -04:00
|
|
|
{ "version", 'v', POPT_ARG_NONE, &version, 0, "Display irssi version", NULL },
|
2001-12-17 13:41:06 -05:00
|
|
|
{ NULL, '\0', 0, NULL }
|
|
|
|
};
|
|
|
|
|
2007-05-23 20:25:36 -04:00
|
|
|
core_register_options();
|
|
|
|
fe_common_core_register_options();
|
|
|
|
args_register(options);
|
|
|
|
args_execute(argc, argv);
|
|
|
|
|
2007-05-23 20:44:29 -04:00
|
|
|
if (version) {
|
|
|
|
printf(PACKAGE" " IRSSI_VERSION" (%d %04d)\n",
|
|
|
|
IRSSI_VERSION_DATE, IRSSI_VERSION_TIME);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-01-24 22:19:40 -05:00
|
|
|
#ifdef USE_GC
|
2002-12-23 01:06:14 -05:00
|
|
|
g_mem_set_vtable(&gc_mem_table);
|
|
|
|
#endif
|
|
|
|
|
2006-03-26 03:42:34 -05:00
|
|
|
srand(time(NULL));
|
|
|
|
|
2001-12-17 13:41:06 -05:00
|
|
|
dummy = FALSE;
|
2001-10-28 13:40:12 -05:00
|
|
|
quitting = FALSE;
|
2007-05-23 20:25:36 -04:00
|
|
|
core_preinit(argv[0]);
|
2001-07-14 20:39:48 -04:00
|
|
|
|
2000-12-03 00:23:26 -05:00
|
|
|
check_files();
|
2001-12-17 18:01:12 -05:00
|
|
|
|
2000-12-05 14:43:12 -05:00
|
|
|
#ifdef WIN32
|
|
|
|
winsock_init();
|
|
|
|
#endif
|
2000-04-26 04:03:38 -04:00
|
|
|
#ifdef HAVE_SOCKS
|
2000-05-04 06:32:42 -04:00
|
|
|
SOCKSinit(argv[0]);
|
2000-04-26 04:03:38 -04:00
|
|
|
#endif
|
|
|
|
|
2002-07-01 13:32:05 -04:00
|
|
|
/* setlocale() must be called at the beginning before any calls that
|
|
|
|
affect it, especially regexps seem to break if they're generated
|
2007-04-19 04:21:51 -04:00
|
|
|
before this call.
|
2002-07-01 13:32:05 -04:00
|
|
|
|
|
|
|
locales aren't actually used for anything else than autodetection
|
2005-10-12 14:22:14 -04:00
|
|
|
of UTF-8 currently..
|
2002-07-01 13:32:05 -04:00
|
|
|
|
2005-10-12 14:22:14 -04:00
|
|
|
furthermore to get the users's charset with g_get_charset() properly
|
|
|
|
you have to call setlocale(LC_ALL, "") */
|
2005-01-12 11:40:44 -05:00
|
|
|
setlocale(LC_ALL, "");
|
2005-10-12 14:22:14 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
textui_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-12-17 13:41:06 -05:00
|
|
|
if (!dummy && !term_init()) {
|
|
|
|
fprintf(stderr, "Can't initialize screen handling, quitting.\n");
|
|
|
|
fprintf(stderr, "You can still use the dummy mode with -d parameter\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
textui_finish_init();
|
|
|
|
main_loop = g_main_new(TRUE);
|
2001-10-28 13:40:12 -05:00
|
|
|
|
|
|
|
/* Does the same as g_main_run(main_loop), except we
|
|
|
|
can call our dirty-checker after each iteration */
|
|
|
|
while (!quitting) {
|
2003-01-25 16:19:41 -05:00
|
|
|
#ifdef USE_GC
|
2003-01-24 22:19:40 -05:00
|
|
|
GC_collect_a_little();
|
2003-01-25 16:19:41 -05:00
|
|
|
#endif
|
2003-01-24 22:19:40 -05:00
|
|
|
if (!dummy) term_refresh_freeze();
|
2001-10-28 13:40:12 -05:00
|
|
|
g_main_iteration(TRUE);
|
2002-06-07 11:52:16 -04:00
|
|
|
if (!dummy) term_refresh_thaw();
|
2002-03-10 10:20:44 -05:00
|
|
|
|
|
|
|
if (reload_config) {
|
|
|
|
/* SIGHUP received, do /RELOAD */
|
|
|
|
reload_config = FALSE;
|
|
|
|
signal_emit("command reload", 1, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
dirty_check();
|
2001-10-28 13:40:12 -05:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
g_main_destroy(main_loop);
|
|
|
|
textui_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-11-19 20:47:29 -05:00
|
|
|
session_upgrade(); /* if we /UPGRADEd, start the new process */
|
2000-05-04 06:32:42 -04:00
|
|
|
return 0;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|