added aio files. some file restructuring in progress

This commit is contained in:
2016-04-27 14:57:50 +00:00
parent 632a4d7181
commit 61a6cf281f
68 changed files with 7385 additions and 143 deletions

View File

@ -8,7 +8,6 @@ pkginclude_HEADERS = \
dir.h \
dll.h \
env.h \
fio.h \
fma.h \
fmt.h \
fs.h \
@ -25,22 +24,17 @@ pkginclude_HEADERS = \
mem.h \
nwad.h \
nwif.h \
nwio.h \
oht.h \
opt.h \
path.h \
pio.h \
pma.h \
rbt.h \
rex.h \
sck.h \
sio.h \
sll.h \
slmb.h \
str.h \
task.h \
time.h \
tio.h \
tmr.h \
tre.h \
uni.h \

View File

@ -123,14 +123,14 @@ am__can_run_installinfo = \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__pkginclude_HEADERS_DIST = alg.h chr.h cp949.h cp950.h dir.h dll.h \
env.h fio.h fma.h fmt.h fs.h gdl.h glob.h htb.h hton.h ipad.h \
lda.h main.h map.h mb8.h mbwc.h mem.h nwad.h nwif.h nwio.h \
oht.h opt.h path.h pio.h pma.h rbt.h rex.h sck.h sio.h sll.h \
slmb.h str.h task.h time.h tio.h tmr.h tre.h uni.h uri.h \
utf8.h xma.h Mmgr.hpp StdMmgr.hpp HeapMmgr.hpp Mmged.hpp \
ScopedPtr.hpp SharedPtr.hpp StrBase.hpp String.hpp Mpool.hpp \
Association.hpp LinkedList.hpp HashList.hpp HashTable.hpp \
RedBlackTree.hpp RedBlackTable.hpp Array.hpp BinaryHeap.hpp
env.h fma.h fmt.h fs.h gdl.h glob.h htb.h hton.h ipad.h lda.h \
main.h map.h mb8.h mbwc.h mem.h nwad.h nwif.h oht.h opt.h \
path.h pma.h rbt.h rex.h sck.h sll.h slmb.h str.h time.h tmr.h \
tre.h uni.h uri.h utf8.h xma.h Mmgr.hpp StdMmgr.hpp \
HeapMmgr.hpp Mmged.hpp ScopedPtr.hpp SharedPtr.hpp StrBase.hpp \
String.hpp Mpool.hpp Association.hpp LinkedList.hpp \
HashList.hpp HashTable.hpp RedBlackTree.hpp RedBlackTable.hpp \
Array.hpp BinaryHeap.hpp
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@ -357,11 +357,10 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
pkginclude_HEADERS = alg.h chr.h cp949.h cp950.h dir.h dll.h env.h \
fio.h fma.h fmt.h fs.h gdl.h glob.h htb.h hton.h ipad.h lda.h \
main.h map.h mb8.h mbwc.h mem.h nwad.h nwif.h nwio.h oht.h \
opt.h path.h pio.h pma.h rbt.h rex.h sck.h sio.h sll.h slmb.h \
str.h task.h time.h tio.h tmr.h tre.h uni.h uri.h utf8.h xma.h \
$(am__append_1)
fma.h fmt.h fs.h gdl.h glob.h htb.h hton.h ipad.h lda.h main.h \
map.h mb8.h mbwc.h mem.h nwad.h nwif.h oht.h opt.h path.h \
pma.h rbt.h rex.h sck.h sll.h slmb.h str.h time.h tmr.h tre.h \
uni.h uri.h utf8.h xma.h $(am__append_1)
all: all-am
.SUFFIXES:

View File

@ -1,325 +0,0 @@
/*
* $Id$
*
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_CMN_FIO_H_
#define _QSE_CMN_FIO_H_
/** @file
* This file defines a simple file I/O interface.
*/
#include <qse/types.h>
#include <qse/macros.h>
enum qse_fio_flag_t
{
/* (1 << 0) to (1 << 7) reserved for qse_sio_flag_t.
* see <qse/cmn/sio.h>. nerver use this value. */
QSE_FIO_RESERVED = 0xFF,
/** treat the file name pointer as a handle pointer */
QSE_FIO_HANDLE = (1 << 8),
/** treate the file name pointer as a pointer to file name
* template to use when making a temporary file name */
QSE_FIO_TEMPORARY = (1 << 9),
/** don't close an I/O handle in qse_fio_fini() and qse_fio_close() */
QSE_FIO_NOCLOSE = (1 << 10),
/** treat the path name as a multi-byte string */
QSE_FIO_MBSPATH = (1 << 11),
/* normal open flags */
QSE_FIO_READ = (1 << 14),
QSE_FIO_WRITE = (1 << 15),
QSE_FIO_APPEND = (1 << 16),
QSE_FIO_CREATE = (1 << 17),
QSE_FIO_TRUNCATE = (1 << 18),
QSE_FIO_EXCLUSIVE = (1 << 19),
QSE_FIO_SYNC = (1 << 20),
/* do not follow a symbolic link, only on a supported platform */
QSE_FIO_NOFOLLOW = (1 << 23),
/* for WIN32 only. harmless(no effect) when used on other platforms */
QSE_FIO_NOSHREAD = (1 << 24),
QSE_FIO_NOSHWRITE = (1 << 25),
QSE_FIO_NOSHDELETE = (1 << 26),
/* hints to OS. harmless(no effect) when used on unsupported platforms */
QSE_FIO_RANDOM = (1 << 27), /* hint that access be random */
QSE_FIO_SEQUENTIAL = (1 << 28) /* hint that access is sequential */
};
enum qse_fio_errnum_t
{
QSE_FIO_ENOERR = 0, /**< no error */
QSE_FIO_EOTHER, /**< other error */
QSE_FIO_ENOIMPL, /**< not implemented */
QSE_FIO_ESYSERR, /**< subsystem(system call) error */
QSE_FIO_EINTERN, /**< internal error */
QSE_FIO_ENOMEM, /**< out of memory */
QSE_FIO_EINVAL, /**< invalid parameter */
QSE_FIO_EACCES, /**< access denied */
QSE_FIO_ENOENT, /**< no such file */
QSE_FIO_EEXIST, /**< already exist */
QSE_FIO_EINTR, /**< interrupted */
QSE_FIO_EPIPE, /**< broken pipe */
QSE_FIO_EAGAIN /**< resource not available temporarily */
};
typedef enum qse_fio_errnum_t qse_fio_errnum_t;
enum qse_fio_std_t
{
QSE_FIO_STDIN = 0,
QSE_FIO_STDOUT = 1,
QSE_FIO_STDERR = 2
};
typedef enum qse_fio_std_t qse_fio_std_t;
/* seek origin */
enum qse_fio_ori_t
{
QSE_FIO_BEGIN = 0,
QSE_FIO_CURRENT = 1,
QSE_FIO_END = 2
};
/* file origin for seek */
typedef enum qse_fio_ori_t qse_fio_ori_t;
enum qse_fio_mode_t
{
QSE_FIO_SUID = 04000, /* set UID */
QSE_FIO_SGID = 02000, /* set GID */
QSE_FIO_SVTX = 01000, /* sticky bit */
QSE_FIO_RUSR = 00400, /* can be read by owner */
QSE_FIO_WUSR = 00200, /* can be written by owner */
QSE_FIO_XUSR = 00100, /* can be executed by owner */
QSE_FIO_RGRP = 00040, /* can be read by group */
QSE_FIO_WGRP = 00020, /* can be written by group */
QSE_FIO_XGRP = 00010, /* can be executed by group */
QSE_FIO_ROTH = 00004, /* can be read by others */
QSE_FIO_WOTH = 00002, /* can be written by others */
QSE_FIO_XOTH = 00001 /* can be executed by others */
};
#if defined(_WIN32)
/* <winnt.h> => typedef PVOID HANDLE; */
typedef void* qse_fio_hnd_t;
#elif defined(__OS2__)
/* <os2def.h> => typedef LHANDLE HFILE;
typedef unsigned long LHANDLE; */
typedef unsigned long qse_fio_hnd_t;
#elif defined(__DOS__)
typedef int qse_fio_hnd_t;
#elif defined(vms) || defined(__vms)
typedef void* qse_fio_hnd_t; /* struct FAB*, struct RAB* */
#else
typedef int qse_fio_hnd_t;
#endif
/* file offset */
typedef qse_foff_t qse_fio_off_t;
typedef struct qse_fio_t qse_fio_t;
typedef struct qse_fio_lck_t qse_fio_lck_t;
struct qse_fio_t
{
qse_mmgr_t* mmgr;
qse_fio_errnum_t errnum;
qse_fio_hnd_t handle;
int status;
};
struct qse_fio_lck_t
{
int type; /* READ, WRITE */
qse_fio_off_t offset; /* starting offset */
qse_fio_off_t length; /* length */
qse_fio_ori_t origin; /* origin */
};
#define QSE_FIO_HANDLE(fio) ((fio)->handle)
#if defined(__cplusplus)
extern "C" {
#endif
/**
* The qse_fio_open() function opens a file.
* To open a file, you should set the flags with at least one of
* QSE_FIO_READ, QSE_FIO_WRITE, QSE_FIO_APPEND.
*
* If the #QSE_FIO_HANDLE flag is set, the @a path parameter is interpreted
* as a pointer to qse_fio_hnd_t.
*
* If the #QSE_FIO_TEMPORARY flag is set, the @a path parameter is
* interpreted as a path name template and an actual file name to open
* is internally generated using the template. The @a path parameter
* is filled with the last actual path name attempted when the function
* returns. So, you must not pass a constant string to the @a path
* parameter when #QSE_FIO_TEMPORARY is set.
*/
QSE_EXPORT qse_fio_t* qse_fio_open (
qse_mmgr_t* mmgr,
qse_size_t ext,
const qse_char_t* path,
int flags,
int mode
);
/**
* The qse_fio_close() function closes a file.
*/
QSE_EXPORT void qse_fio_close (
qse_fio_t* fio
);
/**
* The qse_fio_close() function opens a file into @a fio.
*/
QSE_EXPORT int qse_fio_init (
qse_fio_t* fio,
qse_mmgr_t* mmgr,
const qse_char_t* path,
int flags,
int mode
);
/**
* The qse_fio_close() function finalizes a file by closing the handle
* stored in @a fio.
*/
QSE_EXPORT void qse_fio_fini (
qse_fio_t* fio
);
QSE_EXPORT qse_mmgr_t* qse_fio_getmmgr (
qse_fio_t* fio
);
QSE_EXPORT void* qse_fio_getxtn (
qse_fio_t* fio
);
QSE_EXPORT qse_fio_errnum_t qse_fio_geterrnum (
const qse_fio_t* fio
);
/**
* The qse_fio_gethandle() function returns the native file handle.
*/
QSE_EXPORT qse_fio_hnd_t qse_fio_gethandle (
const qse_fio_t* fio
);
/**
* The qse_fio_seek() function changes the current file position.
*/
QSE_EXPORT qse_fio_off_t qse_fio_seek (
qse_fio_t* fio,
qse_fio_off_t offset,
qse_fio_ori_t origin
);
/**
* The qse_fio_truncate() function truncates a file to @a size.
*/
QSE_EXPORT int qse_fio_truncate (
qse_fio_t* fio,
qse_fio_off_t size
);
/**
* The qse_fio_read() function reads data.
*/
QSE_EXPORT qse_ssize_t qse_fio_read (
qse_fio_t* fio,
void* buf,
qse_size_t size
);
/**
* The qse_fio_write() function writes data.
*/
QSE_EXPORT qse_ssize_t qse_fio_write (
qse_fio_t* fio,
const void* data,
qse_size_t size
);
/**
* The qse_fio_chmod() function changes the file mode.
*
* @note
* On _WIN32, this function is implemented on the best-effort basis and
* returns an error on the following conditions:
* - The file size is 0.
* - The file is opened without #QSE_FIO_READ.
*/
QSE_EXPORT int qse_fio_chmod (
qse_fio_t* fio,
int mode
);
/**
* The qse_fio_sync() function synchronizes file contents into storage media
* It is useful in determining the media error, without which qse_fio_close()
* may succeed despite such an error.
*/
QSE_EXPORT int qse_fio_sync (
qse_fio_t* fio
);
/* TODO: qse_fio_lock, qse_fio_unlock */
QSE_EXPORT int qse_fio_lock (
qse_fio_t* fio,
qse_fio_lck_t* lck,
int flags
);
QSE_EXPORT int qse_fio_unlock (
qse_fio_t* fio,
qse_fio_lck_t* lck,
int flags
);
QSE_EXPORT int qse_getstdfiohandle (
qse_fio_std_t std,
qse_fio_hnd_t* hnd
);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -30,6 +30,30 @@
#include <qse/types.h>
#include <qse/macros.h>
#define QSE_CONST_SWAP16(x) \
((qse_uint16_t)((((qse_uint16_t)(x) & (qse_uint16_t)0x00ffU) << 8) | \
(((qse_uint16_t)(x) & (qse_uint16_t)0xff00U) >> 8) ))
#define QSE_CONST_SWAP32(x) \
((qse_uint32_t)((((qse_uint32_t)(x) & (qse_uint32_t)0x000000ffUL) << 24) | \
(((qse_uint32_t)(x) & (qse_uint32_t)0x0000ff00UL) << 8) | \
(((qse_uint32_t)(x) & (qse_uint32_t)0x00ff0000UL) >> 8) | \
(((qse_uint32_t)(x) & (qse_uint32_t)0xff000000UL) >> 24) ))
#if defined(QSE_ENDIAN_LITTLE)
# define QSE_CONST_NTOH16(x) QSE_CONST_SWAP16(x)
# define QSE_CONST_HTON16(x) QSE_CONST_SWAP16(x)
# define QSE_CONST_NTOH32(x) QSE_CONST_SWAP32(x)
# define QSE_CONST_HTON32(x) QSE_CONST_SWAP32(x)
#elif defined(QSE_ENDIAN_BIG)
# define QSE_CONST_NTOH16(x) (x)
# define QSE_CONST_HTON16(x) (x)
# define QSE_CONST_NTOH32(x) (x)
# define QSE_CONST_HTON32(x) (x)
#else
# error UNKNOWN ENDIAN
#endif
#if defined(__cplusplus)
extern "C" {
#endif

View File

@ -1,219 +0,0 @@
/*
* $Id$
*
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_CMN_NWIO_H_
#define _QSE_CMN_NWIO_H_
/** @file
* This file defines a network-based text I/O interface.
*/
#include <qse/types.h>
#include <qse/macros.h>
#include <qse/cmn/tio.h>
#include <qse/cmn/nwad.h>
#include <qse/cmn/time.h>
#include <qse/cmn/sck.h>
enum qse_nwio_flag_t
{
QSE_NWIO_TEXT = (1 << 0),
QSE_NWIO_IGNOREMBWCERR = (1 << 1),
QSE_NWIO_NOAUTOFLUSH = (1 << 2),
/* normal open flags */
QSE_NWIO_PASSIVE = (1 << 8),
QSE_NWIO_TCP = (1 << 9),
QSE_NWIO_UDP = (1 << 10),
QSE_NWIO_REUSEADDR = (1 << 12),
QSE_NWIO_KEEPALIVE = (1 << 13),
/** do not reread if read has been interrupted */
QSE_NWIO_READNORETRY = (1 << 14),
/** do not rewrite if write has been interrupted */
QSE_NWIO_WRITENORETRY = (1 << 15),
};
enum qse_nwio_errnum_t
{
QSE_NWIO_ENOERR = 0, /**< no error */
QSE_NWIO_EOTHER, /**< other error */
QSE_NWIO_ENOIMPL, /**< not implemented */
QSE_NWIO_ESYSERR, /**< subsystem(system call) error */
QSE_NWIO_EINTERN, /**< internal error */
QSE_NWIO_ENOMEM, /**< out of memory */
QSE_NWIO_EINVAL, /**< invalid parameter */
QSE_NWIO_EACCES, /**< access denied */
QSE_NWIO_ENOENT, /**< no such file */
QSE_NWIO_EEXIST, /**< already exist */
QSE_NWIO_EINTR, /**< interrupted */
QSE_NWIO_ETMOUT, /**< timed out */
QSE_NWIO_EPIPE, /**< broken pipe */
QSE_NWIO_EAGAIN, /**< resource not available temporarily */
QSE_NWIO_ECONN, /**< connection refused */
QSE_NWIO_EILSEQ, /**< illegal sequence */
QSE_NWIO_EICSEQ, /**< incomplete sequence */
QSE_NWIO_EILCHR /**< illegal character */
};
typedef enum qse_nwio_errnum_t qse_nwio_errnum_t;
struct qse_nwio_tmout_t
{
qse_ntime_t r, w, c, a;
};
typedef struct qse_nwio_tmout_t qse_nwio_tmout_t;
typedef qse_sck_hnd_t qse_nwio_hnd_t;
typedef struct qse_nwio_t qse_nwio_t;
/**
* The qse_nwio_t type defines a structure for a network-based stream.
*/
struct qse_nwio_t
{
qse_mmgr_t* mmgr;
int flags;
qse_nwio_errnum_t errnum;
qse_nwio_tmout_t tmout;
qse_nwio_hnd_t handle;
qse_tio_t* tio;
int status;
};
#define QSE_NWIO_HANDLE(nwio) ((nwio)->handle)
#if defined(__cplusplus)
extern "C" {
#endif
/**
* The qse_nwio_open() function opens a file.
* To open a file, you should set the flags with at least one of
* QSE_NWIO_READ, QSE_NWIO_WRITE, QSE_NWIO_APPEND.
*
* If the #QSE_NWIO_HANDLE flag is set, the @a nwad parameter is interpreted
* as a pointer to qse_nwio_hnd_t.
*/
QSE_EXPORT qse_nwio_t* qse_nwio_open (
qse_mmgr_t* mmgr,
qse_size_t ext,
const qse_nwad_t* nwad,
int flags,
const qse_nwio_tmout_t* tmout
);
/**
* The qse_nwio_close() function closes a file.
*/
QSE_EXPORT void qse_nwio_close (
qse_nwio_t* nwio
);
/**
* The qse_nwio_close() function opens a file into @a nwio.
*/
QSE_EXPORT int qse_nwio_init (
qse_nwio_t* nwio,
qse_mmgr_t* mmgr,
const qse_nwad_t* nwad,
int flags,
const qse_nwio_tmout_t* tmout
);
/**
* The qse_nwio_close() function finalizes a file by closing the handle
* stored in @a nwio.
*/
QSE_EXPORT void qse_nwio_fini (
qse_nwio_t* nwio
);
QSE_EXPORT qse_mmgr_t* qse_nwio_getmmgr (
qse_nwio_t* nwio
);
QSE_EXPORT void* qse_nwio_getxtn (
qse_nwio_t* nwio
);
QSE_EXPORT qse_nwio_errnum_t qse_nwio_geterrnum (
const qse_nwio_t* nwio
);
/**
* The qse_nwio_gethandle() function returns the native file handle.
*/
QSE_EXPORT qse_nwio_hnd_t qse_nwio_gethandle (
const qse_nwio_t* nwio
);
QSE_EXPORT qse_cmgr_t* qse_nwio_getcmgr (
qse_nwio_t* nwio
);
QSE_EXPORT void qse_nwio_setcmgr (
qse_nwio_t* nwio,
qse_cmgr_t* cmgr
);
QSE_EXPORT qse_ssize_t qse_nwio_flush (
qse_nwio_t* nwio
);
QSE_EXPORT void qse_nwio_drain (
qse_nwio_t* nwio
);
/**
* The qse_nwio_read() function reads data.
*/
QSE_EXPORT qse_ssize_t qse_nwio_read (
qse_nwio_t* nwio,
void* buf,
qse_size_t size
);
/**
* The qse_nwio_write() function writes data.
* If QSE_NWIO_TEXT is used and the size parameter is (qse_size_t)-1,
* the function treats the data parameter as a pointer to a null-terminated
* string.
*/
QSE_EXPORT qse_ssize_t qse_nwio_write (
qse_nwio_t* nwio,
const void* data,
qse_size_t size
);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -1,423 +0,0 @@
/*
* $Id$
*
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_CMN_PIO_H_
#define _QSE_CMN_PIO_H_
#include <qse/types.h>
#include <qse/macros.h>
#include <qse/cmn/tio.h>
#include <qse/cmn/env.h>
/** \file
* This file defines a piped interface to a child process. You can execute
* a child process, read and write to its stdin, stdout, stderr, and terminate
* it. It provides more advanced interface than popen() and pclose().
*/
/**
* The qse_pio_flag_t defines enumerators to compose flags to qse_pio_open().
*/
enum qse_pio_flag_t
{
/** enable text based I/O. */
QSE_PIO_TEXT = (1 << 0),
QSE_PIO_IGNOREMBWCERR = (1 << 1),
QSE_PIO_NOAUTOFLUSH = (1 << 2),
/** execute the command via a system shell
* (/bin/sh on unix/linux, cmd.exe on windows and os2) */
QSE_PIO_SHELL = (1 << 3),
/** indicate that the command to qse_pio_open() is a multi-byte string.
* it is useful if #QSE_CHAR_IS_WCHAR is defined. */
QSE_PIO_MBSCMD = (1 << 4),
/** don't attempt to close open file descriptors unknown to pio.
* it is useful only on a unix-like systems where file descriptors
* not set with FD_CLOEXEC are inherited by a child process.
* you're advised to set this option if all normal file descriptors
* in your application are open with FD_CLOEXEC set. it can skip
* checking a bunch of file descriptors and arranging to close
* them to prevent inheritance. */
QSE_PIO_NOCLOEXEC = (1 << 5),
/** indidate that the command to qse_pio_open()/qse_pio_init() is
* a pointer to a #qse_pio_fnc_t structure. supported on unix/linux
* only */
QSE_PIO_FNCCMD = (1 << 6),
/** write to stdin of a child process */
QSE_PIO_WRITEIN = (1 << 8),
/** read stdout of a child process */
QSE_PIO_READOUT = (1 << 9),
/** read stderr of a child process */
QSE_PIO_READERR = (1 << 10),
/** redirect stderr to stdout (2>&1, require #QSE_PIO_READOUT) */
QSE_PIO_ERRTOOUT = (1 << 11),
/** redirect stdout to stderr (1>&2, require #QSE_PIO_READERR) */
QSE_PIO_OUTTOERR = (1 << 12),
/** redirect stdin to the null device (</dev/null, <NUL) */
QSE_PIO_INTONUL = (1 << 13),
/** redirect stdin to the null device (>/dev/null, >NUL) */
QSE_PIO_ERRTONUL = (1 << 14),
/** redirect stderr to the null device (2>/dev/null, 2>NUL) */
QSE_PIO_OUTTONUL = (1 << 15),
/** drop stdin */
QSE_PIO_DROPIN = (1 << 16),
/** drop stdout */
QSE_PIO_DROPOUT = (1 << 17),
/** drop stderr */
QSE_PIO_DROPERR = (1 << 18),
/** do not reread if read has been interrupted */
QSE_PIO_READNORETRY = (1 << 21),
/** do not rewrite if write has been interrupted */
QSE_PIO_WRITENORETRY = (1 << 22),
/** return immediately from qse_pio_wait() if a child has not exited */
QSE_PIO_WAITNOBLOCK = (1 << 23),
/** do not wait again if waitpid has been interrupted */
QSE_PIO_WAITNORETRY = (1 << 24),
/** put stdin to non-blocking mode (only on supported platforms) */
QSE_PIO_INNOBLOCK = (1 << 25),
/** put stdout to non-blocking mode (only on supported platforms)*/
QSE_PIO_OUTNOBLOCK = (1 << 26),
/** put stderr to non-blocking mode (only on supported platforms) */
QSE_PIO_ERRNOBLOCK = (1 << 27)
};
/**
* The qse_pio_hid_t type defines pipe IDs established to a child process.
*/
enum qse_pio_hid_t
{
QSE_PIO_IN = 0, /**< stdin of a child process */
QSE_PIO_OUT = 1, /**< stdout of a child process */
QSE_PIO_ERR = 2 /**< stderr of a child process */
};
typedef enum qse_pio_hid_t qse_pio_hid_t;
typedef int (*qse_pio_fncptr_t) (void* ctx, qse_env_char_t** envir);
/**
* The qse_pio_fnc_t type defines a structure to point to the function
* executed in a child process when #QSE_PIO_FNCCMD is specified.
*/
typedef struct qse_pio_fnc_t qse_pio_fnc_t;
struct qse_pio_fnc_t
{
qse_pio_fncptr_t ptr;
void* ctx;
};
/**
* The qse_pio_errnum_t type defines error numbers.
*/
enum qse_pio_errnum_t
{
QSE_PIO_ENOERR = 0, /**< no error */
QSE_PIO_EOTHER, /**< unknown error */
QSE_PIO_ENOIMPL, /**< not implemented */
QSE_PIO_ESYSERR, /**< subsystem error */
QSE_PIO_EINTERN, /**< internal error */
QSE_PIO_ENOMEM, /**< out of memory */
QSE_PIO_EINVAL, /**< invalid parameter */
QSE_PIO_EACCES, /**< access denied */
QSE_PIO_ENOENT, /**< no such file */
QSE_PIO_EEXIST, /**< already exist */
QSE_PIO_EINTR, /**< interrupted */
QSE_PIO_EPIPE, /**< broken pipe */
QSE_PIO_EAGAIN, /**< resource not available temporarily */
QSE_PIO_ENOHND, /**< no handle available */
QSE_PIO_ECHILD, /**< the child is not valid */
QSE_PIO_EILSEQ, /**< illegal sequence */
QSE_PIO_EICSEQ, /**< incomplete sequence */
QSE_PIO_EILCHR /**< illegal character */
};
typedef enum qse_pio_errnum_t qse_pio_errnum_t;
#if defined(_WIN32)
/* <winnt.h> => typedef PVOID HANDLE; */
typedef void* qse_pio_hnd_t; /**< defines a pipe handle type */
typedef void* qse_pio_pid_t; /**< defines a process handle type */
# define QSE_PIO_HND_NIL ((qse_pio_hnd_t)QSE_NULL)
# define QSE_PIO_PID_NIL ((qse_pio_pid_t)QSE_NULL)
#elif defined(__OS2__)
/* <os2def.h> => typedef LHANDLE HFILE;
typedef LHANDLE PID;
typedef unsigned long LHANDLE; */
typedef unsigned long qse_pio_hnd_t; /**< defines a pipe handle type */
typedef unsigned long qse_pio_pid_t; /**< defined a process handle type */
# define QSE_PIO_HND_NIL ((qse_pio_hnd_t)-1)
# define QSE_PIO_PID_NIL ((qse_pio_pid_t)-1)
#elif defined(__DOS__)
typedef int qse_pio_hnd_t; /**< defines a pipe handle type */
typedef int qse_pio_pid_t; /**< defines a process handle type */
# define QSE_PIO_HND_NIL ((qse_pio_hnd_t)-1)
# define QSE_PIO_PID_NIL ((qse_pio_pid_t)-1)
#else
typedef int qse_pio_hnd_t; /**< defines a pipe handle type */
typedef int qse_pio_pid_t; /**< defines a process handle type */
# define QSE_PIO_HND_NIL ((qse_pio_hnd_t)-1)
# define QSE_PIO_PID_NIL ((qse_pio_pid_t)-1)
#endif
typedef struct qse_pio_t qse_pio_t;
typedef struct qse_pio_pin_t qse_pio_pin_t;
struct qse_pio_pin_t
{
qse_pio_hnd_t handle;
qse_tio_t* tio;
qse_pio_t* self;
};
/**
* The qse_pio_t type defines a structure to store status for piped I/O
* to a child process. The qse_pio_xxx() funtions are written around this
* type. Do not change the value of each field directly.
*/
struct qse_pio_t
{
qse_mmgr_t* mmgr;
int flags; /**< options */
qse_pio_errnum_t errnum; /**< error number */
qse_pio_pid_t child; /**< handle to a child process */
qse_pio_pin_t pin[3];
};
/** access the \a errnum field of the #qse_pio_t structure */
#define QSE_PIO_ERRNUM(pio) ((pio)->errnum)
/** access the \a child field of the #qse_pio_t structure */
#define QSE_PIO_CHILD(pio) ((pio)->child)
/** get the native handle from the #qse_pio_t structure */
#define QSE_PIO_HANDLE(pio,hid) ((pio)->pin[hid].handle)
#if defined(__cplusplus)
extern "C" {
#endif
/**
* The qse_pio_open() function executes a command \a cmd and establishes
* pipes to it. #QSE_PIO_SHELL causes the function to execute \a cmd via
* the default shell of an underlying system: /bin/sh on *nix, cmd.exe on win32.
* On *nix systems, a full path to the command is needed if it is not specified.
* If \a env is #QSE_NULL, the environment of \a cmd inherits that of the
* calling process. If you want to pass an empty environment, you can pass
* an empty \a env object with no items inserted. If #QSE_PIO_MBSCMD is
* specified in \a flags, \a cmd is treated as a multi-byte string whose
* character type is #qse_mchar_t.
* \return #qse_pio_t object on success, #QSE_NULL on failure
*/
QSE_EXPORT qse_pio_t* qse_pio_open (
qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t ext, /**< extension size */
const qse_char_t* cmd, /**< command to execute */
qse_env_t* env, /**< environment */
int flags /**< 0 or a number OR'ed of the
#qse_pio_flag_t enumerators*/
);
/**
* The qse_pio_close() function closes pipes to a child process and waits for
* the child process to exit.
*/
QSE_EXPORT void qse_pio_close (
qse_pio_t* pio /**< pio object */
);
/**
* The qse_pio_init() functions performs the same task as the qse_pio_open()
* except that you need to allocate a #qse_pio_t structure and pass it to the
* function.
* \return 0 on success, -1 on failure
*/
QSE_EXPORT int qse_pio_init (
qse_pio_t* pio, /**< pio object */
qse_mmgr_t* mmgr, /**< memory manager */
const qse_char_t* cmd, /**< command to execute */
qse_env_t* env, /**< environment */
int flags /**< 0 or a number OR'ed of the
#qse_pio_flag_t enumerators*/
);
/**
* The qse_pio_fini() function performs the same task as qse_pio_close()
* except that it does not destroy a #qse_pio_t structure pointed to by \a pio.
*/
QSE_EXPORT void qse_pio_fini (
qse_pio_t* pio /**< pio object */
);
QSE_EXPORT qse_mmgr_t* qse_pio_getmmgr (
qse_pio_t* pio
);
QSE_EXPORT void* qse_pio_getxtn (
qse_pio_t* pio
);
/**
* The qse_pio_geterrnum() function returns the number of the last error
* occurred.
* \return error number
*/
QSE_EXPORT qse_pio_errnum_t qse_pio_geterrnum (
const qse_pio_t* pio /**< pio object */
);
/**
* The qse_pio_getcmgr() function returns the current character manager.
* It returns #QSE_NULL is \a pio is not opened with #QSE_PIO_TEXT.
*/
QSE_EXPORT qse_cmgr_t* qse_pio_getcmgr (
qse_pio_t* pio,
qse_pio_hid_t hid
);
/**
* The qse_pio_setcmgr() function changes the character manager to \a cmgr.
* The character manager is used only if \a pio is opened with #QSE_PIO_TEXT.
*/
QSE_EXPORT void qse_pio_setcmgr (
qse_pio_t* pio,
qse_pio_hid_t hid,
qse_cmgr_t* cmgr
);
/**
* The qse_pio_gethandle() function gets a pipe handle.
* \return pipe handle
*/
QSE_EXPORT qse_pio_hnd_t qse_pio_gethandle (
const qse_pio_t* pio, /**< pio object */
qse_pio_hid_t hid /**< handle ID */
);
/**
* The qse_pio_getchild() function gets a process handle.
* \return process handle
*/
QSE_EXPORT qse_pio_pid_t qse_pio_getchild (
const qse_pio_t* pio /**< pio object */
);
/**
* The qse_pio_read() fucntion reads at most \a size bytes/characters
* and stores them to the buffer pointed to by \a buf.
* \return -1 on failure, 0 on EOF, data length read on success
*/
QSE_EXPORT qse_ssize_t qse_pio_read (
qse_pio_t* pio, /**< pio object */
qse_pio_hid_t hid, /**< handle ID */
void* buf, /**< buffer to fill */
qse_size_t size /**< buffer size */
);
/**
* The qse_pio_write() function writes up \a size bytes/characters
* from the buffer pointed to by \a data. If #QSE_PIO_TEXT is used
* and the \a size parameter is (qse_size_t)-1, the function treats
* the \a data parameter as a pointer to a null-terminated string.
* (qse_size_t)-1 into \a size is not treated specially if #QSE_PIO_TEXT
* is not set.
*
* \return -1 on failure, data length written on success
*/
QSE_EXPORT qse_ssize_t qse_pio_write (
qse_pio_t* pio, /**< pio object */
qse_pio_hid_t hid, /**< handle ID */
const void* data, /**< data to write */
qse_size_t size /**< data size */
);
/**
* The qse_pio_flush() flushes buffered data if #QSE_PIO_TEXT has been
* specified to qse_pio_open() and qse_pio_init().
*/
QSE_EXPORT qse_ssize_t qse_pio_flush (
qse_pio_t* pio, /**< pio object */
qse_pio_hid_t hid /**< handle ID */
);
/**
* The qse_pio_drain() drops unflushed input and output data in the
* buffer.
*/
QSE_EXPORT void qse_pio_drain (
qse_pio_t* pio, /**< pio object */
qse_pio_hid_t hid /**< handle ID */
);
/**
* The qse_pio_end() function closes a pipe to a child process
*/
QSE_EXPORT void qse_pio_end (
qse_pio_t* pio, /**< pio object */
qse_pio_hid_t hid /**< handle ID */
);
/**
* The qse_pio_wait() function waits for a child process to terminate.
* #QSE_PIO_WAIT_NORETRY causes the function to return an error and set the
* \a pio->errnum field to #QSE_PIO_EINTR if the underlying system call has
* been interrupted. If #QSE_PIO_WAIT_NOBLOCK is used, the return value of 256
* indicates that the child process has not terminated. Otherwise, 256 is never
* returned.
*
* \return
* -1 on error, 256 if the child is alive and #QSE_PIO_WAIT_NOBLOCK is used,
* a number between 0 and 255 inclusive if the child process ends normally,
* 256 + signal number if the child process is terminated by a signal.
*/
QSE_EXPORT int qse_pio_wait (
qse_pio_t* pio /**< pio object */
);
/**
* The qse_pio_kill() function terminates a child process by force.
* You should know the danger of calling this function as the function can
* kill a process that is not your child process if it has terminated but
* there is a new process with the same process handle.
* \return 0 on success, -1 on failure
*/
QSE_EXPORT int qse_pio_kill (
qse_pio_t* pio /**< pio object */
);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -1,462 +0,0 @@
/*
* $Id$
*
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_CMN_SIO_H_
#define _QSE_CMN_SIO_H_
/** @file
* This file defines a simple stream I/O interface.
*/
#include <qse/types.h>
#include <qse/macros.h>
#include <qse/cmn/fio.h>
#include <qse/cmn/tio.h>
#include <stdarg.h>
enum qse_sio_flag_t
{
/* ensure that these enumerators never overlap with
* qse_fio_flag_t enumerators. you can use values between
* (1<<0) and (1<<7) inclusive reserved in qse_fio_flag_t.
* the range is represented by QSE_FIO_RESERVED. */
QSE_SIO_LINEBREAK = (1 << 0), /* expand \n to a system line-break convention if necessary */
QSE_SIO_IGNOREMBWCERR = (1 << 1),
QSE_SIO_NOAUTOFLUSH = (1 << 2),
QSE_SIO_KEEPPATH = (1 << 3),
/* ensure that the following enumerators are one of
* qse_fio_flags_t enumerators */
QSE_SIO_HANDLE = QSE_FIO_HANDLE,
QSE_SIO_TEMPORARY = QSE_FIO_TEMPORARY,
QSE_SIO_NOCLOSE = QSE_FIO_NOCLOSE,
QSE_SIO_READ = QSE_FIO_READ,
QSE_SIO_WRITE = QSE_FIO_WRITE,
QSE_SIO_APPEND = QSE_FIO_APPEND,
QSE_SIO_CREATE = QSE_FIO_CREATE,
QSE_SIO_TRUNCATE = QSE_FIO_TRUNCATE,
QSE_SIO_EXCLUSIVE = QSE_FIO_EXCLUSIVE,
QSE_SIO_SYNC = QSE_FIO_SYNC,
QSE_SIO_NOFOLLOW = QSE_FIO_NOFOLLOW,
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
};
enum qse_sio_errnum_t
{
QSE_SIO_ENOERR = 0, /**< no error */
QSE_SIO_EOTHER, /**< other error */
QSE_SIO_ENOIMPL, /**< not implemented */
QSE_SIO_ESYSERR, /**< subsystem(system call) error */
QSE_SIO_EINTERN, /**< internal error */
QSE_SIO_ENOMEM, /**< out of memory */
QSE_SIO_EINVAL, /**< invalid parameter */
QSE_SIO_EACCES, /**< access denied */
QSE_SIO_ENOENT, /**< no such file */
QSE_SIO_EEXIST, /**< already exist */
QSE_SIO_EINTR, /**< interrupted */
QSE_SIO_EPIPE, /**< broken pipe */
QSE_SIO_EAGAIN, /**< resource not available temporarily */
QSE_SIO_EILSEQ, /**< illegal sequence */
QSE_SIO_EICSEQ, /**< incomplete sequence */
QSE_SIO_EILCHR /**< illegal character */
};
typedef enum qse_sio_errnum_t qse_sio_errnum_t;
typedef qse_fio_off_t qse_sio_pos_t;
typedef qse_fio_hnd_t qse_sio_hnd_t;
typedef qse_fio_std_t qse_sio_std_t;
typedef qse_fio_ori_t qse_sio_ori_t;
#define QSE_SIO_STDIN QSE_FIO_STDIN
#define QSE_SIO_STDOUT QSE_FIO_STDOUT
#define QSE_SIO_STDERR QSE_FIO_STDERR
#define QSE_SIO_BEGIN QSE_FIO_BEGIN
#define QSE_SIO_CURRENT QSE_FIO_CURRENT
#define QSE_SIO_END QSE_FIO_END
/**
* The qse_sio_t type defines a simple text stream over a file. It also
* provides predefined streams for standard input, output, and error.
*/
typedef struct qse_sio_t qse_sio_t;
struct qse_sio_t
{
qse_mmgr_t* mmgr;
qse_sio_errnum_t errnum;
qse_fio_t file;
struct
{
qse_tio_t io;
qse_sio_t* xtn; /* static extension for tio */
} tio;
qse_mchar_t inbuf[2048];
qse_mchar_t outbuf[2048];
qse_char_t* path;
#if defined(_WIN32) || defined(__OS2__)
int status;
#endif
};
/** access the @a errnum field of the #qse_sio_t structure */
#define QSE_SIO_ERRNUM(sio) ((sio)->errnum)
#if defined(__cplusplus)
extern "C" {
#endif
/**
* The qse_sio_open() fucntion creates a stream object.
*/
QSE_EXPORT 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 flags /**< number OR'ed of #qse_sio_flag_t */
);
QSE_EXPORT 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 flags /**< number OR'ed of #qse_sio_flag_t */
);
/**
* The qse_sio_close() function destroys a stream object.
*/
QSE_EXPORT void qse_sio_close (
qse_sio_t* sio /**< stream */
);
QSE_EXPORT int qse_sio_init (
qse_sio_t* sio,
qse_mmgr_t* mmgr,
const qse_char_t* file,
int flags
);
QSE_EXPORT int qse_sio_initstd (
qse_sio_t* sio,
qse_mmgr_t* mmgr,
qse_sio_std_t std,
int flags
);
QSE_EXPORT void qse_sio_fini (
qse_sio_t* sio
);
QSE_EXPORT qse_mmgr_t* qse_sio_getmmgr (
qse_sio_t* sio
);
QSE_EXPORT void* qse_sio_getxtn (
qse_sio_t* sio
);
QSE_EXPORT qse_sio_errnum_t qse_sio_geterrnum (
const qse_sio_t* sio
);
QSE_EXPORT qse_cmgr_t* qse_sio_getcmgr (
qse_sio_t* sio
);
QSE_EXPORT void qse_sio_setcmgr (
qse_sio_t* sio,
qse_cmgr_t* cmgr
);
QSE_EXPORT qse_sio_hnd_t qse_sio_gethandle (
const qse_sio_t* sio
);
/**
* The qse_sio_getpath() returns the file path used to open the stream.
* It returns #QSE_NULL if #QSE_SIO_HANDLE was on or #QSE_SIO_KEEPPATH
* was off at the time of opening.
*/
QSE_EXPORT const qse_char_t* qse_sio_getpath (
qse_sio_t* sio
);
QSE_EXPORT qse_ssize_t qse_sio_flush (
qse_sio_t* sio
);
/**
* The qse_sio_drain() funtion purges all buffered data without writing.
*/
QSE_EXPORT void qse_sio_drain (
qse_sio_t* sio
);
QSE_EXPORT qse_ssize_t qse_sio_getmc (
qse_sio_t* sio,
qse_mchar_t* c
);
QSE_EXPORT qse_ssize_t qse_sio_getwc (
qse_sio_t* sio,
qse_wchar_t* c
);
QSE_EXPORT qse_ssize_t qse_sio_getmbs (
qse_sio_t* sio,
qse_mchar_t* buf,
qse_size_t size
);
QSE_EXPORT qse_ssize_t qse_sio_getmbsn (
qse_sio_t* sio,
qse_mchar_t* buf,
qse_size_t size
);
/**
* The qse_sio_getwcs() function reads at most @a size - 1 characters
* from the stream @a sio into the buffer @a buf. If a new line or EOF
* is encountered, it stops reading from the stream. It null-terminates
* the buffer if @a size is greater than 0.
*/
QSE_EXPORT qse_ssize_t qse_sio_getwcs (
qse_sio_t* sio,
qse_wchar_t* buf,
qse_size_t size
);
/**
* The qse_sio_getwcsn() function reads at most @a size characters
* from the stream @a sio into the buffer @a buf. If a new line or EOF
* is encountered, it stops reading from the stream.
*/
QSE_EXPORT qse_ssize_t qse_sio_getwcsn (
qse_sio_t* sio,
qse_wchar_t* buf,
qse_size_t size
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_sio_getc(sio,c) qse_sio_getmb(sio,c)
# define qse_sio_getstr(sio,buf,size) qse_sio_getmbs(sio,buf,size)
# define qse_sio_getstrn(sio,buf,size) qse_sio_getmbsn(sio,buf,size)
#else
# define qse_sio_getc(sio,c) qse_sio_getwc(sio,c)
# define qse_sio_getstr(sio,buf,size) qse_sio_getwcs(sio,buf,size)
# define qse_sio_getstrn(sio,buf,size) qse_sio_getwcsn(sio,buf,size)
#endif
QSE_EXPORT qse_ssize_t qse_sio_putmb (
qse_sio_t* sio,
qse_mchar_t c
);
QSE_EXPORT qse_ssize_t qse_sio_putwc (
qse_sio_t* sio,
qse_wchar_t c
);
QSE_EXPORT qse_ssize_t qse_sio_putmbs (
qse_sio_t* sio,
const qse_mchar_t* str
);
QSE_EXPORT qse_ssize_t qse_sio_putwcs (
qse_sio_t* sio,
const qse_wchar_t* str
);
QSE_EXPORT qse_ssize_t qse_sio_putmbsn (
qse_sio_t* sio,
const qse_mchar_t* str,
qse_size_t size
);
QSE_EXPORT qse_ssize_t qse_sio_putwcsn (
qse_sio_t* sio,
const qse_wchar_t* str,
qse_size_t size
);
QSE_EXPORT qse_ssize_t qse_sio_putmbsf (
qse_sio_t* sio,
const qse_mchar_t* fmt,
...
);
QSE_EXPORT qse_ssize_t qse_sio_putwcsf (
qse_sio_t* sio,
const qse_wchar_t* fmt,
...
);
QSE_EXPORT qse_ssize_t qse_sio_putmbsvf (
qse_sio_t* sio,
const qse_mchar_t* fmt,
va_list ap
);
QSE_EXPORT qse_ssize_t qse_sio_putwcsvf (
qse_sio_t* sio,
const qse_wchar_t* fmt,
va_list ap
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_sio_putc(sio,c) qse_sio_putmb(sio,c)
# define qse_sio_putstr(sio,str) qse_sio_putmbs(sio,str)
# define qse_sio_putstrn(sio,str,size) qse_sio_putmbsn(sio,str,size)
# define qse_sio_putstrf qse_sio_putmbsf
# define qse_sio_putstrvf(sio,fmt,ap) qse_sio_putmbsvf(sio,fmt,ap)
#else
# define qse_sio_putc(sio,c) qse_sio_putwc(sio,c)
# define qse_sio_putstr(sio,str) qse_sio_putwcs(sio,str)
# define qse_sio_putstrn(sio,str,size) qse_sio_putwcsn(sio,str,size)
# define qse_sio_putstrf qse_sio_putwcsf
# define qse_sio_putstrvf(sio,fmt,ap) qse_sio_putwcsvf(sio,fmt,ap)
#endif
/**
* The qse_sio_getpos() function gets the current position in a stream.
* Note that it may not return the desired postion due to buffering.
* @return 0 on success, -1 on failure
*/
QSE_EXPORT int qse_sio_getpos (
qse_sio_t* sio, /**< stream */
qse_sio_pos_t* pos /**< position */
);
/**
* The qse_sio_setpos() function changes the current position in a stream.
* @return 0 on success, -1 on failure
*/
QSE_EXPORT int qse_sio_setpos (
qse_sio_t* sio, /**< stream */
qse_sio_pos_t pos /**< position */
);
QSE_EXPORT int qse_sio_truncate (
qse_sio_t* sio,
qse_sio_pos_t pos
);
/**
* The qse_sio_seek() function repositions the current file offset.
* Upon success, \a pos is adjusted to the new offset from the beginning
* of the file.
*/
QSE_EXPORT int qse_sio_seek (
qse_sio_t* sio,
qse_sio_pos_t* pos,
qse_sio_ori_t origin
);
QSE_EXPORT int qse_openstdsios (void);
QSE_EXPORT void qse_closestdsios (void);
QSE_EXPORT qse_sio_t* qse_getstdout (void);
QSE_EXPORT qse_sio_t* qse_getstderr (void);
QSE_EXPORT qse_ssize_t qse_putmbsf (
const qse_mchar_t* fmt,
...
);
QSE_EXPORT qse_ssize_t qse_putwcsf (
const qse_wchar_t* fmt,
...
);
QSE_EXPORT qse_ssize_t qse_putmbsvf (
const qse_mchar_t* fmt,
va_list ap
);
QSE_EXPORT qse_ssize_t qse_putwcsvf (
const qse_wchar_t* fmt,
va_list ap
);
QSE_EXPORT qse_ssize_t qse_errputmbsf (
const qse_mchar_t* fmt,
...
);
QSE_EXPORT qse_ssize_t qse_errputwcsf (
const qse_wchar_t* fmt,
...
);
QSE_EXPORT qse_ssize_t qse_errputmbsvf (
const qse_mchar_t* fmt,
va_list ap
);
QSE_EXPORT qse_ssize_t qse_errputwcsvf (
const qse_wchar_t* fmt,
va_list ap
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_putstrf qse_putmbsf
# define qse_putstrvf(fmt,ap) qse_putmbsvf(fmt,ap)
# define qse_errputstrf qse_errputmbsf
# define qse_errputstrvf(fmt,ap) qse_errputmbsvf(fmt,ap)
#else
# define qse_putstrf qse_putwcsf
# define qse_putstrvf(fmt,ap) qse_putwcsvf(fmt,ap)
# define qse_errputstrf qse_errputwcsf
# define qse_errputstrvf(fmt,ap) qse_errputwcsvf(fmt,ap)
#endif
/* Some convenience macros */
#define QSE_STDOUT (qse_getstdout())
#define QSE_STDERR (qse_getstderr())
#define qse_printf qse_putstrf
#define qse_vprintf qse_putstrvf
#define qse_fprintf qse_sio_putstrf
#define qse_vfprintf qse_sio_putstrvf
#define qse_fflush qse_sio_flush
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -1,87 +0,0 @@
/*
* $Id$
*
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_CMN_TASK_H_
#define _QSE_CMN_TASK_H_
#include <qse/types.h>
#include <qse/macros.h>
typedef struct qse_task_t qse_task_t;
typedef struct qse_task_slice_t qse_task_slice_t;
typedef qse_task_slice_t* (*qse_task_fnc_t) (
qse_task_t* task,
qse_task_slice_t* slice,
void* ctx
);
#if defined(__cplusplus)
extern "C" {
#endif
QSE_EXPORT qse_task_t* qse_task_open (
qse_mmgr_t* mmgr,
qse_size_t xtnsize
);
QSE_EXPORT void qse_task_close (
qse_task_t* task
);
QSE_EXPORT qse_mmgr_t* qse_task_getmmgr (
qse_task_t* task
);
QSE_EXPORT void* qse_task_getxtn (
qse_task_t* task
);
QSE_EXPORT qse_task_slice_t* qse_task_create (
qse_task_t* task,
qse_task_fnc_t fnc,
void* ctx,
qse_size_t stksize
);
QSE_EXPORT int qse_task_boot (
qse_task_t* task,
qse_task_slice_t* to
);
QSE_EXPORT void qse_task_schedule (
qse_task_t* task,
qse_task_slice_t* from,
qse_task_slice_t* to
);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -121,11 +121,17 @@ struct qse_btime_t
#define qse_inittime(x,s,ns) (((x)->sec = (s)), ((x)->nsec = (ns)))
#define qse_cleartime(x) qse_inittime(x,0,0)
/*#define qse_cleartime(x) ((x)->sec = (x)->nsec = 0)*/
#define qse_cmptime(x,y) \
(((x)->sec == (y)->sec)? ((x)->nsec - (y)->nsec): \
((x)->sec - (y)->sec))
/* if time has been normalized properly, nsec must be equal to or
* greater than 0. */
#define qse_isnegtime(x) ((x)->sec < 0)
#define qse_ispostime(x) ((x)->sec > 0 || ((x)->sec == 0 && (x)->nsec > 0))
#define qse_iszerotime(x) ((x)->sec == 0 && (x)->nsec == 0)
#if defined(__cplusplus)
extern "C" {
#endif

View File

@ -1,324 +0,0 @@
/*
* $Id$
*
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_CMN_TIO_H_
#define _QSE_CMN_TIO_H_
/** @file
* This file provides an interface to a text stream processor.
*/
#include <qse/types.h>
#include <qse/macros.h>
#include <qse/cmn/chr.h>
#include <qse/cmn/str.h>
enum qse_tio_errnum_t
{
QSE_TIO_ENOERR = 0, /**< no error */
QSE_TIO_EOTHER, /**< other error */
QSE_TIO_ENOIMPL, /**< not implmeneted */
QSE_TIO_ESYSERR, /**< subsystem error */
QSE_TIO_EINTERN, /**< internal error */
QSE_TIO_ENOMEM, /**< out of memory */
QSE_TIO_EINVAL, /**< invalid parameter */
QSE_TIO_EACCES, /**< access denied */
QSE_TIO_ENOENT, /**< no such file */
QSE_TIO_ENOSPC, /**< no more space */
QSE_TIO_EILSEQ, /**< illegal sequence */
QSE_TIO_EICSEQ, /**< incomplete sequence */
QSE_TIO_EILCHR, /**< illegal character */
QSE_TIO_ENINPF, /**< no input function attached */
QSE_TIO_ENOUTF /**< no output function attached */
};
typedef enum qse_tio_errnum_t qse_tio_errnum_t;
enum qse_tio_cmd_t
{
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),
/**< do not flush data in the buffer until the buffer gets full. */
QSE_TIO_NOAUTOFLUSH = (1 << 1)
};
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)
typedef struct qse_tio_t qse_tio_t;
/**
* The qse_tio_io_impl_t types define a text I/O handler.
*/
typedef qse_ssize_t (*qse_tio_io_impl_t) (
qse_tio_t* tio,
qse_tio_cmd_t cmd,
void* data,
qse_size_t size
);
struct qse_tio_io_t
{
qse_tio_io_impl_t fun;
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,
* it handles a multi-byte stream converted to a wide character stream.
*/
struct qse_tio_t
{
qse_mmgr_t* mmgr;
qse_tio_errnum_t errnum;
int flags;
qse_cmgr_t* cmgr;
qse_tio_io_t in;
qse_tio_io_t out;
/* for house keeping from here */
int status;
qse_size_t inbuf_cur;
qse_size_t inbuf_len;
qse_size_t outbuf_len;
};
#if defined(__cplusplus)
extern "C" {
#endif
/**
* The qse_tio_open() function creates an text stream processoor.
*/
QSE_EXPORT qse_tio_t* qse_tio_open (
qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t xtnsize, /**< extension size in bytes */
int flags /**< ORed of qse_tio_flag_t enumerators */
);
/**
* The qse_tio_close() function destroys an text stream processor.
*/
QSE_EXPORT int qse_tio_close (
qse_tio_t* tio
);
/**
* The qse_tio_init() function initialize a statically declared
* text stream processor.
*/
QSE_EXPORT int qse_tio_init (
qse_tio_t* tio,
qse_mmgr_t* mmgr,
int flags
);
/**
* The qse_tio_fini() function finalizes a text stream processor
*/
QSE_EXPORT int qse_tio_fini (
qse_tio_t* tio
);
QSE_EXPORT qse_mmgr_t* qse_tio_getmmgr (
qse_tio_t* tio
);
QSE_EXPORT void* qse_tio_getxtn (
qse_tio_t* tio
);
/**
* The qse_tio_geterrnum() function returns the current error code.
*/
QSE_EXPORT qse_tio_errnum_t qse_tio_geterrnum (
const qse_tio_t* tio
);
/**
* The qse_tio_geterrnum() function changes the current error code.
* typically from within the I/O handler attached.
*/
QSE_EXPORT void qse_tio_seterrnum (
qse_tio_t* tio,
qse_tio_errnum_t errnum
);
/**
* The qse_tio_getcmgr() function returns the character manager.
*/
QSE_EXPORT qse_cmgr_t* qse_tio_getcmgr (
qse_tio_t* tio
);
/**
* The qse_tio_setcmgr() function changes the character manager.
*/
QSE_EXPORT void qse_tio_setcmgr (
qse_tio_t* tio,
qse_cmgr_t* cmgr
);
/**
* The qse_tio_attachin() function attachs an input handler .
* @return 0 on success, -1 on failure
*/
QSE_EXPORT int qse_tio_attachin (
qse_tio_t* tio,
qse_tio_io_impl_t input,
qse_mchar_t* bufptr,
qse_size_t bufcapa
);
/**
* The qse_tio_detachin() function detaches an input handler .
* @return 0 on success, -1 on failure
*/
QSE_EXPORT int qse_tio_detachin (
qse_tio_t* tio
);
/**
* The qse_tio_attachout() function attaches an output handler.
* @return 0 on success, -1 on failure
*/
QSE_EXPORT int qse_tio_attachout (
qse_tio_t* tio,
qse_tio_io_impl_t output,
qse_mchar_t* bufptr,
qse_size_t bufcapa
);
/**
* The qse_tio_detachout() function detaches an output handler .
* @return 0 on success, -1 on failure
*/
QSE_EXPORT int qse_tio_detachout (
qse_tio_t* tio
);
/**
* The qse_tio_flush() function flushes the output buffer. It returns the
* number of bytes written on success, -1 on failure.
*/
QSE_EXPORT qse_ssize_t qse_tio_flush (
qse_tio_t* tio
);
/**
* The qse_tio_drain() function empties input and output buffers.
*/
QSE_EXPORT void qse_tio_drain (
qse_tio_t* tio
);
QSE_EXPORT qse_ssize_t qse_tio_readmbs (
qse_tio_t* tio,
qse_mchar_t* buf,
qse_size_t size
);
QSE_EXPORT qse_ssize_t qse_tio_readwcs (
qse_tio_t* tio,
qse_wchar_t* buf,
qse_size_t size
);
/**
* The qse_tio_read() macro is character-type neutral. It maps
* to qse_tio_readmbs() or qse_tio_readwcs().
*/
#ifdef QSE_CHAR_IS_MCHAR
# define qse_tio_read(tio,buf,size) qse_tio_readmbs(tio,buf,size)
#else
# define qse_tio_read(tio,buf,size) qse_tio_readwcs(tio,buf,size)
#endif
/**
* The qse_tio_writembs() function writes the @a size characters
* from a multibyte string @a str. If @a size is (qse_size_t)-1,
* it writes on until a terminating null is found. It doesn't
* write more than QSE_TYPE_MAX(qse_ssize_t) characters.
* @return number of characters written on success, -1 on failure.
*/
QSE_EXPORT qse_ssize_t qse_tio_writembs (
qse_tio_t* tio,
const qse_mchar_t* str,
qse_size_t size
);
/**
* The qse_tio_writembs() function writes the @a size characters
* from a wide-character string @a str. If @a size is (qse_size_t)-1,
* it writes on until a terminating null is found. It doesn't write
* more than QSE_TYPE_MAX(qse_ssize_t) characters.
* @return number of characters written on success, -1 on failure.
*/
QSE_EXPORT qse_ssize_t qse_tio_writewcs (
qse_tio_t* tio,
const qse_wchar_t* str,
qse_size_t size
);
/**
* The qse_tio_write() macro is character-type neutral. It maps
* to qse_tio_writembs() or qse_tio_writewcs().
*/
#ifdef QSE_CHAR_IS_MCHAR
# define qse_tio_write(tio,str,size) qse_tio_writembs(tio,str,size)
#else
# define qse_tio_write(tio,str,size) qse_tio_writewcs(tio,str,size)
#endif
#if defined(__cplusplus)
}
#endif
#endif