summaryrefslogtreecommitdiffstats
path: root/ui.c
blob: 0d882e79d3000bac37b6351534adcca9f5a189e6 (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
/* See LICENSE file for copyright and license details. */
#include "common.h"


struct warning_class_data warning_classes[] = {
#define X(ENUM, NAME, ACTION) {NAME, ACTION},
	LIST_WARNING_CLASSES(X)
#undef X
	{NULL, 0}
};


static void
vxprintwarningf(enum warning_class class, int severity, const char *fmt, va_list ap)
{
	if (warning_classes[class].action != IGNORE) {
		fprintf(stderr, "[%s] ",
		        warning_classes[class].action == INFORM ? "info" :
		        warning_classes[class].action == WARN_STYLE ? "style" : "warning");
		vfprintf(stderr, fmt, ap);
		fprintf(stderr, " (-w%s)\n", warning_classes[class].name);
		if (warning_classes[class].action != INFORM)
			exit_status = MAX(exit_status, severity);
	}
}


void
xprintwarningf(enum warning_class class, int severity, const char *fmt, ...)
{
	va_list ap;
	va_start(ap, fmt);
	vxprintwarningf(class, severity, fmt, ap);
	va_end(ap);
}


void
printinfof(enum warning_class class, const char *fmt, ...)
{
	va_list ap;
	if (warning_classes[class].action != IGNORE) {
		va_start(ap, fmt);
		fprintf(stderr, "[info] ");
		vfprintf(stderr, fmt, ap);
		fprintf(stderr, "\n");
		va_end(ap);
	}
}


void
printerrorf(const char *fmt, ...)
{
	va_list ap;
	va_start(ap, fmt);
	fprintf(stderr, "%s: [error] ", argv0);
	vfprintf(stderr, fmt, ap);
	fprintf(stderr, "\n");
	va_end(ap);
	exit(EXIT_CRITICAL);
}


void
printtipf(enum warning_class class, const char *fmt, ...)
{
	va_list ap;
	if (warning_classes[class].action != IGNORE) {
		va_start(ap, fmt);
		fprintf(stderr, "[tip] ");
		vfprintf(stderr, fmt, ap);
		fprintf(stderr, "\n");
		va_end(ap);
	}
}