aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-11-02 15:44:27 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-11-02 15:44:27 +0200
commit38e58d3662ac6c2e53e9ec8b85934e0e23a199c0 (patch)
tree13eb93e3ff14c94ccdcaa13a0a85ed883ece438a /src
parentf7ea305fee69c0814a075d01b2b92a153916f093 (diff)
downloadmailfromd-38e58d3662ac6c2e53e9ec8b85934e0e23a199c0.tar.gz
mailfromd-38e58d3662ac6c2e53e9ec8b85934e0e23a199c0.tar.bz2
Follow Mailutils commit dc62b399
Diffstat (limited to 'src')
-rw-r--r--src/main.c175
1 files changed, 141 insertions, 34 deletions
diff --git a/src/main.c b/src/main.c
index 18785afa..ab9315fe 100644
--- a/src/main.c
+++ b/src/main.c
@@ -931,33 +931,62 @@ mf_runtime_param_finish()
/* Auxiliary functions */
+unsigned keyword_column = 0;
+unsigned header_column = 2;
+unsigned value_column = 32;
+unsigned right_margin = 79;
+
+static void
+set_column(mu_stream_t str, unsigned margin)
+{
+ mu_stream_ioctl(str, MU_IOCTL_WORDWRAPSTREAM,
+ MU_IOCTL_WORDWRAP_SET_MARGIN,
+ &margin);
+}
static int
db_format_enumerator(struct db_format *fmt, void *data)
{
- printf("%s database: %s\n", fmt->name, fmt->dbname);
+ mu_stream_t str = data;
+
+ set_column(str, keyword_column);
+ mu_stream_printf(str, "%s database:", fmt->name);
+ set_column(str, value_column);
+ mu_stream_printf(str, "%s\n", fmt->dbname);
+
+ set_column(str, keyword_column);
if (strcmp(fmt->name, "cache") == 0) {
- printf("%s positive expiration: %lu\n", fmt->name,
- fmt->expire_interval);
- printf("%s negative expiration: %lu\n", fmt->name,
- negative_expire_interval);
- } else
- printf("%s expiration: %lu\n", fmt->name,
- fmt->expire_interval);
+ mu_stream_printf(str, "%s positive expiration:", fmt->name);
+ set_column(str, value_column);
+ mu_stream_printf(str, "%lu\n", fmt->expire_interval);
+
+ set_column(str, keyword_column);
+ mu_stream_printf(str, "%s negative expiration:", fmt->name);
+ set_column(str, value_column);
+ mu_stream_printf(str, "%lu\n", negative_expire_interval);
+ } else {
+ mu_stream_printf(str, "%s expiration:", fmt->name);
+ set_column(str, value_column);
+ mu_stream_printf(str, "%lu\n", fmt->expire_interval);
+ }
return 0;
}
static void
-list_db_formats(const char *pfx)
+list_db_formats(mu_stream_t str, const char *pfx)
{
mu_iterator_t itr;
int rc;
const char *defdb = DEFAULT_DB_TYPE;
- printf("%s", pfx);
+ set_column(str, keyword_column);
+ mu_stream_printf(str, "%s:", pfx);
+
+ set_column(str, value_column);
+
rc = mu_dbm_impl_iterator(&itr);
if (rc) {
- printf("%s\n", _("unknown"));
+ mu_stream_printf(str, "%s\n", _("unknown"));
mu_error("%s", mu_strerror(rc));
} else {
int i;
@@ -967,45 +996,123 @@ list_db_formats(const char *pfx)
mu_iterator_current(itr, (void**)&impl);
if (i)
- printf(", ");
+ mu_stream_printf(str, ", ");
else if (!defdb)
defdb = impl->_dbm_name;
- printf("%s", impl->_dbm_name);
+ mu_stream_printf(str, "%s", impl->_dbm_name);
}
- putchar('\n');
+ mu_stream_write(str, "\n", 1, NULL);
mu_iterator_destroy(&itr);
}
- printf("default database type: %s\n", defdb);
+
+ set_column(str, keyword_column);
+ mu_stream_printf(str, "%s:", "default database type");
+ set_column(str, value_column);
+ mu_stream_printf(str, "%s\n", defdb);
}
-void
-mailfromd_show_defaults()
+struct string_value {
+ char const *kw;
+ int type;
+ union {
+ char *s_const;
+ char **s_var;
+ char *(*s_func) (void);
+ } data;
+};
+
+static char *
+string_preprocessor (void)
{
- printf("version: %s\n", VERSION);
- printf("script file: %s\n", script_file);
- printf("preprocessor: %s\n", ext_pp ? ext_pp : "none");
- printf("user: %s\n", mf_server_user);
- printf("statedir: %s\n", mailfromd_state_dir);
- printf("socket: %s\n", DEFAULT_SOCKET);
- printf("pidfile: %s\n", pidfile);
+ return ext_pp ? ext_pp : "none";
+}
+
#ifdef USE_SYSLOG_ASYNC
-#if DEFAULT_SYSLOG_ASYNC == 1
- printf("default syslog: non-blocking\n");
+# if DEFAULT_SYSLOG_ASYNC == 1
+# define DEFAULT_SYSLOG "non-blocking"
+# else
+# define DEFAULT_SYSLOG "blocking"
+# endif
#else
- printf("default syslog: blocking\n");
+# define DEFAULT_SYSLOG "blocking"
#endif
-#endif
- list_db_formats("supported databases: ");
- printf("Optional features: ");
+
+enum {
+ STRING_CONSTANT,
+ STRING_VARIABLE,
+ STRING_FUNCTION
+};
+
+static struct string_value string_values[] = {
+ { "version", STRING_CONSTANT, { .s_const = VERSION } },
+ { "script file", STRING_VARIABLE, { .s_var = &script_file } },
+ { "preprocessor", STRING_FUNCTION, { .s_func = string_preprocessor } },
+ { "user", STRING_VARIABLE, { .s_var = &mf_server_user } },
+ { "statedir", STRING_VARIABLE, { .s_var = &mailfromd_state_dir } },
+ { "socket", STRING_CONSTANT, { .s_const = DEFAULT_SOCKET } },
+ { "pidfile", STRING_VARIABLE, { .s_var = &pidfile } },
+ { "default syslog", STRING_CONSTANT, { .s_const = DEFAULT_SYSLOG } },
+ { NULL }
+};
+
+static void
+print_string_values(mu_stream_t str)
+{
+ struct string_value *p;
+ char const *val;
+
+ for (p = string_values; p->kw; p++) {
+ set_column(str, keyword_column);
+ mu_stream_printf(str, "%s:", p->kw);
+
+ switch (p->type) {
+ case STRING_CONSTANT:
+ val = p->data.s_const;
+ break;
+
+ case STRING_VARIABLE:
+ val = *p->data.s_var;
+ break;
+
+ case STRING_FUNCTION:
+ val = p->data.s_func ();
+ }
+
+ set_column(str, value_column);
+ mu_stream_printf(str, "%s\n", val);
+ }
+}
+
+void
+mailfromd_show_defaults(void)
+{
+ int rc;
+ mu_stream_t str;
+
+ rc = mu_wordwrap_stream_create (&str, mu_strout, 0, right_margin);
+ if (rc) {
+ str = mu_strout;
+ mu_stream_ref(str);
+ }
+
+ print_string_values(str);
+
+ list_db_formats(str, "supported databases");
+
+ set_column(str, keyword_column);
+ mu_stream_printf(str, "%s:", "optional features");
+ set_column(str, value_column);
#if defined WITH_GEOIP
- printf(" GeoIP");
+ mu_stream_printf(str, " %s", "GeoIP");
#endif
#if defined WITH_DSPAM
- printf(" DSPAM");
+ mu_stream_printf(str, " %s", "DSPAM");
#endif
- printf("\n");
+ mu_stream_write(str, "\n", 1, NULL);
+
+ db_format_enumerate(db_format_enumerator, str);
- db_format_enumerate(db_format_enumerator, NULL);
+ mu_stream_destroy (&str);
}
static int

Return to:

Send suggestions and report system problems to the System administrator.