Author: dgorbachev
Date: Sat Aug 8 21:34:21 2009
New Revision: 42534
URL:
http://svn.reactos.org/svn/reactos?rev=42534&view=rev
Log:
- Do not compare an ULONG variable with -1 in DbgPrint().
- Simplify TuiPrintf().
Modified:
trunk/reactos/boot/freeldr/freeldr/debug.c
trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c
trunk/reactos/boot/freeldr/freeldr/ui/tui.c
Modified: trunk/reactos/boot/freeldr/freeldr/debug.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/debug…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/debug.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/debug.c [iso-8859-1] Sat Aug 8 21:34:21 2009
@@ -102,209 +102,208 @@
ULONG
DbgPrint(const char *Format, ...)
{
+ int i;
+ int Length;
+ va_list ap;
+ CHAR Buffer[512];
+
+ va_start(ap, Format);
+ Length = _vsnprintf(Buffer, sizeof(Buffer), Format, ap);
+ va_end(ap);
+
+ /* Check if we went past the buffer */
+ if (Length == -1)
+ {
+ /* Terminate it if we went over-board */
+ Buffer[sizeof(Buffer) - 1] = '\n';
+
+ /* Put maximum */
+ Length = sizeof(Buffer);
+ }
+
+ for (i = 0; i < Length; i++)
+ {
+ DebugPrintChar(Buffer[i]);
+ }
+
+ return 0;
+}
+
+VOID DebugPrintHeader(ULONG Mask)
+{
+ /* No header */
+ if (Mask == 0)
+ return;
+
+ switch (Mask)
+ {
+ case DPRINT_WARNING:
+ DbgPrint("WARNING: ");
+ break;
+ case DPRINT_MEMORY:
+ DbgPrint("MEMORY: ");
+ break;
+ case DPRINT_FILESYSTEM:
+ DbgPrint("FILESYS: ");
+ break;
+ case DPRINT_INIFILE:
+ DbgPrint("INIFILE: ");
+ break;
+ case DPRINT_UI:
+ DbgPrint("UI: ");
+ break;
+ case DPRINT_DISK:
+ DbgPrint("DISK: ");
+ break;
+ case DPRINT_CACHE:
+ DbgPrint("CACHE: ");
+ break;
+ case DPRINT_REGISTRY:
+ DbgPrint("REGISTER: ");
+ break;
+ case DPRINT_REACTOS:
+ DbgPrint("REACTOS: ");
+ break;
+ case DPRINT_LINUX:
+ DbgPrint("LINUX: ");
+ break;
+ case DPRINT_WINDOWS:
+ DbgPrint("WINLDR: ");
+ break;
+ case DPRINT_HWDETECT:
+ DbgPrint("HWDETECT: ");
+ break;
+ default:
+ DbgPrint("UNKNOWN: ");
+ break;
+ }
+}
+
+char* g_file;
+int g_line;
+
+VOID DbgPrintMask(ULONG Mask, char *format, ...)
+{
+ va_list ap;
+ char Buffer[2096];
+ char *ptr = Buffer;
+
+ // Mask out unwanted debug messages
+ if (!(Mask & DebugPrintMask))
+ {
+ return;
+ }
+
+ // Print the header if we have started a new line
+ if (DebugStartOfLine)
+ {
+ DbgPrint("(%s:%d) ", g_file, g_line);
+ DebugPrintHeader(Mask);
+ DebugStartOfLine = FALSE;
+ }
+
+ va_start(ap, format);
+ vsprintf(Buffer, format, ap);
+ va_end(ap);
+
+ while (*ptr)
+ {
+ DebugPrintChar(*ptr++);
+ }
+}
+
+VOID DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length)
+{
+ PUCHAR BufPtr = (PUCHAR)Buffer;
+ ULONG Idx;
+ ULONG Idx2;
+
+ // Mask out unwanted debug messages
+ if (!(Mask & DebugPrintMask))
+ {
+ return;
+ }
+
+ DebugStartOfLine = FALSE; // We don't want line headers
+ DbgPrintMask(Mask, "Dumping buffer at 0x%x with length of %d bytes:\n",
Buffer, Length);
+
+ for (Idx=0; Idx<Length; )
+ {
+ DebugStartOfLine = FALSE; // We don't want line headers
+
+ if (Idx < 0x0010)
+ {
+ DbgPrintMask(Mask, "000%x:\t", Idx);
+ }
+ else if (Idx < 0x0100)
+ {
+ DbgPrintMask(Mask, "00%x:\t", Idx);
+ }
+ else if (Idx < 0x1000)
+ {
+ DbgPrintMask(Mask, "0%x:\t", Idx);
+ }
+ else
+ {
+ DbgPrintMask(Mask, "%x:\t", Idx);
+ }
+
+ for (Idx2=0; Idx2<16; Idx2++,Idx++)
+ {
+ if (BufPtr[Idx] < 0x10)
+ {
+ DbgPrintMask(Mask, "0");
+ }
+ DbgPrintMask(Mask, "%x", BufPtr[Idx]);
+
+ if (Idx2 == 7)
+ {
+ DbgPrintMask(Mask, "-");
+ }
+ else
+ {
+ DbgPrintMask(Mask, " ");
+ }
+ }
+
+ Idx -= 16;
+ DbgPrintMask(Mask, " ");
+
+ for (Idx2=0; Idx2<16; Idx2++,Idx++)
+ {
+ if ((BufPtr[Idx] > 20) && (BufPtr[Idx] < 0x80))
+ {
+ DbgPrintMask(Mask, "%c", BufPtr[Idx]);
+ }
+ else
+ {
+ DbgPrintMask(Mask, ".");
+ }
+ }
+
+ DbgPrintMask(Mask, "\n");
+ }
+}
+
+#else
+
+VOID DbgPrintMask(ULONG Mask, char *format, ...)
+{
+}
+
+ULONG DbgPrint(PCCH Format, ...)
+{
+ return 0;
+}
+
+#endif // DBG
+
+ULONG
+MsgBoxPrint(const char *Format, ...)
+{
va_list ap;
CHAR Buffer[512];
ULONG Length;
- char *ptr = Buffer;
-
- va_start(ap, Format);
-
- /* Construct a string */
- Length = _vsnprintf(Buffer, 512, Format, ap);
-
- /* Check if we went past the buffer */
- if (Length == -1)
- {
- /* Terminate it if we went over-board */
- Buffer[sizeof(Buffer) - 1] = '\n';
-
- /* Put maximum */
- Length = sizeof(Buffer);
- }
-
- while (*ptr)
- {
- DebugPrintChar(*ptr++);
- }
-
- va_end(ap);
- return 0;
-}
-
-VOID DebugPrintHeader(ULONG Mask)
-{
- /* No header */
- if (Mask == 0)
- return;
-
- switch (Mask)
- {
- case DPRINT_WARNING:
- DbgPrint("WARNING: ");
- break;
- case DPRINT_MEMORY:
- DbgPrint("MEMORY: ");
- break;
- case DPRINT_FILESYSTEM:
- DbgPrint("FILESYS: ");
- break;
- case DPRINT_INIFILE:
- DbgPrint("INIFILE: ");
- break;
- case DPRINT_UI:
- DbgPrint("UI: ");
- break;
- case DPRINT_DISK:
- DbgPrint("DISK: ");
- break;
- case DPRINT_CACHE:
- DbgPrint("CACHE: ");
- break;
- case DPRINT_REGISTRY:
- DbgPrint("REGISTER: ");
- break;
- case DPRINT_REACTOS:
- DbgPrint("REACTOS: ");
- break;
- case DPRINT_LINUX:
- DbgPrint("LINUX: ");
- break;
- case DPRINT_WINDOWS:
- DbgPrint("WINLDR: ");
- break;
- case DPRINT_HWDETECT:
- DbgPrint("HWDETECT: ");
- break;
- default:
- DbgPrint("UNKNOWN: ");
- break;
- }
-}
-
-char* g_file;
-int g_line;
-
-VOID DbgPrintMask(ULONG Mask, char *format, ...)
-{
- va_list ap;
- char Buffer[2096];
- char *ptr = Buffer;
-
- // Mask out unwanted debug messages
- if (!(Mask & DebugPrintMask))
- {
- return;
- }
-
- // Print the header if we have started a new line
- if (DebugStartOfLine)
- {
- DbgPrint("(%s:%d) ", g_file, g_line);
- DebugPrintHeader(Mask);
- DebugStartOfLine = FALSE;
- }
-
- va_start(ap, format);
- vsprintf(Buffer, format, ap);
- va_end(ap);
- while (*ptr)
- {
- DebugPrintChar(*ptr++);
- }
-}
-
-VOID DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length)
-{
- PUCHAR BufPtr = (PUCHAR)Buffer;
- ULONG Idx;
- ULONG Idx2;
-
- // Mask out unwanted debug messages
- if (!(Mask & DebugPrintMask))
- {
- return;
- }
-
- DebugStartOfLine = FALSE; // We don't want line headers
- DbgPrintMask(Mask, "Dumping buffer at 0x%x with length of %d bytes:\n",
Buffer, Length);
-
- for (Idx=0; Idx<Length; )
- {
- DebugStartOfLine = FALSE; // We don't want line headers
-
- if (Idx < 0x0010)
- {
- DbgPrintMask(Mask, "000%x:\t", Idx);
- }
- else if (Idx < 0x0100)
- {
- DbgPrintMask(Mask, "00%x:\t", Idx);
- }
- else if (Idx < 0x1000)
- {
- DbgPrintMask(Mask, "0%x:\t", Idx);
- }
- else
- {
- DbgPrintMask(Mask, "%x:\t", Idx);
- }
-
- for (Idx2=0; Idx2<16; Idx2++,Idx++)
- {
- if (BufPtr[Idx] < 0x10)
- {
- DbgPrintMask(Mask, "0");
- }
- DbgPrintMask(Mask, "%x", BufPtr[Idx]);
-
- if (Idx2 == 7)
- {
- DbgPrintMask(Mask, "-");
- }
- else
- {
- DbgPrintMask(Mask, " ");
- }
- }
-
- Idx -= 16;
- DbgPrintMask(Mask, " ");
-
- for (Idx2=0; Idx2<16; Idx2++,Idx++)
- {
- if ((BufPtr[Idx] > 20) && (BufPtr[Idx] < 0x80))
- {
- DbgPrintMask(Mask, "%c", BufPtr[Idx]);
- }
- else
- {
- DbgPrintMask(Mask, ".");
- }
- }
-
- DbgPrintMask(Mask, "\n");
- }
-}
-
-#else
-
-VOID DbgPrintMask(ULONG Mask, char *format, ...)
-{
-}
-
-ULONG DbgPrint(PCCH Format, ...)
-{
- return 0;
-}
-
-#endif // DBG
-
-ULONG
-MsgBoxPrint(const char *Format, ...)
-{
- va_list ap;
- CHAR Buffer[512];
- ULONG Length;
va_start(ap, Format);
Modified: trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/react…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c [iso-8859-1] Sat Aug 8 21:34:21
2009
@@ -871,7 +871,7 @@
UiMessageBox("Could not load the System hive!\n");
return;
}
- DPRINTM(DPRINT_REACTOS, "SystemHive loaded at 0x%x size %u", (unsigned)Base,
(unsigned)Size);
+ DPRINTM(DPRINT_REACTOS, "SystemHive loaded at 0x%x size %u\n", (unsigned)Base,
(unsigned)Size);
/*
* Import the loaded system hive
Modified: trunk/reactos/boot/freeldr/freeldr/ui/tui.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/ui/tu…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/ui/tui.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/ui/tui.c [iso-8859-1] Sat Aug 8 21:34:21 2009
@@ -22,61 +22,28 @@
PVOID TextVideoBuffer = NULL;
/*
- * printf() - prints formatted text to stdout
- * originally from GRUB
+ * TuiPrintf()
+ * Prints formatted text to the screen
*/
-int TuiPrintf(const char *format, ... )
-{
- char c, *ptr, str[16];
+int TuiPrintf(const char *Format, ...)
+{
+ int i;
+ int Length;
va_list ap;
- va_start(ap,format);
-
- while ((c = *(format++)))
- {
- if (c != '%')
- {
- MachConsPutChar(c);
- }
- else
- {
- switch (c = *(format++))
- {
- case 'c':
- MachConsPutChar((va_arg(ap, int)) & 0xff);
- break;
- case 's':
- ptr = va_arg(ap, char *);
- while ((c = *(ptr++)))
- {
- MachConsPutChar(c);
- }
- break;
- case '%':
- MachConsPutChar(c);
- break;
- case 'l':
- c = *(format++);
- /* Fall through. */
- case 'd': case 'u': case 'x':
- if (c == 'x')
- _itoa(va_arg(ap, unsigned long), str, 16);
- else
- _itoa(va_arg(ap, unsigned long), str, 10);
- ptr = str;
- while (*ptr)
- {
- MachConsPutChar(*(ptr++));
- }
- break;
- default:
- printf("\nprintf() invalid format specifier - %%%c\n", c);
- break;
- }
- }
- }
-
+ CHAR Buffer[512];
+
+ va_start(ap, Format);
+ Length = _vsnprintf(Buffer, sizeof(Buffer), Format, ap);
va_end(ap);
- return 0;
+
+ if (Length == -1) Length = sizeof(Buffer);
+
+ for (i = 0; i < Length; i++)
+ {
+ MachConsPutChar(Buffer[i]);
+ }
+
+ return Length;
}
BOOLEAN TuiInitialize(VOID)
@@ -447,8 +414,8 @@
CHAR TempString[20];
BOOLEAN PMHour = FALSE;
- /* Don't draw the time if this has been disabled */
- if (!UiDrawTime) return;
+ /* Don't draw the time if this has been disabled */
+ if (!UiDrawTime) return;
TimeInfo = ArcGetTime();
if (TimeInfo->Year < 1 || 9999 < TimeInfo->Year ||