2014-06-01 17:55:23 +00:00
|
|
|
/*
|
2018-09-02 00:57:29 +00:00
|
|
|
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
|
2014-06-01 17:55:23 +00:00
|
|
|
* It is copyright by its individual contributors, as recorded in the
|
|
|
|
* project's Git history. See COPYING.txt at the top level for license
|
|
|
|
* terms and a link to the Git history.
|
|
|
|
*/
|
2008-04-06 20:23:28 +00:00
|
|
|
/* Console */
|
|
|
|
|
2015-06-07 16:20:46 +00:00
|
|
|
#pragma once
|
2008-04-06 20:23:28 +00:00
|
|
|
|
2013-12-17 23:30:39 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstring>
|
2017-10-14 17:10:30 +00:00
|
|
|
#include <type_traits>
|
2008-04-06 20:23:28 +00:00
|
|
|
#include "pstypes.h"
|
2013-06-27 02:35:22 +00:00
|
|
|
#include "dxxsconf.h"
|
2013-12-07 01:01:27 +00:00
|
|
|
#include "fmtcheck.h"
|
2015-02-11 07:35:44 +00:00
|
|
|
#include "cli.h"
|
|
|
|
#include "cmd.h"
|
2017-12-06 05:14:32 +00:00
|
|
|
#include "d_srcloc.h"
|
2008-04-06 20:23:28 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2008-04-06 20:23:28 +00:00
|
|
|
/* Priority levels */
|
2017-03-18 18:07:36 +00:00
|
|
|
enum con_priority
|
|
|
|
{
|
|
|
|
CON_CRITICAL = -3,
|
|
|
|
CON_URGENT,
|
|
|
|
CON_HUD,
|
|
|
|
CON_NORMAL,
|
|
|
|
CON_VERBOSE,
|
|
|
|
CON_DEBUG
|
|
|
|
};
|
2008-04-06 20:23:28 +00:00
|
|
|
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<std::size_t, 2048> CON_LINE_LENGTH{};
|
2008-04-06 20:23:28 +00:00
|
|
|
|
2013-12-22 22:03:07 +00:00
|
|
|
struct console_buffer
|
2008-04-06 20:23:28 +00:00
|
|
|
{
|
|
|
|
char line[CON_LINE_LENGTH];
|
|
|
|
int priority;
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2008-04-06 20:23:28 +00:00
|
|
|
|
2017-12-06 05:14:32 +00:00
|
|
|
/* Define to 1 to capture the __FILE__, __LINE__ of callers to
|
|
|
|
* con_printf, con_puts, and show the captured value in `gamelog.txt`.
|
|
|
|
*/
|
|
|
|
#ifndef DXX_CONSOLE_SHOW_FILE_LINE
|
|
|
|
#define DXX_CONSOLE_SHOW_FILE_LINE 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using con_priority_wrapper = location_value_wrapper<con_priority, DXX_CONSOLE_SHOW_FILE_LINE>;
|
|
|
|
|
|
|
|
#undef DXX_CONSOLE_SHOW_FILE_LINE
|
|
|
|
|
2008-04-06 20:23:28 +00:00
|
|
|
void con_init(void);
|
2017-12-06 05:14:32 +00:00
|
|
|
void con_puts(con_priority_wrapper level, char *str, size_t len) __attribute_nonnull();
|
|
|
|
void con_puts(con_priority_wrapper level, const char *str, size_t len) __attribute_nonnull();
|
2017-12-05 05:29:55 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2017-12-06 05:14:32 +00:00
|
|
|
static inline void con_puts(const con_priority_wrapper level, T &&str)
|
2013-12-17 23:30:39 +00:00
|
|
|
{
|
2017-12-05 05:29:55 +00:00
|
|
|
using rr = typename std::remove_reference<T>::type;
|
|
|
|
constexpr std::size_t len = std::extent<rr>::value;
|
|
|
|
con_puts(level, str, len && std::is_const<rr>::value ? len - 1 : strlen(str));
|
2013-12-17 23:30:39 +00:00
|
|
|
}
|
2017-12-05 05:29:55 +00:00
|
|
|
|
2017-12-06 05:14:32 +00:00
|
|
|
void con_printf(con_priority_wrapper level, const char *fmt, ...) __attribute_format_printf(2, 3);
|
2016-11-12 18:10:09 +00:00
|
|
|
#ifdef DXX_CONSTANT_TRUE
|
|
|
|
#define DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(F) \
|
|
|
|
(DXX_CONSTANT_TRUE(sizeof((F)) > 1 && (F)[sizeof((F)) - 2] == '\n') && \
|
2015-02-13 03:27:28 +00:00
|
|
|
(DXX_ALWAYS_ERROR_FUNCTION(dxx_trap_trailing_newline, "trailing literal newline on con_printf"), 0)),
|
|
|
|
#else
|
2016-11-12 18:10:09 +00:00
|
|
|
#define DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(C)
|
2015-02-13 03:27:28 +00:00
|
|
|
#endif
|
|
|
|
#define con_printf(A1,F,...) \
|
2016-11-12 18:10:09 +00:00
|
|
|
DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(F) \
|
2017-12-05 05:29:55 +00:00
|
|
|
dxx_call_printf_checked(con_printf,con_puts,(A1),(F),##__VA_ARGS__)
|
2011-01-14 21:55:55 +00:00
|
|
|
void con_showup(void);
|
2008-04-06 20:23:28 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#endif
|