📄 this.cpp
字号:
return 101;
}
else
{
fi.Insert(input1,-1+old_current++);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
}
else
{
fi.Insert(input1,-1+old_current++);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
}
else
{
fi.Insert(input1,-1+old_current++);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
} //front lines inserted successfully
}
case 202://ib #
{
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=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;
fi.current=new_current;
_file_modified=1;
return 101;
}
else
{
fi.Insert(input1,-1+lnum++);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
}
else
{
fi.Insert(input1,-1+lnum++);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
}
else
{
fi.Insert(input1,-1+lnum++);
if(strlen(input1)==0)
{
strcpy(input1,input2);
}
else
{
printf(" ");
gets(input1);
}
}
}//front lines inserted successfully
}
case 301://a
{
char *input=new char[_max_input];
long old_current=fi.SumLNow();
if(fi.SumLNow()==0)
old_current=1;
while(1)
{
printf(" ");
gets(input);
if(strlen(input)==0)
{
if(getch()==13)
{
fi.Print(old_current,1);
delete input;
fi.current=fi.SumLNow();
_file_modified=1;
return 301;
}
}
else
{
fi.Append(input);
}
}
}
case 401://l
{
fi.Print(fi.current,1);
if(fi.SumLNow()<1)
printf(".........file is empty........\n");
return 401;// lines referred listed
}
case 402://l #
{
long lnum1=0;
lnum1=atol(charpointer[1]);
if(lnum1<=0||lnum1>fi.SumLNow()){return -3;}//
if(lnum1>0&&lnum1<=fi.SumLNow())
{
fi.Print(lnum1,1);
}
if(fi.SumLNow()<1)
printf(".........file is empty........\n");
return 401;
}
case 501://ln
{
fi.Print(fi.current,0);
if(fi.SumLNow()<1)
printf(".........file is empty........\n");
return 501;// list without line number
}
case 502://ln #
{
long lnum1=0;
lnum1=atol(charpointer[1]);
if(lnum1<=0||lnum1>fi.SumLNow()){return -3;}//
if(lnum1>0&&lnum1<=fi.SumLNow())
{
fi.Print(lnum1,0);
}
if(fi.SumLNow()<1)
printf(".........file is empty........\n");
return 502;
}
case 601://d
{//
fi.DeleteLine(fi.current);
long new_current=fi.current;
if(fi.current<1)
{
printf(".........file is empty........\n");
return -1;
}
if(fi.SumLNow()<1)
{
fi.current=0;
}
fi.Print(fi.current,1);
if(fi.SumLNow()!=0)
fi.current=new_current;
else
fi.current=0;
_file_modified=1;
return 601;
}
case 602://d #
{
long lnum=0,new_current=fi.current;
lnum=atol(charpointer[1]);
if(lnum<=0){return -2;}//
if(lnum>fi.SumLNow())
{
printf("\7........ the line %4d is invalid.........\n",lnum);
return -3;
}
if(lnum>0&&lnum<=fi.SumLNow())
{
fi.DeleteLine(lnum);
new_current=fi.current;
}
if(fi.current<1)
{
printf(".........file is empty........\n");
return -1;
}
if(fi.SumLNow()<1)
{
fi.current=0;
}
fi.Print(lnum,1);
if(fi.SumLNow()!=0)
fi.current=new_current;
else
fi.current=0;
_file_modified=1;
return 602;
}
case 603://d # length
{
long posi1=0;
int length=0;
long lnum=0,new_current=fi.current;
lnum=atol(charpointer[1]);
length=atoi(charpointer[2]);
if(length==0){break;}
if(lnum<=0||lnum>fi.SumLNow()){return -2;}//
if(lnum>0&&lnum<=fi.SumLNow())
{
if(length>0)
{
long tempint=fi.SumLNow();
for(posi1=lnum;posi1<=((lnum+length-1>tempint)?tempint:lnum+length-1);posi1++)
{
fi.DeleteLine(lnum);
}
if(fi.SumLNow()<1)
{
printf(".........file is empty........\n");
fi.current=0;
}
else
{
new_current=fi.current;
}
fi.Print(lnum,1);
fi.current=new_current;
_file_modified=1;
return 603;
}
if(length<0)
{
for(posi1=lnum;posi1>=((lnum-length+1<0)?0:lnum+length+1);posi1--)
{
fi.DeleteLine(posi1);
}
if(fi.SumLNow()<1)
{
printf(".........file is empty........\n");
fi.current=0;
}
else
{
new_current=fi.current;
}
fi.Print(lnum,1);
fi.current=new_current;
_file_modified=1;
return 603;
}
}
}
///find substring form # to #+length-1
case 704://f str # length
{
long posi1=0;
long lnum=0;
int length=0,_find_str=0; //sign if there is a line to be found
long templnum=0;
printf("------------------------------------------------------------------------------\n");
lnum=atol(charpointer[2]);
length=atoi(charpointer[3]);
if(fi.SumLNow()<1)
{
printf("\7---------------file is empty--------------------\n");
return -1;
}
if(length==0)
{
printf("\7----------- the line's length is incorrect---------\n");
return -1;
}
if(lnum<=0)//
{
lnum=1;
}
if(lnum>fi.SumLNow())
{
lnum=fi.SumLNow();
}
if(lnum>0&&lnum<=fi.SumLNow())
{
if(length>0)
{
long tempint=fi.SumLNow();
for(posi1=lnum;posi1<=((lnum+length-1>tempint)?tempint:lnum+length-1);posi1++)
{
templnum=fi.FindStr(charpointer[1],posi1);
if(templnum!=-1)
{
_find_str=1;
printf("%4d:",templnum);
fi.Display(templnum);
}
}
if(_find_str==0)
{
printf("---- no proper lines found from line %d to line %d-----\n",lnum,lnum+length-1);
}
printf("------------------------------------------------------------------------------\n");
return 704;
}
if(length<0)
{
for(posi1=lnum;posi1>=((lnum-length+1<0)?0:lnum+length+1);posi1--)
{
templnum=fi.FindStr(charpointer[1],posi1);
if(templnum!=-1)
{
_find_str=1;
printf("%4d:",templnum);
fi.Display(posi1);
}
}
if(_find_str==0)
{
printf("---- no proper lines found from line %d to line %d-----\n",lnum,lnum+length-1);
}
printf("------------------------------------------------------------------------------\n");
return 704;
}
}
}
case 801://c str1/str2
{
char *source=new char[_max_input]; //Note : the source string must less than 128
char *target=new char[_max_input];
int temp=0;
int length=0;
length=strlen(charpointer[1]);
for(temp=0;temp<length;temp++)
{
if(charpointer[1][temp]=='/')
{
break;
}
}
if(temp==0)
{
return -1;
}
if(temp==length-1)
{
charpointer[1][temp]='\x0';
char *str1=fi.Position(fi.current);
fi.Replace(charpointer[1],"");
delete str1;
}
if(temp>0 && temp<length-1)
{
strcpy(source,charpointer[1]+temp+1);
charpointer[1][temp]='\x0';
strcpy(target,charpointer[1]);
char *str=fi.Position(fi.current);
fi.Replace(target,source);
delete str;
}
delete source;
delete target;
fi.Print(fi.current,1);
_file_modified=1;
return 802;
}
///////////////////////////////////////////////////////////////////////////
case 804: //c str1/str2 # length
{
char *source=new char[_max_input];
char *target=new char[_max_input];
int temp=0,length=0,lenlnum=0;
long lnum=atol(charpointer[2]); //the beginning line to be replaced
lenlnum=atoi(charpointer[3]); //how many line will be replaced
if(lnum+lenlnum>fi.SumLNow())
lenlnum=fi.SumLNow()-lnum+1;
if(lenlnum<1)
return -1;
length=strlen(charpointer[1]);
for(temp=0;temp<length;temp++)
{
if(charpointer[1][temp]=='/')
{
break;
}
}
if(temp==0)
{
return -1;
}
if(temp==length-1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -