⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vc.c

📁 这是一个介绍 linux 编程知识的文章。
💻 C
📖 第 1 页 / 共 2 页
字号:
            lzero (con->flagBuff + addr, con->dispxmax);
            /* needless to latch */        
        }
        
        addr = TextAddress (con, con->x, con->y);
        len = con->dispxmax - con->x;
        // bzero2 (con->textBuff + addr, len);
        // bzero2 (con->attrBuff + addr, len);
        memset (con->textBuff + addr, 0x20, len);
        memset (con->attrBuff + addr, (con->bcol << 4) | con->fcol, len);
        bzero2 (con->flagBuff + addr, len); /* needless to latch */
        break;
    }
}

static void TextClearBand (CONINFO *con, int top, int btm)
{
    int y, addr;

    for (y = top; y <= btm; y ++) {
        addr = TextAddress (con, 0, y);
        // lzero (con->textBuff + addr, con->dispxmax);
        // lzero (con->attrBuff + addr, con->dispxmax);
        memset (con->textBuff + addr, 0x20, con->dispxmax);
        memset (con->attrBuff + addr, 
                (con->bcol << 4) | con->fcol, con->dispxmax);
        lzero (con->flagBuff + addr, con->dispxmax);/* needless to latch */
    }
}

// --------------------------------------------------------------
// TextClearChars - Added by Holly Lee
//    ConInfo * con
//    int row
//    int fromColumn
//    int columns
// --------------------------------------------------------------
void TextClearChars (CONINFO* con, int len)
{
     int addr;
     
     // Must be in one line
     if ( con->x + len > con->dispxmax )
        len = con->dispxmax - con->x;

     addr = TextAddress (con, con->x, con->y);
     memset (con->textBuff + addr, 0x20, len);
     memset (con->attrBuff + addr, (con->bcol << 4) | con->fcol, len);
     bzero2 (con->flagBuff + addr, len);  /* needless to latch */
}

/****************************************************************************
 *                   TextCopy/TextPaste/TextReverse                         *
 ****************************************************************************/
static inline void KanjiAdjust (CONINFO *con, int *x, int *y)
{
    if (IsKanji2 (con, *x, *y))
        --*x;
}

#define COPY_FILE   "/tmp/.vcongui.copy"

void TextCopy (CONINFO *con, int fx, int fy, int tx, int ty)
{
    int fd;
    int from, to, y, swp, xx, x;
    u_char ch, ch2;
    char szTmpFileName [MAX_PATH];

    strcpy (szTmpFileName, COPY_FILE);
    strcat (szTmpFileName, ".");
    strcat (szTmpFileName, getlogin ());

    unlink (szTmpFileName);
    if ((fd = open (szTmpFileName, O_WRONLY|O_CREAT, 0600)) < 0)
        return;

    KanjiAdjust (con, &fx, &fy);
    KanjiAdjust (con, &tx, &ty);
    
    if (fy > ty) {
        swp = fy; fy = ty; ty = swp;
        swp = fx; fx = tx; tx = swp;
    }
    else if (fy == ty && fx > tx) {
        swp = fx; fx = tx; tx = swp;
    }

    for (xx = con->dispxmax - 1, y = fy; y <= ty; y ++) {
    
        if (y == ty)
            xx = tx;
            
        from = TextAddress (con, fx, y);
        
        if (con->flagBuff[from] & CODEIS_2)
            /* 2nd byte of kanji */
            from--;
        to = TextAddress (con, xx, y);
        
        for (x = to; x >= from; x --)
            if (con->textBuff[x] > ' ')
                break;

        to = x;

        for (x = from; x <= to; x ++)
        {
            ch = con->textBuff[x];
            if (!ch)
                ch = ' ';
            if (con->flagBuff[x] & CODEIS_1) {
                x ++;
                ch2 = con->textBuff[x];
                
                switch (con->sysCoding) {
                case CODE_EUC:
                    ch2 |= 0x80;
                    ch |= 0x80;
                    break;
                case CODE_SJIS:
                    jistosjis(ch2, ch);
                    break;
                }
                
                write (fd, &ch, 1);
                write (fd, &ch2, 1);
            }
            else 
                write (fd, &ch, 1);
        }

        if (y < ty) {
            ch = '\n';
            write(fd, &ch, 1);
        }
        
        fx = 0;
    }
    
    close(fd);
}

void TextPaste (CONINFO *con)
{
    u_char ch;
    int    fd;
    char szTmpFileName [MAX_PATH];

    strcpy (szTmpFileName, COPY_FILE);
    strcat (szTmpFileName, ".");
    strcat (szTmpFileName, getlogin ());

    if ((fd = open(szTmpFileName, O_RDONLY)) < 0)
        return;
        
    while (read (fd, &ch, 1) == 1)
        write (con->masterPty, &ch, 1);
    
    close(fd);
}

void TextReverse (CONINFO *con, int* ofx, int* ofy, int* otx, int* oty)
{
    int fx, fy, tx, ty;
    int from, to, y, swp, xx, x;
    u_char fc, bc, fc2, bc2;

    KanjiAdjust (con, ofx, ofy);
    KanjiAdjust (con, otx, oty);

    fx = *ofx; fy = *ofy;
    tx = *otx; ty = *oty;

    if (fy > ty) {
        swp = fy; fy = ty; ty = swp;
        swp = fx; fx = tx; tx = swp;
    }
    else if (fy == ty && fx > tx) {
        swp = fx; fx = tx; tx = swp;
    }

    for (xx = con->dispxmax - 1, y = fy; y <= ty; y ++) {
        if (y == ty)
            xx = tx;
            
        from = TextAddress (con, fx, y);
        to = TextAddress (con, xx, y);
        
        if (con->flagBuff[from] & CODEIS_2)
            /* 2nd byte of kanji */
            from--;

        for (x = from; x <= to; x ++) {
            if (!con->textBuff[x])
                continue;
            fc = con->attrBuff[x];
            bc = fc >> 4;
            bc2 = (bc & 8) | (fc & 7);
            fc2 = (fc & 8) | (bc & 7);
            con->attrBuff[x] = fc2 | (bc2 << 4);
            con->flagBuff[x] &= ~CLEAN_S;
        }

        fx = 0;
    }
}

/****************************************************************************
 *                TextWput1/TextWput2/TextWput/TextSput                     *
 ****************************************************************************/
void TextWput1 (CONINFO *con, u_char ch)
{
    u_int addr;

    addr = TextAddress (con, con->x, con->y);
    con->attrBuff[addr] = con->fcol | (con->bcol << 4);
    con->textBuff[addr] = ch;
    con->flagBuff[addr] = con->db;
}

void TextWput2 (CONINFO *con, u_char ch)
{
    u_int addr;

    addr = TextAddress (con, con->x, con->y);
    con->attrBuff[addr] = con->fcol | (con->bcol << 4);
    con->textBuff[addr] = ch;
    con->flagBuff[addr] = LATCH_2;

    // clear first byte.
    con->flagBuff[addr - 1] &= ~CLEAN_S;
}

void TextWput (CONINFO *con, u_char ch1, u_char ch2)
{
    u_int addr;

    addr = TextAddress (con, con->x, con->y);
    con->attrBuff[addr] = con->fcol | (con->bcol << 4);
    con->attrBuff[addr+1] = con->fcol | (con->bcol << 4);
    con->textBuff[addr] = ch2;
    con->textBuff[addr+1] = ch1;
    con->flagBuff[addr] = con->db | LATCH_1;
    con->flagBuff[addr+1] = LATCH_2;
}

void TextSput (CONINFO *con, u_char ch)
{
    u_int addr;

    addr = TextAddress (con, con->x, con->y);
    con->flagBuff[addr] = LATCH_S | con->sb;
    con->attrBuff[addr] = con->fcol | (con->bcol << 4);
    con->textBuff[addr] = ch;
}

/****************************************************************************
 *                         TextRefresh/HardScroll                           *
 ****************************************************************************/

void HardScroll (CONINFO *con)
{
    int scroll, color;
     
    scroll = con->currentScroll + con->scrollLine;
    color = ((con->attr & ATTR_REVERSE) ? con->fcol : con->bcol) & 7;

    /* con->currentScroll should be in 0-18  0-42 18+24=42 */
    if (con->scrollLine > 0) {
        if (scroll < 19)
            WindowScrollUp (con, con->scrollLine, color);
        else {
            WindowScrollDown (con, con->currentScroll, color);
            llatch(con->flagBuff, con->textSize); /* force to redraw */
            scroll = 0;
       }
    }
    else if (con->scrollLine < 0) {
        if (scroll > 0)
            WindowScrollDown (con, con->currentScroll, color);
        else if (scroll < 0) {
            if (con->currentScroll > 0)
                WindowScrollDown (con, con->currentScroll, color);
                llatch (con->flagBuff, con->textSize); /* force to redraw */
                scroll = 0;
           }
      }

      con->currentScroll = scroll;
      con->scrollLine = 0;
}

#define OUTPUTCHAR                                  \
                con->flagBuff[i] |= CLEAN_S;        \
                if (flag & CODEIS_1) {              \
                    i ++;                           \
                    con->flagBuff[i] |= CLEAN_S;    \
                    ch2 = con->textBuff[i];         \
                    if (con->ins)                   \
                        TextInsertChar (con, 2);    \
                    line [count++] = ch;            \
                    line [count++] = ch2;           \
                }                                   \
                else {                              \
                    if (con->ins)                   \
                        TextInsertChar (con, 1);    \
                    if (ch)                         \
                        line [count++] = ch;        \
                    else                            \
                        line [count++] = ' ';       \
                }

void TextRefresh (CONINFO *con, bool bHideCaret)
{
    int     x, y, i, j;
    u_char  ch, ch2, fc, bc, flag;
    int     color;
    u_char  line [MAX_NUMBER_COLS + 1];
    int     count, startx;

    color = ((con->attr & ATTR_REVERSE) ? con->fcol : con->bcol) & 7; 

    if (bHideCaret)
        WindowHideCaret (con->hWnd);

    if (con->textClear)
        WindowClearAll (con, color);
        
    if (bHideCaret)
        HardScroll (con);

    con->textClear = false;

    /* con->textSize = con->dispxmax * con->dispymax = 80 * 25 = 2000 */
    j = 0;
    fc = 0; bc = 0;
    for (y = 0; y < con->dispymax; y ++) {
        count = 0;
        startx = 0;
        for (x = 0; x < con->dispxmax; x ++) {
            u_char newfc, newbc;
                
            i = (con->textHead + j ) % con->textSize;

            newfc = *(con->attrBuff + i);
            newbc = *(con->attrBuff + i) >> 4;
            ch    = *(con->textBuff + i);
            flag  = *(con->flagBuff + i);
            
            if (flag & CLEAN_S) {
                if (count != 0) {
                    line [count] = '\0';
                    WindowStringPut (con, line, fc, bc, startx, y);

                    count = 0;
                }
            }
            else if (count == 0) {
                startx = x;
                fc = newfc; bc = newbc;

                OUTPUTCHAR
            }
            else {
                if ((fc != newfc) || (bc != newbc)) {
                    line [count] = '\0';
                    WindowStringPut (con, line, fc, bc, startx, y);

                    count = 0; startx = x;
                    fc = newfc; bc = newbc;
                    
                    OUTPUTCHAR
                }
                else {
                    OUTPUTCHAR
                }
            }

            j ++;
        }
        
        if (count != 0) {
            line [count] = '\0';
            WindowStringPut (con, line, fc, bc, startx, y);
        }
    }

    if (bHideCaret) {
        WindowSetCursor (con, con->x, con->y, IsKanji (con, con->x, con->y));
        WindowShowCaret (con->hWnd);
    }
}

void TextRepaintAll (CONINFO *con)
{
    /* force to redraw all the chars */
    llatch (con->flagBuff, con->textSize);
    con->currentScroll = con->scrollLine = 0;
    TextRefresh (con, false);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -