-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.h
80 lines (72 loc) · 1.99 KB
/
print.h
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
/** @file print.h
* @brief Console printing related macros
* @author ByteBard
* @copyright MIT
*
* The macro definition seen in this document represent the platform data of Unix.
*/
#ifndef CLIBS_PRINT_H
#define CLIBS_PRINT_H
#ifdef __cplusplus
#include <cstdio>
#else
#include <stdio.h>
#endif
#ifndef END_OF_LINE
#define END_OF_LINE "\n"
#endif
/** @def PRINT(format, ...)
* @brief Print formated string to \b stdout without trailing EOL.
*
* Basically, \b PRINT is just a repackaged \a printf function seen
* \b stdio.h.
*/
#ifndef PRINT
#define PRINT(format, ...) { \
fprintf(stdout, format, ##__VA_ARGS__); \
}
#endif
/** @def PERROR(format, ...)
* @brief Print formated string to \b stderr without trailing EOL.
*
* \b PERROR works as \b PRINT, but to \b stderr.
*/
#ifndef PERROR
#define PERROR(format, ...) { \
fprintf(stderr, format, ##__VA_ARGS__); \
}
#endif
/** @def PUTS(format, ...)
* @brief Print formated string to \b stdout with trailing EOL.
*
* The EOL will change according to the host environment.
*/
#ifndef PUTS
#define PUTS(format, ...) { \
fprintf(stdout, format "%s", ##__VA_ARGS__, END_OF_LINE); \
}
#endif
/** @def PUTERR(format, ...)
* @brief Print formated string to \b stderr with trailing EOL.
*
* The EOL will change according to the host environment.
*/
#ifndef PUTERR
#define PUTERR(format, ...) { \
fprintf(stderr, format "%s", ##__VA_ARGS__, END_OF_LINE); \
}
#endif
/** @def DEBUG_INFO(format, ...)
* @brief Print formated debug message to \b stderr with trailing EOL.
*
* \b DEBUG_INFO works similarly to \b PUTERR but adds source file
* and line number. Hence, developers can track the location of the
* message more easily.
*/
#ifndef DEBUG_INFO
#define DEBUG_INFO(format, ...) { \
fprintf(stderr, "(%s:%d) " format "%s", \
__FILE__, __LINE__, ##__VA_ARGS__, END_OF_LINE); \
}
#endif
#endif /* CLIBS_PRINT_H */