summaryrefslogtreecommitdiff
path: root/mh/mh_whatnow.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-11-11 23:40:01 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2010-11-11 23:40:59 +0200
commit3fb87f63f3dc9dbbcf3cecc2a9ef2c85bd007204 (patch)
tree178d1cd02e31c905a05644d6ea34b31cced275d2 /mh/mh_whatnow.c
parentc02201707fd4664252ba0e3fe93d3018ec816c89 (diff)
downloadmailutils-3fb87f63f3dc9dbbcf3cecc2a9ef2c85bd007204.tar.gz
mailutils-3fb87f63f3dc9dbbcf3cecc2a9ef2c85bd007204.tar.bz2
Document null streams
* doc/texinfo/nullstream.texi: New file. * mh/mh_init.c (mh_real_install): Use mu_stream_t instead of FILE. * mh/mh_whatnow.c (_whatnow): Likewise.
Diffstat (limited to 'mh/mh_whatnow.c')
-rw-r--r--mh/mh_whatnow.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index 6582fd8b3..9ba2195bc 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -323,37 +323,51 @@ static int
_whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
{
int rc, status = 0;
+ mu_stream_t in;
+ char *line = NULL;
+ size_t size = 0;
+ struct mu_wordsplit ws;
+ int wsflags = MU_WRDSF_DEFFLAGS|MU_WRDSF_COMMENT;
+
+ rc = mu_stdio_stream_create (&in, MU_STDIN_FD, 0);
+ if (rc)
+ {
+ mu_error (_("cannot create input stream: %s"), mu_strerror (rc));
+ exit (1);
+ }
do
{
- char *line = NULL;
- size_t size = 0;
- struct mu_wordsplit ws;
handler_fp fun;
printf ("%s ", wh->prompt);
- getline (&line, &size, stdin);
- if (!line)
- continue;
+ fflush (stdout);
+ status = mu_stream_getline (in, &line, &size, NULL);
+ if (rc)
+ {
+ mu_error (_("cannot read input stream: %s"), mu_strerror (rc));
+ break;
+ }
ws.ws_comment = "#";
- rc = mu_wordsplit (line, &ws, MU_WRDSF_DEFFLAGS|MU_WRDSF_COMMENT);
- free (line);
+ rc = mu_wordsplit (line, &ws, wsflags);
if (rc)
{
mu_error (_("cannot split line `%s': %s"), line,
mu_wordsplit_strerror (&ws));
break;
}
-
+ wsflags |= MU_WRDSF_REUSE;
fun = func (tab, ws.ws_wordv[0]);
if (fun)
rc = fun (wh, ws.ws_wordc, ws.ws_wordv, &status);
else
rc = 0;
- mu_wordsplit_free (&ws);
}
while (rc == 0);
+ if (wsflags & MU_WRDSF_REUSE)
+ mu_wordsplit_free (&ws);
+ free (line);
return status;
}

Return to:

Send suggestions and report system problems to the System administrator.