[PPL-devel] [GIT] ppl/ppl(formatted_output): Added repeated char for left and right margin.
Abramo Bagnara
abramo.bagnara at gmail.com
Mon Mar 23 22:17:25 CET 2009
Module: ppl/ppl
Branch: formatted_output
Commit: bace9caed4ba2aba49450798390a526501db70bd
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=bace9caed4ba2aba49450798390a526501db70bd
Author: Abramo Bagnara <abramo.bagnara at gmail.com>
Date: Mon Mar 23 22:16:56 2009 +0100
Added repeated char for left and right margin.
---
interfaces/C/tests/print_to_buffer.c | 55 +++++++++++++++++++++-------------
src/c_stream.cc | 24 +++++++-------
src/c_stream.h | 8 +++++
src/c_streambuf_format.cc | 5 +++
4 files changed, 59 insertions(+), 33 deletions(-)
diff --git a/interfaces/C/tests/print_to_buffer.c b/interfaces/C/tests/print_to_buffer.c
index 5de5698..87a81e4 100644
--- a/interfaces/C/tests/print_to_buffer.c
+++ b/interfaces/C/tests/print_to_buffer.c
@@ -31,9 +31,6 @@ print_ppl_##Name##_t_to_buffer(ppl_const_##Name##_t p, \
unsigned indent_depth, \
unsigned pfll, \
unsigned pll) { \
- char in[indent_depth + 1]; \
- memset(in, ' ', indent_depth); \
- in[indent_depth] = '\0'; \
struct ppl_io_format_settings settings = { \
0, /* tr_in */ \
0, /* tr_out */ \
@@ -46,26 +43,42 @@ print_ppl_##Name##_t_to_buffer(ppl_const_##Name##_t p, \
0, /* top */ \
0, /* bottom */ \
{ \
- /* length, left, right, alignment, fill_char */ \
- { pfll, "", "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* FIRST */ \
- { pfll, "", "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* FIRSTLAST */ \
- { pll, in, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* NEXT */ \
- { pll, in, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* LAST */ \
- { 0, "", "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* CHOPPED_FIRST */ \
- { 0, "", "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* CHOPPED_NEXT */ \
- { pfll, "", "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* LONGER_FIRST */ \
- { pfll, "", "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* LONGER_FIRSTLAST */ \
- { pll, in, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* LONGER_NEXT */ \
- { pll, in, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* LONGER_LAST */ \
- { pfll, "", "", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* UNTERMINATED_FIRST */ \
- { pll, in, "", PPL_IO_FORMAT_ALIGN_LEFT, 0 } /* UNTERMINATED_NEXT */ \
- } \
+ /* length, left, left_n, left_c, right_n, right_c right, alignment, fill_char */ \
+ { 0, 0, ' ', 0, 0, ' ', "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* FIRST */ \
+ { 0, 0, ' ', 0, 0, ' ', "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* FIRSTLAST */ \
+ { 0, 0, ' ', 0, 0, ' ', "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* NEXT */ \
+ { 0, 0, ' ', 0, 0, ' ', "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* LAST */ \
+ { 0, 0, ' ', 0, 0, ' ', "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* CHOPPED_FIRST */ \
+ { 0, 0, ' ', 0, 0, ' ', "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* CHOPPED_NEXT */ \
+ { 0, 0, ' ', 0, 0, ' ', "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* LONGER_FIRST */ \
+ { 0, 0, ' ', 0, 0, ' ', "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* LONGER_FIRSTLAST */ \
+ { 0, 0, ' ', 0, 0, ' ', "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* LONGER_NEXT */ \
+ { 0, 0, ' ', 0, 0, ' ', "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* LONGER_LAST */ \
+ { 0, 0, ' ', 0, 0, ' ', "", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, /* UNTERMINATED_FIRST */ \
+ { 0, 0, ' ', 0, 0, ' ', "", PPL_IO_FORMAT_ALIGN_LEFT, 0 } /* UNTERMINATED_NEXT */ \
+ } \
}; \
- struct ppl_io_ostream* target = ppl_io_ostream_buffer_new(); \
- struct ppl_io_ostream* stream = ppl_io_ostream_format_new(target, &settings); \
- ppl_io_write_##NAME(stream, object); \
- ppl_io_ostream_delete(stream); \
+ struct ppl_io_ostream *target, *stream; \
char *buf; \
+ settings.lines[PPL_IO_FORMAT_LINE_FIRST].length = pfll; \
+ settings.lines[PPL_IO_FORMAT_LINE_FIRSTLAST].length = pfll; \
+ settings.lines[PPL_IO_FORMAT_LINE_LONGER_FIRST].length = pfll; \
+ settings.lines[PPL_IO_FORMAT_LINE_LONGER_FIRSTLAST].length = pfll; \
+ settings.lines[PPL_IO_FORMAT_LINE_UNTERMINATED_FIRST].length = pfll; \
+ settings.lines[PPL_IO_FORMAT_LINE_NEXT].length = pll; \
+ settings.lines[PPL_IO_FORMAT_LINE_LAST].length = pll; \
+ settings.lines[PPL_IO_FORMAT_LINE_LONGER_NEXT].length = pll; \
+ settings.lines[PPL_IO_FORMAT_LINE_LONGER_LAST].length = pll; \
+ settings.lines[PPL_IO_FORMAT_LINE_UNTERMINATED_NEXT].length = pll; \
+ settings.lines[PPL_IO_FORMAT_LINE_NEXT].left_n = indent_depth; \
+ settings.lines[PPL_IO_FORMAT_LINE_LAST].left_n = indent_depth; \
+ settings.lines[PPL_IO_FORMAT_LINE_LONGER_NEXT].left_n = indent_depth; \
+ settings.lines[PPL_IO_FORMAT_LINE_LONGER_LAST].left_n = indent_depth; \
+ settings.lines[PPL_IO_FORMAT_LINE_UNTERMINATED_NEXT].left_n = indent_depth; \
+ target = ppl_io_ostream_buffer_new(); \
+ stream = ppl_io_ostream_format_new(target, &settings); \
+ ppl_io_write_##Name(stream, p); \
+ ppl_io_ostream_delete(stream); \
ppl_io_ostream_buffer_get(target, &buf); \
ppl_io_ostream_delete(target); \
return buf; \
diff --git a/src/c_stream.cc b/src/c_stream.cc
index 6b3b20b..11ea69e 100644
--- a/src/c_stream.cc
+++ b/src/c_stream.cc
@@ -34,18 +34,18 @@ ppl_io_format_settings ppl_io_format_default_settings = {
0, // bottom
{
// length, left, right, alignment, fill_char
- { 80, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // FIRST
- { 80, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // FIRSTLAST
- { 80, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // NEXT
- { 80, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // LAST
- { 80, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // CHOPPED_FIRST
- { 80, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // CHOPPED_NEXT
- { 80, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // LONGER_FIRST
- { 80, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // LONGER_FIRSTLAST
- { 80, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // LONGER_NEXT
- { 80, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // LONGER_LAST
- { 80, 0, 0, PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // UNTERMINATED_FIRST
- { 80, 0, 0, PPL_IO_FORMAT_ALIGN_LEFT, 0 } // UNTERMINATED_NEXT
+ { 80, 0, 0, 0, 0, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // FIRST
+ { 80, 0, 0, 0, 0, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // FIRSTLAST
+ { 80, 0, 0, 0, 0, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // NEXT
+ { 80, 0, 0, 0, 0, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // LAST
+ { 80, 0, 0, 0, 0, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // CHOPPED_FIRST
+ { 80, 0, 0, 0, 0, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // CHOPPED_NEXT
+ { 80, 0, 0, 0, 0, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // LONGER_FIRST
+ { 80, 0, 0, 0, 0, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // LONGER_FIRSTLAST
+ { 80, 0, 0, 0, 0, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // LONGER_NEXT
+ { 80, 0, 0, 0, 0, 0, "\n", PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // LONGER_LAST
+ { 80, 0, 0, 0, 0, 0, 0, PPL_IO_FORMAT_ALIGN_LEFT, 0 }, // UNTERMINATED_FIRST
+ { 80, 0, 0, 0, 0, 0, 0, PPL_IO_FORMAT_ALIGN_LEFT, 0 } // UNTERMINATED_NEXT
}
};
diff --git a/src/c_stream.h b/src/c_stream.h
index e8857ee..3c8454d 100644
--- a/src/c_stream.h
+++ b/src/c_stream.h
@@ -68,6 +68,14 @@ struct ppl_io_format_settings {
unsigned int length;
/* Left margin string */
const char *left;
+ /* Left margin repeated char count */
+ unsigned int left_n;
+ /* Left margin repeated char */
+ char left_c;
+ /* Right margin repeated char count */
+ unsigned int right_n;
+ /* Right margin repeated char */
+ unsigned int right_c;
/* Right margin string */
const char *right;
/* 0 left, 8 center, 16 right */
diff --git a/src/c_streambuf_format.cc b/src/c_streambuf_format.cc
index 368a494..5d94ac6 100644
--- a/src/c_streambuf_format.cc
+++ b/src/c_streambuf_format.cc
@@ -145,6 +145,9 @@ bool c_streambuf_format::output_line(const char *s, unsigned int n, ppl_io_forma
}
if (settings->lines[type].left)
stream << settings->lines[type].left;
+ unsigned int i;
+ for (i = 0; i < settings->lines[type].left_n; ++i)
+ stream.put(settings->lines[type].left_c);
if (settings->lines[type].fill_char && n < settings->lines[type].length) {
unsigned int left = 0;
unsigned int right = 0;
@@ -160,6 +163,8 @@ bool c_streambuf_format::output_line(const char *s, unsigned int n, ppl_io_forma
}
else
stream.write(s, n);
+ for (i = 0; i < settings->lines[type].right_n; ++i)
+ stream.put(settings->lines[type].right_c);
if (settings->lines[type].right)
stream << settings->lines[type].right;
switch (type) {
More information about the PPL-devel
mailing list