int INKEY(int *code)
{
int m;
while(!bioskey(1))/*可加入无按键时代码*/;
*code=bioskey(0);
m=*code*255;
if(!m) m=*code>>8;
*code=*code&255;
return m;
}
int DATE(char *s,char type)
{
char dat[30];
int num;
struct tm *tblock;
time_t t;
t=time(NULL);
tblock=localtime(&t);
strcpy(dt,asctime(tblock));
strcpy(s,"");
switch(type)
{
case 'N':
num=(*tblock).tm_year+1900;
itoa(num,s,10);
break;
case 'Y':
num=(*tblock).tm_mon+1;
itoa(num,s,10);
break;
case 'R':
num=(*tblock).tm_mday;
itoa(num,s,10);
break;
case 'S':
strcpy(dt,asctime(tblock));
MID(s,dt,12,8);
break;
}
}
return num;
}
/* 参数说明 data:需转换的浮点数;s:输出字符串;len:转换后的长度*/
void f_to_s(double data,char *s,int len)
{
int dec,sign,i;
char *s1,s2[100],s3[100];
s1=0;
s2[0]=0;
s3[0]=0;
s1=fcvt(data,len,&dec,&sign);
if (!sign&&data>=1)
{
MID(s2,s1,dec+1,-1);
MID(s3,s1,1,dec);
strcpy(s,"+");
strcat(s,s3);
strcat(s,".");
strcat(s,s2);
}
if (sign&&fabs(data)>=1)
{
MID(s2,s1,dec+1,-1);
strcpy(s,"-");
MID(s3,s1,1,dec);
strcat(s,s3);
strcat(s,".");
strcat(s,s2);
}
if (!sign&&dec==0)
{
strcpy(s,"+0.");
strcat(s,s1);
}
if (sign&&dec==0)
{
strcpy(s,"-0.");
strcat(s,s1);
}
if (!sign&&dec<0)
{
strcpy(s,"+0.");
for(i=1;i<=fabs(dec);i++)
strcat(s,"0");
strcat(s,s1);
}
if (sign&&dec<0)
{
strcpy(s,"-0.");
for(i=1;i<=fabs(dec);i++)
strcat(s,"0");
strcat(s,s1);
}
if (strlen(s)>len) s[len]=0;
}
void CLSXY(int color,int x,int y,int xl,int yl)
{
int x1,y1;
union REGS r;
if(x<1||y<1) return;
y--;
x--;
y1=y+yl-1;
x1=x+xl-1;
if (y1>25||x1>80)
return;
r.h.ah=6; /*子功能号*/
r.h.al=0; /*滚动行数*/
r.h.ch=y;
r.h.cl=x;
r.h.dh=y1;
r.h.dl=x1;
r.h.bh=color*16;
int86(16,&r,&r);
}
/*显示时间*/
void display_time(int color,int back_color,int y,int x)
{
static char oldtime[9]="";
char newtime[9];
if(y<1||x<1) return;
settextstyle(1,0,1);
DATA(newtime,'S');
back_color=7;
if(strcmp(newtime,oldtime))
{
setfillstyle(1,back_color);
setcolor(color);
bar(535,458,635,475);
outtextxy(x,y,newtime);
strcpy(oldtime,newtime);
}
}
/*打印一个矩形*/
void PRINT_KJ(int x,int y,int wide,int high)
{
int i;
for(i=x;i{
gotoxy(i,y);
cprintf(" ");
}
gotoxy(x,y+high);
cprintf(" ");
gotoxy(x+wide,y+high);
cprintf(" ");
gotoxy(x,y);
cprintf(" ");
gotoxy(x+wide,y);
cprintf(" ");
for(i=x+2;i{
gotoxy(i,y+high);
cprintf(" ");
}
for(i=y+1;i{
gotoxy(x,i);
cprintf(" ");
}
for(i=y+1;i{
gotoxy(x+wide,i);
cprintf(" ");
}
}
void CUT_ALL_SPC(char *s)
{
int i,n;
char d[10000];
n=0;
for(i=0;iif(s[i]!=32)
{
d[n]=s[i];
n++;
}
d[n]=0;
strcpy(s,d);
}
/*取子字符串*/
void MID(char *s,char *t,int n,int m)
{
int i,j,p;
if(n<1) n=1;
i=strlen(s);
if(iif(m<0) m=i;
else m=n+m-1;
if(m>i) m=i;
p=m-n+1;
if(p<0) p=0;
for(i=n-1,j=0;it[j]=s[i];
t[p]=0;
}
/*从文件中读取字符*/
int READ_STR(char *s,FILE *fp)
{
int i=0;
if(!fp) return 0;
if(fgets(s,10000,fp)) i=1;
s[strlen(s)-1]=0;
return i;
}
void MOVE_LEFT(char *d,char *s,int n)
{
int i,l;
l=strlen(s);
if(n>l) n=l;
for(i=0;i*d++=*s++;
*d=0;
}
void LEFT(char *d,char *s,int n)
{
int i,l;
i=0;
l=strlen(s);
if(n>l) n=l;
for(i=0;id[i]=s[i];
d[n]=0;
}
/*向文件写数据*/
void WRITE_STR(char *s,FILE *fp)
{
char c=10;
if(!fp) return;
fputs(s,fp);
fputc(c,fp);
}
void RIGHT(char *dest,char *source,int num)
{
int i,j;
if (num<1) num=0;
num=strlen(source)-num;
if (num<0) num=0;
for(i=0,j=num;j<=strlen(source);i++,j++) dest[i]=source[j];
}
/*打开或关闭光标*/
void CURSOR(int on2off)
{
union REGS r;
if (on2off!=OFF) on2off=10;
r.h.ah=1;
r.h.ch=3;
r.h.cl=on2off;
int86(16,&r,&r);
}
void SOUND(int frequency,int time)
{
int i;
i=time*50;
if (i>30000) i=30000;
if (i<50) i=50;
sound(frequency);
MYDELAY(i);
nosound();
}
void MYDELAY(long t)
{
time_t OldTime;
long t0;
t0=t/55;
if (t0<1) t0=1;
OldTime=clock();
while(clock()-OldTime}
/*正点报时*/
void REPORT_CLOCK(void)
{
int i;
for(i=0;i<5;i++);
{
SOUND(500,10);
MYDELAY(1000);
}
SOUND(800,10);
}
/*写整数于文件中*/
void WRITE_INT(int num,FILE *p)
{
char s[20],a=10;
if (!p) return;
itoa(num,s,10);
fputs(s,p);
fputc(a,p);
}
/*从文件中读取整数*/
int READ_INT(int *num,FILE *p)
{
int i;
char s[30]="";
if (!p) return 0;
if (fgets(s,10000,p))
{
i=-1;
s[strlen(s)-1]=0;
*num=atoi(s);
}
else i=0;
return i;
}
/*报警 */
void WARN(void)
{
SOUND(300,1);
SOUND(100,1);
}
/*字符串右靠齐*/
void MOVE_RIGHT(char *s,int wide)
{
int i,l,n;
l=strlen(s);
n=wide-l;
if (n>0)
{
for(i=l;i>-1;i--) s[i+n]=s[i];
for(i=0;i}
}
/*字符串居中*/
void MOVE_MIDDLE(char *s,int wide)
{
int i,l,n;
l=strlen(s);
if (wide>l)
{
wide=wide-1;
n=wide/2;
wide=wide-n;
for(i=l;i>-1;i--) s[i+n]=s[i];
for(i=0;ifor(i=0;is[l+n+i]=0;
}
}
void Delete_SubString(char *source,int start,int num)
{
int i,l;
l=strlen(source);
if (num>l-start+1||num==-1) num=l-start+1;
if (start<1||start>1) return;
for(i=start;isource[i-1]=source[i+num-1];
}
int INSTR(int n,char *source,char *dest)
{
int i,j,k1,k2,p;
int start=0;
if (n==0) n=1;
k1=strlen(source);
k2=strlen(dest);
if (n<0)
{
char s[100];
n=-n;
MID(s,source,n,k2);
if (strcmp(s,dest)) return 0;
return n;
}
if (k1-n+1for(i=n-1;i{
p=0;
for(j=0;jif (source[i+j]!=dest[j]) break;
else p++;
if (p==k2)
{
start=i+1;
break;
}
}
return start;
}
/*产生空格*/
void SPACE(char *s,int n)
{
int i;
if (n<0) n=0;
for(i=0;i*s=0;
}
/*产生字符串*/
void STRING(int n,char *s1,char *s2)
{
int i;
if (n<0) n=0;
s1[0]=0;
for(i=1;i<=n;i++) strcat(s1,s2);
}
/*砍掉字符串左边空格*/
void CUT_LEFT_SPACE(char *s)
{
int i,j,k=0;
i=strlen(s)+1;
for(j=0;jfor(k=0;j}
/*砍掉字符串右边空格*/
void CUT_RIGHT_SPACE(char *s)
{
int i,j;
i=strlen(s)-1;
for(j=i;j>-1;j--) if (s[j]!=' ') break;
s[j+1]=0;
}
void DISPLAY(char *s)
{
union REGS regs;
int color,x,y;
x=wherex();
y=wherey();
color=16*bjys+qjys;
while(*s)
{
if(x>80) break;
regs.h.ah=9;
regs.h.al=*s;
regs.h.bh=0;
regs.h.bl=color;
regs.x.cx=1; /*显示的次数,不改变光标位置*/
int86(16,®s,®s);
x++;
if(x>80)
{
x=1;
y++;
if(y>25) y=25;
}
gotoxy(x,y);
s++;
}
}
void COLOR(int ForeColor,int BackColor)
{
if(ForeColor<0||ForeColor>15) return;
if(BackColor<0||BackColor>15) return;
qjys=ForeColor;
bjys=BackColor;
}
void quit_YesNo(char *s1,char *s2)
{
char buffer[2000],jx;
gettext(30,8,76,16,buffer);
textbackground(3);
CLSXY(8,32,9,30,6);
CLSXY(4,30,8,30,6);
COLOR(15,4);
gotoxy(35,10);
DISPLAY(s1);
gotoxy(35,12);
DISPLAY(s2);
gotoxy(35+strlen(s2)+1,12);
jx=getch();
puttext(30,8,76,16,buffer);
if (jx=='n'||jx=='N') return;
textbackground(0);
textcolor(15);
clrscr();
CURSOR(ON);
exit(0);
}