replace SKIPWS with a proper inline func with the right API.
authorPierre Habouzit <madcoder@debian.org>
Mon, 30 Oct 2006 23:41:20 +0000 (00:41 +0100)
committerPierre Habouzit <madcoder@debian.org>
Mon, 30 Oct 2006 23:41:20 +0000 (00:41 +0100)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
31 files changed:
browser.c
compose.c
edit.c
from.c
headers.c
help.c
hook.c
imap/command.c
imap/imap.c
imap/message.c
imap/util.c
init.c
lib-lib/buffer.c
lib-lib/buffer.h
lib-lib/str.h
lib/str.c
lib/str.h
mutt.h
parse.c
pattern.c
pgp.c
pgpmicalg.c
pop/pop_lib.c
postpone.c
remailer.c
rfc1524.c
rfc822.c
send.c
sendlib.c
smime.c
url.c

index c46c89e..fd607ce 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -1191,10 +1191,9 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
         /* 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;
         }
 
index 6ecac7f..b0b20aa 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -622,7 +622,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
             && 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)
@@ -640,7 +640,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
             && 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)
diff --git a/edit.c b/edit.c
index 893732e..d4bcc68 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -324,8 +324,7 @@ int mutt_builtin_editor (const char *path, HEADER * msg, HEADER * cur)
       while (p >= tmp && ISSPACE (*p))
         *p-- = 0;
 
-      p = tmp + 2;
-      SKIPWS (p);
+      p = vskipspaces(tmp + 2);
 
       switch (tmp[1]) {
       case '?':
diff --git a/from.c b/from.c
index 87c44a0..64686fc 100644 (file)
--- a/from.c
+++ b/from.c
 #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)
@@ -102,8 +102,7 @@ int is_from (const char *s, char *path, size_t pathlen, time_t * tp)
       debug_print (3, ("got return path: %s\n", path));
     }
 
-    s = p + 1;
-    SKIPWS (s);
+    s = vskipspaces(p + 1);
     if (!*s)
       return 0;
 
index abd9b0f..a3476a8 100644 (file)
--- a/headers.c
+++ b/headers.c
@@ -129,8 +129,7 @@ void mutt_edit_headers (const char *editor,
      * 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);
@@ -142,12 +141,11 @@ void mutt_edit_headers (const char *editor,
       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);
diff --git a/help.c b/help.c
index f01bbea..d8392b7 100644 (file)
--- a/help.c
+++ b/help.c
@@ -200,7 +200,7 @@ static void format_line (FILE * f, int ismacro,
       n = COLS - col;
 
       if (ismacro >= 0) {
-        SKIPWS (t3);
+        t3 = vskipspaces(t3);
 
         /* FIXME: this is completely wrong */
         if ((n = m_strlen(t3)) > COLS - col) {
diff --git a/hook.c b/hook.c
index fcb6a22..c6686ae 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -61,8 +61,7 @@ int mutt_parse_hook (BUFFER * buf, BUFFER * s, unsigned long data,
   p_clear(&command, 1);
 
   if (*s->dptr == '!') {
-    s->dptr++;
-    SKIPWS (s->dptr);
+    s->dptr = vskipspaces(s->dptr + 1);
     not = 1;
   }
 
index 15aa019..af4c2b2 100644 (file)
@@ -155,9 +155,8 @@ int imap_cmd_step (IMAP_DATA * idata)
 /* 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.
@@ -367,8 +366,7 @@ static int cmd_handle_untagged (IMAP_DATA * idata)
       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);
index cb100ce..4b004f1 100644 (file)
@@ -493,8 +493,7 @@ static char *imap_get_flags (LIST ** hflags, char *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;
@@ -505,8 +504,7 @@ static char *imap_get_flags (LIST ** hflags, char *s)
   *hflags = flags;
 
   while (*s && *s != ')') {
-    s++;
-    SKIPWS (s);
+    s = vskipspaces(s + 1);
     flag_word = s;
     while (*s && (*s != ')') && !ISSPACE (*s))
       s++;
@@ -1311,9 +1309,8 @@ static int imap_compile_search (const pattern_t* pat, BUFFER* buf)
         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;
index c6db226..3ece306 100644 (file)
@@ -552,8 +552,7 @@ int imap_append_message (CONTEXT * ctx, MESSAGE * msg)
 
     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);
@@ -588,8 +587,7 @@ int imap_append_message (CONTEXT * ctx, MESSAGE * msg)
     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);
@@ -970,22 +968,20 @@ static int msg_parse_fetch (IMAP_HEADER * h, char *s)
     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;
@@ -1001,8 +997,7 @@ static int msg_parse_fetch (IMAP_HEADER * h, char *s)
       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++;
@@ -1036,8 +1031,7 @@ static char *msg_parse_flags (IMAP_HEADER * h, char *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;
@@ -1081,7 +1075,7 @@ static char *msg_parse_flags (IMAP_HEADER * h, char *s)
       mutt_add_list (h->data->keywords, flag_word);
       *s = ctmp;
     }
-    SKIPWS (s);
+    s = vskipspaces(s);
   }
 
   /* wrap up, or note bad flags response */
index 4bef04b..f869a98 100644 (file)
@@ -292,8 +292,7 @@ char *imap_next_word (char *s)
     s++;
   }
 
-  SKIPWS (s);
-  return s;
+  return vskipspaces(s);
 }
 
 /* imap_parse_date: date is of the form: DD-MMM-YYYY HH:MM:SS +ZZzz */
diff --git a/init.c b/init.c
index 4b4daa3..2d6f7fd 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1878,7 +1878,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
       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) {
@@ -2176,7 +2176,7 @@ int mutt_parse_rc_line ( /* const */ char *line, BUFFER * token, BUFFER * err)
 
   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 */
@@ -2244,7 +2244,7 @@ int mutt_command_complete (char *buffer, size_t len, int pos, int numtabs)
   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;
@@ -2391,7 +2391,7 @@ int mutt_var_value_complete (char *buffer, size_t len, int pos)
   if (buffer[0] == 0)
     return 0;
 
-  SKIPWS (buffer);
+  buffer = vskipspaces(buffer);
   spaces = buffer - pt;
 
   pt = buffer + pos - spaces;
@@ -2665,8 +2665,7 @@ void mutt_init (int skip_sys_rc, LIST * commands)
     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++;
index 2abfa39..6b46380 100644 (file)
 #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.
@@ -111,7 +112,7 @@ int mutt_extract_token(BUFFER *dest, BUFFER *tok, int flags)
     /* 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))
@@ -281,7 +282,7 @@ int mutt_extract_token(BUFFER *dest, BUFFER *tok, int flags)
         }
     }
     mutt_buffer_addch(dest, 0);  /* terminate the string */
-    SKIPWS(tok->dptr);
+    tok->dptr = vskipspaces(tok->dptr);
     return 0;
 }
 
index da476ac..50e3904 100644 (file)
 
 #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 */
index e319f2a..973e0be 100644 (file)
 #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;
@@ -40,10 +52,9 @@ static inline ssize_t m_strnlen(const char *s, ssize_t n) {
     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));
@@ -61,6 +72,14 @@ static inline int m_strncasecmp(const char *a, const char *b, size_t n) {
     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);
@@ -76,4 +95,17 @@ m_strncat(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 */
index b3fc401..a91dd17 100644 (file)
--- a/lib/str.c
+++ b/lib/str.c
@@ -92,11 +92,6 @@ int str_eq (const char* s1, const char* s2) {
   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;
 
index 140a4ba..636e288 100644 (file)
--- a/lib/str.h
+++ b/lib/str.h
 
 #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
  */
@@ -44,7 +22,6 @@ void str_replace (char**, const char*);
 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 */
diff --git a/mutt.h b/mutt.h
index eb23ab5..10e6c0c 100644 (file)
--- a/mutt.h
+++ b/mutt.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 */
diff --git a/parse.c b/parse.c
index c010636..b415ad3 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -194,8 +194,7 @@ static PARAMETER *parse_parameters (const char *s)
       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;
@@ -257,10 +256,8 @@ static PARAMETER *parse_parameters (const char *s)
       break;                    /* no more parameters */
 
     do {
-      s++;
-
       /* Move past any leading whitespace */
-      SKIPWS (s);
+      s = vskipspaces(s + 1);
     }
     while (*s == ';');          /* skip empty parameters */
   }
@@ -396,11 +393,9 @@ static void parse_content_disposition (char *s, BODY * ct)
 
   /* 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);
@@ -431,9 +426,8 @@ BODY *mutt_read_mime_header (FILE * fp, int digest)
   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;
@@ -668,8 +662,7 @@ static const char *uncomment_timezone (char *buf, size_t buflen,
 
   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;
@@ -803,7 +796,7 @@ time_t mutt_parse_date (const char *s, HEADER * h)
     t++;
   else
     t = scratch;
-  SKIPWS (t);
+  t = vskipspaces(t);
 
   p_clear(&tm, 1);
 
@@ -1043,7 +1036,7 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
     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;
     }
@@ -1126,7 +1119,7 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
     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;
@@ -1378,9 +1371,8 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
       }
     }
 
-    *p = 0;
-    p++;
-    SKIPWS (p);
+    *p++ = 0;
+    p = vskipspaces(p);
     if (!*p)
       continue;                 /* skip empty header fields */
 
index a02e96e..f40ea59 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -359,8 +359,7 @@ int eat_range (pattern_t * pat, BUFFER * s, BUFFER * err)
   if (skip_quote && *tmp == '"')
     tmp++;
 
-  SKIPWS (tmp);
-  s->dptr = tmp;
+  s->dptr = vskipspaces(tmp);
   return 0;
 }
 
@@ -468,7 +467,7 @@ static const char *parse_date_range (const char *pc, struct tm *min,
     const char *pt;
     char ch = *pc++;
 
-    SKIPWS (pc);
+    pc = vskipspaces(pc);
     switch (ch) {
     case '-':
       {
@@ -524,7 +523,7 @@ static const char *parse_date_range (const char *pc, struct tm *min,
     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);
@@ -608,11 +607,11 @@ static int eat_date (pattern_t * pat, BUFFER * s, BUFFER * err)
         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');
       }
     }
@@ -718,7 +717,7 @@ pattern_t *mutt_pattern_comp ( /* const */ char *s, int flags, BUFFER * err)
   ps.dsize = m_strlen(s);
 
   while (*ps.dptr) {
-    SKIPWS (ps.dptr);
+    ps.dptr = vskipspaces(ps.dptr);
     switch (*ps.dptr) {
     case '^':
       ps.dptr++;
@@ -792,8 +791,7 @@ pattern_t *mutt_pattern_comp ( /* const */ char *s, int flags, BUFFER * err)
       }
       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) {
diff --git a/pgp.c b/pgp.c
index 33213bd..bdb78d6 100644 (file)
--- a/pgp.c
+++ b/pgp.c
@@ -211,7 +211,7 @@ static void pgp_copy_clearsigned (FILE * fpin, STATE * s, char *charset)
       break;
 
     if (armor_header) {
-      char *p = str_skip_initws (buf);
+      char *p = vskipspaces(buf);
 
       if (*p == '\0')
         armor_header = 0;
index e63c943..7010761 100644 (file)
@@ -84,7 +84,7 @@ static void pgp_dearmor (FILE * in, FILE * out)
   /* skip the armor header */
 
   while ((r = fgets (line, sizeof (line), in)) != NULL) {
-    SKIPWS (r);
+    r = vskipspaces(r);
     if (!*r)
       break;
   }
index 763dffc..e34165b 100644 (file)
@@ -68,9 +68,7 @@ void pop_error (POP_DATA * pop_data, char *msg)
   c = msg;
 
   if (!m_strncmp(msg, "-ERR ", 5)) {
-    c2 = msg + 5;
-    SKIPWS (c2);
-
+    c2 = vskipspaces(msg + 5);
     if (*c2)
       c = c2;
   }
@@ -87,8 +85,7 @@ static int fetch_capa (char *line, void *data)
 
   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);
   }
 
index d37f043..bb99448 100644 (file)
@@ -298,8 +298,7 @@ int mutt_get_postponed (CONTEXT * ctx, HEADER * hdr, HEADER ** cur, char *fcc,
       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);
@@ -318,8 +317,7 @@ int mutt_get_postponed (CONTEXT * ctx, HEADER * hdr, HEADER ** cur, char *fcc,
         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);
 
@@ -409,8 +407,7 @@ int mutt_parse_crypt_hdr (char *p, int set_signas)
   if (!WithCrypto)
     return 0;
 
-  SKIPWS (p);
-  for (; *p; p++) {
+  for (p = vskipspaces(p); *p; p++) {
 
     switch (*p) {
     case 'e':
index ffa19a3..cb71404 100644 (file)
@@ -16,6 +16,7 @@
 #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>
@@ -463,7 +464,7 @@ static struct mapping_t RemailerHelp[] = {
   {N_("Delete"), OP_MIX_DELETE},
   {N_("Abort"), OP_EXIT},
   {N_("OK"), OP_MIX_USE},
-  {NULL}
+  {NULL, OP_NULL}
 };
 
 
index 5a843f8..d45c474 100644 (file)
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -127,8 +127,8 @@ static char *get_field (char *s)
         s++;
     }
     else {
-      *ch++ = 0;
-      SKIPWS (ch);
+      *ch++ = '\0';
+      ch = vskipspaces(ch);
       break;
     }
   }
@@ -139,11 +139,10 @@ static char *get_field (char *s)
 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;
index cbe5ba4..30f1379 100644 (file)
--- a/rfc822.c
+++ b/rfc822.c
@@ -165,7 +165,7 @@ static const char *parse_mailboxdomain (const char *s, const char *nonspecial,
   const char *ps;
 
   while (*s) {
-    SKIPWS (s);
+    s = vskipspaces(s);
     if (strchr (nonspecial, *s) == NULL && is_special (*s))
       return s;
 
@@ -224,7 +224,7 @@ static const char *parse_route_addr (const char *s,
   char token[STRING];
   size_t tokenlen = 0;
 
-  SKIPWS (s);
+  s = vskipspaces(s);
 
   /* find the end of the route */
   if (*s == '@') {
@@ -313,8 +313,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS * top, const char *s)
 
   ws_pending = isspace ((unsigned char) *s);
 
-  SKIPWS (s);
-  begin = s;
+  begin = s = vskipspaces(s);
   while (*s) {
     if (*s == ',') {
       if (phraselen) {
@@ -330,8 +329,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS * top, const char *s)
       commentlen = 0;
       phraselen = 0;
       s++;
-      begin = s;
-      SKIPWS (begin);
+      begin = vskipspaces(s);
     }
     else if (*s == '(') {
       if (commentlen && commentlen < sizeof (comment) - 1)
@@ -359,8 +357,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS * top, const char *s)
       phraselen = 0;
       commentlen = 0;
       s++;
-      begin = s;
-      SKIPWS (begin);
+      begin = vskipspaces(s);
     }
     else if (*s == ';') {
       if (phraselen) {
@@ -383,8 +380,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS * top, const char *s)
       phraselen = 0;
       commentlen = 0;
       s++;
-      begin = s;
-      SKIPWS (begin);
+      begin = vskipspaces(s);
     }
     else if (*s == '<') {
       terminate_buffer (phrase, phraselen);
@@ -425,7 +421,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS * top, const char *s)
       s = ps;
     }
     ws_pending = isspace ((unsigned char) *s);
-    SKIPWS (s);
+    s = vskipspaces(s);
   }
 
   if (phraselen) {
diff --git a/send.c b/send.c
index c827e7e..dfed65c 100644 (file)
--- a/send.c
+++ b/send.c
@@ -265,8 +265,7 @@ static int edit_envelope (ENVELOPE * en, int flags)
     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);
       }
     }
@@ -303,10 +302,9 @@ static int edit_envelope (ENVELOPE * en, int flags)
 }
 
 #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
 
index 1daf044..7ec942c 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -924,14 +924,13 @@ int mutt_lookup_mime_type (BODY * att, const char *path)
           *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"))) {
@@ -1596,8 +1595,7 @@ int mutt_write_rfc822_header (FILE * fp, ENVELOPE * env, BODY * attach,
   /* 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. */
 
@@ -1642,8 +1640,7 @@ static void encode_headers (LIST * h)
       continue;
 
     i = p - h->data;
-    ++p;
-    SKIPWS (p);
+    p = vskipspaces(p + 1);
     tmp = m_strdup(p);
 
     if (!tmp)
diff --git a/smime.c b/smime.c
index a5d2fbc..5a8f7e7 100644 (file)
--- a/smime.c
+++ b/smime.c
@@ -83,10 +83,19 @@ static char SmimeIntermediateToUse[_POSIX_PATH_MAX];
 
 
 /*
- *     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 */
diff --git a/url.c b/url.c
index c889b2e..597fdca 100644 (file)
--- a/url.c
+++ b/url.c
@@ -245,8 +245,7 @@ int url_parse_mailto (ENVELOPE * e, char **body, const char *src)
       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 */