interim commit while overhauling pio

- added qse_wcstombslen()
This commit is contained in:
hyung-hwan 2009-01-06 04:40:25 +00:00
parent b037bfcaf5
commit e606d9f9e1
23 changed files with 522 additions and 122 deletions

View File

@ -8,54 +8,32 @@
#include <qse/types.h>
#include <qse/macros.h>
#if 0
IN_FROM_NUL /* < /dev/null */
IN_DROP
IN_ACCEPT
IN_KEEP
OUT_TO_NUL /* > /dev/null */
OUT_DROP /* close it.. */
OUT_ACCEPT
OUT_KEEP /* dont do anything */
ERR_TO_NUL
ERR_DROP
ERR_ACCEPT
ERR_KEEP
#endif
enum qse_pio_open_flag_t
{
QSE_PIO_WRITEIN = (1 << 0),
QSE_PIO_READOUT = (1 << 1),
QSE_PIO_READERR = (1 << 2),
QSE_PIO_DROPIN = (1 << 3),
QSE_PIO_DROPOUT = (1 << 4),
QSE_PIO_DROPERR = (1 << 5),
QSE_PIO_ERRTOOUT = (1 << 6),
QSE_PIO_OUTTOERR = (1 << 7),
QSE_PIO_ERRTONUL = (1 << 8),
QSE_PIO_OUTTONUL = (1 << 9),
QSE_PIO_READ = (QSE_PIO_READOUT),
QSE_PIO_WRITE = (QSE_PIO_WRITEIN)
QSE_PIO_ERRTOOUT = (1 << 3),
QSE_PIO_OUTTOERR = (1 << 4),
QSE_PIO_INTONUL = (1 << 5),
QSE_PIO_ERRTONUL = (1 << 6),
QSE_PIO_OUTTONUL = (1 << 7),
QSE_PIO_DROPIN = (1 << 8),
QSE_PIO_DROPOUT = (1 << 9),
QSE_PIO_DROPERR = (1 << 10),
/* invoke the command through a default system shell */
QSE_PIO_SHELL = (1 << 11)
};
enum qse_pio_rw_flag_t
enum qse_pio_hid_t
{
QSE_PIO_IN = (1 << 0),
QSE_PIO_OUT = (1 << 1),
QSE_PIO_ERR = (1 << 2),
QSE_PIO_END = (1 << 8)
};
enum qse_pio_handle_id_t
{
QSE_PIO_HANDLE_IN = 0,
QSE_PIO_HANDLE_OUT = 1,
QSE_PIO_HANDLE_ERR = 2
QSE_PIO_ERR = (1 << 2)
};
#ifdef _WIN32
@ -83,7 +61,7 @@ struct qse_pio_t
extern "C" {
#endif
/****f* qse.pio/qse_pio_open
/****f* qse.cmn.pio/qse_pio_open
* NAME
* qse_pio_open - open a pipe to a child process
*
@ -97,7 +75,7 @@ qse_pio_t* qse_pio_open (
);
/******/
/****f* qse.pio/qse_pio_close
/****f* qse.cmn.pio/qse_pio_close
* NAME
* qse_pio_close - close a pipe
*
@ -119,7 +97,7 @@ void qse_pio_fini (
qse_pio_t* pio
);
/****f* qse.pio/qse_pio_wait
/****f* qse.cmn.pio/qse_pio_wait
* NAME
* qse_pio_wait - wait for a child process
*
@ -130,8 +108,19 @@ int qse_pio_wait (
);
/******/
/****f* qse.cmn.pio/qse_pio_gethandle
* NAME
* qse_pio_gethandle - get system handle
*
* SYNOPSIS
*/
qse_pio_hnd_t qse_pio_gethandle (
qse_pio_t* pio,
int hid
);
/******/
/****f* qse.pio/qse_pio_read
/****f* qse.cmn.pio/qse_pio_read
* NAME
* qse_pio_read - read data
*
@ -141,11 +130,11 @@ qse_ssize_t qse_pio_read (
qse_pio_t* pio,
void* buf,
qse_size_t size,
int flags
int hid
);
/******/
/****f* qse.pio/qse_pio_write
/****f* qse.cmn.pio/qse_pio_write
* NAME
* qse_pio_write - write data
*
@ -159,11 +148,11 @@ qse_ssize_t qse_pio_write (
qse_pio_t* pio,
const void* data,
qse_size_t size,
int flags
int hid
);
/******/
/****f* qse.pio/qse_pio_end
/****f* qse.cmn.pio/qse_pio_end
* NAME
* qse_pio_end
*
@ -171,7 +160,7 @@ qse_ssize_t qse_pio_write (
*/
void qse_pio_end (
qse_pio_t* pio,
int flags
int hid
);
/******/

View File

@ -408,6 +408,28 @@ qse_size_t qse_mbsntowcsn (
);
/******/
/****f* qse.cmn.str/qse_wcstombslen
* NAME
* qse_wcstombslen - get the length
*
* DESCRIPTION
* The qse_wcstombslen() function scans a null-terminated wide character
* string to get the total number of multibyte characters that it can be
* converted to. The resulting number of characters is stored into memory
* pointed to by mbslen.
*
* RETURN
* The qse_wcstombslen() function returns the number of wide characters
* handled.
*
* SYNOPSIS
*/
qse_size_t qse_wcstombslen (
const qse_wchar_t* wcs,
qse_size_t* mbslen
);
/******/
/****f* qse.cmn.str/qse_wcstombs
* NAME
* qse_wcstombs - convert a wide character string to a multibyte string.

View File

@ -1,7 +1,19 @@
/*
* $Id: ctype.c 132 2008-03-17 10:27:02Z baconevi $
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/chr.h>

View File

@ -1,5 +1,19 @@
/*
* $Id$
*
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/chr.h>

View File

@ -1,7 +1,19 @@
/*
* $Id$
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/dll.h>

View File

@ -1,5 +1,19 @@
/*
* $Id: fio.c,v 1.23 2006/06/30 04:18:47 bacon Exp $
*
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/fio.h>

View File

@ -1,7 +1,19 @@
/*
* $Id: lda.c 337 2008-08-20 09:17:25Z baconevi $
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/lda.h>

View File

@ -1,7 +1,19 @@
/*
* $Id: map.c 496 2008-12-15 09:56:48Z baconevi $
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/map.h>

View File

@ -1,7 +1,19 @@
/*
* $Id: mem.c 335 2008-08-20 08:22:07Z baconevi $
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/mem.h>

View File

@ -1,7 +1,19 @@
/*
* $Id: misc.c 191 2008-06-06 10:19:57Z baconevi $
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if defined(__BORLANDC__)

View File

@ -1,7 +1,19 @@
/*
* $Id: getopt.c 313 2008-08-03 14:06:43Z baconevi $
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/opt.h>

View File

@ -1,5 +1,19 @@
/*
* $Id: pio.c,v 1.23 2006/06/30 04:18:47 bacon Exp $
*
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/pio.h>
@ -10,13 +24,10 @@
#include <tchar.h>
#else
#include "syscall.h"
#include <fcntl.h>
#include <errno.h>
#endif
#define HNDIN(pio) ((pio)->handle[QSE_PIO_HANDLE_IN])
#define HNDOUT(pio) ((pio)->handle[QSE_PIO_HANDLE_OUT])
#define HNDERR(pio) ((pio)->handle[QSE_PIO_HANDLE_ERR])
qse_pio_t* qse_pio_open (
qse_mmgr_t* mmgr, qse_size_t ext,
const qse_char_t* path, int flags)
@ -53,8 +64,7 @@ void qse_pio_close (qse_pio_t* pio)
qse_pio_t* qse_pio_init (
qse_pio_t* pio, qse_mmgr_t* mmgr,
const qse_char_t* path, int flags)
qse_pio_t* pio, qse_mmgr_t* mmgr, const qse_char_t* cmd, int flags)
{
qse_pio_pid_t pid;
qse_pio_hnd_t handle[6] = { -1, -1, -1, -1, -1, -1 };
@ -96,6 +106,7 @@ qse_pio_t* qse_pio_init (
if (pid == 0)
{
/* child */
qse_pio_hnd_t devnull;
if (flags & QSE_PIO_WRITEIN)
{
@ -133,14 +144,58 @@ qse_pio_t* qse_pio_init (
QSE_CLOSE (handle[5]);
}
if ((flags & QSE_PIO_INTONUL) ||
(flags & QSE_PIO_OUTTONUL) ||
(flags & QSE_PIO_ERRTONUL))
{
#ifdef O_LARGEFILE
devnull = QSE_OPEN ("/dev/null", O_RDWR|O_LARGEFILE, 0);
#else
devnull = QSE_OPEN ("/dev/null", O_RDWR, 0);
#endif
if (devnull == -1) goto oops;
}
/* TODO: ... */
//execl ("/bin/sh", "sh", "-c", "cat", QSE_NULL);
execl ("/bin/sh", "sh", "-c", "cat -aksksks", QSE_NULL);
if ((flags & QSE_PIO_INTONUL) &&
QSE_DUP2(devnull,0) == -1) goto child_oops;
if ((flags & QSE_PIO_OUTTONUL) &&
QSE_DUP2(devnull,1) == -1) goto child_oops;
if ((flags & QSE_PIO_ERRTONUL) &&
QSE_DUP2(devnull,2) == -1) goto child_oops;
if ((flags & QSE_PIO_INTONUL) ||
(flags & QSE_PIO_OUTTONUL) ||
(flags & QSE_PIO_ERRTONUL)) QSE_CLOSE (devnull);
if (flags & QSE_PIO_DROPIN) QSE_CLOSE(0);
if (flags & QSE_PIO_DROPOUT) QSE_CLOSE(1);
if (flags & QSE_PIO_DROPERR) QSE_CLOSE(2);
if (flags & QSE_PIO_SHELL)
{
#ifdef QSE_CHAR_IS_MCHAR
const char* mcmd = cmd;
#else
qse_size_t n, mn;
const char mcmd[1024];
mn = QSE_COUNTOF (mcmd);
n = qse_wcstombs (cmd, mcmd, &mn);
if (cmd[n] != QSE_WT('\0')) goto child_oops;
if (mn >= QSE_COUNTOF(mcmd)) goto child_oops;
execl ("/bin/sh", "sh", "-c", mcmd, QSE_NULL);
}
else
{
/* TODO: need to parse the command in a simple manner */
}
child_oops:
QSE_EXIT(127);
}
#endif
/* parent */
pio->child = pid;
@ -180,14 +235,10 @@ qse_pio_t* qse_pio_init (
#endif
HNDIN(pio) = handle[1];
HNDOUT(pio) = handle[2];
HNDERR(pio) = handle[4];
pio->handle[QSE_PIO_IN] = handle[1];
pio->handle[QSE_PIO_OUT] = handle[2];
pio->handle[QSE_PIO_ERR] = handle[4];
for (i = minidx; i < maxidx; i++)
{
qse_printf (QSE_T("%d ==> %d\n"), i, handle[i]);
}
return pio;
oops:
@ -202,17 +253,9 @@ void qse_pio_fini (qse_pio_t* pio)
#else
int i, status;
if (HNDOUT(pio) != -1)
{
QSE_CLOSE (HNDOUT(pio));
HNDOUT(pio) = -1;
}
if (HNDIN(pio) != -1)
{
QSE_CLOSE (HNDIN(pio));
HNDIN(pio) = -1;
}
qse_pio_end (pio, QSE_PIO_IN);
qse_pio_end (pio, QSE_PIO_OUT);
qse_pio_end (pio, QSE_PIO_ERR);
while (QSE_WAITPID (pio->child, &status, 0) == -1)
{
@ -245,15 +288,13 @@ int qse_pio_wait (qse_pio_t* pio)
return -1;
}
/*
qse_pio_hnd_t qse_pio_gethandle (qse_pio_t* pio, int readorwrite)
qse_pio_hnd_t qse_pio_gethandle (qse_pio_t* pio, int hid)
{
return handle[xxx];
return pio->handle[hid];
}
*/
qse_ssize_t qse_pio_read (
qse_pio_t* pio, void* buf, qse_size_t size, int flags)
qse_pio_t* pio, void* buf, qse_size_t size, int hid)
{
#ifdef _WIN32
DWORD count;
@ -261,25 +302,19 @@ qse_ssize_t qse_pio_read (
if (ReadFile(pio->handle, buf, size, &count, QSE_NULL) == FALSE) return -1;
return (qse_ssize_t)count;
#else
qse_pio_hnd_t handle = -1;
if (flags == 0) flags = QSE_PIO_OUT;
if (flags & QSE_PIO_ERR) handle = HNDERR(pio);
if (flags & QSE_PIO_OUT) handle = HNDOUT(pio);
if (handle == -1)
if (pio->handle[hid] == -1)
{
/* the stream is already closed */
return (qse_ssize_t)-1;
}
if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t);
return QSE_READ (handle, buf, size);
return QSE_READ (pio->handle[hid], buf, size);
#endif
}
qse_ssize_t qse_pio_write (
qse_pio_t* pio, const void* data, qse_size_t size, int flags)
qse_pio_t* pio, const void* data, qse_size_t size, int hid)
{
#ifdef _WIN32
DWORD count;
@ -287,37 +322,22 @@ qse_ssize_t qse_pio_write (
if (WriteFile(pio->handle, data, size, &count, QSE_NULL) == FALSE) return -1;
return (qse_ssize_t)count;
#else
qse_pio_hnd_t handle;
if (flags == 0) flags = QSE_PIO_IN;
if (flags & QSE_PIO_IN) handle = HNDIN(pio);
if (handle == -1)
if (pio->handle[hid] == -1)
{
/* the stream is already closed */
return (qse_ssize_t)-1;
}
if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t);
return QSE_WRITE (handle, data, size);
return QSE_WRITE (pio->handle[hid], data, size);
#endif
}
void qse_pio_end (qse_pio_t* pio, int flags)
void qse_pio_end (qse_pio_t* pio, int hid)
{
if ((flags & QSE_PIO_IN) && HNDIN(pio) != -1)
if (pio->handle[hid] != -1)
{
QSE_CLOSE (HNDIN(pio));
HNDIN(pio) = -1;
}
if ((flags & QSE_PIO_ERR) && HNDERR(pio) != -1)
{
QSE_CLOSE (HNDERR(pio));
HNDERR(pio) = -1;
}
if ((flags & QSE_PIO_OUT) && HNDOUT(pio) != -1)
{
QSE_CLOSE (HNDOUT(pio));
HNDOUT(pio) = -1;
QSE_CLOSE (pio->handle[hid]);
pio->handle[hid] = -1;
}
}

View File

@ -1,7 +1,19 @@
/*
* $Id: rex.c 470 2008-12-11 13:43:05Z baconevi $
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/rex.h>

View File

@ -1,5 +1,19 @@
/*
* $Id: sio.c,v 1.30 2006/01/15 06:51:35 bacon Ease $
*
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/sio.h>

View File

@ -1,7 +1,19 @@
/*
* $Id$
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/sll.h>

View File

@ -1,7 +1,19 @@
/*
* $Id: str_bas.c 376 2008-09-24 07:18:50Z baconevi $
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/str.h>

View File

@ -1,7 +1,19 @@
/*
* $Id: str_cnv.c 455 2008-11-26 09:05:00Z baconevi $
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/str.h>
@ -203,7 +215,30 @@ qse_size_t qse_wcstombs (
*mbslen -= rem;
/* null-terminate the multibyte sequence if it has sufficient space */
if (rem > 0) *mbs = '\0';
if (rem > 0) *mbs = QSE_MT('\0');
/* returns the number of characters handled. */
return p - wcs;
}
qse_size_t qse_wcstombslen (const qse_wchar_t* wcs, qse_size_t* mbslen)
{
const qse_wchar_t* p = wcs;
qse_mchar_t mbs[128];
qse_size_t mlen = 0;
while (*p != QSE_WT('\0'))
{
qse_size_t n = qse_wctomb (*p, mbs, QSE_COUNTOF(mbs));
if (n == 0) break; /* illegal character */
/* it assumes that mbs is large enough to hold a character */
QSE_ASSERT (n <= QSE_COUNTOF(mbs));
p++; mlen += n;
}
*mbslen = mlen;
/* returns the number of characters handled. */
return p - wcs;
@ -243,7 +278,13 @@ int qse_wcstombs_strict (
qse_size_t mn = mbslen;
n = qse_wcstombs (wcs, mbs, &mn);
if (wcs[n] != QSE_WT('\0')) return -1; /* didn't process all */
if (wcs[n] != QSE_WT('\0'))
{
/* if qse_wcstombs() processed all wide characters,
* the character at position 'n' should be a null character
* as 'n' is the number of wide characters processed. */
return -1;
}
if (mn >= mbslen)
{
/* mbs not big enough to be null-terminated.

View File

@ -1,7 +1,19 @@
/*
* $Id: str_dyn.c 496 2008-12-15 09:56:48Z baconevi $
*
* {License}
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/str.h>

View File

@ -1,5 +1,19 @@
/*
* $Id$
*
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/time.h>

View File

@ -1,5 +1,19 @@
/*
* $Id: tio.c,v 1.13 2006/01/01 13:50:24 bacon Exp $
*
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/tio.h>

View File

@ -1,5 +1,19 @@
/*
* $Id: tio_get.c,v 1.8 2005/12/26 07:41:48 bacon Exp $
*
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/tio.h>

View File

@ -1,5 +1,19 @@
/*
* $Id: tio_put.c,v 1.2 2005/12/26 07:41:48 bacon Exp $
*
Copyright 2006-2008 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <qse/cmn/tio.h>

98
qse/test/cmn/pio.c Normal file
View File

@ -0,0 +1,98 @@
#include <qse/cmn/pio.h>
#include <qse/utl/stdio.h>
#include <string.h>
#include <locale.h>
#define R(f) \
do { \
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
if (f() == -1) return -1; \
} while (0)
static int test1 (void)
{
qse_pio_t* pio;
pio = qse_pio_open (
QSE_NULL,
0,
QSE_T("ls -laF"),
QSE_PIO_READERR|QSE_PIO_WRITEIN|QSE_PIO_ERRTOOUT|QSE_PIO_ERRTONUL | QSE_PIO_INTONUL
);
if (pio == QSE_NULL)
{
qse_printf (QSE_T("cannot open program through pipe\n"));
return -1;
}
qse_pio_write (pio, "xxxxxxxxxxxx\n", 13, QSE_PIO_IN);
qse_pio_write (pio, QSE_NULL, 0, QSE_PIO_IN);
while (1)
{
qse_byte_t buf[128];
/*qse_pio_canread (pio, QSE_PIO_ERR, 1000)*/
qse_ssize_t n = qse_pio_read (pio, buf, sizeof(buf), QSE_PIO_ERR);
if (n == 0) break;
if (n < 0)
{
qse_printf (QSE_T("qse_pio_read() returned error\n"));
break;
}
#ifdef QSE_CHAR_IS_MCHAR
qse_printf (QSE_T("buf => [%.*s]\n"), (int)n. buf);
#else
qse_printf (QSE_T("buf => [%.*S]\n"), (int)n, buf);
#endif
}
qse_pio_close (pio);
return 0;
}
#if 0
static int test1 (void)
{
qse_pio_t* pio;
pio = qse_pio_open (
QSE_NULL,
0,
QSE_T("ls -laF"),
QSE_PIO_READ | QSE_PIO_WRITE | QSE_PIO_READ_ERR
);
if (pio == QSE_NULL)
{
qse_printf (QSE_T("cannot open program through pipe\n"));
return -1;
}
qse_pio_open (RW, "/bin/ls -laF", R, W, E)
qse_pio_write ("xxx");
qse_pio_read (buf, QSE_COUNOF(buf), QSE_PIO_OUT);
qse_pio_read (buf, QSE_COUNOF(buf), QSE_PIO_ERR);
qse_pio_write ("xxxx", 4, QSE_PIO_IN | QSE_PIO_EOF);
qse_pio_close (pio);
return 0;
}
#endif
int main ()
{
setlocale (LC_ALL, "");
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n"));
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
R (test1);
return 0;
}