📄 tools.h
字号:
{
Gwindow_showstring(gwnd,1,1,sss);
unsigned char s1[70]="";
gcvt(rr,8,s1);
Gwindow_editstring(gwnd,1+strlen(sss),1,s1);
unsigned char s2[70]="";
Rtrim(s1,s2);
unsigned char s3[70]="";
Ltrim(s2,s3);
r=strtod(s3,&endptr);
if(*endptr!='\0')
{ Error("format of data error,input again!");
Gwindow_clear_line(gwnd,1);
}
}
while( !(*endptr=='\0') );
Gwindow_done(gwnd);
}
struct fdunode
{
public:
fdunode * prior,* next;
char fileinfo[30];
word no;
};
typedef fdunode * fdulink;
fdulink l,curp,curpno1;
gwindow gwnd;
int fcol,frow;
char p1[20],f1[20];
void Create_fdulink(fdulink& l,string path,int attr)
{fdulink s;
word n=0;
struct ffblk ffblk;
struct ffblk *p=nil;
p=&ffblk;
int done;
l=new fdunode;
l->prior=l;
l->next=l;
n=0;
l->no=n;
done=findfirst(path,p,FA_DIREC);
if(done!=0)
;//Gwindow_showstring(gwnd,1,1,"not find path");
else
{
while (!done)
{
n=n+1;
s=new fdunode;
s->no=n;
strcpy(s->fileinfo,p->ff_name);
s->prior=l->prior;
s->next=l;
s->prior->next=s;
l->prior=s;
done=findnext(p) ;
}
l->no=s->no;
}
}
void Dispose_fdulink(fdulink& l)
{ fdulink s;
l->prior->next=nil;
while (l!=nil)
{ s=l;
l=l->next;
delete s;
}
}
void Goto_fdulink_no(fdulink l,int n,fdulink& p)
{ int i=0;
p=l;
while ( (i!=n)&&(p->next!=l))
{ p=p->next;
i=i+1;
}
}
void Goto_fdulink_delno(fdulink p0,int deln,fdulink& p)
{ p=p0;
if (deln>0)
while ( (deln!=0)&&(p->next!=l) )
{ p=p->next;
deln--;
}
else while ( (deln!=0)&&(p->prior!=l) )
{ p=p->prior;
deln++;
}
}
void Dispfilename_gwindow_from(fdulink p1, gwindow& gwnd)
{int i,j,num;
fdulink p;
setfillpattern(fillpatterntype,GREEN);
bar(gwnd.gx1+4,gwnd.gy1+4,gwnd.gx2-4,gwnd.gy2-4);
num=0;
p=p1;
if (p!=l)
while ( (p!=l)&&(num<frow*fcol))
{ i=num/fcol+1;
j=num%fcol+1;
Gwindow_showstring(gwnd,(j-1)*14+1,i,p->fileinfo);
p=p->next;
num=num+1;
}
}
void Scroll(int delrow,fdulink& curpno1, gwindow& gwnd)
{Goto_fdulink_delno(curpno1,-delrow*fcol,curpno1);
Dispfilename_gwindow_from(curpno1,gwnd);
}
int Rows(fdulink p)
{int rows=(p->no-1)/fcol+1;
return rows;
}
int Relcol(int relnum) // {1<=.. <=fcol}
{ int relcol=relnum%fcol+1;
return relcol;
}
int Relrow(int relnum) // {1<=.. <=frow}
{ int relrow=relnum/fcol+1;
return relrow;
}
int Relnum()
{ int relnum=curp->no-curpno1->no;
return relnum;
}
int Curno1()
{ int curno1=curpno1->no;
return curno1;
}
void Selectfile_in_gwindow(fdulink l,string fname,
gwindow& gwnd,boolean& selected)
{ int key;
int i,j,newrow,dr;
string s1;
boolean aborted,redisp;
i=1; j=1;
aborted=false;
selected=false;
curp=l->next;
curpno1=curp;
Dispfilename_gwindow_from(curpno1, gwnd);
Gmenubar_init(gmnbar,RED,12);
Gmenubar_moveto(gwnd,gmnbar,i,j);
do
{
Getkey(key,funckey);
Gmenubar_hide(gwnd,gmnbar);
if (!funckey) //{ return or esc }
if (key==10||key==13)
{ strcpy(fname,curp->fileinfo);
selected=true;
}
else if (key==esc)
aborted=true;
else
cout<<'\007'<<endl;
else if (key==left||key==right||key==up||key==down||key==pgup||key==pgdn||key==home||key==endk)
switch(key)
{
case up: if (curp->no>fcol)
{
Goto_fdulink_delno(curp,-fcol,curp);
if (Relnum()<0)
Scroll(1, curpno1,gwnd);
}
break;
case down: if (l->no-curp->no>=fcol)
{ Goto_fdulink_delno(curp,fcol, curp);
if (Relnum()>=frow*fcol)
Scroll(-1, curpno1,gwnd);
}
break;
case left: if (curp->no>1 )
{ curp=curp->prior;
if (Relnum()<0 )
Scroll(1,curpno1,gwnd);
}
break;
case right: if (curp->no<l->no)
{
curp=curp->next;
if (Relnum()>=frow*fcol)
Scroll(-1,curpno1,gwnd);
}
break;
case home: { j=Relcol(Relnum());
Goto_fdulink_delno(curp,-(j-1), curp);
}
break;
case endk: { j=Relcol(Relnum());
Goto_fdulink_delno(curp,fcol-j, curp);
}
break;
case pgup: if (curpno1->no==1) //{top page}
Goto_fdulink_delno(curp,-fcol*(Relnum()/fcol),curp);
else if
(Curno1()>fcol*(frow-1) )
// { whole page }
{
Goto_fdulink_delno(curp,-fcol*(frow-1),curp);
Scroll(frow-1,curpno1,gwnd);
}
else { curpno1=l->next;
if (Rows(curp)>=frow)
Goto_fdulink_delno(curp,-fcol*(frow-1),curp);
else
Goto_fdulink_delno(curp,-fcol*(Rows(curp)-1),curp);
Dispfilename_gwindow_from(curpno1, gwnd);
}
break;
case pgdn: if( curp->no+(frow-1)*fcol<=l->no) //{after Have a page}
{ Goto_fdulink_delno(curp,fcol*(frow-1),curp);
Scroll(-(frow-1),curpno1,gwnd);
}
else if (curpno1->no+frow*fcol-1<=l->no)
{ curp=l->prior; // {after. Have half page}
Scroll(-(frow-1),curpno1,gwnd);
}
else curp=l->prior;// {last page, goto last node}
break;
}
i=Relrow(Relnum());
j=Relcol(Relnum());
Gmenubar_moveto(gwnd,gmnbar,i,j);
}
while( !(selected||aborted) );
Gmenubar_hide(gwnd,gmnbar);
}
void Get_file_from_gwindow(string path,int attr,string fname,
int xl,int yl,int xr,int yr,boolean& selected)
{
if ( (!Is_file_path(path) ) && Havefile(path,attr) )
{ strcpy(fname,path);
selected=true;
}
else {
fcol=Trunc((xr-xl+1)/14);
frow=yr-yl+1;
xr=xl+fcol*14;
Create_fdulink(l,path,attr);
if (l->next==l)
{ strcpy(fname,"");
unsigned char ss[60]="no files in path,";
Waitkey(ss,yl-2,1);
selected=false;
}
else
{ Gwindow_init(gwnd,xl,yl,xr,yr);
Gwindow_newwindow(gwnd);
Selectfile_in_gwindow(l,fname,gwnd,selected);
if (!selected)
strcpy(fname,"");
else
{
Disconnect(path,p1,f1);
strcat(p1,fname);
strcpy(fname,p1);
}
Gwindow_done(gwnd);
}
Dispose_fdulink(l);
}
}
void Menu(string ss)
{int r;
setfillstyle(1,0);
rectangle(1,getmaxy()-20,getmaxx()-1,getmaxy()-2);
bar(2,getmaxy()-19,getmaxx()-2,getmaxy()-1);
r=getmaxy()/charhigh+1;
int i=2;
Displaytextxy(i,r,ss);
}
void Statusline(string ss)
{ Menu(ss); }
void Get_dos_file(string ss1,string ss)
{ do
{cout<<ss1;
cout<<":"<<endl;
cin>>ss;
}
while(!strcmp(ss,""));
}
boolean Answer_yes(string ss)
{
int x1,x2,y1,l;
unsigned char ss1[70];
unsigned char s[10];
strcpy(ss1,ss);
l=strlen(ss1);
x1=(80-l-2)/2;
x2=80-x1;
y1=6;
do
{strcpy(s,"");
Inputstrinwnd(x1,y1,x2,ss1,s);
}
while(! ( (!strcmpi(s,"y")) || (!strcmpi(s,"n")) ) );
boolean answer_yes=boolean(!strcmpi(s,"y"));
return answer_yes;
}
void Savequestion(string ss1,string ss,boolean& canorno)
{ do
{
Editstrinwnd(20,4,60,ss1,ss);
}
while (!strcmp(ss,""));
canorno=true;
if (Havefile(ss,0) )
{ unsigned char s1[60];
strcpy(s1,"the file ");
strcat(s1,ss);
strcat(s1," exist, Overwrite?[y/n]" );
canorno=Answer_yes(s1 );
}
}
void Loadquestion(string ss1,string ss,boolean& selected)
{ Editstrinwnd(20,4,70,ss1,ss);
unsigned char fname[60]="";
Get_file_from_gwindow(ss, 0,fname,10,10,55,15,selected);//$3f,ss,10,10,55,15,selected);
strcpy(ss,fname);
}
void Get_string(string s0,string ss)
{ Inputstrinwnd(20,6,60,s0,ss) ; }
void Waitkey(string s,int numofline, int contorstop)
{int w,x1;
unsigned char s0[40]="";
if (contorstop==1)
strcpy(s0," 按任一键继续 ");
else
strcpy(s0," 按任一键返回 ");
strcat(s,s0);
w=strlen(s);
x1=(80-w-2)/2;
Dispstrinwnd(x1,numofline,s);
getch();
}
void Wait()
{ unsigned char s[60]="";
Waitkey(s,getmaxy()/charhigh-2,1);
}
void Cond_wait(boolean b,int k)
{ if (b)
Wait();
else
delay(k);
}
void Waitanykey()
{ Wait(); }
void Cond_waitanykey(boolean b ,int k)
{ Cond_wait(b,k);
}
/* boolean check_file()
{FILE * f;
string ss1,ss2,fs;
fs="check.chk";
if (!havefile(fs,hidden) )
then if havefile('a:'+fs,hidden) then fs:='a:'+fs
else if havefile('b:'+fs,hidden) then fs:='b:'+fs
else check_file:=false
else { assign(f,fs); reset(f); readln(f,ss1); readln(f,ss2);
check_file:=(ss1='19941115'+ss2) and (ss2='hudata19941115')
} };
function check_date:boolean;
var y,m,d,day:word;
{ getdate(y,m,d,day);
check_date:=(y<deadyear) or (y=deadyear) and (m<=deadmonth) };
*/
void Into_graph()
{
if(kk==0)
{
int graphdriver = DETECT, graphmode;
initgraph(&graphdriver, &graphmode, "..\\bgi");
/*if (graph_state=0)
then if check_file {and check_date} then
{ graphdriver:=detect;
initgraph(graphdriver,graphmode,'d:\drivers');
errorcode:=graphresult;
settextjustify(centertext,centertext);
setcolor(white); DirectViDeO:=FaLse;
graph_state:=1;setfillstyle(1,0);bar(0,0,getmaxx,getmaxy);
setfillstyle(1,white);
} else { write(#7); error_exit('illegal copy!') }
*/
gmaxx=getmaxx();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -