Subversion Repositories Games.Descent

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/*
2
 * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3
 * It is copyright by its individual contributors, as recorded in the
4
 * project's Git history.  See COPYING.txt at the top level for license
5
 * terms and a link to the Git history.
6
 */
7
/* Console */
8
 
9
#pragma once
10
 
11
#include <cstddef>
12
#include <cstring>
13
#include <type_traits>
14
#include "pstypes.h"
15
#include "dxxsconf.h"
16
#include "fmtcheck.h"
17
#include "cli.h"
18
#include "cmd.h"
19
#include "d_srcloc.h"
20
 
21
#ifdef __cplusplus
22
 
23
/* Priority levels */
24
enum con_priority
25
{
26
        CON_CRITICAL = -3,
27
        CON_URGENT,
28
        CON_HUD,
29
        CON_NORMAL,
30
        CON_VERBOSE,
31
        CON_DEBUG
32
};
33
 
34
constexpr std::integral_constant<std::size_t, 2048> CON_LINE_LENGTH{};
35
 
36
struct console_buffer
37
{
38
        char line[CON_LINE_LENGTH];
39
        int priority;
40
};
41
 
42
/* Define to 1 to capture the __FILE__, __LINE__ of callers to
43
 * con_printf, con_puts, and show the captured value in `gamelog.txt`.
44
 */
45
#ifndef DXX_CONSOLE_SHOW_FILE_LINE
46
#define DXX_CONSOLE_SHOW_FILE_LINE      0
47
#endif
48
 
49
using con_priority_wrapper = location_value_wrapper<con_priority, DXX_CONSOLE_SHOW_FILE_LINE>;
50
 
51
#undef DXX_CONSOLE_SHOW_FILE_LINE
52
 
53
void con_init(void);
54
void con_puts(con_priority_wrapper level, char *str, size_t len) __attribute_nonnull();
55
void con_puts(con_priority_wrapper level, const char *str, size_t len) __attribute_nonnull();
56
 
57
template <typename T>
58
static inline void con_puts(const con_priority_wrapper level, T &&str)
59
{
60
        using rr = typename std::remove_reference<T>::type;
61
        constexpr std::size_t len = std::extent<rr>::value;
62
        con_puts(level, str, len && std::is_const<rr>::value ? len - 1 : strlen(str));
63
}
64
 
65
void con_printf(con_priority_wrapper level, const char *fmt, ...) __attribute_format_printf(2, 3);
66
#ifdef DXX_CONSTANT_TRUE
67
#define DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(F)        \
68
        (DXX_CONSTANT_TRUE(sizeof((F)) > 1 && (F)[sizeof((F)) - 2] == '\n') &&  \
69
                (DXX_ALWAYS_ERROR_FUNCTION(dxx_trap_trailing_newline, "trailing literal newline on con_printf"), 0)),
70
#else
71
#define DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(C)
72
#endif
73
#define con_printf(A1,F,...)    \
74
        DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(F)        \
75
        dxx_call_printf_checked(con_printf,con_puts,(A1),(F),##__VA_ARGS__)
76
void con_showup(void);
77
 
78
#endif