changed qse_tio_t to accept buffer specified externally.

removed the internal buffer from qse_tio_t.
added the WriteFile/WriteConsoleW hack into qse_sio_putwcs()/qse_sio_wcsn() as a partial solution to the WriteFile issue with UTF8 strings on the UTF8 console on win32
This commit is contained in:
2011-12-25 15:25:28 +00:00
parent 5b436e2304
commit 29107a71be
13 changed files with 557 additions and 300 deletions

View File

@ -32,9 +32,10 @@
enum qse_fio_open_flag_t
{
/** request qse_char_io based IO */
/** request text-based based IO */
QSE_FIO_TEXT = (1 << 0),
QSE_FIO_IGNOREMBWCERR = (1 << 1),
QSE_FIO_IGNOREMBWCERR = (1 << 1), /* useful if QSE_FIO_TEXT is set */
QSE_FIO_NOAUTOFLUSH = (1 << 2), /* useful if QSE_FIO_TEXT is set */
/** treat the file name pointer as a handle pointer */
QSE_FIO_HANDLE = (1 << 3),
@ -60,18 +61,14 @@ enum qse_fio_open_flag_t
QSE_FIO_NOFOLLOW = (1 << 15),
/* for WIN32 only. harmless(no effect) when used on other platforms */
QSE_FIO_NOSHRD = (1 << 20),
QSE_FIO_NOSHWR = (1 << 21),
QSE_FIO_NOSHDL = (1 << 22),
QSE_FIO_NOSHREAD = (1 << 20),
QSE_FIO_NOSHWRITE = (1 << 21),
QSE_FIO_NOSHDELETE = (1 << 22),
/* hints to OS. harmless(no effect) when used on unsupported platforms */
QSE_FIO_RANDOM = (1 << 23), /* hint that access be random */
QSE_FIO_SEQUENTIAL = (1 << 24) /* hint that access is sequential */
/* NOTE:
* NEVER (1 << 31) since QSE_SIO_NOAUTOFLUSH is defined to
* that value in sio.h FIO doesn't have any bufferring.
*/
};
enum qse_fio_std_t

View File

@ -119,7 +119,7 @@ enum qse_pio_errnum_t
{
QSE_PIO_ENOERR = 0, /**< no error */
QSE_PIO_ENOMEM, /**< out of memory */
QSE_PIO_EINVAL, /**< out of memory */
QSE_PIO_EINVAL, /**< invalid parameter */
QSE_PIO_ENOHND, /**< no handle available */
QSE_PIO_ECHILD, /**< the child is not valid */
QSE_PIO_EINTR, /**< interrupted */

View File

@ -30,12 +30,13 @@
#include <qse/cmn/fio.h>
#include <qse/cmn/tio.h>
enum qse_sio_oflag_t
enum qse_sio_flag_t
{
QSE_SIO_IGNOREMBWCERR = QSE_FIO_IGNOREMBWCERR,
QSE_SIO_NOAUTOFLUSH = QSE_FIO_NOAUTOFLUSH,
QSE_SIO_HANDLE = QSE_FIO_HANDLE,
QSE_SIO_TEMPORARY = QSE_FIO_TEMPORARY,
QSE_SIO_IGNOREMBWCERR = QSE_FIO_IGNOREMBWCERR,
QSE_SIO_NOCLOSE = QSE_FIO_NOCLOSE,
QSE_SIO_READ = QSE_FIO_READ,
@ -48,16 +49,12 @@ enum qse_sio_oflag_t
QSE_SIO_SYNC = QSE_FIO_SYNC,
QSE_SIO_NOFOLLOW = QSE_FIO_NOFOLLOW,
QSE_SIO_NOSHRD = QSE_FIO_NOSHRD,
QSE_SIO_NOSHWR = QSE_FIO_NOSHWR,
QSE_SIO_NOSHDL = QSE_FIO_NOSHDL,
QSE_SIO_NOSHREAD = QSE_FIO_NOSHREAD,
QSE_SIO_NOSHWRITE = QSE_FIO_NOSHWRITE,
QSE_SIO_NOSHDELETE = QSE_FIO_NOSHDELETE,
QSE_SIO_RANDOM = QSE_FIO_RANDOM,
QSE_SIO_SEQUENTIAL = QSE_FIO_SEQUENTIAL,
/* Beware that this should not overlap with any QSE_FIO_XXXX.
* See NOTE in fio.h */
QSE_SIO_NOAUTOFLUSH = (1 << 31)
QSE_SIO_SEQUENTIAL = QSE_FIO_SEQUENTIAL
};
typedef qse_tio_errnum_t qse_sio_errnum_t;
@ -88,6 +85,13 @@ struct qse_sio_t
QSE_DEFINE_COMMON_FIELDS (tio)
qse_fio_t fio;
qse_tio_t tio;
qse_mchar_t inbuf[2048];
qse_mchar_t outbuf[2048];
#if defined(_WIN32)
int status;
#endif
};
#ifdef __cplusplus
@ -101,14 +105,14 @@ qse_sio_t* qse_sio_open (
qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t xtnsize, /**< extension size in bytes */
const qse_char_t* file, /**< file name */
int oflags /**< number OR'ed of #qse_sio_oflag_t */
int flags /**< number OR'ed of #qse_sio_flag_t */
);
qse_sio_t* qse_sio_openstd (
qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t xtnsize, /**< extension size in bytes */
qse_sio_std_t std, /**< standard I/O identifier */
int oflags /**< number OR'ed of #qse_sio_oflag_t */
int flags /**< number OR'ed of #qse_sio_flag_t */
);
/**

View File

@ -34,44 +34,44 @@ enum qse_tio_errnum_t
{
QSE_TIO_ENOERR = 0,
QSE_TIO_ENOMEM, /* out of memory */
QSE_TIO_EINVAL, /* invalid parameter */
QSE_TIO_ENOSPC, /* no more space */
QSE_TIO_EILSEQ, /* illegal sequence */
QSE_TIO_EICSEQ, /* incomplete sequence */
QSE_TIO_EILCHR, /* illegal character */
QSE_TIO_ENOINF, /* no input function attached */
QSE_TIO_EINPUT, /* input function returned an error */
QSE_TIO_EINPOP, /* input function failed to open */
QSE_TIO_EINPCL, /* input function failed to close */
QSE_TIO_ENINPF, /* no input function attached */
QSE_TIO_ENOUTF, /* no output function attached */
QSE_TIO_EOUTPT, /* output function returned an error */
QSE_TIO_EOUTOP, /* output function failed to open */
QSE_TIO_EOUTCL /* output function failed to close */
QSE_TIO_EIOERR /* I/O error */
};
typedef enum qse_tio_errnum_t qse_tio_errnum_t;
enum
{
/* the size of input buffer should be at least equal to or greater
* than the maximum sequence length of the qse_mchar_t string.
* (i.e. 6 for utf8)
*/
QSE_TIO_MAX_INBUF_LEN = 4096,
QSE_TIO_MAX_OUTBUF_LEN = 4096
};
enum qse_tio_cmd_t
{
QSE_TIO_IO_OPEN,
QSE_TIO_IO_CLOSE,
QSE_TIO_IO_DATA
QSE_TIO_OPEN,
QSE_TIO_CLOSE,
QSE_TIO_DATA
};
typedef enum qse_tio_cmd_t qse_tio_cmd_t;
enum qse_tio_flag_t
{
/**< ignore multibyte/wide-character conversion error by
* inserting a question mark for each error occurrence */
QSE_TIO_IGNOREMBWCERR = (1 << 0),
QSE_TIO_NOAUTOFLUSH = (1 << 1)
/**< do not flush data in the buffer until the buffer gets full. */
QSE_TIO_NOAUTOFLUSH = (1 << 1),
/* for internal use only. */
QSE_TIO_DYNINBUF = (1 << 30),
QSE_TIO_DYNOUTBUF = (1 << 31)
};
enum qse_tio_misc_t
{
QSE_TIO_MININBUFCAPA = 32,
QSE_TIO_MINOUTBUFCAPA = 32
};
#define QSE_TIO_ERRNUM(tio) ((const qse_tio_errnum_t)(tio)->errnum)
@ -79,15 +79,28 @@ enum qse_tio_flag_t
typedef struct qse_tio_t qse_tio_t;
/**
* The qse_tio_io_t types define a text I/O handler.
* The qse_tio_io_fun_t types define a text I/O handler.
*/
typedef qse_ssize_t (*qse_tio_io_t) (
typedef qse_ssize_t (*qse_tio_io_fun_t) (
qse_tio_cmd_t cmd,
void* arg,
void* data,
qse_size_t size
);
struct qse_tio_io_t
{
qse_tio_io_fun_t fun;
void* arg;
struct
{
qse_size_t capa;
qse_mchar_t* ptr;
} buf;
};
typedef struct qse_tio_io_t qse_tio_io_t;
/**
* The qse_tio_t type defines a generic type for text IO. If #qse_char_t is
* #qse_mchar_t, it handles any byte streams. If qse_char_t is #qse_wchar_t,
@ -99,20 +112,14 @@ struct qse_tio_t
qse_tio_errnum_t errnum;
int flags;
/* io functions */
qse_tio_io_t input_func;
qse_tio_io_t output_func;
void* input_arg;
void* output_arg;
qse_tio_io_t in;
qse_tio_io_t out;
/* for housekeeping */
/* for house keeping from here */
int input_status;
qse_size_t inbuf_cur;
qse_size_t inbuf_len;
qse_size_t outbuf_len;
qse_mchar_t inbuf[QSE_TIO_MAX_INBUF_LEN];
qse_mchar_t outbuf[QSE_TIO_MAX_OUTBUF_LEN];
};
#ifdef __cplusplus
@ -174,9 +181,11 @@ const qse_char_t* qse_tio_geterrmsg (
* @return 0 on success, -1 on failure
*/
int qse_tio_attachin (
qse_tio_t* tio,
qse_tio_io_t input,
void* arg
qse_tio_t* tio,
qse_tio_io_fun_t input,
void* arg,
qse_mchar_t* bufptr,
qse_size_t bufcapa
);
/**
@ -192,9 +201,11 @@ int qse_tio_detachin (
* @return 0 on success, -1 on failure
*/
int qse_tio_attachout (
qse_tio_t* tio,
qse_tio_io_t output,
void* arg
qse_tio_t* tio,
qse_tio_io_fun_t output,
void* arg,
qse_mchar_t* bufptr,
qse_size_t bufcapa
);
/**