Commit 2613d48d 2613d48d056396600993c447ab9fe6b64896abe6 by Sergey Poznyakoff

mu: use stdstream functions.

* include/mailutils/stdstream.h (mu_printf): New prototype.
* include/mailutils/version.h: Include mailutils/types.h instead of
stdio.h
(mu_fprint_options, mu_fprint_conf_option): Remove protos.
(mu_format_options, mu_format_conf_option): New protos.
* libmailutils/base/version.c (mu_fprint_options): Replace
with mu_format_options, which outputs formatted data to a mu_stream_t.
(mu_fprint_conf_option): Ditto.  Replaced by mu_format_conf_option.
(mu_print_options): Update accordingly.
* libmailutils/stdstream/basestr.c (mu_printf): New function.

* mu/acl.c: Replace stdio calls with stdstream ones.
* mu/cflags.c: Likewise.
* mu/filter.c: Likewise.
* mu/flt2047.c: Likewise.
* mu/imap.c: Likewise.
* mu/info.c: Likewise.
* mu/ldflags.c: Likewise.
* mu/logger.c: Likewise.
* mu/mu.c: Likewise.
* mu/mu.h: Likewise.
* mu/pop.c: Likewise.
* mu/query.c: Likewise.
* mu/shell.c: Likewise.
* mu/verbose.c: Likewise.
* mu/wicket.c: Likewise.
1 parent 76df98da
...@@ -37,6 +37,7 @@ void mu_stdstream_setup (void); ...@@ -37,6 +37,7 @@ void mu_stdstream_setup (void);
37 int mu_stdstream_strerr_create (mu_stream_t *str, int type, int facility, 37 int mu_stdstream_strerr_create (mu_stream_t *str, int type, int facility,
38 int priority, const char *tag, 38 int priority, const char *tag,
39 const char *fname); 39 const char *fname);
40 int mu_printf (const char *fmt, ...);
40 41
41 #ifdef __cplusplus 42 #ifdef __cplusplus
42 } 43 }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
18 #ifndef _MAILUTILS_VERSION_H 18 #ifndef _MAILUTILS_VERSION_H
19 #define _MAILUTILS_VERSION_H 19 #define _MAILUTILS_VERSION_H
20 20
21 #include <stdio.h> 21 #include <mailutils/types.h>
22 22
23 #ifdef __cplusplus 23 #ifdef __cplusplus
24 extern "C" { 24 extern "C" {
...@@ -31,8 +31,9 @@ struct mu_conf_option ...@@ -31,8 +31,9 @@ struct mu_conf_option
31 }; 31 };
32 32
33 extern void mu_print_options (void); 33 extern void mu_print_options (void);
34 extern void mu_fprint_options (FILE *fp, int verbose); 34 extern void mu_format_options (mu_stream_t, int verbose);
35 extern void mu_fprint_conf_option (FILE *fp, const struct mu_conf_option *opt, 35 extern void mu_format_conf_option (mu_stream_t,
36 const struct mu_conf_option *opt,
36 int verbose); 37 int verbose);
37 extern const struct mu_conf_option *mu_check_option (char *name); 38 extern const struct mu_conf_option *mu_check_option (char *name);
38 39
......
...@@ -22,7 +22,11 @@ ...@@ -22,7 +22,11 @@
22 #include <mailutils/nls.h> 22 #include <mailutils/nls.h>
23 #include <mailutils/version.h> 23 #include <mailutils/version.h>
24 #include <mailutils/cstr.h> 24 #include <mailutils/cstr.h>
25 #include <mailutils/stream.h>
26 #include <mailutils/stdstream.h>
27 #include <mailutils/errno.h>
25 #include <stdio.h> 28 #include <stdio.h>
29 #include <stdlib.h>
26 #include <string.h> 30 #include <string.h>
27 31
28 #include <confpaths.h> 32 #include <confpaths.h>
...@@ -121,27 +125,41 @@ static struct mu_conf_option mu_conf_option[] = { ...@@ -121,27 +125,41 @@ static struct mu_conf_option mu_conf_option[] = {
121 }; 125 };
122 126
123 void 127 void
124 mu_fprint_conf_option (FILE *fp, const struct mu_conf_option *opt, int verbose) 128 mu_format_conf_option (mu_stream_t stream, const struct mu_conf_option *opt,
129 int verbose)
125 { 130 {
126 fprintf (fp, "%s", opt->name); 131 mu_stream_printf (stream, "%s", opt->name);
127 if (verbose && opt->descr) 132 if (verbose && opt->descr)
128 fprintf (fp, " \t- %s", _(opt->descr)); 133 mu_stream_printf (stream, " \t- %s", _(opt->descr));
129 fputc('\n', fp); 134 mu_stream_printf (stream, "\n");
130 } 135 }
131 136
132 void 137 void
133 mu_fprint_options (FILE *fp, int verbose) 138 mu_format_options (mu_stream_t stream, int verbose)
134 { 139 {
135 int i; 140 int i;
136 141
137 for (i = 0; mu_conf_option[i].name; i++) 142 for (i = 0; mu_conf_option[i].name; i++)
138 mu_fprint_conf_option (fp, mu_conf_option + i, verbose); 143 mu_format_conf_option (stream, mu_conf_option + i, verbose);
139 } 144 }
140 145
141 void 146 void
142 mu_print_options () 147 mu_print_options ()
143 { 148 {
144 mu_fprint_options (stdout, 1); 149 if (mu_strout)
150 mu_stream_ref (mu_strout);
151 else
152 {
153 int rc = mu_stdio_stream_create (&mu_strout, MU_STDOUT_FD, 0);
154 if (rc)
155 {
156 fprintf (stderr, "mu_stdio_stream_create(%d): %s\n",
157 MU_STDOUT_FD, mu_strerror (rc));
158 abort ();
159 }
160 }
161 mu_format_options (mu_strout, 1);
162 mu_stream_unref (mu_strout);
145 } 163 }
146 164
147 const struct mu_conf_option * 165 const struct mu_conf_option *
......
...@@ -77,4 +77,17 @@ mu_stdstream_setup () ...@@ -77,4 +77,17 @@ mu_stdstream_setup ()
77 if (mu_stdstream_strerr_create (&mu_strerr, MU_STRERR_STDERR, 0, 0, 77 if (mu_stdstream_strerr_create (&mu_strerr, MU_STRERR_STDERR, 0, 0,
78 NULL, NULL)) 78 NULL, NULL))
79 abort (); 79 abort ();
80 /* FIXME: atexit (flushall) */
81 }
82
83 int
84 mu_printf (const char *fmt, ...)
85 {
86 int rc;
87 va_list ap;
88
89 va_start (ap, fmt);
90 rc = mu_stream_vprintf (mu_strout, fmt, ap);
91 va_end (ap);
92 return rc;
80 } 93 }
......
...@@ -163,7 +163,7 @@ mutool_acl (int argc, char **argv) ...@@ -163,7 +163,7 @@ mutool_acl (int argc, char **argv)
163 const char *ap = *argv++; 163 const char *ap = *argv++;
164 164
165 target_sa = parse_address (&target_salen, ap); 165 target_sa = parse_address (&target_salen, ap);
166 printf ("Testing %s:\n", ap); 166 mu_printf ("Testing %s:\n", ap);
167 rc = mu_acl_check_sockaddr (acl, target_sa, target_salen, &result); 167 rc = mu_acl_check_sockaddr (acl, target_sa, target_salen, &result);
168 if (rc) 168 if (rc)
169 { 169 {
...@@ -174,15 +174,15 @@ mutool_acl (int argc, char **argv) ...@@ -174,15 +174,15 @@ mutool_acl (int argc, char **argv)
174 switch (result) 174 switch (result)
175 { 175 {
176 case mu_acl_result_undefined: 176 case mu_acl_result_undefined:
177 printf ("%s: undefined\n", ap); 177 mu_printf ("%s: undefined\n", ap);
178 break; 178 break;
179 179
180 case mu_acl_result_accept: 180 case mu_acl_result_accept:
181 printf ("%s: accept\n", ap); 181 mu_printf ("%s: accept\n", ap);
182 break; 182 break;
183 183
184 case mu_acl_result_deny: 184 case mu_acl_result_deny:
185 printf ("%s: deny\n", ap); 185 mu_printf ("%s: deny\n", ap);
186 break; 186 break;
187 } 187 }
188 } 188 }
......
...@@ -40,7 +40,7 @@ mutool_cflags (int argc, char **argv) ...@@ -40,7 +40,7 @@ mutool_cflags (int argc, char **argv)
40 { 40 {
41 if (argp_parse (&cflags_argp, argc, argv, ARGP_IN_ORDER, NULL, NULL)) 41 if (argp_parse (&cflags_argp, argc, argv, ARGP_IN_ORDER, NULL, NULL))
42 return 1; 42 return 1;
43 printf ("%s\n", COMPILE_FLAGS); 43 mu_printf ("%s\n", COMPILE_FLAGS);
44 return 0; 44 return 0;
45 } 45 }
46 46
......
...@@ -130,7 +130,7 @@ int ...@@ -130,7 +130,7 @@ int
130 mutool_filter (int argc, char **argv) 130 mutool_filter (int argc, char **argv)
131 { 131 {
132 int rc, index; 132 int rc, index;
133 mu_stream_t in, out, flt; 133 mu_stream_t flt;
134 const char *fltname; 134 const char *fltname;
135 135
136 if (argp_parse (&filter_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) 136 if (argp_parse (&filter_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
...@@ -157,24 +157,11 @@ mutool_filter (int argc, char **argv) ...@@ -157,24 +157,11 @@ mutool_filter (int argc, char **argv)
157 157
158 fltname = argv[0]; 158 fltname = argv[0];
159 159
160 rc = mu_stdio_stream_create (&in, MU_STDIN_FD, 0);
161 if (rc)
162 {
163 mu_error (_("cannot open input stream: %s"), mu_strerror (rc));
164 return 1;
165 }
166
167 rc = mu_stdio_stream_create (&out, MU_STDOUT_FD, 0);
168 if (rc)
169 {
170 mu_error (_("cannot open output stream: %s"), mu_strerror (rc));
171 return 1;
172 }
173
174 if (line_length_option) 160 if (line_length_option)
175 reset_line_length (fltname, line_length); 161 reset_line_length (fltname, line_length);
176 162
177 rc = mu_filter_create_args (&flt, in, fltname, argc, (const char **)argv, 163 rc = mu_filter_create_args (&flt, mu_strin, fltname,
164 argc, (const char **)argv,
178 filter_mode, MU_STREAM_READ); 165 filter_mode, MU_STREAM_READ);
179 if (rc) 166 if (rc)
180 { 167 {
...@@ -182,7 +169,7 @@ mutool_filter (int argc, char **argv) ...@@ -182,7 +169,7 @@ mutool_filter (int argc, char **argv)
182 return 1; 169 return 1;
183 } 170 }
184 171
185 rc = mu_stream_copy (out, flt, 0, NULL); 172 rc = mu_stream_copy (mu_strout, flt, 0, NULL);
186 173
187 if (rc) 174 if (rc)
188 { 175 {
...@@ -191,9 +178,10 @@ mutool_filter (int argc, char **argv) ...@@ -191,9 +178,10 @@ mutool_filter (int argc, char **argv)
191 } 178 }
192 179
193 if (newline_option) 180 if (newline_option)
194 mu_stream_write (out, "\n", 1, NULL); 181 mu_stream_write (mu_strout, "\n", 1, NULL);
195 182
196 mu_stream_flush (out); 183 mu_stream_destroy (&flt);
184 mu_stream_flush (mu_strout);
197 185
198 return 0; 186 return 0;
199 } 187 }
......
...@@ -88,7 +88,6 @@ int ...@@ -88,7 +88,6 @@ int
88 mutool_flt2047 (int argc, char **argv) 88 mutool_flt2047 (int argc, char **argv)
89 { 89 {
90 int rc, index; 90 int rc, index;
91 mu_stream_t in, out;
92 char *p; 91 char *p;
93 92
94 if (argp_parse (&flt2047_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) 93 if (argp_parse (&flt2047_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
...@@ -97,20 +96,6 @@ mutool_flt2047 (int argc, char **argv) ...@@ -97,20 +96,6 @@ mutool_flt2047 (int argc, char **argv)
97 argc -= index; 96 argc -= index;
98 argv += index; 97 argv += index;
99 98
100 rc = mu_stdio_stream_create (&in, MU_STDIN_FD, 0);
101 if (rc)
102 {
103 mu_error (_("cannot open input stream: %s"), mu_strerror (rc));
104 return 1;
105 }
106
107 rc = mu_stdio_stream_create (&out, MU_STDOUT_FD, 0);
108 if (rc)
109 {
110 mu_error (_("cannot open output stream: %s"), mu_strerror (rc));
111 return 1;
112 }
113
114 if (argc) 99 if (argc)
115 { 100 {
116 char *p; 101 char *p;
...@@ -127,7 +112,7 @@ mutool_flt2047 (int argc, char **argv) ...@@ -127,7 +112,7 @@ mutool_flt2047 (int argc, char **argv)
127 mu_error ("%s", mu_strerror (rc)); 112 mu_error ("%s", mu_strerror (rc));
128 return 1; 113 return 1;
129 } 114 }
130 mu_stream_printf (out, "%s\n", p); 115 mu_printf ("%s\n", p);
131 } 116 }
132 } 117 }
133 else 118 else
...@@ -135,7 +120,8 @@ mutool_flt2047 (int argc, char **argv) ...@@ -135,7 +120,8 @@ mutool_flt2047 (int argc, char **argv)
135 size_t size = 0, n; 120 size_t size = 0, n;
136 char *buf = NULL; 121 char *buf = NULL;
137 122
138 while ((rc = mu_stream_getline (in, &buf, &size, &n)) == 0 && n > 0) 123 while ((rc = mu_stream_getline (mu_strin, &buf, &size, &n)) == 0
124 && n > 0)
139 { 125 {
140 mu_rtrim_class (buf, MU_CTYPE_SPACE); 126 mu_rtrim_class (buf, MU_CTYPE_SPACE);
141 if (decode_mode) 127 if (decode_mode)
...@@ -147,10 +133,10 @@ mutool_flt2047 (int argc, char **argv) ...@@ -147,10 +133,10 @@ mutool_flt2047 (int argc, char **argv)
147 mu_error ("%s", mu_strerror (rc)); 133 mu_error ("%s", mu_strerror (rc));
148 return 1; 134 return 1;
149 } 135 }
150 mu_stream_printf (out, "%s\n", p); 136 mu_printf ("%s\n", p);
151 } 137 }
152 } 138 }
153 mu_stream_flush (out); 139 mu_stream_flush (mu_strout);
154 140
155 return 0; 141 return 0;
156 } 142 }
......
...@@ -284,12 +284,11 @@ com_logout (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED) ...@@ -284,12 +284,11 @@ com_logout (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
284 } 284 }
285 else 285 else
286 { 286 {
287 mu_stream_printf (mustrout, "Try 'exit' to leave %s\n", 287 mu_printf ("Try 'exit' to leave %s\n", mu_program_name);
288 mu_program_name);
289 } 288 }
290 } 289 }
291 else 290 else
292 mu_stream_printf (mustrout, "Try 'exit' to leave %s\n", mu_program_name); 291 mu_printf ("Try 'exit' to leave %s\n", mu_program_name);
293 return status; 292 return status;
294 } 293 }
295 294
...@@ -325,13 +324,13 @@ com_capability (int argc, char **argv) ...@@ -325,13 +324,13 @@ com_capability (int argc, char **argv)
325 { 324 {
326 case 0: 325 case 0:
327 if (*elt) 326 if (*elt)
328 mu_stream_printf (mustrout, "%s: %s\n", argv[i], elt); 327 mu_printf ("%s: %s\n", argv[i], elt);
329 else 328 else
330 mu_stream_printf (mustrout, "%s is set\n", argv[i]); 329 mu_printf ("%s is set\n", argv[i]);
331 break; 330 break;
332 331
333 case MU_ERR_NOENT: 332 case MU_ERR_NOENT:
334 mu_stream_printf (mustrout, "%s is not set\n", argv[i]); 333 mu_printf ("%s is not set\n", argv[i]);
335 break; 334 break;
336 335
337 default: 336 default:
...@@ -350,7 +349,7 @@ com_capability (int argc, char **argv) ...@@ -350,7 +349,7 @@ com_capability (int argc, char **argv)
350 { 349 {
351 char *capa = NULL; 350 char *capa = NULL;
352 mu_iterator_current (iterator, (void **) &capa); 351 mu_iterator_current (iterator, (void **) &capa);
353 mu_stream_printf (mustrout, "CAPA: %s\n", capa ? capa : ""); 352 mu_printf ("CAPA: %s\n", capa ? capa : "");
354 } 353 }
355 mu_iterator_destroy (&iterator); 354 mu_iterator_destroy (&iterator);
356 } 355 }
...@@ -371,7 +370,7 @@ com_login (int argc, char **argv) ...@@ -371,7 +370,7 @@ com_login (int argc, char **argv)
371 mu_error (_("login: password required")); 370 mu_error (_("login: password required"));
372 return 1; 371 return 1;
373 } 372 }
374 status = mu_getpass (mustrin, mustrout, "Password:", &passbuf); 373 status = mu_getpass (mu_strin, mu_strout, "Password:", &passbuf);
375 if (status) 374 if (status)
376 return status; 375 return status;
377 pwd = passbuf; 376 pwd = passbuf;
...@@ -400,7 +399,7 @@ static int ...@@ -400,7 +399,7 @@ static int
400 _print_id (void *item, void *data) 399 _print_id (void *item, void *data)
401 { 400 {
402 const char *id = item; 401 const char *id = item;
403 mu_stream_printf (mustrout, "ID: %s %s\n", id, id + strlen (id) + 1); 402 mu_printf ("ID: %s %s\n", id, id + strlen (id) + 1);
404 return 0; 403 return 0;
405 } 404 }
406 405
...@@ -435,12 +434,11 @@ com_id (int argc, char **argv) ...@@ -435,12 +434,11 @@ com_id (int argc, char **argv)
435 switch (rc) 434 switch (rc)
436 { 435 {
437 case 0: 436 case 0:
438 mu_stream_printf (mustrout, "%s: %s\n", test, 437 mu_printf ("%s: %s\n", test, res + strlen (res) + 1);
439 res + strlen (res) + 1);
440 break; 438 break;
441 439
442 case MU_ERR_NOENT: 440 case MU_ERR_NOENT:
443 mu_stream_printf (mustrout, "%s is not set\n", test); 441 mu_printf ("%s is not set\n", test);
444 break; 442 break;
445 443
446 default: 444 default:
......
...@@ -74,7 +74,7 @@ mutool_info (int argc, char **argv) ...@@ -74,7 +74,7 @@ mutool_info (int argc, char **argv)
74 argv += index; 74 argv += index;
75 75
76 if (argc == 0) 76 if (argc == 0)
77 mu_fprint_options (stdout, verbose); 77 mu_format_options (mu_strout, verbose);
78 else 78 else
79 { 79 {
80 int i, found = 0; 80 int i, found = 0;
...@@ -85,7 +85,7 @@ mutool_info (int argc, char **argv) ...@@ -85,7 +85,7 @@ mutool_info (int argc, char **argv)
85 if (opt) 85 if (opt)
86 { 86 {
87 found++; 87 found++;
88 mu_fprint_conf_option (stdout, opt, verbose); 88 mu_format_conf_option (mu_strout, opt, verbose);
89 } 89 }
90 } 90 }
91 return found == argc ? 0 : 1; 91 return found == argc ? 0 : 1;
......
...@@ -184,12 +184,12 @@ mutool_ldflags (int argc, char **argv) ...@@ -184,12 +184,12 @@ mutool_ldflags (int argc, char **argv)
184 sort_entries (); 184 sort_entries ();
185 185
186 /* At least one entry is always present */ 186 /* At least one entry is always present */
187 printf ("%s", lib_entry[0].ptr); 187 mu_printf ("%s", lib_entry[0].ptr);
188 188
189 /* Print the rest of them separated by a space */ 189 /* Print the rest of them separated by a space */
190 for (j = 1; j < nentry; j++) 190 for (j = 1; j < nentry; j++)
191 printf (" %s", lib_entry[j].ptr); 191 mu_printf (" %s", lib_entry[j].ptr);
192 putchar ('\n'); 192 mu_printf ("\n");
193 return 0; 193 return 0;
194 } 194 }
195 195
......
...@@ -44,7 +44,7 @@ static struct argp_option logger_options[] = { ...@@ -44,7 +44,7 @@ static struct argp_option logger_options[] = {
44 }; 44 };
45 45
46 static char *input_file = NULL; 46 static char *input_file = NULL;
47 static int use_syslog = 0; 47 static int logger_type = MU_STRERR_STDERR;
48 static int log_severity = MU_LOG_ERROR; 48 static int log_severity = MU_LOG_ERROR;
49 static struct mu_locus locus; 49 static struct mu_locus locus;
50 static int syslog_facility = LOG_USER; 50 static int syslog_facility = LOG_USER;
...@@ -61,11 +61,11 @@ logger_parse_opt (int key, char *arg, struct argp_state *state) ...@@ -61,11 +61,11 @@ logger_parse_opt (int key, char *arg, struct argp_state *state)
61 break; 61 break;
62 62
63 case OPT_SYSLOG: 63 case OPT_SYSLOG:
64 use_syslog = 1; 64 logger_type = MU_STRERR_SYSLOG;
65 break; 65 break;
66 66
67 case OPT_STDERR: 67 case OPT_STDERR:
68 use_syslog = 0; 68 logger_type = MU_STRERR_STDERR;
69 break; 69 break;
70 70
71 case 's': 71 case 's':
...@@ -96,7 +96,7 @@ logger_parse_opt (int key, char *arg, struct argp_state *state) ...@@ -96,7 +96,7 @@ logger_parse_opt (int key, char *arg, struct argp_state *state)
96 if (s && 96 if (s &&
97 mu_string_to_syslog_priority (s, &syslog_priority)) 97 mu_string_to_syslog_priority (s, &syslog_priority))
98 argp_error (state, _("unknown priority: %s"), s); 98 argp_error (state, _("unknown priority: %s"), s);
99 use_syslog = 1; 99 logger_type = MU_STRERR_SYSLOG;
100 break; 100 break;
101 } 101 }
102 102
...@@ -142,7 +142,7 @@ int ...@@ -142,7 +142,7 @@ int
142 mutool_logger (int argc, char **argv) 142 mutool_logger (int argc, char **argv)
143 { 143 {
144 int index; 144 int index;
145 mu_stream_t transport, logger; 145 mu_stream_t logger, input;
146 int rc, mode; 146 int rc, mode;
147 147
148 if (argp_parse (&logger_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) 148 if (argp_parse (&logger_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
...@@ -158,50 +158,14 @@ mutool_logger (int argc, char **argv) ...@@ -158,50 +158,14 @@ mutool_logger (int argc, char **argv)
158 158
159 if (!syslog_tag) 159 if (!syslog_tag)
160 syslog_tag = "mu-logger"; 160 syslog_tag = "mu-logger";
161 if (use_syslog) 161 if (mu_stdstream_strerr_create (&logger, logger_type,
162 syslog_facility, syslog_priority,
163 syslog_tag, NULL))
162 { 164 {
163 openlog (syslog_tag, LOG_PID, syslog_facility); 165 mu_error (_("cannot create log stream: %s"),
164
165 rc = mu_syslog_stream_create (&transport, syslog_priority);
166 if (rc)
167 {
168 mu_error (_("cannot create syslog stream: %s"),
169 mu_strerror (rc)); 166 mu_strerror (rc));
170 exit (1); 167 exit (1);
171 } 168 }
172 }
173 else
174 {
175 mu_stream_t str;
176 char *fltargs[3] = { "INLINE-COMMENT", };
177
178 rc = mu_stdio_stream_create (&str, MU_STDERR_FD, 0);
179 if (rc)
180 {
181 mu_error (_("cannot open error stream: %s"), mu_strerror (rc));
182 return 1;
183 }
184 mu_asprintf (&fltargs[1], "%s: ", syslog_tag);
185 fltargs[2] = NULL;
186 rc = mu_filter_create_args (&transport, str,
187 "INLINE-COMMENT", 2, (const char *)fltargs,
188 MU_FILTER_ENCODE, MU_STREAM_WRITE);
189 mu_stream_unref (str);
190 free (fltargs[1]);
191 if (rc)
192 {
193 mu_error (_("cannot open filter stream: %s"), mu_strerror (rc));
194 return 1;
195 }
196 }
197
198 rc = mu_log_stream_create (&logger, transport);
199 mu_stream_unref (transport);
200 if (rc)
201 {
202 mu_error (_("cannot open logger stream: %s"), mu_strerror (rc));
203 return 1;
204 }
205 169
206 mode = MU_LOGMODE_SEVERITY | MU_LOGMODE_LOCUS; 170 mode = MU_LOGMODE_SEVERITY | MU_LOGMODE_LOCUS;
207 mu_stream_ioctl (logger, MU_IOCTL_LOGSTREAM_SET_MODE, &mode); 171 mu_stream_ioctl (logger, MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
...@@ -223,16 +187,12 @@ mutool_logger (int argc, char **argv) ...@@ -223,16 +187,12 @@ mutool_logger (int argc, char **argv)
223 } 187 }
224 else if (!input_file || strcmp (input_file, "-") == 0) 188 else if (!input_file || strcmp (input_file, "-") == 0)
225 { 189 {
226 rc = mu_stdio_stream_create (&transport, MU_STDIN_FD, 0); 190 mu_stream_ref (mu_strin);
227 if (rc) 191 input = mu_strin;
228 {
229 mu_error (_("cannot open input stream: %s"), mu_strerror (rc));
230 return 1;
231 }
232 } 192 }
233 else 193 else
234 { 194 {
235 rc = mu_file_stream_create (&transport, input_file, MU_STREAM_READ); 195 rc = mu_file_stream_create (&input, input_file, MU_STREAM_READ);
236 if (rc) 196 if (rc)
237 { 197 {
238 mu_error (_("cannot open input stream %s: %s"), 198 mu_error (_("cannot open input stream %s: %s"),
...@@ -241,8 +201,8 @@ mutool_logger (int argc, char **argv) ...@@ -241,8 +201,8 @@ mutool_logger (int argc, char **argv)
241 } 201 }
242 } 202 }
243 203
244 rc = mu_stream_copy (logger, transport, 0, NULL); 204 rc = mu_stream_copy (logger, input, 0, NULL);
245 mu_stream_unref (transport); 205 mu_stream_unref (input);
246 mu_stream_unref (logger); 206 mu_stream_unref (logger);
247 return !!rc; 207 return !!rc;
248 } 208 }
......
...@@ -105,6 +105,8 @@ main (int argc, char **argv) ...@@ -105,6 +105,8 @@ main (int argc, char **argv)
105 MU_APP_INIT_NLS (); 105 MU_APP_INIT_NLS ();
106 MU_AUTH_REGISTER_ALL_MODULES (); 106 MU_AUTH_REGISTER_ALL_MODULES ();
107 107
108 mu_stdstream_setup ();
109
108 /* Register the desired mailbox formats. */ 110 /* Register the desired mailbox formats. */
109 mu_register_all_mbox_formats (); 111 mu_register_all_mbox_formats ();
110 112
......
...@@ -33,7 +33,6 @@ struct mutool_command ...@@ -33,7 +33,6 @@ struct mutool_command
33 extern char *mutool_shell_prompt; 33 extern char *mutool_shell_prompt;
34 extern char **mutool_prompt_env; 34 extern char **mutool_prompt_env;
35 extern int mutool_shell_interactive; 35 extern int mutool_shell_interactive;
36 extern mu_stream_t mustrin, mustrout;
37 int mutool_shell (const char *name, struct mutool_command *cmd); 36 int mutool_shell (const char *name, struct mutool_command *cmd);
38 mu_stream_t mutool_open_pager (void); 37 mu_stream_t mutool_open_pager (void);
39 38
......
...@@ -186,7 +186,7 @@ com_apop (int argc, char **argv) ...@@ -186,7 +186,7 @@ com_apop (int argc, char **argv)
186 } 186 }
187 else 187 else
188 { 188 {
189 status = mu_getpass (mustrin, mustrout, "Password:", &passbuf); 189 status = mu_getpass (mu_strin, mu_strout, "Password:", &passbuf);
190 if (status) 190 if (status)
191 return status; 191 return status;
192 pwd = passbuf; 192 pwd = passbuf;
...@@ -234,13 +234,13 @@ com_capa (int argc, char **argv) ...@@ -234,13 +234,13 @@ com_capa (int argc, char **argv)
234 { 234 {
235 case 0: 235 case 0:
236 if (*elt) 236 if (*elt)
237 mu_stream_printf (mustrout, "%s: %s\n", argv[i], elt); 237 mu_printf ("%s: %s\n", argv[i], elt);
238 else 238 else
239 mu_stream_printf (mustrout, "%s is set\n", argv[i]); 239 mu_printf ("%s is set\n", argv[i]);
240 break; 240 break;
241 241
242 case MU_ERR_NOENT: 242 case MU_ERR_NOENT:
243 mu_stream_printf (mustrout, "%s is not set\n", argv[i]); 243 mu_printf ("%s is not set\n", argv[i]);
244 break; 244 break;
245 245
246 default: 246 default:
...@@ -259,7 +259,7 @@ com_capa (int argc, char **argv) ...@@ -259,7 +259,7 @@ com_capa (int argc, char **argv)
259 { 259 {
260 char *capa = NULL; 260 char *capa = NULL;
261 mu_iterator_current (iterator, (void **) &capa); 261 mu_iterator_current (iterator, (void **) &capa);
262 mu_stream_printf (mustrout, "CAPA: %s\n", capa ? capa : ""); 262 mu_printf ("CAPA: %s\n", capa ? capa : "");
263 } 263 }
264 mu_iterator_destroy (&iterator); 264 mu_iterator_destroy (&iterator);
265 } 265 }
...@@ -296,7 +296,7 @@ com_uidl (int argc, char **argv) ...@@ -296,7 +296,7 @@ com_uidl (int argc, char **argv)
296 unsigned int msgno = strtoul (argv[1], NULL, 10); 296 unsigned int msgno = strtoul (argv[1], NULL, 10);
297 status = mu_pop3_uidl (pop3, msgno, &uidl); 297 status = mu_pop3_uidl (pop3, msgno, &uidl);
298 if (status == 0) 298 if (status == 0)
299 mu_stream_printf (mustrout, "Msg: %d UIDL: %s\n", msgno, uidl ? uidl : ""); 299 mu_printf ("Msg: %d UIDL: %s\n", msgno, uidl ? uidl : "");
300 free (uidl); 300 free (uidl);
301 } 301 }
302 return status; 302 return status;
...@@ -331,7 +331,7 @@ com_list (int argc, char **argv) ...@@ -331,7 +331,7 @@ com_list (int argc, char **argv)
331 unsigned int msgno = strtoul (argv[1], NULL, 10); 331 unsigned int msgno = strtoul (argv[1], NULL, 10);
332 status = mu_pop3_list (pop3, msgno, &size); 332 status = mu_pop3_list (pop3, msgno, &size);
333 if (status == 0) 333 if (status == 0)
334 mu_stream_printf (mustrout, "Msg: %u Size: %lu\n", msgno, (unsigned long) size); 334 mu_printf ("Msg: %u Size: %lu\n", msgno, (unsigned long) size);
335 } 335 }
336 return status; 336 return status;
337 } 337 }
...@@ -355,7 +355,7 @@ com_pass (int argc, char **argv) ...@@ -355,7 +355,7 @@ com_pass (int argc, char **argv)
355 mu_error (_("pass: password required")); 355 mu_error (_("pass: password required"));
356 return 1; 356 return 1;
357 } 357 }
358 status = mu_getpass (mustrin, mustrout, "Password:", &passbuf); 358 status = mu_getpass (mu_strin, mu_strout, "Password:", &passbuf);
359 if (status) 359 if (status)
360 return status; 360 return status;
361 pwd = passbuf; 361 pwd = passbuf;
...@@ -380,7 +380,7 @@ com_stat (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED) ...@@ -380,7 +380,7 @@ com_stat (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
380 int status = 0; 380 int status = 0;
381 381
382 status = mu_pop3_stat (pop3, &count, &size); 382 status = mu_pop3_stat (pop3, &count, &size);
383 mu_stream_printf (mustrout, "Mesgs: %lu Size %lu\n", 383 mu_printf ("Mesgs: %lu Size %lu\n",
384 (unsigned long) count, (unsigned long) size); 384 (unsigned long) count, (unsigned long) size);
385 return status; 385 return status;
386 } 386 }
...@@ -578,11 +578,11 @@ com_quit (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED) ...@@ -578,11 +578,11 @@ com_quit (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
578 } 578 }
579 else 579 else
580 { 580 {
581 mu_stream_printf (mustrout, "Try 'exit' to leave %s\n", mu_program_name); 581 mu_printf ("Try 'exit' to leave %s\n", mu_program_name);
582 } 582 }
583 } 583 }
584 else 584 else
585 mu_stream_printf (mustrout, "Try 'exit' to leave %s\n", mu_program_name); 585 mu_printf ("Try 'exit' to leave %s\n", mu_program_name);
586 return status; 586 return status;
587 } 587 }
588 588
......
...@@ -72,10 +72,9 @@ static struct argp query_argp = { ...@@ -72,10 +72,9 @@ static struct argp query_argp = {
72 int 72 int
73 mutool_query (int argc, char **argv) 73 mutool_query (int argc, char **argv)
74 { 74 {
75 int rc, index; 75 int index;
76 mu_cfg_tree_t *tree = NULL; 76 mu_cfg_tree_t *tree = NULL;
77 int fmtflags = 0; 77 int fmtflags = 0;
78 mu_stream_t stream;
79 78
80 if (argp_parse (&query_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) 79 if (argp_parse (&query_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
81 return 1; 80 return 1;
...@@ -100,12 +99,6 @@ mutool_query (int argc, char **argv) ...@@ -100,12 +99,6 @@ mutool_query (int argc, char **argv)
100 return 1; 99 return 1;
101 if (!tree) 100 if (!tree)
102 return 0; 101 return 0;
103 rc = mu_stdio_stream_create (&stream, MU_STDOUT_FD, 0);
104 if (rc)
105 {
106 mu_error ("mu_stdio_stream_create: %s", mu_strerror (rc));
107 return 1;
108 }
109 if (verbose_option) 102 if (verbose_option)
110 fmtflags = MU_CFG_FMT_LOCUS; 103 fmtflags = MU_CFG_FMT_LOCUS;
111 for ( ; argc > 0; argc--, argv++) 104 for ( ; argc > 0; argc--, argv++)
...@@ -114,7 +107,7 @@ mutool_query (int argc, char **argv) ...@@ -114,7 +107,7 @@ mutool_query (int argc, char **argv)
114 mu_cfg_node_t *node; 107 mu_cfg_node_t *node;
115 108
116 if (mu_cfg_find_node (tree, path, &node) == 0) 109 if (mu_cfg_find_node (tree, path, &node) == 0)
117 mu_cfg_format_node (stream, node, fmtflags); 110 mu_cfg_format_node (mu_strout, node, fmtflags);
118 } 111 }
119 return 0; 112 return 0;
120 } 113 }
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
33 char *mutool_shell_prompt; 33 char *mutool_shell_prompt;
34 char **mutool_prompt_env; 34 char **mutool_prompt_env;
35 int mutool_shell_interactive; 35 int mutool_shell_interactive;
36 mu_stream_t mustrin, mustrout;
37 36
38 37
39 static int shell_exit (int, char **); 38 static int shell_exit (int, char **);
...@@ -161,16 +160,16 @@ list_commands (struct mutool_command *tab, const char *name) ...@@ -161,16 +160,16 @@ list_commands (struct mutool_command *tab, const char *name)
161 if (printed == 6) 160 if (printed == 6)
162 { 161 {
163 printed = 0; 162 printed = 0;
164 mu_stream_printf (mustrout, "\n"); 163 mu_printf ("\n");
165 } 164 }
166 if (mu_c_strncasecmp (tab->name, name, namelen) == 0) 165 if (mu_c_strncasecmp (tab->name, name, namelen) == 0)
167 { 166 {
168 mu_stream_printf (mustrout, "%s\t", tab->name); 167 mu_printf ("%s\t", tab->name);
169 printed++; 168 printed++;
170 } 169 }
171 } 170 }
172 if (printed && printed < 6) 171 if (printed && printed < 6)
173 mu_stream_printf (mustrout, "\n"); 172 mu_printf ("\n");
174 } 173 }
175 174
176 static struct mutool_command * 175 static struct mutool_command *
...@@ -204,12 +203,10 @@ shell_help (int argc, char **argv) ...@@ -204,12 +203,10 @@ shell_help (int argc, char **argv)
204 struct mutool_command *com = find_command (argv[1]); 203 struct mutool_command *com = find_command (argv[1]);
205 204
206 if (com) 205 if (com)
207 print_comtab (mustrout, com); 206 print_comtab (mu_strout, com);
208 else 207 else
209 { 208 {
210 mu_stream_printf (mustrout, 209 mu_printf ("No commands match `%s'. Possibilties are:\n", name);
211 "No commands match `%s'. Possibilties are:\n",
212 name);
213 list_commands (shell_comtab, name); 210 list_commands (shell_comtab, name);
214 } 211 }
215 } 212 }
...@@ -248,8 +245,8 @@ mutool_open_pager () ...@@ -248,8 +245,8 @@ mutool_open_pager ()
248 return stream; 245 return stream;
249 mu_error (_("cannot start pager: %s"), mu_strerror (rc)); 246 mu_error (_("cannot start pager: %s"), mu_strerror (rc));
250 } 247 }
251 mu_stream_ref (mustrout); 248 mu_stream_ref (mu_strout);
252 return mustrout; 249 return mu_strout;
253 } 250 }
254 251
255 252
...@@ -391,7 +388,7 @@ retrieve_history (char *str) ...@@ -391,7 +388,7 @@ retrieve_history (char *str)
391 return 1; 388 return 1;
392 389
393 case 2: 390 case 2:
394 mu_stream_printf (mustrout, "%s\n", out); 391 mu_printf ("%s\n", out);
395 free (out); 392 free (out);
396 return 1; 393 return 1;
397 } 394 }
...@@ -425,10 +422,10 @@ readline (char *prompt) ...@@ -425,10 +422,10 @@ readline (char *prompt)
425 422
426 if (prompt) 423 if (prompt)
427 { 424 {
428 mu_stream_printf (mustrout, "%s", prompt); 425 mu_printf ("%s", prompt);
429 fflush (stdout); 426 mu_stream_flush (mu_strout);
430 } 427 }
431 if (mu_stream_getline (mustrin, &buf, &size, &n) || n == 0) 428 if (mu_stream_getline (mu_strin, &buf, &size, &n) || n == 0)
432 { 429 {
433 free (buf); 430 free (buf);
434 buf = NULL; 431 buf = NULL;
...@@ -530,7 +527,7 @@ input_line_script () ...@@ -530,7 +527,7 @@ input_line_script ()
530 size_t size = 0, n; 527 size_t size = 0, n;
531 char *buf = NULL; 528 char *buf = NULL;
532 529
533 if (mu_stream_getline (mustrin, &buf, &size, &n) || n == 0) 530 if (mu_stream_getline (mu_strin, &buf, &size, &n) || n == 0)
534 return NULL; 531 return NULL;
535 return buf; 532 return buf;
536 } 533 }
...@@ -547,28 +544,9 @@ shell_exit (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED) ...@@ -547,28 +544,9 @@ shell_exit (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
547 int 544 int
548 mutool_shell (const char *name, struct mutool_command *cmd) 545 mutool_shell (const char *name, struct mutool_command *cmd)
549 { 546 {
550 int rc;
551 size_t n; 547 size_t n;
552 char *(*input_line) (); 548 char *(*input_line) ();
553 549
554 rc = mu_stdio_stream_create (&mustrin, MU_STDIN_FD,
555 MU_STREAM_READ);
556 if (rc)
557 {
558 mu_diag_funcall (MU_DIAG_ERROR, "mu_stdio_stream_create",
559 "MU_STDIN_FD", rc);
560 return 1;
561 }
562
563 rc = mu_stdio_stream_create (&mustrout, MU_STDOUT_FD,
564 MU_STREAM_WRITE);
565 if (rc)
566 {
567 mu_diag_funcall (MU_DIAG_ERROR, "mu_stdio_stream_create",
568 "MU_STDOUT_FD", rc);
569 return 1;
570 }
571
572 mutool_shell_interactive = isatty (0); 550 mutool_shell_interactive = isatty (0);
573 input_line = mutool_shell_interactive ? 551 input_line = mutool_shell_interactive ?
574 input_line_interactive : input_line_script; 552 input_line_interactive : input_line_script;
...@@ -616,8 +594,8 @@ mutool_shell (const char *name, struct mutool_command *cmd) ...@@ -616,8 +594,8 @@ mutool_shell (const char *name, struct mutool_command *cmd)
616 } 594 }
617 if (mutool_shell_interactive) 595 if (mutool_shell_interactive)
618 finish_readline (); 596 finish_readline ();
619 mu_stream_destroy (&mustrin); 597 mu_stream_destroy (&mu_strin);
620 mu_stream_destroy (&mustrout); 598 mu_stream_destroy (&mu_strout);
621 return 0; 599 return 0;
622 } 600 }
623 601
......
...@@ -67,24 +67,24 @@ shell_verbose (int argc, char **argv, ...@@ -67,24 +67,24 @@ shell_verbose (int argc, char **argv,
67 { 67 {
68 if (QRY_VERBOSE ()) 68 if (QRY_VERBOSE ())
69 { 69 {
70 mu_stream_printf (mustrout, "verbose is on"); 70 mu_printf ("verbose is on");
71 if (HAS_VERBOSE_MASK ()) 71 if (HAS_VERBOSE_MASK ())
72 { 72 {
73 char *delim = " ("; 73 char *delim = " (";
74 74
75 if (QRY_VERBOSE_MASK (MU_XSCRIPT_SECURE)) 75 if (QRY_VERBOSE_MASK (MU_XSCRIPT_SECURE))
76 { 76 {
77 mu_stream_printf (mustrout, "%ssecure", delim); 77 mu_printf ("%ssecure", delim);
78 delim = ", "; 78 delim = ", ";
79 } 79 }
80 if (QRY_VERBOSE_MASK (MU_XSCRIPT_PAYLOAD)) 80 if (QRY_VERBOSE_MASK (MU_XSCRIPT_PAYLOAD))
81 mu_stream_printf (mustrout, "%spayload", delim); 81 mu_printf ("%spayload", delim);
82 mu_stream_printf (mustrout, ")"); 82 mu_printf (")");
83 } 83 }
84 mu_stream_printf (mustrout, "\n"); 84 mu_printf ("\n");
85 } 85 }
86 else 86 else
87 mu_stream_printf (mustrout, "verbose is off\n"); 87 mu_printf ("verbose is off\n");
88 } 88 }
89 else 89 else
90 { 90 {
......
...@@ -103,16 +103,16 @@ wicket_match (mu_stream_t stream, const char *str) ...@@ -103,16 +103,16 @@ wicket_match (mu_stream_t stream, const char *str)
103 ret = 0; 103 ret = 0;
104 if (wicket_verbose) 104 if (wicket_verbose)
105 { 105 {
106 printf ("%s: %s:%d", str, loc.file, loc.line); 106 mu_printf ("%s: %s:%d", str, loc.file, loc.line);
107 if (wicket_verbose > 1) 107 if (wicket_verbose > 1)
108 printf (": %s", mu_url_to_string (url)); 108 mu_printf (": %s", mu_url_to_string (url));
109 putchar ('\n'); 109 mu_printf ("\n");
110 } 110 }
111 break; 111 break;
112 112
113 case MU_ERR_NOENT: 113 case MU_ERR_NOENT:
114 if (wicket_verbose) 114 if (wicket_verbose)
115 printf ("%s: %s\n", str, _("not found")); 115 mu_printf ("%s: %s\n", str, _("not found"));
116 ret = 1; 116 ret = 1;
117 break; 117 break;
118 118
......