move mutt_strsysexit into lib-sys/exit.[hc]
authorPierre Habouzit <madcoder@debian.org>
Sun, 12 Nov 2006 00:35:27 +0000 (01:35 +0100)
committerPierre Habouzit <madcoder@debian.org>
Sun, 12 Nov 2006 00:35:27 +0000 (01:35 +0100)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
commands.c
lib-sys/Makefile.am
lib-sys/exit.c [new file with mode: 0644]
lib-sys/exit.h [new file with mode: 0644]
lib-sys/mutt_tunnel.c
lib.c
lib.h
sendlib.c

index 3ad59c8..6a0dc10 100644 (file)
@@ -29,6 +29,8 @@
 
 #include <lib-mime/mime.h>
 
+#include <lib-sys/exit.h>
+
 #include <lib-ui/curses.h>
 #include <lib-ui/enter.h>
 #include <lib-ui/menu.h>
index de7194f..5e896e5 100644 (file)
@@ -1,7 +1,10 @@
 noinst_LIBRARIES = libsys.a
 
-libsys_a_SOURCES = mutt_socket.h mutt_tunnel.c mutt_ssl.h \
-                      mutt_socket.c mutt_tunnel.h mutt_ssl.c mutt_ssl_gnutls.c
+libsys_a_SOURCES = exit.h \
+                  exit.c \
+                  $(___networking_part____) \
+                  mutt_socket.h mutt_tunnel.c mutt_ssl.h \
+                  mutt_socket.c mutt_tunnel.h mutt_ssl.c mutt_ssl_gnutls.c
 
 noinst_HEADERS   = mutt_socket.h mutt_tunnel.c mutt_ssl.h
 
diff --git a/lib-sys/exit.c b/lib-sys/exit.c
new file mode 100644 (file)
index 0000000..0b4e499
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ *  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., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  Copyright © 2006 Pierre Habouzit
+ */
+/*
+ * Copyright notice from original mutt:
+ * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
+ * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
+ *
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
+ */
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+#ifdef HAVE_SYSEXITS_H
+#include <sysexits.h>
+#else /* Make sure EX_OK is defined <philiph@pobox.com> */
+#define EX_OK 0
+#endif
+
+#include <lib-lib/mem.h>
+
+#include "exit.h"
+
+static const struct {
+    int v;
+    const char *str;
+} sysexits_h[] = {
+#ifdef EX_USAGE
+    { 0xff & EX_USAGE, "Bad usage." },
+#endif
+#ifdef EX_DATAERR
+    { 0xff & EX_DATAERR, "Data format error." },
+#endif
+#ifdef EX_NOINPUT
+    { 0xff & EX_NOINPUT, "Cannot open input." },
+#endif
+#ifdef EX_NOUSER
+    { 0xff & EX_NOUSER, "User unknown." },
+#endif
+#ifdef EX_NOHOST
+    { 0xff & EX_NOHOST, "Host unknown." },
+#endif
+#ifdef EX_UNAVAILABLE
+    { 0xff & EX_UNAVAILABLE, "Service unavailable." },
+#endif
+#ifdef EX_SOFTWARE
+    { 0xff & EX_SOFTWARE, "Internal error." },
+#endif
+#ifdef EX_OSERR
+    { 0xff & EX_OSERR, "Operating system error." },
+#endif
+#ifdef EX_OSFILE
+    { 0xff & EX_OSFILE, "System file missing." },
+#endif
+#ifdef EX_CANTCREAT
+    { 0xff & EX_CANTCREAT, "Can't create output." },
+#endif
+#ifdef EX_IOERR
+    { 0xff & EX_IOERR, "I/O error." },
+#endif
+#ifdef EX_TEMPFAIL
+    { 0xff & EX_TEMPFAIL, "Deferred." },
+#endif
+#ifdef EX_PROTOCOL
+    { 0xff & EX_PROTOCOL, "Remote protocol error." },
+#endif
+#ifdef EX_NOPERM
+    { 0xff & EX_NOPERM, "Insufficient permission." },
+#endif
+#ifdef EX_CONFIG
+    { 0xff & EX_NOPERM, "Local configuration error." },
+#endif
+    { S_ERR, "Exec error." },
+};
+
+const char *m_strsysexit(int e)
+{
+    int i;
+
+    for (i = 0; countof(sysexits_h); i++) {
+        if (e == sysexits_h[i].v)
+            return sysexits_h[i].str;
+    }
+
+    return "";
+}
diff --git a/lib-sys/exit.h b/lib-sys/exit.h
new file mode 100644 (file)
index 0000000..2602ebd
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *  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., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  Copyright © 2006 Pierre Habouzit
+ */
+/*
+ * Copyright notice from original mutt:
+ * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
+ * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
+ *
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
+ */
+
+#ifndef MUTT_LIB_SYS_EXIT_H
+#define MUTT_LIB_SYS_EXIT_H
+
+/* Exit values used in send_msg() */
+#define S_ERR 127
+#define S_BKG 126
+
+const char *m_strsysexit(int e);
+
+#endif /* MUTT_LIB_SYS_EXIT_H */
index a37fa11..d82ec63 100644 (file)
@@ -127,7 +127,7 @@ static int tunnel_socket_close (CONNECTION * conn)
   if (!WIFEXITED(status) || WEXITSTATUS(status)) {
     mutt_error(_("Tunnel to %s returned error %d (%s)"),
                conn->account.host, WEXITSTATUS(status),
-               NONULL(mutt_strsysexit(WEXITSTATUS(status))));
+               m_strsysexit(WEXITSTATUS(status)));
     mutt_sleep (2);
   }
   p_delete(&conn->sockdata);
diff --git a/lib.c b/lib.c
index d07878a..39676a5 100644 (file)
--- a/lib.c
+++ b/lib.c
 #include <fcntl.h>
 #include <pwd.h>
 
-#ifdef HAVE_SYSEXITS_H
-#include <sysexits.h>
-#else /* Make sure EX_OK is defined <philiph@pobox.com> */
-#define EX_OK 0
-#endif
-
 #include <lib-lib/macros.h>
 #include <lib-lib/mem.h>
 #include <lib-lib/str.h>
 
 #include "lib.h"
 
-
-static struct sysexits
-{
-  int v;
-  const char *str;
-} 
-sysexits_h[] = 
-{
-#ifdef EX_USAGE
-  { 0xff & EX_USAGE, "Bad usage." },
-#endif
-#ifdef EX_DATAERR
-  { 0xff & EX_DATAERR, "Data format error." },
-#endif
-#ifdef EX_NOINPUT
-  { 0xff & EX_NOINPUT, "Cannot open input." },
-#endif
-#ifdef EX_NOUSER
-  { 0xff & EX_NOUSER, "User unknown." },
-#endif
-#ifdef EX_NOHOST
-  { 0xff & EX_NOHOST, "Host unknown." },
-#endif
-#ifdef EX_UNAVAILABLE
-  { 0xff & EX_UNAVAILABLE, "Service unavailable." },
-#endif
-#ifdef EX_SOFTWARE
-  { 0xff & EX_SOFTWARE, "Internal error." },
-#endif
-#ifdef EX_OSERR
-  { 0xff & EX_OSERR, "Operating system error." },
-#endif
-#ifdef EX_OSFILE
-  { 0xff & EX_OSFILE, "System file missing." },
-#endif
-#ifdef EX_CANTCREAT
-  { 0xff & EX_CANTCREAT, "Can't create output." },
-#endif
-#ifdef EX_IOERR
-  { 0xff & EX_IOERR, "I/O error." },
-#endif
-#ifdef EX_TEMPFAIL
-  { 0xff & EX_TEMPFAIL, "Deferred." },
-#endif
-#ifdef EX_PROTOCOL
-  { 0xff & EX_PROTOCOL, "Remote protocol error." },
-#endif
-#ifdef EX_NOPERM
-  { 0xff & EX_NOPERM, "Insufficient permission." },
-#endif
-#ifdef EX_CONFIG
-  { 0xff & EX_NOPERM, "Local configuration error." },
-#endif
-  { S_ERR, "Exec error." },
-  { -1, NULL}
-};
-
 void mutt_nocurses_error (const char *fmt, ...)
 {
   va_list ap;
@@ -108,17 +45,3 @@ void mutt_nocurses_error (const char *fmt, ...)
   fputc ('\n', stderr);
 }
 
-
-const char *
-mutt_strsysexit(int e)
-{
-  int i;
-  
-  for(i = 0; sysexits_h[i].str; i++)
-  {
-    if(e == sysexits_h[i].v)
-      break;
-  }
-  
-  return sysexits_h[i].str;
-}
diff --git a/lib.h b/lib.h
index 44a793a..3985310 100644 (file)
--- a/lib.h
+++ b/lib.h
 
 void mutt_exit (int);
 
-/* Exit values used in send_msg() */
-#define S_ERR 127
-#define S_BKG 126
-
 /* The actual library functions. */
 
 void mutt_nocurses_error (const char *, ...);
 
-const char *mutt_strsysexit(int e);
-
 #endif
index 2afe601..e6c0359 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -31,6 +31,8 @@
 #include <lib-lib/file.h>
 #include <lib-lib/debug.h>
 
+#include <lib-sys/exit.h>
+
 #include <lib-mime/mime.h>
 
 #include <lib-ui/curses.h>
@@ -2024,11 +2026,8 @@ static int mutt_invoke_sendmail (address_t * from,        /* the sender */
 
   if ((i = send_msg (path, args, msg, &childout)) != (EX_OK & 0xff)) {
     if (i != S_BKG) {
-      const char *e = mutt_strsysexit (i);
-
-      e = mutt_strsysexit (i);
       mutt_error (_("Error sending message, child exited %d (%s)."), i,
-                  NONULL (e));
+                  m_strsysexit(i));
       if (childout) {
         struct stat st;