Commit f88a8d05 f88a8d059027ab10e2b6f0bd0f59764a6947474c by Sergey Poznyakoff

frm,messages,readmsg: Use MU streams instead of stdio.

* frm/common.c: Use MU streams instead of stdio.
* frm/frm.c: Likewise.
* messages/messages.c: Likewise.
* readmsg/readmsg.c: Likewise.
* frm/frm.h: Include mailutils/stdstream.h
* readmsg/readmsg.h: Likewise.
1 parent 1f44f1ad
......@@ -127,7 +127,7 @@ puts_bidi (char *string)
}
if (fb_charset_num == 0)
puts (string);
mu_printf ("%s\n", string);
else
{
FriBidiStrIndex len;
......@@ -186,20 +186,20 @@ puts_bidi (char *string)
new_len = fribidi_unicode_to_charset (fb_charset_num,
visual + st, inlen,
outstring);
printf ("%s", outstring);
mu_printf ("%s", outstring);
}
putchar ('\n');
mu_printf ("\n");
}
else
{
/* Print the string as is */
puts (string);
mu_printf ("%s\n", string);
}
}
}
#else
# define alloc_logical(s)
# define puts_bidi puts
# define puts_bidi(s) mu_stream_printf ("%s\n", s)
#endif
......@@ -236,7 +236,7 @@ print_line ()
curcol = nextstart = 0;
}
else
putchar ('\n');
mu_printf ("\n");
curfield = 0;
}
......@@ -245,9 +245,9 @@ format_field_simple (const char *fmt, ...)
{
va_list ap;
if (curfield++)
putchar ('\t');
mu_printf ("\t");
va_start (ap, fmt);
vprintf (fmt, ap);
mu_stream_vprintf (mu_strout, fmt, ap);
va_end (ap);
}
......@@ -266,7 +266,7 @@ format_field_align (const char *fmt, ...)
{
puts_bidi (linebuf);
linepos = 0;
printf ("%*s", nextstart, "");
mu_printf ("%*s", nextstart, "");
}
else
{
......@@ -526,7 +526,7 @@ frm_abort (mu_mailbox_t *mbox)
(mu_message_t). It returns non-zero if that message is to be displayed
and zero otherwise.
Upon finishing scanning, the function places the overall number of
Upon finishing scanning, the function places total number of
the messages processed into the memory location pointed to by
TOTAL */
void
......
......@@ -266,16 +266,16 @@ frm (char *mailbox_name)
if (show_summary)
{
if (total == 0)
printf (_("Folder contains no messages."));
mu_printf (_("Folder contains no messages."));
else
{
char *delim = "";
printf (_("Folder contains "));
mu_printf (_("Folder contains "));
if (counter.new)
{
printf (ngettext ("%lu new message",
mu_printf (ngettext ("%lu new message",
"%lu new messages",
counter.new),
(u_long) counter.new);
......@@ -284,9 +284,9 @@ frm (char *mailbox_name)
if (counter.unread)
{
printf ("%s", delim);
mu_printf ("%s", delim);
printf (ngettext ("%lu unread message",
mu_printf (ngettext ("%lu unread message",
"%lu unread messages",
counter.unread),
(u_long) counter.unread);
......@@ -295,9 +295,9 @@ frm (char *mailbox_name)
if (counter.read)
{
printf ("%s", delim);
mu_printf ("%s", delim);
printf (ngettext ("%lu read message",
mu_printf (ngettext ("%lu read message",
"%lu read messages",
counter.read),
(u_long) counter.read);
......@@ -309,16 +309,16 @@ frm (char *mailbox_name)
Leave it as it is unless your language requires to reorder
the parts of speach in the message
*/
printf (_("."));
mu_printf (_("."));
}
printf ("\n");
mu_printf ("\n");
}
else if (show_query)
{
if (total > 0)
printf (_("There are messages in that folder.\n"));
mu_printf (_("There are messages in that folder.\n"));
else
printf (_("No messages in that folder!\n"));
mu_printf (_("No messages in that folder!\n"));
}
/* EXIT STATUS
......@@ -366,7 +366,7 @@ main (int argc, char **argv)
else
for (; c < argc; c++)
{
printf ("%s:\n", argv[c]);
mu_printf ("%s:\n", argv[c]);
status = frm (argv[c]);
}
......
......@@ -55,6 +55,7 @@
#include <mailutils/observer.h>
#include <mailutils/registrar.h>
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
#include <mailutils/url.h>
#include <mailutils/nls.h>
#include <mailutils/tls.h>
......
......@@ -144,7 +144,7 @@ main (int argc, char **argv)
if (count_only)
{
printf (ngettext ("There is %lu message in your incoming mailbox.\n",
mu_printf (ngettext ("There is %lu message in your incoming mailbox.\n",
"There are %lu messages in your incoming mailbox.\n",
total),
(unsigned long) total);
......
......@@ -166,9 +166,10 @@ messages_count (const char *box)
}
if (silent)
printf ("%lu\n", (unsigned long) count);
mu_printf ("%lu\n", (unsigned long) count);
else
printf (_("Number of messages in %s: %lu\n"), box, (unsigned long) count);
mu_printf (_("Number of messages in %s: %lu\n"), box,
(unsigned long) count);
status = mu_mailbox_close (mbox);
if (status != 0)
......
......@@ -175,7 +175,7 @@ print_unix_header (mu_message_t message)
if (mu_envelope_sget_sender (envelope, &buf))
buf = "UNKNOWN";
printf ("From %s ", buf);
mu_printf ("From %s ", buf);
if (mu_envelope_sget_date (envelope, &buf))
{
......@@ -189,10 +189,10 @@ print_unix_header (mu_message_t message)
buf = datebuf;
}
printf ("%s", buf);
mu_printf ("%s", buf);
size = strlen (buf);
if (size > 1 && buf[size-1] != '\n')
putchar ('\n');
mu_printf ("\n");
}
static void
......@@ -205,17 +205,9 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv)
if (weedc == 0)
{
mu_stream_t stream = NULL;
size_t len = 0;
char buf[128];
/* FIXME: Use mu_stream_copy */
mu_header_get_streamref (header, &stream);
while (mu_stream_read (stream, buf, sizeof (buf) - 1, &len) == 0
&& len != 0)
{
buf[len] = '\0';
printf ("%s", buf);
}
mu_stream_copy (mu_strout, stream, 0, NULL);
mu_stream_destroy (&stream);
}
else
......@@ -235,11 +227,11 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv)
for (i = 1; i <= count; i++)
{
int j;
char *name = NULL;
char *value = NULL;
const char *name = NULL;
const char *value = NULL;
mu_header_aget_field_name (header, i, &name);
mu_header_aget_field_value (header, i, &value);
mu_header_sget_field_name (header, i, &name);
mu_header_sget_field_value (header, i, &value);
for (j = 0; j < weedc; j++)
{
if (weedv[j][0] == '!')
......@@ -249,15 +241,13 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv)
}
else if (string_starts_with (name, weedv[j]))
{
/* Check if mu_header_aget_value return an empty string. */
/* Check if mu_header_sget_value returns an empty string. */
if (value && *value)
printf ("%s: %s\n", name, value);
mu_printf ("%s: %s\n", name, value);
}
}
free (value);
free (name);
}
putchar ('\n');
mu_printf ("\n");
}
}
......@@ -265,26 +255,17 @@ static void
print_body (mu_message_t message)
{
int status;
char buf[128];
mu_body_t body = NULL;
mu_stream_t stream = NULL;
size_t len = 0;
mu_message_get_body (message, &body);
/* FIXME: Use mu_stream_copy */
status = mu_body_get_streamref (body, &stream);
if (status)
{
mu_error (_("cannot get body stream: %s"), mu_strerror (status));
return;
}
while (mu_stream_read (stream, buf, sizeof (buf) - 1, &len) == 0
&& len != 0)
{
buf[len] = '\0';
printf ("%s", buf);
}
mu_stream_copy (mu_strout, stream, 0, NULL);
mu_stream_destroy (&stream);
}
......@@ -410,13 +391,10 @@ main (int argc, char **argv)
print_header (msg, unix_header, weedc, weedv);
print_body (msg);
if (form_feed)
putchar ('\f');
else
putchar ('\n');
mu_printf (form_feed ? "\f" : "\n");
}
putchar ('\n');
mu_printf ("\n");
mu_mailbox_close (mbox);
mu_mailbox_destroy (&mbox);
......
......@@ -43,6 +43,7 @@
#include <mailutils/filter.h>
#include <mailutils/registrar.h>
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
#include <mailutils/url.h>
#include <mailutils/nls.h>
#include <mailutils/tls.h>
......