Skip to content

Commit b2a17d4

Browse files
committed
update(internal/utils): Removing macro for PRINT(F)
1 parent 07037d5 commit b2a17d4

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void PrintToClientOrConsole(CPlayerSlot *slot, std::string category, std::string
7979
PRINTF(category, message, args...);
8080
else
8181
CLIENT_PRINTF(*slot, category, message, args...);
82-
};
82+
}
8383

8484
bool ends_with(std::string value, std::string ending);
8585
bool starts_with(std::string value, std::string starting);

src/utils.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "common.h"
2+
#include "utils.h"
3+
#include <cstdarg>
4+
5+
size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list params)
6+
{
7+
size_t len = vsnprintf(buffer, maxlength, fmt, params);
8+
9+
if (len >= maxlength)
10+
{
11+
len = maxlength - 1;
12+
buffer[len] = '\0';
13+
}
14+
15+
return len;
16+
}
17+
18+
void PLUGIN_PRINT(std::string category, std::string str)
19+
{
20+
g_SMAPI->ConPrint((PREFIX " [" + category + "] " + str).c_str());
21+
}
22+
23+
void PLUGIN_PRINTF(std::string category, std::string str, ...)
24+
{
25+
va_list ap;
26+
char buffer[4096];
27+
28+
va_start(ap, str);
29+
UTIL_FormatArgs(buffer, sizeof(buffer), str.c_str(), ap);
30+
va_end(ap);
31+
32+
g_SMAPI->ConPrint((PREFIX " [" + category + "] " + std::string(buffer)).c_str());
33+
}

src/utils.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111

1212
#define GCC_COMPILER (defined(__GNUC__) && !defined(__clang__))
1313

14-
#define PRINT(CATEGORY, FORMAT_STR) g_SMAPI->ConPrint(std::string(PREFIX).append(" [").append(CATEGORY).append("] ").append(FORMAT_STR).c_str())
15-
#define PRINTF(CATEGORY, FORMAT_STR, ...) g_SMAPI->ConPrintf(std::string(PREFIX).append(" [").append(CATEGORY).append("] ").append(FORMAT_STR).c_str(), __VA_ARGS__)
14+
void PLUGIN_PRINT(std::string category, std::string str);
15+
void PLUGIN_PRINTF(std::string category, std::string str, ...);
16+
17+
#define PRINT PLUGIN_PRINT
18+
#define PRINTF PLUGIN_PRINTF
1619
#define PRINTRET(CATEGORY, FORMAT_STR, RET) \
1720
{ \
1821
PRINT(CATEGORY, FORMAT_STR); \

0 commit comments

Comments
 (0)