提交 b0e70cbe 编写于 作者: B bernard.xiong

fix strlcpy usage in rtc_calendar.c

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@504 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 c870bdb6
......@@ -23,15 +23,15 @@ rt_uint32_t year_seprt=0;
rt_uint8_t month_seprt=0;
rt_uint8_t day_seprt=0;
rt_int8_t *month_cn[12] ={ "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月",
"九月", "十月", "十一月", "十二月"
};
rt_int8_t *month_en[12] ={ "January", "February", "March", "April", "May", "June", "July",
"Auguest", "September", "October", "November", "December"
};
static const rt_int8_t *month_cn[12] ={ "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月",
"九月", "十月", "十一月", "十二月"
};
static const rt_int8_t *month_en[12] ={ "January", "February", "March", "April", "May", "June", "July",
"Auguest", "September", "October", "November", "December"
};
rt_int8_t *day_en[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Firday","Saturday"};
rt_int8_t *day_cn[7]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
static const rt_int8_t *day_en[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Firday","Saturday"};
static const rt_int8_t *day_cn[7]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
//=====================================================================
//read from uart
......@@ -56,12 +56,14 @@ rt_int32_t rt_rtc_month_day_num(rt_int32_t month, rt_int32_t leapyn)
rt_int32_t len_month = 0;
if ((month == 4) || (month == 6) || (month == 9) || (month == 11))
len_month = 30;
else if (month == 2) {
else if (month == 2)
{
if (leapyn == 1)
len_month = 29;
else
len_month = 28;
} else
}
else
len_month = 31;
return len_month;
}
......@@ -71,7 +73,8 @@ rt_int32_t rt_rtc_space_days(rt_int32_t month, rt_int32_t year)
rt_int32_t all_days = 0;
rt_int32_t i = 1;
rt_int32_t leap = rt_rtc_isleap(year);
for (i = 1; i <= month; i++) {
for (i = 1; i <= month; i++)
{
all_days = all_days + rt_rtc_month_day_num(i, leap);
}
return all_days;
......@@ -82,7 +85,8 @@ rt_int32_t rt_rtc_weekday_month(rt_int32_t month, rt_int32_t year)
rt_int32_t space = 0, j, all_days = 0;
rt_int32_t leap = rt_rtc_isleap(year);
space = rt_rtc_week_of_newyears_day(year);
for (j = 1; j <= month - 1; j++) {
for (j = 1; j <= month - 1; j++)
{
all_days = all_days + rt_rtc_month_day_num(j, leap);
}
......@@ -95,7 +99,7 @@ void rt_rtc_print_common_fmt(rt_uint8_t month, rt_uint8_t weekday, rt_uint8_t le
rt_int32_t day, j, len_of_month;
rt_kprintf("\n%s %s %d\n",
month_cn[month - 1], month_en[month - 1], year_seprt);
month_cn[month - 1], month_en[month - 1], year_seprt);
rt_kprintf("----------------------------------\n");
rt_kprintf("SUN MON TUE WED THU FRI SAT\n");
rt_kprintf("----------------------------------\n");
......@@ -103,13 +107,15 @@ void rt_rtc_print_common_fmt(rt_uint8_t month, rt_uint8_t weekday, rt_uint8_t le
rt_kprintf(" ");
len_of_month = rt_rtc_month_day_num(month, leapyear);
for (day = 1; day <= len_of_month; day++) {
for (day = 1; day <= len_of_month; day++)
{
if (day > 9)
rt_kprintf("%d ", day);
else
rt_kprintf("%d ", day);
weekday = weekday + 1;
if (weekday == 7) {
if (weekday == 7)
{
weekday = 0;
rt_kprintf("\n");
}
......@@ -129,11 +135,14 @@ void rt_rtc_print_calendar(rt_uint32_t year)
{
rt_uint8_t month;
if (month_seprt == 0) {
for (month = 1; month <= 12; month = month + 1) {
if (month_seprt == 0)
{
for (month = 1; month <= 12; month = month + 1)
{
rt_rtc_print_one_month(month, year);
}
} else
}
else
rt_rtc_print_one_month(month_seprt, year);
}
......@@ -142,7 +151,8 @@ void rt_rtc_year_month_day_seperate(rt_uint32_t year)
{
rt_uint32_t temp;
if (year < 1900 || year > 30000000) {
if (year < 1900 || year > 30000000)
{
rt_kprintf("\nPlease input year and month, if not, system default is loaded!\n");
year = DEFAULT_YEAR;
}
......@@ -151,23 +161,28 @@ void rt_rtc_year_month_day_seperate(rt_uint32_t year)
year_seprt = year;
month_seprt = 0;
day_seprt = 0;
} else if (year / 100 < 300 && year / 100 > 196)
}
else if (year / 100 < 300 && year / 100 > 196)
{
year_seprt = year / 10;
month_seprt = year % 10;
day_seprt = 0;
} else if (year / 100 < 3000 && year / 100 > 1960)
}
else if (year / 100 < 3000 && year / 100 > 1960)
{
year_seprt = year / 100;
month_seprt = year % 100;
if (month_seprt > 12) {
if (month_seprt > 12)
{
temp = month_seprt;
month_seprt = temp / 10;
day_seprt = temp % 10;
} else if (month_seprt < 10)
}
else if (month_seprt < 10)
day_seprt = 0;
} else if (year / 100 < 30000 && year / 100 > 19600)
}
else if (year / 100 < 30000 && year / 100 > 19600)
{
year_seprt = year / 1000;
month_seprt = (year % 1000) / 100;
......@@ -175,27 +190,30 @@ void rt_rtc_year_month_day_seperate(rt_uint32_t year)
{
month_seprt = (year % 100) / 10;
day_seprt = year % 10;
} else
}
else
day_seprt = year % 100;
temp = rt_rtc_month_day_num(month_seprt, rt_rtc_isleap(year_seprt));
if (day_seprt > temp) {
rt_kprintf
("\nError:There are only %d days this month, using default date\n", temp);
if (day_seprt > temp)
{
rt_kprintf("\nError:There are only %d days this month, using default date\n", temp);
day_seprt = DEFAULT_DAY;
}
} else {
}
else
{
year_seprt = year / 10000;
month_seprt = (year % 10000) / 100;
if (month_seprt > 12) {
rt_kprintf
("\nError: There are only 12 months a year, using default date\n");
if (month_seprt > 12)
{
rt_kprintf("\nError: There are only 12 months a year, using default date\n");
month_seprt = DEFAULT_MONTH;
}
day_seprt = year % 100;
temp = rt_rtc_month_day_num(month_seprt, rt_rtc_isleap(year_seprt));
if (day_seprt > temp) {
rt_kprintf
("\nError: There are %d days in this month, using default date\n", temp);
if (day_seprt > temp)
{
rt_kprintf("\nError: There are %d days in this month, using default date\n", temp);
day_seprt = DEFAULT_DAY;
}
}
......@@ -211,22 +229,22 @@ void rt_rtc_weekdate_calculate(void)
}
extern size_t strlcpy(char *dest, const char *src, size_t siz);
rt_uint8_t *list_month[12]={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static const rt_uint8_t *list_month[12]={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
void rt_calendar(void)
{
//static rt_uint8_t receive_char;
static rt_int32_t year;
rt_uint8_t i = 0;
rt_int32_t result, num_month, num_year;
rt_uint8_t date_year[7], date_month[3], *date = __DATE__;
rt_uint8_t date_year[5], date_month[4], *date = __DATE__;
strlcpy((char *)date_month, (const char *)date, 3);
strlcpy((char *)date_month, (const char *)date, 4);
date += 7;
strlcpy((char *)date_year, (const char *)date, 4);
strlcpy((char *)date_year, (const char *)date, 5);
date = RT_NULL;
num_year = atoi(date_year);
do{
do
{
result = strcmp((const char *)date_month, (const char *)list_month[i++]);
if(result !=0)
result = 1;
......@@ -236,22 +254,27 @@ void rt_calendar(void)
i = 0;
result = 1;
year = num_year*100 + num_month;
//year = Uart_GetIntNum_MT();
//rt_kprintf("\nThe date is %d\n", year);
rt_rtc_year_month_day_seperate(year);
//year = Uart_GetIntNum_MT();
//rt_kprintf("\nThe date is %d\n", year);
rt_rtc_year_month_day_seperate(year);
if (day_seprt == 0 && month_seprt == 0) {
//rt_kprintf("\nYear: %d\n", year_seprt);
rt_rtc_print_calendar(year_seprt);
if (day_seprt == 0 && month_seprt == 0)
{
//rt_kprintf("\nYear: %d\n", year_seprt);
rt_rtc_print_calendar(year_seprt);
} else if (day_seprt == 0) {
//rt_kprintf("\n%d/%d\n", year_seprt, month_seprt);
rt_rtc_print_calendar(year_seprt);
}
else if (day_seprt == 0)
{
//rt_kprintf("\n%d/%d\n", year_seprt, month_seprt);
rt_rtc_print_calendar(year_seprt);
} else {
//rt_kprintf("\n%d/%d/%d\n", year_seprt, month_seprt, day_seprt);
rt_rtc_weekdate_calculate();
}
}
else
{
//rt_kprintf("\n%d/%d/%d\n", year_seprt, month_seprt, day_seprt);
rt_rtc_weekdate_calculate();
}
}
#ifdef RT_USING_FINSH
#include <finsh.h>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册