BBS水木清华站∶精华区

发信人:  yes.bbs@firebird.cs.ccu.edu.tw (□),                 看板  linux 
标  题:  使 NcFTP 2.3.0 可以看彩色与中文 
发信站:  中正大学四百年来第一站 (Sun Jan 28 23:01:02 1996) 
转信站: 
 
如何让 NcFTP 2.3.0 在 Visual Mode 下也可以看到含彩色控制码与中文的画面 
 
*此修改版本使用 NcFTP 2.3.0 与 ncurses 1.9.8a。作业系统 Linux, kernel 
 版本 1.2.13。 
 
需要修改的档案: 
NcFTP: Util.c Win.c 
ncurses: lib_addch.c lib_addstr.c 
 
由於 ncurses 本身的 waddstr 等 function 会过滤控制字元,使得即使我们修 
改 NcFTP 的原始程式使其不过滤控制码,到了 ncurses 的层次仍会被滤掉。底 
下所说明的修改法便是同时修改这两套软体的原始程式,使我们在使用 NcFTP时 
即使在 visual mode 下也可以看到正常的彩色字。 
 
修改 NcFTP 的部份只要是使其不过滤中文字与 ESC 这个控制字元,以及在输出 
时改成呼叫我们增加的 esc_waddnstr() 这个 function。 
 
修改 ncurses 的部份主要是增加了 esc_waddnstr() 这个 function,以及其所 
使用的两个 function,使其不过滤 ESC。 
 
修改之处如下: 
Util.c:(改 MakeStringPrintable()) 
while ((i < siz) && (*src != '\0')) { 
        c = *src++; 
        if (isprint(c) || (c == '\n') || (c == '\t') 
            || (c & 0x80) || (c == 0x1b)) {  /* 不过滤中文与 ESC */ 
                *dst++ = c; 
                ++i; 
        } else if (iscntrl(c) && (c != 0x7f)) { 
 
Win.c:(改 PrintToListWindow()) 
        /* Weird things happened if I did wprintw(gListWin, "%s", startp). */ 
        /* 原本呼叫 waddstr() */ 
        esc_waddnstr(gListWin, startp, -1); 
 
        /* May need to gCurRow++ if line wraps around other side... */ 
        if (haveNL) { 
                gCurRow++; 
 
lib_addch.c:(增加以下的 function) 
/* 取消对 ESC 的过滤 */ 
/* 加在 waddch_nosync() 之後,#undef DO_NEWLINE 之前 */ 
static inline 
int esc_waddch_nosync(WINDOW *win, const chtype c) 
/* the workhorse function -- add a character to the given window */ 

register chtype ch = c; 
register int    x, y; 
int             newx; 
 
        x = win->_curx; 
        y = win->_cury; 
 
        CHECK_POSITION(win, x, y); 
 
        if (ch & A_ALTCHARSET) 
                goto noctrl; 
 
        switch (ch&A_CHARTEXT) { 
        case '\t': 
                if (win->_flags & _NEED_WRAP) { 
                        x = 0; 
                        newx = min(TABSIZE, win->_maxx+1); 
                } else 
                        newx = min(x + (TABSIZE-(x%TABSIZE)), win->_maxx+1); 
                while (win->_curx < newx) { 
                        if (waddch_literal(win, ' ' | (ch&A_ATTRIBUTES)) == ERR) 
 
                                return(ERR); 
                } 
                return(OK); 
        case '\n': 
                wclrtoeol(win); 
                DO_NEWLINE 
                break; 
        case '\r': 
                x = 0; 
                win->_flags &= ~_NEED_WRAP; 
                break; 
        case '\b': 
                if (win->_flags & _NEED_WRAP) 
                        win->_flags &= ~_NEED_WRAP; 
                else if (--x < 0) 
                        x = 0; 
                break; 
        default: 
                if (is7bits(ch & A_CHARTEXT) && iscntrl(ch & A_CHARTEXT) 
                    && ((ch & A_CHARTEXT) != 0x1b))   /* 不过滤 ESC */ 
                        return(waddstr(win, unctrl((unsigned char)ch))); 
 
                /* FALL THROUGH */ 
        noctrl: 
                waddch_literal(win, ch); 
                return(OK); 
        } 
 
        win->_curx = x; 
        win->_cury = y; 
 
        return(OK); 

 
/* 加在档案最後即可 */ 
int _esc_nc_waddch_nosync(WINDOW *win, const chtype c) 
/* export copy of waddch_nosync() so the string-put functions can use it */ 

    return(esc_waddch_nosync(win, c)); 

 
lib_addstr.c:(增加以下的 function) 
/* 加在档案最後即可 */ 
int 
esc_waddnstr(WINDOW *win, const char *astr, int n) 

unsigned char *str = (unsigned char *)astr; 
int code = ERR; 
 
        T(("esc_waddnstr(%p,\"%s\",%d) called %s", win, _nc_visbuf(astr), n, _tr 
aceattr(win->_attrs))); 
 
        if (str != NULL) { 
 
                TR(TRACE_VIRTPUT, ("str is not null")); 
                code = OK; 
                if (n < 0) 
                        n = strlen(astr); 
 
                while((n-- > 0) && (*str != '\0')) { 
                        TR(TRACE_VIRTPUT, ("*str = %x", *str)); 
                        if (_esc_nc_waddch_nosync(win, (unsigned char)*str++) == 
 ERR) { 
                                code = ERR; 
                                break; 
                        } 
                } 
        } 
        _nc_synchook(win); 
        TR(TRACE_VIRTPUT, ("esc_waddnstr returns %d", code)); 
        return code; 

 
 

BBS水木清华站∶精华区