added QSE_TIO_IGNOREMBWCERR
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: fio.c 556 2011-08-31 15:43:46Z hyunghwan.chung $
|
||||
* $Id: fio.c 565 2011-09-11 02:48:21Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -45,8 +45,8 @@
|
||||
|
||||
QSE_IMPLEMENT_COMMON_FUNCTIONS (fio)
|
||||
|
||||
static qse_ssize_t fio_input (int cmd, void* arg, void* buf, qse_size_t size);
|
||||
static qse_ssize_t fio_output (int cmd, void* arg, void* buf, qse_size_t size);
|
||||
static qse_ssize_t fio_input (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size);
|
||||
static qse_ssize_t fio_output (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size);
|
||||
|
||||
qse_fio_t* qse_fio_open (
|
||||
qse_mmgr_t* mmgr, qse_size_t ext,
|
||||
@ -365,8 +365,11 @@ int qse_fio_init (
|
||||
if (flags & QSE_FIO_TEXT)
|
||||
{
|
||||
qse_tio_t* tio;
|
||||
int opt = 0;
|
||||
|
||||
tio = qse_tio_open (fio->mmgr, 0);
|
||||
if (fio->flags & QSE_FIO_IGNOREMBWCERR) opt |= QSE_TIO_IGNOREMBWCERR;
|
||||
|
||||
tio = qse_tio_open (fio->mmgr, 0, opt);
|
||||
if (tio == QSE_NULL) QSE_THROW_ERR (tio);
|
||||
|
||||
if (qse_tio_attachin (tio, fio_input, fio) <= -1 ||
|
||||
@ -826,7 +829,7 @@ int qse_fio_unlock (qse_fio_t* fio, qse_fio_lck_t* lck, int flags)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static qse_ssize_t fio_input (int cmd, void* arg, void* buf, qse_size_t size)
|
||||
static qse_ssize_t fio_input (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size)
|
||||
{
|
||||
qse_fio_t* fio = (qse_fio_t*)arg;
|
||||
QSE_ASSERT (fio != QSE_NULL);
|
||||
@ -838,7 +841,7 @@ static qse_ssize_t fio_input (int cmd, void* arg, void* buf, qse_size_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static qse_ssize_t fio_output (int cmd, void* arg, void* buf, qse_size_t size)
|
||||
static qse_ssize_t fio_output (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size)
|
||||
{
|
||||
qse_fio_t* fio = (qse_fio_t*)arg;
|
||||
QSE_ASSERT (fio != QSE_NULL);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: pio.c 556 2011-08-31 15:43:46Z hyunghwan.chung $
|
||||
* $Id: pio.c 565 2011-09-11 02:48:21Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -40,8 +40,8 @@
|
||||
|
||||
QSE_IMPLEMENT_COMMON_FUNCTIONS (pio)
|
||||
|
||||
static qse_ssize_t pio_input (int cmd, void* arg, void* buf, qse_size_t size);
|
||||
static qse_ssize_t pio_output (int cmd, void* arg, void* buf, qse_size_t size);
|
||||
static qse_ssize_t pio_input (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size);
|
||||
static qse_ssize_t pio_output (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size);
|
||||
|
||||
qse_pio_t* qse_pio_open (
|
||||
qse_mmgr_t* mmgr, qse_size_t ext,
|
||||
@ -999,11 +999,15 @@ int qse_pio_init (
|
||||
|
||||
if (oflags & QSE_PIO_TEXT)
|
||||
{
|
||||
int topt = 0;
|
||||
|
||||
if (oflags & QSE_PIO_IGNOREMBWCERR) topt |= QSE_TIO_IGNOREMBWCERR;
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(tio); i++)
|
||||
{
|
||||
int r;
|
||||
|
||||
tio[i] = qse_tio_open (pio->mmgr, 0);
|
||||
tio[i] = qse_tio_open (pio->mmgr, 0, topt);
|
||||
if (tio[i] == QSE_NULL)
|
||||
{
|
||||
pio->errnum = QSE_PIO_ENOMEM;
|
||||
@ -1565,7 +1569,7 @@ int qse_pio_kill (qse_pio_t* pio)
|
||||
#endif
|
||||
}
|
||||
|
||||
static qse_ssize_t pio_input (int cmd, void* arg, void* buf, qse_size_t size)
|
||||
static qse_ssize_t pio_input (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size)
|
||||
{
|
||||
qse_pio_pin_t* pin = (qse_pio_pin_t*)arg;
|
||||
QSE_ASSERT (pin != QSE_NULL);
|
||||
@ -1580,7 +1584,7 @@ static qse_ssize_t pio_input (int cmd, void* arg, void* buf, qse_size_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static qse_ssize_t pio_output (int cmd, void* arg, void* buf, qse_size_t size)
|
||||
static qse_ssize_t pio_output (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size)
|
||||
{
|
||||
qse_pio_pin_t* pin = (qse_pio_pin_t*)arg;
|
||||
QSE_ASSERT (pin != QSE_NULL);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: sio.c 556 2011-08-31 15:43:46Z hyunghwan.chung $
|
||||
* $Id: sio.c 565 2011-09-11 02:48:21Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -21,8 +21,8 @@
|
||||
#include <qse/cmn/sio.h>
|
||||
#include "mem.h"
|
||||
|
||||
static qse_ssize_t __sio_input (int cmd, void* arg, void* buf, qse_size_t size);
|
||||
static qse_ssize_t __sio_output (int cmd, void* arg, void* buf, qse_size_t size);
|
||||
static qse_ssize_t __sio_input (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size);
|
||||
static qse_ssize_t __sio_output (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size);
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <windows.h>
|
||||
@ -56,6 +56,7 @@ static qse_sio_t __sio_in =
|
||||
{
|
||||
QSE_NULL,
|
||||
0,
|
||||
0,
|
||||
|
||||
__sio_input,
|
||||
__sio_output,
|
||||
@ -97,6 +98,7 @@ static qse_sio_t __sio_out =
|
||||
{
|
||||
QSE_NULL,
|
||||
0,
|
||||
0,
|
||||
|
||||
__sio_input,
|
||||
__sio_output,
|
||||
@ -138,6 +140,7 @@ static qse_sio_t __sio_err =
|
||||
{
|
||||
QSE_NULL,
|
||||
0,
|
||||
0,
|
||||
|
||||
__sio_input,
|
||||
__sio_output,
|
||||
@ -195,6 +198,7 @@ int qse_sio_init (
|
||||
qse_sio_t* sio, qse_mmgr_t* mmgr, const qse_char_t* file, int flags)
|
||||
{
|
||||
int mode;
|
||||
int topt = 0;
|
||||
|
||||
if (mmgr == QSE_NULL) mmgr = QSE_MMGR_GETDFL();
|
||||
|
||||
@ -206,7 +210,9 @@ int qse_sio_init (
|
||||
|
||||
if (qse_fio_init (&sio->fio, mmgr, file, flags, mode) <= -1) return -1;
|
||||
|
||||
if (qse_tio_init(&sio->tio, mmgr) <= -1)
|
||||
if (flags & QSE_SIO_IGNOREMBWCERR) topt |= QSE_TIO_IGNOREMBWCERR;
|
||||
|
||||
if (qse_tio_init(&sio->tio, mmgr, topt) <= -1)
|
||||
{
|
||||
qse_fio_fini (&sio->fio);
|
||||
return -1;
|
||||
@ -329,7 +335,7 @@ int qse_sio_seek (qse_sio_t* sio, qse_sio_seek_t pos)
|
||||
}
|
||||
#endif
|
||||
|
||||
static qse_ssize_t __sio_input (int cmd, void* arg, void* buf, qse_size_t size)
|
||||
static qse_ssize_t __sio_input (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size)
|
||||
{
|
||||
qse_sio_t* sio = (qse_sio_t*)arg;
|
||||
|
||||
@ -358,7 +364,7 @@ static qse_ssize_t __sio_input (int cmd, void* arg, void* buf, qse_size_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static qse_ssize_t __sio_output (int cmd, void* arg, void* buf, qse_size_t size)
|
||||
static qse_ssize_t __sio_output (qse_tio_cmd_t cmd, void* arg, void* buf, qse_size_t size)
|
||||
{
|
||||
qse_sio_t* sio = (qse_sio_t*)arg;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: tio-get.c 556 2011-08-31 15:43:46Z hyunghwan.chung $
|
||||
* $Id: tio-get.c 565 2011-09-11 02:48:21Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -84,6 +84,12 @@ static qse_ssize_t tio_getc (qse_tio_t* tio, qse_char_t* c)
|
||||
if (n == 0)
|
||||
{
|
||||
/* illegal sequence */
|
||||
if (tio->flags & QSE_TIO_IGNOREMBWCERR)
|
||||
{
|
||||
*c = tio->inbuf[tio->inbuf_curp++];
|
||||
return 1;
|
||||
}
|
||||
|
||||
tio->inbuf_curp++; /* skip one byte */
|
||||
tio->errnum = QSE_TIO_EILSEQ;
|
||||
return -1;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: tio-put.c 559 2011-09-04 16:21:54Z hyunghwan.chung $
|
||||
* $Id: tio-put.c 565 2011-09-11 02:48:21Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -51,6 +51,12 @@ static qse_ssize_t tio_putc (qse_tio_t* tio, qse_char_t c, int* flush_needed)
|
||||
n = qse_wcrtomb (c, mc, QSE_COUNTOF(mc), &tio->mbstate.out);
|
||||
if (n == 0)
|
||||
{
|
||||
if (tio->flags & QSE_TIO_IGNOREMBWCERR)
|
||||
{
|
||||
/* return 1 as if c has been written successfully */
|
||||
return 1;
|
||||
}
|
||||
|
||||
tio->errnum = QSE_TIO_EILCHR;
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: tio.c 559 2011-09-04 16:21:54Z hyunghwan.chung $
|
||||
* $Id: tio.c 565 2011-09-11 02:48:21Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
QSE_IMPLEMENT_COMMON_FUNCTIONS (tio)
|
||||
|
||||
qse_tio_t* qse_tio_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
|
||||
qse_tio_t* qse_tio_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, int flags)
|
||||
{
|
||||
qse_tio_t* tio;
|
||||
|
||||
@ -40,7 +40,7 @@ qse_tio_t* qse_tio_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
|
||||
tio = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_tio_t) + xtnsize);
|
||||
if (tio == QSE_NULL) return QSE_NULL;
|
||||
|
||||
if (qse_tio_init (tio, mmgr) <= -1)
|
||||
if (qse_tio_init (tio, mmgr, flags) <= -1)
|
||||
{
|
||||
QSE_MMGR_FREE (mmgr, tio);
|
||||
return QSE_NULL;
|
||||
@ -56,13 +56,14 @@ int qse_tio_close (qse_tio_t* tio)
|
||||
return n;
|
||||
}
|
||||
|
||||
int qse_tio_init (qse_tio_t* tio, qse_mmgr_t* mmgr)
|
||||
int qse_tio_init (qse_tio_t* tio, qse_mmgr_t* mmgr, int flags)
|
||||
{
|
||||
if (mmgr == QSE_NULL) mmgr = QSE_MMGR_GETDFL();
|
||||
|
||||
QSE_MEMSET (tio, 0, QSE_SIZEOF(*tio));
|
||||
|
||||
tio->mmgr = mmgr;
|
||||
tio->flags = flags;
|
||||
|
||||
/*
|
||||
tio->input_func = QSE_NULL;
|
||||
@ -77,7 +78,6 @@ int qse_tio_init (qse_tio_t* tio, qse_mmgr_t* mmgr)
|
||||
*/
|
||||
|
||||
tio->errnum = QSE_TIO_ENOERR;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user