From 37344d7e09c9af381b04bae4b2b5816317704833 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 8 Jan 2009 04:26:55 +0000 Subject: [PATCH] interim commit - added wide-to-multibyte charater conversion in pio --- qse/include/qse/cmn/chr.h | 14 ++++++++++++++ qse/include/qse/cmn/dll.h | 14 +++++++++++++- qse/include/qse/cmn/fio.h | 14 ++++++++++++++ qse/include/qse/cmn/io.h | 14 ++++++++++++++ qse/include/qse/cmn/lda.h | 14 +++++++++++++- qse/include/qse/cmn/map.h | 14 +++++++++++++- qse/include/qse/cmn/mem.h | 14 +++++++++++++- qse/include/qse/cmn/opt.h | 14 +++++++++++++- qse/include/qse/cmn/pio.h | 14 ++++++++++++++ qse/include/qse/cmn/rex.h | 14 +++++++++++++- qse/include/qse/cmn/sio.h | 14 ++++++++++++++ qse/include/qse/cmn/sll.h | 14 +++++++++++++- qse/include/qse/cmn/str.h | 14 +++++++++++++- qse/include/qse/cmn/time.h | 14 ++++++++++++++ qse/include/qse/cmn/tio.h | 14 ++++++++++++++ qse/include/qse/lsp/lsp.h | 14 +++++++++++++- qse/lib/cmn/pio.c | 21 +++++++++++++++------ qse/lib/cmn/str_cnv.c | 7 +++++-- qse/test/cmn/pio.c | 4 ++-- 19 files changed, 237 insertions(+), 19 deletions(-) diff --git a/qse/include/qse/cmn/chr.h b/qse/include/qse/cmn/chr.h index 2895f487..9c820070 100644 --- a/qse/include/qse/cmn/chr.h +++ b/qse/include/qse/cmn/chr.h @@ -1,5 +1,19 @@ /* * $Id: ctype.h 223 2008-06-26 06:44:41Z baconevi $ + * + 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. */ #ifndef _QSE_CMN_CHR_H_ diff --git a/qse/include/qse/cmn/dll.h b/qse/include/qse/cmn/dll.h index 2602609b..4df9e88d 100644 --- a/qse/include/qse/cmn/dll.h +++ b/qse/include/qse/cmn/dll.h @@ -1,7 +1,19 @@ /* * $Id: map.h 223 2008-06-26 06:44:41Z 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. */ #ifndef _QSE_CMN_DLL_H_ diff --git a/qse/include/qse/cmn/fio.h b/qse/include/qse/cmn/fio.h index 1e1dd704..d79b1dc4 100644 --- a/qse/include/qse/cmn/fio.h +++ b/qse/include/qse/cmn/fio.h @@ -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. */ #ifndef _QSE_CMN_FIO_H_ diff --git a/qse/include/qse/cmn/io.h b/qse/include/qse/cmn/io.h index 71f522af..e8371a2a 100644 --- a/qse/include/qse/cmn/io.h +++ b/qse/include/qse/cmn/io.h @@ -1,5 +1,19 @@ /* * $Id: sysapi.h,v 1.56 2006/03/21 16:15:16 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. */ #ifndef _QSE_CMN_IO_H_ diff --git a/qse/include/qse/cmn/lda.h b/qse/include/qse/cmn/lda.h index 54c7fa93..bfe4738a 100644 --- a/qse/include/qse/cmn/lda.h +++ b/qse/include/qse/cmn/lda.h @@ -1,7 +1,19 @@ /* * $Id: lda.h 363 2008-09-04 10:58:08Z 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. */ #ifndef _QSE_CMN_LDA_H_ diff --git a/qse/include/qse/cmn/map.h b/qse/include/qse/cmn/map.h index 56ce1796..dfd0a867 100644 --- a/qse/include/qse/cmn/map.h +++ b/qse/include/qse/cmn/map.h @@ -1,7 +1,19 @@ /* * $Id: map.h 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. */ #ifndef _QSE_CMN_MAP_H_ diff --git a/qse/include/qse/cmn/mem.h b/qse/include/qse/cmn/mem.h index e9ef78e0..532cc352 100644 --- a/qse/include/qse/cmn/mem.h +++ b/qse/include/qse/cmn/mem.h @@ -1,7 +1,19 @@ /* * $Id: mem.h 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. */ #ifndef _QSE_CMN_MEM_H_ diff --git a/qse/include/qse/cmn/opt.h b/qse/include/qse/cmn/opt.h index 430d4f20..65a53712 100644 --- a/qse/include/qse/cmn/opt.h +++ b/qse/include/qse/cmn/opt.h @@ -1,7 +1,19 @@ /* * $Id: getopt.h 290 2008-07-27 06:16:54Z 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. */ #ifndef _QSE_CMN_OPT_H_ diff --git a/qse/include/qse/cmn/pio.h b/qse/include/qse/cmn/pio.h index 16cd39d1..ec24e107 100644 --- a/qse/include/qse/cmn/pio.h +++ b/qse/include/qse/cmn/pio.h @@ -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. */ #ifndef _QSE_CMN_PIO_H_ diff --git a/qse/include/qse/cmn/rex.h b/qse/include/qse/cmn/rex.h index 185706f1..bb74c214 100644 --- a/qse/include/qse/cmn/rex.h +++ b/qse/include/qse/cmn/rex.h @@ -1,7 +1,19 @@ /* * $Id: rex.h 223 2008-06-26 06:44:41Z 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. */ #ifndef _QSE_CMN_REX_H_ diff --git a/qse/include/qse/cmn/sio.h b/qse/include/qse/cmn/sio.h index d323e93a..afc04fb8 100644 --- a/qse/include/qse/cmn/sio.h +++ b/qse/include/qse/cmn/sio.h @@ -1,5 +1,19 @@ /* * $Id: sio.h,v 1.29 2005/12/26 05:38:24 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. */ #ifndef _QSE_CMN_SIO_H_ diff --git a/qse/include/qse/cmn/sll.h b/qse/include/qse/cmn/sll.h index 5c3e0ef3..142bf300 100644 --- a/qse/include/qse/cmn/sll.h +++ b/qse/include/qse/cmn/sll.h @@ -1,7 +1,19 @@ /* * $Id: sll.h 223 2008-06-26 06:44:41Z 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. */ #ifndef _QSE_CMN_SLL_H_ diff --git a/qse/include/qse/cmn/str.h b/qse/include/qse/cmn/str.h index 33175511..5447bbf9 100644 --- a/qse/include/qse/cmn/str.h +++ b/qse/include/qse/cmn/str.h @@ -1,7 +1,19 @@ /* * $Id: str.h 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. */ #ifndef _QSE_CMN_STR_H_ diff --git a/qse/include/qse/cmn/time.h b/qse/include/qse/cmn/time.h index cc850d5f..74fc4cac 100644 --- a/qse/include/qse/cmn/time.h +++ b/qse/include/qse/cmn/time.h @@ -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. */ #ifndef _QSE_CMN_TIME_H_ diff --git a/qse/include/qse/cmn/tio.h b/qse/include/qse/cmn/tio.h index e08c8e66..ba9b910c 100644 --- a/qse/include/qse/cmn/tio.h +++ b/qse/include/qse/cmn/tio.h @@ -1,5 +1,19 @@ /* * $Id: tio.h,v 1.19 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. */ #ifndef _QSE_CMN_TIO_H_ diff --git a/qse/include/qse/lsp/lsp.h b/qse/include/qse/lsp/lsp.h index 525009ca..8e5fcc6e 100644 --- a/qse/include/qse/lsp/lsp.h +++ b/qse/include/qse/lsp/lsp.h @@ -1,7 +1,19 @@ /* * $Id: lsp.h 183 2008-06-03 08:18:55Z 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. */ #ifndef _QSE_LSP_LSP_H_ diff --git a/qse/lib/cmn/pio.c b/qse/lib/cmn/pio.c index b0b6444f..5d1c3aa8 100644 --- a/qse/lib/cmn/pio.c +++ b/qse/lib/cmn/pio.c @@ -173,17 +173,26 @@ qse_pio_t* qse_pio_init ( if (flags & QSE_PIO_SHELL) { + const qse_mchar_t* mcmd; + #ifdef QSE_CHAR_IS_MCHAR - const char* mcmd = cmd; + mcmd = cmd; #else qse_size_t n, mn; - const char mcmd[1024]; - mn = QSE_COUNTOF (mcmd); - n = qse_wcstombs (cmd, mcmd, &mn); + n = qse_wcstombslen (cmd, &mn); + if (cmd[n] != QSE_WT('\0')) + { + /* cmd has illegal sequence */ + goto child_oops; + } - if (cmd[n] != QSE_WT('\0')) goto child_oops; - if (mn >= QSE_COUNTOF(mcmd)) goto child_oops; + mn = mn + 1; + mcmd = QSE_MMGR_ALLOC ( + pio->mmgr, mn*QSE_SIZEOF(*mcmd)); + if (mcmd == QSE_NULL) goto child_oops; + + n = qse_wcstombs (cmd, mcmd, &mn); execl ("/bin/sh", "sh", "-c", mcmd, QSE_NULL); } diff --git a/qse/lib/cmn/str_cnv.c b/qse/lib/cmn/str_cnv.c index cc1547d1..2df48abb 100644 --- a/qse/lib/cmn/str_cnv.c +++ b/qse/lib/cmn/str_cnv.c @@ -238,10 +238,13 @@ qse_size_t qse_wcstombslen (const qse_wchar_t* wcs, qse_size_t* mbslen) p++; mlen += n; } + /* this length excludes the terminating null character. */ *mbslen = mlen; - /* returns the number of characters handled. */ - return p - wcs; + /* returns the number of characters handled. + * if the function has encountered an illegal character in + * the while loop above, wcs[p-wcs] will not be a null character */ + return p - wcs; } qse_size_t qse_wcsntombsn ( diff --git a/qse/test/cmn/pio.c b/qse/test/cmn/pio.c index 185c1231..538df4e0 100644 --- a/qse/test/cmn/pio.c +++ b/qse/test/cmn/pio.c @@ -18,7 +18,7 @@ static int test1 (void) QSE_NULL, 0, QSE_T("ls -laF"), - QSE_PIO_READERR|QSE_PIO_WRITEIN|QSE_PIO_ERRTOOUT|QSE_PIO_ERRTONUL | QSE_PIO_INTONUL + QSE_PIO_READOUT|QSE_PIO_WRITEIN|QSE_PIO_SHELL ); if (pio == QSE_NULL) { @@ -33,7 +33,7 @@ static int test1 (void) 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); + qse_ssize_t n = qse_pio_read (pio, buf, sizeof(buf), QSE_PIO_OUT); if (n == 0) break; if (n < 0) {