www.pudn.com > 外壳示例3.rar > 8111.c


 
#include"80bao.h" 
 
/*------------------base function ----------*/ 
 
#define Enter printf("\n"); 
 
int Print(ElementType *e) 
{ 
 printf("%c",*e); 
 return 1; 
} 
 
int dingwei(void) 
{ 
 char panfu; 
 char *dir; 
 dir=(char *)malloc(20*sizeof(char)); 
 if(!dir) return 0; 
 panfu='a'+getdisk(); 
 getcurdir(0,dir); 
 printf("%c:\\",panfu-32); 
 printf("%s>",dir); 
 return 1; 
} 
 
 
int huichuan(LinearList *ll,ElementType *str) 
{ 
 int i; 
 ChainNode *p; 
 p=ll->head; 
 for(i=0;p->next!=ll->head;i++) 
 { 
  p=p->next; 
  str[i]=p->data; 
 } 
 str[i-1]='\0'; 
 return 1; 
} 
 
 
void jingru() 
{ 
 textcolor(RED); 
 cprintf("\n\n\rThis is a command shell on DOS ! Maker: Zhang Yong qiang. Welcome you to it !\n"); 
 textcolor(WHITE); 
 cprintf("\n"); 
} 
 
void tuichu() 
{ 
  textcolor(GREEN); 
  cprintf("\n\rUnload DOS shell programm! Maker:ZhangYongqiang. Welcome you to use it again!"); 
  textcolor(WHITE); 
  cprintf("\n\r"); 
  exit(1);   /*     weishenmo */ 
} 
 
/*-------------------   main    ---------------------------*/ 
 
main() 
{ 
 int i,shu,kun=1,xx,yy,fu; 
 char a; 
 char *s; 
 
 LinearList *ll; 
 
 ChainNode *p; 
 s=(char *)malloc(80*sizeof(char)); 
 
 ll=(LinearList *)CreateList(); 
 
 jingru(); 
 
 printf("\r"); 
head: 
 dingwei(); 
 while(kun) 
  { 
    ListAppend(ll,' '); 
    MoveBegin(ll); 
    while((shu=bioskey(0))!=0x1c0d) 
      { 
	switch(shu) 
	  { 
	    case 0x0e08: 
	     { 
	       xx=wherex(); 
	       yy=wherey(); 
 
	       if( MovePrior(ll)==0 ) break; 
	       if(ll->cursor.cp==ll->head->prior) break; 
	       if(ListDeleteCurrent(ll)==0) break; 
 
	       gotoxy(1,yy); 
	       printf("                                                                      \r"); 
	       dingwei(); 
	       ListTraverse(ll,Print,2); 
 
	       gotoxy(xx-1,yy); 
 
	       break; 
	     }/* 退格键 */ 
 
	    case 0x4b00: 
	     { 
	       xx=wherex(); 
	       yy=wherey(); 
	       if( MovePrior(ll) == 0 ) break; 
	       gotoxy(1,yy); 
	       printf("                                                                      \r"); 
	       dingwei(); 
	       ListTraverse(ll,Print,2); 
 
	       gotoxy(xx-1,yy); 
	       break; 
	     } /* 左移*/ 
 
	    case 0x3d00: 
	     { 
	       ListDelete(ll,1); 
	       for(fu=0;s[fu]!='\0';fu++) 
		ListAppend(ll,s[fu]); 
		ListTraverse(ll,Print,2); 
	       break; 
	     } /* F3 */ 
 
	    case 0x4d00: 
	     { 
	       xx=wherex(); 
	       yy=wherey(); 
 
	       if(MoveNext(ll)==0) break; 
 
	       gotoxy(1,yy); 
	       printf("                                                                    \b\r"); 
	       dingwei(); 
	       ListTraverse(ll,Print,2); 
 
	       gotoxy(xx+1,yy); 
	       break; 
	     }  /*右移*/ 
 
	    case 0x5300: 
	     { 
		xx=wherex(); 
		yy=wherey(); 
		if(ll->cursor.cp==ll->head) break; 
                if( ListDeleteCurrent(ll)==0 ) break; 
		gotoxy(1,yy); 
		printf("                                                                      \r"); 
		dingwei(); 
		ListTraverse(ll,Print,2); 
 
		gotoxy(xx,yy); 
		break; 
	     }   /*删除*/ 
 
	    default: 
	     { 
		 a=(char *)shu; 
		 if(ListInsertCurrent(ll,a)==0) break; 
		 xx=wherex(); 
		 yy=wherey(); 
		 gotoxy(1,yy); 
		 printf("                                                                      \r"); 
		 dingwei(); 
		 ListTraverse(ll,Print,2); 
 
		 gotoxy(xx+1,yy); 
		 break;  /*插入 */ 
	     }/* default */ 
	  } 
      } /*while2*/ 
 
 
   huichuan(ll,s); 
 
   ClearList(ll); 
 
   if( !strcmp(s,"unload\0") ) 
     tuichu(); 
   else 
    { 
      Enter; 
      if(s[0]==0) goto head; 
      system(s); 
 
      dingwei(); 
    }/*else*/ 
 } /*while1*/ 
 
 getch(); 
} /*main*/