]> Chaos Git - corbenik/ctrulib.git/commitdiff
allow redirecting stderr to 3dmoo
authorDave Murphy <davem@devkitpro.org>
Sat, 13 Dec 2014 14:03:12 +0000 (14:03 +0000)
committerDave Murphy <davem@devkitpro.org>
Sat, 13 Dec 2014 14:03:12 +0000 (14:03 +0000)
libctru/include/3ds/console.h
libctru/source/console.c

index 95b39a14869a15bfe15a2cc171230b9869fcf1e2..48c7224ea0767bdec825e5cd6b5f30a15e5267b8 100644 (file)
@@ -102,6 +102,13 @@ typedef struct PrintConsole
 #define CONSOLE_CONCEAL                (1<<7)\r
 #define CONSOLE_CROSSED_OUT    (1<<8)\r
 \r
+//! Console debug devices supported by libnds.\r
+typedef enum {\r
+       debugDevice_NULL,       //!< swallows prints to stderr\r
+       debugDevice_3DMOO,      //!< Directs stderr debug statements to 3dmoo\r
+       debugDevice_CONSOLE,    //!< Directs stderr debug statements to 3DS console window\r
+} debugDevice;\r
+\r
 /*!    \brief Loads the font into the console\r
        \param console pointer to the console to update, if NULL it will update the current console\r
        \param font the font to load\r
@@ -136,6 +143,12 @@ PrintConsole *consoleSelect(PrintConsole* console);
 */\r
 PrintConsole* consoleInit(gfxScreen_t screen, PrintConsole* console);\r
 \r
+/*!    \brief Initializes debug console output on stderr to the specified device\r
+       \param device The debug device (or devices) to output debug print statements to\r
+*/\r
+void consoleDebugInit(debugDevice device);\r
+\r
+\r
 //! Clears the screan by using iprintf("\x1b[2J");\r
 void consoleClear(void);\r
 \r
index ffd5d4960ed0b088a7b2479dd19ce929b346fc6a..c6469f29e25c9d9d53dbc296ff06cd8d02f80942 100644 (file)
@@ -3,6 +3,7 @@
 #include <sys/iosupport.h>\r
 #include <3ds/gfx.h>\r
 #include <3ds/console.h>\r
+#include <3ds/svc.h>\r
 \r
 #include "default_font_bin.h"\r
 \r
@@ -467,6 +468,25 @@ static const devoptab_t dotab_stdout = {
        NULL\r
 };\r
 \r
+//---------------------------------------------------------------------------------\r
+ssize_t debug_write(struct _reent *r, int fd, const char *ptr, size_t len) {\r
+//---------------------------------------------------------------------------------\r
+       svcOutputDebugString(ptr,len);\r
+       return len;\r
+}\r
+\r
+static const devoptab_t dotab_3dmoo = {\r
+       "3dmoo",\r
+       0,\r
+       NULL,\r
+       NULL,\r
+       debug_write,\r
+       NULL,\r
+       NULL,\r
+       NULL\r
+};\r
+\r
+\r
 static const devoptab_t dotab_null = {\r
        "null",\r
        0,\r
@@ -519,6 +539,30 @@ PrintConsole* consoleInit(gfxScreen_t screen, PrintConsole* console) {
        return currentConsole;\r
 \r
 }\r
+\r
+//---------------------------------------------------------------------------------\r
+void consoleDebugInit(debugDevice device){\r
+//---------------------------------------------------------------------------------\r
+\r
+       int buffertype = _IONBF;\r
+\r
+       switch(device) {\r
+\r
+       case debugDevice_3DMOO:\r
+               devoptab_list[STD_ERR] = &dotab_3dmoo;\r
+               buffertype = _IOLBF;\r
+               break;\r
+       case debugDevice_CONSOLE:\r
+               devoptab_list[STD_ERR] = &dotab_stdout;\r
+               break;\r
+       case debugDevice_NULL:\r
+               devoptab_list[STD_ERR] = &dotab_null;\r
+               break;\r
+       }\r
+       setvbuf(stderr, NULL , buffertype, 0);\r
+\r
+}\r
+\r
 //---------------------------------------------------------------------------------\r
 PrintConsole *consoleSelect(PrintConsole* console){\r
 //---------------------------------------------------------------------------------\r