summaryrefslogtreecommitdiff
path: root/src/common/showmsg.c
blob: 24d51d2dc501480d84de0bb6304ae4c945b37c34 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "showmsg.h"

char tmp_output[1024] = {"\0"};

// 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];
	
	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,CL_GREEN"[Status]"CL_RESET":");
			break;
		case MSG_SQL: //Bright Violet (For dumping out anything related with SQL)
			strcpy(prefix,CL_MAGENTA"[SQL]"CL_RESET":");
			break;
		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,CL_WHITE"[Notice]"CL_RESET":");
			break;
		case MSG_WARNING: //Bright Yellow
			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,CL_RED"[Error]"CL_RESET":");
			break;
		case MSG_FATALERROR: //Bright Red (Fatal errors, abort(); if possible)
			strcpy(prefix,CL_RED"[Fatal Error]"CL_RESET":");
			break;
		default:
			printf("In function _ShowMessage() -> Invalid flag passed.\n");
			return 1;
	}

	if (!(flag == MSG_DEBUG && !SHOW_DEBUG_MSG)) {
		if (flag != MSG_NONE)
			printf ("%s ", prefix);
		vprintf (string, ap);
		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(CL_RED"[Error]"CL_RESET": Could not open '"CL_WHITE"%s"CL_RESET"', file not found.\n",OUTPUT_MESSAGES_LOG);
			fflush(stdout);
			return;
		}
		StripColor(output);
		strcpy(output,"\r");
		fwrite(output,strlen(output),1,fp);
		fclose(fp);
	}
*/
	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);
}