Skip to content

Commit

Permalink
visio: Handle '\0' and '\xFF'.
Browse files Browse the repository at this point in the history
- maple/visio.c:
   - `ochar()`: Handle `'\xFF'` by sending `IAC` `IAC` instead.
   - `iac_count()`: Add comments about `IAC` `IAC` represents `'\xFF'`.
- maple/bbslua.c: `bl_k2s()`: Handle `'\0'`.
- maple/pfterm.c:
   - Add configuration macro `PFTERM_SUPPORT_IAC`
   - macro `FTDBCS_ISBADLEAD()`: Accept `'\xFF'` if `PFTERM_SUPPORT_IAC` is defined
   - `outc()`: Do not ignore `'\xFF'` if `PFTERM_SUPPORT_IAC` is defined.
  • Loading branch information
IepIweidieng committed Feb 13, 2020
1 parent 44e454e commit 60b6353
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion maple/bbslua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ bl_k2s(lua_State* L, int v)
#endif

#if IS_NORMAL_KEY(-1) /* Negative key values are ignored */
if (v <= 0)
if (v < 0)
lua_pushnil(L);
else
#endif
Expand Down
13 changes: 11 additions & 2 deletions maple/pfterm.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#define USE_PFTERM
#undef PFTERM_HAVE_VKEY
#define PFTERM_EXPOSED_VISIO_VI
#define PFTERM_SUPPORT_IAC /* `ochar()` handles `'\xFF'` correctly */
#endif //M3_USE_PFTERM

#ifndef PFTERM_HAVE_VKEY
Expand Down Expand Up @@ -374,9 +375,13 @@ static FlatTerm ft;
#define FTDBCS_ISLEAD(x) (((unsigned char)(x))>=(0x80))
#define FTDBCS_ISTAIL(x) (((unsigned char)(x))>=(0x40))

// - 0xFF is used as telnet IAC, don't use it!
#ifdef PFTERM_SUPPORT_IAC
// - 0x80 is invalid for Big5.
#define FTDBCS_ISBADLEAD(x) (((unsigned char)(x)) == 0x80)
#else
// - 0xFF is used as telnet IAC, don't use it!
#define FTDBCS_ISBADLEAD(x) ((((unsigned char)(x)) == 0x80) || (((unsigned char)(x)) == 0xFF))
#endif

// even faster:
// #define FTDBCS_ISLEAD(x) (((unsigned char)(x)) & 0x80)
Expand Down Expand Up @@ -1327,8 +1332,12 @@ outstr(const char *str)
void
outc(unsigned char c)
{
#ifndef PFTERM_SUPPORT_IAC
// 0xFF is invalid for most cases (even DBCS),
if (c == 0xFF || c == 0x00)
if (c == 0xFF)
return;
#endif
if (c == 0x00)
return;

fterm_markdirty();
Expand Down
10 changes: 8 additions & 2 deletions maple/visio.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ output(

size = vo_size;
data = vo_pool;
if (size + len > VO_MAX - 8)
if (size + len >= VO_MAX - 8)
{
telnet_flush(data, size);
size = len;
Expand Down Expand Up @@ -129,12 +129,16 @@ ochar(

data = vo_pool;
size = vo_size;
if (size > VO_MAX - 2)
if (size >= VO_MAX - 2)
{
telnet_flush(data, size);
size = 0;
}
data[size++] = ch;
if (ch == IAC) /* `'\xff'` => `IAC` `IAC` */
{
data[size++] = ch;
}
vo_size = size;
}

Expand Down Expand Up @@ -1586,6 +1590,8 @@ iac_count(
}
}
}
case IAC: /* `IAC` `IAC` => `'\xff'` */
default:;
}
return 1;
}
Expand Down

0 comments on commit 60b6353

Please sign in to comment.