Commit 5ed8b1e9 authored by Niels Möller's avatar Niels Möller

New (kludge) function werror_safe_utf8().

Rev: src/werror.c:1.6
Rev: src/werror.h:1.5
parent ff786f72
......@@ -48,35 +48,38 @@ void verbose(char *format, ...)
}
}
/* Escape non-printable characters. */
void werror_washed(UINT32 length, UINT8 *msg)
void wash_char(UINT8 c)
{
int i;
for(i = 0; i<length; i++)
switch(c)
{
switch(msg[i])
case '\\':
fputs("\\\\", stderr);
break;
case '\r':
/* Ignore */
break;
default:
if (!isprint(c))
{
case '\\':
fputs("\\\\", stderr);
break;
case '\r':
/* Ignore */
break;
default:
if (!isprint(msg[i]))
{
fprintf(stderr, "\\x%02x", msg[i]);
break;
}
/* Fall through */
case '\n':
putc(msg[i], stderr);
fprintf(stderr, "\\x%02x", c);
break;
}
/* Fall through */
case '\n':
putc(c, stderr);
break;
}
}
/* Escape non-printable characters. */
void werror_washed(UINT32 length, UINT8 *msg)
{
int i;
for(i = 0; i<length; i++)
wash_char(msg[i]);
}
/* For outputting data recieved from the other end */
void werror_safe(UINT32 length, UINT8 *msg)
{
......@@ -96,6 +99,42 @@ void verbose_safe(UINT32 length, UINT8 *msg)
werror_washed(length, msg);
}
void werror_safe_utf8(UINT32 length, UINT8 *msg)
{
/* FIXME: This function assumes that the system charset is
* iso-8859-1, aka latin1. */
if (!quiet_flag)
{
int i=0;
while(i<length)
{
UINT8 c = msg[i++];
if (!(c & 0x80))
wash_char(c);
else
{
if ( (c & 0xd0) != 0xc0)
{
/* Unicode value >= 0x800 */
fputs("\\?", stderr);
while ( (i < length) & (msg[i] & 0x80) )
i++;
}
else
{
if (i == length)
/* String ends with a partial character! */
fputs("\\!", stderr);
else
wash_char( ((c & 3) << 6) || (msg[i++] & 0x3f) );
}
}
}
}
}
void fatal(char *format, ...)
{
va_list args;
......
......@@ -21,6 +21,8 @@ void werror_safe(UINT32 length, UINT8 *msg);
void debug_safe(UINT32 length, UINT8 *msg);
void verbose_safe(UINT32 length, UINT8 *msg);
void werror_safe_utf8(UINT32 length, UINT8 *msg);
void fatal(char *format, ...) PRINTF_STYLE(1,2) NORETURN;
#endif /* LSH_ERROR_H_INCLUDED */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment