- 论坛徽章:
- 0
|
我在网上下载了一个unix下的菜单原码,它需要配置菜单文件:match.menu和menu.add。还有一个文件nas.menu,我读了程序,看不出这几个菜单文件该如何配置,请高手帮忙看一下。
程序是这样的,就是菜单配置文件信息的程序:
#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]; /* 菜单选择项标识号 */
char sItemName[31]; /* 菜单选择项名 */
char cProcType; /* 处理类型 M:子菜单 E:退出菜单 */
/* X:shell命令;F:函数调用 */
char sProcName[21]; /* 激活菜单操作的函数或过程名 */
/* 当proc_type为'F','M','E'时用 */
char sMenuId[11]; /* 菜单标识号(proc_type='M'时需填 */
char sShell[128]; /* 当proc_type='X'时,shell命令串 */
char sHelpID[11]; /* 帮助信息标识号 */
int iLine; /* Menu.txt中的行号 */
char sParam[30]; /* add liujin */
} *pMenuItem;
int iMenuItemCount;
int iMenuCount;
/*
* 初始处理菜单定义
*
* 先从文件MENU_add(view/Menu.add)中获取附加的菜单选择项定义
* 再从文件MENU_F(view/nas.menu)中读取并分析运行时菜单结构定义
*
* 同时整理SMenu[],SMenuItem[]
* 置两数组的最大下标iMenuCount,iMenuItemCount(全局变量)
*/
GetMenu(pfMenuFile, pfAddFile)
FILE *pfMenuFile; /* 菜单描述文件 */
FILE *pfAddFile; /* 附加菜单项定义文件 */
{
int i;
int iRetAdd, iRetMenu;
/*
* 获取固定菜单项数
*/
iMenuItemCount = 0;
for (i = 0; i < MAX_MENU_ITEMS; i++) {
if (!strcmp(SMenuItem.sItemId, "I_END" )
break;
}
iMenuItemCount = i;
/*
* 获取固定子菜单数
*/
iMenuCount = 0;
for (i = 0; i < MAX_MENUS; i++) {
if (!strcmp(SMenu.sMenuId, "M_END" )
break;
}
iMenuCount = i;
if (pfAddFile != NULL) {
/*
* 获取临时增加的菜单结构项
*/
iRetAdd = GetAddMenu(pfAddFile);
}
/*
* 获取当前使用的菜单结构安排(从文件view/nas.view)
*/
iRetMenu = GetActiveMenu(pfMenuFile);
/*
* 只要有错就返回错
*/
if (iRetAdd == -1 || iRetMenu == -1)
return(-1);
/*
* 只要有警告就返回警告
*/
if (iRetAdd < 0 || iRetMenu < 0)
return(-2);
return(0);
}
/*
* 获取临时增加的菜单结构信息
*/
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 附加菜单项文件(%s)分析\n\n", sDate, sTime, MENU_add);
/*
* 分配菜单信息临时结构空间
*/
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);
}
/*
* 预处理附加的菜单选择项
*/
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 标示菜单项定义开始 */
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: 数据格式错! (忽略)\n", iLine);
cWarnFlag = 1;
continue;
}
strcpy(sTmpStr, &sTmpStr[j]);
iCount = zut_get_seperate(sTmpStr, '|');
if (iCount < { /* 该行数据不完整,忽略 */
if ( j >; 0)
fprintf(pfErrorFile, "行%d: 数据不完整,可能头上缺\'|\'! (忽略)\n", iLine);
else
fprintf(pfErrorFile, "行%d: 数据不完整! (忽略)\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)域选择项处理类型只应为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: 以下域有错", iLine);
fprintf(pfErrorFile, "%s\n", sErrorString);
cWarnFlag = 1;
continue;
}
pMenuItem.iLine = iLine;
i++;
}
iItemAddCount = i;
/*
* 处理附加的菜单项
*/
#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: 数据格式错! (忽略)\n", iLine);
cWarnFlag = 1;
continue;
}
strcpy(sTmpStr, &sTmpStr[j]);
iCount = zut_get_seperate(sTmpStr, '|');
if (iCount < 5) { /* 该行数据不完整,忽略 */
if ( j >; 0)
fprintf(pfErrorFile, "行%d: 数据不完整,可能头上缺\'|\'! (忽略)\n", iLine);
else
fprintf(pfErrorFile, "行%d: 数据不完整! (忽略)\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)域对应的菜单项(%s)不允许更改, 此行忽略。\n",
j+1, pMenuItem[j].sMenuId);
cErrorFlag = 1;
continue;
}
if (k == iMenuCount) {
/*
* 若找不到则在后面新添一项
*/
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坐标应在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坐标应为偶数", 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坐标应在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坐标应为偶数", 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)域显示格式只应为H(横向)或V(纵向)", j+1);
strcat(sErrorString, sTmpString);
cErrorFlag = 1;
break;
}
SMenu[k].iDispFormat = sTmpBuffer[0];
break;
default:
break;
}
}
if (cErrorFlag == 1) {
fprintf(pfErrorFile, "行%d: 以下域有错", iLine);
fprintf(pfErrorFile, "%s\n", sErrorString);
cWarnFlag = 1;
continue;
}
/*
* 将子菜单选择项置为空,以后通过view/nas.menu具体定义
*/
SMenu[k].iMenuItemSet[0] = -1;
i++;
}
/*
* 正式处理附加菜单选择项
*/
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行对应的函数(%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行对应的函数(%s)不存在, 此行忽略。\n",
pMenuItem[j].iLine, pMenuItem[j].sProcName);
cWarnFlag = 1;
continue;
}
}
if (pMenuItem[j].cProcType == 'M') {
/*
* 在SMenu[]中查找sMenuId, 若不存在,则报错
*/
iMenuOrd = GetMenuOrd(pMenuItem[j].sMenuId);
if (iMenuOrd < 0) {
fprintf(pfErrorFile, "第%d行%s对应的菜单项在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行对应的函数(%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行对应的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行对应的选择项(%s)不允许更改, 此行忽略。\n",
pMenuItem[j].iLine, pMenuItem[j].sItemId);
cWarnFlag = 1;
continue;
}
if (k == iMenuItemCount) {
/*
* 若找不到则在后面新添一项
*/
strcpy(SMenuItem[k].sItemId, pMenuItem[j].sItemId);
SMenuItem[k].cReplace = 1; /* 新增项允许更改 */
strcpy(SMenuItem[k].sName, pMenuItem[j].sItemName);
iMenuItemCount ++;
if (iMenuItemCount >;= MAX_MENU_ITEMS) {
fprintf(pfErrorFile, "第%d行对应的选择项(%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 附加菜单项文件(%s)分析\n\n", sDate, sTime, MENU_add);
fclose(pfErrorFile);
if (cWarnFlag == 1)
return(-2);
else
return(0);
}
/*
* 根据选择项标识查找选择项序号
*/
GetItemOrd(pcItemId)
char *pcItemId;
{
int i;
for (i = 0; i < iMenuItemCount; i++) {
if (!strcmp(SMenuItem.sItemId, pcItemId))
return(i);
}
return(-1);
}
/*
* 根据菜单标识查找菜单序号
*/
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
/*
* 获取实际使用的菜单结构
*/
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 运行菜单定义文件(%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:菜单中未定义选择项!\n", iLine-1);
else if (cLastFlag == LINE_ITEM)
fprintf(pfErrorFile, "\t行%d:未定义选择项说明!\n", iLine-1);
else if (cLastFlag == LINE_NOTE || cLastFlag == LINE_SHELL)
fprintf(pfErrorFile, "\t行%d前面:未有'$'标识行!\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_"); /* 取菜单标识 */
if (pcIdOff != NULL) {
strncpy(sMenuId, pcIdOff, 9);
sMenuId[9] = '\0';
} else {
fprintf(pfErrorFile, "\t行%d: 无菜单标识号!\n", iLine);
cErrorFlag ++;
iMenuNo = -1;
break;
}
if ((iMenuNo = GetMenuOrd(sMenuId)) < 0) {
fprintf(pfErrorFile, "\t行%d: 菜单标识号\"%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前面:未定义选择项说明!\n", iLine);
cWarnFlag ++;
}
cLastFlag = LINE_ITEM;
pcIdOff = (char *)strstr(sTmpStr, "I_"); /* 取选择项标识 */
if (pcIdOff != NULL) {
strncpy(sItemId, pcIdOff, 9);
sItemId[9] = '\0';
} else {
fprintf(pfErrorFile, "\t行%d: 无选择项标识号!\n", iLine);
/* 将此项忽略,不算致命错误 */
cWarnFlag ++;
iItemNo = -1;
break;
}
if ((iItemNo = GetItemOrd(sItemId)) < 0) {
fprintf(pfErrorFile, "\t行%d: 选择项标识号%s有误!\n", iLine, sMenuId);
/* 将此项忽略,不算致命错误 */
cWarnFlag ++;
iItemNo = -1;
break;
} else {
if (iMenuNo >;= 0) {
SMenu[iMenuNo].iMenuItemSet[cItemOrd] = iItemNo;
SMenuItem[iItemNo].iPower = 1;
cItemOrd ++;
} else {
/* 由于菜单非法,故其下的选择项也非法 */
iItemNo = -1;
}
}
break;
case '#':
if (cLastFlag == LINE_MENU || cLastFlag == LINE_FIRST) {
fprintf(pfErrorFile, "\t行%d前面:未定义选择项! (忽略)\n", iLine);
cWarnFlag ++;
break;
} else if (cLastFlag == LINE_NOTE) {
fprintf(pfErrorFile, "\t行%d:选择项说明多行定义! (忽略)\n", iLine);
cWarnFlag ++;
break;
} else if (cLastFlag == LINE_SHELL) {
fprintf(pfErrorFile, "\t行%d:注释行不应出现在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:此处不应出现Shell程序定义! (忽略)\n", iLine);
break;
case '$':
if (cLastFlag == LINE_ITEM) {
fprintf(pfErrorFile, "\t行%d前面:选择项无说明!\n", iLine);
cWarnFlag ++;
} else if (cLastFlag == LINE_MENU) {
fprintf(pfErrorFile, "\t行%d前面:菜单无选择项定义!\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 ********* 有错误!! *******\n");
else if (cWarnFlag)
fprintf(pfErrorFile, "\n ********* 有警告!! *******\n");
else
fprintf(pfErrorFile, "\n ********* OK !! *******\n");
getdatef(sDate, "-");
gettimef(sTime, ":");
fprintf(pfErrorFile, "\n%s %s ****Finish 运行菜单结构定义文件(%s)分析\n\n", sDate, sTime, MENU_f);
fclose(pfErrorFile);
if (cErrorFlag)
return(-1);
else if (cWarnFlag)
return(-2);
return(0);
}
/*
* 功能: 初始化菜单项信息
* 入口: 菜单号, 菜单信息文件句柄
* 出口: 菜单选择项名
* 选择项说明
* 选择项首字母
* 选择项的帮助文件索引
* 当前选择项所在行的首尾项号
*/
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_"); /* 取菜单标识 */
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_"); /* 取选择项标识 */
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);
} |
|