📄 help
字号:
BEGIN:sample.h#include "apmenu.h"#include "menu.h"#define MAX_X 79#define MAX_Y 23#define MIN_X 0#define MIN_Y 0#define HELP_X 40#define HELP_Y 5#define HELP_W 38#define HELP_H 15struct ip_link { /**** IP TREE 附信息******/ char ipaddr[20]; char hostname[52]; char domain[52]; bool connect_bz;};typedef struct ip_link ST_IPLINK;END:sample.hBEGIN:开始 联机帮助系统 1998/11 说明: 从HELPFILE读取信息生成联机帮助 提示:[End]退出,[Home]菜单,光标移到<<..>>按回车进入该主题 提示:[BackSpace] 退出一层菜单, [回车] 进行选择 END:开始BEGIN:使用指南 =========== 使用指南 ======== <<开始>> <<sample.h>> <<sample.c>> <<apmenu.h>> <<tool.c>> <<tool1.c>>END:使用指南BEGIN:sample.c/***** ** ***/#include "sample.h"#define M_EXIT 18#define M_HELP 71#define M_CONNECT_WINDOW 61main( argc, argv)int argc;char *argv[];{ int i; int y,x,width,height; SAVESCR *scr; TREE_CONTROL *tree; WINDOW *w; int Max_item; int ret,retflag=0; char s[100]; int Select_tree_move ( ); int Select_tree_keydown ( ); MENU_ITEM menu_bar[]={ 1, "0", "连接[C] ~发送[S] ~接收[R] ~协议[P] ~设置[O] ~窗口[W] ~帮助[H]", "csrpowh", 2, "1", "节点刷新[W] ~连接刷新[B] ~连接节点[C] ~节点信息[M] ~增加节点[A] ~删除节点[D] ~打印[P] ~退出[E] ", "wbcmadpe", 2, "2", "录入[W] ~开始发送[S]" , "ws", 2, "3", "录入[W] ~开始接收[R]" , "wr", 2, "4", "TCP/IP[T]-> ~SPX/IPX[S] ~SNA[I] ~NETBIOS[N]" , "tsin", 3, "41", "TCP ~UDP ~ICMP ~ARP ~RARP " , "", 2, "5", "连接[C] ~无连接[N]" , "cn", 2, "6", "连接窗口[C] ~发送窗口[S] ~接收窗口[R] ~协议窗口[P] ~状态窗口[Z] ~出错窗口[E] " , "csrpze", 2, "7", "帮助[H] ~主题[T] ~关于[A] " , "hta", }; initscr(); noecho(); w = newwin(23,79,0,0); wclear(w); wrefresh(w); wsetcolor( w, WHITE, M_BC ); for (i=MIN_X;i<MAX_X;i++) mvwaddstr( w, MIN_Y, i , " " ); wsetcolor( w, BLACK, WHITE ); for (i=MIN_X;i<MAX_X;i++) mvwaddstr( w, MAX_Y-1, i , " " ); mvwaddstr( w, MAX_Y-1, MIN_X , "END 键弹出菜单 " ); mvwaddstr( w, MAX_Y-1, MAX_X - 33 , "网络管理系统 NETCON V1.0, 1998/11"); tree = (TREE_CONTROL *)init_treecontrol ( w, MIN_Y+2,MIN_X+2,MAX_Y-1-3,MAX_X/2,WHITE, BLACK, RED, CYAN ); tree_add_item( tree, (TREE_ITEM *)NULL,"TCP 网络","",1); Init_host( tree ) ; trigger_tree_move( tree, Select_tree_move ) ; generate_treelist( tree ); if ( tree->num != tree->i ) printf( "初始化出错: num =%d, but i =%d",tree->num,tree->i); show_tree( tree ); Max_item= sizeof(menu_bar)/sizeof(struct menu_item_code); while(1){ ret = Do_menu(w, menu_bar, NULL, Max_item, 0, 0, 0, 0) ; switch(ret){ case M_CONNECT_WINDOW: do_tree( tree ); break; case M_EXIT: retflag = 1; break; case M_HELP: /* scr = Saverect(HELP_H, HELP_W, HELP_Y, HELP_X); */ Disp_Help( w, HELP_Y, HELP_X, HELP_H, HELP_W, "使用指南", 0 );/* Putrect(w,HELP_Y,HELP_X,scr); Free(scr);*/ break; } if ( retflag == 1 ) break; } clear(); refresh(); endwin(w);}Init_host(tree) TREE_CONTROL *tree;{ char s[1024], ipaddr[20], hostname[256], domain[256]; char *p; FILE *fp; ST_IPLINK *clink = NULL; TREE_ITEM *item; if ( (fp=fopen("/etc/hosts", "r" )) == NULL ) { printf( "file /etc/hosts not found!" ); return(-1); } while ( !feof(fp) ) { fgets( s, 256, fp ); for(p=s;(*p==Key_tab||*p==Key_space)&&(*p);p++); if ( *p == '#' ) continue; for(*ipaddr='\0';*p!=Key_space&&*p!=Key_tab&&*p!=Key_nxtrow&& (*p);p++) { sprintf( ipaddr, "%s%c", ipaddr, p[0] ) ; } for(;(*p==Key_tab||*p==Key_space)&&(*p);p++); for(*hostname='\0';*p!=Key_space&&*p!=Key_tab&&*p!=Key_nxtrow&& (*p);p++) { sprintf( hostname, "%s%c", hostname, p[0] ) ; } for(;(*p==Key_tab||*p==Key_space)&&(*p);p++); for(*domain='\0';*p!=Key_space&&*p!=Key_tab&&*p!=Key_nxtrow&& (*p);p++) { sprintf( domain, "%s%c", domain, p[0] ) ; } if ( *ipaddr != '\0' ) { if ( !(item =(TREE_ITEM *)Find_tree_str ( tree , domain ))) { if ( *domain != '\0' ) { tree_add_item( tree, tree->startitem, domain,NULL,1); item = tree->curitem; } else { item = tree->startitem; } } clink = (ST_IPLINK *) malloc(sizeof(ST_IPLINK)); strcpy( clink->ipaddr, ipaddr ) ; strcpy( clink->hostname, hostname ) ; strcpy( clink->domain, domain ) ; clink->connect_bz = FALSE ; tree_add_item( tree, item, hostname,clink,1); } } fclose( fp );}/* ** Move the item of tree ** Show the ipaddr in the help bar***/Select_tree_move ( tree )TREE_CONTROL *tree;{ ST_IPLINK *link = ((ST_IPLINK *)((TREE_ITEM *)Getcuritem(tree))->link); if ( link ) Show_help( tree->win, link->ipaddr ); else Show_help( tree->win, ((TREE_ITEM *)Getcuritem(tree))->text); }Select_tree_keydown ( tree, ch )TREE_CONTROL *tree;int ch;{ char s[10]; sprintf( s, "%d", ch ) ; Show_help( tree->win, s ); return 0 ;}Show_help( WINDOW *win, char *s ){ int i ; wsetcolor( win, BLACK, WHITE ); for (i=MIN_X;i<40;i++) mvwaddstr( win, MAX_Y-1, i , " " ); mvwaddstr( win, MAX_Y-1, MIN_X , s ) ; wrefresh(win);}END:sample.cBEGIN:tool.c#include "./apmenu.h"/***** 保存屏幕***/SAVESCR *Saverect(w, height, width, y, x)WINDOW *w;int height;int width;int y;int x;{ int i, j, c, k=0; int *str; SAVESCR *Savescr; if(height>25||width>80)return NULL; str=(int *)malloc(height*width*sizeof(int)); Savescr=(SAVESCR *)malloc(sizeof(SAVESCR)); if(Savescr==NULL||str==NULL)return NULL; Savescr->height=height; Savescr->width=width; Savescr->p=str; for(j=y;j<y+height;j++) for(i=x;i<x+width;i++){ c=mvwinch(w,j,i); Savescr->p[k]=c; k++; } wrefresh(w); return Savescr;}/***** 恢复屏幕***/int Putrect(w, y, x, Savescr)WINDOW *w;int y;int x;SAVESCR *Savescr;{ int i,j,k=0; if(Savescr==NULL)return FALSE; wsetcolor(w,0,0); for(j=y;j<y+Savescr->height;j++) for(i=x;i<x+Savescr->width;i++){ mvwaddch(w,j,i,Savescr->p[k]); k++; } wrefresh(w); return TRUE;}/***** 释放屏幕内存***/int Free(Savescr)SAVESCR *Savescr;{ int i,j; i=free(Savescr->p); j=free(Savescr); if(i==-1||j==-1)return FALSE; else return TRUE;}/***** 画框函数***/int Box(w, row, wide, y, x)WINDOW *w;int row;int wide;int y;int x;{ int i,y1,x1; y1=y+row;x1=x+wide; mvwaddstr(w,y,x,"┏"); mvwaddstr(w,y,x1,"┓"); mvwaddstr(w,y1,x1,"┛"); mvwaddstr(w,y1,x,"┗"); for(i=x+2;i<=x1-2;i+=2){ mvwaddstr(w,y,i,"━"); mvwaddstr(w,y1,i,"━"); } for(i=y+1;i<=y1-1;i+=1){ mvwaddstr(w,i,x,"┃"); mvwaddstr(w,i,x1,"┃"); } wrefresh(w); return TRUE;}/***** 画线函数*****/int Line( w, height, width, y, x)WINDOW *w;int height;int width;int y;int x;{ int i,j; if (height==0) for (i=x;i<x+width;i++) mvwaddch(w,y,i,'-'); else if (width==0) for (i=y;i<y+height;i++) mvwaddstr(w,i,x,"┃"); wrefresh(w);}/***** 填充正方形函数*****/int Clear( w, height, wide, y, x, color)WINDOW *w;int height;int wide;int y;int x;int color;{ int i,j; wsetcolor(w,1,color); for(i=y;i<=(y+height);i++)for(j=x;j<(x+wide);j++) mvwaddch(w,i,j,' '); wrefresh(w);}/***** 获取字符串函数*****/char *Getstr( w, y, x, maxlen,listlen, color, bkcolor)WINDOW *w;int y;int x;int maxlen;int listlen;int color;int bkcolor;{ int i=0,j=0,ch; char *str; str=(char *)malloc(80); wsetcolor(w,color,bkcolor); wmove(w,y,x); wrefresh(w); while(1){ ch=getch(); if(ch==Key_esc){if(ch=getch()==91){ ch=getch(); if(ch==Key_right){ i++; wmove(w,y,x+i); wrefresh(w); } if(ch==Key_left){ i--; wsetcolor(w,bkcolor,bkcolor); mvwaddch(w,y,x+i,' '); wmove(w,y,x+i); wrefresh(w); wsetcolor(w,color,bkcolor); } } } else { if(ch==Key_enter)break; if(ch!=Key_backspace){ mvwaddch(w,y,x+i,ch); wrefresh(w); str[i]=(char)ch; i++; } else { i--; wsetcolor(w,bkcolor,bkcolor); mvwaddch(w,y,x+i,' '); wmove(w,y,x+i); wrefresh(w); wsetcolor(w,color,bkcolor); } } } str[i]='\0'; return str;}/***** 信息框函数*****/int MessageBox(w, y,x,strs,strt,flags)WINDOW *w;int y;int x;char *strs;char *strt;int flags;{ int height=0,width=0,i=0,j=0,k=0; int color1=RED,color2=CYAN; char *p,str1[60],str2[2],OK1[]="<Ok> Cancle ",CL1[]=" Ok <Cancle>",ch; SAVESCR *Scr; p=strs; while(p[i]!='\0'){ if(p[i]=='~'){ height++; j=Min(j+1,60); width=Max(width,j); j=0; i++; } else{ i++; j++; } } if(height==0){ width=j; width=Min(width,60); } else width=Max(width,j); height=height+5; if(width<17) width=17; width=width+12; Scr=(SAVESCR *)Saverect(w,height+2,width+2,y,x); j=y;k=x; Clear(w,height,width,y+1,x+2,GRAY); if(strlen(strt)>0){ wsetcolor(w,BLACK,GRAY); mvwaddstr(w,y,x,"━"); Clear(w,0,width-2,y,x+2,BLUE); wsetcolor(w,LT_WHITE,BLUE); wmove(w,y,x+(width-strlen(strt))/2); waddstr(w,strt); Clear(w,height-1,width,y+1,x,color2); } else Clear(w,height,width,y,x,color2); wmove(w,y,x+6); y=y+2; p=strs; i=0; wsetcolor(w,color1,color2); str1[0]='\0'; while(*p!='\0'){ if(*p=='~'){ p++; i=0; wmove(w,y++,x+6); waddstr(w,str1); wrefresh(w); str1[0]='\0'; } if(i>59){ while(*p!='~') p++; i=0; p++; wmove(w,y++,x+6); waddstr(w,str1); wrefresh(w); str1[0]='\0'; } str2[0]=*p; str2[1]='\0'; strcat(str1,str2); i++; p++; } wmove(w,y++,x+6); waddstr(w,str1); wrefresh(w); str1[0]='\0';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -