summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/binary.n9
-rw-r--r--generic/tclBinary.c19
-rw-r--r--tests/binary.test17
3 files changed, 25 insertions, 20 deletions
diff --git a/doc/binary.n b/doc/binary.n
index b301f4d..0cdf465 100644
--- a/doc/binary.n
+++ b/doc/binary.n
@@ -64,7 +64,7 @@ Indicates that the output should be split into lines of no more than
.
Indicates that, when lines are split because of the \fB\-maxlen\fR option,
\fIcharacter\fR should be used to separate lines. By default, this is a
-newline character,
+newline character.
.QW \en .
.PP
During decoding, the following options are supported:
@@ -102,6 +102,13 @@ During encoding, the following options are supported:
Indicates that the output should be split into lines of no more than
\fIlength\fR characters. By default, lines are split every 61 characters, and
this must be in the range 3 to 85 due to limitations in the encoding.
+.TP
+\fB\-wrapchar \fIcharacter\fR
+.
+Indicates that, when lines are split because of the \fB\-maxlen\fR option,
+\fIcharacter\fR should be used to separate lines. By default, this is a
+newline character.
+.QW \en .
.PP
During decoding, the following options are supported:
.TP
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index c0dd926..2053319 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -2584,13 +2584,15 @@ BinaryEncodeUu(
{
Tcl_Obj *resultObj;
unsigned char *data, *start, *cursor;
- int offset, count, rawLength, n, i, bits, index;
+ int offset, count, rawLength, n, i, j, bits, index;
int lineLength = 61;
- enum {OPT_MAXLEN};
- static const char *const optStrings[] = { "-maxlen", NULL };
+ const char *wrapchar = "\n";
+ int wrapcharlen = 1;
+ enum {OPT_MAXLEN, OPT_WRAPCHAR };
+ static const char *const optStrings[] = { "-maxlen", "-wrapchar", NULL };
if (objc < 2 || objc%2 != 0) {
- Tcl_WrongNumArgs(interp, 1, objv, "?-maxlen len? data");
+ Tcl_WrongNumArgs(interp, 1, objv, "?-maxlen len? ?-wrapchar char? data");
return TCL_ERROR;
}
for (i = 1; i < objc-1; i += 2) {
@@ -2610,6 +2612,9 @@ BinaryEncodeUu(
return TCL_ERROR;
}
break;
+ case OPT_WRAPCHAR:
+ wrapchar = Tcl_GetStringFromObj(objv[i+1], &wrapcharlen);
+ break;
}
}
@@ -2623,7 +2628,7 @@ BinaryEncodeUu(
data = Tcl_GetByteArrayFromObj(objv[objc-1], &count);
rawLength = (lineLength - 1) * 3 / 4;
start = cursor = Tcl_SetByteArrayLength(resultObj,
- (lineLength + 1) * ((count + (rawLength - 1)) / rawLength));
+ (lineLength + wrapcharlen) * ((count + (rawLength - 1)) / rawLength));
n = bits = 0;
/*
@@ -2652,7 +2657,9 @@ BinaryEncodeUu(
*cursor++ = UueDigits[(n >> (bits + 2)) & 0x3f];
bits = 0;
}
- *cursor++ = '\n';
+ for (j=0; j<wrapcharlen; ++j) {
+ *cursor++ = wrapchar[j];
+ }
}
/*
diff --git a/tests/binary.test b/tests/binary.test
index 607a070..40b1315 100644
--- a/tests/binary.test
+++ b/tests/binary.test
@@ -2733,23 +2733,14 @@ test binary-74.9 {binary encode uuencode} -body {
} -result {$``````
}
test binary-74.10 {binary encode uuencode} -returnCodes error -body {
- binary encode uuencode -maxlen 30 -wrapchar | abcabcabc
-} -result {bad option "-wrapchar": must be -maxlen}
+ binary encode uuencode -foo 30 abcabcabc
+} -result {bad option "-foo": must be -maxlen or -wrapchar}
test binary-74.11 {binary encode uuencode} -returnCodes error -body {
binary encode uuencode -maxlen 1 abcabcabc
} -result {line length out of range}
test binary-74.12 {binary encode uuencode} -body {
- binary encode uuencode -maxlen 3 abcabcabc
-} -result {!80
-!8@
-!8P
-!80
-!8@
-!8P
-!80
-!8@
-!8P
-}
+ binary encode uuencode -maxlen 3 -wrapchar | abcabcabc
+} -result {!80|!8@|!8P|!80|!8@|!8P|!80|!8@|!8P|}
test binary-75.1 {binary decode uuencode} -body {
binary decode uuencode