diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2007-12-12 09:42:23 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2007-12-12 09:42:23 +0800 |
commit | 9a12adf6d29cdefc98afe2566a9e5479489f111b (patch) | |
tree | 6e2b911398cb6dcb08b183ab645817e098182968 /mbbsd/io.c | |
parent | 3d16ea67c380607528e7c8df0b2cc5a2f2636b9f (diff) | |
download | pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.gz pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.bz2 pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.lz pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.xz pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.zst pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.zip |
* extract common functions as library.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3673 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/io.c')
-rw-r--r-- | mbbsd/io.c | 136 |
1 files changed, 0 insertions, 136 deletions
@@ -637,142 +637,6 @@ wait_input(float f, int flDoRefresh) return 1; } -/** - * 根據 mode 來 strip 字串 str,並把結果存到 buf - * @param buf - * @param str - * @param mode enum {STRIP_ALL = 0, ONLY_COLOR, NO_RELOAD}; - * STRIP_ALL: 全部吃掉 - * ONLY_COLOR: 吃掉所有跟顏色無關的 (ESC[*m) - * 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; - - for(; *str; ++str) - if( *str != ESC_CHR ){ - if( buf ) - *buf++ = *str; - ++count; - }else{ - const char* p = str + 1; - if( *p != '[' ){ - ++str; - if(*str=='\0') break; - continue; - } - 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(*str=='\0') break; - } - if( buf ) - *buf = 0; - return count; -} - -int -strlen_noansi(const char *s) -{ - // XXX this is almost identical to - // strip_ansi(NULL, s, STRIP_ALL) - 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) -{ - int i; - int len=0; - for(i=0;i<maxlen && str[i];i++) { - if(32<=str[i] && str[i]<128) - str[len++]=str[i]; - else if(str[i]==255) { - if(i+1<maxlen) - if(251<=str[i+1] && str[i+1]<=254) { - i++; - if(i+1<maxlen && str[i+1]) - i++; - } - continue; - } else if(str[i]&0x80) { - if(i+1<maxlen) - if((0x40<=str[i+1] && str[i+1]<=0x7e) || - (0xa1<=str[i+1] && str[i+1]<=0xfe)) { - str[len++]=str[i]; - str[len++]=str[i+1]; - i++; - } - } - } - if(len<maxlen) - str[len]='\0'; -} #ifdef DBCSAWARE |