summaryrefslogtreecommitdiff
path: root/examples/nntpclient.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-07-07 19:47:12 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-07-07 19:47:12 +0300
commitf765125dd064487abedac21273e872f65bebac7b (patch)
tree0e522cdfe2b77bd327da9c1a5a6dbc56ef20d586 /examples/nntpclient.c
parent2e70a57ec264dfa688bed7eb91763c59bc467754 (diff)
downloadmailutils-f765125dd064487abedac21273e872f65bebac7b.tar.gz
mailutils-f765125dd064487abedac21273e872f65bebac7b.tar.bz2
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.
Diffstat (limited to 'examples/nntpclient.c')
-rw-r--r--examples/nntpclient.c62
1 files changed, 15 insertions, 47 deletions
diff --git a/examples/nntpclient.c b/examples/nntpclient.c
index 6d4a6bc70..b8bd401e1 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)
{

Return to:

Send suggestions and report system problems to the System administrator.