/* assume that the user wants to see everything */
if (!buf[0])
m_strcpy(buf, sizeof(buf), ".");
- SKIPWS (s);
+ s = vskipspaces(s);
if (*s == '!') {
- s++;
- SKIPWS (s);
+ s = vskipspaces(s + 1);
not = 1;
}
&& buf[0]) {
p_delete(&msg->env->newsgroups);
str_skip_trailws (buf);
- msg->env->newsgroups = m_strdup(str_skip_initws (buf));
+ msg->env->newsgroups = m_strdup(vskipspaces(buf));
move (HDR_TO, HDR_XOFFSET);
clrtoeol ();
if (msg->env->newsgroups)
&& buf[0]) {
p_delete(&msg->env->followup_to);
str_skip_trailws (buf);
- msg->env->followup_to = m_strdup(str_skip_initws (buf));
+ msg->env->followup_to = m_strdup(vskipspaces(buf));
move (HDR_CC, HDR_XOFFSET);
clrtoeol ();
if (msg->env->followup_to)
while (p >= tmp && ISSPACE (*p))
*p-- = 0;
- p = tmp + 2;
- SKIPWS (p);
+ p = vskipspaces(tmp + 2);
switch (tmp[1]) {
case '?':
#include <ctype.h>
#include <string.h>
-static const char *next_word (const char *s)
+static const char *next_word(const char *s)
{
- while (*s && !ISSPACE (*s))
- s++;
- SKIPWS (s);
- return s;
+ while (*s && !ISSPACE(*s))
+ s++;
+ s = skipspaces(s);
+ return s;
}
int mutt_check_month (const char *s)
debug_print (3, ("got return path: %s\n", path));
}
- s = p + 1;
- SKIPWS (s);
+ s = vskipspaces(p + 1);
if (!*s)
return 0;
* message based upon this one.
*/
if (fcc && ascii_strncasecmp ("fcc:", cur->data, 4) == 0) {
- p = cur->data + 4;
- SKIPWS (p);
+ p = vskipspaces(cur->data + 4);
if (*p) {
m_strcpy(fcc, fcclen, p);
mutt_pretty_mailbox (fcc);
BODY *parts;
char *q;
- p = cur->data + 7;
- SKIPWS (p);
+ p = vskipspaces(cur->data + 7);
if (*p) {
if ((q = strpbrk (p, " \t"))) {
- str_substrcpy (path, p, q, sizeof (path));
- SKIPWS (q);
+ str_substrcpy(path, p, q, sizeof(path));
+ q = vskipspaces(q);
}
else
m_strcpy(path, sizeof(path), p);
n = COLS - col;
if (ismacro >= 0) {
- SKIPWS (t3);
+ t3 = vskipspaces(t3);
/* FIXME: this is completely wrong */
if ((n = m_strlen(t3)) > COLS - col) {
p_clear(&command, 1);
if (*s->dptr == '!') {
- s->dptr++;
- SKIPWS (s->dptr);
+ s->dptr = vskipspaces(s->dptr + 1);
not = 1;
}
/* imap_code: returns 1 if the command result was OK, or 0 if NO or BAD */
int imap_code (const char *s)
{
- s += SEQLEN;
- SKIPWS (s);
- return (ascii_strncasecmp ("OK", s, 2) == 0);
+ s = vskipspaces(s + SEQLEN);
+ return !ascii_strncasecmp("OK", s, 2);
}
/* imap_exec: execute a command, and wait for the response from the server.
return 0;
/* server shut down our connection */
- s += 3;
- SKIPWS (s);
+ s = vskipspaces(s + 3);
mutt_error ("%s", s);
mutt_sleep (2);
cmd_handle_fatal (idata);
debug_print (1, ("not a FLAGS response: %s\n", s));
return NULL;
}
- s += 5;
- SKIPWS (s);
+ s = vskipspaces(s + 5);
if (*s != '(') {
debug_print (1, ("bogus FLAGS response: %s\n", s));
return NULL;
*hflags = flags;
while (*s && *s != ')') {
- s++;
- SKIPWS (s);
+ s = vskipspaces(s + 1);
flag_word = s;
while (*s && (*s != ')') && !ISSPACE (*s))
s++;
mutt_buffer_addch (buf, ' ');
/* and field */
- *delim = ':';
- delim++;
- SKIPWS(delim);
+ *delim++ = ':';
+ delim = vskipspaces(delim);
imap_quote_string (term, sizeof (term), delim);
mutt_buffer_addstr (buf, term);
break;
debug_print (1, ("command failed: %s\n", idata->cmd.buf));
- pc = idata->cmd.buf + SEQLEN;
- SKIPWS (pc);
+ pc = vskipspaces(idata->cmd.buf + SEQLEN);
pc = imap_next_word (pc);
mutt_error ("%s", pc);
mutt_sleep (1);
char *pc;
debug_print (1, ("command failed: %s\n", idata->cmd.buf));
- pc = idata->cmd.buf + SEQLEN;
- SKIPWS (pc);
+ pc = vskipspaces(idata->cmd.buf + SEQLEN);
pc = imap_next_word (pc);
mutt_error ("%s", pc);
mutt_sleep (1);
return -1;
while (*s) {
- SKIPWS (s);
+ s = vskipspaces(s);
if (ascii_strncasecmp ("FLAGS", s, 5) == 0) {
if ((s = msg_parse_flags (h, s)) == NULL)
return -1;
}
else if (ascii_strncasecmp ("UID", s, 3) == 0) {
- s += 3;
- SKIPWS (s);
+ s = vskipspaces(s + 3);
h->data->uid = (unsigned int) atoi (s);
s = imap_next_word (s);
}
else if (ascii_strncasecmp ("INTERNALDATE", s, 12) == 0) {
- s += 12;
- SKIPWS (s);
+ s = vskipspaces(s + 12);
if (*s != '\"') {
debug_print (1, ("bogus INTERNALDATE entry: %s\n", s));
return -1;
h->received = imap_parse_date (tmp);
}
else if (ascii_strncasecmp ("RFC822.SIZE", s, 11) == 0) {
- s += 11;
- SKIPWS (s);
+ s = vskipspaces(s + 11);
ptmp = tmp;
while (isdigit ((unsigned char) *s))
*ptmp++ = *s++;
debug_print (1, ("not a FLAGS response: %s\n", s));
return NULL;
}
- s += 5;
- SKIPWS (s);
+ s = vskipspaces(s + 5);
if (*s != '(') {
debug_print (1, ("bogus FLAGS response: %s\n", s));
return NULL;
mutt_add_list (h->data->keywords, flag_word);
*s = ctmp;
}
- SKIPWS (s);
+ s = vskipspaces(s);
}
/* wrap up, or note bad flags response */
s++;
}
- SKIPWS (s);
- return s;
+ return vskipspaces(s);
}
/* imap_parse_date: date is of the form: DD-MMM-YYYY HH:MM:SS +ZZzz */
snprintf (err->data, err->dsize, _("%s: unknown variable"), tmp->data);
return (-1);
}
- SKIPWS (s->dptr);
+ s->dptr = vskipspaces(s->dptr);
if (reset) {
if (query || unset || inv) {
debug_print (1, ("expand '%s'\n", line));
- SKIPWS (expn.dptr);
+ expn.dptr = vskipspaces(expn.dptr);
while (*expn.dptr) {
if (*expn.dptr == '#')
break; /* rest of line is a comment */
int num;
int spaces; /* keep track of the number of leading spaces on the line */
- SKIPWS (buffer);
+ buffer = vskipspaces(buffer);
spaces = buffer - pt;
pt = buffer + pos - spaces;
if (buffer[0] == 0)
return 0;
- SKIPWS (buffer);
+ buffer = vskipspaces(buffer);
spaces = buffer - pt;
pt = buffer + pos - spaces;
if ((f = safe_fopen (SYSCONFDIR "/nntpserver", "r"))) {
buffer[0] = '\0';
fgets (buffer, sizeof(buffer), f);
- p = buffer;
- SKIPWS (p);
+ p = vskipspaces(buffer);
q = (char*)p;
while (*q && !isspace(*q))
q++;
#include <string.h>
#include <ctype.h>
-#include <lib-lib/mem.h>
-#include <lib-lib/str.h>
-#include <lib-lib/ascii.h>
-#include <lib-lib/buffer.h>
-
-#include "mutt.h"
+#include "mem.h"
+#include "str.h"
+#include "ascii.h"
+#include "buffer.h"
+#include "file.h"
#include "lib/debug.h"
+#include "mutt.h"
+
/*
* Creates and initializes a BUFFER*. If passed an existing BUFFER*,
* just initializes. Frees anything already in the buffer.
/* reset the destination pointer to the beginning of the buffer */
dest->dptr = dest->data;
- SKIPWS(tok->dptr);
+ tok->dptr = vskipspaces(tok->dptr);
while ((ch = *tok->dptr)) {
if (!qc) {
if ((ISSPACE(ch) && !(flags & M_TOKEN_SPACE))
}
}
mutt_buffer_addch(dest, 0); /* terminate the string */
- SKIPWS(tok->dptr);
+ tok->dptr = vskipspaces(tok->dptr);
return 0;
}
#include <lib-lib/str.h>
+/* flags for mutt_extract_token() */
+#define M_TOKEN_EQUAL 1 /* treat '=' as a special */
+#define M_TOKEN_CONDENSE (1<<1) /* ^(char) to control chars (macros) */
+#define M_TOKEN_SPACE (1<<2) /* don't treat whitespace as a term */
+#define M_TOKEN_QUOTE (1<<3) /* don't interpret quotes */
+#define M_TOKEN_PATTERN (1<<4) /* !)|~ are terms (for patterns) */
+#define M_TOKEN_COMMENT (1<<5) /* don't reap comments */
+#define M_TOKEN_SEMICOLON (1<<6) /* don't treat ; as special */
+
+
typedef struct {
char *data; /* pointer to data */
char *dptr; /* current read/write position */
#define MUTT_LIB_LIB_STR_H
#include <string.h>
+#include <ctype.h>
+
#include "../lib/str.h"
#include "mem.h"
+#define HUGE_STRING 5120
+#define LONG_STRING 1024
+#define STRING 256
+#define SHORT_STRING 128
+
#define NONULL(x) (x?x:"")
+# define ISSPACE(c) isspace((unsigned char)c)
+
+/****************************************************************************/
+/* length related */
+/****************************************************************************/
static inline int m_strisempty(const char *s) {
return !s || !*s;
return p ? p - s : n;
}
-static inline char *m_strdup(const char *s) {
- ssize_t len = m_strlen(s);
- return len ? p_dup(s, len + 1) : NULL;
-}
+/****************************************************************************/
+/* comparisons */
+/****************************************************************************/
static inline int m_strcmp(const char *a, const char *b) {
return strcmp(NONULL(a), NONULL(b));
return strncasecmp(NONULL(a), NONULL(b), n);
}
+/****************************************************************************/
+/* making copies */
+/****************************************************************************/
+
+static inline char *m_strdup(const char *s) {
+ ssize_t len = m_strlen(s);
+ return len ? p_dup(s, len + 1) : NULL;
+}
ssize_t m_strcpy(char *dst, ssize_t n, const char *src);
ssize_t m_strncpy(char *dst, ssize_t n, const char *src, ssize_t l);
return dlen + m_strncpy(dst + dlen, n - dlen, src, l);
}
+/****************************************************************************/
+/* parsing related */
+/****************************************************************************/
+
+static inline const char *skipspaces(const char *s) {
+ while (*s && isspace((unsigned char)*s))
+ s++;
+ return s;
+}
+static inline char *vskipspaces(const char *s) {
+ return (char *)skipspaces(s);
+}
+
#endif /* MUTT_LIB_LIB_STR_H */
return (m_strncmp(s1, s2, l) == 0);
}
-char* str_skip_initws (char* s) {
- SKIPWS (s);
- return (s);
-}
-
void str_skip_trailws (char *s) {
char *p;
#include <sys/types.h>
-# 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 ISBLANK(c) (c == ' ' || c == '\t')
-/* 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++;
-
/*
* tools
*/
void str_adjust (char**);
int str_eq (const char*, const char*);
const char *str_isstr (const char*, const char*);
-char* str_skip_initws (char*);
void str_skip_trailws (char*);
#endif /* !_LIB_STR_H */
#define INITVAL(x)
#endif
-/* flags for mutt_extract_token() */
-#define M_TOKEN_EQUAL 1 /* treat '=' as a special */
-#define M_TOKEN_CONDENSE (1<<1) /* ^(char) to control chars (macros) */
-#define M_TOKEN_SPACE (1<<2) /* don't treat whitespace as a term */
-#define M_TOKEN_QUOTE (1<<3) /* don't interpret quotes */
-#define M_TOKEN_PATTERN (1<<4) /* !)|~ are terms (for patterns) */
-#define M_TOKEN_COMMENT (1<<5) /* don't reap comments */
-#define M_TOKEN_SEMICOLON (1<<6) /* don't treat ; as special */
-
typedef struct {
int ch; /* raw key pressed */
int op; /* function op */
while (ISSPACE (new->attribute[--i]))
new->attribute[i] = 0;
- s = p + 1; /* skip over the = */
- SKIPWS (s);
+ s = vskipspaces(p + 1); /* skip over the = */
if (*s == '"') {
int state_ascii = 1;
break; /* no more parameters */
do {
- s++;
-
/* Move past any leading whitespace */
- SKIPWS (s);
+ s = vskipspaces(s + 1);
}
while (*s == ';'); /* skip empty parameters */
}
/* Check to see if a default filename was given */
if ((s = strchr (s, ';')) != NULL) {
- s++;
- SKIPWS (s);
- if ((s =
- mutt_get_parameter ("filename",
- (parms = parse_parameters (s)))) != 0)
+ s = vskipspaces(s + 1);
+ if ((s = mutt_get_parameter("filename",
+ (parms = parse_parameters (s)))) != 0)
str_replace (&ct->filename, s);
if ((s = mutt_get_parameter ("name", parms)) != 0)
ct->form_name = m_strdup(s);
while (*(line = mutt_read_rfc822_line (fp, line, &linelen)) != 0) {
/* Find the value of the current header */
if ((c = strchr (line, ':'))) {
- *c = 0;
- c++;
- SKIPWS (c);
+ *c++ = 0;
+ c = vskipspaces(c);
if (!*c) {
debug_print (1, ("skipping empty header field: %s\n", line));
continue;
if (*tz != '(')
return tz; /* no need to do anything */
- tz++;
- SKIPWS (tz);
+ tz = vskipspaces(tz + 1);
if ((p = strpbrk (tz, " )")) == NULL)
return tz;
len = p - tz;
t++;
else
t = scratch;
- SKIPWS (t);
+ t = vskipspaces(t);
p_clear(&tm, 1);
else if (!m_strcasecmp(line + 1, "ollowup-to")) {
if (!e->followup_to) {
str_skip_trailws (p);
- e->followup_to = m_strdup(str_skip_initws (p));
+ e->followup_to = m_strdup(vskipspaces(p));
}
matched = 1;
}
if (!m_strcasecmp(line + 1, "ewsgroups")) {
p_delete(&e->newsgroups);
str_skip_trailws (p);
- e->newsgroups = m_strdup(str_skip_initws (p));
+ e->newsgroups = m_strdup(vskipspaces(p));
matched = 1;
}
break;
}
}
- *p = 0;
- p++;
- SKIPWS (p);
+ *p++ = 0;
+ p = vskipspaces(p);
if (!*p)
continue; /* skip empty header fields */
if (skip_quote && *tmp == '"')
tmp++;
- SKIPWS (tmp);
- s->dptr = tmp;
+ s->dptr = vskipspaces(tmp);
return 0;
}
const char *pt;
char ch = *pc++;
- SKIPWS (pc);
+ pc = vskipspaces(pc);
switch (ch) {
case '-':
{
default:
flag |= M_PDR_ERRORDONE;
}
- SKIPWS (pc);
+ pc = vskipspaces(pc);
}
if ((flag & M_PDR_ERROR) && !(flag & M_PDR_ABSOLUTE)) { /* getDate has its own error message, don't overwrite it here */
snprintf (err->data, err->dsize, _("Invalid relative date: %s"), pc - 1);
return (-1);
}
haveMin = TRUE;
- SKIPWS (pc);
+ pc = vskipspaces(pc);
if (*pc == '-') {
- const char *pt = pc + 1;
+ const char *pt;
- SKIPWS (pt);
+ pt = skipspaces(pc + 1);
untilNow = (*pt == '\0');
}
}
ps.dsize = m_strlen(s);
while (*ps.dptr) {
- SKIPWS (ps.dptr);
+ ps.dptr = vskipspaces(ps.dptr);
switch (*ps.dptr) {
case '^':
ps.dptr++;
}
tmp->op = entry->op;
- ps.dptr++; /* eat the operator and any optional whitespace */
- SKIPWS (ps.dptr);
+ ps.dptr = vskipspaces(ps.dptr + 1);
if (entry->eat_arg) {
if (!*ps.dptr) {
break;
if (armor_header) {
- char *p = str_skip_initws (buf);
+ char *p = vskipspaces(buf);
if (*p == '\0')
armor_header = 0;
/* skip the armor header */
while ((r = fgets (line, sizeof (line), in)) != NULL) {
- SKIPWS (r);
+ r = vskipspaces(r);
if (!*r)
break;
}
c = msg;
if (!m_strncmp(msg, "-ERR ", 5)) {
- c2 = msg + 5;
- SKIPWS (c2);
-
+ c2 = vskipspaces(msg + 5);
if (*c2)
c = c2;
}
if (!ascii_strncasecmp (line, "SASL", 4)) {
p_delete(&pop_data->auth_list);
- c = line + 4;
- SKIPWS (c);
+ c = vskipspaces(line + 4);
pop_data->auth_list = m_strdup(c);
}
if (ctx) {
/* if a mailbox is currently open, look to see if the orignal message
the user attempted to reply to is in this mailbox */
- p = tmp->data + 18;
- SKIPWS (p);
+ p = vskipspaces(tmp->data + 18);
if (!ctx->id_hash)
ctx->id_hash = mutt_make_id_hash (ctx);
*cur = hash_find (ctx->id_hash, p);
code |= SENDREPLY;
}
else if (ascii_strncasecmp ("X-Mutt-Fcc:", tmp->data, 11) == 0) {
- p = tmp->data + 11;
- SKIPWS (p);
+ p = vskipspaces(tmp->data + 11);
m_strcpy(fcc, fcclen, p);
mutt_pretty_mailbox (fcc);
if (!WithCrypto)
return 0;
- SKIPWS (p);
- for (; *p; p++) {
+ for (p = vskipspaces(p); *p; p++) {
switch (*p) {
case 'e':
#endif
#include <lib-lib/mem.h>
+#include <lib-lib/ascii.h>
#include <lib-lib/str.h>
#include <lib-lib/macros.h>
#include <lib-lib/file.h>
{N_("Delete"), OP_MIX_DELETE},
{N_("Abort"), OP_EXIT},
{N_("OK"), OP_MIX_USE},
- {NULL}
+ {NULL, OP_NULL}
};
s++;
}
else {
- *ch++ = 0;
- SKIPWS (ch);
+ *ch++ = '\0';
+ ch = vskipspaces(ch);
break;
}
}
static int get_field_text (char *field, char **entry,
char *type, char *filename, int line)
{
- field = str_skip_initws (field);
+ field = vskipspaces(field);
if (*field == '=') {
if (entry) {
- field++;
- field = str_skip_initws (field);
+ field = vskipspaces(field + 1);
str_replace (entry, field);
}
return 1;
const char *ps;
while (*s) {
- SKIPWS (s);
+ s = vskipspaces(s);
if (strchr (nonspecial, *s) == NULL && is_special (*s))
return s;
char token[STRING];
size_t tokenlen = 0;
- SKIPWS (s);
+ s = vskipspaces(s);
/* find the end of the route */
if (*s == '@') {
ws_pending = isspace ((unsigned char) *s);
- SKIPWS (s);
- begin = s;
+ begin = s = vskipspaces(s);
while (*s) {
if (*s == ',') {
if (phraselen) {
commentlen = 0;
phraselen = 0;
s++;
- begin = s;
- SKIPWS (begin);
+ begin = vskipspaces(s);
}
else if (*s == '(') {
if (commentlen && commentlen < sizeof (comment) - 1)
phraselen = 0;
commentlen = 0;
s++;
- begin = s;
- SKIPWS (begin);
+ begin = vskipspaces(s);
}
else if (*s == ';') {
if (phraselen) {
phraselen = 0;
commentlen = 0;
s++;
- begin = s;
- SKIPWS (begin);
+ begin = vskipspaces(s);
}
else if (*s == '<') {
terminate_buffer (phrase, phraselen);
s = ps;
}
ws_pending = isspace ((unsigned char) *s);
- SKIPWS (s);
+ s = vskipspaces(s);
}
if (phraselen) {
buf[0] = 0;
for (; uh; uh = uh->next) {
if (ascii_strncasecmp ("subject:", uh->data, 8) == 0) {
- p = uh->data + 8;
- SKIPWS (p);
+ p = vskipspaces(uh->data + 8);
m_strcpy(buf, sizeof(buf), p);
}
}
}
#ifdef USE_NNTP
-char *nntp_get_header (const char *s)
+char *nntp_get_header(const char *s)
{
- SKIPWS (s);
- return m_strdup(s);
+ return m_strdup(skipspaces(s));
}
#endif
*p = 0;
/* remove any leading space. */
- ct = buf;
- SKIPWS (ct);
+ ct = vskipspaces(buf);
/* position on the next field in this line */
if ((p = strpbrk (ct, " \t")) == NULL)
continue;
*p++ = 0;
- SKIPWS (p);
+ p = vskipspaces(p);
/* cycle through the file extensions */
while ((p = strtok (p, " \t\n"))) {
/* Add any user defined headers */
for (; tmp; tmp = tmp->next) {
if ((p = strchr (tmp->data, ':'))) {
- p++;
- SKIPWS (p);
+ p = vskipspaces(p + 1);
if (!*p)
continue; /* don't emit empty fields. */
continue;
i = p - h->data;
- ++p;
- SKIPWS (p);
+ p = vskipspaces(p + 1);
tmp = m_strdup(p);
if (!tmp)
/*
- * Queries and passphrase handling.
+ * 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")
+/*
+ * Queries and passphrase handling.
+ */
/* these are copies from pgp.c */
snprintf (scratch, sizeof (scratch), "%s%s: %s", SAFEPFX, tag, value);
#undef SAVEPFX
scratch[taglen] = '\0';
- value = &scratch[taglen + 1];
- SKIPWS (value);
+ value = vskipspaces(&scratch[taglen + 1]);
mutt_parse_rfc822_line (e, NULL, scratch, value, 1, 0, 0, &last);
/* if $strict_mailto is set, force editing headers to let
* users have a look at what we got */