commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. mu-1-2-90-separate-argp-cfg


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. mu-1-2-90-separate-argp-cfg-285-g671cdfc
Date: Tue, 07 Jul 2009 17:06:45 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=671cdfcc3c3fcaae6a70b7e1672cac86b09effe2

The branch, master has been updated
       via  671cdfcc3c3fcaae6a70b7e1672cac86b09effe2 (commit)
       via  f765125dd064487abedac21273e872f65bebac7b (commit)
       via  2e70a57ec264dfa688bed7eb91763c59bc467754 (commit)
      from  4fe47925e890ad37d75e4ad5fa75d68a48419176 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 671cdfcc3c3fcaae6a70b7e1672cac86b09effe2
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Jul 7 19:48:05 2009 +0300

    Update include/.gitignore

commit f765125dd064487abedac21273e872f65bebac7b
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Jul 7 19:47:12 2009 +0300

    Use new string trimming functions in parsers.
    
    * include/mailutils/cstr.h (mu_str_stripws): New function.
    * mailbox/stripws.c: New file.
    * mailbox/Makefile.am (libmailutils_la_SOURCES): Add stripws.c
    
    * examples/nntpclient.c (stripwhite): Remove. Use mu_str_stripws instead.
    (execute_line): Rewrite using new string functions.
    * examples/pop3client.c: Likewise.
    * mailbox/mailcap.c (stripwhite): Remove. Use mu_str_stripws instead.
    * mailbox/mime.c (_strltrim, _strttrim, _strtrim): Remove. Use
    mu_str_stripws instead.
    
    * mail/mail.c: Use mu_str_stripws.
    * mail/mail.h (util_stripwhite): Remove prototype.
    * mail/util.c (util_stripwhite): Remove
    * examples/pop3client.c: Likewise.
    * imap4d/util.c: Use new string functions.
    * maidag/forward.c: Likewise.
    * maidag/lmtp.c: Likewise.
    * mh/mhn.c: Likewise.
    
    * libproto/imap/folder.c: Remove unused local.
    * libproto/mailer/smtp.c (smtp_writeline): Minor optimization.

commit 2e70a57ec264dfa688bed7eb91763c59bc467754
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Jul 7 16:36:35 2009 +0300

    Minor changes.
    
    * include/mailutils/cstr.h (mu_str_skip_class_comp)
    (mu_str_skip_cset_comp): New prototypes.
    * mailbox/strskip.c (mu_str_skip_class_comp)
    (mu_str_skip_cset_comp): New functions.
    * libmu_auth/ldap.c (find_pwcheck): Fix typo in function
    call.
    * libproto/pop/mbox.c: Fix typos in diagnostic messages.

-----------------------------------------------------------------------

Summary of changes:
 examples/nntpclient.c              |   62 +++++++++---------------------------
 examples/pop3client.c              |   58 +++++++--------------------------
 imap4d/util.c                      |   10 ++---
 include/.gitignore                 |    2 +
 include/mailutils/cstr.h           |    4 ++
 libmu_auth/ldap.c                  |    2 +-
 libproto/imap/folder.c             |    1 -
 libproto/mailer/smtp.c             |   13 ++++---
 libproto/pop/mbox.c                |   20 ++++++------
 maidag/forward.c                   |   18 +++-------
 maidag/lmtp.c                      |   15 +-------
 mail/mail.c                        |    2 +-
 mail/mail.h                        |    1 -
 mail/util.c                        |   18 ----------
 mailbox/Makefile.am                |    1 +
 mailbox/mailcap.c                  |   35 ++++----------------
 mailbox/mime.c                     |   28 +---------------
 mailbox/{cstrlower.c => stripws.c} |   16 +++++----
 mailbox/strskip.c                  |   12 ++++++-
 mh/mh_fmtgram.y                    |    2 +-
 mh/mhn.c                           |   44 ++++++++++---------------
 21 files changed, 111 insertions(+), 253 deletions(-)
 copy mailbox/{cstrlower.c => stripws.c} (77%)

diff --git a/examples/nntpclient.c b/examples/nntpclient.c
index 6d4a6bc..b8bd401 100644
--- a/examples/nntpclient.c
+++ b/examples/nntpclient.c
@@ -44,6 +44,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/mutil.h>
 #include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
 
 /* A structure which contains information on the commands this program
    can understand. */
@@ -87,7 +88,6 @@ int com_stat (char *);
 int com_verbose (char *);
 
 void initialize_readline (void);
-char *stripwhite (char *);
 COMMAND *find_command (char *);
 char *dupstr (const char *);
 int execute_line (char *);
@@ -274,7 +274,7 @@ main (int argc MU_ARG_UNUSED, char **argv)
       /* Remove leading and trailing whitespace from the line.
          Then, if there is anything left, add it to the history list
          and execute it. */
-      s = stripwhite (line);
+      s = mu_str_stripws (line);
 
       if (*s)
        {
@@ -294,45 +294,34 @@ main (int argc MU_ARG_UNUSED, char **argv)
 int
 execute_line (char *line)
 {
-  register int i;
   COMMAND *command;
-  char *word;
+  char *word, *arg;
 
   /* Isolate the command word. */
-  i = 0;
-  while (line[i] && mu_isblank (line[i]))
-    i++;
-  word = line + i;
-
-  while (line[i] && !mu_isblank (line[i]))
-    i++;
-
-  if (line[i])
-    line[i++] = '\0';
-
+  word = mu_str_skip_class (line, MU_CTYPE_SPACE);
+  arg = mu_str_skip_class_comp (word, MU_CTYPE_SPACE);
+  if (*arg)
+    {
+      *arg++ = 0;
+      arg = mu_str_skip_class (arg, MU_CTYPE_SPACE);
+    }
+      
   command = find_command (word);
 
   if (!command)
     {
-      fprintf (stderr, "%s: No such command for %s.\n", word, progname);
-      return (-1);
+      mu_error ("%s: No such command.", word);
+      return 0;
     }
 
-  /* Get argument to command, if any. */
-  while (mu_isblank (line[i]))
-    i++;
-
-  word = line + i;
-
   /* Call the function. */
-  return ((*(command->func)) (word));
+  return ((*(command->func)) (arg));
 }
 
 /* Look up NAME as the name of a command, and return a pointer to that
    command.  Return a NULL pointer if NAME isn't a command name. */
 COMMAND *
-find_command (name)
-     char *name;
+find_command (char *name)
 {
   register int i;
 
@@ -343,27 +332,6 @@ find_command (name)
   return ((COMMAND *) NULL);
 }
 
-/* Strip whitespace from the start and end of STRING.  Return a pointer
-   into STRING. */
-char *
-stripwhite (char *string)
-{
-  register char *s, *t;
-
-  for (s = string; mu_isblank (*s); s++)
-    ;
-
-  if (*s == 0)
-    return (s);
-
-  t = s + strlen (s) - 1;
-  while (t > s && mu_isblank (*t))
-    t--;
-  *++t = '\0';
-
-  return s;
-}
-
 int
 com_verbose (char *arg)
 {
diff --git a/examples/pop3client.c b/examples/pop3client.c
index e4367c9..c073fe9 100644
--- a/examples/pop3client.c
+++ b/examples/pop3client.c
@@ -46,6 +46,7 @@
 #include <mailutils/vartab.h>
 #include <mailutils/argcv.h>
 #include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
 
 /* A structure which contains information on the commands this program
    can understand. */
@@ -80,7 +81,6 @@ int com_verbose (char *);
 int com_prompt (char *);
 
 void initialize_readline (void);
-char *stripwhite (char *);
 COMMAND *find_command (char *);
 char *dupstr (const char *);
 int execute_line (char *);
@@ -322,7 +322,7 @@ main (int argc MU_ARG_UNUSED, char **argv)
       /* Remove leading and trailing whitespace from the line.
          Then, if there is anything left, add it to the history list
          and execute it. */
-      s = stripwhite (line);
+      s = mu_str_stripws (line);
 
       if (*s)
        {
@@ -342,22 +342,18 @@ main (int argc MU_ARG_UNUSED, char **argv)
 int
 execute_line (char *line)
 {
-  register int i;
   COMMAND *command;
-  char *word;
+  char *word, *arg;
 
   /* Isolate the command word. */
-  i = 0;
-  while (line[i] && mu_isblank (line[i]))
-    i++;
-  word = line + i;
-
-  while (line[i] && !mu_isblank (line[i]))
-    i++;
-
-  if (line[i])
-    line[i++] = '\0';
-
+  word = mu_str_skip_class (line, MU_CTYPE_SPACE);
+  arg = mu_str_skip_class_comp (word, MU_CTYPE_SPACE);
+  if (*arg)
+    {
+      *arg++ = 0;
+      arg = mu_str_skip_class (arg, MU_CTYPE_SPACE);
+    }
+      
   command = find_command (word);
 
   if (!command)
@@ -366,21 +362,14 @@ execute_line (char *line)
       return 0;
     }
 
-  /* Get argument to command, if any. */
-  while (mu_isblank (line[i]))
-    i++;
-
-  word = line + i;
-
   /* Call the function. */
-  return ((*(command->func)) (word));
+  return ((*(command->func)) (arg));
 }
 
 /* Look up NAME as the name of a command, and return a pointer to that
    command.  Return a NULL pointer if NAME isn't a command name. */
 COMMAND *
-find_command (name)
-     char *name;
+find_command (char *name)
 {
   register int i;
 
@@ -391,27 +380,6 @@ find_command (name)
   return ((COMMAND *) NULL);
 }
 
-/* Strip whitespace from the start and end of STRING.  Return a pointer
-   into STRING. */
-char *
-stripwhite (char *string)
-{
-  register char *s, *t;
-
-  for (s = string; mu_isblank (*s); s++)
-    ;
-
-  if (*s == 0)
-    return (s);
-
-  t = s + strlen (s) - 1;
-  while (t > s && mu_isblank (*t))
-    t--;
-  *++t = '\0';
-
-  return s;
-}
-
 int
 com_verbose (char *arg)
 {
diff --git a/imap4d/util.c b/imap4d/util.c
index 48e7077..4da948a 100644
--- a/imap4d/util.c
+++ b/imap4d/util.c
@@ -1363,13 +1363,11 @@ imap4d_readline (struct imap4d_tokbuf *tok)
           char *p = mu_strcasestr (tok->buffer, "LOGIN");
           if (p && p > tok->buffer && mu_isblank (p[-1]))
             {
-              char *q = p + 5;
-              while (*q && mu_isblank (*q))
-                q++;
-              while (*q && !mu_isblank (*q))
-                q++;
+             char *q = mu_str_skip_class (p + 5, MU_CTYPE_SPACE);
+             q = mu_str_skip_class_comp (q, MU_CTYPE_SPACE);
               len = q - tok->buffer; 
-              mu_diag_output (MU_DIAG_DEBUG, "recv: %*.*s {censored}", len, 
len,
+              mu_diag_output (MU_DIAG_DEBUG,
+                             "recv: %*.*s {censored}", len, len,
                               tok->buffer);
              }
            else
diff --git a/include/.gitignore b/include/.gitignore
index 2c3cd71..6e15c94 100644
--- a/include/.gitignore
+++ b/include/.gitignore
@@ -1,3 +1,5 @@
 Makefile
 Makefile.in
 confpaths.h
+gettext.h
+intprops.h
diff --git a/include/mailutils/cstr.h b/include/mailutils/cstr.h
index fc80789..2077647 100644
--- a/include/mailutils/cstr.h
+++ b/include/mailutils/cstr.h
@@ -36,6 +36,10 @@ size_t mu_ltrim_cset (char *str, const char *cset);
 char *mu_str_skip_class (const char *str, int class);
 char *mu_str_skip_cset (const char *str, const char *cset);
 
+char *mu_str_skip_class_comp (const char *str, int class);
+char *mu_str_skip_cset_comp (const char *str, const char *cset);
+
+char *mu_str_stripws (char *string);  
   
 #ifdef __cplusplus
 }
diff --git a/libmu_auth/ldap.c b/libmu_auth/ldap.c
index 28fb084..e3cda49 100644
--- a/libmu_auth/ldap.c
+++ b/libmu_auth/ldap.c
@@ -745,7 +745,7 @@ find_pwcheck (const char *algo, int len)
 {
   struct passwd_algo *p;
   for (p = pwtab; p->algo; p++)
-    if (len == p->len && mu_strncasecmp (p->algo, algo, len) == 0)
+    if (len == p->len && mu_c_strncasecmp (p->algo, algo, len) == 0)
       return p->pwcheck;
   return NULL;
 }
diff --git a/libproto/imap/folder.c b/libproto/imap/folder.c
index 81faa71..9857f69 100644
--- a/libproto/imap/folder.c
+++ b/libproto/imap/folder.c
@@ -1817,7 +1817,6 @@ imap_body (f_imap_t f_imap, char **ptr)
        {
          size_t len = sep - *ptr;
          char *section = malloc (len + 1);
-         char *p;
          
          if (!section)
            return ENOMEM;
diff --git a/libproto/mailer/smtp.c b/libproto/mailer/smtp.c
index e64daef..22f37d9 100644
--- a/libproto/mailer/smtp.c
+++ b/libproto/mailer/smtp.c
@@ -1067,14 +1067,15 @@ smtp_writeline (smtp_t smtp, const char *format, ...)
 
   smtp->ptr = smtp->buffer + len;
 
-  while (len > 0 && mu_isblank (smtp->buffer[len - 1]))
-    len--;
-
   if ((smtp->state != SMTP_SEND && smtp->state != SMTP_SEND_DOT)
       || smtp->mailer->flags & MAILER_FLAG_DEBUG_DATA)
-    MU_DEBUG2 (smtp->mailer->debug, MU_DEBUG_PROT, "> %.*s\n", len,
-               smtp->buffer);
-
+    {
+      while (len > 0 && mu_isblank (smtp->buffer[len - 1]))
+       len--;
+      MU_DEBUG2 (smtp->mailer->debug, MU_DEBUG_PROT, "> %.*s\n", len,
+                smtp->buffer);
+    }
+  
   return 0;
 }
 
diff --git a/libproto/pop/mbox.c b/libproto/pop/mbox.c
index 83f01cf..76a04f7 100644
--- a/libproto/pop/mbox.c
+++ b/libproto/pop/mbox.c
@@ -458,7 +458,7 @@ pop_parse_capa (pop_data_t mpd)
     }
   else
     {
-      /* mu_error ("CAPA not implemented\n"); */ /* FIXME */
+      /* mu_error ("CAPA not implemented"); */ /* FIXME */
       return -1;
     }
 }
@@ -864,7 +864,7 @@ pop_open (mu_mailbox_t mbox, int flags)
 
     default:
       /*
-       mu_error ("pop_open unknown state\n");
+       mu_error ("pop_open: unknown state");
       */
       break;
     }/* End AUTHORISATION state. */
@@ -920,13 +920,13 @@ pop_close (mu_mailbox_t mbox)
          lets just be verbose about the error but close the connection
          anyway.  */
       if (mu_c_strncasecmp (mpd->buffer, "+OK", 3) != 0)
-       mu_error ("pop_close: %s\n", mpd->buffer);
+       mu_error ("pop_close: %s", mpd->buffer);
       mu_stream_close (mbox->stream);
       break;
 
     default:
       /*
-       mu_error ("pop_close unknown state");
+       mu_error ("pop_close: unknown state");
       */
       break;
     } /* UPDATE state.  */
@@ -1209,7 +1209,7 @@ pop_messages_count (mu_mailbox_t mbox, size_t *pcount)
 
     default:
       /*
-       mu_error ("pop_messages_count: unknow state\n");
+       mu_error ("pop_messages_count: unknown state");
       */
       break;
     }
@@ -1327,7 +1327,7 @@ pop_expunge (mu_mailbox_t mbox)
                  break;
 
                default:
-                 /* mu_error ("pop_expunge: unknow state\n"); */
+                 /* mu_error ("pop_expunge: unknown state); */
                  break;
                } /* switch (state) */
            } /* if mu_attribute_is_deleted() */
@@ -1417,7 +1417,7 @@ pop_message_size (mu_message_t msg, size_t *psize)
 
     default:
       /*
-       mu_error ("pop_message_size state\n");
+       mu_error ("pop_message_size: unknown state");
       */
       break;
     }
@@ -1636,7 +1636,7 @@ pop_uidl (mu_message_t msg, char *buffer, size_t buflen, 
size_t *pnwriten)
 
     default:
       /*
-       mu_error ("pop_uidl state\n");
+       mu_error ("pop_uidl: unknown state");
       */
       break;
     }
@@ -1737,7 +1737,7 @@ pop_top (mu_header_t header, char *buffer, size_t buflen,
       CHECK_EAGAIN (mpd, status);
       MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer);
       /* if (mu_c_strncasecmp (mpd->buffer, "+OK", 3) != 0)
-          mu_error ("TOP not implemented\n"); */ /* FIXME */
+          mu_error ("TOP not implemented"); */ /* FIXME */
       mpd->state = POP_TOP_RX;
 
     case POP_TOP_RX:
@@ -2089,7 +2089,7 @@ pop_retr (pop_message_t mpm, char *buffer, size_t buflen,
       /* A convenient break, this is here we can return 0, we're done.  */
 
     default:
-      /* mu_error ("pop_retr unknow state\n"); */
+      /* mu_error ("pop_retr: unknown state"); */
       break;
     } /* Switch state.  */
 
diff --git a/maidag/forward.c b/maidag/forward.c
index 735f011..527980d 100644
--- a/maidag/forward.c
+++ b/maidag/forward.c
@@ -220,19 +220,11 @@ process_forward (mu_message_t msg, char *filename, const 
char *myname)
 
   while (getline (&buf, &size, fp) > 0)
     {
-      char *p, *q;
-      for (p = buf; *p && mu_isblank (*p); p++)
-       ;
-      q = p + strlen (p);
-      if (q > p)
-       {
-         if (*--q == '\n')
-           q--;
-         for (; q > p && mu_isblank (*q); q--)
-           ;
-         q[1] = 0;
-       }
-      
+      char *p;
+
+      mu_rtrim_class (buf, MU_CTYPE_SPACE);
+      p = mu_str_skip_class (buf, MU_CTYPE_SPACE);
+
       if (*p && *p != '#')
        {
          if (strchr (p, '@'))
diff --git a/maidag/lmtp.c b/maidag/lmtp.c
index a06a3f9..c52b333 100644
--- a/maidag/lmtp.c
+++ b/maidag/lmtp.c
@@ -77,16 +77,6 @@ lmtp_reply (FILE *fp, char *code, char *enh, char *fmt, ...)
 }
 
 void
-trimnl (char *arg)
-{
-  size_t len = strlen (arg);
-  if (len > 0 && arg[len-1] == '\n')
-    arg[--len] = 0;
-  if (len > 0 && arg[len-1] == '\r')
-    arg[--len] = 0;
-}
-
-void
 xlatnl (char *arg)
 {
   size_t len = strlen (arg);
@@ -543,7 +533,7 @@ lmtp_loop (FILE *in, FILE *out, unsigned int timeout)
          enum lmtp_command cmd = cp->cmd_code;
          enum lmtp_state next_state = transtab[cmd][state];
 
-         trimnl (buf);
+         mu_rtrim_cset (sp, "\r\n");
 
          if (lmtp_transcript)
            mu_diag_output (MU_DIAG_INFO, "LMTP recieve: %s", buf);
@@ -552,8 +542,7 @@ lmtp_loop (FILE *in, FILE *out, unsigned int timeout)
            {
              if (cp->cmd_fun)
                {
-                 while (*sp && mu_isblank (*sp))
-                   sp++;
+                 sp = mu_str_skip_class (sp, MU_CTYPE_SPACE);
                  if (cp->cmd_fun (out, sp))
                    continue;
                }
diff --git a/mail/mail.c b/mail/mail.c
index c07cae9..3ebf90b 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -529,7 +529,7 @@ mail_mainloop (char *(*input) (void *, int),
          command = buf;
          len = strlen (command);
        }
-      cmd = util_stripwhite (command);
+      cmd = mu_str_stripws (command);
       util_do_command ("%s", cmd);
 #ifdef WITH_READLINE
       if (do_history && !(mu_isspace(cmd[0]) || cmd[0] == '#'))
diff --git a/mail/mail.h b/mail/mail.h
index bca79c2..9883250 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -313,7 +313,6 @@ extern size_t util_range_msg (size_t low, size_t high, int 
flags,
                              msg_handler_t func, void *data);
 
 extern function_t* util_command_get (const char *cmd);
-extern char *util_stripwhite (char *string);
 
 extern void *util_find_entry (void *table, size_t nmemb, size_t size,
                              const char *cmd);
diff --git a/mail/util.c b/mail/util.c
index b1878e1..0b5cc27 100644
--- a/mail/util.c
+++ b/mail/util.c
@@ -336,24 +336,6 @@ util_command_list (void *table, size_t nmemb, size_t size)
 }
 
 /*
- * removes whitespace from the beginning and end of a string
- */
-char *
-util_stripwhite (char *string)
-{
-  register char *s, *t;
-  for (s = string; mu_isspace ((unsigned)*s); s++)
-    ;
-  if (*s == 0)
-    return s;
-  t = s + strlen (s) - 1;
-  while (t > s && mu_isspace ((unsigned)*t))
-    t--;
-  *++t = '\0';
-  return s;
-}
-
-/*
  * Get the number of columns on the screen
  * First try an ioctl() call not all shells set the COLUMNS environ.
  */
diff --git a/mailbox/Makefile.am b/mailbox/Makefile.am
index 0447643..4f5e119 100644
--- a/mailbox/Makefile.am
+++ b/mailbox/Makefile.am
@@ -123,6 +123,7 @@ libmailutils_la_SOURCES = \
  stream.c\
  strltrim.c\
  strskip.c\
+ stripws.c\
  strrtrim.c\
  syslog.c\
  system.c\
diff --git a/mailbox/mailcap.c b/mailbox/mailcap.c
index 85fad9c..0efd218 100644
--- a/mailbox/mailcap.c
+++ b/mailbox/mailcap.c
@@ -50,7 +50,6 @@ struct _mu_mailcap
 
 static int mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream);
 static int mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char *buffer);
-static char * stripwhite (char *string);
 static char * tokenize (char *s, char **save_ptr);
 
 int
@@ -371,8 +370,8 @@ mu_mailcap_entry_get_value (mu_mailcap_entry_t entry, const 
char *key,
                      if (value != NULL)
                        {
                          value++; /* Pass the equal.  */
-                         /* Remove prepend space.  */
-                         for (; mu_isspace ((unsigned char)*value); value++)
+                         /* Remove leading space.  */
+                         for (; mu_isspace (*value); value++)
                            ;
                          len = strlen (value);
                          /* Strip surrounding double quotes */
@@ -400,27 +399,6 @@ mu_mailcap_entry_get_value (mu_mailcap_entry_t entry, 
const char *key,
   return status;
 }
 
-/* Strip whitespace from the start and end of STRING.  Return a pointer
-   into STRING. */
-static char *
-stripwhite (char *string)
-{
-  register char *s, *t;
-
-  for (s = string; mu_isspace ((unsigned char)*s); s++)
-    ;
-
-  if (*s == 0)
-    return (s);
-
-  t = s + strlen (s) - 1;
-  while (t > s && mu_isspace (*t))
-    t--;
-  *++t = '\0';
-
-  return s;
-}
-
 /*
  * break the line on ';'.  Same as strtok() but
  * check for escaped "\;"
@@ -479,12 +457,12 @@ mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char 
*buffer)
        {
          /* The first entry in a mailcap line is the typefield.  */
        case 0:
-         entry->typefield = strdup (stripwhite (token));
+         entry->typefield = strdup (mu_str_stripws (token));
          break;
 
          /* The second entry in a mailcap line is the view-command.  */
        case 1:
-         entry->viewcommand = strdup (stripwhite(token));
+         entry->viewcommand = strdup (mu_str_stripws (token));
          break;
 
          /* The rest are the optional fields.  */
@@ -496,7 +474,8 @@ mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char 
*buffer)
            if (fields != NULL)
              {
                entry->fields = fields;
-               entry->fields[entry->fields_count] = strdup (stripwhite 
(token));
+               entry->fields[entry->fields_count] =
+                 strdup (mu_str_stripws (token));
                entry->fields_count++;
              }
          }
@@ -643,7 +622,7 @@ mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream)
       /* Parse the well-form mailcap line entry.  */
       if (previous == NULL) {
        /* Nuke the trailing/prepend spaces.  */
-       char *line = stripwhite(buffer);
+       char *line = mu_str_stripws (buffer);
        /* Ignore comments or empty lines  */
        if (*line != '#' && *line != '\0')
          {
diff --git a/mailbox/mime.c b/mailbox/mime.c
index 04c1e11..3199a20 100644
--- a/mailbox/mime.c
+++ b/mailbox/mime.c
@@ -133,31 +133,7 @@ _mime_append_part (mu_mime_t mime, mu_message_t msg, int 
offset, int len, int li
   return 0;
 }
 
-static char *
-_strltrim (char *str)
-{
-  char *p;
-
-  for (p = str; mu_isspace (*p) && *p != '\0'; ++p);
-  return ((p != str) ? memmove (str, p, strlen (p) + 1) : str);
-}
-
-static char *
-_strttrim (char *str)
-{
-  char *p;
-
-  for (p = str + strlen (str) - 1;
-       mu_isspace (*p) && p >= str; --p);
-  *++p = '\0';
-  return (str);
-}
-
-char *_strtrim (char *str);
-
-#define _strtrim(str) _strltrim(_strttrim(str))
-
-#define _ISSPECIAL(c) ( \
+#define _ISSPECIAL(c) (                                                 \
     ((c) == '(') || ((c) == ')') || ((c) == '<') || ((c) == '>') \
     || ((c) == '@') || ((c) == ',') || ((c) == ';') || ((c) == ':') \
     || ((c) == '\\') || ((c) == '.') || ((c) == '[') \
@@ -169,7 +145,7 @@ _mime_munge_content_header (char *field_body)
   char           *p, *e, *str = field_body;
   int             quoted = 0;
 
-  _strtrim (field_body);
+  mu_str_stripws (field_body);
 
   if ((e = strchr (str, ';')) == NULL)
     return;
diff --git a/mailbox/cstrlower.c b/mailbox/stripws.c
similarity index 77%
copy from mailbox/cstrlower.c
copy to mailbox/stripws.c
index 058075b..cb96a74 100644
--- a/mailbox/cstrlower.c
+++ b/mailbox/stripws.c
@@ -18,14 +18,16 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
+#include <stdlib.h>
 #include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
 
-int
-mu_strlower (char *s)
+/*
+ * removes whitespace from the beginning and end of a string
+ */
+char *
+mu_str_stripws (char *string)
 {
-  if (!s)
-    return 0;
-  for (; *s; s++)
-    *s = mu_tolower (*s);
-  return 0;
+  mu_rtrim_class (string, MU_CTYPE_SPACE);
+  return mu_str_skip_class (string, MU_CTYPE_SPACE);
 }
diff --git a/mailbox/strskip.c b/mailbox/strskip.c
index 1c974a3..669ec22 100644
--- a/mailbox/strskip.c
+++ b/mailbox/strskip.c
@@ -33,9 +33,17 @@ mu_str_skip_class (const char *str, int class)
 }
 
 char *
-mu_str_skip_cset (const char *str, const char *cset)
+mu_str_skip_class_comp (const char *str, int class)
 {
-  for (; *str && strchr (cset, *str) != NULL; str++)
+  for (; *str && !mu_c_is_class (*str, class); str++)
+    ;
+  return (char*) str;
+}
+
+char *
+mu_str_skip_cset_comp (const char *str, const char *cset)
+{
+  for (; *str && strchr (cset, *str) == NULL; str++)
     ;
   return (char*) str;
 }
diff --git a/mh/mh_fmtgram.y b/mh/mh_fmtgram.y
index be9bfdf..845fd12 100644
--- a/mh/mh_fmtgram.y
+++ b/mh/mh_fmtgram.y
@@ -480,7 +480,7 @@ yylex ()
        {
          curp -= rest;
          yylval.builtin = bp;
-         while (*curp && mu_isspace(*curp))
+         while (*curp && mu_isspace (*curp))
            curp++;
          return FUNCTION;
        }
diff --git a/mh/mhn.c b/mh/mhn.c
index d4b380c..7d6d409 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -617,8 +617,7 @@ mhn_compose_command (char *typestr, int *flags, char *file)
     %s  subtype */
 
   obstack_init (&stk);
-  for (p = str; *p && mu_isspace (*p); p++)
-    ;
+  p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   
   if (*p == '|')
     p++;
@@ -661,12 +660,11 @@ mhn_compose_command (char *typestr, int *flags, char 
*file)
   free (subtype);
 
   str = obstack_finish (&stk);
-  for (p = str; *p && mu_isspace (*p); p++)
-    ;
+  p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   if (!*p)
     str = NULL;
   else
-    str = strdup (str);
+    str = strdup (p);
 
   obstack_free (&stk, NULL);
   return (char*) str;
@@ -700,8 +698,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int 
*flags,
     %d  content description */
 
   obstack_init (&stk);
-  for (p = str; *p && mu_isspace (*p); p++)
-    ;
+  p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   
   if (*p == '|')
     p++;
@@ -777,12 +774,11 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int 
*flags,
   free (subtype);
 
   str = obstack_finish (&stk);
-  for (p = str; *p && mu_isspace (*p); p++)
-    ;
+  p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   if (!*p)
     str = NULL;
   else
-    str = strdup (str);
+    str = strdup (p);
 
   obstack_free (&stk, NULL);
   return (char*) str;
@@ -869,12 +865,11 @@ mhn_store_command (mu_message_t msg, msg_part_t part, 
char *name)
   free (subtype);
   
   str = obstack_finish (&stk);
-  for (p = str; *p && mu_isspace (*p); p++)
-    ;
+  p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   if (!*p)
     str = NULL;
   else
-    str = strdup (str);
+    str = strdup (p);
   
   obstack_free (&stk, NULL);
   return (char*) str;
@@ -985,9 +980,8 @@ get_extbody_params (mu_message_t msg, char **content, char 
**descr)
          && mu_c_strncasecmp (buf, MU_HEADER_CONTENT_DESCRIPTION ":",
                               sizeof (MU_HEADER_CONTENT_DESCRIPTION)) == 0)
        {
-         for (p = buf + sizeof (MU_HEADER_CONTENT_DESCRIPTION);
-              *p && mu_isspace (*p); p++)
-           ;
+         p = mu_str_skip_class (buf + sizeof (MU_HEADER_CONTENT_DESCRIPTION),
+                                MU_CTYPE_SPACE);
          *descr = strdup (p);
        }
       else if (content
@@ -995,9 +989,8 @@ get_extbody_params (mu_message_t msg, char **content, char 
**descr)
                                    sizeof (MU_HEADER_CONTENT_TYPE)) == 0)
        {
          char *q;
-         for (p = buf + sizeof (MU_HEADER_CONTENT_TYPE);
-              *p && mu_isspace (*p); p++)
-           ;
+         p = mu_str_skip_class (buf + sizeof (MU_HEADER_CONTENT_TYPE),
+                                MU_CTYPE_SPACE);
          q = strchr (p, ';');
          if (q)
            *q = 0;
@@ -1830,7 +1823,7 @@ parse_brace (char **pval, char **cmd, int c, struct 
compose_env *env)
 }
 
 #define isdelim(c) (mu_isspace (c) || strchr (";<[(", c))
-#define skipws(ptr) do { while (*ptr && mu_isspace (*ptr)) ptr++; } while (0)
+#define skipws(ptr) (ptr) = mu_str_skip_class (ptr, MU_CTYPE_SPACE)
 
 int
 parse_content_type (struct compose_env *env,
@@ -2300,10 +2293,8 @@ edit_mime (char *cmd, struct compose_env *env, 
mu_message_t *msg, int level)
   rc = parse_type_command (&cmd, env, hdr);
   if (rc)
     return 1;
-  
-  for (p = cmd + strlen (cmd) - 1; p > cmd && mu_isspace (*p); p--)
-    ;
-  p[1] = 0;
+
+  mu_rtrim_class (cmd, MU_CTYPE_SPACE);
 
   _get_content_type (hdr, &typestr, NULL);
   shell_cmd = mhn_compose_command (typestr, &flags, cmd);
@@ -2463,9 +2454,8 @@ mhn_edit (struct compose_env *env, int level)
                finish_text_msg (env, &msg, ascii_buf);
              
              /* Execute the directive */
-             tok = sp = buf;
-             while (*sp && !mu_isspace (*sp))
-               sp++;
+             tok = buf;
+             sp = mu_str_skip_class_comp (buf, MU_CTYPE_SPACE);
              c = *sp;
              *sp = 0;
 


hooks/post-receive
-- 
GNU Mailutils




reply via email to

[Prev in Thread] Current Thread [Next in Thread]