* Added code to handle the case when QSE_PIO_SHELL is not set in qse_pio_init() for OS/2.

* Added qse_mbschr(), qse_wcschr(), qse_mbsstr(), and qse_wcsstr()
This commit is contained in:
hyung-hwan 2011-03-22 08:01:10 +00:00
parent 98eaacce41
commit fe67761da6
4 changed files with 172 additions and 85 deletions

View File

@ -224,8 +224,12 @@ int scm_main (int argc, qse_char_t* argv[])
qse_scm_attachio (scm, &io);
}
{
pio1 (QSE_T("pstat"), QSE_PIO_READOUT|QSE_PIO_WRITEIN|QSE_PIO_SHELL|QSE_PIO_DROPERR, QSE_PIO_OUT);
int i;
for (i = 0; i<200; i++)
pio1 (QSE_T("pstat.exe /c"), QSE_PIO_READOUT|QSE_PIO_WRITEIN|/*QSE_PIO_SHELL|*/QSE_PIO_DROPERR, QSE_PIO_OUT);
}
{

View File

@ -1,5 +1,5 @@
/*
* $Id: str.h 404 2011-03-20 14:16:54Z hyunghwan.chung $
* $Id: str.h 405 2011-03-21 14:01:10Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -136,13 +136,29 @@ extern "C" {
*/
/**
* The qse_strlen() function returns the number of characters in a
* null-terminated string. The length returned excludes a terminating null.
* The qse_mbslen() function returns the number of characters in a
* multibyte null-terminated string. The length returned excludes a
* terminating null.
*/
qse_size_t qse_strlen (
const qse_char_t* str
qse_size_t qse_mbslen (
const qse_mchar_t* mbs
);
/**
* The qse_wcslen() function returns the number of characters in a
* wide-character null-terminated string. The length returned excludes
* a terminating null.
*/
qse_size_t qse_wcslen (
const qse_wchar_t* wcs
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strlen(str) qse_mbslen(str)
#else
# define qse_strlen(str) qse_wcslen(str)
#endif
/**
* The qse_strbytes() function returns the number of bytes a null-terminated
* string is holding excluding a terminating null.
@ -151,19 +167,6 @@ qse_size_t qse_strbytes (
const qse_char_t* str
);
qse_size_t qse_mbslen (
const qse_mchar_t* mbs
);
qse_size_t qse_wcslen (
const qse_wchar_t* wcs
);
qse_size_t qse_strcpy (
qse_char_t* buf,
const qse_char_t* str
);
qse_size_t qse_mbscpy (
qse_mchar_t* buf,
const qse_mchar_t* str
@ -174,6 +177,12 @@ qse_size_t qse_wcscpy (
const qse_wchar_t* str
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strcpy(buf,str) qse_mbscpy(buf,str)
#else
# define qse_strcpy(buf,str) qse_wcscpy(buf,str)
#endif
qse_size_t qse_strxcpy (
qse_char_t* buf,
qse_size_t bsz,
@ -401,16 +410,33 @@ qse_char_t* qse_strxdup2 (
);
/**
* The qse_strstr() function searchs a string @a str for the first occurrence
* The qse_mbsstr() function searchs a string @a str for the first occurrence
* of a substring @a sub.
* @return pointer to the first occurrence in @a str if @a sub is found,
* QSE_NULL if not.
*/
qse_char_t* qse_strstr (
const qse_char_t* str,
const qse_char_t* sub
qse_mchar_t* qse_mbsstr (
const qse_mchar_t* str,
const qse_mchar_t* sub
);
/**
* The qse_wcsstr() function searchs a string @a str for the first occurrence
* of a substring @a sub.
* @return pointer to the first occurrence in @a str if @a sub is found,
* QSE_NULL if not.
*/
qse_wchar_t* qse_wcsstr (
const qse_wchar_t* str,
const qse_wchar_t* sub
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strstr(str,sub) qse_mbsstr(str,sub)
#else
# define qse_strstr(str,sub) qse_wcsstr(str,,sub)
#endif
qse_char_t* qse_strxstr (
const qse_char_t* str,
qse_size_t size,
@ -466,11 +492,22 @@ qse_char_t* qse_strxnrstr (
qse_size_t subsz
);
qse_char_t* qse_strchr (
const qse_char_t* str,
qse_cint_t c
qse_mchar_t* qse_mbschr (
const qse_mchar_t* str,
qse_mcint_t c
);
qse_wchar_t* qse_wcschr (
const qse_wchar_t* str,
qse_wcint_t c
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strchr(str,c) qse_mbschr(str,c)
#else
# define qse_strchr(str,c) qse_wcschr(str,c)
#endif
qse_char_t* qse_strxchr (
const qse_char_t* str,
qse_size_t len,

View File

@ -1,5 +1,5 @@
/*
* $Id: pio.c 404 2011-03-20 14:16:54Z hyunghwan.chung $
* $Id: pio.c 405 2011-03-21 14:01:10Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -294,14 +294,12 @@ qse_pio_t* qse_pio_init (
#elif defined(__OS2__)
#define DOS_DUP_HANDLE(x,y) QSE_BLOCK ( \
if (DosDupHandle(x,y) != NO_ERROR) goto oops; \
)
#define DOS_DUP_HANDLE(x,y) QSE_BLOCK ( \
if (DosDupHandle(x,y) != NO_ERROR) goto oops; \
)
if (oflags & QSE_PIO_WRITEIN)
{
ULONG state;
/* child reads, parent writes */
if (DosCreatePipe (
&handle[0], &handle[1], pipe_size) != NO_ERROR) goto oops;
@ -311,6 +309,7 @@ qse_pio_t* qse_pio_init (
if (DosSetFHState (handle[1], OPEN_FLAGS_NOINHERIT) != NO_ERROR) goto oops;
/* Need to do somthing like this to set the flag instead?
ULONG state;
DosQueryFHState (handle[1], &state);
DosSetFHState (handle[1], state | OPEN_FLAGS_NOINHERIT); */
@ -319,8 +318,6 @@ qse_pio_t* qse_pio_init (
if (oflags & QSE_PIO_READOUT)
{
ULONG state;
/* child writes, parent reads */
if (DosCreatePipe (
&handle[2], &handle[3], pipe_size) != NO_ERROR) goto oops;
@ -335,8 +332,6 @@ qse_pio_t* qse_pio_init (
if (oflags & QSE_PIO_READERR)
{
ULONG state;
/* child writes, parent reads */
if (DosCreatePipe (
&handle[4], &handle[5], pipe_size) != NO_ERROR) goto oops;
@ -444,9 +439,8 @@ qse_pio_t* qse_pio_init (
if (oflags & QSE_PIO_DROPIN) DosClose (std_in);
if (oflags & QSE_PIO_DROPOUT) DosClose (std_out);
if (oflags & QSE_PIO_DROPERR) DosClose (std_err);
#if 0
if (oflags & QSE_PIO_SHELL)
#endif
{
qse_size_t n, mn;
@ -472,17 +466,39 @@ qse_pio_t* qse_pio_init (
cmd_file = QSE_MT("cmd.exe");
}
#if 0
else
{
qse_mchar_t* mptr;
#ifdef QSE_CHAR_IS_MCHAR
#else
cmd_line = qse_strdup (cmd, mmgr);
qse_size_t mn = qse_strlen(cmd);
cmd_line = qse_strdup2 (cmd, QSE_T(" "), pio->mmgr);
if (cmd_line == QSE_NULL) goto oops;
#else
qse_size_t n, mn;
n = qse_wcstombslen (cmd, &mn);
if (cmd[n] != QSE_T('\0')) goto oops; /* illegal sequence in cmd */
mn = mn + 1;
cmd_line = QSE_MMGR_ALLOC (pio->mmgr, mn * QSE_SIZEOF(qse_char_t));
if (cmd_line == QSE_NULL) goto oops;
qse_wcstombs (cmd, cmd_line, &mn);
#endif
cmd_file...
/* TODO: enhance this part by:
* supporting file names containing whitespaces.
* detecting the end of the file name better.
* doing better parsing of the command line.
*/
/* NOTE: you must separate the command name and the parameters with
* a space. "pstat.exe /c" is ok while "pstat.exe/c" is not. */
mptr = qse_mbschr (cmd_line, QSE_MT(' '));
if (mptr) *mptr = QSE_MT('\0');
cmd_line[mn+1] = QSE_MT('\0'); /* the second '\0' at the end */
cmd_file = cmd_line;
}
#endif
/* execute the command line */
rc = DosExecPgm (
@ -682,6 +698,7 @@ qse_pio_t* qse_pio_init (
goto child_oops;
}
/* calculate the length of the string after splitting */
for (wl = 0, n = fcnt; n > 0; )
{
if (wcmd[wl++] == QSE_T('\0')) n--;
@ -691,6 +708,8 @@ qse_pio_t* qse_pio_init (
if (n != wl) goto child_oops;
}
/* prepare to reserve 1 more slot for the terminating '\0'
* by incrementing mn by 1. */
mn = mn + 1;
if (mn <= QSE_COUNTOF(buf))

View File

@ -1,5 +1,5 @@
/*
* $Id: str_bas.c 404 2011-03-20 14:16:54Z hyunghwan.chung $
* $Id: str_bas.c 405 2011-03-21 14:01:10Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -22,11 +22,18 @@
#include <qse/cmn/chr.h>
#include "mem.h"
qse_size_t qse_strlen (const qse_char_t* str)
qse_size_t qse_mbslen (const qse_mchar_t* mbs)
{
const qse_char_t* p = str;
while (*p != QSE_T('\0')) p++;
return p - str;
const qse_mchar_t* p = mbs;
while (*p != QSE_MT('\0')) p++;
return p - mbs;
}
qse_size_t qse_wcslen (const qse_wchar_t* wcs)
{
const qse_wchar_t* p = wcs;
while (*p != QSE_WT('\0')) p++;
return p - wcs;
}
qse_size_t qse_strbytes (const qse_char_t* str)
@ -36,27 +43,6 @@ qse_size_t qse_strbytes (const qse_char_t* str)
return (p - str) * QSE_SIZEOF(qse_char_t);
}
qse_size_t qse_mbslen (const qse_mchar_t* mbs)
{
const qse_mchar_t* p = mbs;
while (*p != QSE_T('\0')) p++;
return p - mbs;
}
qse_size_t qse_wcslen (const qse_wchar_t* wcs)
{
const qse_wchar_t* p = wcs;
while (*p != QSE_T('\0')) p++;
return p - wcs;
}
qse_size_t qse_strcpy (qse_char_t* buf, const qse_char_t* str)
{
qse_char_t* org = buf;
while ((*buf++ = *str++) != QSE_T('\0'));
return buf - org - 1;
}
qse_size_t qse_mbscpy (qse_mchar_t* buf, const qse_mchar_t* str)
{
qse_mchar_t* org = buf;
@ -645,14 +631,14 @@ qse_char_t* qse_strxdup2 (
return tmp;
}
qse_char_t* qse_strstr (const qse_char_t* str, const qse_char_t* sub)
qse_mchar_t* qse_mbsstr (const qse_mchar_t* str, const qse_mchar_t* sub)
{
const qse_char_t* x, * y;
const qse_mchar_t* x, * y;
y = sub;
if (*y == QSE_T('\0')) return (qse_char_t*)str;
if (*y == QSE_MT('\0')) return (qse_mchar_t*)str;
while (*str != QSE_T('\0'))
while (*str != QSE_MT('\0'))
{
if (*str != *y)
{
@ -661,11 +647,42 @@ qse_char_t* qse_strstr (const qse_char_t* str, const qse_char_t* sub)
}
x = str;
while (1)
do
{
if (*y == QSE_T('\0')) return (qse_char_t*)str;
if (*y == QSE_MT('\0')) return (qse_mchar_t*)str;
if (*x++ != *y++) break;
}
while (1);
y = sub;
str++;
}
return QSE_NULL;
}
qse_wchar_t* qse_wcsstr (const qse_wchar_t* str, const qse_wchar_t* sub)
{
const qse_wchar_t* x, * y;
y = sub;
if (*y == QSE_WT('\0')) return (qse_wchar_t*)str;
while (*str != QSE_WT('\0'))
{
if (*str != *y)
{
str++;
continue;
}
x = str;
do
{
if (*y == QSE_WT('\0')) return (qse_wchar_t*)str;
if (*x++ != *y++) break;
}
while (1);
y = sub;
str++;
@ -817,11 +834,21 @@ qse_char_t* qse_strxnrstr (
return QSE_NULL;
}
qse_char_t* qse_strchr (const qse_char_t* str, qse_cint_t c)
qse_mchar_t* qse_mbschr (const qse_mchar_t* str, qse_mcint_t c)
{
while (*str != QSE_T('\0'))
while (*str != QSE_MT('\0'))
{
if (*str == c) return (qse_char_t*)str;
if (*str == c) return (qse_mchar_t*)str;
str++;
}
return QSE_NULL;
}
qse_wchar_t* qse_wcschr (const qse_wchar_t* str, qse_wcint_t c)
{
while (*str != QSE_WT('\0'))
{
if (*str == c) return (qse_wchar_t*)str;
str++;
}
return QSE_NULL;