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
|
2007-05-08 18:16:58 +00:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-04-26 08:03:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
2002-07-01 17:32:05 +00:00
|
|
|
#include <locale.h>
|
2000-04-26 08:03:38 +00:00
|
|
|
|
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-12-17 18:41:06 +00:00
|
|
|
void term_dummy_init(void);
|
|
|
|
void term_dummy_deinit(void);
|
|
|
|
|
|
|
|
static int dirty, full_redraw, dummy;
|
2001-10-28 18:40:12 +00:00
|
|
|
|
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 =
|
2002-11-09 23:05:22 +00:00
|
|
|
"Looks like this is the first time you've run irssi.\n"
|
2000-12-03 05:47:50 +00:00
|
|
|
"This is just a reminder that you really should go read\n"
|
2004-07-11 14:41:46 +00: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 05:47:50 +00:00
|
|
|
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)
|
|
|
|
{
|
2001-12-17 18:41:06 +00:00
|
|
|
if (!dirty || dummy)
|
2001-10-28 18:40:12 +00:00
|
|
|
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)
|
|
|
|
{
|
2002-02-02 19:55:33 +00: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 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);
|
2001-12-03 13:06:31 +00:00
|
|
|
signal_add_last("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-12-17 18:41:06 +00: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 15:52:16 +00:00
|
|
|
|
|
|
|
/* don't check settings with dummy mode */
|
|
|
|
settings_check();
|
2001-12-17 18:41:06 +00:00
|
|
|
}
|
2000-05-04 10:32:42 +00:00
|
|
|
|
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-12-17 18:41:06 +00: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 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;
|
|
|
|
}
|
|
|
|
|
2007-02-14 10:43:34 +00:00
|
|
|
printf("\nYou seem to have an old default.theme in %s/ directory.\n", get_irssi_dir());
|
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);
|
2002-01-27 20:45:59 +00:00
|
|
|
if (i_toupper(str[0]) == 'Y' || str[0] == '\n' || str[0] == '\0')
|
2000-12-03 05:23:26 +00:00
|
|
|
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
|
|
|
|
|
2003-01-25 03:19:40 +00:00
|
|
|
#ifdef USE_GC
|
2003-01-11 00:24:30 +00:00
|
|
|
#ifdef HAVE_GC_H
|
|
|
|
# include <gc.h>
|
|
|
|
#else
|
|
|
|
# include <gc/gc.h>
|
|
|
|
#endif
|
2003-01-25 03:19:40 +00:00
|
|
|
|
2002-12-23 06:06:14 +00:00
|
|
|
GMemVTable gc_mem_table = {
|
|
|
|
GC_malloc,
|
|
|
|
GC_realloc,
|
|
|
|
GC_free,
|
|
|
|
|
|
|
|
NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2001-12-17 18:41:06 +00:00
|
|
|
static struct poptOption options[] = {
|
|
|
|
{ "dummy", 'd', POPT_ARG_NONE, &dummy, 0, "Use the dummy terminal mode", NULL },
|
|
|
|
{ NULL, '\0', 0, NULL }
|
|
|
|
};
|
|
|
|
|
2003-01-25 03:19:40 +00:00
|
|
|
#ifdef USE_GC
|
2002-12-23 06:06:14 +00:00
|
|
|
g_mem_set_vtable(&gc_mem_table);
|
|
|
|
#endif
|
|
|
|
|
2006-03-26 08:42:34 +00:00
|
|
|
srand(time(NULL));
|
|
|
|
|
2001-12-17 18:41:06 +00:00
|
|
|
dummy = FALSE;
|
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();
|
2001-12-17 23:01:12 +00:00
|
|
|
|
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
|
|
|
|
|
2002-07-01 17:32:05 +00: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 08:21:51 +00:00
|
|
|
before this call.
|
2002-07-01 17:32:05 +00:00
|
|
|
|
|
|
|
locales aren't actually used for anything else than autodetection
|
2005-10-12 18:22:14 +00:00
|
|
|
of UTF-8 currently..
|
2002-07-01 17:32:05 +00:00
|
|
|
|
2005-10-12 18:22:14 +00:00
|
|
|
furthermore to get the users's charset with g_get_charset() properly
|
|
|
|
you have to call setlocale(LC_ALL, "") */
|
2005-01-12 16:40:44 +00:00
|
|
|
setlocale(LC_ALL, "");
|
2005-10-12 18:22:14 +00:00
|
|
|
|
2000-05-04 10:32:42 +00:00
|
|
|
textui_init();
|
2001-12-17 18:41:06 +00:00
|
|
|
args_register(options);
|
2000-05-04 10:32:42 +00:00
|
|
|
args_execute(argc, argv);
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2001-12-17 18:41:06 +00: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 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) {
|
2003-01-25 21:19:41 +00:00
|
|
|
#ifdef USE_GC
|
2003-01-25 03:19:40 +00:00
|
|
|
GC_collect_a_little();
|
2003-01-25 21:19:41 +00:00
|
|
|
#endif
|
2003-01-25 03:19:40 +00:00
|
|
|
if (!dummy) term_refresh_freeze();
|
2001-10-28 18:40:12 +00:00
|
|
|
g_main_iteration(TRUE);
|
2002-06-07 15:52:16 +00:00
|
|
|
if (!dummy) term_refresh_thaw();
|
2002-03-10 15:20:44 +00:00
|
|
|
|
|
|
|
if (reload_config) {
|
|
|
|
/* SIGHUP received, do /RELOAD */
|
|
|
|
reload_config = FALSE;
|
|
|
|
signal_emit("command reload", 1, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
dirty_check();
|
2001-10-28 18:40:12 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|