mirror of https://github.com/mpv-player/mpv
win32: add puts/fputs wrappers
This commit is contained in:
parent
3372e17d51
commit
fc55f355fc
35
osdep/io.c
35
osdep/io.c
|
@ -298,6 +298,31 @@ int mp_fstat(int fd, struct mp_stat *buf)
|
||||||
return hstat(h, buf);
|
return hstat(h, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline HANDLE get_handle(FILE *stream)
|
||||||
|
{
|
||||||
|
HANDLE wstream = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
|
if (stream == stdout || stream == stderr) {
|
||||||
|
wstream = GetStdHandle(stream == stdout ?
|
||||||
|
STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
|
||||||
|
}
|
||||||
|
return wstream;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mp_fputs(const char *str, FILE *stream)
|
||||||
|
{
|
||||||
|
HANDLE wstream = get_handle(stream);
|
||||||
|
if (mp_check_console(wstream))
|
||||||
|
return mp_console_fputs(wstream, bstr0(str));
|
||||||
|
|
||||||
|
return fputs(str, stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mp_puts(const char *str)
|
||||||
|
{
|
||||||
|
return mp_fputs(str, stdout);
|
||||||
|
}
|
||||||
|
|
||||||
#if HAVE_UWP
|
#if HAVE_UWP
|
||||||
static int mp_vfprintf(FILE *stream, const char *format, va_list args)
|
static int mp_vfprintf(FILE *stream, const char *format, va_list args)
|
||||||
{
|
{
|
||||||
|
@ -307,15 +332,9 @@ static int mp_vfprintf(FILE *stream, const char *format, va_list args)
|
||||||
|
|
||||||
static int mp_vfprintf(FILE *stream, const char *format, va_list args)
|
static int mp_vfprintf(FILE *stream, const char *format, va_list args)
|
||||||
{
|
{
|
||||||
HANDLE wstream = INVALID_HANDLE_VALUE;
|
HANDLE wstream = get_handle(stream);
|
||||||
|
|
||||||
if (stream == stdout || stream == stderr) {
|
|
||||||
wstream = GetStdHandle(stream == stdout ?
|
|
||||||
STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mp_check_console(wstream))
|
if (mp_check_console(wstream))
|
||||||
return mp_write_console_ansi(wstream, format, args);
|
return mp_console_vfprintf(wstream, format, args);
|
||||||
|
|
||||||
return vfprintf(stream, format, args);
|
return vfprintf(stream, format, args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,8 @@ char *mp_to_utf8(void *talloc_ctx, const wchar_t *s);
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
int mp_puts(const char *str);
|
||||||
|
int mp_fputs(const char *str, FILE *stream);
|
||||||
int mp_printf(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
|
int mp_printf(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
|
||||||
int mp_fprintf(FILE *stream, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
|
int mp_fprintf(FILE *stream, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
|
||||||
int mp_open(const char *filename, int oflag, ...);
|
int mp_open(const char *filename, int oflag, ...);
|
||||||
|
@ -174,6 +176,8 @@ int mp_glob(const char *restrict pattern, int flags,
|
||||||
int (*errfunc)(const char*, int), mp_glob_t *restrict pglob);
|
int (*errfunc)(const char*, int), mp_glob_t *restrict pglob);
|
||||||
void mp_globfree(mp_glob_t *pglob);
|
void mp_globfree(mp_glob_t *pglob);
|
||||||
|
|
||||||
|
#define puts(...) mp_puts(__VA_ARGS__)
|
||||||
|
#define fputs(...) mp_fputs(__VA_ARGS__)
|
||||||
#define printf(...) mp_printf(__VA_ARGS__)
|
#define printf(...) mp_printf(__VA_ARGS__)
|
||||||
#define fprintf(...) mp_fprintf(__VA_ARGS__)
|
#define fprintf(...) mp_fprintf(__VA_ARGS__)
|
||||||
#define open(...) mp_open(__VA_ARGS__)
|
#define open(...) mp_open(__VA_ARGS__)
|
||||||
|
|
|
@ -27,7 +27,12 @@ void terminal_get_size2(int *rows, int *cols, int *px_width, int *px_height)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int mp_write_console_ansi(void *wstream, const char *format, va_list args)
|
int mp_console_vfprintf(void *wstream, const char *format, va_list args)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mp_console_fputs(void *wstream, bstr str)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,15 +226,36 @@ bool terminal_in_background(void)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mp_write_console_ansi(HANDLE wstream, const char *format, va_list args)
|
int mp_console_vfprintf(HANDLE wstream, const char *format, va_list args)
|
||||||
{
|
{
|
||||||
struct tmp_buffers *buffers = FlsGetValue(tmp_buffers_key);
|
struct tmp_buffers *buffers = FlsGetValue(tmp_buffers_key);
|
||||||
if (!buffers)
|
bool free_buf = false;
|
||||||
|
if (!buffers) {
|
||||||
buffers = talloc_zero(NULL, struct tmp_buffers);
|
buffers = talloc_zero(NULL, struct tmp_buffers);
|
||||||
|
free_buf = !FlsSetValue(tmp_buffers_key, buffers);
|
||||||
|
}
|
||||||
|
|
||||||
buffers->write_console_buf.len = 0;
|
buffers->write_console_buf.len = 0;
|
||||||
bstr_xappend_vasprintf(buffers, &buffers->write_console_buf, format, args);
|
bstr_xappend_vasprintf(buffers, &buffers->write_console_buf, format, args);
|
||||||
int wlen = bstr_to_wchar(buffers, buffers->write_console_buf, &buffers->write_console_wbuf);
|
|
||||||
|
int ret = mp_console_fputs(wstream, buffers->write_console_buf);
|
||||||
|
|
||||||
|
if (free_buf)
|
||||||
|
talloc_free(buffers);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mp_console_fputs(HANDLE wstream, bstr str)
|
||||||
|
{
|
||||||
|
struct tmp_buffers *buffers = FlsGetValue(tmp_buffers_key);
|
||||||
|
bool free_buf = false;
|
||||||
|
if (!buffers) {
|
||||||
|
buffers = talloc_zero(NULL, struct tmp_buffers);
|
||||||
|
free_buf = !FlsSetValue(tmp_buffers_key, buffers);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wlen = bstr_to_wchar(buffers, str, &buffers->write_console_wbuf);
|
||||||
wchar_t *pos = buffers->write_console_wbuf;
|
wchar_t *pos = buffers->write_console_wbuf;
|
||||||
|
|
||||||
while (*pos) {
|
while (*pos) {
|
||||||
|
@ -380,7 +401,7 @@ int mp_write_console_ansi(HANDLE wstream, const char *format, va_list args)
|
||||||
|
|
||||||
int ret = buffers->write_console_buf.len;
|
int ret = buffers->write_console_buf.len;
|
||||||
|
|
||||||
if (!FlsSetValue(tmp_buffers_key, buffers))
|
if (free_buf)
|
||||||
talloc_free(buffers);
|
talloc_free(buffers);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -54,7 +54,8 @@ void terminal_get_size(int *w, int *h);
|
||||||
void terminal_get_size2(int *rows, int *cols, int *px_width, int *px_height);
|
void terminal_get_size2(int *rows, int *cols, int *px_width, int *px_height);
|
||||||
|
|
||||||
// Windows only.
|
// Windows only.
|
||||||
int mp_write_console_ansi(void *wstream, const char *format, va_list args);
|
int mp_console_vfprintf(void *wstream, const char *format, va_list args);
|
||||||
|
int mp_console_fputs(void *wstream, bstr str);
|
||||||
bool mp_check_console(void *handle);
|
bool mp_check_console(void *handle);
|
||||||
|
|
||||||
/* Windows-only function to attach to the parent process's console */
|
/* Windows-only function to attach to the parent process's console */
|
||||||
|
|
|
@ -107,7 +107,8 @@ void mp_msg(struct mp_log *log, int lev, const char *format, ...) {};
|
||||||
int mp_msg_find_level(const char *s) {return 0;};
|
int mp_msg_find_level(const char *s) {return 0;};
|
||||||
int mp_msg_level(struct mp_log *log) {return 0;};
|
int mp_msg_level(struct mp_log *log) {return 0;};
|
||||||
void mp_msg_set_max_level(struct mp_log *log, int lev) {};
|
void mp_msg_set_max_level(struct mp_log *log, int lev) {};
|
||||||
int mp_write_console_ansi(void *wstream, const char *format, va_list args) {return 0;};
|
int mp_console_vfprintf(void *wstream, const char *format, va_list args) {return 0;};
|
||||||
|
int mp_console_fputs(void *wstream, bstr str) {return 0;};
|
||||||
bool mp_check_console(void *handle) { return false; };
|
bool mp_check_console(void *handle) { return false; };
|
||||||
void mp_set_avdict(AVDictionary **dict, char **kv) {};
|
void mp_set_avdict(AVDictionary **dict, char **kv) {};
|
||||||
struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,
|
struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,
|
||||||
|
|
Loading…
Reference in New Issue