diff options
author | dgp <dgp@users.sourceforge.net> | 2014-03-11 03:38:55 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2014-03-11 03:38:55 (GMT) |
commit | 507194e18d3ee09110002c002daa35eea2b249fd (patch) | |
tree | 68b0ba7e1239b62a199f35a0035f41ee9d1099a4 /generic/tclIO.c | |
parent | d539d0925f6d60f1334d053247c8f3112e8de938 (diff) | |
download | tcl-507194e18d3ee09110002c002daa35eea2b249fd.zip tcl-507194e18d3ee09110002c002daa35eea2b249fd.tar.gz tcl-507194e18d3ee09110002c002daa35eea2b249fd.tar.bz2 |
Trial rewrite of AUTO input translation.
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r-- | generic/tclIO.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c index 6194637..8d8e30f 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -5680,6 +5680,40 @@ TranslateInputEOL( break; } case TCL_TRANSLATE_AUTO: { +#if 1 + const char *crFound, *src = srcStart; + char *dst = dstStart; + int lesser; + + if ((statePtr->flags & INPUT_SAW_CR) && srcLen) { + if (*src == '\n') { + src++; + srcLen--; + } + ResetFlag(statePtr, INPUT_SAW_CR); + } + lesser = (dstLen < srcLen) ? dstLen : srcLen; + while ((crFound = memchr(src, '\r', lesser))) { + int numBytes = crFound - src; + memmove(dst, src, numBytes); + + dst[numBytes] = '\n'; + dst += numBytes + 1; + dstLen -= numBytes + 1; + src += numBytes + 1; + srcLen -= numBytes + 1; + if (srcLen == 0) { + SetFlag(statePtr, INPUT_SAW_CR); + } else if (*src == '\n') { + src++; + srcLen--; + } + lesser = (dstLen < srcLen) ? dstLen : srcLen; + } + memmove(dst, src, lesser); + srcLen = src + lesser - srcStart; + dstLen = dst + lesser - dstStart; +#else const char *srcEnd = srcStart + srcLen; const char *dstEnd = dstStart + dstLen; const char *src = srcStart; @@ -5706,6 +5740,7 @@ TranslateInputEOL( } srcLen = src - srcStart; dstLen = dst - dstStart; +#endif break; } default: |