if (list_empty(Incoming) || !path || !*path)
return (-1);
for (i = 0; i < Incoming->length; i++) {
- if (str_eq (((BUFFY*) Incoming->data[i])->path, path) )
+ if (!m_strcmp(((BUFFY*)Incoming->data[i])->path, path) )
return (i);
}
return (-1);
mutt_extract_token (path, s, 0);
m_strcpy(buf, sizeof(buf), path->data);
- if (data == M_UNMAILBOXES && str_eq (buf, "*")) {
+ if (data == M_UNMAILBOXES && !strcmp(buf, "*")) {
list_del (&Incoming, (list_del_t*) buffy_free);
return 0;
}
* before polling */
if (!Context || !Context->path || (local ? (sb.st_dev != contex_sb.st_dev ||
sb.st_ino != contex_sb.st_ino) :
- !str_eq (tmp->path, Context->path))) {
+ !m_strcmp(tmp->path, Context->path))) {
switch (tmp->magic) {
case M_MBOX:
case M_MMDF:
i = 1 + buffy_lookup (s);
for (l=0; l < Incoming->length; l++) {
c = (l+i) % Incoming->length;
- if ((!Context || !Context->path || !str_eq (((BUFFY*) Incoming->data[c])->path, Context->path)) &&
+ if ((!Context || !Context->path || m_strcmp(((BUFFY*) Incoming->data[c])->path, Context->path)) &&
((BUFFY*) Incoming->data[c])->new > 0)
break;
}
if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
&& buf[0]) {
p_delete(&msg->env->newsgroups);
- str_skip_trailws (buf);
- msg->env->newsgroups = m_strdup(vskipspaces(buf));
+ m_strrtrim(buf);
+ msg->env->newsgroups = m_strdup(skipspaces(buf));
move (HDR_TO, HDR_XOFFSET);
clrtoeol ();
if (msg->env->newsgroups)
if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
&& buf[0]) {
p_delete(&msg->env->followup_to);
- str_skip_trailws (buf);
- msg->env->followup_to = m_strdup(vskipspaces(buf));
+ m_strrtrim(buf);
+ msg->env->followup_to = m_strdup(skipspaces(buf));
move (HDR_CC, HDR_XOFFSET);
clrtoeol ();
if (msg->env->followup_to)
|| (option (OPTPGPLONGIDS)
&& !m_strncasecmp(p, "0x", 2)
&& !m_strcasecmp(p + 2, crypt_keyid (k) + 8))
- || str_isstr (k->uid, p)) {
+ || m_stristr(k->uid, p)) {
crypt_key_t *tmp;
debug_print (5, ("match.\n"));
p = vskipspaces(cur->data + 7);
if (*p) {
if ((q = strpbrk (p, " \t"))) {
- str_substrcpy(path, p, q, sizeof(path));
+ m_strncpy(path, sizeof(path), p, q - p);
q = vskipspaces(q);
}
else
if (mutt_bit_isset (idata->rights, ACL_WRITE))
imap_add_keywords (flags, hdr, idata->flags, sizeof (flags));
- str_skip_trailws (flags);
+ m_strrtrim(flags);
/* UW-IMAP is OK with null flags, Cyrus isn't. The only solution is to
* explicitly revoke all system flags (if we have permission) */
imap_set_flag (idata, ACL_WRITE, 1, "\\Answered ", flags, sizeof (flags));
imap_set_flag (idata, ACL_DELETE, 1, "\\Deleted ", flags, sizeof (flags));
- str_skip_trailws (flags);
+ m_strrtrim(flags);
mutt_buffer_addstr (cmd, " -FLAGS.SILENT (");
} else
uname (&utsname);
/* some systems report the FQDN instead of just the hostname */
if ((p = strchr (utsname.nodename, '.'))) {
- Hostname = str_substrdup (utsname.nodename, p);
+ Hostname = p_dupstr(utsname.nodename, p - utsname.nodename);
p++;
m_strcpy(buffer, sizeof(buffer), p); /* save the domain for below */
}
if (*tok->dptr == '{') {
tok->dptr++;
if ((pc = strchr (tok->dptr, '}'))) {
- var = str_substrdup (tok->dptr, pc);
+ var = p_dupstr(tok->dptr, pc - tok->dptr);
tok->dptr = pc + 1;
}
} else {
#include "file.h"
#include "../lib/debug.h"
-#include "../lib/str.h"
#ifndef O_NOFOLLOW
# define O_NOFOLLOW 0
return len;
}
+
+char *m_strrtrim(char *s)
+{
+ if (s) {
+ char *p = s + m_strlen(s);
+
+ while (p > s && ISSPACE(p[-1])) {
+ *--p = '\0';
+ }
+ return p;
+ }
+
+ return NULL;
+}
+
+const char *m_stristrn(const char *haystack, const char *needle, ssize_t nlen)
+{
+ int nc;
+
+ if (!nlen)
+ return haystack;
+
+ nc = tolower(*needle);
+ for (;;) {
+ int c = tolower(*haystack);
+
+ if (c != nc) {
+ if (c == '\0')
+ return NULL;
+ } else {
+ ssize_t i;
+
+ /* compare the rest of needle */
+ for (i = 1;; i++) {
+ if (i == nlen)
+ return haystack;
+ if (c == '\0')
+ return NULL;
+ c = tolower(haystack[i]);
+ if (c != tolower(needle[i]))
+ break;
+ }
+ }
+
+ haystack++;
+ }
+}
#include <string.h>
#include <ctype.h>
-#include "../lib/str.h"
-
#include "mem.h"
#define HUGE_STRING 5120
extern char const __m_b36chars_upper[36];
/****************************************************************************/
-/* char related */
+/* conversions */
/****************************************************************************/
static inline int hexval(int c) {
return (c & ~127) ? -1 : __m_b64digits[c];
}
+static inline void m_strtolower(char *p) {
+ for (; *p; p++)
+ *p = tolower((unsigned char)*p);
+}
+
/****************************************************************************/
/* length related */
/****************************************************************************/
return len ? p_dup(s, len + 1) : NULL;
}
+static inline char *m_substrdup(const char *s, const char *end) {
+ return p_dupstr(s, end ? end - s : m_strlen(s));
+}
+
static inline char *m_strreplace(char **p, const char *s) {
p_delete(p);
return (*p = m_strdup(s));
return (char *)skipspaces(s);
}
+char *m_strrtrim(char *s);
+
+/****************************************************************************/
+/* search */
+/****************************************************************************/
+
+const char *
+m_stristrn(const char *haystack, const char *needle, ssize_t nlen);
+
+static inline const char *
+m_stristr(const char *haystack, const char *needle) {
+ return m_stristrn(haystack, needle, m_strlen(needle));
+}
+
#endif /* MUTT_LIB_LIB_STR_H */
AUTOMAKE_OPTIONS = foreign
noinst_LIBRARIES = libsane.a
-noinst_HEADERS = str.h list.h rx.h debug.h
+noinst_HEADERS = list.h rx.h debug.h
-libsane_a_SOURCES = str.c list.c rx.h debug.h \
- str.h list.h rx.c debug.c
+libsane_a_SOURCES = list.c rx.h debug.h \
+ list.h rx.c debug.c
-include ../cflags.mk
+++ /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 <lib-lib/mem.h>
-#include <lib-lib/str.h>
-
-#include "str.h"
-
-/* convert all characters in the string to lowercase */
-char *str_tolower (char *s)
-{
- char *p = s;
-
- while (*p) {
- *p = tolower ((unsigned char) *p);
- p++;
- }
-
- return (s);
-}
-
-/* NULL-pointer aware string comparison functions */
-
-char *str_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 *str_substrdup(const char *begin, const char *end)
-{
- return p_dupstr(begin, (end ? end - begin : strlen(begin)));
-}
-
-const char *str_isstr (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;
-}
-
-int str_eq (const char* s1, const char* s2) {
- int l = m_strlen(s1);
-
- if (l != m_strlen(s2))
- return (0);
- return (m_strncmp(s1, s2, l) == 0);
-}
-
-void str_skip_trailws (char *s) {
- char *p;
-
- for (p = s + m_strlen(s) - 1; p >= s && ISSPACE (*p); p--)
- *p = 0;
-}
+++ /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.
- */
-#ifndef _LIB_STR_H
-#define _LIB_STR_H
-
-#include <sys/types.h>
-
-/*
- * tools
- */
-char *str_tolower (char*);
-char *str_substrcpy (char*, const char*, const char*, size_t);
-char *str_substrdup (const char*, const char*);
-int str_eq (const char*, const char*);
-const char *str_isstr (const char*, const char*);
-void str_skip_trailws (char*);
-
-#endif /* !_LIB_STR_H */
if ((p = strpbrk (d, "%@")))
*p = 0;
}
- str_tolower (d);
+ m_strtolower(d);
}
else
*d = 0;
data, flags);
if (lower)
- str_tolower (buf);
+ m_strtolower(buf);
if (nodots) {
char *p = buf;
switch (op) {
case 's':
m_strcpy(fn, sizeof (fn), NewsServer);
- str_tolower (fn);
+ m_strtolower(fn);
snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
snprintf (dest, destlen, tmp, fn);
break;
else if (!m_strncmp("201", buf, 3))
mutt_message (_("Connected to %s. Posting NOT ok."), conn->account.host);
else {
- mutt_socket_close (conn);
- str_skip_trailws (buf);
- mutt_error ("%s", buf);
+ mutt_socket_close(conn);
+ m_strrtrim(buf);
+ mutt_error("%s", buf);
sleep (2);
return -1;
}
#ifdef USE_NNTP
else if (!m_strcasecmp(line + 1, "ollowup-to")) {
if (!e->followup_to) {
- str_skip_trailws (p);
- e->followup_to = m_strdup(vskipspaces(p));
+ m_strrtrim(p);
+ e->followup_to = m_strdup(skipspaces(p));
}
matched = 1;
}
/* Take the first mailto URL */
if (url_check_scheme (beg) == U_MAILTO) {
p_delete(&e->list_post);
- e->list_post = str_substrdup (beg, end);
+ e->list_post = p_dupstr(beg, end - beg);
break;
}
}
case 'n':
if (!m_strcasecmp(line + 1, "ewsgroups")) {
p_delete(&e->newsgroups);
- str_skip_trailws (p);
- e->newsgroups = m_strdup(vskipspaces(p));
+ m_strrtrim(p);
+ e->newsgroups = m_strdup(skipspaces(p));
matched = 1;
}
break;
return NULL;
}
/* compile the sub-expression */
- buf = str_substrdup (ps.dptr + 1, p);
+ buf = p_dupstr(ps.dptr + 1, p - ps.dptr - 1);
if ((tmp = mutt_pattern_comp (buf, flags, err)) == NULL) {
p_delete(&buf);
mutt_pattern_free (&curlist);
&& !m_strcasecmp(p + 2, pgp_keyid (k)))
|| (option (OPTPGPLONGIDS) && !m_strncasecmp(p, "0x", 2)
&& !m_strcasecmp(p + 2, k->keyid + 8))
- || str_isstr (a->addr, p)) {
+ || m_stristr(a->addr, p)) {
debug_print (5, ("match.\n"));
match = 1;
break;
return 1;
for (i = 0; i < nhints; i++) {
- if (str_isstr (s, hints[i]) != NULL)
+ if (m_stristr(s, hints[i]) != NULL)
return 1;
}
}
m_strcpy(t, sizeof(pop_data->err_msg) - strlen(pop_data->err_msg), c);
- str_skip_trailws (pop_data->err_msg);
+ m_strrtrim(pop_data->err_msg);
}
/* Parse CAPA output */
break;
}
}
- str_skip_trailws (s);
+ m_strrtrim(s);
return ch;
}
for (c = tocodes, i = 0; c; c = c1 ? c1 + 1 : 0, i++) {
if ((c1 = strchr (c, ':')) == c)
continue;
- tcode[i] = str_substrdup (c, c1);
+ tcode[i] = m_substrdup(c, c1);
}
ret = (size_t) (-1);
for (c = fromcodes; c; c = c1 ? c1 + 1 : 0) {
if ((c1 = strchr (c, ':')) == c)
continue;
- fcode = str_substrdup (c, c1);
+ fcode = m_substrdup(c, c1);
ret = convert_file_to (file, fcode, ncodes, (const char **) tcode,
&cn, info);
for (q = p; *q && !ISSPACE (*q); q++);
- str_substrcpy (subtype, p, q, sizeof (subtype));
+ m_strncpy(subtype, sizeof(subtype), p, q - p);
if ((type = mutt_check_mime_type (ct)) == TYPEOTHER)
m_strcpy(xtype, sizeof(xtype), ct);
char tmp[SHORT_STRING];
BUFFY* b = (BUFFY*) Incoming->data[data];
int opt = flags & M_FORMAT_OPTIONAL;
- int c = Context && str_eq (Context->path, b->path);
+ int c = Context && !m_strcmp(Context->path, b->path);
switch (op) {
/* deleted */
SidebarWidth = COLS;
if (option (OPTSIDEBARNEWMAILONLY) && box && Context && Context->path &&
- !str_eq (Context->path, box) && ((BUFFY*) Incoming->data[idx])->new == 0)
+ m_strcmp(Context->path, box) && ((BUFFY*) Incoming->data[idx])->new == 0)
/* if $sidebar_newmail_only is set, don't display the
* box only if it's not the currently opened
* (i.e. always display the currently opened) */
continue;
/* Check if query matches this certificate */
- if (!str_isstr (fields[0], qry) && !str_isstr (fields[2], qry))
+ if (!m_stristr(fields[0], qry) && !m_stristr(fields[2], qry))
continue;
Table[cur].hash = hash;