From: Heiko Schlittermann (HS12-RIPE) Date: Sat, 26 Dec 2015 13:16:43 +0000 (+0100) Subject: Pretty print for -bP config X-Git-Tag: exim-4_87_RC3~34 X-Git-Url: https://git.exim.org/users/heiko/exim.git/commitdiff_plain/30ef6099db9a7e26e55e9c58d8e1c0f79a95b06f?hp=f40d5be37b9adca10b16e6b576f84c65f69899f5 Pretty print for -bP config --- diff --git a/src/src/readconf.c b/src/src/readconf.c index 8dd5915e4..e52f45fca 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -4275,7 +4275,7 @@ int indent = 0; for (i = config_lines; i; i = i->next) { - const uschar *current; + uschar *current; uschar *p; /* skip over to the first non-space */ @@ -4285,7 +4285,23 @@ for (i = config_lines; i; i = i->next) if (*current == '\0') continue; - /* TODO: Collapse or insert spaces around the first '=' */ + /* Collapse runs of spaces. We stop this if we encounter one of the + * following characters: "'$, as this may indicate careful formatting */ + for (p = current; *p; ++p) + { + uschar *next; + if (!isspace(*p)) continue; + if (*p != ' ') *p = ' '; + + for (next = p; isspace(*next); ++next) + ; + + if (next - p > 1) + memmove(p+1, next, strlen(next)+1); + + if (*next == '"' || *next == '\'' || *next == '$') + break; + } /* # lines */ if (current[0] == '#') @@ -4294,6 +4310,7 @@ for (i = config_lines; i; i = i->next) /* begin lines are left aligned */ else if (Ustrncmp(current, "begin", 5) == 0 && isspace(current[5])) { + puts(""); puts(CCS current); indent = TS; } @@ -4301,11 +4318,11 @@ for (i = config_lines; i; i = i->next) /* router/acl/transport block names */ else if (current[Ustrlen(current)-1] == ':' && !Ustrchr(current, '=')) { - printf("%*s%s\n", TS, "", current); + printf("\n%*s%s\n", TS, "", current); indent = 2 * TS; } - /* hidden lines (MACROS or prefixed with hide) */ + /* hidden lines (all MACROS or lines prefixed with "hide") */ else if ( !admin && ( isupper(*current) || Ustrncmp(current, "hide", 4) == 0 && isspace(current[4]) @@ -4315,7 +4332,7 @@ for (i = config_lines; i; i = i->next) if ((p = Ustrchr(current, '='))) { *p = '\0'; - printf("%*s%s = %s\n", indent, "", current, hidden); + printf("%*s%s= %s\n", indent, "", current, hidden); } /* e.g.: hide split_spool_directory */ else