https://git.reactos.org/?p=reactos.git;a=commitdiff;h=44ed4fb001f091f75be16…
commit 44ed4fb001f091f75be168f40c9096f38b15d647
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Feb 20 04:09:47 2022 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Mon Feb 21 02:54:02 2022 +0100
[FREELDR:UI] TuiUpdateDateTime(): Simplify building the date/time strings.
---
boot/freeldr/freeldr/include/ui.h | 2 +-
boot/freeldr/freeldr/ui/tui.c | 93 ++++++++++++++-------------------------
boot/freeldr/freeldr/ui/ui.c | 2 +-
3 files changed, 35 insertions(+), 62 deletions(-)
diff --git a/boot/freeldr/freeldr/include/ui.h b/boot/freeldr/freeldr/include/ui.h
index 938192e19b8..d27815599fd 100644
--- a/boot/freeldr/freeldr/include/ui.h
+++ b/boot/freeldr/freeldr/include/ui.h
@@ -47,7 +47,7 @@ extern BOOLEAN UiMenuBox;
extern CHAR UiTimeText[];
extern BOOLEAN UiDrawTime;
-extern const CHAR UiMonthNames[12][15];
+extern const PCSTR UiMonthNames[12];
///////////////////////////////////////////////////////////////////////////////////////
//
diff --git a/boot/freeldr/freeldr/ui/tui.c b/boot/freeldr/freeldr/ui/tui.c
index c75afedc236..4c3a1eeb058 100644
--- a/boot/freeldr/freeldr/ui/tui.c
+++ b/boot/freeldr/freeldr/ui/tui.c
@@ -533,11 +533,10 @@ VOID TuiDrawStatusText(PCSTR StatusText)
VOID TuiUpdateDateTime(VOID)
{
- TIMEINFO* TimeInfo;
- char DateString[40];
- CHAR TimeString[40];
- CHAR TempString[20];
- BOOLEAN PMHour = FALSE;
+ TIMEINFO* TimeInfo;
+ PCSTR DayPostfix;
+ BOOLEAN PMHour = FALSE;
+ CHAR Buffer[40];
/* Don't draw the time if this has been disabled */
if (!UiDrawTime) return;
@@ -550,43 +549,33 @@ VOID TuiUpdateDateTime(VOID)
59 < TimeInfo->Minute ||
59 < TimeInfo->Second)
{
- /* This happens on QEmu sometimes. We just skip updating */
+ /* This happens on QEmu sometimes. We just skip updating. */
return;
}
- // Get the month name
- strcpy(DateString, UiMonthNames[TimeInfo->Month - 1]);
- // Get the day
- _itoa(TimeInfo->Day, TempString, 10);
- // Get the day postfix
+
+ /* Get the day postfix */
if (1 == TimeInfo->Day || 21 == TimeInfo->Day || 31 == TimeInfo->Day)
- {
- strcat(TempString, "st");
- }
+ DayPostfix = "st";
else if (2 == TimeInfo->Day || 22 == TimeInfo->Day)
- {
- strcat(TempString, "nd");
- }
+ DayPostfix = "nd";
else if (3 == TimeInfo->Day || 23 == TimeInfo->Day)
- {
- strcat(TempString, "rd");
- }
+ DayPostfix = "rd";
else
- {
- strcat(TempString, "th");
- }
-
- // Add the day to the date
- strcat(DateString, TempString);
- strcat(DateString, " ");
+ DayPostfix = "th";
- // Get the year and add it to the date
- _itoa(TimeInfo->Year, TempString, 10);
- strcat(DateString, TempString);
+ /* Build the date string in format: "MMMM dx yyyy" */
+ RtlStringCbPrintfA(Buffer, sizeof(Buffer),
+ "%s %d%s %d",
+ UiMonthNames[TimeInfo->Month - 1],
+ TimeInfo->Day,
+ DayPostfix,
+ TimeInfo->Year);
- // Draw the date
- TuiDrawText(UiScreenWidth-(ULONG)strlen(DateString)-2, 1, DateString,
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
+ /* Draw the date */
+ TuiDrawText(UiScreenWidth - (ULONG)strlen(Buffer) - 2, 1,
+ Buffer, ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
- // Get the hour and change from 24-hour mode to 12-hour
+ /* Get the hour and change from 24-hour mode to 12-hour */
if (TimeInfo->Hour > 12)
{
TimeInfo->Hour -= 12;
@@ -596,34 +585,18 @@ VOID TuiUpdateDateTime(VOID)
{
TimeInfo->Hour = 12;
}
- _itoa(TimeInfo->Hour, TempString, 10);
- strcpy(TimeString, " ");
- strcat(TimeString, TempString);
- strcat(TimeString, ":");
- _itoa(TimeInfo->Minute, TempString, 10);
- if (TimeInfo->Minute < 10)
- {
- strcat(TimeString, "0");
- }
- strcat(TimeString, TempString);
- strcat(TimeString, ":");
- _itoa(TimeInfo->Second, TempString, 10);
- if (TimeInfo->Second < 10)
- {
- strcat(TimeString, "0");
- }
- strcat(TimeString, TempString);
- if (PMHour)
- {
- strcat(TimeString, " PM");
- }
- else
- {
- strcat(TimeString, " AM");
- }
- // Draw the time
- TuiDrawText(UiScreenWidth-(ULONG)strlen(TimeString)-2, 2, TimeString,
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
+ /* Build the time string in format: "h:mm:ss tt" */
+ RtlStringCbPrintfA(Buffer, sizeof(Buffer),
+ " %d:%02d:%02d %s",
+ TimeInfo->Hour,
+ TimeInfo->Minute,
+ TimeInfo->Second,
+ PMHour ? "PM" : "AM");
+
+ /* Draw the time */
+ TuiDrawText(UiScreenWidth - (ULONG)strlen(Buffer) - 2, 2,
+ Buffer, ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
}
VOID TuiSaveScreen(PUCHAR Buffer)
diff --git a/boot/freeldr/freeldr/ui/ui.c b/boot/freeldr/freeldr/ui/ui.c
index 513cabfc195..49636eab5e5 100644
--- a/boot/freeldr/freeldr/ui/ui.c
+++ b/boot/freeldr/freeldr/ui/ui.c
@@ -54,7 +54,7 @@ BOOLEAN UiCenterMenu = TRUE; // Tells us if we should use a
centered
BOOLEAN UiMenuBox = TRUE; // Tells us if we should draw a box around the
menu
CHAR UiTimeText[260] = "[Time Remaining: %d]";
-const CHAR UiMonthNames[12][15] = { "January ", "February ",
"March ", "April ", "May ", "June ", "July
", "August ", "September ", "October ", "November
", "December " };
+const PCSTR UiMonthNames[12] = { "January", "February",
"March", "April", "May", "June", "July",
"August", "September", "October", "November",
"December" };
#endif // _M_ARM