Rocco Rutte:
authorpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Sun, 20 Mar 2005 14:36:37 +0000 (14:36 +0000)
committerpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Sun, 20 Mar 2005 14:36:37 +0000 (14:36 +0000)
move towards modularization (THIS REVISION IS BROKEN)

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@210 e385b8ad-14ed-0310-8656-cc95a2468c6d

16 files changed:
Makefile.am
configure.in
lib.c
lib.h
lib/Makefile.am [new file with mode: 0644]
lib/exit.c [new file with mode: 0644]
lib/exit.h [new file with mode: 0644]
lib/intl.h [new file with mode: 0644]
lib/mem.c [new file with mode: 0644]
lib/mem.h [new file with mode: 0644]
lib/str.h [new file with mode: 0644]
nntp/newsrc.c
nntp/nntp.c
pop/pop.c
pop/pop_auth.c
pop/pop_lib.c

index 3fd390d..2cf711c 100644 (file)
@@ -19,7 +19,7 @@ NNTP_SUBDIR = nntp
 NNTP_INCLUDES = -I$(top_srcdir)/nntp
 endif
 
-SUBDIRS = m4 po intl doc contrib $(IMAP_SUBDIR) $(POP_SUBDIR) $(NNTP_SUBDIR)
+SUBDIRS = m4 po intl doc contrib lib $(IMAP_SUBDIR) $(POP_SUBDIR) $(NNTP_SUBDIR)
 
 bin_SCRIPTS = muttngbug fleang
 
@@ -41,7 +41,7 @@ muttng_SOURCES = $(BUILT_SOURCES) \
        url.c ascii.c mutt_idna.c sidebar.c hcache.c crypt-mod.c crypt-mod.h
 
 muttng_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAP) $(LIBPOP) $(LIBNNTP) \
-       $(MUTTLIBS) $(INTLLIBS) $(LIBICONV)
+       -Llib -lsane $(MUTTLIBS) $(INTLLIBS) $(LIBICONV)
 
 muttng_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAPDEPS) $(LIBPOPDEPS) $(LIBNNTPDEPS) \
        $(INTLDEPS)
index 0ab911c..c199e96 100644 (file)
@@ -1160,6 +1160,7 @@ AC_SUBST(SGML2HTML_CMD)
 AC_OUTPUT(Makefile intl/Makefile m4/Makefile
         po/Makefile.in doc/Makefile contrib/Makefile
         muttbug.sh
+        lib/Makefile
         imap/Makefile
         pop/Makefile
         nntp/Makefile
diff --git a/lib.c b/lib.c
index 1966fd6..2b15053 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -42,84 +42,6 @@ void mutt_nocurses_error (const char *fmt, ...)
   fputc ('\n', stderr);
 }
 
-void *safe_calloc (size_t nmemb, size_t size)
-{
-  void *p;
-
-  if (!nmemb || !size)
-    return NULL;
-
-  if (((size_t) - 1) / nmemb <= size) {
-    mutt_error _("Integer overflow -- can't allocate memory!");
-
-    sleep (1);
-    mutt_exit (1);
-  }
-
-  if (!(p = calloc (nmemb, size))) {
-    mutt_error _("Out of memory!");
-
-    sleep (1);
-    mutt_exit (1);
-  }
-  return p;
-}
-
-void *safe_malloc (size_t siz)
-{
-  void *p;
-
-  if (siz == 0)
-    return 0;
-  if ((p = (void *) malloc (siz)) == 0) {       /* __MEM_CHECKED__ */
-    mutt_error _("Out of memory!");
-
-    sleep (1);
-    mutt_exit (1);
-  }
-  return (p);
-}
-
-void safe_realloc (void *ptr, size_t siz)
-{
-  void *r;
-  void **p = (void **) ptr;
-
-  if (siz == 0) {
-    if (*p) {
-      free (*p);                /* __MEM_CHECKED__ */
-      *p = NULL;
-    }
-    return;
-  }
-
-  if (*p)
-    r = (void *) realloc (*p, siz);     /* __MEM_CHECKED__ */
-  else {
-    /* realloc(NULL, nbytes) doesn't seem to work under SunOS 4.1.x  --- __MEM_CHECKED__ */
-    r = (void *) malloc (siz);  /* __MEM_CHECKED__ */
-  }
-
-  if (!r) {
-    mutt_error _("Out of memory!");
-
-    sleep (1);
-    mutt_exit (1);
-  }
-
-  *p = r;
-}
-
-void safe_free (void *ptr)
-{
-  void **p = (void **) ptr;
-
-  if (*p) {
-    free (*p);                  /* __MEM_CHECKED__ */
-    *p = 0;
-  }
-}
-
 int safe_fclose (FILE ** f)
 {
   int r = 0;
diff --git a/lib.h b/lib.h
index 96f1360..a6eb67b 100644 (file)
--- a/lib.h
+++ b/lib.h
 #  include <posix1_lim.h>
 # endif
 
-# ifdef ENABLE_NLS
-#  include <libintl.h>
-# define _(a) (gettext (a))
-#  ifdef gettext_noop
-#   define N_(a) gettext_noop (a)
-#  else
-#   define N_(a) (a)
-#  endif
-# else
-#  define _(a) (a)
-#  define N_(a) a
-# endif
-
 # define TRUE 1
 # define FALSE 0
 
@@ -61,9 +48,6 @@
 # define MUTT_FORMAT(a)                _MUTT_FORMAT_1(a, "s")
 # define MUTT_FORMAT2(a,b)     _MUTT_FORMAT_1(a, b)
 
-
-# define FREE(x) safe_free(x)
-# define NONULL(x) x?x:""
 # define ISSPACE(c) isspace((unsigned char)c)
 # define strfcpy(A,B,C) strncpy(A,B,C), *(A+(C)-1)=0
 
@@ -72,7 +56,6 @@
 # define MAX(a,b) ((a) < (b) ? (b) : (a))
 # define MIN(a,b) ((a) < (b) ? (a) : (b))
 
-
 #define FOREVER while (1)
 
 /* this macro must check for *c == 0 since isspace(0) has unreliable behavior
@@ -125,15 +108,11 @@ int safe_fclose (FILE **);
 size_t mutt_quote_filename (char *, size_t, const char *);
 size_t mutt_strlen (const char *);
 
-void *safe_calloc (size_t, size_t);
-void *safe_malloc (size_t);
 void mutt_nocurses_error (const char *, ...);
 void mutt_remove_trailing_ws (char *);
 void mutt_sanitize_filename (char *, short);
 void mutt_str_replace (char **p, const char *s);
 void mutt_str_adjust (char **p);
 void mutt_unlink (const char *);
-void safe_free (void *);
-void safe_realloc (void *, size_t);
 
 #endif
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644 (file)
index 0000000..0417af1
--- /dev/null
@@ -0,0 +1,13 @@
+## Process this file with automake to produce Makefile.in
+
+AR=@AR@
+
+AUTOMAKE_OPTIONS = foreign
+
+INCLUDES = -I$(top_srcdir) -I../intl
+
+noinst_LIBRARIES = libsane.a
+noinst_HEADERS = mem.h str.h exit.h intl.h
+
+libsane_a_SOURCES = mem.c exit.c \
+                   mem.h exit.h str.h intl.h
diff --git a/lib/exit.c b/lib/exit.c
new file mode 100644 (file)
index 0000000..fb46b82
--- /dev/null
@@ -0,0 +1,21 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "exit.h"
+#include "str.h"
+#include "intl.h"
+
+/* XXX remove after modularization*/
+extern void mutt_endwin (void*);
+
+void exit_fatal (const char* func, const char* msg, int line, 
+                 const char* fname, int code) {
+  mutt_endwin (NULL);
+  fprintf (stderr, _("Fatal error in function '%s' called from "
+                     "file '%s', line '%d': %s\n"
+                     "(please report this error to "
+                     "<mutt-ng-devel@lists.berlios.de>\n"),
+           NONULL(func), NONULL(fname), line, NONULL(msg));
+  exit (code);
+}
diff --git a/lib/exit.h b/lib/exit.h
new file mode 100644 (file)
index 0000000..3cc4537
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef _LIB_EXIT_H
+#define _LIB_EXIT_H
+
+void exit_fatal (const char*, const char*, int, const char*, int);
+
+#endif /* !_LIB_EXIT_H */
diff --git a/lib/intl.h b/lib/intl.h
new file mode 100644 (file)
index 0000000..b124bef
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef _LIB_INTL_H
+#define _LIB_INTL_H
+
+/*
+ * config.h must be included by source file!
+ */
+
+# ifdef ENABLE_NLS
+#  include <libintl.h>
+# define _(a) (gettext (a))
+#  ifdef gettext_noop
+#   define N_(a) gettext_noop (a)
+#  else
+#   define N_(a) (a)
+#  endif
+# else
+#  define _(a) (a)
+#  define N_(a) a
+# endif
+
+#endif /* !_LIB_INTL_H */
diff --git a/lib/mem.c b/lib/mem.c
new file mode 100644 (file)
index 0000000..ba40e98
--- /dev/null
+++ b/lib/mem.c
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+
+#include "mem.h"
+#include "exit.h"
+#include "intl.h"
+
+void *_safe_calloc (size_t nmemb, size_t size, int line, const char* fname) {
+  void *p;
+
+  if (!nmemb || !size)
+    return NULL;
+
+  if (((size_t) - 1) / nmemb <= size) {
+    exit_fatal ("safe_calloc", _("Integer overflow -- can't allocate memory!"),
+                line, fname, 1);
+    return (NULL);
+  }
+
+  if (!(p = calloc (nmemb, size))) {
+    exit_fatal ("safe_calloc", _("Out of memory!"), line, fname, 1);
+    return (NULL);
+  }
+  return p;
+}
+
+void *_safe_malloc (size_t siz, int line, const char* fname) {
+  void *p;
+
+  if (siz == 0)
+    return 0;
+  if ((p = (void *) malloc (siz)) == 0) {       /* __MEM_CHECKED__ */
+    exit_fatal ("safe_malloc", _("Out of memory!"), line, fname, 1);
+    return (NULL);
+  }
+  return (p);
+}
+
+void _safe_realloc (void *ptr, size_t siz, int line, const char* fname) {
+  void *r;
+  void **p = (void **) ptr;
+
+  if (siz == 0) {
+    if (*p) {
+      free (*p);                /* __MEM_CHECKED__ */
+      *p = NULL;
+    }
+    return;
+  }
+
+  if (*p)
+    r = (void *) realloc (*p, siz);     /* __MEM_CHECKED__ */
+  else {
+    /* realloc(NULL, nbytes) doesn't seem to work under SunOS 4.1.x  --- __MEM_CHECKED__ */
+    r = (void *) malloc (siz);  /* __MEM_CHECKED__ */
+  }
+
+  if (!r)
+    exit_fatal ("safe_realloc", _("Out of memory!"), line, fname, 1);
+
+  *p = r;
+}
+
+void safe_free (void *ptr) {
+  void **p = (void **) ptr;
+
+  if (*p) {
+    free (*p);                  /* __MEM_CHECKED__ */
+    *p = 0;
+  }
+}
diff --git a/lib/mem.h b/lib/mem.h
new file mode 100644 (file)
index 0000000..8ea8160
--- /dev/null
+++ b/lib/mem.h
@@ -0,0 +1,20 @@
+/*
+ * 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 _LIB_MEM_H
+#define _LIB_MEM_H
+
+void* _safe_malloc (size_t, int, const char*);
+void* _safe_calloc (size_t, size_t, int, const char*);
+void _safe_realloc (void*, size_t, int, const char*);
+void _safe_free (void*);
+
+#define safe_malloc(s) _safe_malloc(s,__LINE__,__FILE__)
+#define safe_calloc(s,c) _safe_calloc(s,c,__LINE__,__FILE__)
+#define safe_realloc(p,c) _safe_realloc(p,c,__LINE__,__FILE__)
+#define FREE(x) _safe_free(x)
+
+#endif /* !_LIB_MEM_H */
diff --git a/lib/str.h b/lib/str.h
new file mode 100644 (file)
index 0000000..b9adfec
--- /dev/null
+++ b/lib/str.h
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */
+
+/* mutt functions which are generally useful. */
+
+#ifndef _LIB_STR_H
+#define _LIB_STR_H
+
+#define NONULL(x) x?x:""
+
+#endif /* !_LIB_STR_H */
index 10a539f..22ff5a2 100644 (file)
 #include "rfc1524.h"
 #include "rfc2047.h"
 
+#include "lib/mem.h"
+#include "lib/str.h"
+#include "lib/intl.h"
+
 #include <unistd.h>
 #include <string.h>
 #include <ctype.h>
index efd887f..5fbe0c7 100644 (file)
 #include "smime.h"
 #endif
 
+#include "lib/mem.h"
+#include "lib/str.h"
+#include "lib/intl.h"
+
 #include <unistd.h>
 #include <string.h>
 #include <ctype.h>
index 358bed6..b2edb96 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
 #include "pop.h"
 #include "mutt_crypt.h"
 
+#include "lib/mem.h"
+#include "lib/str.h"
+#include "lib/intl.h"
+
 #include <string.h>
 #include <unistd.h>
 
index d715d7e..7499816 100644 (file)
@@ -16,6 +16,9 @@
 #include "md5.h"
 #include "pop.h"
 
+#include "lib/mem.h"
+#include "lib/intl.h"
+
 #include <string.h>
 #include <unistd.h>
 
index 093a70e..b17cb25 100644 (file)
@@ -19,6 +19,9 @@
 # include "mutt_ssl.h"
 #endif
 
+#include "lib/mem.h"
+#include "lib/intl.h"
+
 #include <string.h>
 #include <unistd.h>
 #include <ctype.h>