From f60aa68ee934b5e8127582f51f713cc05ef1387a Mon Sep 17 00:00:00 2001 From: peavey Date: Mon, 16 Jul 2007 15:39:31 +0000 Subject: Ok windows.. YOU WIN :< .. but at least I can use MAXBUF now and configure will have to endure the fixed 500 limit :> git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7452 e03df62e-2008-0410-955e-edbf42e46eb7 --- win/configure.cpp | 7 +++- win/inspircd_win32wrapper.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++ win/inspircd_win32wrapper.h | 6 +-- 3 files changed, 97 insertions(+), 5 deletions(-) (limited to 'win') diff --git a/win/configure.cpp b/win/configure.cpp index 4acc18bf0..44666398e 100644 --- a/win/configure.cpp +++ b/win/configure.cpp @@ -13,8 +13,11 @@ #define _CRT_SECURE_NO_DEPRECATE -#include -#include "inspircd_win32wrapper.h" +#include +#include +#include +#include +#include "colours.h" using namespace std; void Run(); diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp index 0af54a39c..b3af867cf 100644 --- a/win/inspircd_win32wrapper.cpp +++ b/win/inspircd_win32wrapper.cpp @@ -197,6 +197,95 @@ const char * dlerror() return errormessage; } +#define TRED FOREGROUND_RED | FOREGROUND_INTENSITY +#define TGREEN FOREGROUND_GREEN | FOREGROUND_INTENSITY +#define TYELLOW FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY +#define TNORMAL FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE +#define TWHITE TNORMAL | FOREGROUND_INTENSITY +#define TBLUE FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY + +/* Handles colors in printf */ +int printf_c(const char * format, ...) +{ + // Better hope we're not multithreaded, otherwise we'll have chickens crossing the road other side to get the to :P + static char message[MAXBUF]; + static char temp[MAXBUF]; + int color1, color2; + + /* parse arguments */ + va_list ap; + va_start(ap, format); + vsnprintf(message, 500, format, ap); + va_end(ap); + + /* search for unix-style escape sequences */ + int t; + int c = 0; + const char * p = message; + while (*p != 0) + { + if (*p == '\033') + { + // Escape sequence -> copy into the temp buffer, and parse the color. + p++; + t = 0; + while ((*p) && (*p != 'm')) + { + temp[t++] = *p; + ++p; + } + + temp[t] = 0; + p++; + + if (*temp == '[') + { + if (sscanf(temp, "[%u;%u", &color1, &color2) == 2) + { + switch(color2) + { + case 32: // Green + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY); // Yellow + break; + + default: // Unknown + // White + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); + break; + } + } + else + { + switch (*(temp+1)) + { + case '0': + // Returning to normal colour. + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); + break; + + case '1': + // White + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), TWHITE); + break; + + default: + char message[50]; + sprintf(message, "Unknown color code: %s", temp); + MessageBox(0, message, message, MB_OK); + break; + } + } + } + } + + putchar(*p); + ++c; + ++p; + } + + return c; +} + int arg_counter = 1; char optarg[514]; int getopt_long_only(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind) diff --git a/win/inspircd_win32wrapper.h b/win/inspircd_win32wrapper.h index 250f41e3f..2daa4ced7 100644 --- a/win/inspircd_win32wrapper.h +++ b/win/inspircd_win32wrapper.h @@ -66,9 +66,6 @@ #include #include -/* printf_c support for printing ansi colors in console */ -#include "colours.h" - /* strcasecmp is not defined on windows by default */ #define strcasecmp _stricmp @@ -103,6 +100,9 @@ CoreExport int inet_aton(const char *, struct in_addr *); /* Unix-style get running user id */ CoreExport int geteuid(); +/* Handles colors in printf */ +CoreExport int printf_c(const char * format, ...); + /* getopt() wrapper */ # define no_argument 0 # define required_argument 1 -- cgit v1.2.3