[Negitoro-svn] [146] コマンド date で時刻を設定する際 , 時分秒の一つ以上に0がある場合に時刻設定ができないバグを修正 .

Zurück zum Archiv-Index

svnno****@sourc***** svnno****@sourc*****
2011年 1月 15日 (土) 02:35:57 JST


Revision: 146
          http://sourceforge.jp/projects/negitoro/svn/view?view=rev&revision=146
Author:   sero_s
Date:     2011-01-15 02:35:57 +0900 (Sat, 15 Jan 2011)

Log Message:
-----------
コマンド date で時刻を設定する際, 時分秒の一つ以上に0がある場合に時刻設定ができないバグを修正. 参照: sero_s によるr141のコードレビュー.

Modified Paths:
--------------
    trunk/kernel/command.c
    trunk/kernel/rtc.c

Modified: trunk/kernel/command.c
===================================================================
--- trunk/kernel/command.c	2010-12-22 15:49:52 UTC (rev 145)
+++ trunk/kernel/command.c	2011-01-14 17:35:57 UTC (rev 146)
@@ -4,6 +4,7 @@
 /// @date ?
 
 #include "bootpack.h"
+unsigned long strtoul(const char *s, const char **endp, int base);	// #include <stdlib.h>
 
 /// @brief bootdƒRƒ}ƒ“ƒh
 /// @brief bootinfo‚Ì“à—e‚ð•\Ž¦‚·‚é
@@ -202,23 +203,28 @@
 		cons_putstr0(cons, " usage: >date (YEAR-MONTH-DAY-HOUR-MINUTE-SECOND)\n");
 	} else {
 		/* rtc‚ɏ‘‚«ž‚Þ */
+		const char *p = cmdline, *q;
+		int i;
 		if (scan_char(cmdline, '-') != 5) {
 			goto ferr;
 		}
-		dat[5] = atoi(strtok(cmdline, "-"));	/* year */
-		dat[4] = atoi(strtok(NULL, "-"));		/* month */
-		dat[3] = atoi(strtok(NULL, "-"));		/* day */
-		dat[2] = atoi(strtok(NULL, "-"));		/* hour */
-		dat[1] = atoi(strtok(NULL, "-"));		/* minute */
-		dat[0] = atoi(strtok(NULL, "-"));		/* second */
+		for (i = 0; i < 6; i++) {
+			dat[6-1-i] = strtoul(p, &q, 10);	// year, month, day, hour, minute, second
+			if (q == p)
+				goto ferr;
+			if (i < 6-1) {
+				if (*q != '-')
+					goto ferr;
+				q++;
+			}
+			p = q;
+		}
+		if (*p != '\0')
+			goto ferr;
 		b = dat[5] / 100;
-		if (dat[5] && dat[4] && dat[3] && dat[2] && dat[1] && dat[0]) {
-			setdates(b, dat[5] - b * 100, dat[4], dat[3], dat[2], dat[1], dat[0]);
-			cons_putstr0(cons, "RTC is written.\n");
-			clo
 ck_refresh();
-		} else {
-			goto ferr;
-		}
+		setdates(b, dat[5] - b * 100, dat[4], dat[3], dat[2], dat[1], dat[0]);
+		cons_putstr0(cons, "RTC is written.\n");
+		clock_refresh();
 	}
 	
 	goto fin;
Modified: trunk/kernel/rtc.c
===================================================================
--- trunk/kernel/rtc.c	2010-12-22 15:49:52 UTC (rev 145)
+++ trunk/kernel/rtc.c	2011-01-14 17:35:57 UTC (rev 146)
@@ -72,7 +72,8 @@
 	}
 }
 
-/// @brief “ú•tƒf[ƒ^‚ð‘‚«ž‚Ý
+/// @brief “ú•tƒf[ƒ^‚ð‘‚«ž‚Ý.
+/// ˆø”‚ªˆê‚‚łà•s³‚Ȃ牽‚à‚µ‚È‚¢.
 /// @param year_high ¼—ïã“ñŒ…
 /// @param year_low ¼—“ñŒ…
 /// @param month ŒŽ
@@ -80,18 +81,27 @@
 /// @param hour Žž
 /// @param minute •ª
 /// @param second •b
+/// @todo ‘‚«ž‚ñ‚¾Œã, ³‚µ‚­‚©‚¯‚½‚©‚Ç‚¤‚©Šm”F‚·‚é.
+/// @todo ”N‚ÆŒŽ‚É‚æ‚Á‚Ä“ú‚͈̔͂ª•Ï‚í‚邱‚Ƃւ̑Ώˆ.
+/// @todo ˆø”‚ª•s³‚ŏ‘‚«ž‚Ü‚È‚©‚Á‚½‚Æ‚«ŒÄ‚яo‚µŒ³‚Ö’Ê’m‚Í•K—v‚©.
+/// @todo ”N‚Ì—LŒø”͈͂Í0‚©‚ç9999‚Ü‚Å‚Å‚æ‚¢‚Ì‚©.
 void setdates(int year_high, int year_low, int month, 
 			int day, int hour, int minute, int second)
 {
+	static const int rtcmin[] = { 0, 0, 0, 1, 1, 0, 0 };
+	const int date[] = { second, minute, hour, day, month, year_low, year_high };
+	int i;
+
+	// ‚Ç‚ê‚©ˆê‚‚łàˆÙí‚Ȃ珑‚«ž‚Ü‚¸‚ɏI—¹.
+	for (i = 0; i < sizeof(date)/sizeof(*date); i++) {
+		if (date[i] < rtcmin[i] || rtcmax[i] < date[i])
+			return;
+	}
+
 	/* •b‚©‚珑‚­ */
-	if (second <= rtcmax[0]) writedata_cmos(rtcadr[0], bcdconv(second));
-	if (minute <= rtcmax[1]) writedata_cmos(rtcadr[1], bcdconv(minute));
-	if (hour <= rtcmax[2]) writedata_cmos(rtcadr[2], bcdconv(hour));
-	if (day <= rtcmax[3]) writedata_cmos(rtcadr[3], bcdconv(day));
-	if (month <= rtcmax[4]) writedata_cmos(rtcadr[4], bcdconv(month));
-	if (year_low <= rtcmax[5]) writedata_cmos(rtcadr[5], bcdconv(year_low));
-	if (year_high <= rtcmax[6]) writedata_cmos(rtcadr[6], bcdconv(year_high));
-	return;
+	for (i = 0; i < sizeof(date)/sizeof(*date); i++) {
+		writedata_cmos(rtcadr[i], bcdconv(date[i]));
+	}
 }
 
 /// @brief BCD‚Ö•ÏŠ·




Negitoro-svn メーリングリストの案内
Zurück zum Archiv-Index