|
/**************************************************************************************/
/* Function name: int get_today() */
/* Instruction:提取当日节目菜单 */
/* argument: */
/* int n,struct mission * hand */
/* return: */
/* none */
/**************************************************************************************/
int get_today(int n, struct mission * head)
{
struct mission * p = head;
struct mission * to_p[2][n];
long ist_date, ien_date;
int date[3], w, to_n[2] = {0};
int i, j, k;
w = get_date(&date[0], &date[1], &date[2]);
if (head != NULL)
do
{
returnnextday(&date[0], &date[1], &date[2]);
for(i = 0; i < n; i++)
{
for(k = 0; k < 2; k++)
{
if(dcmp(date, p->st_date) != 1 &&
dcmp(date, p->en_date) != -1)
{
for(j = 0; j < 7; j++)
if(p->wdate[j] == 1 && w == j)
{
to_p[k][to_n[k]] = p;
to_n[k]++;
}
}
if ( p->next != NULL)
p = p->next;
}
}
}while(get_time() == 1439);//在每天的23:59:00重新提取;
queue(&to_n, to_p);
play_today(&to_n, to_p);
return 0;
}
/**************************************************************************************/
/* Function name: int queue() */
/* Instruction:将节目菜单排序 */
/* argument: */
/* int a[2],struct mission *b[2][3] */
/* return: */
/* none */
/**************************************************************************************/
int queue(int a[2], struct mission *b[2][3])
{
struct mission *t;
int l, m, k;
for(k = 0; k < 2; k++)//区分今日与明日;
for(m = 0; m < a[k] - 1; m++)//冒泡;
for(l = 0; l < a[k] - m - 1; l++)
{
if(tcmp((b[k][l])->st_time, (b[k][l + 1])->st_time) == -1)
{
t = b[k][l];
b[k][l] = b[k][l + 1];
b[k][l+1] = t;
}
}
//printf("下一预约:%s\n", &b[0][0]->name);
return 0;
}
/**************************************************************************************/
/* Function name: int play_today() */
/* Instruction:慢慢地把预约逐个播放 */
/* argument: */
/* int c[2],struct mission *d[2][3] */
/* return: */
/* none */
/**************************************************************************************/
int play_today(int c[2], struct mission *d[2][3])
{
int i, j, z;
int dst_time[3];
for(i = 0 ; i <= c[0]; i++)
{
dst_time[0] = d[0]->st_time[0] * 60 +
d[0]->st_time[1] ;
dst_time[1] = d[0]->en_time[0] * 60 +
d[0]->en_time[1] ;
z = (dst_time[1] - dst_time[0]) * 60;
if(dst_time[0] - 1 == get_time())
{
countsec(30);
for(j = 3 ; j > 0 ; j--)
{
countsec(10);
printf("%d\n", j);
}
printf("0\n录像中。。。\n");
if(i != c[0] - 1)
printf("下一预约:%s\n", d[0][i + 1]->name);
else
{
if(c[1] == 0)
printf("明天没有预约!!\n");
else
printf("下一预约:%s\n", d[1][0]->name);
}
countsec(z);
printf("录像结束\n等待中。。。\n");
}
if(i != c[0] - 1)
countsec(d[0][i+1]->st_time[0] * 60 +
d[0][i + 1]->st_time[1] -
dst_time[1] );
}
if(d[1]->st_time[0] * 60 + d[1]->st_time[1] == 0 ) // 0时判断;
{
for(j = 0; ; j++)
if(get_time() == 2359)
{
countsec(30);
for(j = 3 ; j >= 0 ; j--)
{
countsec(10);
printf("%d\n", j);
}
printf("录像中。。。\n");
}
}
return 0;
}
/**************************************************************************************/
/* Function name: int countsec() */
/* Instruction:计时 */
/* argument: */
/* int n */
/* return: */
/* none */
/**************************************************************************************/
int countsec(int n)
{
int i;
struct tm *ptr;
time_t st, et;
st = time(NULL);
for(i = 0; ; i++)
{
et = time(NULL);
if(et - st == n)
break;
}
return 0;
}
/**************************************************************************************/
/* Function name: int get_time() */
/* Instruction: 提取系统的时间 */
/* argument: */
/* none */
/* return: */
/* int ti */
/**************************************************************************************/
int get_time(void)
{
struct tm *ptr;
time_t lt;
int i, ti;
char tim[5];
lt = time(NULL);
ptr = localtime(<);
strftime(tim,5,"%H%M",ptr);
for(i = 0,ti = 0; i < 4; i++)
ti = ti * 10 + tim - 48;
ti = (int)(ti / 100) * 60 + ti % 100;
return ti;
} |
|