2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #define TRED FOREGROUND_RED | FOREGROUND_INTENSITY
25 #define TGREEN FOREGROUND_GREEN | FOREGROUND_INTENSITY
26 #define TYELLOW FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY
27 #define TNORMAL FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE
28 #define TWHITE TNORMAL | FOREGROUND_INTENSITY
29 #define TBLUE FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY
31 /* Handles colors in printf */
32 int printf_c(const char * format, ...)
34 // Better hope we're not multithreaded, otherwise we'll have chickens crossing the road other side to get the to :P
35 static char message[500];
36 static char temp[500];
42 vsnprintf(message, 500, format, ap);
45 /* search for unix-style escape sequences */
48 const char * p = message;
53 // Escape sequence -> copy into the temp buffer, and parse the color.
56 while ((*p) && (*p != 'm'))
67 if (sscanf(temp, "[%u;%u", &color1, &color2) == 2)
72 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY); // Yellow
77 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
86 // Returning to normal colour.
87 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
92 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), TWHITE);
97 sprintf(message, "Unknown color code: %s", temp);
98 MessageBoxA(0, message, message, MB_OK);