diff --git a/qse/include/qse/cmn/str.h b/qse/include/qse/cmn/str.h index f8daece3..a2fc1c12 100644 --- a/qse/include/qse/cmn/str.h +++ b/qse/include/qse/cmn/str.h @@ -1,5 +1,5 @@ /* - * $Id: str.h 408 2011-03-23 02:45:39Z hyunghwan.chung $ + * $Id: str.h 410 2011-03-23 15:07:24Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -167,6 +167,7 @@ qse_size_t qse_strbytes ( const qse_char_t* str ); + qse_size_t qse_mbscpy ( qse_mchar_t* buf, const qse_mchar_t* str @@ -177,39 +178,72 @@ 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_mbsxcpy ( + qse_mchar_t* buf, + qse_size_t bsz, + const qse_mchar_t* str +); -qse_size_t qse_strxcpy ( - qse_char_t* buf, - qse_size_t bsz, - const qse_char_t* str +qse_size_t qse_wcsxcpy ( + qse_wchar_t* buf, + qse_size_t bsz, + const qse_wchar_t* str ); /** - * The qse_strycpy() function copies a length-bounded string into + * The qse_mbsncpy() function copies a length-bounded string into * a buffer with unknown size. */ -qse_size_t qse_strncpy ( - qse_char_t* buf, /**< buffer with unknown length */ - const qse_char_t* str, /**< length-bounded string */ - qse_size_t len /**< string length */ +qse_size_t qse_mbsncpy ( + qse_mchar_t* buf, /**< buffer with unknown length */ + const qse_mchar_t* str, /**< length-bounded string */ + qse_size_t len /**< string length */ ); /** - * The qse_strycpy() function copies a length-bounded string into + * The qse_wcsncpy() function copies a length-bounded string into + * a buffer with unknown size. + */ +qse_size_t qse_wcsncpy ( + qse_wchar_t* buf, /**< buffer with unknown length */ + const qse_wchar_t* str, /**< length-bounded string */ + qse_size_t len /**< string length */ +); + +/** + * The qse_mbsxncpy() function copies a length-bounded string into * a length-bounded buffer. */ -qse_size_t qse_strxncpy ( - qse_char_t* buf, /**< length-bounded buffer */ - qse_size_t bsz, /**< buffer length */ - const qse_char_t* str, /**< length-bounded string */ - qse_size_t len /**< string length */ +qse_size_t qse_mbsxncpy ( + qse_mchar_t* buf, /**< length-bounded buffer */ + qse_size_t bsz, /**< buffer length */ + const qse_mchar_t* str, /**< length-bounded string */ + qse_size_t len /**< string length */ ); +/** + * The qse_wcsxncpy() function copies a length-bounded string into + * a length-bounded buffer. + */ +qse_size_t qse_wcsxncpy ( + qse_wchar_t* buf, /**< length-bounded buffer */ + qse_size_t bsz, /**< buffer length */ + const qse_wchar_t* str, /**< length-bounded string */ + qse_size_t len /**< string length */ +); + +#ifdef QSE_CHAR_IS_MCHAR +# define qse_strcpy(buf,str) qse_mbscpy(buf,str) +# define qse_strxcpy(buf,bsz,str) qse_mbsxcpy(buf,bsz,str) +# define qse_strncpy(buf,str,len) qse_mbsncpy(buf,str,len) +# define qse_strxncpy(buf,bsz,str,len) qse_mbsxncpy(buf,bsz,str,len) +#else +# define qse_strcpy(buf,str) qse_wcscpy(buf,str) +# define qse_strxcpy(buf,bsz,str) qse_wcsxcpy(buf,bsz,str) +# define qse_strncpy(buf,str,len) qse_wcsncpy(buf,str,len) +# define qse_strxncpy(buf,bsz,str,len) qse_wcsxncpy(buf,bsz,str,len) +#endif + /** * The qse_strxput() function copies the string @a str into the buffer @a buf * of the size @a bsz. Unlike qse_strxcpy(), it does not null-terminate the diff --git a/qse/lib/cmn/Makefile.am b/qse/lib/cmn/Makefile.am index a14303ea..1882bb29 100644 --- a/qse/lib/cmn/Makefile.am +++ b/qse/lib/cmn/Makefile.am @@ -9,7 +9,7 @@ lib_LTLIBRARIES = libqsecmn.la libqsecmn_la_SOURCES = \ syscall.h mem.h \ mem.c xma.c fma.c chr.c chr_cnv.c rex.c \ - str_bas.c str_cnv.c str_dyn.c str_pbrk.c str_spn.c str_utl.c \ + str_bas.c str_cnv.c str_cpy.c str_dyn.c str_pbrk.c str_spn.c str_utl.c \ lda.c oht.c htb.c rbt.c sll.c gdl.c dll.c opt.c \ tio.c tio_get.c tio_put.c \ fio.c pio.c sio.c \ diff --git a/qse/lib/cmn/Makefile.in b/qse/lib/cmn/Makefile.in index 44bf278c..73e8d103 100644 --- a/qse/lib/cmn/Makefile.in +++ b/qse/lib/cmn/Makefile.in @@ -265,7 +265,7 @@ lib_LTLIBRARIES = libqsecmn.la $(am__append_1) libqsecmn_la_SOURCES = \ syscall.h mem.h \ mem.c xma.c fma.c chr.c chr_cnv.c rex.c \ - str_bas.c str_cnv.c str_dyn.c str_pbrk.c str_spn.c str_utl.c \ + str_bas.c str_cnv.c str_cpy.c str_dyn.c str_pbrk.c str_spn.c str_utl.c \ lda.c oht.c htb.c rbt.c sll.c gdl.c dll.c opt.c \ tio.c tio_get.c tio_put.c \ fio.c pio.c sio.c \ diff --git a/qse/lib/cmn/pio.c b/qse/lib/cmn/pio.c index 3b734824..0a4360d1 100644 --- a/qse/lib/cmn/pio.c +++ b/qse/lib/cmn/pio.c @@ -1,5 +1,5 @@ /* - * $Id: pio.c 407 2011-03-23 02:21:14Z hyunghwan.chung $ + * $Id: pio.c 410 2011-03-23 15:07:24Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -492,9 +492,10 @@ qse_pio_t* qse_pio_init ( * 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(' ')); + /* 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_mbspbrk (cmd_line, QSE_MT(" \t")); if (mptr) *mptr = QSE_MT('\0'); cmd_line[mn+1] = QSE_MT('\0'); /* the second '\0' at the end */ cmd_file = cmd_line; diff --git a/qse/lib/cmn/str_bas.c b/qse/lib/cmn/str_bas.c index 510b7955..25585b96 100644 --- a/qse/lib/cmn/str_bas.c +++ b/qse/lib/cmn/str_bas.c @@ -1,5 +1,5 @@ /* - * $Id: str_bas.c 405 2011-03-21 14:01:10Z hyunghwan.chung $ + * $Id: str_bas.c 410 2011-03-23 15:07:24Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -43,85 +43,6 @@ qse_size_t qse_strbytes (const qse_char_t* str) return (p - str) * QSE_SIZEOF(qse_char_t); } -qse_size_t qse_mbscpy (qse_mchar_t* buf, const qse_mchar_t* str) -{ - qse_mchar_t* org = buf; - while ((*buf++ = *str++) != QSE_MT('\0')); - return buf - org - 1; -} - -qse_size_t qse_wcscpy (qse_wchar_t* buf, const qse_wchar_t* str) -{ - qse_wchar_t* org = buf; - while ((*buf++ = *str++) != QSE_WT('\0')); - return buf - org - 1; -} - -qse_size_t qse_strxcpy ( - qse_char_t* buf, qse_size_t bsz, const qse_char_t* str) -{ - qse_char_t* p, * p2; - - p = buf; p2 = buf + bsz - 1; - - while (p < p2) - { - if (*str == QSE_T('\0')) break; - *p++ = *str++; - } - - if (bsz > 0) *p = QSE_T('\0'); - return p - buf; -} - -qse_size_t qse_strncpy ( - qse_char_t* buf, const qse_char_t* str, qse_size_t len) -{ - /* - const qse_char_t* end = str + len; - while (str < end) *buf++ = *str++; - *buf = QSE_T('\0'); - return len; - */ - - if (len > 0) - { - qse_size_t n = (len-1) >> 3; /* (len-1) / 8 */ - - switch (len & 7) /* len % 8 */ - { - repeat: - case 0: *buf++ = *str++; - case 7: *buf++ = *str++; - case 6: *buf++ = *str++; - case 5: *buf++ = *str++; - case 4: *buf++ = *str++; - case 3: *buf++ = *str++; - case 2: *buf++ = *str++; - case 1: *buf++ = *str++; - if (n <= 0) break; - n--; - goto repeat; - } - } - - *buf = QSE_T('\0'); - return len; -} - -qse_size_t qse_strxncpy ( - qse_char_t* buf, qse_size_t bsz, const qse_char_t* str, qse_size_t len) -{ - qse_size_t n; - - if (bsz <= 0) return 0; - if ((n = bsz - 1) > len) n = len; - QSE_MEMCPY (buf, str, n * QSE_SIZEOF(qse_char_t)); - buf[n] = QSE_T('\0'); - - return n; -} - qse_size_t qse_strxput ( qse_char_t* buf, qse_size_t bsz, const qse_char_t* str) { diff --git a/qse/lib/cmn/str_cpy.c b/qse/lib/cmn/str_cpy.c new file mode 100644 index 00000000..81cb3adc --- /dev/null +++ b/qse/lib/cmn/str_cpy.c @@ -0,0 +1,174 @@ +/* + * $Id: str_cnv.c 402 2011-03-18 15:07:21Z hyunghwan.chung $ + * + Copyright 2006-2009 Chung, Hyung-Hwan. + This file is part of QSE. + + QSE is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + QSE is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with QSE. If not, see . + */ + +#include +#include "mem.h" + +qse_size_t qse_mbscpy (qse_mchar_t* buf, const qse_mchar_t* str) +{ + qse_mchar_t* org = buf; + while ((*buf++ = *str++) != QSE_MT('\0')); + return buf - org - 1; +} + +qse_size_t qse_wcscpy (qse_wchar_t* buf, const qse_wchar_t* str) +{ + qse_wchar_t* org = buf; + while ((*buf++ = *str++) != QSE_WT('\0')); + return buf - org - 1; +} + +qse_size_t qse_mcsxcpy ( + qse_mchar_t* buf, qse_size_t bsz, const qse_mchar_t* str) +{ + qse_mchar_t* p, * p2; + + p = buf; p2 = buf + bsz - 1; + + while (p < p2) + { + if (*str == QSE_MT('\0')) break; + *p++ = *str++; + } + + if (bsz > 0) *p = QSE_MT('\0'); + return p - buf; +} + +qse_size_t qse_wcsxcpy ( + qse_wchar_t* buf, qse_size_t bsz, const qse_wchar_t* str) +{ + qse_wchar_t* p, * p2; + + p = buf; p2 = buf + bsz - 1; + + while (p < p2) + { + if (*str == QSE_WT('\0')) break; + *p++ = *str++; + } + + if (bsz > 0) *p = QSE_WT('\0'); + return p - buf; +} + +qse_size_t qse_mcsncpy ( + qse_mchar_t* buf, const qse_mchar_t* str, qse_size_t len) +{ + /* + const qse_mchar_t* end = str + len; + while (str < end) *buf++ = *str++; + *buf = QSE_MT('\0'); + return len; + */ + + if (len > 0) + { + qse_size_t n = (len-1) >> 3; /* (len-1) / 8 */ + + switch (len & 7) /* len % 8 */ + { + repeat: + case 0: *buf++ = *str++; + case 7: *buf++ = *str++; + case 6: *buf++ = *str++; + case 5: *buf++ = *str++; + case 4: *buf++ = *str++; + case 3: *buf++ = *str++; + case 2: *buf++ = *str++; + case 1: *buf++ = *str++; + if (n <= 0) break; + n--; + goto repeat; + } + } + + *buf = QSE_MT('\0'); + return len; +} + +qse_size_t qse_wcsncpy ( + qse_wchar_t* buf, const qse_wchar_t* str, qse_size_t len) +{ + /* + const qse_wchar_t* end = str + len; + while (str < end) *buf++ = *str++; + *buf = QSE_WT('\0'); + return len; + */ + + if (len > 0) + { + qse_size_t n = (len-1) >> 3; /* (len-1) / 8 */ + + switch (len & 7) /* len % 8 */ + { + repeat: + case 0: *buf++ = *str++; + case 7: *buf++ = *str++; + case 6: *buf++ = *str++; + case 5: *buf++ = *str++; + case 4: *buf++ = *str++; + case 3: *buf++ = *str++; + case 2: *buf++ = *str++; + case 1: *buf++ = *str++; + if (n <= 0) break; + n--; + goto repeat; + } + } + + *buf = QSE_WT('\0'); + return len; +} + +qse_size_t qse_mcsxncpy ( + qse_mchar_t* buf, qse_size_t bsz, + const qse_mchar_t* str, qse_size_t len) +{ + qse_size_t n; + + if (bsz <= 0) return 0; + if ((n = bsz - 1) > len) n = len; + QSE_MEMCPY (buf, str, n * QSE_SIZEOF(qse_mchar_t)); + buf[n] = QSE_MT('\0'); + + return n; +} + +qse_size_t qse_wcsxncpy ( + qse_wchar_t* buf, qse_size_t bsz, + const qse_wchar_t* str, qse_size_t len) +{ + qse_size_t n; + + if (bsz <= 0) return 0; + if ((n = bsz - 1) > len) n = len; + QSE_MEMCPY (buf, str, n * QSE_SIZEOF(qse_wchar_t)); + buf[n] = QSE_WT('\0'); + + return n; +} + + + + + + diff --git a/qse/lib/cmn/str_pbrk.c b/qse/lib/cmn/str_pbrk.c index d24020e9..c26a5f73 100644 --- a/qse/lib/cmn/str_pbrk.c +++ b/qse/lib/cmn/str_pbrk.c @@ -19,7 +19,6 @@ */ #include -#include qse_mchar_t* qse_mbspbrk (const qse_mchar_t* str1, const qse_mchar_t* str2) { diff --git a/qse/lib/cmn/str_spn.c b/qse/lib/cmn/str_spn.c index d8fdf276..47fba528 100644 --- a/qse/lib/cmn/str_spn.c +++ b/qse/lib/cmn/str_spn.c @@ -19,7 +19,6 @@ */ #include -#include qse_size_t qse_mbsspn (const qse_mchar_t* str1, const qse_mchar_t* str2) { diff --git a/qse/lib/scm/eval.c b/qse/lib/scm/eval.c index 45373ad5..2570451c 100644 --- a/qse/lib/scm/eval.c +++ b/qse/lib/scm/eval.c @@ -21,7 +21,7 @@ #include "scm.h" static int eval_entity (qse_scm_t* scm); - + #if 0 static int save (qse_scm_t* scm, qse_scm_ent_t* ) { @@ -29,8 +29,8 @@ static int save (qse_scm_t* scm, qse_scm_ent_t* ) static int leave (qse_scm_t* scm) { -} -#endif +} +#endif int qse_scm_dolambda (qse_scm_t* scm) { diff --git a/qse/watcom/debug/os2/lib/cmn/qsecmn.tgt b/qse/watcom/debug/os2/lib/cmn/qsecmn.tgt index 05e8a822..081e5c28 100755 --- a/qse/watcom/debug/os2/lib/cmn/qsecmn.tgt +++ b/qse/watcom/debug/os2/lib/cmn/qsecmn.tgt @@ -42,7 +42,7 @@ WVList 0 10 WPickList -37 +38 11 MItem 3 @@ -512,7 +512,7 @@ WVList 115 MItem 32 -..\..\..\..\..\lib\cmn\str_dyn.c +..\..\..\..\..\lib\cmn\str_cpy.c 116 WString 4 @@ -529,8 +529,8 @@ WVList 0 119 MItem -33 -..\..\..\..\..\lib\cmn\str_pbrk.c +32 +..\..\..\..\..\lib\cmn\str_dyn.c 120 WString 4 @@ -547,8 +547,8 @@ WVList 0 123 MItem -32 -..\..\..\..\..\lib\cmn\str_spn.c +33 +..\..\..\..\..\lib\cmn\str_pbrk.c 124 WString 4 @@ -566,7 +566,7 @@ WVList 127 MItem 32 -..\..\..\..\..\lib\cmn\str_utl.c +..\..\..\..\..\lib\cmn\str_spn.c 128 WString 4 @@ -583,8 +583,8 @@ WVList 0 131 MItem -29 -..\..\..\..\..\lib\cmn\time.c +32 +..\..\..\..\..\lib\cmn\str_utl.c 132 WString 4 @@ -601,8 +601,8 @@ WVList 0 135 MItem -28 -..\..\..\..\..\lib\cmn\tio.c +29 +..\..\..\..\..\lib\cmn\time.c 136 WString 4 @@ -619,8 +619,8 @@ WVList 0 139 MItem -32 -..\..\..\..\..\lib\cmn\tio_get.c +28 +..\..\..\..\..\lib\cmn\tio.c 140 WString 4 @@ -638,7 +638,7 @@ WVList 143 MItem 32 -..\..\..\..\..\lib\cmn\tio_put.c +..\..\..\..\..\lib\cmn\tio_get.c 144 WString 4 @@ -655,8 +655,8 @@ WVList 0 147 MItem -28 -..\..\..\..\..\lib\cmn\xma.c +32 +..\..\..\..\..\lib\cmn\tio_put.c 148 WString 4 @@ -673,26 +673,26 @@ WVList 0 151 MItem -3 -*.h +28 +..\..\..\..\..\lib\cmn\xma.c 152 WString -3 -NIL +4 +COBJ 153 WVList 0 154 WVList 0 --1 +11 1 1 0 155 MItem -28 -..\..\..\..\..\lib\cmn\mem.h +3 +*.h 156 WString 3 @@ -703,14 +703,14 @@ WVList 158 WVList 0 -151 +-1 1 1 0 159 MItem -32 -..\..\..\..\..\lib\cmn\syscall.h +28 +..\..\..\..\..\lib\cmn\mem.h 160 WString 3 @@ -721,7 +721,25 @@ WVList 162 WVList 0 -151 +155 +1 +1 +0 +163 +MItem +32 +..\..\..\..\..\lib\cmn\syscall.h +164 +WString +3 +NIL +165 +WVList +0 +166 +WVList +0 +155 1 1 0 diff --git a/qse/watcom/qse.wpj b/qse/watcom/qse.wpj index 3ce53608..8aac96cf 100755 --- a/qse/watcom/qse.wpj +++ b/qse/watcom/qse.wpj @@ -56,8 +56,8 @@ WVList VComponent 15 WRect -0 -0 +180 +1680 5700 4240 1 @@ -66,7 +66,7 @@ WRect WFileName 30 release/os2/lib/cmn/qsecmn.tgt -25 +24 25 17 VComponent @@ -124,14 +124,14 @@ WRect 320 5700 4240 -1 +0 0 28 WFileName 28 debug/os2/lib/cmn/qsecmn.tgt 19 -26 +22 29 VComponent 30 @@ -140,7 +140,7 @@ WRect 1800 5700 4240 -0 +1 0 31 WFileName @@ -180,4 +180,4 @@ WFileName debug/os2/cmd/scm/qsescm.tgt 0 1 -32 +35 diff --git a/qse/watcom/release/os2/lib/cmn/qsecmn.tgt b/qse/watcom/release/os2/lib/cmn/qsecmn.tgt index 82152496..2d01f0ea 100755 --- a/qse/watcom/release/os2/lib/cmn/qsecmn.tgt +++ b/qse/watcom/release/os2/lib/cmn/qsecmn.tgt @@ -42,7 +42,7 @@ WVList 0 10 WPickList -37 +38 11 MItem 3 @@ -576,7 +576,7 @@ WVList 131 MItem 32 -..\..\..\..\..\lib\cmn\str_dyn.c +..\..\..\..\..\lib\cmn\str_cpy.c 132 WString 4 @@ -593,8 +593,8 @@ WVList 0 135 MItem -33 -..\..\..\..\..\lib\cmn\str_pbrk.c +32 +..\..\..\..\..\lib\cmn\str_dyn.c 136 WString 4 @@ -611,8 +611,8 @@ WVList 0 139 MItem -32 -..\..\..\..\..\lib\cmn\str_spn.c +33 +..\..\..\..\..\lib\cmn\str_pbrk.c 140 WString 4 @@ -630,47 +630,47 @@ WVList 143 MItem 32 -..\..\..\..\..\lib\cmn\str_utl.c +..\..\..\..\..\lib\cmn\str_spn.c 144 WString 4 COBJ 145 WVList -1 -146 -MVState -147 -WString -3 -WCC -148 -WString -25 -o?2??Include directories: -1 -149 -WString -54 -"$(%watcom)/h;$(%watcom)/h/os2;..\..\..\..\..\include" 0 -150 +146 WVList 0 11 1 1 0 -151 +147 MItem -29 -..\..\..\..\..\lib\cmn\time.c -152 +32 +..\..\..\..\..\lib\cmn\str_utl.c +148 WString 4 COBJ -153 +149 WVList +1 +150 +MVState +151 +WString +3 +WCC +152 +WString +25 +o?2??Include directories: +1 +153 +WString +54 +"$(%watcom)/h;$(%watcom)/h/os2;..\..\..\..\..\include" 0 154 WVList @@ -681,8 +681,8 @@ WVList 0 155 MItem -28 -..\..\..\..\..\lib\cmn\tio.c +29 +..\..\..\..\..\lib\cmn\time.c 156 WString 4 @@ -699,8 +699,8 @@ WVList 0 159 MItem -32 -..\..\..\..\..\lib\cmn\tio_get.c +28 +..\..\..\..\..\lib\cmn\tio.c 160 WString 4 @@ -718,7 +718,7 @@ WVList 163 MItem 32 -..\..\..\..\..\lib\cmn\tio_put.c +..\..\..\..\..\lib\cmn\tio_get.c 164 WString 4 @@ -735,8 +735,8 @@ WVList 0 167 MItem -28 -..\..\..\..\..\lib\cmn\xma.c +32 +..\..\..\..\..\lib\cmn\tio_put.c 168 WString 4 @@ -753,26 +753,26 @@ WVList 0 171 MItem -3 -*.h +28 +..\..\..\..\..\lib\cmn\xma.c 172 WString -3 -NIL +4 +COBJ 173 WVList 0 174 WVList 0 --1 +11 1 1 0 175 MItem -28 -..\..\..\..\..\lib\cmn\mem.h +3 +*.h 176 WString 3 @@ -783,14 +783,14 @@ WVList 178 WVList 0 -171 +-1 1 1 0 179 MItem -32 -..\..\..\..\..\lib\cmn\syscall.h +28 +..\..\..\..\..\lib\cmn\mem.h 180 WString 3 @@ -801,7 +801,25 @@ WVList 182 WVList 0 -171 +175 +1 +1 +0 +183 +MItem +32 +..\..\..\..\..\lib\cmn\syscall.h +184 +WString +3 +NIL +185 +WVList +0 +186 +WVList +0 +175 1 1 0