Move the threading stuff in the evtloop module.
[apps/madmutt.git] / main.c
diff --git a/main.c b/main.c
index c2d06c5..cc432d9 100644 (file)
--- a/main.c
+++ b/main.c
@@ -21,6 +21,7 @@
 
 #include <lib-lua/lib-lua.h>
 #include <lib-sys/mutt_signal.h>
+#include <lib-sys/evtloop.h>
 #include <lib-mime/mime.h>
 #include <lib-ui/lib-ui.h>
 #include <lib-mx/mx.h>
@@ -45,13 +46,9 @@ extern int optind;
 #include <stringprep.h>
 #endif
 
-#ifdef USE_NNTP
-#include "nntp.h"
-#endif
-
 #ifdef USE_HCACHE
-#if defined(HAVE_QDBM)
-#include <depot.h>
+#if defined(HAVE_TOKYOCABINET)
+#include <tcutil.h>
 #elif defined(HAVE_GDBM)
 #include <gdbm.h>
 #endif
@@ -60,6 +57,8 @@ extern int optind;
 #include <gnutls/gnutls.h>
 #include <gpgme.h>
 
+#include <libintl.h>
+
 void mutt_exit(int code)
 {
     mutt_endwin(NULL);
@@ -68,7 +67,7 @@ void mutt_exit(int code)
 
 static void mutt_usage (void)
 {
-    puts(mutt_make_version());
+    puts(madmutt_version);
 
     puts(_("\
 usage: madmutt [ -nRyzZ ] [ -e <cmd> ] [ -F <file> ] [ -f <file> ]\n\
@@ -83,10 +82,6 @@ usage: madmutt [ -nRyzZ ] [ -e <cmd> ] [ -F <file> ] [ -f <file> ]\n\
     puts(_("  -e <command>  specify a command to be executed after initialization"));
     puts(_("  -f <file>     specify which mailbox to read"));
     puts(_("  -F <file>     specify an alternate Madmuttrc file"));
-#ifdef USE_NNTP
-    puts(_("  -g <server>   specify a newsserver"));
-    puts(_("  -G            select a newsgroup"));
-#endif
     puts(_("  -H <file>     specify a draft file to read header and body from"));
     puts(_("  -i <file>     specify a file which Madmutt should include in the body"));
     puts(_("  -n            causes Madmutt not to read the system Madmuttrc"));
@@ -94,7 +89,6 @@ usage: madmutt [ -nRyzZ ] [ -e <cmd> ] [ -F <file> ] [ -f <file> ]\n\
     puts(_("  -R            open mailbox in read-only mode"));
     puts(_("  -s <subj>     specify a subject (must be in quotes if it has spaces)"));
     puts(_("  -v            show version and compile-time definitions"));
-    puts(_("  -y            select a mailbox specified in your `mailboxes' list"));
     puts(_("  -z            exit immediately if there are no messages in the mailbox"));
     puts(_("  -Z            open the first folder with new message, exit immediately if none"));
     puts(_("  -h            this help message"));
@@ -107,7 +101,7 @@ static void show_version (void)
     struct utsname uts;
     uname(&uts);
 
-    puts(mutt_make_version());
+    puts(madmutt_version);
     puts(_("  Copyright (C) 1996-2002 Michael R. Elkins and others."));
     puts(_("  Copyright (C) 2005      The Mutt-ng Team"));
     puts(_("  Copyright (C) 2006-2007 Pierre Habouzit"));
@@ -127,8 +121,8 @@ static void show_version (void)
     printf("  libidn %s\n", STRINGPREP_VERSION);
 #endif
 #ifdef USE_HCACHE
-#if defined(HAVE_QDBM)
-    printf("  qdbm %s\n", dpversion);
+#if defined(HAVE_TOKYOCABINET)
+    printf("  tokyocabinet %s\n", tcversion);
 #elif defined(HAVE_GDBM)
     printf("  gdbm %s\n", gdbm_version);
 #endif
@@ -138,26 +132,11 @@ static void show_version (void)
     puts (_("Compile Options:"));
 
     puts (
-#ifdef USE_FCNTL
-        "  +USE_FCNTL"
-#else
-        "  -USE_FCNTL"
-#endif
-#ifdef USE_FLOCK
-        "  +USE_FLOCK"
-#else
-        "  -USE_FLOCK"
-#endif
 #ifdef USE_HCACHE
         "  +USE_HCACHE"
 #else
         "  -USE_HCACHE"
 #endif
-#ifdef USE_NNTP
-        "  +USE_NNTP"
-#else
-        "  -USE_NNTP"
-#endif
 #ifdef HAVE_LIBIDN
         "  +HAVE_LIBIDN"
 #else
@@ -180,27 +159,10 @@ static void show_version (void)
     exit(0);
 }
 
-static void start_curses (void)
-{
-  km_init ();                   /* must come before mutt_init */
-  mutt_signal_initialize ();
-  if (initscr () == NULL) {
-    puts _("Error initializing terminal.");
-
-    exit (1);
-  }
-  mutt_signal_initialize ();
-  curses_initialize();
-}
-
 #define M_IGNORE  (1<<0)        /* -z */
 #define M_BUFFY   (1<<1)        /* -Z */
 #define M_NOSYSRC (1<<2)        /* -n */
 #define M_RO      (1<<3)        /* -R */
-#define M_SELECT  (1<<4)        /* -y */
-#ifdef USE_NNTP
-#define M_NEWS    (1<<5)        /* -g and -G */
-#endif
 
 __attribute__((format(printf, 1, 0)))
 static void mutt_nocurses_error (const char *fmt, ...)
@@ -247,11 +209,7 @@ int main (int argc, char **argv)
   srand48 (time (NULL));
   umask (077);
 
-  while ((i = getopt(argc, argv, "a:b:F:f:c:e:H:s:i:hnpRTtvyzZ"
-#ifdef USE_NNTP
-                                                                    "g:G"
-#endif
-                    )) >= 0)
+  while ((i = getopt(argc, argv, "a:b:F:f:c:e:H:s:i:hnpRTtvzZ")) >= 0)
     switch (i) {
     case 'a':
       if (strlen(optarg)<=512)
@@ -315,24 +273,6 @@ int main (int argc, char **argv)
       version++;
       break;
 
-    case 'y':                  /* My special hack mode */
-      flags |= M_SELECT;
-      break;
-
-#ifdef USE_NNTP
-    case 'g':                  /* Specify a newsserver */
-      {
-        char buf[LONG_STRING];
-
-        snprintf (buf, sizeof (buf), "set nntp_host=%s", optarg);
-        commands = mutt_add_list (commands, buf);
-      }
-
-    case 'G':                  /* List of newsgroups */
-      flags |= M_SELECT | M_NEWS;
-      break;
-#endif
-
     case 'z':
       flags |= M_IGNORE;
       break;
@@ -357,10 +297,14 @@ int main (int argc, char **argv)
 
   /* This must come before mutt_init() because curses needs to be started
      before calling the init_pair() function to set the color scheme.  */
-  if (!option (OPTNOCURSES))
-    start_curses();
+  if (!option (OPTNOCURSES)) {
+    km_init();
+    curses_initialize();
+    mutt_signal_initialize();
+  }
 
   /* set defaults and read init files */
+  el_initialize();
   mutt_init (flags & M_NOSYSRC, commands);
   string_list_wipe(&commands);
 
@@ -522,42 +466,11 @@ int main (int argc, char **argv)
       folder[0] = 0;
       buffy_next (folder, sizeof (folder));
     }
-    else if (flags & M_SELECT) {
-#ifdef USE_NNTP
-      if (flags & M_NEWS) {
-        set_option (OPTNEWS);
-        if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer))) {
-          mutt_endwin (Errorbuf);
-          exit (1);
-        }
-      } else
-#endif
-      if (!Incoming.len) {
-        mutt_endwin _("No incoming mailboxes defined.");
-
-        exit (1);
-      }
-      folder[0] = 0;
-      mutt_select_file(folder, sizeof(folder), M_SEL_FOLDER | M_SEL_BUFFY,
-                       NULL, NULL);
-      if (!folder[0]) {
-        mutt_endwin (NULL);
-        exit (0);
-      }
-    }
 
     if (!folder[0])
       m_strcpy(folder, sizeof(folder), NONULL(Spoolfile));
 
-#ifdef USE_NNTP
-    if (option (OPTNEWS)) {
-      unset_option (OPTNEWS);
-      nntp_expand_path (folder, sizeof (folder),
-                        &CurrentNewsSrv->conn->account);
-    } else
-#endif
-      mutt_expand_path (folder, sizeof (folder));
-
+    mutt_expand_path (folder, sizeof (folder));
     m_strreplace(&CurrentFolder, folder);
     m_strreplace(&LastFolder, folder);
 
@@ -579,6 +492,7 @@ int main (int argc, char **argv)
                                    NULL)) || !explicit_folder)
     {
       mutt_index_menu ();
+
       if (option (OPTXTERMSETTITLES))
         printf("\033]2;%s\007", NONULL(XtermLeave));
       if (Context)
@@ -589,5 +503,6 @@ int main (int argc, char **argv)
 
   luaM_shutdown();
   mutt_sasl_shutdown();
+  el_shutdown();
   exit (0);
 }