#define len_SubDir 22
#define KEY_ESC 27
#define KEY_ESC2 114  //ԶڶASC룩 ǰr 
#define KEY_SHIFT 26
#define KEY_HELP 25
#define MarkP 127			//filedataеλ
#define p_readpath 48		//filedataеλ
#define MarkFileHead 256	//ǩļ"ļͷ"

char FileType;
char fpMark;
char font;
char linesize;
char upfromim,findchmode,Boss_show;
char KEY;
char cmd;
char DIYup='a';
char DIYdn='z';
char DIYpgup='d';
char DIYpgdn='c';
char Boss_key;
char filedata[205];
char fp;
long thispage_begin;
long thispage_end;
long nextpage_begin;
long nextpage_end;
long nextline_begin;
long nextline_end;
long lastpage_begin;
long lastpage_end;
long lastline_begin;
long lastline_end;
char path[4][16];
char pathpoint;
char filestr[15];
char SHIFTaBYTE;

char tofindstrs[53];
char save_pass;

char Auto_ByHand;
char Auto_ByHand2;
int ms=4000;
int hkpas=1;

long parentdir;//˱ûãɾ
long SubDir_add[5];//
long SubDir_name[5];//
char Num_of_SubDir;//
long CurrentSubDir_Name_p;//

long dataBegin;		//EBK_only_for_mark_begin-8
long dataEnd;

char EBK_only_for_mark_begin[2];
char dir_p;
long dir[10];
long BlockOffset;
char CurrentSubDir_p[10];
char CurrentSubDir;
char fromSubDir;
long dir_add;
long VTorId_maxID;
long VTorId_minID;
long VTorId_i;
long VTorId_add;
long BlockID;
char EBK_only_for_mark_end[2];//EBK_only_for_mark_end
int ebk_v_BEGIN;
int ebk_v_END;
char DatFileIsOK;


char password[53];
char fav_setting[4];
char choT[8]={60,66,153,189,189,153,66,60};
char choF[8]={60,66,129,129,129,129,66,60};
/*
char B16_order[]={           //(16+16)*16= 	  
			 
				0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,//0	 ڱ,δõ 
				0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,//1
				0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,//2
				0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,//3
				0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,//4
				0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,1,//5
				0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,//6
				1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,//7
				1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,0,//8
				1,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,//9
				1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,//a
				1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,//b
				1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,//c
				1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,//d
				1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,//e
				0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 //f
				};//WQXBMP෴
*/

struct TIME
{
int year;
char month;
char day;
char hour;
char minute;
char second;
char week;
};
struct TIME time;
void showword(long word)
{
int wdlen;
wdlen=strlen(word);
Box((160-wdlen*6)/2-2,28,(160-wdlen*6)/2+wdlen*6+3,46,1,0);
TextOut((160-wdlen*6)/2,31,word,65);
Box((160-wdlen*6)/2-1,29,(160-wdlen*6)/2+wdlen*6+1,44,0,1);
Line((160-wdlen*6)/2,45,(160-wdlen*6)/2+wdlen*6+2,45,1);
Line((160-wdlen*6)/2+wdlen*6+2,30,(160-wdlen*6)/2+wdlen*6+2,45,1);
}

char inputpass(int show_word,int str_add)
{
char word[3];
char strings[78];
char word_num;
char show_pass[10];
int c;
char i;
char string_return[10];
word[2]=0;
word_num=0;
string_return[0]=0;
memset(strings,0,78);
SetScreen(1);
Box(31,20,128,63,1,0);
Box(32,21,126,61,0,1);
Line(33,62,127,62,1);
Line(127,22,127,62,1);
Line(35,38,123,38,1);
TextOut(34,24,show_word,97);
TextOut(34,43," :",97);
while(1) 
{
c=getchar();
if (c==13) break;
else if (((c==29)||(c==23))&&word_num)word_num--;
else if(c==27)return(0);
else if(word_num==8)continue;
else if ((c&0xff00)==0 && isprint(c))
{
word[0]=c;
word[1]=0;
strcpy(strings+3*word_num,word);
word_num++;
}
show_pass[0]=0;
for(i=0;i<word_num;i++)strcat(show_pass,"*");
string_return[0]=0;
for(i=0;i<word_num;i++)strcat(string_return,strings+3*i);
Box(72,43,120,56,1,0);
TextOut(72,43,show_pass,97);
}
strcpy(str_add,string_return);
return 1;
}


char MsgBox(int show_word,char mode)
{
char c;
mode=abs(--mode);
Box(31,20,128,63,1,0);
Box(32,21,126,61,0,1);
Line(33,62,127,62,1);
Line(127,22,127,62,1);
Line(35,38,123,38,1);
TextOut(34,24,show_word,97);
TextOut(42,44,"(Y)  (N)",97);
Box(38,42,74,57,0,2);
Box(81,42,117,57,0,2);
for(;;)
{
Box(39+(43*mode),43,73+(43*mode),56,1,2);
c=getchar();
Box(39+(43*mode),43,73+(43*mode),56,1,2);
if(c==22||c==23||c==20||c==21) mode=abs(--mode);
if(c==KEY_ESC||c==KEY_ESC2) return 0;
if(c==13) return abs(--mode);
if(c=='y') return 1;
if(c=='n') return 0;
}
}

char DELETEorNOT()
{
if(MsgBox("ɾļ?",0))
{fclose(fp);fp=0;DeleteFile(filestr);showword("ɹɾ!");Delay(800);return 1;}
else {showword("ѷɾ!");}Delay(800);return 0;
}

void printHELP()
{
char c,hp,hpword[5][160];
hp=0;
strcpy(hpword[0]," Reader2_30  ˵ []     /ҳ\n[Q]+[] Ӧ [S]/[L]      /ǩ\n[SHIFT]+[L]  ǩ [ո]       ");
strcpy(hpword[1],"[F1]    ģʽ\n[F2]    ɾǰļ\n[F3]   [] һ[.]     \n[P]     鿴ʱ\n[]  鿴/޸ĵǰλ");
strcpy(hpword[2],"[W||O] ͣ/  [R]\nùһ붹ǰϼ룬лDojoлԭlinjian525!\nEmail:hnlihe65@yahoo.com.cn====Dojoע=====");
strcpy(hpword[3],"DojoReader2_27ĻϸĽģлԭlinjian525漰ȨⶼСҪϵ:\nE-mail:dojosoft@163.com\nhttp://dojosoft.ys168.com");
strcpy(hpword[4],"==== ԭߵİ ====Email:\ncnyahoocom-xx@yahoo.com.cnҷʼʱעǷйؼ»µĶûϸʱҵʼ");
for(;;){
SetScreen(1);
printf(hpword[hp]);
Line(159,0,159,79,1);
Line(159,hp*20,159,hp*20+19,0);
c=getchar();
if((c==14||c==21||c==22||c==DIYpgdn||c==DIYdn)&&(hp<4))hp++;
else if((c==19||c==20||c==23||c==DIYpgup||c==DIYup)&&(hp>0))hp--;
else if(c==27||c==KEY_ESC2)return;
}
}


long fsize(char fsize_fp)
{
fseek(fsize_fp,0,SEEK_END);
return ftell(fsize_fp);
}

char fopen_fp()
{
    while(1) 
    	{
        if (!FileList(filestr))
        	{
        	if (pathpoint==0) exit(0);
        	ChDir("..");
        	strcpy(path[--pathpoint],"/");
        	continue;
        	}
        else if (ChDir(filestr)) 
        		{
        		if (!strcmp(filestr,".."))
        			{if(pathpoint)strcpy(path[--pathpoint],"/");  }
        		else if(pathpoint==3){showword("֧4Ŀ¼!");ChDir("..");Delay(800);continue;}
        		else {strcat(path[pathpoint++],filestr);strcpy(path[pathpoint],"/");}
        		continue;
        		}
        break;
    	}    
    if ((fp=fopen(filestr,"r"))==0) {SetScreen(1);printf("ļ %s ʧ!",filestr);getchar();return 0;}
return 1;
}

char TYPEofFILE()
{
char type_flag[5];
rewind(fp);
fread(type_flag,1,5,fp);
rewind(fp);
if((!type_flag[0])&&(!type_flag[1])&&(!type_flag[2]))
	{
	if((!type_flag[3])&&(!type_flag[4]))return 1;//TXT
	else return 2;//EBK
	}
else if((type_flag[0]=='B')&&(type_flag[1]=='1')&&(type_flag[2]=='6'))return 3;//B16
else if((type_flag[0]=='B')&&(type_flag[1]=='M'))return 4;//BMP
else if((type_flag[0]=='F')&&(type_flag[1]=='L')&&(type_flag[2]=='M'))return 5;//FLM
else if(type_flag[0]&&type_flag[1]&&type_flag[2]&&type_flag[3]&&type_flag[4])return 1;
else return 0;
}

long getnum(char getnum_fp,long getnum_OffSet,char digitals)//digitals<=4
{
long getnum_Num;
char digital[4];
char i;
getnum_Num=0;
fseek(getnum_fp,getnum_OffSet,0);
for(i=0;i!=digitals;i++)digital[i]=getc(getnum_fp);
while(digitals--)getnum_Num=getnum_Num*256+digital[digitals];
return getnum_Num;
}

void progress()
{
char y1;
char y2;
if(dataEnd-dataBegin)
	{
	y1=(79*(thispage_begin-dataBegin))/(dataEnd-dataBegin);
	y2=1+(79*(thispage_end-dataBegin))/(dataEnd-dataBegin);
	Line(159,0,159,79,1);
	Line(159,y1,159,y2,0);
	}
else Line(159,0,159,79,0);
}

long ismid(long nowp,long end){
long i;
for(i=nowp;*i>=160&&i>=end;i--);
return(!((nowp-i)%2));
}
char stri(char y,char x,int title,int o,int maxl){
char ch[3],show[21],str[60];
int word,n,l,sx;
SetScreen(0);
printf("%s",title);
memset(str,0,maxl+1);
memset(ch,0,3);
strcpy(str,o);
n=0;
sx=0;
while(ch[0]!=13){
memset(show,0,21);
if(n<sx)sx=n;
if(n>sx+20)sx=n-20;
memcpy(show,str+sx,20);
l=strlen(str);
if(show[0]>=160&&ismid(str+sx,str))show[0]='_';
if(show[19]>=160&&!ismid(show+19,show))show[19]='_';
Locate(4,0);printf("                    ");
Locate(y,0);printf("%s  ",show);Box(8*(n-sx),16*y,8*(n-sx)+1,16*y+16,1,2);
if(ch[0]==22||ch[0]==23){Delay(80);ReleaseKey(128);}
word=GetWord(3);
ch[0]=word;
if(isprint(ch[0])&&l<maxl){memmove(str+n+1,str+n,l-n);str[n]=ch[0];n++;}
else if(ch[0]>=160&&l<maxl-1){ch[1]=word>>8;memmove(str+n+2,str+n,l-n);memcpy(str+n,ch,2);n=n+2;}
else if(ch[0]==27){strcpy(str,"");return 0;}
else if(ch[0]==29&&n>0){
 if(str[n-1]>=160){memmove(str+n-2,str+n,l-n);memset(str+l-2,0,2);n=n-2;}
 else {memmove(str+n-1,str+n,l-n);str[l-1]=0;n--;}}
else if(ch[0]==23){if(n==0)n=l;else if(str[n-1]>=160)n=n-2;else n--;
  }//if
else if(ch[0]==22){if(n>=l)n=0;else if(str[n]>=160)n=n+2;else n++;
  }//if
else if(ch[0]==19){memset(str,0,maxl+1);Locate(y,0);printf("                    ");n=0;}
else if(ch[0]==30)n=0;
else if(ch[0]==31)n=strlen(str);
 }//while
strcpy(tofindstrs,str);
return 1;
}


long inputnum(long num_old,char figures,char num_begin_x,char num_begin_y,long min,long max)
{
char c;
char one_figure[10];
char i;
char j;
long num_input;

Inkey();
num_input=num_old;
i=0;
Locate(num_begin_x,num_begin_y);
do	{
	j=figures;
	while(j--)
		{
		one_figure[j]=num_input%10;
		one_figure[j]=one_figure[j]+0x30;
		num_input=num_input/10;
		}
	one_figure[figures]=0;

	
	printf("%s",one_figure);
	Box(6*(num_begin_y+i)+2,13*num_begin_x,6*(num_begin_y+i)+8,13*num_begin_x+13,1,2);
	Locate(num_begin_x,num_begin_y);
	c=getchar();
	if(c==21){if(one_figure[i]>'0')one_figure[i]--;else one_figure[i]='9';}
	else if(c==20){if(one_figure[i]<'9')one_figure[i]++;else one_figure[i]='0';}
	else if((i)&&(c==23))i--;
	else if((i<figures-1)&&(c==22))i++;
	else 
		{
		if(c=='0') one_figure[i]='0';
		else if(c=='b') one_figure[i]='1';
		else if(c=='n') one_figure[i]='2';
		else if(c=='m') one_figure[i]='3';
		else if(c=='g') one_figure[i]='4';
		else if(c=='h') one_figure[i]='5';
		else if(c=='j') one_figure[i]='6';
		else if(c=='t') one_figure[i]='7';
		else if(c=='y') one_figure[i]='8';
		else if(c=='u') one_figure[i]='9';

		if(i<figures-1)i++;
		else i=0;
		}
	for(num_input=(j=0);j<figures;j++)num_input=10*num_input+one_figure[j]-0x30;
	if(num_input<min)num_input=min;
	else if(num_input>max)num_input=max;
	}while((c!=13)&&(c!=27)&&(c!=KEY_ESC2))

if(c==27)return num_old;
else return num_input;
}


char nextfile(int memadd)
{
char filestr_new[15];
char filestr_temp[15];
char NUMs[16];

long p;
char i;
char j;
char k;
char l;


p=-1;l=1;
while(strstr(filestr+p+1,"."))p=(strstr(filestr,".")-filestr);
strcpy(filestr_temp,filestr);
if(p!=-1)filestr_temp[p]=0;

k=strlen(filestr_temp);
i=k-1;
while(i){if(!isdigit(filestr_temp[i])){break;}i--;}

if(i==k-1){*memadd=0;return(0);}

j=0;i++;
while(j<i){filestr_new[j]=filestr_temp[j];j++;}filestr_new[j]=0;
j=i;
while(j<k){NUMs[j]=filestr_temp[j]-48;j++;}

while((--k)>=i)
	{
	if(l)
		if(NUMs[k]==9){NUMs[k]=0;}
		else {NUMs[k]++;l=0;}
	//k--;
	}
if(l){filestr_temp[0]=48+1;k=1;}
else k=0;
while(i<j)filestr_temp[k++]=NUMs[i++]+48;
filestr_temp[k]=0;
strcat(filestr_new,filestr_temp);
if(p!=-1)strcat(filestr_new,filestr+p);
if (strlen(filestr_new)>14)
	{
	*memadd=0;
	return 0;
	}
else
	{
	memcpy(memadd,filestr_new,15);
	return 1;
	}
}



long find(long returnIFfaild,long Seekfrom,char NewSearch)
{

char data[1077];

int c;
char i;
int CanRead;
int strstr_value;
int strstr_value1;
int Temp_strstr_value;
long lastestCrLf;
long seek;
char CrLf[2];
long find_result;
long SeachBegin;
char half;
long CharsRest;//CHARS from CrLf to STRING


data[1076]=0;
lastestCrLf=0;
CrLf[0]=10;CrLf[1]=0;
half=0;

if(NewSearch)if(!stri(1,1,"Ҫҵַ:",tofindstrs,20))return(returnIFfaild);

//strcpy(tofindstrs,"ŷ쿴ȥ");//FOR TEST ON PC


if(FileType==1){SetScreen(0);printf("ڲңԺ...");}

SeachBegin=Seekfrom;
seek=Seekfrom;

while(1)
	{
	while(1)
		{
		//printf(".");
		if(Inkey()==27){if(FileType==2)return (-2);else return(returnIFfaild);}
		fseek(fp,seek,0);
		CanRead=fread(data,1,1076,fp);
		
		if(seek+CanRead>dataEnd){CanRead=dataEnd-seek;data[CanRead]=0;}
		else data[CanRead]=0;
		Temp_strstr_value=data;
		if(strstr_value1=strstr(data,tofindstrs))
			{
			while(strstr_value=strstr(Temp_strstr_value,CrLf))
				{
				if(strstr_value<strstr_value1)lastestCrLf=seek+strstr_value-data;
				else break;
				Temp_strstr_value=strstr_value+1;
				}
			break;
			}
		else{
			while(strstr_value=strstr(Temp_strstr_value,CrLf))
				{
				lastestCrLf=seek+strstr_value-data;
				Temp_strstr_value=strstr_value+1;
				}		
			}
		if(CanRead!=1076)break;
		seek=seek+1024;
		}
	if((CanRead!=1076)&&(!strstr_value1))
		{
		SetScreen(1);
		if(FileType==1)
			{
			printf("TXTļβ,");
			printf("\nδַ:\n\n%s",tofindstrs);getchar();
			}
		return(returnIFfaild);
		}
	else 
		{
		find_result=seek+strstr_value1-data;
		if(!lastestCrLf)lastestCrLf=Seekfrom-1;
		fseek(fp,lastestCrLf+1,0);
		
		CharsRest=find_result-lastestCrLf;//CharsRest￪ʼǵfind_resultľ
		i=0;
		while(CharsRest>1076)
			{
			//printf("~");
			if(Inkey()==27){if(FileType==2)return (-2);else return(returnIFfaild);}
			if(half){c++;half=0;}
			fread(data,1,1076,fp);
			c=0;
			while(c<1075)
				{
				if(data[c]>128)
					{
					if(i==25)i=2;
					else i=i+2;
					c=c+2;
					}
				else {c++;i++;}
				if(i==26)i=0;
				}
			if((c==1075)&&(data[1075]>128))half=1;
			CharsRest=CharsRest-1076;
			}
		fread(data,1,CharsRest,fp);
		
		CharsRest--;
		c=0;
		//printf("^");
		if(Inkey()==27){if(FileType==2)return (-2);else return(returnIFfaild);}
		while(CharsRest>1)
			{
			if(data[c]>128)
				{
				if(i==25)i=2;
				else i=i+2;
				c=c+2;
				CharsRest=CharsRest-2;
				}
			else {c++;i++;CharsRest--;}
			if(i==26)i=0;
			}
		if(CharsRest==1)
			{
			if(data[c]>128){SeachBegin=find_result+1;seek=SeachBegin;continue;}//strstrܴӺֵһֽڼҵtofindstrs
			else return(find_result-i-1);
			}
		else return(find_result-i);
		}
	}

}






////////////////////////////////////////////////////////////////////////////////////

long EBK_find_inBlock()
{
long find_result;
fseek(fp,BlockOffset+BlockID*9,0);
KEY=getc(fp);
dataBegin=getc(fp)+getc(fp)*256+getc(fp)*256*256;
dataEnd=getc(fp)+getc(fp)*256+getc(fp)*256*256;
if(thispage_begin==-1)thispage_end=dataBegin-1;
if (KEY==0)
	{
	find_result=find(-1,thispage_end+1,0);/////////////////
	return (find_result);
	}
else return (-1);
}

long EBK_find_inDir(long add)
{
long find_result;
find_result=-1;
fseek(fp,add+7,0);

VTorId_minID=getc(fp)+getc(fp)*256;
getc(fp);getc(fp);getc(fp);
VTorId_maxID=getc(fp)+getc(fp)*256;

BlockID=VTorId_minID;
do{
	if((find_result=EBK_find_inBlock())!=-1)break;
	
	BlockID++;
}while(BlockID<VTorId_maxID)

return (find_result);	
}

long EBK_changeNextDir()
{
long add;
char c;
long dir_return;
long dir_unknow;

while(1)
	{
	if(CurrentSubDir+1<Num_of_SubDir)//һ
		{
		CurrentSubDir++;
		CurrentSubDir_p[dir_p]=CurrentSubDir;
		fseek(fp,dir_add+3+2*CurrentSubDir,0);
		dir_unknow=getc(fp)+getc(fp)*256;
	
		fseek(fp,dir[dir_p],0);
		while(getc(fp)!=0xff);
		dir[dir_p]=ftell(fp);
		
		break;
		}
	else //һ
		{
		if(!dir_p) {return(-1);}
		fseek(fp,dir_add+1,0);parentdir=getc(fp)+getc(fp)*256;
		fseek(fp,parentdir,0);
		Num_of_SubDir=getc(fp);
		dir_add=parentdir;parentdir=getc(fp)+getc(fp)*256;
		CurrentSubDir_p[dir_p]=0;
		CurrentSubDir=CurrentSubDir_p[--dir_p];//if(CurrentSubDir+1<Num_of_SubDir)ϱߣ
		}
	}
	
	
	
while(1)//Ŀ¼
	{
	fseek(fp,dir_unknow,0);
	c=getc(fp);
	if((!c)||(dir_p>9))break;//(dir_p>9)ֹ
	else
		{
		CurrentSubDir=0;CurrentSubDir_p[++dir_p]=0;
		Num_of_SubDir=c;parentdir=dir_add;dir_add=dir_unknow;
		fseek(fp,dir_add+3,0);dir_unknow=getc(fp)+getc(fp)*256;
		dir[dir_p]=dir_add+3+2*Num_of_SubDir;
		}
	}
	
thispage_begin=-1;//ҪEBK_find_inBlock()
return(dir_unknow);

}


long findInEBK(long returnIFfaild,char NewSearch)
{
long old_dataBegin;
long old_dataEnd;
char CurrentSubDir_p_old[10];
char dir_p_old;
long dir_old[10];
char CurrentSubDir_old;
long parentdir_old;	
long dir_add_old;
long VTorId_maxID_old;
long VTorId_minID_old;
long VTorId_i_old;
long VTorId_add_old;
int Num_of_SubDir_old;

long find_result;

if(NewSearch)if(!stri(1,1,"Ҫҵַ:",tofindstrs,20))return(returnIFfaild);
//strcpy(tofindstrs,"INT");
if(tofindstrs[0]==0)return(returnIFfaild);

SetScreen(0);printf("ڲңԺ...");
old_dataBegin=dataBegin;
old_dataEnd=dataEnd;
memcpy(CurrentSubDir_p_old,CurrentSubDir_p,10);
CurrentSubDir_old=CurrentSubDir;
parentdir_old=parentdir;
memcpy(dir_old,dir,40);
dir_add_old=dir_add;
dir_p_old=dir_p;
VTorId_maxID_old=VTorId_maxID;
VTorId_minID_old=VTorId_minID;
VTorId_i_old=VTorId_i;
VTorId_add_old=VTorId_add;
Num_of_SubDir_old=Num_of_SubDir;

find_result=-1;

do{
	
	if((find_result=EBK_find_inDir(VTorId_add))!=-1)break;
	else
		{
		
		VTorId_add=EBK_changeNextDir();
		
		}
	}while(VTorId_add!=-1)


if((find_result!=-1)&&(find_result!=-2)){fromSubDir=CurrentSubDir;return(find_result);}
else
	{
	dataBegin=old_dataBegin;
	dataEnd=old_dataEnd;
	memcpy(CurrentSubDir_p,CurrentSubDir_p_old,10);
	CurrentSubDir=CurrentSubDir_old;
	parentdir=parentdir_old;
	memcpy(dir,dir_old,40);
	dir_add=dir_add_old;
	dir_p=dir_p_old;
	VTorId_maxID=VTorId_maxID_old;
	VTorId_minID=VTorId_minID_old;
	VTorId_i=VTorId_i_old;	
	VTorId_add=VTorId_add_old;
	Num_of_SubDir=Num_of_SubDir_old;
	if(find_result==-2)return(returnIFfaild);
	SetScreen(1);
	printf("ļβδ\n\n%s",tofindstrs);
	getchar();
	return(returnIFfaild);
	} 
}
///////////////////////////////////////////////////////////////////////////////////////


void set_nextpage()
{
char i;
char space_rest;
char tempchar;
char CanRead;

nextpage_begin=thispage_end+1;
if(nextpage_begin<dataEnd)fseek(fp,nextpage_begin,0);
else {SetScreen(1);if(FileType==2&&VTorId_i<VTorId_maxID)printf("\n\n\n\n\n    [Continue] %d/%d ",VTorId_i-VTorId_minID,VTorId_maxID-VTorId_minID);else printf("\n\n\n\n\n         [END]");progress();cmd=254;return;}
CanRead=fread(filedata,1,164,fp);
if(ftell(fp)>dataEnd)CanRead=CanRead-(ftell(fp)-dataEnd);

if(font)space_rest=156;else space_rest=100;
for(i=0;i<CanRead;i++)
	{
	tempchar=filedata[i];
	if(tempchar<128) 
		{
		if((tempchar==13)||(tempchar==10)) 
			{
			space_rest=((space_rest-1)/linesize)*linesize;
			if(filedata[i+1]==10)i++;
			}
		else space_rest--;
		}
	else 
		{
		if((space_rest%linesize)==1)
			{
			if(space_rest==1){i--;break;}
			space_rest--;
			}
		space_rest=space_rest-2;
		i++;
		}
	if((!space_rest)||(space_rest>156)||(CanRead<=i+1))break;
	}
if(filedata[i]==10)filedata[i]=0;else filedata[i+1]=0;
if(CanRead<=i+1)filedata[CanRead]=0;
nextpage_end=nextpage_begin+i;
SetScreen(font);
if(SHIFTaBYTE)filedata[0]=63;//Chr(63)='?'
printf("%s",filedata);
thispage_begin=nextpage_begin;
thispage_end=nextpage_end;
progress();
if(Auto_ByHand=='h'){do cmd=getchar();while(cmd=='q') if(CheckKey('q'))ReleaseKey(cmd);}else if(Auto_ByHand=='l')cmd=21;else cmd=14;
}

void set_nextline()
{
char i;
char space_rest;
char tempchar;
char CanRead;

nextline_begin=thispage_begin;
if(nextline_begin<dataEnd)fseek(fp,nextline_begin,0);
else {SetScreen(font);if(FileType==2&&VTorId_i<VTorId_maxID)printf("\n\n\n\n\n    [Continue] %d/%d ",VTorId_i-VTorId_minID,VTorId_maxID-VTorId_minID);else printf("\n\n\n\n\n         [END]");progress();cmd=254;return;}
CanRead=fread(filedata,1,30,fp);
if(ftell(fp)>dataEnd)CanRead=CanRead-(ftell(fp)-dataEnd);
if(font)space_rest=26;else space_rest=20;
for(i=0;i<CanRead;i++)
	{
	tempchar=filedata[i];
	if(tempchar<128) 
		{
		if((tempchar==13)||(tempchar==10)) 
			{
			space_rest=0;
			if(filedata[i+1]==10)i++;
			break;
			}
		else space_rest--;
		}
	else 
		{
		if(space_rest==1)
			{
			i--;
			space_rest--;
			break;
			}
		space_rest=space_rest-2;
		i++;
		}
	if((!space_rest)||(space_rest>linesize))break;
	}
if(filedata[i]==10)filedata[i]=0;else filedata[i+1]=0;
if(CanRead<=i+1)filedata[CanRead]=0;
nextline_end=nextline_begin+i;
thispage_end=nextline_end;
set_nextpage();
}

long findlastCrLf(long thisCrLf)
{
char CrLf[2];
char data[513];
int data_p;
int temp_p;
int chars_read;
long LastCrLf;
int i;
char Reach_textbegin;

CrLf[0]=10;CrLf[1]=0;data[512]=0;
i=0;LastCrLf=0;
Reach_textbegin=0;

if(thisCrLf<=dataBegin)return dataBegin-1;
do	{
	i++;
	if(Reach_textbegin){LastCrLf=dataBegin-1;break;}
	if(thisCrLf-512*i>dataBegin) fseek(fp,thisCrLf-512*i,0);
	else {Reach_textbegin=1;fseek(fp,dataBegin,0);}
	
	if((chars_read=fread(data,1,512,fp))!=512)data[chars_read]=0;

	data[512]=0;
	if(i==-1)data[thisCrLf-0]=0;
	if(Reach_textbegin)data[(thisCrLf-dataBegin)%512]=0;
	
	data_p=data;
	while ((temp_p=strstr(data_p+1,CrLf))!=NULL) 
		{
		data_p=temp_p;
		LastCrLf=ftell(fp)-chars_read+data_p-data;
		}
		if(LastCrLf!=0)break;
	}while(1)
return LastCrLf;
}

long Spaceused(long LastCrLf,long thisCrLf,char counttype,long linerest)
{
int i;
char data[513];
int k;
char not_end;
char half;
char line_spaces_rest;
long restchars;
long Spaces_used;
long debug;

i=0;not_end=1;half=0;line_spaces_rest=linesize;Spaces_used=0;data[512]=0;

if((counttype=='c')&&(!linerest))return(LastCrLf+1);
if(LastCrLf-thisCrLf>10000)//ٴ
	{
	if(counttype=='l')//line
		return((LastCrLf-thisCrLf)%linesize);
	else if(counttype=='a')//all
		return(LastCrLf-thisCrLf);
	else if(counttype=='c')//count
		return(LastCrLf-thisCrLf)/linesize*linesize+linesize;
	}


while (not_end)
	{
	if((LastCrLf+i*512+512)<thisCrLf)
		{
		fseek(fp,LastCrLf+i*512+1,0);fread(data,1,512,fp);
		if(half)k=1;else {k=0;half=0;}
		for(;k<512;k++)
			{
			if(data[k]>127)
				{
				if(!(k-511))half=1;
				if(line_spaces_rest==1){line_spaces_rest=linesize;Spaces_used++;linerest--;if((!linerest)&&(counttype=='c')){k--;not_end=0;break;}}
				line_spaces_rest=line_spaces_rest-2;
				Spaces_used=Spaces_used+2;
				k++;
				}
			else 
				{
				if(line_spaces_rest==1){line_spaces_rest=linesize;linerest--;if((!linerest)&&(counttype=='c')){k--;not_end=0;break;}}
				else line_spaces_rest--;
				Spaces_used++;
				}
			if(!line_spaces_rest){line_spaces_rest=linesize;linerest--;if((!linerest)&&(counttype=='c')){not_end=0;break;}}
			}
		}
	else 
		{
		fseek(fp,LastCrLf+i*512+1,0);
		restchars=thisCrLf-LastCrLf-1-i*512;
		fread(data,1,restchars,fp);
		if(data[restchars-1]==13)data[--restchars]=0;else data[restchars]=0;
		if(half)k=1;else {k=0;half=0;}
		while (k<restchars)
			{
			if(data[k]>127)
				{
				if(line_spaces_rest==1){line_spaces_rest=linesize;Spaces_used++;linerest--;if((!linerest)&&(counttype=='c')){k--;not_end=0;break;}}
				line_spaces_rest=line_spaces_rest-2;
				Spaces_used=Spaces_used+2;
				k++;
				}
			else
				{
				//debug[0]=data[k];debug[1]=0;debug[2]=0;
				if(line_spaces_rest==1){line_spaces_rest=linesize;linerest--;if((!linerest)&&(counttype=='c')){k--;not_end=0;break;}}
				else line_spaces_rest--;
				Spaces_used++;
				}
			if(!line_spaces_rest){line_spaces_rest=linesize;linerest--;if((!linerest)&&(counttype=='c')){not_end=0;break;}}
			k++;
			}
		not_end=0;			
		}
	i++;
	}
	debug=LastCrLf+i*512-512+1+k+1;
	123;
if(counttype=='l')//line
	return(line_spaces_rest);
else if(counttype=='a')//all
	return(Spaces_used);
else if(counttype=='c')//count ļָ
	return(LastCrLf+i*512-512+1+k+1);
}



void set_lastpage()
{
char i;
char space_rest;
char tempchar;
char CanRead;
long lastCrLf;

lastpage_end=thispage_begin-1;
if(lastpage_end>=162+dataBegin){fseek(fp,lastpage_end-162,0);CanRead=fread(filedata,1,163,fp);}
else {fseek(fp,dataBegin,0);CanRead=fread(filedata,1,lastpage_end+1-dataBegin,fp);}

if(font)space_rest=156;else space_rest=100;
for(i=CanRead-1;i<CanRead;i--)
	{
	tempchar=filedata[i];
	if(tempchar<128)
		{
		if(tempchar==10)
			{
			if(space_rest%linesize){space_rest=space_rest/linesize*linesize;if(!space_rest)break;}
			lastCrLf=findlastCrLf(thispage_begin-CanRead+i);
			space_rest=space_rest-Spaceused(lastCrLf,thispage_begin-CanRead+i,'l',0);
			if(filedata[i-1]==13)i--;
			}
		else space_rest--;
		}
	else 
		{
		if((space_rest%linesize)==1)
			{
			if(space_rest==1){space_rest=0;i++;break;}
			space_rest--;
			}
		space_rest=space_rest-2;
		i--;
		}
	
	if((!space_rest)||(space_rest>250)||(thispage_begin+i-CanRead<=0))break;
	}
if(filedata[CanRead-1]==10)filedata[CanRead-1]=0;else filedata[CanRead]=0;

lastpage_begin=thispage_begin-CanRead+i;//if(i>CanRead)lastpage_begin=lastpage_begin-256;//char 
SetScreen(font);
if(SHIFTaBYTE)filedata[i]=63;
if((space_rest)&&(space_rest<=156)){if(thispage_begin-dataBegin>200){cmd=255;return;}thispage_end=dataBegin-1;set_nextpage();return;}////////ԼҲǸʲô
else {printf("%s",filedata+i);memmove(filedata,filedata+i,46);}
thispage_begin=lastpage_begin;
thispage_end=lastpage_end;
progress();
if(Auto_ByHand=='h'){do cmd=getchar();while(cmd=='q') if(CheckKey('q'))ReleaseKey(cmd);}else if(Auto_ByHand=='l')cmd=21;else cmd=14;
}


void set_lastline()
{
char i;
char space_rest;
char tempchar;
char CanRead;
long lastCrLf;

lastline_end=thispage_begin-1;

if(lastline_end>=29+dataBegin){fseek(fp,lastline_end-29,0);CanRead=fread(filedata,1,30,fp);}
else {fseek(fp,dataBegin,0);CanRead=fread(filedata,1,lastline_end+1-dataBegin,fp);}

space_rest=linesize;

for(i=CanRead-1;i<CanRead;i--)
	{
	tempchar=filedata[i];
	if(tempchar<128) 
		{
		if(tempchar==10)
			{
			if(space_rest!=linesize)space_rest=0;
			else 
				{
				lastCrLf=findlastCrLf(thispage_begin-CanRead+i);
				space_rest=space_rest-Spaceused(lastCrLf,thispage_begin-CanRead+i,'l',0);
				}
			if(filedata[i-1]==13)i--;
			}
		else space_rest--;
		}
	else 
		{
		//debug[0]=filedata[i-1];debug[1]=filedata[i];debug[2]=0;
		if(space_rest==1){space_rest=0;i++;break;}
		space_rest=space_rest-2;
		i--;
		}
	
	if((!space_rest)||(space_rest>250)||(thispage_begin+i-CanRead<=0))break;
	}

lastline_begin=thispage_begin-CanRead+i;//if(i>CanRead)lastpage_begin=lastpage_begin-256;//char 
if((space_rest)&&(space_rest<=linesize)){if(thispage_begin-dataBegin>200){cmd=255;return;}thispage_end=dataBegin-1;}////////
else thispage_end=lastline_begin-1;
set_nextpage();
}

long seeknextCrLf(long from)
{
long seek;
long result;
char data[513];
char CrLf[2];
long nextCrLf;

//if(from<=dataBegin)return ;
CrLf[0]=10;CrLf[1]=0;data[512]=0;
seek=from;
result=0;
if(seek<dataBegin)return dataBegin-1;
while(seek+512<dataEnd)
	{
	fseek(fp,seek,0);fread(data,1,512,fp);
	result=strstr(data,CrLf);
	if(result)break;
	seek=seek+512;
	}
if(!result){fseek(fp,seek,0);fread(data,1,dataEnd-seek,fp);data[dataEnd-seek]=0;result=strstr(data,CrLf);}
nextCrLf=seek+result-data;
if(!result)return(dataEnd-1);
else return(seek+result-data);
}


void print_6or5_ph(long page_begin)
{
char i;
char j;
char k;
char c;
long next_ph;
long HeadOFph[7];
long positionINph[6];
long ph_len[6];
long ph_right[6];
long ph_blank[6];
char fastseekposition[6];

char ph_blank_test;

long nextCrLf;
long temp_CrLf;
long cols;

char chars[28];
char ii;
char jj;
char spacerest;
char CanRead;
long Line_begin;


next_ph=page_begin;nextCrLf=page_begin;
c=0;cols=0;
for(i=0;i<6;i++){ph_blank[i]=0;fastseekposition[i]=1;}
if(font)j=6;else j=5;

while(c!=28)
	{

	filedata[0]=0;
	if(!c) {c=14;HeadOFph[j]=page_begin;}
	else
		{
		for(i=0;i<j;i++)
			{
			if(ph_blank[i]>0)
				{
				memset(filedata+linesize*i,' ',linesize);
				filedata[linesize*i+linesize]=0;
				continue;
				}
			Line_begin=positionINph[i];
			ii=0;
			spacerest=linesize;
			if(Line_begin<dataEnd)fseek(fp,Line_begin,0);
			if(Line_begin>=HeadOFph[i+1]) CanRead=0;
			else{
				if(Line_begin+27<=HeadOFph[i+1])
					{
					CanRead=fread(chars,1,27,fp);
					}
				else CanRead=fread(chars,1,HeadOFph[i+1]-Line_begin,fp);
				}
			chars[CanRead]=10;
			if(!CanRead)ph_blank[i]++;
			
			while(spacerest)
				{
				if(chars[ii]>128){ii=ii+2;spacerest=spacerest-2;}
				else if(chars[ii]==13){chars[ii]=0x20;ii++;spacerest--;}
				else if(chars[ii]!=10){ii++;spacerest--;}
				else {chars[ii]=0x20;ii++;break;}
				if(spacerest==1)if(chars[ii]>128){fastseekposition[i]=0;break;}
				}
			for(jj=ii;jj<linesize;jj++)chars[jj]=0x20;

			chars[linesize]=0;
			strcat(filedata,chars);
			
			if(ii==1)ii=0;//Ҫ
			ph_right[i]=Line_begin+ii;
			}
		SetScreen(font);
		printf("%s",filedata);
	
		do {c=getchar();if(c>96&&c<123)c=14;}
while((c!=14)&&(c!=19)&&(c!=20)&&(c!=21)&&(c!=28)&&(c!=22)&&(c!=23))
		}	
	if(c==21)
		{
		for(i=0;i<j-1;i++)
			{
			HeadOFph[i]=HeadOFph[i+1];
			positionINph[i]=positionINph[i+1];
			ph_blank[i]=ph_blank[i+1];
			}
		HeadOFph[j-1]=HeadOFph[j];
		HeadOFph[j]=seeknextCrLf(HeadOFph[j-1])+1;
		positionINph[j-1]=Spaceused(HeadOFph[j-1]-1,HeadOFph[j],'c',cols);
		ph_blank[j-1]=0;//ph_blank[j-1]=cols-(positionINph[j-1]-HeadOFph[j-1])/linesize+1;

		}//ld
	else if(c==14)
		{
		HeadOFph[0]=HeadOFph[j];
		ph_blank[0]=0;//ph_blank[0]=cols-(positionINph[0]-HeadOFph[0])/linesize+1;
		for(i=0;i<j;i++)
			{
			HeadOFph[i+1]=seeknextCrLf(HeadOFph[i])+1;
			positionINph[i]=Spaceused(HeadOFph[i]-1,HeadOFph[i+1],'c',cols);
			ph_blank[i]=0;//if(positionINph[i]==HeadOFph[i+1])ph_blank[i]=cols-(positionINph[i]-HeadOFph[i])/linesize+1;
			}
		}//pd
	else if(c==20)
		{
		temp_CrLf=findlastCrLf(HeadOFph[0]-1)+1;
		if((temp_CrLf>=dataBegin)&&(HeadOFph[0]>dataBegin))
			{
			HeadOFph[j]=HeadOFph[j-1];
			for(i=j-1;i>0;i--)
				{
				HeadOFph[i]=HeadOFph[i-1];
				positionINph[i]=positionINph[i-1];
				ph_blank[i]=ph_blank[i-1];
				}
			HeadOFph[0]=temp_CrLf;
			positionINph[0]=Spaceused(HeadOFph[0]-1,HeadOFph[1],'c',cols);
			ph_blank[0]=0;//ph_blank[0]=cols-(positionINph[0]-HeadOFph[0])/linesize+1;
			}
		}//lu
	else if(c==19)
		{
		HeadOFph[j]=HeadOFph[0];
		for(k=6;k;k--)
			{
			temp_CrLf=findlastCrLf(HeadOFph[0]-1)+1;
			if((temp_CrLf>=dataBegin)&&(HeadOFph[0]>dataBegin))
				{
				for(i=j-1;i>0;i--)
					{
					HeadOFph[i]=HeadOFph[i-1];
					positionINph[i]=positionINph[i-1];
					ph_blank[i]=ph_blank[i-1];
					}
				HeadOFph[0]=temp_CrLf;
				positionINph[0]=Spaceused(HeadOFph[0]-1,HeadOFph[1],'c',cols);
				ph_blank[0]=0;//ph_blank[0]=cols-(positionINph[0]-HeadOFph[0])/linesize+1;
				}
			}
		}//lu*6=pu
	else if(c==22)
		{
		for(i=0;i<6;i++)
			{
			positionINph[i]=ph_right[i];
			}
		cols++;
		}//right
	else if(c==23)
		{
		if(cols)
			{
			cols--;
			for(i=0;i<6;i++)
				{
				if(ph_blank[i]>0){ph_blank[i]--;if(!ph_blank[i])positionINph[i]=Spaceused(HeadOFph[i]-1,HeadOFph[i+1],'c',cols);}//ph_blank[i]=ph_blank[i]-2;
				else
					{
					if(fastseekposition[i])positionINph[i]=HeadOFph[i]+linesize*cols;
					else positionINph[i]=Spaceused(HeadOFph[i]-1,HeadOFph[i+1],'c',cols);
					ph_blank[i]=0;//ph_blank[i]=cols-(positionINph[i]-HeadOFph[i])/linesize+1;
					
					}
				}
			}
		}//left

	ph_blank_test=1;
	for(i=0;i<j;i++)if(!ph_blank[i])ph_blank_test=0;
	if(ph_blank_test){for(i=0;i<j;i++)ph_blank[i]--;cols--;}
	}
	
thispage_begin=HeadOFph[0];
}


char CheckExistDATfile()
{
char fp_check;
char blankMemory[64];
char i;
ChDir("/");if(!ChDir("LavaData"))MakeDir("LavaData");ChDir("/");
if ((!(fp_check=fopen("/LavaData/Reader2.dat","r+")))||(fp_check&&(fsize(fp_check)!=8192)))
	{
	if(fp_check){fclose(fp_check);fp_check=0;}
	if(!(fp_check=fopen("/LavaData/Reader2.dat","w+"))){showword("޷DATļ :(");Delay(1000);return 0;}
	else 
		{
		SetScreen(1);showword("ڴDATļ.....");
		memset(blankMemory,0,64);
		for(i=0;i<128;i++)fwrite(blankMemory,1,64,fp_check);
		return fp_check;
		}
	}
else return fp_check;

}

void SetMark(char Action)
{
int i;
long temp_long;
int num;
char oldest_i;
int oldest_num;
int newest;
char Mark[20];
long MarkBegin[20];
int Mark_num[20];
long exchange_temp;
char j;
char c;
char k;
char blank;
char fp_toTestFileExistORnot;
int Mem_add1;
int Mem_add2;
int Mem_add3;
//char FileTypeS[5];
i=0;
oldest_num=0x7fff;
oldest_i=0;
newest=0;
blank=20;

if(!DatFileIsOK)return;
else {if(FileType!=255)fclose(fp);fp=0;fpMark=fopen("/LavaData/Reader2.dat","r+");}

filedata[MarkP]=0;

for(i=0;i!=pathpoint;i++)strcat(filedata+MarkP,path[i]);
strcat(filedata+MarkP,"/");strcat(filedata+MarkP,filestr);

if (Action==1)
	{
	showword("ڼDATļ.....");
	fseek(fpMark,0,0);
	fread(Mark_num,1,40,fpMark);
	for(i=0;i<20;i++)
		{
		if(Mark_num[i]==0)blank=i;
		else 
			{
			if(Mark_num[i]<oldest_num){oldest_num=Mark_num[i];oldest_i=i;}
			if(Mark_num[i]>newest)newest=Mark_num[i];
			}
		}

	if(blank==20) 
		{SetScreen(1);
		printf("ǩѴ20,\n\nǷɾʧЧǩ Y/N ?");
		if (getchar()=='y')
			{
			showword("ɾʧЧǩ.....");
			for(i=0;i<20;i++)
				{
				fseek(fpMark,128*i+2+MarkFileHead,0);
				fread(filedata+p_readpath,1,75,fpMark);	
				if ((!(fp_toTestFileExistORnot=fopen(filedata+p_readpath,"r")))&&(strcmp(filedata+p_readpath,filedata+MarkP))) 
					{
					blank=i;
					fseek(fpMark,128*i+2+MarkFileHead,0);putc(0,fpMark);
					fseek(fpMark,i*2,0);putc(0,fpMark);putc(0,fpMark);	
					}
				else {fclose(fp_toTestFileExistORnot);fp_toTestFileExistORnot=0;}
				}
			if (blank==20)
				{
				SetScreen(1);
				printf("ûʧЧǩ,\n\nǷɾɵǩ Y/N ?");
				if (getchar()=='y') blank=oldest_i;else {showword("δǩ");Delay(1000);goto exit_SetMark;}
				}
			}
		else 
			
			{
			SetScreen(1);
			printf("\n\nǷɾɵǩ Y/N ?");
			if (getchar()=='y') blank=oldest_i;else {showword("δǩ");Delay(1000);goto exit_SetMark;}
			}
		}
	fseek(fpMark,128*blank+MarkFileHead,0);
	
	num=newest+1;
	filedata[MarkP-2]=num;filedata[MarkP-1]=num>>8;//putc(num&0x00ff,fpMark);putc(num>>8,fpMark);
	filedata[strlen(filedata+MarkP)+MarkP]=0;

	fwrite(filedata+MarkP-2,1,76,fpMark);
	
	/*putc(0,fpMark);	
	temp_long=thispage_begin;
	for (i=0;i<4;i++){putc((temp_long&0x00ff),fpMark);temp_long=temp_long>>8;}//thispage_begin
	putc(0,fpMark);*/
	//*
	i=p_readpath;
	filedata[i++]=0;	
	temp_long=thispage_begin;
	j=4;while(j--){filedata[i++]=temp_long;temp_long=temp_long>>8;}//thispage_begin
	filedata[i++]=0;
	fwrite(filedata+p_readpath,1,6,fpMark);//*/
	fwrite(filedata,1,46,fpMark);
	
	fseek(fpMark,blank*2,0);putc(num%256,fpMark);putc(num>>8,fpMark);
	
	
	if(FileType==2)
		{
		fseek(fpMark,128*blank+2560+MarkFileHead,0);
		fwrite(ebk_v_BEGIN-8,1,ebk_v_END-ebk_v_BEGIN+8,fpMark);
		}
	
	filedata[46]=0;
	SetScreen(1);
	printf("%s\n",filedata);
	Locate(4,16);printf("                                    ");
	Locate(4,0);printf(" << ǩ: %s",filedata+MarkP);
	thispage_end=thispage_begin-1;
	Delay(500);
	}
else if (Action==2)
	{ 

	j=0;
	for(i=0;i<20;i++)
		{
		fseek(fpMark,128*i+MarkFileHead,0);fread(filedata,1,82,fpMark);
		if (!strcmp(filedata+2,filedata+MarkP))
			{
			Mark[j]=i;MarkBegin[j]=(filedata[77]+(filedata[78]+(filedata[79]+filedata[80]*256)*256)*256);
			Mark_num[j]=filedata[0]+filedata[1]*256;
			j++;
			}
		}
	for(k=1;k<j;k++)
		{
		for(i=j-1;i>=k;i--)
			{
			if(Mark_num[i]>Mark_num[i-1])
				{
				exchange_temp=Mark_num[i];Mark_num[i]=Mark_num[i-1];Mark_num[i-1]=exchange_temp;				
				exchange_temp=Mark[i];Mark[i]=Mark[i-1];Mark[i-1]=exchange_temp;
				exchange_temp=MarkBegin[i];MarkBegin[i]=MarkBegin[i-1];MarkBegin[i-1]=exchange_temp;
				}
			
			}
		}
		i=0;
	if(j!=0)
		do{	
			fseek(fpMark,Mark[i]*128+82+MarkFileHead,0);fread(filedata,1,46,fpMark);filedata[46]=0;
			SetScreen(1);
			printf("%s",filedata);
			Locate(5,1);printf("%d ǩ< %d >",i+1,j);
			if (((c=getchar())==21)&&(i>0)) i--;
			else if ((c==20)&&(i<j-1)) i++;
			else if(c==29)
				{
				fseek(fpMark,2*Mark[i],0);putc(0,fpMark);putc(0,fpMark);
				fseek(fpMark,128*Mark[i]+2+MarkFileHead,0);putc(0,fpMark);
				if(i==j-1){j--;i--;}else {for(k=i;k<j-1;k++){Mark[k]=Mark[k+1];MarkBegin[k]=MarkBegin[k+1];}j--;}
				if(j==0)break;
				}
								
			}while((c!=13)&&(c!=27)&&(c!=KEY_ESC2))
	if(j==0){showword("Ŀǰǩ");Delay(800);c=0;}
	
	if (c==13) 
		{
		if(FileType==2)
			{
			fseek(fpMark,128*Mark[i]+2560+MarkFileHead,0);
			fread(ebk_v_BEGIN-8,1,ebk_v_END-ebk_v_BEGIN+8,fpMark);
			}
		thispage_begin=MarkBegin[i];
		SetScreen(1);Locate(4,0);printf(" >> Ѷȡǩ...");Delay(500);
		
		}

	}
else if (Action==3)
	{
	j=0;
	for(i=0;i<20;i++)
		{
		fseek(fpMark,128*i+MarkFileHead,0);fread(filedata,1,82,fpMark);
		if(filedata[2]!=0)
			{
			Mark[j]=i;MarkBegin[j]=(filedata[77]+(filedata[78]+(filedata[79]+filedata[80]*256)*256)*256);
			Mark_num[j]=filedata[0]+filedata[1]*256;
			j++;
			}
		}
		
	i=0;
	if(j!=0)
		do{	
			fseek(fpMark,Mark[i]*128+2+MarkFileHead,0);fread(filedata,1,126,fpMark);filedata[126]=0;
			SetScreen(1);
			for(Mem_add1=filedata;(Mem_add1=strstr(Mem_add1+1,"/"));)Mem_add2=Mem_add1;
			printf("\n\n%s",filedata+80);
			Locate(0,0);printf("%d/%d>>%s\n",i+1,j,Mem_add2+1);
			do c=getchar();while((c!=20)&&(c!=21)&&(c!=13)&&(c!=27)&&(c!=29))
			if ((c==21)&&(i>0)) i--;
			else if ((c==20)&&(i<j-1)) i++;
			else if(c==29)
				{
				fseek(fpMark,2*Mark[i],0);putc(0,fpMark);putc(0,fpMark);
				fseek(fpMark,128*Mark[i]+2+MarkFileHead,0);putc(0,fpMark);
				if(i==j-1){j--;i--;}else {for(k=i;k<j-1;k++){Mark[k]=Mark[k+1];MarkBegin[k]=MarkBegin[k+1];}j--;}
				if(j==0)break;
				}
								
			}while((c!=13)&&(c!=27)&&(c!=KEY_ESC2))
	if(j==0){showword("Ŀǰǩ");Delay(800);c=0;}
	if (c==13)
		{
		if(strcmp(filedata,filedata+MarkP))
			{
			fseek(fpMark,128*Mark[i]+2560+MarkFileHead,0);
			fread(filedata+MarkP,1,ebk_v_END-ebk_v_BEGIN+8,fpMark);//fread(ebk_v_BEGIN-8,1,ebk_v_END-ebk_v_BEGIN+8,fpMark);
			fclose(fpMark);fpMark=0;
			if (fp_toTestFileExistORnot=fopen(filedata,"r")) 
				{
				if(!ChDir("/")){showword("򿪸Ŀ¼ʧܣ");getchar();goto exit_SetMark;}		
				pathpoint=0;Mem_add1=strstr(filedata,"/");Mem_add3=0;
				do	{
					strcpy(path[pathpoint],"/");
					if((Mem_add1)||(Mem_add3))
						{
						if(Mem_add3=strstr(Mem_add1+1,"/"))
							{
							*Mem_add3=0;
							Mem_add2=Mem_add1;
							strcat(path[pathpoint],Mem_add1+1);
							if(strstr(path[pathpoint]+1,"/"))*strstr(path[pathpoint]+1,"/")=0;
							if(!ChDir(Mem_add1+1)){showword("Ŀ¼ʧܣ");getchar();goto exit_SetMark;}
							pathpoint++;
							}
						else {strcpy(filestr,Mem_add1+1);}
						Mem_add1=Mem_add3;
						}
					else break;
					}while(1)
				fp=fp_toTestFileExistORnot;
				}
			else {showword("ļʧܣ");getchar();goto exit_SetMark;}
			}
		
		else 
			{
			fseek(fpMark,128*Mark[i]+2560+MarkFileHead,0);
			fread(filedata+MarkP,1,ebk_v_END-ebk_v_BEGIN+8,fpMark);//fread(ebk_v_BEGIN-8,1,ebk_v_END-ebk_v_BEGIN+8,fpMark);
			fclose(fpMark);fpMark=0;fp=fopen(filestr,"r");
			}
		memcpy(ebk_v_BEGIN-8,filedata+MarkP,ebk_v_END-ebk_v_BEGIN+8);
		
		FileType=TYPEofFILE();
		if(FileType!=2){FileType=1;rewind(fp);if(getc(fp)==0)dataBegin=24;else dataBegin=0;dataEnd=fsize(fp);}
			
		thispage_begin=MarkBegin[i];cmd=255;
		SetScreen(1);Locate(4,0);printf(" >> Ѷȡǩ...");Delay(500);return;
		
		}

	}

exit_SetMark:if(fpMark)fclose(fpMark);fpMark=0;fp=fopen(filestr,"r");cmd=255;
}
void Setms()
{
char c;

SetScreen(1);
printf("\n    ڷҳʱ %d.%ds\n\n   趨밴 ϡ ...\n   <>ȷ...",ms/1000,ms/100-((ms)/1000)*10);

	while ((c=getchar())!=13)	{		
		if ((c==20)&&(ms<=19900)) {ms=ms+100;ReleaseKey(20);}
		else if ((c==19)&&(ms<=19900)) {if(ms<=19000) ms=ms+1000; else ms=20000;ReleaseKey(19);}
		else if ((ms>201)&&(c==21)) {ms=ms-100;ReleaseKey(21);}
		else if ((ms>201)&&(c==14)) {if(ms>1200)ms=ms-1000;else ms=200;ReleaseKey(14);}			
		Locate(1,16);
		printf(" %d.%ds  ",ms/1000,ms/100-((ms)/1000)*10);
        Delay(80);
		ReleaseKey(128);
		}
}

void Delay_or_Inkey()
{
char inkey_value;
char RestTime;

inkey_value=0;

RestTime=(ms-200)/100;
while(1)
	{
	if(CheckKey('q')){do inkey_value=getchar();while(inkey_value=='q') ReleaseKey(inkey_value);cmd=inkey_value;break;}
	else 
		{
		inkey_value=Inkey();
		if(inkey_value){cmd=inkey_value;break;}
		}
	if(!RestTime)break;
	Delay(100);RestTime--;
	}

//if(CheckKey('q')&&inkey_value)ReleaseKey(inkey_value);

}

void pause()
{
char c;
Inkey();
SetScreen(0);
GetTime(time);
Locate(4,10);printf("%d/%d/%d",time.year,time.month,time.day);
while(((c=Inkey())!='p')&&(c!=15))
{
GetTime(time);
Locate(2,2);printf("ʱ %d:%d:%d   ",time.hour,time.minute,time.second);
Delay(100);
}
}

void Set_fseek()
{
char c;
char i;
long dataEnd_temp;
long num_input;
do{
SetScreen(1);
dataEnd_temp=dataEnd;for(i=0;dataEnd_temp;i++)dataEnd_temp=dataEnd_temp/10;
printf("ǰλ:\n\n %d",thispage_begin);
Locate(2,9);printf("ֽ\n\n\n %d  ; %d ",(thispage_begin-dataBegin)*100/(dataEnd-dataBegin+1),((thispage_begin-dataBegin)*500/(dataEnd-dataBegin+1))*2);
Locate(3,1);printf("%d  %d",dataBegin,dataEnd);
c=getchar();
if(c=='h')thispage_begin=dataBegin;
else if(c=='e')thispage_begin=dataEnd;
else if(c==13||c==31)
{
Locate(5,0);printf("               ");
num_input=inputnum(thispage_begin,i,2,1,dataBegin,dataEnd);
if(thispage_begin==num_input)continue;
else {thispage_begin=num_input;continue;}
}
}while((c!=27)&&(c!=KEY_ESC2));
}

void SetBossKey()
{
char c,Bosstemp;
Bosstemp=Boss_key;
SetScreen(1);
printf("      ϰDIY\n      ǰ: %c  %d\n\n\n    ⰴ м ޸\n    <> ȷ޸...",Boss_key,Boss_key);
for(;;)
{
c=getchar();
if(c>96&&c<123&&c!='q'&&c!='s'&&c!='l'&&c!=DIYpgup&&c!=DIYpgdn&&c!=DIYup&&c!=DIYdn||c==15)
{
Bosstemp=c;
Locate(2,6);
printf("Ϊ: %c  %d ",Bosstemp,Bosstemp);
}
else if(c==13){Boss_key=Bosstemp;return;}
else if(c==27)return;
}
}

void set_fav()
{

char c;
char i;
char j;
char menuNUM;

menuNUM=5;
filedata[0]=0;
if(fav_setting[0])strcat(filedata," *");else strcat(filedata,"  ");strcat(filedata,"  ıʾɾı\n");
if(fav_setting[1])strcat(filedata," *");else strcat(filedata,"  ");strcat(filedata,"  ıȷ\n");
if(fav_setting[2])strcat(filedata," *");else strcat(filedata,"  ");strcat(filedata,"  ²ļʾ");
if(fav_setting[3])strcat(filedata," *");else strcat(filedata,"  ");strcat(filedata,"  ʹ()(  min)");
i=0;
SHO:
SetScreen(1);
printf("%s\n    ϰDIY(ǰ:     )",filedata);
Locate(3,19);printf("%d",fav_setting[3]);
Locate(4,19);printf("%c %d",Boss_key,Boss_key);
Box(1,13*i,158,13*i+12,1,2);
do{
do c=getchar();while((c!=20)&&(c!=21)&&(c!=KEY_ESC&&c!=KEY_ESC2)&&(c!=13)&&(c!=23)&&(c!=22))
j=i;
if((c==20)&&(i))i--;
else if((c==20)&&(!i))i=menuNUM-1;
else if((c==21)&&(i<menuNUM-1))i++;
else if((c==21)&&(i==menuNUM-1))i=0;
else if((c==13)&&(i==4)){SetBossKey();fseek(fpMark,180,0);putc(Boss_key,fpMark);goto SHO;}
else if((c==13)&&(i<4))
{
Locate(i,1);
if(fav_setting[i]){printf(" ");fav_setting[i]=0;Locate(3,19);printf("0 ");}else {printf("*");fav_setting[i]=1;}
if(i==3){Locate(3,19);printf("%d",fav_setting[3]);}
Box(1,13*i,158,13*i+12,1,2);
}
else if((c==23)&&(i==3)&&(fav_setting[3])){fav_setting[3]--;Locate(3,19);printf("%d",fav_setting[3]);if(fav_setting[3]<10)printf(" ");if(!fav_setting[3]){Locate(3,1);printf(" ");}Box(1,13*i,158,13*i+12,1,2);}
else if((c==22)&&(i==3)&&(fav_setting[3]<60)){fav_setting[3]++;Locate(3,19);printf("%d",fav_setting[3]);if(fav_setting[3]<10)printf(" ");if(fav_setting[3]){Locate(3,1);printf("*");}Box(1,13*i,158,13*i+12,1,2);}
else if(c==KEY_ESC||c==KEY_ESC2)break;
else continue;
Box(1,13*j,158,13*j+12,1,2);
Box(1,13*i,158,13*i+12,1,2);
}while(1)
123;
}

void menu_SPACE()
{
char Auto_ByHand_str[6];
char c;
char menuNUM;
char menu_str[27];
char i;
char j;
char OKisPrinted;
char PassWord_is_OK;

i=0;menuNUM=6;OKisPrinted=0;

if(Auto_ByHand=='a')strcpy(Auto_ByHand_str,"ҳ ");
else if(Auto_ByHand=='l')strcpy(Auto_ByHand_str," ");
else strcpy(Auto_ByHand_str,"ֶ ");
SetScreen(1);
ClearScreen();

sprintf(menu_str,"ֶ/ҳ/(ǰ%s)",Auto_ByHand_str);
TextOut(0,0,menu_str,1);
sprintf(menu_str,"÷ҳʱ (ǰ %d.%ds )",ms/1000,ms/100-((ms)/1000)*10);
TextOut(0,13,menu_str,1);
TextOut(0,26,"ΪĬ",1);
TextOut(0,39,"õǰĿ¼ΪĬĿ¼",1);
TextOut(0,52,"/ ʹ",1);
TextOut(0,65,"˲ƫ",1);
Block(1,0,158,12,2);
Refresh();
if(DatFileIsOK){fclose(fp);fp=0;fpMark=fopen("/LavaData/Reader2.dat","r+");}

do	{
	do c=getchar();while((c!=20)&&(c!=21)&&(c!=KEY_ESC&&c!=KEY_ESC2)&&(c!=13))
	if(OKisPrinted){TextOut(135,13*OKisPrinted,"   ",2);OKisPrinted=0;}
	j=i;
	if((c==20)&&(i))i--;
 else if((c==20)&&(!i))i=menuNUM-1;
 else if((c==21)&&(i<menuNUM-1))i++;
 else if((c==21)&&(i==menuNUM-1))i=0;
	else if(c==13)
			{
			if(i==1)
			{
			Setms();
			//ms=inputnum(ms,5,2,0,0,20000);
			sprintf(menu_str,"÷ҳʱ (ǰ %d.%ds ) ",ms/1000,ms/100-((ms)/1000)*10);
			TextOut(0,13,menu_str,2);
			}
			else if(i==0)
					{
if(Auto_ByHand=='a'){Auto_ByHand='l';TextOut(114,0,"",2);Auto_ByHand2=Auto_ByHand;}
else if(Auto_ByHand=='l'){Auto_ByHand='h';TextOut(114,0,"ֶ",2);Auto_ByHand2=Auto_ByHand;}
else {Auto_ByHand='a';TextOut(114,0,"ҳ",2);Auto_ByHand2=Auto_ByHand;}
					}
			else if((i==2)||(i==3)||(i==4)||(i==5))
					{
					if(!DatFileIsOK){showword("DATļ/ʧ!");getchar();}
					else
						{
						
						if(i==2)
						 	{
						 	fseek(fpMark,106,0);putc(1,fpMark);putc(ms&0x00ff,fpMark);putc(ms>>8,fpMark);putc(Auto_ByHand,fpMark);
							TextOut(135,26," OK",2);OKisPrinted=2;
						 	}					
						 else if(i==3)
							{
							fseek(fpMark,40,0);putc(1,fpMark);fwrite(path,1,64,fpMark);putc(pathpoint,fpMark);
							TextOut(135,39," OK",2);OKisPrinted=3;
							}
						 else if(i==4)
							{
							PassWord_is_OK=0;
							fseek(fpMark,110,0);
							if(getc(fpMark)==1)
								{
								fread(filedata,1,53,fpMark);filedata[52]=0;

								do	{
									if(!inputpass(":",filedata+100))break;
									if(strcmp(filedata,filedata+100)){showword("!");if(getchar()==KEY_ESC||getchar()==KEY_ESC2)break;}
									else {PassWord_is_OK=1;break;}
									}while(1)
								}
								else PassWord_is_OK=1;
								
								if(!PassWord_is_OK){Refresh();continue;}
								
								if(!inputpass(":",filedata)){Refresh();continue;}
								else if(!inputpass("һ:",filedata+100)){Refresh();continue;}
								if(strcmp(filedata,filedata+100))
									{showword("벻һ!");Delay(1000);}
								else 
									{
									if(filedata[0]==0){fseek(fpMark,110,0);putc(0,fpMark);showword("!");Delay(1000);}
									else 
										{
										fseek(fpMark,110,0);putc(1,fpMark);fwrite(filedata,1,53,fpMark);
										showword("!");Delay(1000);
										}
									}
									
							}
						 else if(i==5)
						 	{
						 	set_fav();
						 	fseek(fpMark,166,0);
						 	fwrite(fav_setting,1,4,fpMark);
						 	}
						}
					}
			else continue;
			}
	else if(c==KEY_ESC||c==KEY_ESC2)break;
	else continue;
	Block(1,13*j,158,13*j+12,2);
	Block(1,13*i,158,13*i+12,2);
	Refresh();
	}while(1)
	
if(DatFileIsOK){fclose(fpMark);fpMark=0;fp=fopen(filestr,"r");}
}

char menu_F1()
{
char c;
char menuNUM;
char i;
char j;
char zhehang;

zhehang=1;
i=0;menuNUM=2;

SetScreen(1);
ClearScreen();

if(font)TextOut(0,0,"  *С  |  ",1);else TextOut(0,0,"   С  | *",1);
if(zhehang)TextOut(0,13,"  *    |  ",1);else TextOut(0,13,"       | *",1);

Block(1,0,158,12,2);
Refresh();

do	{
	do c=getchar();while((c!=20)&&(c!=21)&&(c!=KEY_ESC&&c!=KEY_ESC2)&&(c!=13))
	j=i;
	if((c==20)&&((i)))i--;
	else if((c==21)&&(i<menuNUM-1))i++;
	else if(c==13)
			{
			if(((i==0)&&font)||((i==1)&&zhehang))
				{
				if(i==0){font=0;linesize=20;}else if(i==1)zhehang=0;
				TextOut(12,i*13," ",2);
				TextOut(77,i*13,"*",2);
				}
			else if(((i==0)&&(!font))||((i==1)&&(!zhehang)))
				{
				if(i==0){font=1;linesize=26;}else if(i==1)zhehang=1;
				TextOut(12,i*13,"*",2);
				TextOut(77,i*13," ",2);
				}
			else continue;
			}
	else if(c==KEY_ESC||c==KEY_ESC2)break;
	else continue;
	Block(1,13*j,158,13*j+12,2);
	Block(1,13*i,158,13*i+12,2);
	Refresh();
	}while(1)
return zhehang;
}


long treat_SHIFT()
{
char SHIFT_cmd;
char time_cmd;

time_cmd=60;
do	{
	SHIFT_cmd=Inkey();
	Delay(50);
	time_cmd--;
	}while(time_cmd&&(!SHIFT_cmd)&&(SHIFT_cmd!=KEY_SHIFT))


if(SHIFT_cmd==20||SHIFT_cmd=='h'){thispage_begin=dataBegin;cmd=255;return 1;}
else if(SHIFT_cmd==21||SHIFT_cmd=='e'){thispage_begin=dataEnd;cmd=255;return 2;}
else if(SHIFT_cmd=='l'){SetMark(3);return 2;}

else if(SHIFT_cmd==KEY_ESC||SHIFT_cmd==KEY_ESC2){if(FileType==2){KEY=SHIFT_cmd;return 27;}else{cmd=27;return 0;}}
else if((SHIFT_cmd==19)&&(FileType==2)){KEY=19;return 19;}
else if((SHIFT_cmd==14)&&(FileType==2)){KEY=14;return 14;}

else {cmd=255;KEY=0;return 0;}
}

void findEBKmode()
{
char chmode;
chmode=0;
Box(32,24,129,65,1,0);
Box(32,24,129,65,0,1);
Box(33,66,131,67,0,1);
Box(130,25,131,65,0,1);
TextOut(57,29,"",193);
TextOut(57,45,"",193);
for(;;)
{
WriteBlock(40,33,8,8,65,choF);
WriteBlock(40,49,8,8,65,choF);
WriteBlock(40,33+16*chmode,8,8,65,choT);
cmd=getchar();
if((cmd==20)&&(chmode))chmode=0;
else if((cmd==21)&&(!chmode))chmode=1;
else if(cmd==27||cmd==KEY_ESC2)return;
else if(cmd==13)break;
}
findchmode=chmode;
if(chmode)thispage_begin=findInEBK(thispage_begin,1);
else {FileType=1;thispage_begin=find(thispage_begin,thispage_end,1);FileType=2;}
}

void Boss_KEY()
{
save_pass=0;
BOS:
SetScreen(0);
if(Boss_show==0)printf("***** Ӣǵ *****Ӣ:         [F1]ƴд        [F3]ع˲ѯ        [F4]ֿ        ");
else if(Boss_show==1)printf("                                                                      2635+221/1          ");
else if(Boss_show==2){SetScreen(1);printf(" ");}
for(;;){
cmd=getchar();
if(cmd==Boss_key)break;
else if(cmd>27&&cmd<31){Boss_show=cmd-28;goto BOS;}
else save_pass=1;
}
}

void viewTEXT()
{
char tempchar;
long newtime;
long oldtime;
char i,testt;

if(upfromim){
thispage_end=dataEnd-1;
thispage_begin=dataEnd;
upfromim=0;
}
else {thispage_end=dataBegin-1;
thispage_begin=dataBegin;
}
testt=1;
SHIFTaBYTE=0;
if(Auto_ByHand!='a'&&Auto_ByHand!='l'){Auto_ByHand='h';Auto_ByHand2=Auto_ByHand;}
if(cmd!=255)cmd=0;
if(FileType==255){SetMark(3);if(FileType==255)return;}
if(fav_setting[3])
{
GetTime(time);
oldtime=time.second+60*(time.minute+60*(time.hour+(24*time.day+(31*time.month+(12*(time.year-2000))))));
}
while(1)
{
if(fav_setting[3])
{
GetTime(time);
newtime=time.second+60*(time.minute+60*(time.hour+(24*time.day+(31*time.month+(12*(time.year-2000))))));
if(newtime-oldtime>=fav_setting[3]*60){i=10;do {if(!(i--))exit(0);inputpass(":",filedata+p_readpath);}while(strcmp(filedata+p_readpath,password))}
oldtime=newtime;
}
if(cmd==21||cmd==DIYdn){if((thispage_begin==dataEnd)&&(FileType==2)&&(VTorId_i<VTorId_maxID)){KEY=14;return;}else set_nextline();}
else if(cmd==14||cmd==22||cmd==DIYpgdn){if((thispage_begin==dataEnd)&&(FileType==2)&&(VTorId_i<VTorId_maxID)){KEY=14;return;}else set_nextpage();}
else if(cmd==19||cmd==23||cmd==DIYpgup){if((thispage_begin==dataBegin)&&(FileType==2)&&(VTorId_i>VTorId_minID)){KEY=19;return;}else set_lastpage();}
else if(cmd==20||cmd==DIYup){if((thispage_begin==dataBegin)&&(FileType==2)&&(VTorId_i>VTorId_minID)){KEY=19;return;}else set_lastline();}
else if(cmd==32){menu_SPACE();cmd=255;continue;}
else if(cmd==27||cmd==KEY_ESC2){if(FileType==1){if(fav_setting[1]){if(MsgBox("ȷ˳?",1))return;else{cmd=255;continue;}}else return;}else{KEY=27;return;}}
else if(cmd=='s'){SetMark(1);cmd=255;continue;}
else if(cmd=='l'){SetMark(2);cmd=255;continue;}
else if(cmd==Boss_key){Boss_KEY();if(save_pass==1)oldtime=0;cmd=255;continue;}
else if(cmd=='p'||cmd==15){pause();cmd=255;continue;}
else if(cmd==13){Set_fseek();cmd=255;continue;}
else if(cmd=='.'){if(SHIFTaBYTE)SHIFTaBYTE=0;else SHIFTaBYTE=1;thispage_end=thispage_begin-1;set_nextpage();}//
else if(cmd==KEY_HELP){printHELP();cmd=255;continue;}
else if(cmd==29){if(DELETEorNOT())return;cmd=255;continue;}
else if(cmd==30){if(FileType==1)thispage_begin=find(thispage_begin,thispage_end,1);else if(FileType==2)findEBKmode();cmd=255;continue;}//
else if(cmd==48){if(tofindstrs[0]){if(FileType==1)thispage_begin=find(thispage_begin,thispage_end,0);else if(FileType==2){if(findchmode)thispage_begin=findInEBK(thispage_begin,0);else {FileType=1;thispage_begin=find(thispage_begin,thispage_end,0);FileType=2;}}}cmd=255;continue;}//
else if(cmd==255){thispage_end=thispage_begin-1;set_nextpage();}//ظղŵһҳ
else if(cmd==254){if(fav_setting[0]){if(DELETEorNOT())return;else {thispage_end=thispage_begin-1;set_nextpage();}}cmd=getchar();if((cmd==14)&&(FileType==2)&&(VTorId_i<VTorId_maxID)){KEY=14;return;}continue;}
else if(cmd==KEY_SHIFT){tempchar=treat_SHIFT();if(tempchar<10)continue;else return;}
else if(cmd==28){if(!menu_F1())print_6or5_ph(thispage_begin);cmd=255;continue;}
else if(cmd=='w'||cmd=='o'){  hkpas=-hkpas;                    
                     if(hkpas==-1)
                    {Auto_ByHand='h';}
                      else {Auto_ByHand=Auto_ByHand2;}
                        cmd=255;
                          continue;
                          }//ͣ||
else if(cmd!=0)set_nextpage();
else if(Auto_ByHand=='l'&&testt!=1)set_nextline();
else set_nextpage();
if(cmd==254){if(fav_setting[0]){if(DELETEorNOT())return;else {thispage_end=thispage_begin-1;set_nextpage();}}cmd=getchar();if((cmd==14||cmd==DIYpgdn)&&(FileType==2)&&(VTorId_i<VTorId_maxID)){KEY=14;return;}continue;}
if(Auto_ByHand=='a'||Auto_ByHand=='l'){cmd=0;testt=0;Delay_or_Inkey();}
}
}

char print_short(long from,char maxsize,char x,char y,int focus,int clear)
{
char size;
fseek(fp,from,0);
for(size=0;size<maxsize;size++)
	{
	filedata[size]=getc(fp);
	if ((filedata[size]>127)&&(filedata[size]!=255))filedata[++size]=getc(fp);
	else if((filedata[size]==255)||(size>=maxsize-1)||size>=200-4){size++;break;}
	
	}
if(focus)CurrentSubDir_Name_p=from+size;
if(filedata[size-1]==255)
	{
	{if(focus)CurrentSubDir_Name_p=SubDir_name[CurrentSubDir-fromSubDir];}
	filedata[size-1]=0;
	}
else {filedata[size]='.';filedata[size+1]='.';filedata[size+2]=0;}



    if(clear) ClearScreen();
    if(focus)focus=8;else focus=0;
    TextOut(x,y,filedata,1+focus);
    
return size;
}

void dir_list()
{
char dir_list_i;
char dir_list_j;
char dir_list_SubDir;
dir_list_SubDir=fromSubDir;

fseek(fp,dir_add+3+dir_list_SubDir*2,0);
dir_list_i=0;
while((dir_list_SubDir<Num_of_SubDir)&&(dir_list_i<5))
	{
	SubDir_add[dir_list_i++]=getc(fp)+getc(fp)*256;
	dir_list_SubDir++;
	}
	
fseek(fp,dir_add+3+Num_of_SubDir*2,0);
dir_list_SubDir=fromSubDir;
while(dir_list_SubDir--)while (getc(fp)!=0xff);
dir_list_SubDir=fromSubDir;dir_list_i=0;
while((dir_list_SubDir<Num_of_SubDir)&&(dir_list_i<5))
	{
	SubDir_name[dir_list_i++]=ftell(fp);
	if(dir_list_SubDir<Num_of_SubDir)while(getc(fp)!=0xff);
	dir_list_SubDir++;
	}
dir_list_SubDir=fromSubDir;

ClearScreen();
while ((dir_list_SubDir-fromSubDir)!=dir_list_i)
	{
	print_short(SubDir_name[dir_list_SubDir-fromSubDir],len_SubDir,12,(dir_list_SubDir-fromSubDir+1)*13+2,dir_list_SubDir==CurrentSubDir,dir_list_SubDir++==fromSubDir);
	}

if(dir_p>3)dir_list_j=dir_p-3;else dir_list_j=0;
for (dir_list_i=dir_list_j;dir_list_i<dir_p;dir_list_i++)
	{
	print_short(dir[dir_list_i],6,(dir_list_i-dir_list_j)*53+1,1,0,0);
	TextOut((dir_list_i-dir_list_j)*53+37,1,"..>",1);
	}
Refresh();
}

void printimage(long imageDataFrom,long READto,int width,int height,int x,int y,char imagetype,char fanxian)//imagetype(ɨ) 1>EBK;2 BMP
{
char i;
char c;
char read_x;
char read_y;
long Seek;
	if (width>=20)read_x=20;else read_x=width;
	if (height>=80)read_y=80;else read_y=height;
	ClearScreen();
	for(i=0;i<read_y;i++)
		{
		if(!imagetype)
			{
			fseek(fp,imageDataFrom,0);fread(READto,1,1600,fp);WriteBlock(0,0,160,80,1+fanxian,READto);break;
			}
		else if(imagetype==1)Seek=imageDataFrom+x+y*width;
		else if(imagetype==2)Seek=imageDataFrom+width*(height-(y+1))+x;
		
		fseek(fp,Seek,0);
		fread(READto,1,read_x,fp);
		if(imagetype==1)WriteBlock(0,i,read_x*8,1,1+fanxian,READto);
		else if(imagetype==2)WriteBlock(0,i,read_x*8,1,1+fanxian,READto);
		y++;//////////
		}Refresh();

}

long viewBlock()
{
char viewBlock_width;
char viewBlock_height;
char viewBlock_x;
char viewBlock_y;

if(FileType!=2)
	{
	viewTEXT();
	return -1;
	}

//Inkey();

fseek(fp,BlockOffset+BlockID*9,0);
KEY=getc(fp);
dataBegin=getc(fp)+getc(fp)*256+getc(fp)*256*256;
dataEnd=getc(fp)+getc(fp)*256+getc(fp)*256*256;

if (KEY==0)
	{
	viewTEXT();
	if(FileType==1)return -1;
	return 0;
	}
else 
	{
	fseek(fp,dataBegin,0);
	viewBlock_width=getc(fp);
	viewBlock_height=getc(fp);
	viewBlock_x=0;
	viewBlock_y=0;
	do	{
		printimage(dataBegin+2,filedata,viewBlock_width,viewBlock_height,viewBlock_x,viewBlock_y,1,0);
		do KEY=getchar(); while((KEY!=23)&&(KEY!=22)&&(KEY!=21)&&(KEY!=20)&&(KEY!=27)&&(KEY!=14)&&(KEY!=19)&&(KEY!=KEY_ESC2));
			if(KEY==27||KEY==KEY_ESC2)break;
			else if((KEY==23)&&(viewBlock_x>0))viewBlock_x--;
			else if((KEY==22)&&(viewBlock_x+20<viewBlock_width))viewBlock_x++;
			else if((KEY==20)&&(viewBlock_y>0)){if(viewBlock_y>=8)viewBlock_y=viewBlock_y-8;else viewBlock_y=0;}
			else if((KEY==21)&&(viewBlock_y+80<viewBlock_height)){if(viewBlock_y+88<=viewBlock_height)viewBlock_y=viewBlock_y+8;else viewBlock_y=viewBlock_height-80;}
		ReleaseKey(23);ReleaseKey(22);ReleaseKey(20);ReleaseKey(21);
		}while((KEY!=27)&&(KEY!=14)&&(KEY!=19)&&(KEY!=KEY_ESC2))
	1;
	return 1;
	}

}

void viewtextorimagedir()
{
char FileType_info;

FileType_info=FileType;
upfromim=0;
if(FileType==2)
	{
	fseek(fp,VTorId_add+7,0);
	VTorId_minID=getc(fp)+getc(fp)*256;
	getc(fp);getc(fp);getc(fp);
	VTorId_maxID=getc(fp)+getc(fp)*256;
	VTorId_i=VTorId_minID;	
	}

else{
	viewBlock();
	if(FileType!=2)return;
	}


while(1)
	{
	if(!fp)return;
	if(FileType_info==2){KEY=0;BlockID=VTorId_i;viewBlock();if(FileType==1)return;}
	
	if(VTorId_maxID==VTorId_minID)
		{
		break;
		}
	else 
		
		{
		if(KEY==27||KEY==KEY_ESC2){KEY=0;break;}
		else if((KEY==14)&&(VTorId_i<VTorId_maxID)){VTorId_i++;upfromim=0;}
		else if((KEY==19)&&(VTorId_i>VTorId_minID)){VTorId_i--;upfromim=1;}
		//else if(VTorId_i==VTorId_maxID)break;
		}
	
	}

}

void viewEBK()
{
char c;
dir_p=0;

ebk_v_BEGIN=EBK_only_for_mark_begin;
ebk_v_END=EBK_only_for_mark_end;
if(FileType==2)
{
c=0;
dir_add=15;
CurrentSubDir_p[dir_p]=0;
fromSubDir=0;
fseek(fp,3,0);
BlockOffset=getc(fp)+getc(fp)*256+15;	
}

else{viewtextorimagedir();if(FileType!=2)return;}

while(1)
{
if(!fp)return;
CurrentSubDir=CurrentSubDir_p[dir_p];
fromSubDir=CurrentSubDir-(CurrentSubDir%5);
fseek(fp,dir_add,0);
Num_of_SubDir=getc(fp);
parentdir=getc(fp)+getc(fp)*256;
dir_list();
CurrentSubDir_Name_p=SubDir_name[CurrentSubDir-fromSubDir];
while(1)
{
if(c!=29)
{
Line(159,0,159,79,1);
Line(159,80*CurrentSubDir/Num_of_SubDir,159,80*(CurrentSubDir+1)/Num_of_SubDir,0);
c=getchar();
if((c==13)||(c==27)||(c==KEY_ESC2))break;}
else {dir_list();c=getchar();}
if((c==20)&&(CurrentSubDir>0))
{
CurrentSubDir--;
if(CurrentSubDir<fromSubDir){fromSubDir--;dir_list();}
else {
TextOut(12,(CurrentSubDir-fromSubDir+2)*13+2,"                         ",1);
print_short(SubDir_name[CurrentSubDir+1-fromSubDir],len_SubDir,12,(CurrentSubDir-fromSubDir+2)*13+2,0,0);
print_short(SubDir_name[CurrentSubDir-fromSubDir],len_SubDir,12,(CurrentSubDir-fromSubDir+1)*13+2,1,0);
Refresh();
}
}
else if((c==21)&&(CurrentSubDir+1<Num_of_SubDir))
{
CurrentSubDir++;
if(CurrentSubDir>=fromSubDir+5){fromSubDir++;dir_list();}
else {
TextOut(12,(CurrentSubDir-fromSubDir)*13+2,"                         ",1);
print_short(SubDir_name[CurrentSubDir-1-fromSubDir],len_SubDir,12,(CurrentSubDir-fromSubDir)*13+2,0,0);
print_short(SubDir_name[CurrentSubDir-fromSubDir],len_SubDir,12,(CurrentSubDir-fromSubDir+1)*13+2,1,0);
Refresh();
}
}
else if ((c==14)&&(fromSubDir+5<Num_of_SubDir))
{
if(CurrentSubDir+5<Num_of_SubDir)
{CurrentSubDir=CurrentSubDir+5;fromSubDir=fromSubDir+5;}
else{CurrentSubDir=Num_of_SubDir-1;fromSubDir=fromSubDir+5;}
dir_list();
}
else if (c==19)
{
if(CurrentSubDir>4)
{
CurrentSubDir=CurrentSubDir-5;
if(fromSubDir>=5)fromSubDir=fromSubDir-5;
else fromSubDir=0;
dir_list();
}
else if(fromSubDir>0&&CurrentSubDir<5)
{
fromSubDir=0;
dir_list();
}
}
else if(c==22)
{
TextOut(12,(CurrentSubDir-fromSubDir+1)*13+2,"                          ",1);
print_short(CurrentSubDir_Name_p,len_SubDir,12,(CurrentSubDir-fromSubDir+1)*13+2,1,0);
Refresh();
}
else if(c=='h'){fromSubDir=0;CurrentSubDir=0;dir_list();}
else if(c=='e'){fromSubDir=Num_of_SubDir-1;CurrentSubDir=fromSubDir;dir_list();}
else if(c==29){if(DELETEorNOT())return;}

CurrentSubDir_p[dir_p]=CurrentSubDir;
}

if (c==27||c==KEY_ESC2)
		{
		fseek(fp,dir_add+1,0);
		parentdir=getc(fp)+getc(fp)*256;
if(parentdir==0){if(fav_setting[1]){if(MsgBox("ȷ˳?",1))return;}else return;}
else {dir_add=parentdir;CurrentSubDir_p[dir_p]=0;dir_p--;fromSubDir=CurrentSubDir_p[dir_p]/5*5;}
		}
	else if (c==13)
		{
		dir[dir_p]=SubDir_name[CurrentSubDir-fromSubDir];
		fseek(fp,SubDir_add[CurrentSubDir-fromSubDir],0);
		if(getc(fp)==0){VTorId_add=SubDir_add[CurrentSubDir-fromSubDir];viewtextorimagedir();if(FileType==1)return;}
		else {dir_add=SubDir_add[CurrentSubDir-fromSubDir];CurrentSubDir_p[dir_p]=CurrentSubDir;dir[dir_p++]=SubDir_name[CurrentSubDir-fromSubDir];CurrentSubDir=0;fromSubDir=0;}
		
		}
	}
}


void view_B16()
{
int n;
int i;
int j;
int size_photo;
char B16DataOffset;
char B16data[1600];
char WriteBlock_type;
char c;
char B_n;
char fp_add;
char file_add[16];
long file_add_size;
long file_add_p;

j=0;
i=0;
c=0;
WriteBlock_type=65;
dataEnd=fsize(fp);
rewind(fp);
if(dataEnd==11200){B16DataOffset=0;size_photo=11200;B_n=8-1;n=1;}
else if((getc(fp)=='B')&&(getc(fp)=='1')&&(getc(fp)=='6'))
		{
		B16DataOffset=getc(fp);
		n=getc(fp);
		size_photo=24000;
		B_n=16-1;
		}
else {SetScreen(1);printf("\n\nļ˳.....");Delay(500);return;}

if(n*size_photo+B16DataOffset!=dataEnd)
	{
	SetScreen(1);printf("\n ļ𻵣Ƿ\n\n   <Y>       <N> ");
	while((c=getchar())!='y'&&(c!='n')&&(c!=27)&&(c!=KEY_ESC2));
	if((c==27)||(c=='n')){SetScreen(1);printf("˳.....");Delay(500);return;}
	}

while(c!=27&&c!=KEY_ESC2)
	{
	for(j=0;j<=B_n;j++)
		{
		if (j==B_n){j=-1;continue;}
		else 
			{
			fseek(fp,B16DataOffset+i*size_photo+j*1600,0);
			fread(B16data,1,1600,fp);
			WriteBlock(0,0,160,80,WriteBlock_type,B16data);
			}
		if(c=CheckKey(128))
			{
				if((c==14)&&(i<n-1)&&(dataEnd-B16DataOffset-i*size_photo>=1600*B_n)){i++;j=-1;ReleaseKey(128);Delay(200);}
				else if((c==19)&&(i>0)){i--;j=-1;ReleaseKey(128);ClearScreen();Refresh();Delay(200);}
				else if(c==26){ReleaseKey(26);ClearScreen();Refresh();Delay(200);if(WriteBlock_type==65)WriteBlock_type=66;else WriteBlock_type=65;}
				else if(c==27||c==KEY_ESC2)break;
				else if(c==29){getchar();if(DELETEorNOT())return;}
				else if((c==28)&&(B_n==15))//׷B16ͼƬ
						{
						if (!FileList(file_add)) {SetScreen(1);printf("\n\n     ׷B16ͼƬ");Delay(500);continue;}
						else {
							SetScreen(1);
							fclose(fp);fp=fopen(filestr,"r+");
							if(!(fp_add=fopen(file_add,"r")))printf("\n\n     ļʧ!");file_add_size=fsize(fp_add);file_add_p=file_add_size-20;
							if(file_add_size-file_add_size/24000*24000!=20){printf("\n\n  ѡļļƥ");Delay(1500);continue;}
							fseek(fp_add,20,0);fseek(fp,0,SEEK_END);
							while(file_add_p>0){fread(B16data,1,1600,fp_add);fwrite(B16data,1,1600,fp);file_add_p=file_add_p-1600;}
							fclose(fp_add);fp_add=0;fseek(fp,4,0);n=n+file_add_size/24000;putc(n,fp);dataEnd=dataEnd+file_add_size-20;printf("\n\n   ׷ %d ͼƬ",file_add_size/24000);Delay(1000);
							}
						}
			
			}	
		
		}
	}
	
}


/*
void Creat_BMP16()
{
char data[3000];
char BMP16_data[800];
int BMP16_data_every4[8];
char i;
char j;
char k;
char m;
char c;
char fp1;
int width;
int height;

SetScreen(1);printf("\n\n B16ͼƬ");

	dataBegin=getnum(fp,0x0a,4);
	width=getnum(fp,0x12,4);
	height=getnum(fp,0x16,4);
fseek(fp,dataBegin,0);
fp1=fopen("/LavaData/ReaderTmp.b16","w+");
putc('B',fp1);putc('1',fp1);putc('6',fp1);
putc(20,fp1);putc(1,fp1);
putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);putc(0,fp1);


for(i=0;i<8;i++)fwrite(data,1,3000,fp1);
Box(10,45,150,55,0,1);

for(i=79;i<80;i=i-10)
	{
	for(j=0;j<10;j++){fseek(fp,dataBegin+(i-j)*80,0);fread(BMP16_data+80*j,1,80,fp);}
		for(j=0;j<200;j++)
			{
			BMP16_data_every4[0]=((BMP16_data[4*j]&0xf0)<<1)+(rand()>>12);BMP16_data_every4[1]=((BMP16_data[4*j]&0x0f)<<5)+(rand()>>12);
			BMP16_data_every4[2]=((BMP16_data[4*j+1]&0xf0)<<1)+(rand()>>12);BMP16_data_every4[3]=((BMP16_data[4*j+1]&0x0f)<<5)+(rand()>>12);
			BMP16_data_every4[4]=((BMP16_data[4*j+2]&0xf0)<<1)+(rand()>>12);BMP16_data_every4[5]=((BMP16_data[4*j+2]&0x0f)<<5)+(rand()>>12);
			BMP16_data_every4[6]=((BMP16_data[4*j+3]&0xf0)<<1)+(rand()>>12);BMP16_data_every4[7]=((BMP16_data[4*j+3]&0x0f)<<5)+(rand()>>12);
		
			for(m=0;m<15;m++)
				{
				data[200*m+j]//B16_order[*]
					=(B16_order[BMP16_data_every4[0]++]<<7)
					+(B16_order[BMP16_data_every4[1]++]<<6)
					+(B16_order[BMP16_data_every4[2]++]<<5)
					+(B16_order[BMP16_data_every4[3]++]<<4)
					+(B16_order[BMP16_data_every4[4]++]<<3)
					+(B16_order[BMP16_data_every4[5]++]<<2)
					+(B16_order[BMP16_data_every4[6]++]<<1)
					+B16_order[BMP16_data_every4[7]++];
				}
			Box(10,45,10+140*j/1600+140*(79-i)/80,55,1,1);
			}

	Box(10,45,10+140*(80-i)/80,55,1,1);
	for(m=0;m<15;m++)
		{
		fseek(fp1,20+1600*m+20*(79-i),0);
		fwrite(data+200*m,1,200,fp1);
		}
	if(CheckKey(27)) return;
	}	



fclose(fp1);fp1=0;

fclose(fp);fp=0;
if ((fp=fopen("/LavaData/ReaderTmp.b16","r+"))==0) {SetScreen(1);printf("ļ %s ʧ!",filestr);getchar();return;}
dataEnd=fsize(fp);
view_B16();
}
*/

void view_BMP()
{
char TypeIsRight;
int width;
int height;
int x;
int y;
char c;
char i;
char fanxian;

TypeIsRight=0;
fanxian=0;

if((getc(fp)=='B')&&(getc(fp)=='M'))
	{
	fseek(fp,28,0);
	if((c=getc(fp))==1){getc(fp);if(getc(fp)==0)TypeIsRight=1;}
	//else if(c==4){getc(fp);if(getc(fp)==0)TypeIsRight=2;}//16ҶBMPͼƬ
	}
if(TypeIsRight==0) {SetScreen(1);printf("\n\n ָ֧øʽBMPͼƬ");Delay(1000);return;}
//if(TypeIsRight==2) {if(fsize(fp)!=6518){SetScreen(1);printf("\n\n  ֻ֧\n  160*80 16ҶBMPͼƬ\n\n        ˳");Delay(1500);}else Creat_BMP16();return;}

else
	{
	dataBegin=getnum(fp,0x0a,4);
	width=getnum(fp,0x12,4);
	height=getnum(fp,0x16,4);
	width=((width-1)/32+1)*4;
	x=0;
	y=0;
	c=128;
	while(1)
		{
		printimage(dataBegin,filedata,width,height,x,y,2,fanxian);
		ReleaseKey(c);
		do	{
			if(CheckKey('q'))i=0;else i=3;
			c=getchar();
			}while(c=='q')
			
		if(c==27||c==KEY_ESC2)break;
		else if(c==KEY_SHIFT){if(fanxian)fanxian=0;else fanxian=1;Delay(100);continue;}
		
		while(i<4)
			{
			if((c==23)&&(x>0))x--;
			else if((c==22)&&(x+20<width))x++;
			else if(c==20){if(y>=8)y=y-8;else y=0;}
			else if(c==21){if(y+88<=height)y=y+8;else y=height-80;}
			i++;
			}
		
		
		
		}
		
	}
}

void play_flm()
{
int n;
int i;
int j;
int k;
char m;
char c;
char FLM_type;
char FLMdata[1800];
char FLMdata_j;
char imagedata[1600];
char unused[70];
int imageDataType;
char WriteBlock_type;
int FLM2size;
char FLM2dataType;
char copysize;
long FLM20_databegin;
char timestr_1[10];
char timestr_2[10];
int DELAYtimeMS;

rewind(fp);



if((getc(fp)=='F')&&(getc(fp)=='L')&&(getc(fp)=='M')&&(getc(fp)==16))
	{
	
	GetTime(time);//////////////////////////ʼʱ//////////////////////////////
	sprintf(timestr_1,"%d:%d:%d",time.hour,time.minute,time.second);///////////////
	
	if((FLM_type=getc(fp))==0)
		{
		n=getc(fp)+getc(fp)*256+1;
		DELAYtimeMS=getc(fp)+getc(fp)*256;
		DELAYtimeMS=DELAYtimeMS*36/10;if(DELAYtimeMS<10)DELAYtimeMS=10;
		if(n!=fsize(fp)/1600)
			{
			SetScreen(1);printf("\n ļ𻵣Ƿ\n\n   <Y>       <N> ");
			while((c=getchar())!='y'&&(c!='n')&&(c!=27));
			if((c==27)||(c=='n')){SetScreen(1);printf("˳.....");Delay(500);return;}
			}	
		for(i=0;i<n;i++)
			{
			printimage(16+i*1600,imagedata,160/8,80,0,0,0,0);
			if((c=Inkey())==27||(c=Inkey())==KEY_ESC2)break;
			else if(c=='p')while(getchar()!='p');
			Delay(DELAYtimeMS);
			}
		}
	else if(FLM_type==1)
		{
		n=getc(fp)+getc(fp)*256+1;
		FLM2size=0;
		FLM20_databegin=16;
		
		for(i=0;i<n;i++)
			{
			fseek(fp,FLM20_databegin,0);
			
			FLM2size=getc(fp);
			FLM2dataType=getc(fp);
			FLM2size=FLM2size+(FLM2dataType&0x0f)*256;
			FLM20_databegin=FLM20_databegin+FLM2size;
			FLM2dataType=FLM2dataType/16;
			if(FLM2dataType==1)
				{
				memset(imagedata,0,1600);
				}
			else FLM2dataType=5;
				
			fread(FLMdata,1,FLM2size-2,fp);		
			FLM2size=FLM2size-3;
			k=0;
			j=0;
			
			do	{
				FLMdata_j=FLMdata[j];
				if(FLMdata_j>0xc0)
					{c=FLMdata[++j];copysize=FLMdata_j-0xc0;while(copysize--)imagedata[k]=imagedata[k++]+c;}
		
				else if(FLMdata_j==0x80) 
					{copysize=0x40;while(copysize--)imagedata[k]=imagedata[k++]+FLMdata[++j];}
		
				else if(FLMdata_j>0x80)
					{copysize=FLMdata_j-0x80;while(copysize--)imagedata[k]=imagedata[k++]+FLMdata[++j];}
		
				else if(FLMdata_j>0x40)
					{copysize=FLMdata_j-0x40;while(copysize--)imagedata[k++]--;}
		
				else if(FLMdata_j>0x00)	
					k=k+FLMdata_j;//copysize=FLMdata_j;//imagedata[k]=imagedata[k++]+0x00


				else if(FLMdata_j==0x00)
					{do{k=k+64;}while(((FLMdata[++j])==0)&&((j<FLM2size+1)));j--;}
			
				j++;
	
				}while((j<FLM2size)&&(k<1600))

			ClearScreen();
			WriteBlock(0,0,160,80,FLM2dataType,imagedata);
			
			Refresh();
			if((c=Inkey())==27||(c=Inkey())==KEY_ESC2)break;
			else if(c=='p')while(getchar()!='p');
			}
			
		}

	}
	
	GetTime(time);//////////////////////////ֹͣʱ//////////////////////////////
	sprintf(timestr_2,"%d:%d:%d",time.hour,time.minute,time.second);///////////////
	ClearScreen();
	SetScreen(1);
	printf("֡%d(%d)\n\nʼʱ%s\nֹͣʱ%s",i,n,timestr_1,timestr_2);
	getchar();
}


char readAfile()
{
int Mem_add1;
int Mem_add2;
char i;

if(FileType==255){/*viewTEXT();*/viewEBK();FileType=0;fclose(fp);fp=0;return 1;}
else 
	{
	if((filestr[0])&&(FileType==1)&&(fav_setting[2]))
		{
		if(nextfile(filedata))
			{
			if(fp=fopen(filedata,"r"))
				{
				Inkey();
				SetScreen(1);
				printf("   Ƿļ:\n\n     %s",filedata);
				if(getchar()!='y')
					{
					fclose(fp);
					fp=0;
					if(!fopen_fp())return 0;
					}
				else strcpy(filestr,filedata);
				}
			else if(!fopen_fp())return 0;
			}
		else if(!fopen_fp())return 0;
		}
	else if(!fopen_fp())return 0;
	}

FileType=TYPEofFILE();
//nextfile(filedata);
if(FileType==1)
	{
	if(getc(fp)==0)dataBegin=24;else dataBegin=0;
	dataEnd=fsize(fp);
	//viewTEXT();
	viewEBK();
	}
else if(FileType==2)
	{
	viewEBK();
	}
else if(FileType==3)
	{
	view_B16();
	Inkey();
	}
else if(FileType==4)
	{
	view_BMP();
	Inkey();
	}
else if(FileType==5)
	{
	play_flm();
	}
if(fp){fclose(fp);fp=0;}
return 1;
}

void main()
{
char i;
long temp_var;
char c;
SetScreen(1);
showword("ڶȡ...");Delay(300);
Box(1,0,159,79,1,0);
c=0;pathpoint=0;
DatFileIsOK=0;
font=1;linesize=26;
filestr[0]=0;

if(fpMark=CheckExistDATfile())
{
DatFileIsOK=1;
fseek(fpMark,40,0);
fread(filedata,1,136,fpMark);
if(filedata[70]==1){SetScreen(1);Box(1,0,159,79,1,0);inputpass(":",filedata+140);if(strcmp(filedata+71,filedata+140)){showword("!");getchar();exit(0);}else strcpy(password,filedata+140);}else password[0]=0;
if(filedata[66]==1){temp_var=filedata[67]+filedata[68]*256;if((temp_var>=200)&&(temp_var<=20000))ms=temp_var;Auto_ByHand=filedata[69];Auto_ByHand2=filedata[69];}
if(filedata[0]==1){c=1;memcpy(path,filedata+1,64);pathpoint=filedata[65];ChDir("/");for(i=0;i<pathpoint;i++)if(!ChDir(path[i]+1)){pathpoint=i;strcpy(path[i],"/");break;}}
memcpy(fav_setting,filedata+126,4);
}//cùĬĿ¼ı־
fseek(fpMark,180,0);
Boss_key=getc(fpMark);
if(Boss_key==0)Boss_key='x';
fclose(fpMark);fpMark=0;

if((!DatFileIsOK)||(!c))
	{
	ChDir("/ıļ");
	strcpy(path[0],"/ıļ");
	strcpy(path[++pathpoint],"/");
	}


if((CheckKey(KEY_HELP))||(CheckKey(KEY_SHIFT)))FileType=255;
else FileType=0;

while(1)
	{
	readAfile();
	}
}



/*
datļṹ:

0-39		ǩʹñ־;
40			ĬĿ¼ñ־;
41-104	ĬĿ¼(path[][]);
105			ĬĿ¼(pathpoint);
106			ҳʱñ־;
107-108	ҳʱ(ms);
109			ֶ/Զ;
110			ñ־;
111-164	;
166-?
256-(256+128*20)	ǩ;
(256+128*20)-(256+128*20+128*20)	EBKǩĿ¼Ϣ;
.
*/