Merge Irssi 0.8.16-rc1
[silc.git] / apps / irssi / src / fe-text / silc.c
index 1591e601cf767622f0652bad1d721f43a3909cc8..a75afd24c37f4b74f01bed8cdbd187037225e910 100644 (file)
@@ -1,7 +1,7 @@
 /*
  irssi.c : irssi
 
-    Copyright (C) 1999-2000 Timo Sirainen
+    Copyright (C) 1999-2000, 2007 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
@@ -40,7 +40,7 @@
 #include "gui-readline.h"
 #include "statusbar.h"
 #include "gui-windows.h"
-#include "textbuffer-reformat.h"
+#include "irssi-version.h"
 
 #include <signal.h>
 #include <locale.h>
@@ -79,20 +79,11 @@ static int dirty, full_redraw, dummy;
 static GMainLoop *main_loop;
 int quitting;
 
-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;
 
-
 static void sig_exit(void)
 {
-        quitting = TRUE;
+  quitting = TRUE;
 }
 
 /* redraw irssi's screen.. */
@@ -165,7 +156,6 @@ static void textui_finish_init(void)
                textbuffer_init();
                textbuffer_view_init();
                textbuffer_commands_init();
-               textbuffer_reformat_init();
                gui_expandos_init();
                gui_printtext_init();
                gui_readline_init();
@@ -176,9 +166,11 @@ static void textui_finish_init(void)
                gui_windows_init();
                statusbar_init();
                term_refresh_thaw();
+
+               /* don't check settings with dummy mode */
+               settings_check();
        }
 
-       settings_check();
        module_register("core", "fe-text");
 
 #ifdef HAVE_STATIC_PERL
@@ -190,13 +182,6 @@ static void textui_finish_init(void)
 
        fe_common_core_finish_init();
        signal_emit("irssi init finished", 0);
-
-#if 0
-       if (display_firsttimer) {
-               printtext_window(active_win, MSGLEVEL_CLIENTNOTICE,
-                                "%s", firsttimer_text);
-       }
-#endif
 }
 
 static void textui_deinit(void)
@@ -227,7 +212,6 @@ static void textui_deinit(void)
                mainwindow_activity_deinit();
                mainwindows_deinit();
                gui_expandos_deinit();
-               textbuffer_reformat_deinit();
                textbuffer_commands_deinit();
                textbuffer_view_deinit();
                textbuffer_deinit();
@@ -244,42 +228,6 @@ static void textui_deinit(void)
        core_deinit();
 }
 
-static void check_oldcrap(void)
-{
-        FILE *f;
-       char *path, str[256];
-        int found;
-
-        /* check that default.theme is up-to-date */
-       path = g_strdup_printf("%s/default.theme", get_irssi_dir());
-       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;
-       }
-
-       printf("\nYou seem to have old default.theme in "IRSSI_DIR_SHORT"/ directory.\n");
-        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 (i_toupper(str[0]) == 'Y' || str[0] == '\n' || str[0] == '\0')
-                remove(path);
-       g_free(path);
-}
-
 static void check_files(void)
 {
        struct stat statbuf;
@@ -287,8 +235,6 @@ static void check_files(void)
        if (stat(get_irssi_dir(), &statbuf) != 0) {
                /* ~/.irssi doesn't exist, first time running irssi */
                display_firsttimer = TRUE;
-       } else {
-                check_oldcrap();
        }
 }
 
@@ -307,18 +253,42 @@ static void winsock_init(void)
 }
 #endif
 
+#ifdef USE_GC
+#ifdef HAVE_GC_H
+#  include <gc.h>
+#else
+#  include <gc/gc.h>
+#endif
+
+GMemVTable gc_mem_table = {
+       GC_malloc,
+       GC_realloc,
+       GC_free,
+
+       NULL, NULL, NULL
+};
+#endif
+
 int main(int argc, char **argv)
 {
-       static struct poptOption options[] = {
-#if 0 /* --dummy is not available in SILC Client */
-               { "dummy", 'd', POPT_ARG_NONE, &dummy, 0, "Use the dummy terminal mode", NULL },
-#endif
-               { NULL, '\0', 0, NULL }
+       static int version = 0;
+       static GOptionEntry options[] = {
+               { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display version", NULL },
+               { NULL }
        };
 
+#ifdef USE_GC
+       g_mem_set_vtable(&gc_mem_table);
+#endif
+
+       core_register_options();
+       fe_common_core_register_options();
+
+       srand(time(NULL));
+
        dummy = FALSE;
        quitting = FALSE;
-       core_init_paths(argc, argv);
+       core_preinit(argv[0]);
 
        check_files();
 
@@ -328,24 +298,29 @@ int main(int argc, char **argv)
 #ifdef HAVE_SOCKS
        SOCKSinit(argv[0]);
 #endif
-#ifdef ENABLE_NLS
-       /* initialize the i18n stuff */
-       bindtextdomain(PACKAGE, LOCALEDIR);
-       textdomain(PACKAGE);
-#endif
 
-        /* setlocale() must be called at the beginning before any callsthat
-           affect it, especially regexps seem to break if they'regenerated
-           before t his call.
+       /* setlocale() must be called at the beginning before any calls that
+          affect it, especially regexps seem to break if they're generated
+          before t his call.
 
-           locales aren't actually used for anything else thanautodetection
-           of UTF-8 currently.. */
-        setlocale(LC_CTYPE, "");
+          locales aren't actually used for anything else than autodetection
+          of UTF-8 currently..
+
+          furthermore to get the users's charset with g_get_charset() properly
+          you have to call setlocale(LC_ALL, "") */
+       setlocale(LC_ALL, "");
 
        textui_init();
+
        args_register(options);
        args_execute(argc, argv);
 
+       if (version) {
+               printf(PACKAGE" " IRSSI_VERSION" (%d %04d)\n",
+                      IRSSI_VERSION_DATE, IRSSI_VERSION_TIME);
+               return 0;
+       }
+
        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");
@@ -358,7 +333,19 @@ int main(int argc, char **argv)
        /* Does the same as g_main_run(main_loop), except we
           can call our dirty-checker after each iteration */
        while (!quitting) {
+#ifdef USE_GC
+               GC_collect_a_little();
+#endif
+               if (!dummy) term_refresh_freeze();
                g_main_iteration(TRUE);
+               if (!dummy) term_refresh_thaw();
+
+               if (reload_config) {
+                       /* SIGHUP received, do /RELOAD */
+                       reload_config = FALSE;
+                       signal_emit("command reload", 1, "");
+               }
+
                 dirty_check();
        }