mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
instant: encode 8bit chars to keep Tcl happy
This commit is contained in:
parent
7712950fb7
commit
23c4c0667d
1 changed files with 49 additions and 14 deletions
|
@ -374,7 +374,7 @@ static int DefaultOutputString(ClientData clientData,
|
||||||
|
|
||||||
/* leave room for worst case expansion plus quotes plus null */
|
/* leave room for worst case expansion plus quotes plus null */
|
||||||
pArgv = argv[1];
|
pArgv = argv[1];
|
||||||
stringLength = (2 * strlen(pArgv)) + 3;
|
stringLength = (3 * strlen(pArgv)) + 3;
|
||||||
|
|
||||||
string = Tcl_Alloc(stringLength);
|
string = Tcl_Alloc(stringLength);
|
||||||
memset(string, 0, stringLength);
|
memset(string, 0, stringLength);
|
||||||
|
@ -385,24 +385,59 @@ static int DefaultOutputString(ClientData clientData,
|
||||||
* any characters that will throw Tcl for a loop */
|
* any characters that will throw Tcl for a loop */
|
||||||
*pString++ = '"';
|
*pString++ = '"';
|
||||||
while (*pArgv) {
|
while (*pArgv) {
|
||||||
switch (*pArgv) {
|
if (*pArgv & 0x80)
|
||||||
case '{':
|
{
|
||||||
case '}':
|
/* 8-bit data - need to encode since modern Tcl expects
|
||||||
case '"':
|
* any "binary" (8-bit) data in strings to be proper UTF-8
|
||||||
case '\'':
|
* encoded. We aren't doing that (yet), so convert any
|
||||||
case '[':
|
* detected 8b characters into a \xNN format.
|
||||||
case ']':
|
*
|
||||||
case '$':
|
* This code should be unnecessary when we switch to UTF8.
|
||||||
case '\\':
|
*/
|
||||||
*pString++ = '\\';
|
char fmt[16];
|
||||||
}
|
snprintf(fmt, 16, "%02x", (int)*pArgv & 0xff);
|
||||||
*pString++ = *pArgv++;
|
#if 0
|
||||||
|
fprintf(stderr, "JET: converted 0x%02x to '%s'\n",
|
||||||
|
*pArgv, fmt);
|
||||||
|
#endif
|
||||||
|
/* copy the 4 bytes into the string */
|
||||||
|
*pString++ = '\\';
|
||||||
|
*pString++ = 'x';
|
||||||
|
*pString++ = fmt[0];
|
||||||
|
*pString++ = fmt[1];
|
||||||
|
pArgv++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (*pArgv) {
|
||||||
|
case '{':
|
||||||
|
case '}':
|
||||||
|
case '"':
|
||||||
|
case '\'':
|
||||||
|
case '[':
|
||||||
|
case ']':
|
||||||
|
case '$':
|
||||||
|
case '\\':
|
||||||
|
*pString++ = '\\';
|
||||||
|
}
|
||||||
|
*pString++ = *pArgv++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*pString++ = '"';
|
*pString++ = '"';
|
||||||
*pString++ = 0;
|
*pString++ = 0;
|
||||||
|
|
||||||
/* put the string to the output */
|
/* put the string to the output */
|
||||||
retCode = Tcl_VarEval(interpreter, "puts -nonewline ", string, 0);
|
retCode = Tcl_VarEval(interpreter, "puts -nonewline ", string,
|
||||||
|
(char *)NULL);
|
||||||
|
#if 0
|
||||||
|
/* JET*/
|
||||||
|
if (retCode != TCL_OK)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "JET: retCode = %d, LEN = %d STRING = '%s'\n",
|
||||||
|
retCode, strlen(string), string);
|
||||||
|
fprintf(stderr, "\tstring[1] = 0x%02x\n", string[1]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Tcl_Free(string);
|
Tcl_Free(string);
|
||||||
|
|
||||||
/* and ripple up any error code we got from the "puts" */
|
/* and ripple up any error code we got from the "puts" */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue