]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - win/colours.h
Change debug message in Invitation::Find() to output expiration time as a string...
[user/henk/code/inspircd.git] / win / colours.h
index 8c16a98bf9c5dc7ed5eca81f3714f2ca478dddf1..fef04903669ac580f485bddb6a3b4d3812fef9b7 100644 (file)
@@ -1 +1,116 @@
-/*       +------------------------------------+\r *       | Inspire Internet Relay Chat Daemon |\r *       +------------------------------------+\r *\r *  InspIRCd: (C) 2002-2007 InspIRCd Development Team\r * See: http://www.inspircd.org/wiki/index.php/Credits\r *\r * This program is free but copyrighted software; see\r *            the file COPYING for details.\r *\r * ---------------------------------------------------\r */\r\r#ifndef __COLOURS_H\r#define __COLOURS_H\r\r#define TRED FOREGROUND_RED | FOREGROUND_INTENSITY\r#define TGREEN FOREGROUND_GREEN | FOREGROUND_INTENSITY\r#define TYELLOW FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY\r#define TNORMAL FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE\r#define TWHITE TNORMAL | FOREGROUND_INTENSITY\r#define TBLUE FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY\r\rinline void sc(WORD color) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color); }\r\r/* Handles colors in printf */\rint printf_c(const char * format, ...)\r{\r   // Better hope we're not multithreaded, otherwise we'll have chickens crossing the road other side to get the to :P\r    static char message[500];\r      static char temp[500];\r int color1, color2;\r\r   /* parse arguments */\r  va_list ap;\r    va_start(ap, format);\r  vsnprintf(message, 500, format, ap);\r   va_end(ap);\r\r   /* search for unix-style escape sequences */\r   int t;\r int c = 0;\r     const char * p = message;\r      while (*p != 0)\r        {\r              if (*p == '\033')\r              {\r                      // Escape sequence -> copy into the temp buffer, and parse the color.\r                  p++;\r                   t = 0;\r                 while ((*p) && (*p != 'm'))\r                    {\r                              temp[t++] = *p;\r                                ++p;\r                   }\r\r                     temp[t] = 0;\r                   p++;\r\r                  if (*temp == '[')\r                      {\r                              if (sscanf(temp, "[%u;%u", &color1, &color2) == 2)\r                             {\r                                      switch(color2)\r                                 {\r                                      case 32:                // Green\r                                               SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);              // Yellow\r                                              break;\r\r                                        default:                // Unknown\r                                             // White\r                                               SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);\r                                          break;\r                                 }\r                              }\r                              else\r                           {\r                                      switch (*(temp+1))\r                                     {\r                                              case '0':\r                                                      // Returning to normal colour.\r                                                 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);\r                                                 break;\r\r                                                case '1':\r                                                      // White\r                                                       SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), TWHITE);\r                                                      break;\r\r                                                default:\r                                                       char message[50];\r                                                      sprintf(message, "Unknown color code: %s", temp);\r                                                      MessageBox(0, message, message, MB_OK);\r                                                        break;\r                                 }\r                              }\r                      }\r              }\r\r             putchar(*p);\r           ++c;\r           ++p;\r   }\r\r     return c;\r}\r\r#endif\r\r
\ No newline at end of file
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef COLORS_H
+#define COLORS_H
+
+#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
+
+inline void sc(WORD color) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color); }
+
+/* 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[500];
+       static char temp[500];
+       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;
+}
+
+#endif
+