summaryrefslogtreecommitdiffstats
path: root/mbbsd/io.c
diff options
context:
space:
mode:
authorscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-12-24 14:58:25 +0800
committerscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-12-24 14:58:25 +0800
commit36b8776e3788b80fa07f4e43288bc60ab1d69b13 (patch)
tree1f4ec895fe0f0f6147a0dca582a2def8b96b8b75 /mbbsd/io.c
parenta2bd0bb8576c56e3221ecfd600700821076cf914 (diff)
downloadpttbbs-36b8776e3788b80fa07f4e43288bc60ab1d69b13.tar
pttbbs-36b8776e3788b80fa07f4e43288bc60ab1d69b13.tar.gz
pttbbs-36b8776e3788b80fa07f4e43288bc60ab1d69b13.tar.bz2
pttbbs-36b8776e3788b80fa07f4e43288bc60ab1d69b13.tar.lz
pttbbs-36b8776e3788b80fa07f4e43288bc60ab1d69b13.tar.xz
pttbbs-36b8776e3788b80fa07f4e43288bc60ab1d69b13.tar.zst
pttbbs-36b8776e3788b80fa07f4e43288bc60ab1d69b13.zip
Rewrite strip_ansi() (also move from vote.c to io.c).
Using STRIP_ALL instead of 0 when calling strip_ansi. Fix some buffer overflow problem. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1428 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/io.c')
-rw-r--r--mbbsd/io.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/mbbsd/io.c b/mbbsd/io.c
index f31d5f30..1d1677a1 100644
--- a/mbbsd/io.c
+++ b/mbbsd/io.c
@@ -387,6 +387,67 @@ igetch()
}
int
+strip_ansi(char *buf, char *str, int mode)
+{
+ register int count = 0;
+ static char EscapeFlag[] = {
+ /* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /* 10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0,
+ /* 20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /* 30 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, /* 0~9 ;= */
+ /* 40 */ 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, /* ABCDHIJK */
+ /* 50 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, /* [ */
+ /* 60 */ 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 2, 2, 0, 0, /* fhlm */
+ /* 70 */ 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* su */
+ /* 80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /* 90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /* A0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /* B0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /* C0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /* D0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /* E0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /* F0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ };
+#define isEscapeParam(X) (EscapeFlag[(X)] & 1)
+#define isEscapeCommand(X) (EscapeFlag[(X)] & 2)
+
+ for(; *str; ++str)
+ if( *str != '\033' ){
+ if( buf )
+ *buf++ = *str;
+ ++count;
+ }else{
+ register char* p = str;
+ while(isEscapeParam(*++p));
+ if( (mode == NO_RELOAD && isEscapeCommand(*p)) ||
+ (mode == ONLY_COLOR && *p == 'm' )){
+ register int len = p - str + 1;
+ if( buf ){
+ strncpy(buf, str, len);
+ buf += len;
+ }
+ count += len;
+ }
+ str = p;
+ }
+ if( buf )
+ *buf = 0;
+ return count;
+
+
+ /* Rewritten by scw.
+ * Moved from vote.c (here is a better place for this function).
+ * register int ansi, count = 0;
+ * for (ansi = 0; *str ; str++) { if (*str == 27) { if (mode) { if (buf)
+ * *buf++ = *str; count++; } ansi = 1; } else if (ansi && strchr(
+ * "[;1234567890mfHABCDnsuJKc=n", *str)) { if ((mode == NO_RELOAD &&
+ * !strchr("c=n", *str)) || (mode == ONLY_COLOR && strchr("[;1234567890m",
+ * *str))) { if (buf) *buf++ = *str; count++; } if (strchr("mHn ", *str))
+ * ansi = 0; } else { ansi = 0; if (buf) *buf++ = *str; count++; } } if
+ * (buf) *buf = '\0'; return count; */
+}
+
+int
oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo)
{
register int ch, i;
@@ -401,7 +462,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo)
move(line, col);
clrtoeol();
outs(prompt);
- x += strip_ansi(NULL, prompt, 0);
+ x += strip_ansi(NULL, prompt, STRIP_ALL);
}
if (!echo) {