亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1788 | 回復(fù): 3
打印 上一主題 下一主題

[SCO UNIX] 大家看看這個(gè)菜單文件該如何設(shè)置 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2005-03-17 08:45 |只看該作者 |倒序?yàn)g覽
我在網(wǎng)上下載了一個(gè)unix下的菜單原碼,它需要配置菜單文件:match.menu和menu.add。還有一個(gè)文件nas.menu,我讀了程序,看不出這幾個(gè)菜單文件該如何配置,請高手幫忙看一下。
程序是這樣的,就是菜單配置文件信息的程序:

#include        <fcntl.h>;
#include        "menu.h"
#include        "mytools.h"

#define        MAX_ADD_ITEMS        100

#define        F_ITEM_ID        0
#define        F_ITEM_NAME        1
#define        F_PROC_TYPE        2
#define        F_PROC_NAME        3
#define        F_MENU_ID        4
#define        F_SHELL                5
#define        F_HELPID        6
#define        F_PARAM                7

struct S_zmenu_item_struc {
        char        sItemId[11];                /* 菜單選擇項(xiàng)標(biāo)識號        */
        char        sItemName[31];                /* 菜單選擇項(xiàng)名          */
        char    cProcType;                /* 處理類型 M:子菜單 E:退出菜單 */
                                        /* X:shell命令;F:函數(shù)調(diào)用    */
        char        sProcName[21];                /* 激活菜單操作的函數(shù)或過程名 */
                                        /* 當(dāng)proc_type為'F','M','E'時(shí)用 */
        char        sMenuId[11];                /* 菜單標(biāo)識號(proc_type='M'時(shí)需填 */
        char        sShell[128];                /* 當(dāng)proc_type='X'時(shí),shell命令串 */
        char        sHelpID[11];                /* 幫助信息標(biāo)識號 */

        int        iLine;                        /* Menu.txt中的行號 */
        char        sParam[30];                /* add liujin */
} *pMenuItem;

int        iMenuItemCount;
int        iMenuCount;

/*
* 初始處理菜單定義
*
* 先從文件MENU_add(view/Menu.add)中獲取附加的菜單選擇項(xiàng)定義
* 再從文件MENU_F(view/nas.menu)中讀取并分析運(yùn)行時(shí)菜單結(jié)構(gòu)定義
*
* 同時(shí)整理SMenu[],SMenuItem[]
* 置兩數(shù)組的最大下標(biāo)iMenuCount,iMenuItemCount(全局變量)
*/
GetMenu(pfMenuFile, pfAddFile)
FILE        *pfMenuFile;        /* 菜單描述文件 */
FILE        *pfAddFile;        /* 附加菜單項(xiàng)定義文件 */
{
        int        i;
        int        iRetAdd, iRetMenu;

        /*
         * 獲取固定菜單項(xiàng)數(shù)
         */
        iMenuItemCount = 0;
        for (i = 0; i < MAX_MENU_ITEMS; i++) {
                if (!strcmp(SMenuItem.sItemId, "I_END")
                        break;
        }
        iMenuItemCount = i;

        /*
         * 獲取固定子菜單數(shù)
         */
        iMenuCount = 0;
        for (i = 0; i < MAX_MENUS; i++) {
                if (!strcmp(SMenu.sMenuId, "M_END")
                        break;
        }
        iMenuCount = i;

        if (pfAddFile != NULL) {
                /*
                 * 獲取臨時(shí)增加的菜單結(jié)構(gòu)項(xiàng)
                 */
                iRetAdd = GetAddMenu(pfAddFile);
        }

        /*
         * 獲取當(dāng)前使用的菜單結(jié)構(gòu)安排(從文件view/nas.view)
         */
        iRetMenu = GetActiveMenu(pfMenuFile);

        /*
         * 只要有錯(cuò)就返回錯(cuò)
         */
        if (iRetAdd == -1 || iRetMenu == -1)
                return(-1);
        /*
         * 只要有警告就返回警告
         */
        if (iRetAdd < 0 || iRetMenu < 0)
                return(-2);

        return(0);

}

/*
* 獲取臨時(shí)增加的菜單結(jié)構(gòu)信息
*/
GetAddMenu(fp)
FILE        *fp;
{
        char        sTmpStr[1024];
        int        iCount = 0;
        int        i, j, k, ii;
        char        c;
        char        sTmpBuffer[64];
        char        sDate[12], sTime[12];
        int        iLine = 0;
        int        iItemAddCount = 0;
        char        cErrorFlag = 0;
        char        cWarnFlag = 0;
        char        sErrorString[1024];
        char        sTmpString[128];
        int        iProcOrd;
        int        iMenuOrd;
        char        sMenuId[10];

        FILE        *pfErrorFile;

        getdatef(sDate, "-";
        gettimef(sTime, ":";
        pfErrorFile = fopen("/tmp/Menu.match.error", "w+";
        if (pfErrorFile == NULL)
                pfErrorFile = stderr;

        fprintf(pfErrorFile, "\n%s %s ****Start 附加菜單項(xiàng)文件(%s)分析\n\n", sDate, sTime, MENU_add);
        /*
         * 分配菜單信息臨時(shí)結(jié)構(gòu)空間
         */
        if ((pMenuItem = (struct S_zmenu_item_struc *)malloc(MAX_ADD_ITEMS * sizeof(struct S_zmenu_item_struc ))) == NULL) {
                fprintf(pfErrorFile, "Malloc memory error!\n";
                return(-1);
        }

        /*
         * 預(yù)處理附加的菜單選擇項(xiàng)
         */
        i = 0;
        while (!feof(fp)) {
                if (fgets(sTmpStr, 1024, fp) == NULL)
                        break;
                iLine ++;
                del_NL_CR(sTmpStr);
                del_all_space(sTmpStr);
                if (sTmpStr[0] == '\0')        /* 空行,則忽略 */
                        continue;
                /* %MENU_DEFINE 標(biāo)示菜單項(xiàng)定義開始 */
                if (!strncmp(sTmpStr, "%MENU_DEFINE", 12))
                        break;
                j = 0;
                while (sTmpStr[j] != '|') {        /* 以|開頭,去掉前面的字符 */
                        if (sTmpStr[j] == '\0' || sTmpStr[j] == '#')
                                break;
                        j++;
                }
                if (sTmpStr[j] == '#')        /* 注釋行,則忽略 */
                        continue;
                if (sTmpStr[j] == '\0') {        /* 無|符,則忽略 */
                        fprintf(pfErrorFile, "行%d: 數(shù)據(jù)格式錯(cuò)! (忽略)\n", iLine);
                        cWarnFlag = 1;
                        continue;
                }
                strcpy(sTmpStr, &sTmpStr[j]);

                iCount = zut_get_seperate(sTmpStr, '|');
                if (iCount < {        /* 該行數(shù)據(jù)不完整,忽略 */
                        if ( j >; 0)
                                fprintf(pfErrorFile, "行%d: 數(shù)據(jù)不完整,可能頭上缺\'|\'! (忽略)\n", iLine);
                        else
                                fprintf(pfErrorFile, "行%d: 數(shù)據(jù)不完整! (忽略)\n", iLine);
                        cWarnFlag = 1;
                        continue;
                }
                sErrorString[0] = '\0';
                for (j = 0; j < iCount; j++) {
                        zut_get_fld(sTmpStr, j+1, sTmpBuffer, '|');
                        del_all_space(sTmpBuffer);
                        switch (j) {
                        case        F_ITEM_ID:
                                if (strlen(sTmpBuffer) >; 10) {
                                        sprintf(sTmpString, "\n\t第%d(ITEM_ID)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                strcpy(pMenuItem.sItemId, sTmpBuffer);
                                break;
                        case        F_ITEM_NAME:
                                if (strlen(sTmpBuffer) >; 30) {
                                        sprintf(sTmpString, "\n\t第%d(ITEM_NAME)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                strcpy(pMenuItem.sItemName, sTmpBuffer);
                                break;
                        case        F_PROC_TYPE:
                                if (strlen(sTmpBuffer) >; 1) {
                                        sprintf(sTmpString, "\n\t第%d(PROC_TYPE)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                if (sTmpBuffer[0] != 'F' && sTmpBuffer[0] != 'f'
                                    && sTmpBuffer[0] != 'E' && sTmpBuffer[0] != 'e'
                                    && sTmpBuffer[0] != 'M' && sTmpBuffer[0] != 'm'
                                    && sTmpBuffer[0] != 'X' && sTmpBuffer[0] != 'x') {
                                        sprintf(sTmpString, "\n\t第%d(PROC_TYPE)域選擇項(xiàng)處理類型只應(yīng)為F,E,M,X", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                pMenuItem.cProcType = toupper(sTmpBuffer[0]);
                                break;
                        case        F_PROC_NAME:
                                if (strlen(sTmpBuffer) >; 30) {
                                        sprintf(sTmpString, "\n\t第%d(PROC_NAME)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                strcpy(pMenuItem.sProcName, sTmpBuffer);
                                break;
                        case        F_MENU_ID:
                                if (strlen(sTmpBuffer) >; 10) {
                                        sprintf(sTmpString, "\n\t第%d(MENU_ID)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                strcpy(pMenuItem.sMenuId, sTmpBuffer);
                                break;
                        case        F_SHELL:
                                if (strlen(sTmpBuffer) >; 127) {
                                        sprintf(sTmpString, "\n\t第%d(SHELL)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                strcpy(pMenuItem.sShell, sTmpBuffer);
                                break;
                        case        F_HELPID:
                                if (strlen(sTmpBuffer) >; 10) {
                                        sprintf(sTmpString, "\n\t第%d(HELPID)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                strcpy(pMenuItem.sHelpID, sTmpBuffer);
                                break;
                        case        F_PARAM:
                                if (strlen(sTmpBuffer) >; 30) {
                                        sprintf(sTmpString, "\n\t第%d(SHELL)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                strcpy(pMenuItem.sParam, sTmpBuffer);
                                break;
                        default:
                                break;
                        }
                }
                if (cErrorFlag == 1) {
                        fprintf(pfErrorFile, "行%d: 以下域有錯(cuò)", iLine);
                        fprintf(pfErrorFile, "%s\n", sErrorString);
                        cWarnFlag = 1;
                        continue;
                }
                pMenuItem.iLine = iLine;
                i++;

        }

        iItemAddCount = i;

        /*
         * 處理附加的菜單項(xiàng)
         */
#define M_MENU_ID        0
#define M_MENU_NAME        1
#define        M_ROW                2
#define        M_COL                3
#define        M_DISP_FMT        4
        i = 0;
        while (!feof(fp)) {
                if (fgets(sTmpStr, 1024, fp) == NULL)
                        break;
                iLine ++;
                del_NL_CR(sTmpStr);
                del_all_space(sTmpStr);
                if (sTmpStr[0] == '\0')        /* 空行,則忽略 */
                        continue;

                j = 0;
                while (sTmpStr[j] != '|') {        /* 以|開頭,去掉前面的字符 */
                        if (sTmpStr[j] == '\0' || sTmpStr[j] == '#')
                                break;
                        j++;
                }
                if (sTmpStr[j] == '#')        /* 注釋行,則忽略 */
                        continue;
                if (sTmpStr[j] == '\0') {        /* 無|符,則忽略 */
                        fprintf(pfErrorFile, "行%d: 數(shù)據(jù)格式錯(cuò)! (忽略)\n", iLine);
                        cWarnFlag = 1;
                        continue;
                }
                strcpy(sTmpStr, &sTmpStr[j]);

                iCount = zut_get_seperate(sTmpStr, '|');
                if (iCount < 5) {        /* 該行數(shù)據(jù)不完整,忽略 */
                        if ( j >; 0)
                                fprintf(pfErrorFile, "行%d: 數(shù)據(jù)不完整,可能頭上缺\'|\'! (忽略)\n", iLine);
                        else
                                fprintf(pfErrorFile, "行%d: 數(shù)據(jù)不完整! (忽略)\n", iLine);
                        cWarnFlag = 1;
                        continue;
                }
                sErrorString[0] = '\0';
                for (j = 0; j < iCount; j++) {
                        zut_get_fld(sTmpStr, j+1, sTmpBuffer, '|');
                        del_all_space(sTmpBuffer);
                        switch (j) {
                        case        M_MENU_ID:
                                if (strlen(sTmpBuffer) >; 10) {
                                        sprintf(sTmpString, "\n\t第%d(MENU_ID)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                strcpy(sMenuId, sTmpBuffer);
                                /*
                                 * 在SMenu[]中查找sMenuId
                                 */
                                for (k = 0; k < iMenuCount; k++) {
                                        if (!strcmp(sMenuId, SMenu[k].sMenuId))
                                                break;
                                }
                                if (k < iMenuCount
                                        && SMenuItem[k].cReplace != 1
                                        && strcmp(G_oper_no, "00"!= 0) {
                                        sprintf(sErrorString, "第%d(MENU_ID)域?qū)?yīng)的菜單項(xiàng)(%s)不允許更改, 此行忽略。\n",
                                                j+1, pMenuItem[j].sMenuId);
                                        cErrorFlag = 1;
                                        continue;
                                }
                                if (k == iMenuCount) {
                                        /*
                                         * 若找不到則在后面新添一項(xiàng)
                                         */
                                        strcpy(SMenu[k].sMenuId, sMenuId);
                                        iMenuCount++;
                                        if (iMenuCount >;= MAX_MENUS) {
                                                sprintf(sErrorString, "第%d(MENU_ID)域不可再新增, 此行忽略。\n",
                                                        j+1, pMenuItem[j].sMenuId);
                                                cErrorFlag = 1;
                                                continue;
                                        }
                                        /*
                                         * 置M_END以防后用
                                         */
                                        SMenu[iMenuCount].sMenuName[0] = '\0';
                                        strcpy(SMenu[iMenuCount].sMenuId, "M_END";
                                }
                                break;
                        case        M_MENU_NAME:
                                if (strlen(sTmpBuffer) >; 30) {
                                        sprintf(sTmpString, "\n\t第%d(MENU_NAME)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                strcpy(SMenu[k].sMenuName, sTmpBuffer);
                                break;
                        case        M_ROW:
                                if (strlen(sTmpBuffer) >; 3) {
                                        sprintf(sTmpString, "\n\t第%d(M_ROW)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                if (atoi(sTmpBuffer) < 2 || atoi(sTmpBuffer) >; 21) {
                                        sprintf(sTmpString, "\n\t第%d(M_ROW)域Y坐標(biāo)應(yīng)在2-21之間", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                SMenu[k].iLocateY = atoi(sTmpBuffer);
                                if (SMenu[k].iLocateY % 2 != 0) {
                                        sprintf(sTmpString, "\n\t第%d(M_ROW)域Y坐標(biāo)應(yīng)為偶數(shù)", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                break;
                        case        M_COL:
                                if (strlen(sTmpBuffer) >; 3) {
                                        sprintf(sTmpString, "\n\t第%d(M_COL)域太長", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                if (atoi(sTmpBuffer) < 2 || atoi(sTmpBuffer) >; 70) {
                                        sprintf(sTmpString, "\n\t第%d(M_COL)域X坐標(biāo)應(yīng)在2-70之間", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                SMenu[k].iLocateX = atoi(sTmpBuffer);
                                if (SMenu[k].iLocateX % 2 != 0) {
                                        sprintf(sTmpString, "\n\t第%d(M_COL)域X坐標(biāo)應(yīng)為偶數(shù)", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                break;
                        case        M_DISP_FMT:
                                if (sTmpBuffer[0] != 'H'
                                    && sTmpBuffer[0] != 'V') {
                                        sprintf(sTmpString, "\n\t第%d(DISP_FMT)域顯示格式只應(yīng)為H(橫向)或V(縱向)", j+1);
                                        strcat(sErrorString, sTmpString);
                                        cErrorFlag = 1;
                                        break;
                                }
                                SMenu[k].iDispFormat = sTmpBuffer[0];
                                break;
                        default:
                                break;
                        }
                }
                if (cErrorFlag == 1) {
                        fprintf(pfErrorFile, "行%d: 以下域有錯(cuò)", iLine);
                        fprintf(pfErrorFile, "%s\n", sErrorString);
                        cWarnFlag = 1;
                        continue;
                }
                /*
                 * 將子菜單選擇項(xiàng)置為空,以后通過view/nas.menu具體定義
                 */
                SMenu[k].iMenuItemSet[0] = -1;
                i++;
        }

        /*
         * 正式處理附加菜單選擇項(xiàng)
         */
        for (j = 0; j < iItemAddCount; j++) {
                iProcOrd = -1;
                iMenuOrd = -1;
                if (pMenuItem[j].cProcType == 'F') {
                        iProcOrd = GetProcOrd(pMenuItem[j].sProcName);
                        if (iProcOrd < 0) {
                                fprintf(pfErrorFile, "第%d行對應(yīng)的函數(shù)(%s)不存在, 此行忽略。\n",
                                        pMenuItem[j].iLine, pMenuItem[j].sProcName);
                                cWarnFlag = 1;
                                continue;
                        }
                }
                if (pMenuItem[j].cProcType == 'E'
                        && pMenuItem[j].sProcName[0] != '\0') {
                       
                        iProcOrd = GetProcOrd(pMenuItem[j].sProcName);
                        if (iProcOrd < 0) {
                                fprintf(pfErrorFile, "第%d行對應(yīng)的函數(shù)(%s)不存在, 此行忽略。\n",
                                        pMenuItem[j].iLine, pMenuItem[j].sProcName);
                                cWarnFlag = 1;
                                continue;
                        }
                }
                if (pMenuItem[j].cProcType == 'M') {
                        /*
                         * 在SMenu[]中查找sMenuId, 若不存在,則報(bào)錯(cuò)
                         */
                        iMenuOrd = GetMenuOrd(pMenuItem[j].sMenuId);
                        if (iMenuOrd < 0) {
                                fprintf(pfErrorFile, "第%d行%s對應(yīng)的菜單項(xiàng)在SMenu[]中不存在, 此行忽略。\n",
                                        pMenuItem[j].iLine, pMenuItem[j].sMenuId);
                                cWarnFlag = 1;
                                continue;
                        }
                        if (pMenuItem[j].sProcName[0] != '\0') {
                                iProcOrd = GetProcOrd(pMenuItem[j].sProcName);
                                if (iProcOrd < 0) {
                                        fprintf(pfErrorFile, "第%d行對應(yīng)的函數(shù)(%s)不存在, 此行忽略。\n",
                                                pMenuItem[j].iLine, pMenuItem[j].sProcName);
                                        cWarnFlag = 1;
                                        continue;
                                }
                        }
                }
                if (pMenuItem[j].cProcType == 'X') {
                        if (pMenuItem[j].sShell[0] == '\0') {
                                fprintf(pfErrorFile, "第%d行對應(yīng)的Shell串不可為空, 此行忽略。\n",
                                        pMenuItem[j].iLine);
                                cWarnFlag = 1;
                                continue;
                        }
                }
                       
                /*
                 * 在SMenuItem[]中查找sMenuId
                 */
                for (k = 0; k < iMenuItemCount; k++) {
                        if (!strcmp(pMenuItem[j].sItemId, SMenuItem[k].sItemId))
                                break;
                }
                if (k < iMenuItemCount
                        && SMenuItem[k].cReplace != 1
                        && strcmp(G_oper_no, "00" != 0) {
                        fprintf(pfErrorFile, "第%d行對應(yīng)的選擇項(xiàng)(%s)不允許更改, 此行忽略。\n",
                                pMenuItem[j].iLine, pMenuItem[j].sItemId);
                        cWarnFlag = 1;
                        continue;
                }
                if (k == iMenuItemCount) {
                        /*
                         * 若找不到則在后面新添一項(xiàng)
                         */
                        strcpy(SMenuItem[k].sItemId, pMenuItem[j].sItemId);
                        SMenuItem[k].cReplace = 1;        /* 新增項(xiàng)允許更改 */
                        strcpy(SMenuItem[k].sName, pMenuItem[j].sItemName);
                        iMenuItemCount ++;
                        if (iMenuItemCount >;= MAX_MENU_ITEMS) {
                                fprintf(pfErrorFile, "第%d行對應(yīng)的選擇項(xiàng)(%s)不可再新增, 此行忽略。\n",
                                        pMenuItem[j].iLine, pMenuItem[j].sItemId);
                                cWarnFlag = 1;
                                continue;
                        }
                        /*
                         * 置I_END以防后用
                         */
                        SMenuItem[iMenuItemCount].sName[0] = '\0';
                        strcpy(SMenuItem[iMenuItemCount].sItemId, "I_END";
                        SMenuItem[iMenuItemCount].iChildMenu = 99;
                }

                SMenuItem[k].cProcType = pMenuItem[j].cProcType;
                if (iProcOrd >;= 0)
                        SMenuItem[k].mproc = proctab[iProcOrd].p_proc;
                SMenuItem[k].iChildMenu = iMenuOrd;     
                strcpy(SMenuItem[k].sShell, pMenuItem[j].sShell);
                strcpy(SMenuItem[k].sParam, pMenuItem[j].sParam);
                strcpy(SMenuItem[k].sHelpId, pMenuItem[j].sHelpID);
        }
        free(pMenuItem);
        getdatef(sDate, "-");
        gettimef(sTime, ":");
        if (cWarnFlag == 0)
                fprintf(pfErrorFile, "\nOK!\n");
        fprintf(pfErrorFile, "\n%s %s ****Finish 附加菜單項(xiàng)文件(%s)分析\n\n", sDate, sTime, MENU_add);
        fclose(pfErrorFile);
        if (cWarnFlag == 1)
                return(-2);
        else
                return(0);
}

/*
* 根據(jù)選擇項(xiàng)標(biāo)識查找選擇項(xiàng)序號
*/
GetItemOrd(pcItemId)
char        *pcItemId;
{
        int        i;

        for (i = 0; i < iMenuItemCount; i++) {
                if (!strcmp(SMenuItem.sItemId, pcItemId))
                        return(i);
        }
        return(-1);
}

/*
* 根據(jù)菜單標(biāo)識查找菜單序號
*/
GetMenuOrd(pMenuId)
char        *pMenuId;
{
        int        i;

        for (i = 0; i < iMenuCount; i++) {
                if (!strcmp(SMenu.sMenuId, pMenuId))
                        return(i);
        }
        return(-1);
}

#define        LINE_FIRST        0
#define        LINE_MENU        1
#define        LINE_ITEM        3
#define        LINE_NOTE        4
#define        LINE_SHELL        5
/*
* 獲取實(shí)際使用的菜單結(jié)構(gòu)
*/
int        GetActiveMenu(pfMenuFile)
FILE        *pfMenuFile;
{
        int        c, i, j, iItemHead;
        char        name[WIDTH1+1];
        char        sMenuId[10], sItemId[10];
        char        sTmpStr[1024];
        char        *pcIdOff = NULL;
        char        cFirstChar;
        int        iLine = 0;
        int        iMenuNo = -1;
        int        iItemNo = -1;
        char        cItemOrd = 0;
        char        cLastFlag = LINE_FIRST;
        char        cErrorFlag = 0, cWarnFlag = 0;
        char        sDate[12], sTime[12];

        FILE        *pfErrorFile;

        getdatef(sDate, "-");
        gettimef(sTime, ":");

        pfErrorFile = fopen("/tmp/Menu.match.error", "a+");
        if (pfErrorFile == NULL)
                pfErrorFile = stderr;

        fprintf(pfErrorFile, "\n%s %s ****Start 運(yùn)行菜單定義文件(%s)分析\n\n", sDate, sTime, MENU_f);

        rewind(pfMenuFile);
        while (!feof(pfMenuFile)) {
                if (fgets(sTmpStr, 1024, pfMenuFile) == NULL) {
                        break;
                }
                iLine++;

                del_NL_CR(sTmpStr);
                del_all_space(sTmpStr);

                cFirstChar = sTmpStr[0];
                strcpy(sTmpStr, &sTmpStr[1]);
                switch (cFirstChar) {
                case        '&':
                        if (cLastFlag != LINE_FIRST) {
                                if (cLastFlag == LINE_MENU)
                                        fprintf(pfErrorFile, "\t行%d:菜單中未定義選擇項(xiàng)!\n", iLine-1);
                                else if (cLastFlag == LINE_ITEM)
                                        fprintf(pfErrorFile, "\t行%d:未定義選擇項(xiàng)說明!\n", iLine-1);
                                else if (cLastFlag == LINE_NOTE || cLastFlag == LINE_SHELL)
                                        fprintf(pfErrorFile, "\t行%d前面:未有'$'標(biāo)識行!\n", iLine);
                                cErrorFlag ++;
                        }
                        if (iMenuNo >;= 0)
                                SMenu[iMenuNo].iMenuItemSet[cItemOrd] = -1;
                        iMenuNo = -1;
                        iItemNo = -1;
                        cItemOrd = 0;
                        cLastFlag = LINE_MENU;
                        pcIdOff = (char *)strstr(sTmpStr, "M_"); /* 取菜單標(biāo)識 */
                        if (pcIdOff != NULL) {
                                strncpy(sMenuId, pcIdOff, 9);
                                sMenuId[9] = '\0';
                        } else {
                                fprintf(pfErrorFile, "\t行%d: 無菜單標(biāo)識號!\n", iLine);
                                cErrorFlag ++;
                                iMenuNo = -1;
                                break;
                        }
                        if ((iMenuNo = GetMenuOrd(sMenuId)) < 0) {
                                fprintf(pfErrorFile, "\t行%d: 菜單標(biāo)識號\"%s\"有誤!\n", iLine, sMenuId);
                                cErrorFlag ++;
                                iMenuNo = -1;
                                break;
                        }
                        break;
                case        '%':
                        if (cLastFlag == LINE_FIRST) {
                                fprintf(pfErrorFile, "\t行%d前面:未定義菜單!\n", iLine);
                                cErrorFlag ++;
                                cLastFlag = LINE_ITEM;
                                break;
                        } else if (cLastFlag == LINE_ITEM) {
                                fprintf(pfErrorFile, "\t行%d前面:未定義選擇項(xiàng)說明!\n", iLine);
                                cWarnFlag ++;
                        }
                        cLastFlag = LINE_ITEM;
                        pcIdOff = (char *)strstr(sTmpStr, "I_"); /* 取選擇項(xiàng)標(biāo)識 */
                        if (pcIdOff != NULL) {
                                strncpy(sItemId, pcIdOff, 9);
                                sItemId[9] = '\0';
                        } else {
                                fprintf(pfErrorFile, "\t行%d: 無選擇項(xiàng)標(biāo)識號!\n", iLine);
                                /* 將此項(xiàng)忽略,不算致命錯(cuò)誤 */
                                cWarnFlag ++;
                                iItemNo = -1;
                                break;
                        }
                        if ((iItemNo = GetItemOrd(sItemId)) < 0) {
                                fprintf(pfErrorFile, "\t行%d: 選擇項(xiàng)標(biāo)識號%s有誤!\n", iLine, sMenuId);
                                /* 將此項(xiàng)忽略,不算致命錯(cuò)誤 */
                                cWarnFlag ++;
                                iItemNo = -1;
                                break;
                        } else {
                                if (iMenuNo >;= 0) {
                                        SMenu[iMenuNo].iMenuItemSet[cItemOrd] = iItemNo;
                                        SMenuItem[iItemNo].iPower = 1;
                                        cItemOrd ++;
                                } else {
                                        /* 由于菜單非法,故其下的選擇項(xiàng)也非法 */
                                        iItemNo = -1;
                                }
                        }
                        break;
                case        '#':
                        if (cLastFlag == LINE_MENU || cLastFlag == LINE_FIRST) {
                                fprintf(pfErrorFile, "\t行%d前面:未定義選擇項(xiàng)! (忽略)\n", iLine);
                                cWarnFlag ++;
                                break;
                        } else if (cLastFlag == LINE_NOTE) {
                                fprintf(pfErrorFile, "\t行%d:選擇項(xiàng)說明多行定義! (忽略)\n", iLine);
                                cWarnFlag ++;
                                break;
                        } else if (cLastFlag == LINE_SHELL) {
                                fprintf(pfErrorFile, "\t行%d:注釋行不應(yīng)出現(xiàn)在Shell命令行之后! (忽略)\n", iLine);
                                cWarnFlag ++;
                                break;
                        }
                        cLastFlag = LINE_NOTE;
                        if (iItemNo >;= 0)
                                strcpy(SMenuItem[iItemNo].sText, sTmpStr);
                        break;
                case        '!':
                        if (cLastFlag == LINE_NOTE) {
                                cLastFlag = LINE_SHELL;
                                if (iItemNo >;= 0) {
                                        SMenuItem[iItemNo].cProcType = 'X';
                                        strcpy(SMenuItem[iItemNo].sShell, sTmpStr);
                                }
                                break;
                        }
                        fprintf(pfErrorFile, "\t行%d:此處不應(yīng)出現(xiàn)Shell程序定義! (忽略)\n", iLine);
                        break;
                       
                case        '$':
                        if (cLastFlag == LINE_ITEM) {
                                fprintf(pfErrorFile, "\t行%d前面:選擇項(xiàng)無說明!\n", iLine);
                                cWarnFlag ++;
                        } else if (cLastFlag == LINE_MENU) {
                                fprintf(pfErrorFile, "\t行%d前面:菜單無選擇項(xiàng)定義!\n", iLine);
                                cErrorFlag ++;
                        }
                        if (iMenuNo >;= 0)
                                SMenu[iMenuNo].iMenuItemSet[cItemOrd] = -1;
                        iMenuNo = -1;
                        iItemNo = -1;
                        cItemOrd = 0;
                        cLastFlag = LINE_FIRST;
                        break;
                default:
                        break;
                               
                }
        }
        if (cErrorFlag)
                fprintf(pfErrorFile, "\n        ********* 有錯(cuò)誤! *******\n");
        else if (cWarnFlag)
                fprintf(pfErrorFile, "\n        ********* 有警告。 *******\n");
        else
                fprintf(pfErrorFile, "\n        ********* OK 。 *******\n");
        getdatef(sDate, "-");
        gettimef(sTime, ":");
        fprintf(pfErrorFile, "\n%s %s ****Finish 運(yùn)行菜單結(jié)構(gòu)定義文件(%s)分析\n\n", sDate, sTime, MENU_f);
        fclose(pfErrorFile);

        if (cErrorFlag)
                return(-1);
        else if (cWarnFlag)
                return(-2);
        return(0);
}


/*
*   功能: 初始化菜單項(xiàng)信息
*   入口: 菜單號, 菜單信息文件句柄
*   出口:   菜單選擇項(xiàng)名
*           選擇項(xiàng)說明
*           選擇項(xiàng)首字母
*           選擇項(xiàng)的幫助文件索引
*           當(dāng)前選擇項(xiàng)所在行的首尾項(xiàng)號
*/
int        GetItemInfo(iMenuNo, pfMenuFile)
int        iMenuNo;
FILE        *pfMenuFile;
{
        int        c, i, j, iItemHead;
        char        sItemName[WIDTH1+1];
        char        sMenuId[10], sItemId[10];
        char        sTmpStr[1024];
        char        *pcIdOff = NULL;
        char        cFirstChar;
        int        iItemNo = -1;
        char        cItemOrd = 0;
        char        cMenuFlag = 0;
        char        cLastFlag = LINE_FIRST;
        char        cErrorFlag = 0, cWarnFlag = 0;
        char        sDate[12], sTime[12];

        rewind(pfMenuFile);
        while (!feof(pfMenuFile)) {
                if (fgets(sTmpStr, 1024, pfMenuFile) == NULL) {
                        break;
                }

                del_NL_CR(sTmpStr);
                del_all_space(sTmpStr);

                cFirstChar = sTmpStr[0];
                strcpy(sTmpStr, &sTmpStr[1]);
                switch (cFirstChar) {
                case        '&':
                        if (cMenuFlag == 1) {
                                SMenu[iMenuNo].iMenuItemSet[cItemOrd] = -1;
                                return(0);
                        }
                        pcIdOff = (char *)strstr(sTmpStr, "M_"); /* 取菜單標(biāo)識 */
                        if (pcIdOff != NULL) {
                                strncpy(sMenuId, pcIdOff, 9);
                                sMenuId[9] = '\0';
                        } else {
                                break;
                        }
                        if (!strcmp(SMenu[iMenuNo].sMenuId, sMenuId)) {
                                cMenuFlag = 1;        /* 找到菜單定義 */
                                cItemOrd = 0;
                                cLastFlag = LINE_MENU;
                                break;
                        }
                        break;
                case        '%':
                        if (cMenuFlag == 0)
                                break;
                        cLastFlag = LINE_ITEM;
                        iItemNo = -1;
                        pcIdOff = (char *)strstr(sTmpStr, "I_"); /* 取選擇項(xiàng)標(biāo)識 */
                        if (pcIdOff != NULL) {
                                strncpy(sItemId, pcIdOff, 9);
                                sItemId[9] = '\0';
                                *pcIdOff = '\0';
                                strcpy(sItemName, sTmpStr);
                        } else {
                                break;
                        }
                        if ((iItemNo = GetItemOrd(sItemId)) < 0) {
                                break;
                        } else {
                                SMenu[iMenuNo].iMenuItemSet[cItemOrd] = iItemNo;
                                strcpy(SMenuItem[iItemNo].sName, sItemName);
                                if (isalpha(sItemName[0]) || isdigit(sItemName[0]))
                                        SMenuItem[iItemNo].cFirstChar = sItemName[0];
                                cItemOrd ++;
                        }
                        break;
                case        '#':
                        if (cMenuFlag == 0)
                                break;
                        if (iItemNo == -1)
                                break;
                        cLastFlag = LINE_NOTE;
                        if (cLastFlag != LINE_ITEM) {
                                break;
                        }
                        strcpy(SMenuItem[iItemNo].sText, sTmpStr);
                        break;
                case        '!':
                        if (cMenuFlag == 0)
                                break;
                        if (iItemNo == -1)
                                break;
                        if (cLastFlag != LINE_NOTE) {
                                break;
                        }
                        cLastFlag = LINE_SHELL;
                        SMenuItem[iItemNo].cProcType = 'X';
                        strcpy(SMenuItem[iItemNo].sShell, sTmpStr);
                        break;
                       
                case        '$':
                        if (cMenuFlag == 1) {
                                SMenu[iMenuNo].iMenuItemSet[cItemOrd] = -1;
                                return(0);
                        }
                        cLastFlag = LINE_FIRST;
                        break;
                default:
                        break;
                               
                }
        }
        if (cMenuFlag == 0) {
                return(-1);
        }
        return(-2);
}

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2005-03-18 17:37 |只看該作者

大家看看這個(gè)菜單文件該如何設(shè)置

是不是代碼太長,沒人愿意看?

論壇徽章:
1
榮譽(yù)版主
日期:2011-11-23 16:44:17
3 [報(bào)告]
發(fā)表于 2005-03-18 21:12 |只看該作者

大家看看這個(gè)菜單文件該如何設(shè)置

看別人的代碼確實(shí)很累。很好的菜單程序SCO壇子里有不少。你可以參考。

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2005-03-21 10:04 |只看該作者

大家看看這個(gè)菜單文件該如何設(shè)置

[quote]原帖由 "htldm"]看別人的代碼確實(shí)很累。很好的菜單程序SCO壇子里有不少。你可以參考。[/quote 發(fā)表:

老大,能給我提供幾個(gè)嗎?謝謝。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP