AIX仿真SCO UNIX的MENU驱动.docx
- 文档编号:28172295
- 上传时间:2023-07-09
- 格式:DOCX
- 页数:14
- 大小:16.18KB
AIX仿真SCO UNIX的MENU驱动.docx
《AIX仿真SCO UNIX的MENU驱动.docx》由会员分享,可在线阅读,更多相关《AIX仿真SCO UNIX的MENU驱动.docx(14页珍藏版)》请在冰豆网上搜索。
AIX仿真SCOUNIX的MENU驱动
AIX仿真SCOUNIX的MENU驱动
王光红
AIX有CURSES库,但没有MENU驱动,这样给用户这样的问题:
一需要自己写MENU程序,二是代码从SCOUNIX移植到AIX,如果用到MENU就无法移植。
本人经过对SCOUNIX的MENU研究,成功地编写了AIX仿真SCOUNIX的MENU驱动代码:
#include
#include"menu.h"//将SCOUNIX的menu.h照搬到AIX上
#include
staticintindex=0;
ITEM*new_item(char*name,char*desc)
{
ITEM*i;
i=(ITEM*)malloc(sizeof(ITEM));
i->name.str=name;
i->name.length=strlen(name);
i->description.str=desc;
i->description.length=strlen(desc);
i->index=index++;
i->imenu=(MENU*)0;
i->value=0;
i->userptr=(char*)0;
i->opt=0x00;
i->status=0;
i->y=0;
i->x=0;
i->left=(ITEM*)0;
i->right=(ITEM*)0;
i->up=(ITEM*)0;
i->down=(ITEM*)0;
returni;
}
MENU*new_menu(ITEM**item)
{
MENU*m;
intn=0;
index=0;
m=(MENU*)malloc(sizeof(MENU));
memset(m,0L,sizeof(MENU));
m->items=item;
m->curitem=item[0];
for(n=m->nitems=0;item[n];m->nitems++,n++){
if(m->namelen
m->namelen=item[n]->name.length;
if(m->desclen
m->desclen=item[n]->description.length;
}
m->marklen=1;
m->width=m->namelen+m->desclen+1+m->marklen;
m->rows=m->height=m->nitems;
m->cols=1;
m->frows=16;
m->fcols=1;
m->itemlen=m->width;
m->pad='';
m->toprow=0;
returnm;
}
intstrncmpi(char*s1,char*s2,intlen)
{
inti;
chart1[512],t2[512];
strcpy(t1,s1);
strcpy(t2,s2);
for(i=0;i if(isupper(t1[i]))t1[i]=tolower(t1[i]); for(i=0;i if(isupper(t2[i]))t2[i]=tolower(t2[i]); returnstrncmp(t1,t2,len); } intset_menu_pattern(MENU*m,char*pattern) { intlen,n,s; ITEM*ci; len=strlen(pattern); n=m->curitem->index; ci=m->curitem; for(s=0;s n%=m->nitems; if(strncmpi(m->items[n]->name.str,pattern,len)==0){ m->pattern=pattern; m->curitem=m->items[n]; returnE_OK; } } returnE_NO_MATCH; } intset_menu_mark(MENU*m,char*mark) { m->mark=mark; m->marklen=strlen(mark); m->width+=m->marklen; m->itemlen+=m->marklen; m->width=m->itemlen; return0; } intset_menu_pad(MENU*m,intpad) { m->pad=pad; return0; } intset_menu_format(MENU*m,inty,intx) { m->frows=y; m->fcols=x; if(x>m->cols){ if(x>=m->nitems){ m->cols=m->nitems; m->rows=1; } else{ m->cols=x; m->rows=(int)(m->nitems/x)+(m->nitems%x>0); } } m->height=y y: m->rows; m->width=(x x: m->cols)*m->itemlen-1; return0; } intscale_menu(MENU*m,int*rows,int*cols) { *rows=m->height; *cols=m->width; return0; } intset_menu_win(MENU*m,WINDOW*w) { m->win=w; } intset_menu_sub(MENU*m,WINDOW*w) { m->sub=w; } staticchar*menu_lable(intn,MENU*m) { staticcharlable[81]; chartag[2]; ints,t; tag[0]=m->pad; tag[1]=0; memset(lable,0L,sizeof(lable)); if(n>=m->nitems)returnlable; s=m->itemlen-m->items[n]->name.length-m->items[n]->description.length-m->marklen-1; sprintf(lable,"%s",m->items[n]->name.str); for(t=0;t strcat(lable,m->items[n]->description.str); returnlable; } staticvoidstart_line(MENU*m) { if(m->curitem->index &&m->curitem->index>m->toprow)return; if(m->nitems>=m->height+m->curitem->index){ if(m->toprow>=m->curitem->index) m->toprow=m->curitem->index; else m->toprow+=m->cols; } else{ m->toprow=m->nitems-m->height; } } staticintcompute_seat(MENU*m) { intn,y,x,t; for(n=0;n t=n-1; if(t<0)m->items[n]->left=m->items[m->nitems-1]; elsem->items[n]->left=m->items[t]; t=n+1; if(t>=m->nitems)m->items[n]->right=m->items[0]; elsem->items[n]->right=m->items[t]; t=n-m->cols; if(t<0)m->items[n]->up=m->items[m->nitems-1]; elsem->items[n]->up=m->items[t]; t=n+m->cols; if(t>=m->nitems)m->items[n]->down=m->items[0]; elsem->items[n]->down=m->items[t]; } } intpost_menu(MENU*m) { touch_menu(m); wrefresh(m->sub); } inttouch_menu(MENU*m) { inty,x,s,cy,cx; char*lable; chtypeattrs; if(m==NULL)return-1; if(m->sub==NULL)return-2; unpost_menu(m); start_line(m); for(s=m->toprow,y=0;y for(x=0;x lable=menu_lable(s,m); if(s==m->curitem->index){ attrs=m->sub->_attrs; wattrset(m->sub,A_REVERSE|m->sub->_attrs); mvwprintw(m->sub,y,x*(m->itemlen),"%s%s",m->mark,lable); cy=y,cx=x*(m->itemlen); wattrset(m->sub,attrs); } else mvwprintw(m->sub,y,x*(m->itemlen)+m->marklen,lable); s++; } wmove(m->sub,cy,cx); wmove(m->win,cy+1,cx+1); compute_seat(m); } intunpost_menu(MENU*m) { werase(m->sub); wrefresh(m->win); } ITEM**menu_items(MENU*m) { returnm->items; } ITEM*current_item(MENU*m) { returnm->curitem; } intitem_index(ITEM*i) { returni->index; } intfree_item(ITEM*i) { free(i); return0; } intfree_menu(MENU*m) { free(m); return0; } intmenu_driver(MENU*m,intc) { switch(c){ caseREQ_LEFT_ITEM: if(m->curitem->left){ m->curitem=m->curitem->left; touch_menu(m); } break; caseREQ_RIGHT_ITEM: if(m->curitem->right){ m->curitem=m->curitem->right; touch_menu(m); } break; caseREQ_UP_ITEM: if(m->curitem->up){ m->curitem=m->curitem->up; touch_menu(m); } break; caseREQ_DOWN_ITEM: if(m->curitem->down){ m->curitem=m->curitem->down; touch_menu(m); } break; caseREQ_SCR_ULINE: caseREQ_SCR_DLINE: caseREQ_SCR_DPAGE: caseREQ_SCR_UPAGE: caseREQ_FIRST_ITEM: m->curitem=m->items[0]; touch_menu(m); break; caseREQ_LAST_ITEM: break; caseREQ_NEXT_ITEM: if(m->curitem->index m->curitem=m->items[m->curitem->index+1]; else m->curitem=m->items[0]; touch_menu(m); break; caseREQ_PREV_ITEM: if(m->curitem->index>0) m->curitem=m->items[m->curitem->index-1]; else m->curitem=m->items[m->nitems-1]; touch_menu(m); break; caseREQ_TOGGLE_ITEM: caseREQ_CLEAR_PATTERN: caseREQ_BACK_PATTERN: caseREQ_NEXT_MATCH: caseREQ_PREV_MATCH: break; } wrefresh(m->sub); returnE_OK; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- AIX仿真SCO UNIX的MENU驱动 AIX 仿真 SCO UNIX MENU 驱动