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

📄 eng_io.c

📁 VIA VT6524 8口网管交换机源码
💻 C
字号:
/*
 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
 * All rights reserved.
 *
 * This software is copyrighted by and is the sole property of
 * VIA Networking Technologies, Inc. This software may only be used
 * in accordance with the corresponding license agreement. Any unauthorized
 * use, duplication, transmission, distribution, or disclosure of this
 * software is expressly forbidden.
 *
 * This software is provided by VIA Networking Technologies, Inc. "as is"
 * and any express or implied warranties, including, but not limited to, the
 * implied warranties of merchantability and fitness for a particular purpose
 * are disclaimed. In no event shall VIA Networking Technologies, Inc.
 * be liable for any direct, indirect, incidental, special, exemplary, or
 * consequential damages.
 *
 *
 * File:    eng_io.c
 *
 * Purpose: UI engine module to support I/O related operations
 *
 * Author:  Jenda Jao
 *
 * Date:    Jan 08, 2002
 *
 * Functions:
 *
 * Revision History:
 *
 */


#include <ctype.h>
#include "str.h"
#include "ttyio.h"
#include "allpages.h"
#include "engine.h"
#include "eng_io.h"
#include "eng_act.h"
#if !defined(__BITOP_H__)
#include "bitop.h"
#endif




/*---------------------  Static Functions  --------------------------*/

/*---------------------  Export Functions  --------------------------*/
////////////////////
//// input functions
// Get a string (include space) / password / dec_num / hex_num
void ENGvInputItem(SItem* pSItem) DIRECT_FUNTYPE_REENT
{
    BYTE byInLen, byStrLen;
    char* strBuf;
    char strNum[MAX_ITEM_DEC_LEN+1];    // num string buffer

    if (! isprint(g_byCurKey))
    {
        g_byCurKey = 0;
        return;
    }

    if (pSItem->f4DataType == ITEM_STRING)
    {
        strBuf = ((SItemString*)(pSItem->pvItem))->strString;
        byStrLen = ((SItemString*)(pSItem->pvItem))->byMaxLen;
    }
    else if (pSItem->f4DataType == ITEM_PASSWORD)
    {
        strBuf = ((SItemPasswd*)(pSItem->pvItem))->strPassword;
        byStrLen = ((SItemPasswd*)(pSItem->pvItem))->byMaxLen;
    }
    else
    {
        if ( ( (pSItem->f4DataType == ITEM_HEXNUM) && ! isxdigit(g_byCurKey) ) ||
             ( (pSItem->f4DataType == ITEM_DECNUM) && ! isdigit(g_byCurKey) ) )
        {
            g_byCurKey = 0;
            return;
        }

        strBuf = strNum;
        byStrLen = ((SItemNum*)(pSItem->pvItem))->f5MaxLen;
    }

    // backspace N char
    TTYvPutChar(KEY_ESC);
    TTYvPutChar('[');
    TTYvPutDec(byStrLen);
    TTYvPutChar('D');

    TTYvRevChar();

    for (byInLen=0; byInLen<byStrLen; byInLen++)
        TTYvPutChar(' ');

    TTYvPutChar(KEY_ESC);
    TTYvPutChar('[');
    TTYvPutDec(byStrLen);
    TTYvPutChar('D');

    // output the first char
    strBuf[0] = g_byCurKey;
    byInLen = 1;
    if (pSItem->f4DataType == ITEM_PASSWORD)
        TTYvPutChar('*');
    else
        TTYvPutChar(g_byCurKey);

    while (1)
    {
        g_byCurKey = TTYcGetChar();
        if (g_byCurKey == KEY_BKSPC)
        {
            if (byInLen > 0)
            {
                byInLen--;
                TTYvBackspace();
            }
        }
        else if (! isprint(g_byCurKey))
        {
            strBuf[byInLen] = 0;
            break;
        }
        else if ( (byInLen < byStrLen) &&
                  ( ( (pSItem->f4DataType == ITEM_STRING) && isprint(g_byCurKey) ) ||
                    ( (pSItem->f4DataType == ITEM_PASSWORD) && isprint(g_byCurKey) ) ||
                    ( (pSItem->f4DataType == ITEM_HEXNUM) && isxdigit(g_byCurKey) ) ||
                    ( (pSItem->f4DataType == ITEM_DECNUM) && isdigit(g_byCurKey) ) )  )
        {
            strBuf[byInLen] = g_byCurKey;
            if (pSItem->f4DataType == ITEM_PASSWORD)
                TTYvPutChar('*');
            else
                TTYvPutChar(g_byCurKey);
            byInLen++;
        }
    }

    if ((pSItem->f4DataType == ITEM_HEXNUM)||(pSItem->f4DataType == ITEM_DECNUM))
    {
        UINT16 wValue=0;

        // convert string to num value
        for (byInLen=0; strBuf[byInLen] != '\0'/*byInLen<STRbyStrlen(strBuf)*/; byInLen++)
            wValue = wValue*((pSItem->f4DataType == ITEM_DECNUM) ? 10 : 16) + toint(strBuf[byInLen]);

        if (((SItemNum*)(pSItem->pvItem))->f3ByteNum == 2)
            (UINT16)(*(((SItemNum*)(pSItem->pvItem))->pbyNum + ((SItemNum*)(pSItem->pvItem))->byVarByteOffset * g_byCurLineID)) = wValue;
        else
            (*(((SItemNum*)(pSItem->pvItem))->pbyNum + ((SItemNum*)(pSItem->pvItem))->byVarByteOffset * g_byCurLineID)) = wValue;
    }
}


/////////////////////
//// output functions
// print whole page
void ENGvPrintPage(void) DIRECT_FUNTYPE_REENT
{
    BYTE ui;

    TTYvRstChar();
    TTYvClearScrn();

    // print fix label
    for (ui=0; ui<g_pSCurPage->byFixLabelNum; ui++)
    {
        if (g_pSCurPage->aSFixLabel[ui].byDrawLineLen)
            TTYvDrawLine(g_pSCurPage->aSFixLabel[ui].SPos.byRow,
                         g_pSCurPage->aSFixLabel[ui].SPos.byCol,
                         g_pSCurPage->aSFixLabel[ui].strLabel[0],
                         g_pSCurPage->aSFixLabel[ui].byDrawLineLen);
        else
            TTYvPutPosStr(g_pSCurPage->aSFixLabel[ui].SPos.byRow,
                          g_pSCurPage->aSFixLabel[ui].SPos.byCol,
                          g_pSCurPage->aSFixLabel[ui].strLabel);
    }

    ENGvPrintVarPage();
    if (g_aSCurActionList)
        ENGvPrintActionbar();
}


// print variable part of a page, only print items with different values
void ENGvPrintVarPage(void) DIRECT_FUNTYPE_REENT
{
    BYTE byLineID, byItemID;

    // print var label
    for (byItemID=0; byItemID<g_pSCurPage->byVarLabelNum; byItemID++)
    {
        switch (g_pSCurPage->aSVarLabel[byItemID].f2RepeatType)
        {
            case REPEAT_TYPE_NONE:
                ENGvPrintItem(0, byItemID, PRINT_VAR_LABEL);
            break;
            case REPEAT_TYPE_RECT_SINGLE:
            case REPEAT_TYPE_RECT_MULTI:
                if (g_byTotalLineNum == 0)
                    break;
                for (byLineID=0; byLineID<g_byTotalLineNum; byLineID++)
                    ENGvPrintItem(byLineID, byItemID, PRINT_VAR_LABEL);
            break;
        }
    }

    // print var item
    for (byItemID=0; byItemID<g_pSCurPage->byVarItemNum; byItemID++)
    {
        if ((g_byTotalLineNum == 0)&&(REPEAT_TYPE_NONE != g_aSCurItemList[byItemID].f2RepeatType))
            continue;

        switch (g_aSCurItemList[byItemID].f2RepeatType)
        {
            case REPEAT_TYPE_NONE:
                ENGvPrintItem(0, byItemID, PRINT_ITEM_NORMAL);
            break;

            case REPEAT_TYPE_RECT_SINGLE:
            case REPEAT_TYPE_RECT_MULTI:
                for (byLineID=0; byLineID<g_byTotalLineNum; byLineID++)
                    ENGvPrintItem(byLineID, byItemID, PRINT_ITEM_NORMAL);
            break;
        }
    }
}

// add space after strBuf in order to satisfy byMaxLen, for ENGvPrintItem() only
static void s_vAddSpace(char* strBuf, BYTE byMaxLen) DIRECT_FUNTYPE_REENT
{
    BYTE len;
    for (len = STRbyStrlen(strBuf); len < byMaxLen; len++)
        strBuf[len] = ' ';
    strBuf[byMaxLen] = 0;
//    if (len < byMaxLen)
//    {
//        STRvMemset(strBuf+len, ' ', byMaxLen-len);
//        strBuf[byMaxLen+1] = 0;
//    }
}
// print a item for all types, and append space to user defined length
void ENGvPrintItem(BYTE byLineID, BYTE byItemID, BYTE byType) DIRECT_FUNTYPE_REENT
{
    SItem* pSItem;

    if (byType == PRINT_VAR_LABEL)  // print var label or item
        pSItem = g_pSCurPage->aSVarLabel + byItemID;
    else
        pSItem = g_aSCurItemList + byItemID;

    if ( (byType == PRINT_ITEM_HIGHLIGHT) &&
         (g_aSCurItemList[byItemID].strDescription) )
        ENGcPrintMessage(g_aSCurItemList[byItemID].strDescription, PRINT_THEN_RETURN);

    // set current position of cursor
    switch (pSItem->f2RepeatType)
    {
        case REPEAT_TYPE_NONE:
            byLineID = 0;
            TTYvSetCurPos(pSItem->SPos.byRow, pSItem->SPos.byCol);
        break;
        case REPEAT_TYPE_RECT_SINGLE:
        case REPEAT_TYPE_RECT_MULTI:
            TTYvSetCurPos(pSItem->SPos.byRow + (byLineID%pSItem->byLineNumPerColumn),
                          pSItem->SPos.byCol + (byLineID/pSItem->byLineNumPerColumn) * pSItem->byPosColOffset);
        break;
    }

    if (byType == PRINT_ITEM_HIGHLIGHT) // highlight item
        TTYvRevChar();

    switch (pSItem->f4DataType)     // for every item type
    {
        case ITEM_MENU_PAGESEL:
        {
            if (byItemID+1 == g_pSCurPage->byVarItemNum)
                TTYvPutChar('0');
            else
                TTYvPutChar('1'+byItemID);
            TTYvPutString(". ");
            TTYvPutString(((SItemPageSel*)(pSItem->pvItem))->strPageSel);
        } break;
        case ITEM_DECNUM:
        case ITEM_HEXNUM:
        {
            SItemNum* pSItemNum = (SItemNum*)(pSItem->pvItem);
            char strBuf[MAX_ITEM_STR_LEN] = {0};
            if (pSItem->f4DataType == ITEM_DECNUM)
            {
                if (pSItemNum->f3ByteNum == 2)    // value is UINT16 or UINT8
                    TTYvSPutDec(strBuf, *((UINT16*)(pSItemNum->pbyNum + pSItemNum->byVarByteOffset * byLineID)));
                else
                    TTYvSPutDec(strBuf, *(pSItemNum->pbyNum + pSItemNum->byVarByteOffset * byLineID));
            }
            else
            {
                if (pSItemNum->f3ByteNum == 2)    // value is UINT16 or UINT8
                    TTYvSPutHex(strBuf, *((UINT16*)(pSItemNum->pbyNum + pSItemNum->byVarByteOffset * byLineID)));
                else
                    TTYvSPutHex(strBuf, *(pSItemNum->pbyNum + pSItemNum->byVarByteOffset * byLineID));
            }
            s_vAddSpace(strBuf, pSItemNum->f5MaxLen);
            TTYvPutString(strBuf);
        } break;
        case ITEM_LISTBOX:
        {
            SItemListbox *pSIListbox = (SItemListbox*)(pSItem->pvItem);
            BYTE byValue;
            BITvExtractBits(pSIListbox->pbyIndex + (pSIListbox->byVarBitOffset>>3) * byLineID,
                            pSIListbox->byStartBit + (pSIListbox->byVarBitOffset&0x07) * byLineID,
                            pSIListbox->byEndBit + (pSIListbox->byVarBitOffset&0x07) * byLineID,
                            &byValue);
            TTYvPutString(pSIListbox->astrListbox[byValue]);
        } break;
        case ITEM_VAR_LISTBOX:
        {
            SItemVarListbox *pSIListbox = (SItemListbox*)(pSItem->pvItem);
            BYTE byValue;
            // The ITEM_VAR_LISTBOX item does not support repeat-type in this smart version
            BITvExtractBits(pSIListbox->pbyIndex,
                            pSIListbox->byStartBit,
                            pSIListbox->byEndBit,
                            &byValue);
            TTYvPutString(pSIListbox->astrListbox[ (pSIListbox->pSStrTblMap->abyListIndex)[byValue] ]);
        } break;
        case ITEM_STRING:
        {
            char strBuf[MAX_ITEM_STR_LEN];
            STRvStrcpy(strBuf, ((SItemString*)(pSItem->pvItem))->strString);
            s_vAddSpace(strBuf, ((SItemString*)(pSItem->pvItem))->byMaxLen);
            TTYvPutString(strBuf);
        } break;
        case ITEM_PASSWORD:
        {
            TTYvDrawLine(pSItem->SPos.byRow, pSItem->SPos.byCol,
                        '*', ((SItemPasswd*)(pSItem->pvItem))->byMaxLen);
        } break;
        default:
            TTYvPutString("BUG!!");
            TTYcGetChar();
    }

    TTYvRstChar();
}


char ENGcPrintMessage(PSTR str, BOOL bPause) DIRECT_FUNTYPE_REENT
{
    if (STRbyStrlen(str) == 0)
        return '\0';

    TTYvRevChar();
    TTYvDrawLine(23,2,' ',77);
    TTYvSetCurPos(23,(80-STRbyStrlen(str))/2);
    TTYvPutString(str);
    TTYvRstChar();

    if (bPause)
        return TTYcGetChar();
    else
        return '\0';
}

⌨️ 快捷键说明

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