summaryrefslogtreecommitdiffstats
path: root/mbbsd/io.c
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-01 18:01:51 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-01 18:01:51 +0800
commit4c256182f70ad244e0ec40af45c0c0857abb0a01 (patch)
treef2663fd39c9234b611a9d3fb8f01fcc3cecaf008 /mbbsd/io.c
parentd2e9ddb320e18206dcb54e7d8476fdc73e489fa9 (diff)
downloadpttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar
pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar.gz
pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar.bz2
pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar.lz
pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar.xz
pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar.zst
pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.zip
- add move_ansi() to support moving to lines with prior ANSI code.
- general improvement git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3602 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/io.c')
-rw-r--r--mbbsd/io.c81
1 files changed, 61 insertions, 20 deletions
diff --git a/mbbsd/io.c b/mbbsd/io.c
index a6d1b2df..30c03712 100644
--- a/mbbsd/io.c
+++ b/mbbsd/io.c
@@ -646,30 +646,31 @@ wait_input(float f, int flDoRefresh)
* ONLY_COLOR: ??
* NO_RELOAD: ¤£ strip (?)
*/
+static const 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, 0, 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[(int)(X)] & 1)
+#define isEscapeCommand(X) (EscapeFlag[(int)(X)] & 2)
+
int
strip_ansi(char *buf, const char *str, int mode)
{
register int count = 0;
- static const 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, 0, 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[(int)(X)] & 1)
-#define isEscapeCommand(X) (EscapeFlag[(int)(X)] & 2)
for(; *str; ++str)
if( *str != ESC_CHR ){
@@ -701,6 +702,46 @@ strip_ansi(char *buf, const char *str, int mode)
return count;
}
+int
+strlen_noansi(const char *s)
+{
+ register int count = 0, mode = 0;
+
+ if (!s || !*s)
+ return 0;
+
+ for (; *s; ++s)
+ {
+ // 0 - no ansi, 1 - [, 2 - param+cmd
+ switch (mode)
+ {
+ case 0:
+ if (*s == ESC_CHR)
+ mode = 1;
+ else
+ count ++;
+ break;
+
+ case 1:
+ if (*s == '[')
+ mode = 2;
+ else
+ mode = 0; // unknown command
+ break;
+
+ case 2:
+ if (isEscapeParam(*s))
+ continue;
+ else if (isEscapeCommand(*s))
+ mode = 0;
+ else
+ mode = 0;
+ break;
+ }
+ }
+ return count;
+}
+
void
strip_nonebig5(unsigned char *str, int maxlen)
{