util: Convert util/u_printf.cpp to util/u_printf.c
By doing this to remove the need of C++ runtime when not using llvmpipe Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Reviewed-by: Mihai Preda <mhpreda@gmail.com> Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15659>
This commit is contained in:
parent
1dca31cda6
commit
6d263ff5a3
|
@ -63,9 +63,9 @@ namespace {
|
|||
size_t fmt_last_pos = 0;
|
||||
size_t fmt_pos = 0;
|
||||
for (int arg_size : fmt.arg_sizes) {
|
||||
const size_t spec_pos = util_printf_next_spec_pos(format, fmt_pos);
|
||||
const size_t spec_pos = util_printf_next_spec_pos(format.c_str(), fmt_pos);
|
||||
const size_t cur_tok = format.rfind('%', spec_pos);
|
||||
const size_t next_spec = util_printf_next_spec_pos(format, spec_pos);
|
||||
const size_t next_spec = util_printf_next_spec_pos(format.c_str(), spec_pos);
|
||||
const size_t next_tok = next_spec == std::string::npos ? std::string::npos :
|
||||
format.rfind('%', next_spec);
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ files_mesa_util = files(
|
|||
'u_debug_memory.c',
|
||||
'u_cpu_detect.c',
|
||||
'u_cpu_detect.h',
|
||||
'u_printf.cpp',
|
||||
'u_printf.c',
|
||||
'u_printf.h',
|
||||
'vl_vlc.h',
|
||||
'vl_rbsp.h',
|
||||
|
|
|
@ -23,8 +23,10 @@
|
|||
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "macros.h"
|
||||
#include "u_printf.h"
|
||||
#include "util/macros.h"
|
||||
|
||||
/* Some versions of MinGW are missing _vscprintf's declaration, although they
|
||||
* still provide the symbol in the import library. */
|
||||
|
@ -40,37 +42,35 @@ _CRTIMP int _vscprintf(const char *format, va_list argptr);
|
|||
#endif
|
||||
#endif
|
||||
|
||||
size_t util_printf_next_spec_pos(const std::string &s, size_t pos)
|
||||
size_t util_printf_next_spec_pos(const char *str, size_t pos)
|
||||
{
|
||||
size_t next_tok, spec_pos;
|
||||
do {
|
||||
pos = s.find_first_of('%', pos);
|
||||
if (str == NULL)
|
||||
return -1;
|
||||
|
||||
if (pos == std::string::npos)
|
||||
const char *str_found = str + pos;
|
||||
do {
|
||||
str_found = strchr(str_found, '%');
|
||||
if (str_found == NULL)
|
||||
return -1;
|
||||
|
||||
if (s[pos + 1] == '%') {
|
||||
pos += 2;
|
||||
++str_found;
|
||||
if (*str_found == '%') {
|
||||
++str_found;
|
||||
continue;
|
||||
}
|
||||
|
||||
next_tok = s.find_first_of('%', pos + 1);
|
||||
spec_pos = s.find_first_of("cdieEfFgGaAosuxXp", pos + 1);
|
||||
if (spec_pos != std::string::npos)
|
||||
if (spec_pos < next_tok)
|
||||
return spec_pos;
|
||||
|
||||
pos++;
|
||||
char *spec_pos = strpbrk(str_found, "cdieEfFgGaAosuxXp%");
|
||||
if (spec_pos == NULL) {
|
||||
return -1;
|
||||
} else if (*spec_pos == '%') {
|
||||
str_found = spec_pos;
|
||||
} else {
|
||||
return spec_pos - str;
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
|
||||
size_t util_printf_next_spec_pos(const char *str, size_t pos)
|
||||
{
|
||||
return util_printf_next_spec_pos(std::string(str), pos);
|
||||
}
|
||||
|
||||
size_t
|
||||
u_printf_length(const char *fmt, va_list untouched_args)
|
||||
size_t u_printf_length(const char *fmt, va_list untouched_args)
|
||||
{
|
||||
int size;
|
||||
char junk;
|
|
@ -26,12 +26,6 @@
|
|||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <string>
|
||||
|
||||
/* find next valid printf specifier in a C++ std::string */
|
||||
size_t util_printf_next_spec_pos(const std::string &s, size_t pos);
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue