aboutsummaryrefslogtreecommitdiff
path: root/dlog.h
blob: dfa346d782a2837124dc5538a9d0cfd07dd9ee2f (plain)
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
#ifndef DLOG_H
#define DLOG_H

#define ENABLE_DLOG 1

#if ENABLE_DLOG

#if 1
#include "vbox.h"
#define dlog_putc vbox_log_putc
#endif

static inline void dlog_endline(void)
{
	dlog_putc('\n');
}

static inline void dlog_print(const char *s)
{
	char c;
	while (c = *s++) {
		dlog_putc(c);
	}
}

static inline void dlog_printu(unsigned int num, int base)
{
	char buf[4];
	int i = 0;

	do {
		int digit = num % base;

		if (digit < 10) {
			buf[i] = '0' + digit;
		} else {
			buf[i] = 'a' + (digit - 10);
		}

		i++;
		num /= base;
	} while (num > 0);

	while (i--) {
		dlog_putc(buf[i]);
	}
}

static inline void dlog_printx(unsigned int num)
{
	dlog_printu(num, 16);
}

static inline void dlog_printd(int num, int base)
{
	unsigned int unum;

	// TODO
	if (num < 0) {
		dlog_putc('-');
		unum = -num;
	} else {
		unum = num;
	}

	dlog_printu(unum, base);
}

static inline void dlog_puts(const char *s)
{
	dlog_print(s);
	dlog_endline();
}

#else

#define dlog_putc(c)
#define dlog_endline()
#define dlog_print(s)
#define dlog_printu(n)
#define dlog_printx(n)
#define dlog_printd(n,b)
#define dlog_puts(s)

#endif

#endif