#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static int pre_step;
void printf_node_escape(void);
void printf_node_start(char *string)
{
fprintf(stderr,string);
pre_step = -1;
}
void printf_node(int step)
{
printf_node_escape();
fprintf(stderr,"%d%c",step,'%');
pre_step = step;
}
#define string_flashing " ###flashing now..."
void printf_node_flashing(void)
{
fprintf(stderr,string_flashing);
}
void printf_node_end(char *string)
{
char *p;
p = (char*)malloc(sizeof(string_flashing));
memset(p,'\b',strlen(string_flashing));
p[strlen(string_flashing)] = 0;
fprintf(stderr,p);
memset(p,' ' ,strlen(string_flashing));
fprintf(stderr,p);
memset(p,'\b',strlen(string_flashing));
p[strlen(string_flashing)] = 0;
fprintf(stderr,p);
free(p);
printf_node_escape();
fprintf(stderr,string);
}
void printf_node_escape(void)
{
if(pre_step >= 100)fprintf(stderr,"\b\b\b\b");
else if(pre_step >= 10)fprintf(stderr,"\b\b\b");
else if(pre_step >= 0)fprintf(stderr,"\b\b");
}
#define manner 3
int main(int argc, char *argv[])
{
int i,j;
//方式1:
#if manner == 1
for(;;)
{
fprintf(stderr,"Downloading ramdisk\r\n");
for(i = 1;i < 101;i++)
{
fprintf(stderr,"%d%c",i,'%');
fprintf(stderr,"\r");
for(j = 0;j < 0xffffff;j++);
}
fprintf(stderr,"\r\n");
}
#endif
printf_node_flashing
//方式2:
#if manner == 2
for(;;)
{
fprintf(stderr,"Downloading ramdisk ...");
for(i = 1;i < 101;i++)
{
if(i > 10)fprintf(stderr,"\b\b\b");
else if(i > 1)fprintf(stderr,"\b\b");
fprintf(stderr,"%d%c",i,'%');
for(j = 0;j < 0x1ffffff;j++);
//sleep(1);
}
fprintf(stderr,"\b\b\b\b");
fprintf(stderr,"Done.\r\n");
}
#endif
//方式3:
#if manner == 3
for(;;)
{
printf_node_start("Downloading ramdisk ...");
for(i = 0;i < 101;i++)
{
printf_node(i);
for(j = 0;j < 0xffffff;j++);
//sleep(1);
}
printf_node_flashing();
sleep(3);
printf_node_end("Done.\r\n");
}
#endif
}
|