5
/* basic line printing support
7
/* #include <postconf.h>
9
/* void pcf_print_line(fp, mode, const char *fmt, ...)
14
/* pcf_print_line() formats text, normalized whitespace, and
15
/* optionally folds long lines.
21
/* Bit-wise OR of zero or more of the following (other flags
30
/* Problems are reported to the standard error stream.
34
/* The Secure Mailer license must be distributed with this software.
37
/* IBM T.J. Watson Research
39
/* Yorktown Heights, NY 10598, USA
48
/* Utility library. */
54
/* Application-specific. */
60
#define STR(x) vstring_str(x)
62
/* pcf_print_line - show line possibly folded, and with normalized whitespace */
64
void pcf_print_line(VSTREAM *fp, int mode, const char *fmt,...)
67
static VSTRING *buf = 0;
74
* One-off initialization.
77
buf = vstring_alloc(100);
83
vstring_vsprintf(buf, fmt, ap);
87
* Normalize the whitespace. We don't use the line_wrap() routine because
88
* 1) that function does not normalize whitespace between words and 2) we
89
* want to normalize whitespace even when not wrapping lines.
91
* XXX Some parameters preserve whitespace: for example, smtpd_banner and
92
* smtpd_reject_footer. If we have to preserve whitespace between words,
93
* then perhaps readlline() can be changed to canonicalize whitespace
94
* that follows a newline.
96
for (start = STR(buf); *(start += strspn(start, PCF_SEPARATORS)) != 0; start = next) {
97
word_len = strcspn(start, PCF_SEPARATORS);
98
if (*(next = start + word_len) != 0)
100
if (word_len > 0 && line_len > 0) {
101
if ((mode & PCF_FOLD_LINE) == 0
102
|| line_len + word_len < PCF_LINE_LIMIT) {
103
vstream_fputs(" ", fp);
106
vstream_fputs("\n" PCF_INDENT_TEXT, fp);
107
line_len = PCF_INDENT_LEN;
110
vstream_fputs(start, fp);
111
line_len += word_len;
113
vstream_fputs("\n", fp);