📄 this.cpp
字号:
if(temp==length-1)
{
charpointer[1][temp]='\x0';
strcpy(target,charpointer[1]);
*source=NULL;
}
if(temp>0 && temp<length-1)
{
strcpy(source,charpointer[1]+temp+1);
charpointer[1][temp]='\x0';
strcpy(target,charpointer[1]);
}
////////////////replace////////////////////////
for(temp=0;temp<lenlnum;temp++)
{
char *str=fi.Position(lnum+temp);
fi.Replace(target,source);
delete str;
}
delete source;
delete target;
fi.Print(fi.current,1);
_file_modified=1;
return 802;
}
//read file str after fi.current
//the file should not empty
case 902:///r str
{
char *tempchar2=new char[30];
strcpy(tempchar2,charpointer[1]);
FILE *fp;
fp=fopen(tempchar2,"r");
if(!fp)
{
printf("Can 't open file %s",charpointer[1]);
return -1; ///error
}
delete tempchar2;
long old_current=fi.current;
if(fi.current==0)
{
old_current=1;
}
else
{
old_current=fi.current;
}
fi.ReadInto(fp,old_current);
_file_modified=1;
fclose(fp);
fi.Print(old_current,1);
return 902;
}
/////////////read file str after line lnum/////////////////////////////////////////////
case 903: //r str #
{
//int temp=0;
long lnum=atol(charpointer[2]);
if(lnum<1 || lnum>fi.SumLNow())
{
printf("\7------line %d is invalid---------\n");
return -1;
}
char *tempchar2=new char[30];
strcpy(tempchar2,charpointer[1]);
FILE *fp;
fp=fopen(tempchar2,"r");
if(!fp)
{
printf("Can 't open file %s",charpointer[1]);
return -1; ///error
}
delete tempchar2;
fi.ReadInto(fp,lnum);
fclose(fp);
fi.Print(lnum,1);
_file_modified=1;
return 903;
}
///////////////////////////////////////////////////////////////////////////////////////
////copy line form #1 to #1+length-1 after line #2
case 1004: //p #1 length #2
{
long beginlnum=atol(charpointer[1]);
int length=atoi(charpointer[2]);
long targetlnum=atol(charpointer[3]);
if(beginlnum<1 || beginlnum>fi.SumLNow())
return -1;
if(length<1)
return -2;
if(targetlnum<1 || targetlnum>fi.SumLNow())
return -3;
if( fi.CopyLine(beginlnum,targetlnum,length)!=-1)
fi.Print(beginlnum,1);
_file_modified=1;
return 1004;
}
///////////////////////save and not exit//////////////////////
case 1101: //s
{
if(_file_exist!=0)
{
fi.Save();
return 1101;
}
else
{
FILE *fp;
printf("Please enter the file name : ");
char *filename=new char[30];
gets(filename);
while(1)
{
if(*filename=='\n')
{
printf("Please enter the file name : ");
gets(filename);
}
else
{
break;
}
}
fp=fopen(filename,"w");
if(!fp)
{
cout<<"Can 't creat file"<<filename<<endl;
return -1;
}
delete filename;
fi.SaveAs(fp);/////////
return 1101;
}
}
//////////////////save and exit/////////////////////
case 1201://e
{
if(_file_modified==0)
{
return 1201;
}
if(_file_exist!=0)
{
fi.Save();
return 1201;
}
else
{
FILE *fp;
printf("Please enter the file name : ");
char *filename=new char[30];
gets(filename);
fp=fopen(filename,"w");
if(!fp)
{
cout<<"Can 't create file"<<filename<<endl;
return -1;
}
delete filename;
fi.SaveAs(fp);
return 1201;
}
}
////quit program if file is 't modified
case 1301://q
{
if(_file_modified==0) // file opened is not be modified
return 1301;
else
{
char ch;
printf(" file is modified, Save or Not? \n");
ch=getch();
if(ch=='s'||ch=='S')
{
if(_file_exist!=0)
{
fi.Save();
return 1301;
}
else
{
FILE *fp;
printf("Please enter the file name : ");
char *filename=new char[30];
gets(filename);
fp=fopen(filename,"w");
if(!fp)
{
cout<<"Can 't create file"<<filename<<endl;
return -1;
}
delete filename;
fi.SaveAs(fp);
return 1301;
}
}
else
{
return 1301;
}
}
}
/////////////////////help display all commander information////////
case 1401: //h
{
system("more help.txt");
return 1401;
}
///////////////////help about the signed commander///////////////////////////////////
case 1402: // h str
{
int command=0;
if(strcmp(charpointer[1],"i")==0){command=1;}
if(strcmp(charpointer[1],"ib")==0){command=2;}
if(strcmp(charpointer[1],"a")==0){command=3;}
if(strcmp(charpointer[1],"l")==0){command=4;}
if(strcmp(charpointer[1],"ln")==0){command=5;}
if(strcmp(charpointer[1],"d")==0){command=6;}
if(strcmp(charpointer[1],"f")==0){command=7;}
if(strcmp(charpointer[1],"c")==0){command=8;}
if(strcmp(charpointer[1],"r")==0){command=9;}
if(strcmp(charpointer[1],"p")==0){command=10;}
if(strcmp(charpointer[1],"s")==0){command=11;}
if(strcmp(charpointer[1],"e")==0){command=12;}
if(strcmp(charpointer[1],"q")==0){command=13;}
if(strcmp(charpointer[1],"h")==0){command=14;}
if(strcmp(charpointer[1],"w")==0){command=15;}
switch(command)
{
case 1://i
{
printf("i i insert new lines after the perline\n");
printf("i # i 21 insert new lines after the # line\n");
break;
}
case 2://ib
{
printf("ib ib insert new lines before perline\n");
printf("ib# ib 21 insert new lines before the # \n");
break;
}
case 3:// a
{
printf("a a add the new lines the user input \n");
printf(" after the whole file .\n");
break;
}
case 4://l
{
printf("l l display line form preline+10 to\n");
printf(" preline+10 with linenum,if possible\n");
printf("l # l 21 display line form line #-10 to # +10\n");
printf(" with linenum,if possible\n");
break;
}
case 5://ln
{
printf("ln ln display line form preline-10 to\n");
printf(" preline+10 if possible\n");
printf("ln# ln 21 display line form line #-10 to #+10\n");
break;
}
case 6:// d
{
printf("d d delete the perline.\n");
printf("d # d 21 delete the #th line.\n");
printf("d # length d 21 3 delete lines at the number of length \n");
printf(" after the #th line.\n");
break;
}
case 7://f str # length
{
printf("f str # length f abc 21 5 find str in range of length lines after\n");
printf(" the #th line.\n");
break;
}
case 8://c str1/str2
{
printf("c str1/str2 f ab/12345 replace str1 to str2. \n");
printf("c str1/str2 # len f ab/123 20 3 replace str1 to str2 from the #th line\n");
printf(" in the range of length line.\n");
break;
}
case 9://r str
{
printf(" r str r file read file str after the perline \n");
printf("r str # r file 20 read file str after the #th line \n");
break;
}
case 10://p #1 length #2
{
printf("p #1 length #2 p 2 2 2 copy [length] lines from the #th after\n");
printf(" after the #th line.\n");
break;
}
case 11://s
{
printf("s s save the files and not exit\n");
break;
}
case 12://e
{
printf("e e save the files and exit\n");
break;
}
case 13://q
{
printf("q q do not save the files and exit\n");
break;
}
case 14://h
{
printf("h h display all the help order\n");
printf("h str h insert display insert order\n");
break;
}
case 15://w str
{
printf("w str w filename save file as the name of filename\n");
printf(" then keep the compile enviroment\n");
printf("w str#length w file 2 20 save the [length] lines after the #th\n");
printf(" line as the name of file.\n");
break;
}
}
return 1402;
}
//////////write file to a new file//////////////////////
case 1502://w str
{
FILE *fp;
fp=fopen(charpointer[1],"w");
if(!fp)
{
cout<<"Can 't creat file"<<charpointer[1]<<endl;
return -1;
}
fi.SaveAs(fp);
return 1502;
}
///////////////////////write # to #+length lines to a new file///////////////
case 1504://w str # length
{
FILE *fp;
long start_line=atol(charpointer[2]);
long length=atol(charpointer[3]);
fp=fopen(charpointer[1],"w");
if(!fp)
{
cout<<"Can 't creat file"<<charpointer[1]<<endl;
return -1;
}
fi.BlockSaveAs(fp,start_line,length);
fclose(fp);
return 1504;
}
case 1702: //current
{
long lnum=atol(charpointer[1]);
if(lnum<1)
fi.current=1;
else if(lnum>fi.SumLNow())
fi.current=fi.SumLNow();
else
fi.current=lnum;
return 1702;
}
default: return 0;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////
/////version 1.0 ////////////////////////////////modified on 2001,9,10,17:29////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
void main(int argc,char *argv[])
{
IniFace();
int whatcommand=0;
char *tempchar=new char[80]; //all command must less than 80 characters
if(argc<=1)
{
_file_exist=0;
FileSwap kk;
printf("------------------------------------------------------------------------------\n");
while(whatcommand!=1301 && whatcommand!=1201)
{
printf("* ");
gets(tempchar);
whatcommand=carryout(tempchar,kk);
}
}
else
{
FILE *fp;
char ch='n';
fp=fopen(argv[1],"r+");
if(!fp)
{
printf("\7 File %s not exist, creat it? Yes or No ? ",argv[1]);
ch=getchar();
if(ch!='y' || ch!='Y')
{
exit(0);
}
else
{
fp=fopen(argv[1],"w+");
if(!fp)
{
printf("\7 file %s creat error ",argv[1]);
exit(1);
}
}
}
FileSwap kk(fp);
printf("------------------------------------------------------------------------------\n");
while(whatcommand!=1301 && whatcommand!=1201)
{
printf("* ");
gets(tempchar);
whatcommand=carryout(tempchar,kk);
}
fclose(fp);
}
delete tempchar;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -