summaryrefslogtreecommitdiff
path: root/src/common/showmsg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/showmsg.c')
-rw-r--r--src/common/showmsg.c125
1 files changed, 96 insertions, 29 deletions
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index b65181f3a..24d51d2dc 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -1,65 +1,68 @@
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
+#include <stdarg.h>
#include "showmsg.h"
char tmp_output[1024] = {"\0"};
-int _ShowMessage(const char *string, enum msg_type flag){ // by MC Cameri
- /*
- _ShowMessage MUST be used instead of printf as of 10/24/2004.
- Return: 0 = Successful, 1 = Failed.
- */
+// by MC Cameri
+int _vShowMessage(enum msg_type flag, const char *string, va_list ap)
+{
+ // _ShowMessage MUST be used instead of printf as of 10/24/2004.
+ // Return: 0 = Successful, 1 = Failed.
// int ret = 0;
char prefix[40];
- char *output;
- if (strlen(string) <= 0) {
- ShowError("Empty string passed to ShowMessage().\n");
+
+ if (!string || strlen(string) <= 0) {
+ printf("Empty string passed to _ShowMessage().\n");
return 1;
}
switch (flag) {
+ case MSG_NONE: // direct printf replacement
+ break;
case MSG_STATUS: //Bright Green (To inform about good things)
- strcpy(prefix,"\033[1;32m[Status]\033[0;0m: ");
+ strcpy(prefix,CL_GREEN"[Status]"CL_RESET":");
break;
-/* //Do we really need this now? [MC Cameri]
case MSG_SQL: //Bright Violet (For dumping out anything related with SQL)
- strcpy(prefix,"\033[1;35m[SQL]\033[0;0m: ");
+ strcpy(prefix,CL_MAGENTA"[SQL]"CL_RESET":");
break;
-*/
- case MSG_INFORMATION: //Bright Blue (Variable information)
- strcpy(prefix,"\033[1;34m[Info]\033[0;0m: ");
+ case MSG_INFORMATION: //Bright White (Variable information)
+ strcpy(prefix,CL_WHITE"[Info]"CL_RESET":");
break;
case MSG_NOTICE: //Bright White (Less than a warning)
- strcpy(prefix,"\033[1;29m[Notice]\033[0;0m: ");
+ strcpy(prefix,CL_WHITE"[Notice]"CL_RESET":");
break;
case MSG_WARNING: //Bright Yellow
- strcpy(prefix,"\033[1;33m[Warning]\033[0;0m: ");
+ strcpy(prefix,CL_YELLOW"[Warning]"CL_RESET":");
+ break;
+ case MSG_DEBUG: //Bright Cyan, important stuff!
+ strcpy(prefix,CL_CYAN"[Debug]"CL_RESET":");
break;
case MSG_ERROR: //Bright Red (Regular errors)
- strcpy(prefix,"\033[1;31m[Error]\033[0;0m: ");
+ strcpy(prefix,CL_RED"[Error]"CL_RESET":");
break;
case MSG_FATALERROR: //Bright Red (Fatal errors, abort(); if possible)
- strcpy(prefix,"\033[1;31m[Fatal Error]\033[0;0m: ");
+ strcpy(prefix,CL_RED"[Fatal Error]"CL_RESET":");
break;
default:
- ShowError("In function _ShowMessage() -> Invalid flag passed.\n");
+ printf("In function _ShowMessage() -> Invalid flag passed.\n");
return 1;
}
- output = (char*)malloc(sizeof(char)*(strlen(prefix)+strlen(string))+1);
- if (output == NULL) {
- return 1;
-// abort(); // Kill server?
+
+ if (!(flag == MSG_DEBUG && !SHOW_DEBUG_MSG)) {
+ if (flag != MSG_NONE)
+ printf ("%s ", prefix);
+ vprintf (string, ap);
+ fflush (stdout);
}
- strcpy(output,prefix);
- strcat(output,string);
- printf(output);
- fflush(stdout);
+
+ va_end(ap);
/*
if ((core_config.debug_output_level > -1) && (flag >= core_config.debug_output_level)) {
FILE *fp;
fp=fopen(OUTPUT_MESSAGES_LOG,"a");
if (fp == NULL) {
- printf("\033[1;31m[Error]\033[0;0m: Could not open \033[1;29m%s\033[0;0m, file not found.\n",OUTPUT_MESSAGES_LOG);
+ printf(CL_RED"[Error]"CL_RESET": Could not open '"CL_WHITE"%s"CL_RESET"', file not found.\n",OUTPUT_MESSAGES_LOG);
fflush(stdout);
return;
}
@@ -71,3 +74,67 @@ int _ShowMessage(const char *string, enum msg_type flag){ // by MC Cameri
*/
return 0;
}
+
+int _ShowMessage(enum msg_type flag, const char *string, ...)
+{
+ va_list ap;
+
+ va_start(ap, string);
+ return _vShowMessage(flag, string, ap);
+}
+
+// direct printf replacement
+int ShowMessage(const char *string, ...) {
+ va_list ap;
+
+ va_start(ap, string);
+ return _vShowMessage(MSG_NONE, string, ap);
+}
+int ShowStatus(const char *string, ...) {
+ va_list ap;
+
+ va_start(ap, string);
+ return _vShowMessage(MSG_STATUS, string, ap);
+}
+int ShowSQL(const char *string, ...) {
+ va_list ap;
+
+ va_start(ap, string);
+ return _vShowMessage(MSG_SQL, string, ap);
+}
+int ShowInfo(const char *string, ...) {
+ va_list ap;
+
+ va_start(ap, string);
+ return _vShowMessage(MSG_INFORMATION, string, ap);
+}
+int ShowNotice(const char *string, ...) {
+ va_list ap;
+
+ va_start(ap, string);
+ return _vShowMessage(MSG_NOTICE, string, ap);
+}
+int ShowWarning(const char *string, ...) {
+ va_list ap;
+
+ va_start(ap, string);
+ return _vShowMessage(MSG_WARNING, string, ap);
+}
+int ShowDebug(const char *string, ...) {
+ va_list ap;
+
+ va_start(ap, string);
+ return _vShowMessage(MSG_DEBUG, string, ap);
+}
+int ShowError(const char *string, ...) {
+ va_list ap;
+
+ va_start(ap, string);
+ return _vShowMessage(MSG_ERROR, string, ap);
+}
+int ShowFatalError(const char *string, ...) {
+ va_list ap;
+
+ va_start(ap, string);
+ return _vShowMessage(MSG_FATALERROR, string, ap);
+}