#include <stdio.h>
#define PRINT_HELP \
"\n"\
"examples:\n"\
"scrott_timer 1:20:8\n"\
"scrott_timer 2:5\n"\
"scrott_timer 60\n"\
void print_help(void)
{
printf(PRINT_HELP);
}
int main(int argc, char *argv[])
{
int i,j;
int seconds;
if(argc != 2)
{
print_help();
return -1;
}
char *s,*pos;
char buffer[256];
int esc_nums = 0;
s = argv[1];
pos = strchr(s, ':');
//if(pos)
{
seconds = strtol(s, NULL, 0);
if(pos)
{
seconds *= 60*60;
seconds += 60*strtol(pos+1, NULL, 0);
pos = strchr(pos+1, ':');
if(pos)
{
seconds += strtol(pos+1, NULL, 0);
}
}
//printf("seconds = %d\n", seconds);
system("sudo date");
for(i = seconds;i >= 0;i--)
{
for(j = 0;j < esc_nums;j++)
{
fprintf(stderr, "\b");
}
for(j = 0;j < esc_nums;j++)
{
fprintf(stderr, " ");
}
for(j = 0;j < esc_nums;j++)
{
fprintf(stderr, "\b");
}
esc_nums = sprintf(buffer, "%d:%d:%d", i/(60*60), (i/60)%60, i%60);
printf(buffer);
fflush(stdout);
sleep(1);
}
system("sudo halt -p");
}
return 0;
}
|
文件: | scrott_timer.tar.bz2 |
大小: | 2KB |
下载: | 下载 |
|
|