muttng_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAP) $(LIBPOP) $(LIBNNTP) \
-Llib -lsane $(MUTTLIBS) $(INTLLIBS) $(LIBICONV)
-muttng_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAPDEPS) $(LIBPOPDEPS) $(LIBNNTPDEPS) \
- $(INTLDEPS)
+muttng_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(top_srcdir)/lib/libsane.a \
+ $(LIBIMAPDEPS) $(LIBPOPDEPS) $(LIBNNTPDEPS) $(INTLDEPS)
makedoc_SOURCES = makedoc.c
makedoc_LDADD =
* It's licensed under the GNU General Public License,
* please see the file GPL in the top level source directory.
*/
+#ifndef _GLOBALS_H
+#define _GLOBALS_H
+
+#include "lib/str.h"
WHERE void (*mutt_error) (const char *, ...);
WHERE void (*mutt_message) (const char *, ...);
#include "sort.h"
#include "mutt_crypt.h"
#endif /* MAIN_C */
+
+#endif /* !_GLOBALS_H */
return r;
}
-char *safe_strdup (const char *s)
-{
- char *p;
- size_t l;
-
- if (!s || !*s)
- return 0;
- l = mutt_strlen (s) + 1;
- p = (char *) safe_malloc (l);
- memcpy (p, s, l);
- return (p);
-}
-
-char *safe_strcat (char *d, size_t l, const char *s)
-{
- char *p = d;
-
- if (!l)
- return d;
-
- l--; /* Space for the trailing '\0'. */
-
- for (; *d && l; l--)
- d++;
- for (; *s && l; l--)
- *d++ = *s++;
-
- *d = '\0';
-
- return p;
-}
-
-char *safe_strncat (char *d, size_t l, const char *s, size_t sl)
-{
- char *p = d;
-
- if (!l)
- return d;
-
- l--; /* Space for the trailing '\0'. */
-
- for (; *d && l; l--)
- d++;
- for (; *s && l && sl; l--, sl--)
- *d++ = *s++;
-
- *d = '\0';
-
- return p;
-}
-
-
-void mutt_str_replace (char **p, const char *s)
-{
- FREE (p);
- *p = safe_strdup (s);
-}
-
-void mutt_str_adjust (char **p)
-{
- if (!p || !*p)
- return;
- safe_realloc (p, mutt_strlen (*p) + 1);
-}
-
-/* convert all characters in the string to lowercase */
-char *mutt_strlower (char *s)
-{
- char *p = s;
-
- while (*p) {
- *p = tolower ((unsigned char) *p);
- p++;
- }
-
- return (s);
-}
-
void mutt_unlink (const char *s)
{
int fd;
}
}
-char *mutt_substrcpy (char *dest, const char *beg, const char *end,
- size_t destlen)
-{
- size_t len;
-
- len = end - beg;
- if (len > destlen - 1)
- len = destlen - 1;
- memcpy (dest, beg, len);
- dest[len] = 0;
- return dest;
-}
-
-char *mutt_substrdup (const char *begin, const char *end)
-{
- size_t len;
- char *p;
-
- if (end)
- len = end - begin;
- else
- len = mutt_strlen (begin);
-
- p = safe_malloc (len + 1);
- memcpy (p, begin, len);
- p[len] = 0;
- return p;
-}
-
/* prepare a file name to survive the shell's quoting rules.
* From the Unix programming FAQ by way of Liviu.
*/
return j;
}
-/* NULL-pointer aware string comparison functions */
-
-int mutt_strcmp (const char *a, const char *b)
-{
- return strcmp (NONULL (a), NONULL (b));
-}
-
-int mutt_strcasecmp (const char *a, const char *b)
-{
- return strcasecmp (NONULL (a), NONULL (b));
-}
-
-int mutt_strncmp (const char *a, const char *b, size_t l)
-{
- return strncmp (NONULL (a), NONULL (b), l);
-}
-
-int mutt_strncasecmp (const char *a, const char *b, size_t l)
-{
- return strncasecmp (NONULL (a), NONULL (b), l);
-}
-
-size_t mutt_strlen (const char *a)
-{
- return a ? strlen (a) : 0;
-}
-
-int mutt_strcoll (const char *a, const char *b)
-{
- return strcoll (NONULL (a), NONULL (b));
-}
-
-const char *mutt_stristr (const char *haystack, const char *needle)
-{
- const char *p, *q;
-
- if (!haystack)
- return NULL;
- if (!needle)
- return (haystack);
-
- while (*(p = haystack)) {
- for (q = needle;
- *p && *q &&
- tolower ((unsigned char) *p) == tolower ((unsigned char) *q);
- p++, q++);
- if (!*q)
- return (haystack);
- haystack++;
- }
- return NULL;
-}
-
-char *mutt_skip_whitespace (char *p)
-{
- SKIPWS (p);
- return p;
-}
-
-void mutt_remove_trailing_ws (char *s)
-{
- char *p;
-
- for (p = s + mutt_strlen (s) - 1; p >= s && ISSPACE (*p); p--)
- *p = 0;
-}
-
char *mutt_concat_path (char *d, const char *dir, const char *fname, size_t l)
{
const char *fmt = "%s/%s";
# define TRUE 1
# define FALSE 0
-# define HUGE_STRING 5120
-# define LONG_STRING 1024
-# define STRING 256
-# define SHORT_STRING 128
-
-/*
- * Create a format string to be used with scanf.
- * To use it, write, for instance, MUTT_FORMAT(HUGE_STRING).
- *
- * See K&R 2nd ed, p. 231 for an explanation.
- */
-# define _MUTT_FORMAT_2(a,b) "%" a b
-# define _MUTT_FORMAT_1(a, b) _MUTT_FORMAT_2(#a, b)
-# define MUTT_FORMAT(a) _MUTT_FORMAT_1(a, "s")
-# define MUTT_FORMAT2(a,b) _MUTT_FORMAT_1(a, b)
-
-# define ISSPACE(c) isspace((unsigned char)c)
-# define strfcpy(A,B,C) strncpy(A,B,C), *(A+(C)-1)=0
-
# undef MAX
# undef MIN
# define MAX(a,b) ((a) < (b) ? (b) : (a))
#define FOREVER while (1)
-/* this macro must check for *c == 0 since isspace(0) has unreliable behavior
- on some systems */
-# define SKIPWS(c) while (*(c) && isspace ((unsigned char) *(c))) c++;
-
-#define ISBLANK(c) (c == ' ' || c == '\t')
-/*
- * These functions aren't defined in lib.c, but
- * they are used there.
- *
- * A non-mutt "implementation" (ahem) can be found in extlib.c.
- */
-
# ifndef _EXTLIB_C
extern void (*mutt_error) (const char *, ...);
# endif
char *mutt_concat_path (char *, const char *, const char *, size_t);
char *mutt_read_line (char *, size_t *, FILE *, int *);
char *mutt_skip_whitespace (char *);
-char *mutt_strlower (char *);
-char *mutt_substrcpy (char *, const char *, const char *, size_t);
-char *mutt_substrdup (const char *, const char *);
-char *safe_strcat (char *, size_t, const char *);
-char *safe_strncat (char *, size_t, const char *, size_t);
-char *safe_strdup (const char *);
const char *mutt_stristr (const char *, const char *);
const char *mutt_basename (const char *);
int mutt_copy_stream (FILE *, FILE *);
int mutt_copy_bytes (FILE *, FILE *, size_t);
int mutt_rx_sanitize_string (char *, size_t, const char *);
-int mutt_strcasecmp (const char *, const char *);
-int mutt_strcmp (const char *, const char *);
-int mutt_strncasecmp (const char *, const char *, size_t);
-int mutt_strncmp (const char *, const char *, size_t);
-int mutt_strcoll (const char *, const char *);
+
int safe_open (const char *, int);
int safe_symlink (const char *, const char *);
int safe_rename (const char *, const char *);
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 *);
#endif
noinst_LIBRARIES = libsane.a
noinst_HEADERS = mem.h str.h exit.h intl.h list.h
-libsane_a_SOURCES = mem.c exit.c list.c \
- mem.h exit.h str.h intl.h list.h
+libsane_a_SOURCES = mem.c exit.c str.c list.c \
+ mem.h exit.h str.h list.h intl.h
--- /dev/null
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "str.h"
+
+#include "mem.h"
+
+char *safe_strdup (const char *s)
+{
+ char *p;
+ size_t l;
+
+ if (!s || !*s)
+ return 0;
+ l = mutt_strlen (s) + 1;
+ p = (char *) safe_malloc (l);
+ memcpy (p, s, l);
+ return (p);
+}
+
+char *safe_strcat (char *d, size_t l, const char *s)
+{
+ char *p = d;
+
+ if (!l)
+ return d;
+
+ l--; /* Space for the trailing '\0'. */
+
+ for (; *d && l; l--)
+ d++;
+ for (; *s && l; l--)
+ *d++ = *s++;
+
+ *d = '\0';
+
+ return p;
+}
+
+char *safe_strncat (char *d, size_t l, const char *s, size_t sl)
+{
+ char *p = d;
+
+ if (!l)
+ return d;
+
+ l--; /* Space for the trailing '\0'. */
+
+ for (; *d && l; l--)
+ d++;
+ for (; *s && l && sl; l--, sl--)
+ *d++ = *s++;
+
+ *d = '\0';
+
+ return p;
+}
+
+void mutt_str_replace (char **p, const char *s)
+{
+ FREE (p);
+ *p = safe_strdup (s);
+}
+
+void mutt_str_adjust (char **p)
+{
+ if (!p || !*p)
+ return;
+ safe_realloc (p, mutt_strlen (*p) + 1);
+}
+
+/* convert all characters in the string to lowercase */
+char *mutt_strlower (char *s)
+{
+ char *p = s;
+
+ while (*p) {
+ *p = tolower ((unsigned char) *p);
+ p++;
+ }
+
+ return (s);
+}
+
+/* NULL-pointer aware string comparison functions */
+
+char *mutt_substrcpy (char *dest, const char *beg, const char *end,
+ size_t destlen)
+{
+ size_t len;
+
+ len = end - beg;
+ if (len > destlen - 1)
+ len = destlen - 1;
+ memcpy (dest, beg, len);
+ dest[len] = 0;
+ return dest;
+}
+
+char *mutt_substrdup (const char *begin, const char *end)
+{
+ size_t len;
+ char *p;
+
+ if (end)
+ len = end - begin;
+ else
+ len = mutt_strlen (begin);
+
+ p = safe_malloc (len + 1);
+ memcpy (p, begin, len);
+ p[len] = 0;
+ return p;
+}
+
+int mutt_strcmp (const char *a, const char *b)
+{
+ return strcmp (NONULL (a), NONULL (b));
+}
+
+int mutt_strcasecmp (const char *a, const char *b)
+{
+ return strcasecmp (NONULL (a), NONULL (b));
+}
+
+int mutt_strncmp (const char *a, const char *b, size_t l)
+{
+ return strncmp (NONULL (a), NONULL (b), l);
+}
+
+int mutt_strncasecmp (const char *a, const char *b, size_t l)
+{
+ return strncasecmp (NONULL (a), NONULL (b), l);
+}
+
+size_t mutt_strlen (const char *a)
+{
+ return a ? strlen (a) : 0;
+}
+
+int mutt_strcoll (const char *a, const char *b)
+{
+ return strcoll (NONULL (a), NONULL (b));
+}
+
+const char *mutt_stristr (const char *haystack, const char *needle)
+{
+ const char *p, *q;
+
+ if (!haystack)
+ return NULL;
+ if (!needle)
+ return (haystack);
+
+ while (*(p = haystack)) {
+ for (q = needle;
+ *p && *q &&
+ tolower ((unsigned char) *p) == tolower ((unsigned char) *q);
+ p++, q++);
+ if (!*q)
+ return (haystack);
+ haystack++;
+ }
+ return NULL;
+}
+
+char *mutt_skip_whitespace (char *p)
+{
+ SKIPWS (p);
+ return p;
+}
+
+void mutt_remove_trailing_ws (char *s)
+{
+ char *p;
+
+ for (p = s + mutt_strlen (s) - 1; p >= s && ISSPACE (*p); p--)
+ *p = 0;
+}
+
* 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
+#include <sys/types.h>
+
#define NONULL(x) x?x:""
+# define HUGE_STRING 5120
+# define LONG_STRING 1024
+# define STRING 256
+# define SHORT_STRING 128
+
+/*
+ * Create a format string to be used with scanf.
+ * To use it, write, for instance, MUTT_FORMAT(HUGE_STRING).
+ *
+ * See K&R 2nd ed, p. 231 for an explanation.
+ */
+# define _MUTT_FORMAT_2(a,b) "%" a b
+# define _MUTT_FORMAT_1(a, b) _MUTT_FORMAT_2(#a, b)
+# define MUTT_FORMAT(a) _MUTT_FORMAT_1(a, "s")
+# define MUTT_FORMAT2(a,b) _MUTT_FORMAT_1(a, b)
+
+# define ISSPACE(c) isspace((unsigned char)c)
+# define strfcpy(A,B,C) strncpy(A,B,C), *(A+(C)-1)=0
+
+/* this macro must check for *c == 0 since isspace(0) has unreliable behavior
+ on some systems */
+# define SKIPWS(c) while (*(c) && isspace ((unsigned char) *(c))) c++;
+
+#define ISBLANK(c) (c == ' ' || c == '\t')
+/*
+ * These functions aren't defined in lib.c, but
+ * they are used there.
+ *
+ * A non-mutt "implementation" (ahem) can be found in extlib.c.
+ */
+
+char *mutt_strlower (char *);
+char *mutt_substrcpy (char *, const char *, const char *, size_t);
+char *mutt_substrdup (const char *, const char *);
+char *safe_strcat (char *, size_t, const char *);
+char *safe_strncat (char *, size_t, const char *, size_t);
+char *safe_strdup (const char *);
+int mutt_strcasecmp (const char *, const char *);
+int mutt_strcmp (const char *, const char *);
+int mutt_strncasecmp (const char *, const char *, size_t);
+int mutt_strncmp (const char *, const char *, size_t);
+int mutt_strcoll (const char *, const char *);
+void mutt_str_replace (char **p, const char *s);
+void mutt_str_adjust (char **p);
+size_t mutt_strlen (const char *a);
+
#endif /* !_LIB_STR_H */