diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-08-28 16:08:07 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-09-08 16:09:55 +0300 |
commit | 5f0b1ed3c5d5276df98b20cb4bb020915b6a064c (patch) | |
tree | c6dde528c87f1fd0cb034445bff41ede3200fded /examples | |
parent | 8f8e01b920d0601df5e60cd8060eba5909a10178 (diff) | |
download | mailutils-5f0b1ed3c5d5276df98b20cb4bb020915b6a064c.tar.gz mailutils-5f0b1ed3c5d5276df98b20cb4bb020915b6a064c.tar.bz2 |
Fix base64 test.
* examples/base64.c (c_copy): Handle printable mode (-p).
(reset_line_length): New function.
(main): New option -lN sets the maximum length for output
lines to N (0 means unlimited).
* mailbox/testsuite/mailbox/base64.exp: Use -l0 in the
Decode test.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/base64.c | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/examples/base64.c b/examples/base64.c index 3785a6a0d..cc0a7e8b3 100644 --- a/examples/base64.c +++ b/examples/base64.c @@ -35,7 +35,28 @@ int printable = 0; static void c_copy (mu_stream_t out, mu_stream_t in) { - MU_ASSERT (mu_stream_copy (out, in, 0)); + if (printable) + { + char c; + size_t size; + + while (mu_stream_read (in, &c, 1, &size) == 0 && size > 0) + { + int rc; + + if (printable && !ISPRINT (c)) + { + char outbuf[24]; + sprintf (outbuf, "\\%03o", (unsigned char) c); + rc = mu_stream_write (out, outbuf, strlen (outbuf), NULL); + } + else + rc = mu_stream_write (out, &c, 1, NULL); + } + } + else + MU_ASSERT (mu_stream_copy (out, in, 0)); + mu_stream_write (out, "\n", 1, NULL); mu_stream_close (out); mu_stream_close (in); if (verbose) @@ -44,6 +65,23 @@ c_copy (mu_stream_t out, mu_stream_t in) (unsigned long) mu_stream_bytes_out (out)); } +/* Set the maximum line length for the filter NAME to LENGTH. + FIXME: This is a kludge. Perhaps API should provide a function + for that. */ +static void +reset_line_length (const char *name, size_t length) +{ + mu_list_t list; + int status; + mu_filter_record_t frec; + + mu_filter_get_list (&list); + status = mu_list_locate (list, (void*)name, (void**)&frec); + if (status == 0) + frec->max_line_length = length; + /* don't bail out, leave that to mu_filter_create */ +} + int main (int argc, char * argv []) { @@ -54,8 +92,10 @@ main (int argc, char * argv []) char *input = NULL, *output = NULL; char *encoding = "base64"; mu_off_t shift = 0; + size_t line_length; + int line_length_option = 0; - while ((c = getopt (argc, argv, "deE:hi:o:ps:vw")) != EOF) + while ((c = getopt (argc, argv, "deE:hi:l:o:ps:vw")) != EOF) switch (c) { case 'i': @@ -78,8 +118,13 @@ main (int argc, char * argv []) mode = MU_FILTER_ENCODE; break; + case 'l': + line_length = strtoul (optarg, NULL, 10); + line_length_option = 1; + break; + case 'p': - printable = 1; /* FIXME: Not implemented */ + printable = 1; break; case 's': @@ -115,6 +160,9 @@ main (int argc, char * argv []) MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0)); MU_ASSERT (mu_stream_open (out)); + if (line_length_option) + reset_line_length (encoding, line_length); + if (flags == MU_STREAM_READ) { MU_ASSERT (mu_filter_create (&flt, in, encoding, mode, |