📄 this.cpp
字号:
#define MAXCOMSTR 4
#define I 1
#define IB 2
#define A 3
#define L 4
#define LN 5
#define D 6
#define F 7
#define C 8
#define R 9
#define P 10
#define S 11
#define E 12
#define Q 13
#define H 14
#define W 15
#define CURRENT 17
#define _max_input 512
int _file_exist=0; //file is not exist
int _file_modified=0; //file is modified
///////////////////////////////////////////////////////////////////////////////////////////
#include "fileswap.h"
///////////////////////////////////////////////////////////////////////////////////////////
int carryout(char *tempchar); //get the command and carry out
int normalspace(char *tempchar); //permit users to input extra space
void stringtolower(char *tempchar);//permit users to comfound the upper and lower
///////////////////////////////////////////////////////////////////////////////////////////
/////////////////initial face//////////////////////////////////////////////////////////////
void IniFace(void)
{
system("cls");
printf("\n\n\n");
printf(" %c",12);
for(int i=1;i<=76;i++)
printf("%c",4);
printf("%c\n",12);
printf(" %c",12);
printf(" ");
printf("%c\n",12);
printf(" %c",12);
printf(" WELCOME USING EDLINE 1.0 ");
printf("%c\n",12);
printf(" %c",12);
printf(" ");
printf("%c\n",12);
printf(" %c",12);
printf(" ------------- CopyRight: 99708 work group ");
printf("%c\n",12);
printf(" %c",12);
printf(" Partner: BaiYan,SunMeng,SunKewei,ZhangHui ");
printf("%c\n",12);
printf(" %c",12);
for(i=1;i<=76;i++)
printf("%c",4);
printf("%c\n",12);
getch();
system("cls");
}
void stringtolower(char *tempchar)
{
int length=0,i=0;
length=strlen(tempchar);
for(i=0;i<length;i++)
{
tempchar[i]=tolower(tempchar[i]);
}
}
///
int normalspace(char *tempchar)
{
char *charposi="";
if(strlen(tempchar)==0)
{
return 0;
}
charposi=tempchar;
if( *charposi==' ')
{
while(*charposi==' ')
{
charposi++;
}
if((*charposi=='c' || *charposi=='C') && *(charposi+1)==' ')
{
strcpy(tempchar,charposi);
return 2;
}
strcpy(tempchar,charposi);
normalspace(tempchar);
}
if(*charposi!=' ')
{
if((*charposi=='c' || *charposi=='C') && *(charposi+1)==' ')
{
strcpy(tempchar,charposi);
return 2;
}
while(strlen(charposi)!=0)
{
if(*charposi==' '&& (*(charposi+1)==' '||strlen(charposi+1)==0))
{
strcpy(charposi,charposi+1);
}
else
{
charposi++;
}
}
}
return 1;
}
//////////////////////////////////////////////////////////////////////////////////////////////
int carryout(char *tempchar,FileSwap &fi)
{
int stringcount=0, posi=0,charnum=0,countnum=1;
int commandnumber=0,commandname=0;
char *charpointer[MAXCOMSTR+1];
char cmdline[MAXCOMSTR][50];
for(int i=0; i<MAXCOMSTR; i++)
{
charpointer[i]=cmdline[i];
}
if( normalspace(tempchar) == 2)
{
strcpy(charpointer[0],"c");
int length=strlen(tempchar);
if(length<5)
{
printf("--------command is error---------\n");
return -1;
}
for(int i=length-1; i>1; i--)
{
if(*(tempchar+i)!=' ' )
{
*(tempchar+i+1)=NULL;
break;
}
}
if( *(tempchar+i)<='9' && *(tempchar+i)>='0')
{
for( ; i>1; i--)
{
if(*(tempchar+i-1)==' ')
{
strcpy(charpointer[3],tempchar+i);
*(tempchar+i-1)=NULL;
break;
}
}
for(i-=2; i>1; i--)
{
if(*(tempchar+i)!=' ' )
break;
}
if( *(tempchar+i)<='9' && *(tempchar+i)>='0')
{
for( ; i>1; i--)
{
if(*(tempchar+i-1)==' ')
{
strcpy(charpointer[2],tempchar+i);
*(tempchar+i-1)=NULL;
if(*(tempchar+1)==' ' )
{
strcpy(charpointer[1],tempchar+2);
stringcount=3;
break;
}
else
{
printf("--------command is error---------\n");
return -1;
}
}
}
}
else
{
printf("--------command is error---------\n");
return -1;
//strcpy(charpointer[2],charpointer[3]);
//strcpy(charpointer[3],"1");
}
}
else
{
if(*(tempchar+1)==' ' )
strcpy(charpointer[1],tempchar+1);
else
{
printf("--------command is error---------\n");
return -1;
}
}
}
else
{
stringtolower(tempchar);
for(posi=0;posi<MAXCOMSTR;posi++)
{
strcpy(charpointer[posi],"\x0");
}
charnum=strlen(tempchar);
charpointer[0]=tempchar;
for(charnum=0;tempchar[charnum]!=NULL;charnum++)
{
if(tempchar[charnum]==' ')
{
stringcount+=1;
tempchar[charnum]='\x0';
charpointer[countnum]=tempchar+charnum+1;
countnum++;
}
}
}
charpointer[4]="";
if(stringcount>=MAXCOMSTR){return -1;}
if(stringcount==0&&strlen(tempchar)==0){return 0;}
if(stringcount<MAXCOMSTR&&stringcount>=0&&strlen(tempchar)!=0)
{
if(strcmp(charpointer[0],"i")==0){commandname=I;}
if(strcmp(charpointer[0],"ib")==0){commandname=IB;}
if(strcmp(charpointer[0],"a")==0){commandname=A;}
if(strcmp(charpointer[0],"l")==0){commandname=L;}
if(strcmp(charpointer[0],"ln")==0){commandname=LN;}
if(strcmp(charpointer[0],"d")==0){commandname=D;}
if(strcmp(charpointer[0],"f")==0){commandname=F;}
if(strcmp(charpointer[0],"c")==0){commandname=C;}
if(strcmp(charpointer[0],"r")==0){commandname=R;}
if(strcmp(charpointer[0],"p")==0){commandname=P;}
if(strcmp(charpointer[0],"s")==0){commandname=S;}
if(strcmp(charpointer[0],"e")==0){commandname=E;}
if(strcmp(charpointer[0],"q")==0){commandname=Q;}
if(strcmp(charpointer[0],"h")==0){commandname=H;}
if(strcmp(charpointer[0],"w")==0){commandname=W;}
if(strcmp(charpointer[0],"#")==0){commandname=CURRENT;}
if(commandname==0){return -1;}
commandnumber=stringcount+1+commandname*100;
}
switch(commandnumber)
{
case 101://i
{
char *input1=new char[_max_input];
char *input2=new char[_max_input];
long old_current=0,new_current=0;
if(fi.current==0)
{
old_current=1;
}
else
{
old_current=fi.current;
}
printf(" ");
gets(input1);
while(1)
{
if(strlen(input1)==0)
{
printf(" ");
gets(input2);
if(strlen(input2)==0)
{
if(getch()==13)
{
new_current=fi.current;
fi.Print(old_current,1);
delete input1;
delete input2;
fi.current=new_current;
_file_modified=1;
return 101;
}
else
{
fi.Insert(input1,fi.current);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
}
else
{
fi.Insert(input1,fi.current);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
}
else
{
fi.Insert(input1,fi.current);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
} //insert successfully
}
case 102://i #
{
char *input1=new char[_max_input];
char *input2=new char[_max_input];
long lnum=0;
lnum=atol(charpointer[1]);
if(lnum<=0||lnum>fi.SumLNow()){return -1;}
long old_current=lnum,new_current=lnum;
if(lnum==0)
{
old_current=1;
}
else
{
old_current=lnum;
}
printf(" ");
gets(input1);
while(1)
{
if(strlen(input1)==0)
{
printf(" ");
gets(input2);
if(strlen(input2)==0)
{
if(getch()==13)
{
new_current=fi.current;
fi.Print(old_current,1);
delete input1;
delete input2;
fi.current=new_current;
_file_modified=1;
return 102;
}
else
{
fi.Insert(input1,fi.current);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
}
else
{
fi.Insert(input1,lnum++);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
}
else
{
fi.Insert(input1,lnum++);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
}//lines inserted successfully
}
case 201: //ib
{
char *input1=new char[_max_input];
char *input2=new char[_max_input];
if(fi.current==0 || fi.current>fi.SumLNow())
{
printf("-----------file is empty--------------\n");
return -1;
}
long old_current=fi.current,new_current=0;
printf(" ");
gets(input1);
while(1)
{
if(strlen(input1)==0)
{
printf(" ");
gets(input2);
if(strlen(input2)==0)
{
if(getch()==13)
{
new_current=fi.current;
fi.Print(old_current,1);
delete input1;
delete input2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -