* 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:
		| @ -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; | ||||
| @ -310,7 +308,8 @@ qse_pio_t* qse_pio_init ( | ||||
| 		 * handle[0] inherited. set the flag not to inherit handle[1]. */ | ||||
| 		if (DosSetFHState (handle[1], OPEN_FLAGS_NOINHERIT) != NO_ERROR) goto oops; | ||||
|  | ||||
| 		/* Need to do somthing like this to set the flag instead?  | ||||
| 		/* 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 | ||||
| 	{ | ||||
| 	#ifdef QSE_CHAR_IS_MCHAR | ||||
| 	#else    | ||||
| 		cmd_line = qse_strdup (cmd, mmgr); | ||||
| 	{ | ||||
| 		qse_mchar_t* mptr; | ||||
|  | ||||
| 	#ifdef QSE_CHAR_IS_MCHAR | ||||
| 		qse_size_t mn = qse_strlen(cmd); | ||||
| 		cmd_line = qse_strdup2 (cmd, QSE_T(" "), pio->mmgr); | ||||
| 		if (cmd_line == QSE_NULL) goto oops; | ||||
| 	#endif | ||||
| 		cmd_file... | ||||
| 	#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 | ||||
|  | ||||
| 		/* 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 ( | ||||
| @ -681,7 +697,8 @@ qse_pio_t* qse_pio_init ( | ||||
| 				/* no field or an error */ | ||||
| 				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--; | ||||
| @ -690,7 +707,9 @@ qse_pio_t* qse_pio_init ( | ||||
| 			n = qse_wcsntombsnlen (wcmd, wl, &mn); | ||||
| 			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))  | ||||
|  | ||||
| @ -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; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user