From a3eed193d58439972a3cd3b1044e645f0fc256f5 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 10 Jan 2012 15:05:40 +0000 Subject: [PATCH] added solaris workaround for mbrlen bug. enhanced socket libarary detection in configure.ac --- qse/Makefile.in | 2 + qse/cmd/Makefile.in | 2 + qse/cmd/awk/Makefile.in | 2 + qse/cmd/awk/awk.c | 8 +- qse/cmd/cut/Makefile.in | 2 + qse/cmd/cut/cut.c | 25 ++++ qse/cmd/fs/Makefile.in | 2 + qse/cmd/sed/Makefile.in | 2 + qse/cmd/sed/sed.c | 8 +- qse/cmd/stx/Makefile.in | 2 + qse/configure | 221 ++++++++++++++++++++++++-------- qse/configure.ac | 34 ++++- qse/doc/Makefile.in | 2 + qse/doc/image/Makefile.in | 2 + qse/doc/page/Makefile.in | 2 + qse/include/Makefile.in | 2 + qse/include/qse/Makefile.in | 2 + qse/include/qse/awk/Makefile.in | 2 + qse/include/qse/cmn/Makefile.in | 2 + qse/include/qse/cut/Makefile.in | 2 + qse/include/qse/net/Makefile.in | 2 + qse/include/qse/sed/Makefile.in | 2 + qse/include/qse/stx/Makefile.in | 2 + qse/lib/Makefile.in | 2 + qse/lib/awk/Makefile.in | 2 + qse/lib/cmn/Makefile.in | 2 + qse/lib/cmn/mbwc.c | 1 - qse/lib/cmn/slmb.c | 72 ++++++++++- qse/lib/cut/Makefile.in | 2 + qse/lib/net/Makefile.in | 2 + qse/lib/sed/Makefile.in | 2 + qse/lib/stx/Makefile.in | 2 + qse/regress/Makefile.in | 2 + qse/regress/awk/Makefile.in | 2 + qse/regress/sed/Makefile.in | 2 + qse/samples/Makefile.in | 2 + qse/samples/awk/Makefile.in | 2 + qse/samples/awk/awk05.cpp | 9 +- qse/samples/awk/awk06.cpp | 8 +- qse/samples/awk/awk07.cpp | 8 +- qse/samples/cmn/Makefile.in | 2 + qse/samples/cmn/mbwc01.c | 36 ++++-- qse/samples/cmn/mbwc02.c | 28 ++-- qse/samples/cmn/slmb01.c | 29 ++++- qse/samples/cut/Makefile.in | 2 + qse/samples/cut/cut01.c | 24 ++++ qse/samples/net/Makefile.am | 2 +- qse/samples/net/Makefile.in | 7 +- qse/samples/sed/Makefile.in | 2 + qse/samples/sed/sed01.c | 9 +- qse/samples/sed/sed02.cpp | 8 +- qse/samples/sed/sed03.cpp | 8 +- 52 files changed, 482 insertions(+), 129 deletions(-) diff --git a/qse/Makefile.in b/qse/Makefile.in index fd1fe0a1..183f6803 100644 --- a/qse/Makefile.in +++ b/qse/Makefile.in @@ -186,8 +186,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/cmd/Makefile.in b/qse/cmd/Makefile.in index 04943ee9..a53c09ce 100644 --- a/qse/cmd/Makefile.in +++ b/qse/cmd/Makefile.in @@ -171,8 +171,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/cmd/awk/Makefile.in b/qse/cmd/awk/Makefile.in index 55e7a788..0e394205 100644 --- a/qse/cmd/awk/Makefile.in +++ b/qse/cmd/awk/Makefile.in @@ -158,8 +158,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/cmd/awk/awk.c b/qse/cmd/awk/awk.c index 86c2b201..2c0a75f9 100644 --- a/qse/cmd/awk/awk.c +++ b/qse/cmd/awk/awk.c @@ -1018,7 +1018,7 @@ oops: int qse_main (int argc, qse_achar_t* argv[]) { #if defined(_WIN32) - char locale[100]; + char locale[100]; UINT codepage = GetConsoleOutputCP(); if (codepage == CP_UTF8) { @@ -1027,12 +1027,12 @@ int qse_main (int argc, qse_achar_t* argv[]) } else { - sprintf (locale, ".%u", (unsigned int)codepage); - setlocale (LC_ALL, locale); + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); qse_setdflcmgr (qse_slmbcmgr); } #else - setlocale (LC_ALL, ""); + setlocale (LC_ALL, ""); qse_setdflcmgr (qse_slmbcmgr); #endif return qse_runmain (argc, argv, awk_main); diff --git a/qse/cmd/cut/Makefile.in b/qse/cmd/cut/Makefile.in index 69d6f1bf..be42bd1f 100644 --- a/qse/cmd/cut/Makefile.in +++ b/qse/cmd/cut/Makefile.in @@ -157,8 +157,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/cmd/cut/cut.c b/qse/cmd/cut/cut.c index 86a53a8d..d8a5c509 100644 --- a/qse/cmd/cut/cut.c +++ b/qse/cmd/cut/cut.c @@ -27,6 +27,12 @@ #include #include #include +#include + +#include +#if defined(_WIN32) +# include +#endif static qse_char_t* g_selector = QSE_NULL; @@ -303,5 +309,24 @@ oops: int qse_main (int argc, char* argv[]) { +#if defined(_WIN32) + char locale[100]; + UINT codepage = GetConsoleOutputCP(); + if (codepage == CP_UTF8) + { + /*SetConsoleOUtputCP (CP_UTF8);*/ + qse_setdflcmgr (qse_utf8cmgr); + } + else + { + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); + qse_setdflcmgr (qse_slmbcmgr); + } +#else + setlocale (LC_ALL, ""); + qse_setdflcmgr (qse_slmbcmgr); +#endif + return qse_runmain (argc, argv, cut_main); } diff --git a/qse/cmd/fs/Makefile.in b/qse/cmd/fs/Makefile.in index fac43df7..a589317a 100644 --- a/qse/cmd/fs/Makefile.in +++ b/qse/cmd/fs/Makefile.in @@ -157,8 +157,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/cmd/sed/Makefile.in b/qse/cmd/sed/Makefile.in index b93e4dbd..7c2384f5 100644 --- a/qse/cmd/sed/Makefile.in +++ b/qse/cmd/sed/Makefile.in @@ -157,8 +157,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/cmd/sed/sed.c b/qse/cmd/sed/sed.c index c1a008b3..13e5d1d6 100644 --- a/qse/cmd/sed/sed.c +++ b/qse/cmd/sed/sed.c @@ -823,7 +823,7 @@ oops: int qse_main (int argc, qse_achar_t* argv[]) { #if defined(_WIN32) - char locale[100]; + char locale[100]; UINT codepage = GetConsoleOutputCP(); if (codepage == CP_UTF8) { @@ -832,12 +832,12 @@ int qse_main (int argc, qse_achar_t* argv[]) } else { - sprintf (locale, ".%u", (unsigned int)codepage); - setlocale (LC_ALL, locale); + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); qse_setdflcmgr (qse_slmbcmgr); } #else - setlocale (LC_ALL, ""); + setlocale (LC_ALL, ""); qse_setdflcmgr (qse_slmbcmgr); #endif return qse_runmain (argc, argv, sed_main); diff --git a/qse/cmd/stx/Makefile.in b/qse/cmd/stx/Makefile.in index 6d203cdf..73d578b0 100644 --- a/qse/cmd/stx/Makefile.in +++ b/qse/cmd/stx/Makefile.in @@ -158,8 +158,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/configure b/qse/configure index f165d3da..2343c867 100755 --- a/qse/configure +++ b/qse/configure @@ -762,6 +762,8 @@ PTHREAD_CFLAGS PTHREAD_LIBS PTHREAD_CC ax_pthread_config +SENDFILE_LIBS +SOCKET_LIBS ENABLE_CXX_FALSE ENABLE_CXX_TRUE BUILD_MODE @@ -5755,13 +5757,13 @@ if test "${lt_cv_nm_interface+set}" = set; then : else lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext - (eval echo "\"\$as_me:5758: $ac_compile\"" >&5) + (eval echo "\"\$as_me:5760: $ac_compile\"" >&5) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&5 - (eval echo "\"\$as_me:5761: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval echo "\"\$as_me:5763: $NM \\\"conftest.$ac_objext\\\"\"" >&5) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&5 - (eval echo "\"\$as_me:5764: output\"" >&5) + (eval echo "\"\$as_me:5766: output\"" >&5) cat conftest.out >&5 if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" @@ -6956,7 +6958,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 6959 "configure"' > conftest.$ac_ext + echo '#line 6961 "configure"' > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -9012,11 +9014,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:9015: $lt_compile\"" >&5) + (eval echo "\"\$as_me:9017: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:9019: \$? = $ac_status" >&5 + echo "$as_me:9021: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -9351,11 +9353,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:9354: $lt_compile\"" >&5) + (eval echo "\"\$as_me:9356: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:9358: \$? = $ac_status" >&5 + echo "$as_me:9360: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -9456,11 +9458,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:9459: $lt_compile\"" >&5) + (eval echo "\"\$as_me:9461: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:9463: \$? = $ac_status" >&5 + echo "$as_me:9465: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -9511,11 +9513,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:9514: $lt_compile\"" >&5) + (eval echo "\"\$as_me:9516: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:9518: \$? = $ac_status" >&5 + echo "$as_me:9520: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -11895,7 +11897,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11898 "configure" +#line 11900 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11991,7 +11993,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11994 "configure" +#line 11996 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -13947,11 +13949,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:13950: $lt_compile\"" >&5) + (eval echo "\"\$as_me:13952: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:13954: \$? = $ac_status" >&5 + echo "$as_me:13956: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -14046,11 +14048,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:14049: $lt_compile\"" >&5) + (eval echo "\"\$as_me:14051: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:14053: \$? = $ac_status" >&5 + echo "$as_me:14055: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -14098,11 +14100,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:14101: $lt_compile\"" >&5) + (eval echo "\"\$as_me:14103: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:14105: \$? = $ac_status" >&5 + echo "$as_me:14107: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -17068,13 +17070,76 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for socket in -lsocket" >&5 -$as_echo_n "checking for socket in -lsocket... " >&6; } -if test "${ac_cv_lib_socket_socket+set}" = set; then : +OLDLIBS="$LIBS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing gethostbyname" >&5 +$as_echo_n "checking for library containing gethostbyname... " >&6; } +if test "${ac_cv_search_gethostbyname+set}" = set; then : $as_echo_n "(cached) " >&6 else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lsocket $LIBS" + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char gethostbyname (); +int +main () +{ +return gethostbyname (); + ; + return 0; +} +_ACEOF +for ac_lib in '' nsl; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_gethostbyname=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if test "${ac_cv_search_gethostbyname+set}" = set; then : + break +fi +done +if test "${ac_cv_search_gethostbyname+set}" = set; then : + +else + ac_cv_search_gethostbyname=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_gethostbyname" >&5 +$as_echo "$ac_cv_search_gethostbyname" >&6; } +ac_res=$ac_cv_search_gethostbyname +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +fi + +LIBS="$OLDLIBS" +if test "$ac_cv_search_gethostbyname" != "none required" -a "$ac_cv_search_gethostbyname" != "no" +then + SOCKET_LIBS="$SOCKET_LIBS -lnsl" +fi + +OLDLIBS="$LIBS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing socket" >&5 +$as_echo_n "checking for library containing socket... " >&6; } +if test "${ac_cv_search_socket+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -17093,29 +17158,53 @@ return socket (); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_socket_socket=yes -else - ac_cv_lib_socket_socket=no +for ac_lib in '' socket; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_socket=$ac_res fi rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS + conftest$ac_exeext + if test "${ac_cv_search_socket+set}" = set; then : + break fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_socket_socket" >&5 -$as_echo "$ac_cv_lib_socket_socket" >&6; } -if test "x$ac_cv_lib_socket_socket" = x""yes; then : - SOCKET_LIBS="-lsocket" -else +done +if test "${ac_cv_search_socket+set}" = set; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for socket in -lsocket" >&5 -$as_echo_n "checking for socket in -lsocket... " >&6; } -if test "${ac_cv_lib_socket_socket+set}" = set; then : +else + ac_cv_search_socket=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_socket" >&5 +$as_echo "$ac_cv_search_socket" >&6; } +ac_res=$ac_cv_search_socket +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +fi + +LIBS="$OLDLIBS" +if test "$ac_cv_search_socket" != "none required" -a "$ac_cv_search_socket" != "no" +then + SOCKET_LIBS="$SOCKET_LIBS -lsocket" +fi + + + +OLDLIBS="$LIBS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing sendfile" >&5 +$as_echo_n "checking for library containing sendfile... " >&6; } +if test "${ac_cv_search_sendfile+set}" = set; then : $as_echo_n "(cached) " >&6 else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lsocket -lnsl - $LIBS" + ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -17125,32 +17214,51 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext #ifdef __cplusplus extern "C" #endif -char socket (); +char sendfile (); int main () { -return socket (); +return sendfile (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_socket_socket=yes -else - ac_cv_lib_socket_socket=no +for ac_lib in '' sendfile; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_sendfile=$ac_res fi rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS + conftest$ac_exeext + if test "${ac_cv_search_sendfile+set}" = set; then : + break fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_socket_socket" >&5 -$as_echo "$ac_cv_lib_socket_socket" >&6; } -if test "x$ac_cv_lib_socket_socket" = x""yes; then : - SOCKET_LIBS="-lsocket -lnsl" +done +if test "${ac_cv_search_sendfile+set}" = set; then : + +else + ac_cv_search_sendfile=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_sendfile" >&5 +$as_echo "$ac_cv_search_sendfile" >&6; } +ac_res=$ac_cv_search_sendfile +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + fi - - +LIBS="$OLDLIBS" +if test "$ac_cv_search_sendfile" != "none required" -a "$ac_cv_search_socket" != "no" +then + SENDFILE_LIBS="$SENDFILE_LIBS -lsendfile" fi @@ -20294,5 +20402,6 @@ echo " Wide character: ${enable_wchar_is}" echo " Math library: ${LIBM}" echo " Pthread library: ${PTHREAD_LIBS}" echo " Socket library: ${SOCKET_LIBS}" +echo " Sendfile library: ${SENDFILE_LIBS}" echo "-------------------------------------------------------------------------" diff --git a/qse/configure.ac b/qse/configure.ac index b9fbf93e..64266e37 100644 --- a/qse/configure.ac +++ b/qse/configure.ac @@ -220,13 +220,32 @@ AC_ARG_ENABLE([cxx], [AS_HELP_STRING([--enable-cxx],[build the library for C++ i AM_CONDITIONAL(ENABLE_CXX, test "${enable_cxx_is}" = "yes" ) -AC_CHECK_LIB([socket], [socket], [SOCKET_LIBS="-lsocket"], - [ - AC_CHECK_LIB([socket], [socket], - [SOCKET_LIBS="-lsocket -lnsl"], [], [-lnsl] - ) - ] -) +OLDLIBS="$LIBS" +AC_SEARCH_LIBS([gethostbyname], [nsl]) +LIBS="$OLDLIBS" +if test "$ac_cv_search_gethostbyname" != "none required" -a "$ac_cv_search_gethostbyname" != "no" +then + SOCKET_LIBS="$SOCKET_LIBS -lnsl" +fi + +OLDLIBS="$LIBS" +AC_SEARCH_LIBS([socket], [socket]) +LIBS="$OLDLIBS" +if test "$ac_cv_search_socket" != "none required" -a "$ac_cv_search_socket" != "no" +then + SOCKET_LIBS="$SOCKET_LIBS -lsocket" +fi + +AC_SUBST(SOCKET_LIBS) + +OLDLIBS="$LIBS" +AC_SEARCH_LIBS([sendfile], [sendfile]) +LIBS="$OLDLIBS" +if test "$ac_cv_search_sendfile" != "none required" -a "$ac_cv_search_socket" != "no" +then + SENDFILE_LIBS="$SENDFILE_LIBS -lsendfile" +fi +AC_SUBST(SENDFILE_LIBS) AC_ARG_ENABLE([reentrant], [AS_HELP_STRING([--enable-reentrant],[define _REENTRANT (default. yes)])], enable_reentrant_is=$enableval,enable_reentrant_is=yes) @@ -323,5 +342,6 @@ echo " Wide character: ${enable_wchar_is}" echo " Math library: ${LIBM}" echo " Pthread library: ${PTHREAD_LIBS}" echo " Socket library: ${SOCKET_LIBS}" +echo " Sendfile library: ${SENDFILE_LIBS}" echo "-------------------------------------------------------------------------" ] diff --git a/qse/doc/Makefile.in b/qse/doc/Makefile.in index 4ee3f810..819204e0 100644 --- a/qse/doc/Makefile.in +++ b/qse/doc/Makefile.in @@ -175,8 +175,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/doc/image/Makefile.in b/qse/doc/image/Makefile.in index 9ab6a966..a4151c78 100644 --- a/qse/doc/image/Makefile.in +++ b/qse/doc/image/Makefile.in @@ -134,8 +134,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/doc/page/Makefile.in b/qse/doc/page/Makefile.in index 490d3b56..d2474e74 100644 --- a/qse/doc/page/Makefile.in +++ b/qse/doc/page/Makefile.in @@ -134,8 +134,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/include/Makefile.in b/qse/include/Makefile.in index da48ca12..41c66ca4 100644 --- a/qse/include/Makefile.in +++ b/qse/include/Makefile.in @@ -172,8 +172,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/include/qse/Makefile.in b/qse/include/qse/Makefile.in index 6c748b99..c5f3e279 100644 --- a/qse/include/qse/Makefile.in +++ b/qse/include/qse/Makefile.in @@ -200,8 +200,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/include/qse/awk/Makefile.in b/qse/include/qse/awk/Makefile.in index 218f2fd1..98cb6d84 100644 --- a/qse/include/qse/awk/Makefile.in +++ b/qse/include/qse/awk/Makefile.in @@ -161,8 +161,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/include/qse/cmn/Makefile.in b/qse/include/qse/cmn/Makefile.in index 5cde6535..4eb8cae6 100644 --- a/qse/include/qse/cmn/Makefile.in +++ b/qse/include/qse/cmn/Makefile.in @@ -165,8 +165,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/include/qse/cut/Makefile.in b/qse/include/qse/cut/Makefile.in index 03214d0f..ff35450f 100644 --- a/qse/include/qse/cut/Makefile.in +++ b/qse/include/qse/cut/Makefile.in @@ -161,8 +161,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/include/qse/net/Makefile.in b/qse/include/qse/net/Makefile.in index c56b164a..64854984 100644 --- a/qse/include/qse/net/Makefile.in +++ b/qse/include/qse/net/Makefile.in @@ -159,8 +159,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/include/qse/sed/Makefile.in b/qse/include/qse/sed/Makefile.in index 20596d42..4b94959e 100644 --- a/qse/include/qse/sed/Makefile.in +++ b/qse/include/qse/sed/Makefile.in @@ -161,8 +161,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/include/qse/stx/Makefile.in b/qse/include/qse/stx/Makefile.in index ee5f2de0..087b2e5b 100644 --- a/qse/include/qse/stx/Makefile.in +++ b/qse/include/qse/stx/Makefile.in @@ -159,8 +159,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/lib/Makefile.in b/qse/lib/Makefile.in index 52f51817..ae1bf3bc 100644 --- a/qse/lib/Makefile.in +++ b/qse/lib/Makefile.in @@ -171,8 +171,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/lib/awk/Makefile.in b/qse/lib/awk/Makefile.in index 558c065b..2367d15d 100644 --- a/qse/lib/awk/Makefile.in +++ b/qse/lib/awk/Makefile.in @@ -198,8 +198,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/lib/cmn/Makefile.in b/qse/lib/cmn/Makefile.in index 8576f795..d9b6561e 100644 --- a/qse/lib/cmn/Makefile.in +++ b/qse/lib/cmn/Makefile.in @@ -212,8 +212,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/lib/cmn/mbwc.c b/qse/lib/cmn/mbwc.c index 3421eecc..c61484d7 100644 --- a/qse/lib/cmn/mbwc.c +++ b/qse/lib/cmn/mbwc.c @@ -102,7 +102,6 @@ int qse_wcsntombsn ( const qse_wchar_t* wcs, qse_size_t* wcslen, qse_mchar_t* mbs, qse_size_t* mbslen) { - return qse_wcsntombsnwithcmgr (wcs, wcslen, mbs, mbslen, dfl_cmgr); } diff --git a/qse/lib/cmn/slmb.c b/qse/lib/cmn/slmb.c index faf256a2..30759f3b 100644 --- a/qse/lib/cmn/slmb.c +++ b/qse/lib/cmn/slmb.c @@ -120,6 +120,35 @@ qse_size_t qse_slmbrtoslwc ( } return dbcslen; +#elif defined(__sun__) && defined(HAVE_MBRTOWC) + /* + * Read comments in qse_slmbrlen(). + */ + + size_t n; + + QSE_ASSERT (mb != QSE_NULL); + QSE_ASSERT (mbl > 0); + + if (wc) + { + n = mbrtowc (wc, mb, mbl, (mbstate_t*)state); + if (n == 0) + { + *wc = QSE_WT('\0'); + return 1; + } + } + else + { + qse_wchar_t dummy; + n = mbrtowc (&dummy, mb, mbl, (mbstate_t*)state); + if (n == 0) return 1; + } + + if (n == (size_t)-1) return 0; /* invalid sequence */ + if (n == (size_t)-2) return mbl + 1; /* incomplete sequence */ + return (qse_size_t)n; #elif defined(HAVE_MBRTOWC) size_t n; @@ -151,9 +180,50 @@ qse_size_t qse_slmbrlen ( QSE_ASSERT (mb != QSE_NULL); QSE_ASSERT (mbl > 0); + /* IsDBCSLeadByte() or IsDBCSLeadByteEx() doesn't validate + * the actual sequence. So it can't actually detect an invalid + * sequence. Thus, qse_slmbrtowc() may return a different length + * for an invalid sequence form qse_slmbrlen(). */ dbcslen = IsDBCSLeadByteEx(CP_THREAD_ACP, *mb)? 2: 1; if (mbl < dbcslen) return mbl + 1; /* incomplete sequence */ return dbcslen; + +#elif defined(__sun__) && defined(HAVE_MBRLEN) + /* on solaris 8, + * for a valid utf8 sequence on the utf8-locale, + * mbrlen() returned -1. + * mbrtowc(NULL, mbs, mbl, state) also returned -1. + * mblen() returned the right length. + * mbrtowc(wc, mbs, mbl, state) returned the right length. + * for a cp949 sequence on the cp949 locale, + * mbrlen() returned the right length. + * mbrtowc(NULL, mbs, mbl, state) returned the right length. + * mblen() returned the right length. + * mbrtowc(wc, mbs, mbl, state) returned the right length. + * + * The problem is buggy mbrlen() that can't handle utf8 sequence + * properly. here is my quick and dirty workaround for solaris. + * + * Newer solaris 9 and 10 or later should be also affected since + * i don't check any version or something. + * + * There could be other platforms with the same issue. + */ + + /* TODO: + * it seems that solaris is not the only platform with + * this kind of a bug. + * + * checking this in autoconf doesn't solve the problem. + * the underlying system could have fixed the problem already. + * + * checking this during library initialization makes sense. + * qse_slmbinit() or qse_initlib() tests if mblen() and mbrlen() + * returns consistant results and arranges properly method + * for this slmb routine. + */ + return qse_slmbrtoslwc (mb, mbl, QSE_NULL, state); + #elif defined(HAVE_MBRLEN) size_t n; @@ -211,7 +281,7 @@ qse_size_t qse_slmblenmax (void) #if defined(_WIN32) /* Windows doesn't handle utf8 properly even when your code page * is CP_UTF8(65001). you should use functions in utf8.c for utf8 - * handleing on windows. */ + * handleing on windows. 2 is the maximum for DBCS encodings. */ return 2; #else return MB_CUR_MAX; diff --git a/qse/lib/cut/Makefile.in b/qse/lib/cut/Makefile.in index 7ac93cbf..55b43047 100644 --- a/qse/lib/cut/Makefile.in +++ b/qse/lib/cut/Makefile.in @@ -196,8 +196,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/lib/net/Makefile.in b/qse/lib/net/Makefile.in index 40e39f37..8b77bd43 100644 --- a/qse/lib/net/Makefile.in +++ b/qse/lib/net/Makefile.in @@ -178,8 +178,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/lib/sed/Makefile.in b/qse/lib/sed/Makefile.in index b4d1b5b3..74fc0646 100644 --- a/qse/lib/sed/Makefile.in +++ b/qse/lib/sed/Makefile.in @@ -196,8 +196,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/lib/stx/Makefile.in b/qse/lib/stx/Makefile.in index 5a559252..e945914f 100644 --- a/qse/lib/stx/Makefile.in +++ b/qse/lib/stx/Makefile.in @@ -178,8 +178,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/regress/Makefile.in b/qse/regress/Makefile.in index d048563e..324855fa 100644 --- a/qse/regress/Makefile.in +++ b/qse/regress/Makefile.in @@ -172,8 +172,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/regress/awk/Makefile.in b/qse/regress/awk/Makefile.in index a436d64f..5ee523fa 100644 --- a/qse/regress/awk/Makefile.in +++ b/qse/regress/awk/Makefile.in @@ -135,8 +135,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/regress/sed/Makefile.in b/qse/regress/sed/Makefile.in index 23e07061..4e9b4555 100644 --- a/qse/regress/sed/Makefile.in +++ b/qse/regress/sed/Makefile.in @@ -137,8 +137,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/samples/Makefile.in b/qse/samples/Makefile.in index fd90816d..0b52795b 100644 --- a/qse/samples/Makefile.in +++ b/qse/samples/Makefile.in @@ -172,8 +172,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/samples/awk/Makefile.in b/qse/samples/awk/Makefile.in index b2da75d0..31eb574c 100644 --- a/qse/samples/awk/Makefile.in +++ b/qse/samples/awk/Makefile.in @@ -216,8 +216,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/samples/awk/awk05.cpp b/qse/samples/awk/awk05.cpp index 10410d19..97083422 100644 --- a/qse/samples/awk/awk05.cpp +++ b/qse/samples/awk/awk05.cpp @@ -83,7 +83,7 @@ static int awk_main (int argc, qse_char_t* argv[]) int qse_main (int argc, qse_achar_t* argv[]) { #if defined(_WIN32) - char locale[100]; + char locale[100]; UINT codepage = GetConsoleOutputCP(); if (codepage == CP_UTF8) { @@ -92,13 +92,14 @@ int qse_main (int argc, qse_achar_t* argv[]) } else { - sprintf (locale, ".%u", (unsigned int)codepage); - setlocale (LC_ALL, locale); + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); qse_setdflcmgr (qse_slmbcmgr); } #else - setlocale (LC_ALL, ""); + setlocale (LC_ALL, ""); qse_setdflcmgr (qse_slmbcmgr); #endif + return qse_runmain (argc,argv,awk_main); } diff --git a/qse/samples/awk/awk06.cpp b/qse/samples/awk/awk06.cpp index d69f99bc..d33ed23a 100644 --- a/qse/samples/awk/awk06.cpp +++ b/qse/samples/awk/awk06.cpp @@ -110,7 +110,7 @@ static int awk_main (int argc, qse_char_t* argv[]) int qse_main (int argc, qse_achar_t* argv[]) { #if defined(_WIN32) - char locale[100]; + char locale[100]; UINT codepage = GetConsoleOutputCP(); if (codepage == CP_UTF8) { @@ -119,12 +119,12 @@ int qse_main (int argc, qse_achar_t* argv[]) } else { - sprintf (locale, ".%u", (unsigned int)codepage); - setlocale (LC_ALL, locale); + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); qse_setdflcmgr (qse_slmbcmgr); } #else - setlocale (LC_ALL, ""); + setlocale (LC_ALL, ""); qse_setdflcmgr (qse_slmbcmgr); #endif return qse_runmain (argc,argv,awk_main); diff --git a/qse/samples/awk/awk07.cpp b/qse/samples/awk/awk07.cpp index 71241775..ada3a432 100644 --- a/qse/samples/awk/awk07.cpp +++ b/qse/samples/awk/awk07.cpp @@ -155,7 +155,7 @@ static int awk_main (int argc, qse_char_t* argv[]) int qse_main (int argc, qse_achar_t* argv[]) { #if defined(_WIN32) - char locale[100]; + char locale[100]; UINT codepage = GetConsoleOutputCP(); if (codepage == CP_UTF8) { @@ -164,12 +164,12 @@ int qse_main (int argc, qse_achar_t* argv[]) } else { - sprintf (locale, ".%u", (unsigned int)codepage); - setlocale (LC_ALL, locale); + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); qse_setdflcmgr (qse_slmbcmgr); } #else - setlocale (LC_ALL, ""); + setlocale (LC_ALL, ""); qse_setdflcmgr (qse_slmbcmgr); #endif return qse_runmain (argc,argv,awk_main); diff --git a/qse/samples/cmn/Makefile.in b/qse/samples/cmn/Makefile.in index 706a285e..17183906 100644 --- a/qse/samples/cmn/Makefile.in +++ b/qse/samples/cmn/Makefile.in @@ -296,8 +296,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/samples/cmn/mbwc01.c b/qse/samples/cmn/mbwc01.c index e2ca2973..9119853c 100644 --- a/qse/samples/cmn/mbwc01.c +++ b/qse/samples/cmn/mbwc01.c @@ -17,12 +17,15 @@ } while (0) +/* the texts here are all in utf-8. you will see many errors + * on a non-utf8 locale */ static int test1 (void) { int i; const qse_mchar_t* x[] = { QSE_MT(""), + QSE_MT("This is good."), QSE_MT("이거슨"), QSE_MT("뭐냐이거"), QSE_MT("過去一個月"), @@ -83,6 +86,7 @@ static int test2 (void) const qse_mchar_t* x[] = { QSE_MT("\0\0\0"), + QSE_MT("This is good."), QSE_MT("이거슨"), QSE_MT("뭐냐이거"), QSE_MT("過去一個月"), @@ -107,10 +111,12 @@ static int test2 (void) while (j < k) { + int y; + wlen = QSE_COUNTOF(buf); mlen = k - j; - int y = qse_mbsntowcsn (&x[i][j], &mlen, buf, &wlen); + y = qse_mbsntowcsn (&x[i][j], &mlen, buf, &wlen); if (y <= -1 && y != -2) @@ -148,6 +154,7 @@ static int test3 (void) const qse_mchar_t* x[] = { QSE_MT(""), + QSE_MT("This is good."), QSE_MT("이거슨"), QSE_MT("뭐냐이거"), QSE_MT("過去一個月"), @@ -180,6 +187,7 @@ static int test4 (void) const qse_mchar_t* x[] = { QSE_MT("\0\0\0"), + QSE_MT("This is good."), QSE_MT("이거슨"), QSE_MT("뭐냐이거"), QSE_MT("過去一個月"), @@ -206,17 +214,22 @@ static int test4 (void) int main () { #if defined(_WIN32) - char codepage[100]; - UINT old_cp = GetConsoleOutputCP(); - SetConsoleOutputCP (CP_UTF8); - - /* TODO: on windows this set locale only affects those mbcs fucntions in clib. - * it doesn't support utf8 i guess find a working way. the following won't work - sprintf (codepage, ".%d", GetACP()); - setlocale (LC_ALL, codepage); - */ + char locale[100]; + UINT codepage = GetConsoleOutputCP(); + if (codepage == CP_UTF8) + { + /*SetConsoleOUtputCP (CP_UTF8);*/ + qse_setdflcmgr (qse_utf8cmgr); + } + else + { + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); + qse_setdflcmgr (qse_slmbcmgr); + } #else setlocale (LC_ALL, ""); + qse_setdflcmgr (qse_slmbcmgr); #endif qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); @@ -228,8 +241,5 @@ int main () R (test3); R (test4); -#if defined(_WIN32) - SetConsoleOutputCP (old_cp); -#endif return 0; } diff --git a/qse/samples/cmn/mbwc02.c b/qse/samples/cmn/mbwc02.c index 9d5a3d6b..ccbabc84 100644 --- a/qse/samples/cmn/mbwc02.c +++ b/qse/samples/cmn/mbwc02.c @@ -149,7 +149,7 @@ static int test2 (void) qse_printf (QSE_T("Converting %d wide-character - "), (int)len); wlen = len; - n = qse_wcsntombsn (&x[i][j], &wlen, QSE_NULL, &mlen); + n = qse_wcsntombsn (x[i], &wlen, QSE_NULL, &mlen); if (n == -1) { qse_printf (QSE_T("***illegal character[mlen=%d/wlen=%d]*** ["), (int)mlen, (int)wlen); @@ -294,17 +294,22 @@ static int test4 (void) int main () { #if defined(_WIN32) - char codepage[100]; - UINT old_cp = GetConsoleOutputCP(); - SetConsoleOutputCP (CP_UTF8); - - /* TODO: on windows this set locale only affects those mbcs fucntions in clib. - * it doesn't support utf8 i guess find a working way. the following won't work - sprintf (codepage, ".%d", GetACP()); - setlocale (LC_ALL, codepage); - */ + char locale[100]; + UINT codepage = GetConsoleOutputCP(); + if (codepage == CP_UTF8) + { + /*SetConsoleOUtputCP (CP_UTF8);*/ + qse_setdflcmgr (qse_utf8cmgr); + } + else + { + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); + qse_setdflcmgr (qse_slmbcmgr); + } #else setlocale (LC_ALL, ""); + qse_setdflcmgr (qse_slmbcmgr); #endif qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); @@ -316,8 +321,5 @@ int main () R (test3); R (test4); -#if defined(_WIN32) - SetConsoleOutputCP (old_cp); -#endif return 0; } diff --git a/qse/samples/cmn/slmb01.c b/qse/samples/cmn/slmb01.c index 43df25e2..3ca442f1 100644 --- a/qse/samples/cmn/slmb01.c +++ b/qse/samples/cmn/slmb01.c @@ -5,6 +5,7 @@ #include #include +#include #if defined(_WIN32) # include @@ -29,6 +30,15 @@ static int test2 (void) { "\0", "뛰어 올라봐", /* this text is in utf8. so some conversions fail on a non-utf8 locale */ +#if defined(QSE_ENDIAN_BIG) + /* this text is in cp949. 뛰어올라봐 */ + "\xD9\xB6\xEE\xBE \xC3\xBF\xF3\xB6\xC1\xBA", +#elif defined(QSE_ENDIAN_LITTLE) + /* this text is in cp949. 뛰어올라봐 */ + "\xB6\xD9\xBE\xEE \xBF\xC3\xB6\xF3\xBA\xC1", +#else +# error ENDIAN UNKNOWN +#endif "Fly to the universe" }; @@ -43,11 +53,26 @@ static int test2 (void) qse_printf (QSE_T("[")); while (j < k) { - qse_size_t y = qse_slmblen (&x[i][j], k-j); + mbstate_t state; + qse_size_t y, ym, ymr; + + y = qse_slmblen (&x[i][j], k-j); + ym = mblen (&x[i][j], k-j); + + memset (&state, 0, sizeof(state)); + ymr = mbrlen (&x[i][j], k-j, &state); + + if (ym != ymr) + { + /* if this line is shown, the c runtime library is buggy. + * note that i assume we handle stateless encoding only + * since the state is initlized to 0 above all the time */ + qse_printf (QSE_T("***buggy clib [mblen=%d],[mbrlen=%d]***"), (int)ym, (int)ymr); + } if (y == 0) { - qse_printf (QSE_T("***illegal sequence***")); + qse_printf (QSE_T("***illegal sequence[y=%d][ym=%d][ymr=%d]***"), (int)y, (int)ym, (int)ymr); break; } else if (y > k-j) diff --git a/qse/samples/cut/Makefile.in b/qse/samples/cut/Makefile.in index fa50339a..2c24e978 100644 --- a/qse/samples/cut/Makefile.in +++ b/qse/samples/cut/Makefile.in @@ -156,8 +156,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/samples/cut/cut01.c b/qse/samples/cut/cut01.c index 41f93b19..c0f0e1e1 100644 --- a/qse/samples/cut/cut01.c +++ b/qse/samples/cut/cut01.c @@ -20,8 +20,14 @@ #include #include +#include #include +#include +#if defined(_WIN32) +# include +#endif + void print_usage (QSE_FILE* s, const qse_char_t* argv0) { qse_fprintf (s, QSE_T("USAGE: %s selector [input-file [output-file]]\n"), argv0); @@ -74,6 +80,24 @@ oops: int qse_main (int argc, qse_achar_t* argv[]) { +#if defined(_WIN32) + char locale[100]; + UINT codepage = GetConsoleOutputCP(); + if (codepage == CP_UTF8) + { + /*SetConsoleOUtputCP (CP_UTF8);*/ + qse_setdflcmgr (qse_utf8cmgr); + } + else + { + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); + qse_setdflcmgr (qse_slmbcmgr); + } +#else + setlocale (LC_ALL, ""); + qse_setdflcmgr (qse_slmbcmgr); +#endif return qse_runmain (argc, argv, cut_main); } diff --git a/qse/samples/net/Makefile.am b/qse/samples/net/Makefile.am index c7f0e400..c4e78a7b 100644 --- a/qse/samples/net/Makefile.am +++ b/qse/samples/net/Makefile.am @@ -8,7 +8,7 @@ AM_CPPFLAGS = \ bin_PROGRAMS = http01 LDFLAGS += -L../../lib/cmn -L../../lib/net -LDADD = -lqsenet -lqsecmn $(PTHREAD_LIBS) $(SOCKET_LIBS) +LDADD = -lqsenet -lqsecmn $(PTHREAD_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS) http01_SOURCES = http01.c diff --git a/qse/samples/net/Makefile.in b/qse/samples/net/Makefile.in index d7b78f3f..50423f02 100644 --- a/qse/samples/net/Makefile.in +++ b/qse/samples/net/Makefile.in @@ -55,7 +55,8 @@ am_http01_OBJECTS = http01.$(OBJEXT) http01_OBJECTS = $(am_http01_OBJECTS) http01_LDADD = $(LDADD) am__DEPENDENCIES_1 = -http01_DEPENDENCIES = $(am__DEPENDENCIES_1) +http01_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) DEFAULT_INCLUDES = depcomp = $(SHELL) $(top_srcdir)/ac/depcomp am__depfiles_maybe = depfiles @@ -156,8 +157,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ @@ -221,7 +224,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/include \ -I$(includedir) -LDADD = -lqsenet -lqsecmn $(PTHREAD_LIBS) $(SOCKET_LIBS) +LDADD = -lqsenet -lqsecmn $(PTHREAD_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS) http01_SOURCES = http01.c all: all-am diff --git a/qse/samples/sed/Makefile.in b/qse/samples/sed/Makefile.in index 870893c3..175bc1aa 100644 --- a/qse/samples/sed/Makefile.in +++ b/qse/samples/sed/Makefile.in @@ -177,8 +177,10 @@ RANLIB = @RANLIB@ RM = @RM@ RMDIR = @RMDIR@ SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ STRIP = @STRIP@ TRUE = @TRUE@ VERSION = @VERSION@ diff --git a/qse/samples/sed/sed01.c b/qse/samples/sed/sed01.c index 767dd912..a6361cc7 100644 --- a/qse/samples/sed/sed01.c +++ b/qse/samples/sed/sed01.c @@ -71,7 +71,7 @@ oops: int qse_main (int argc, qse_achar_t* argv[]) { #if defined(_WIN32) - char locale[100]; + char locale[100]; UINT codepage = GetConsoleOutputCP(); if (codepage == CP_UTF8) { @@ -80,15 +80,14 @@ int qse_main (int argc, qse_achar_t* argv[]) } else { - sprintf (locale, ".%u", (unsigned int)codepage); - setlocale (LC_ALL, locale); + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); qse_setdflcmgr (qse_slmbcmgr); } #else - setlocale (LC_ALL, ""); + setlocale (LC_ALL, ""); qse_setdflcmgr (qse_slmbcmgr); #endif - return qse_runmain (argc, argv, sed_main); } diff --git a/qse/samples/sed/sed02.cpp b/qse/samples/sed/sed02.cpp index fc284007..d616045c 100644 --- a/qse/samples/sed/sed02.cpp +++ b/qse/samples/sed/sed02.cpp @@ -79,7 +79,7 @@ int sed_main (int argc, qse_char_t* argv[]) int qse_main (int argc, qse_achar_t* argv[]) { #if defined(_WIN32) - char locale[100]; + char locale[100]; UINT codepage = GetConsoleOutputCP(); if (codepage == CP_UTF8) { @@ -88,12 +88,12 @@ int qse_main (int argc, qse_achar_t* argv[]) } else { - sprintf (locale, ".%u", (unsigned int)codepage); - setlocale (LC_ALL, locale); + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); qse_setdflcmgr (qse_slmbcmgr); } #else - setlocale (LC_ALL, ""); + setlocale (LC_ALL, ""); qse_setdflcmgr (qse_slmbcmgr); #endif return qse_runmain (argc, argv, sed_main); diff --git a/qse/samples/sed/sed03.cpp b/qse/samples/sed/sed03.cpp index c46bbee7..f0f3cf9f 100644 --- a/qse/samples/sed/sed03.cpp +++ b/qse/samples/sed/sed03.cpp @@ -94,7 +94,7 @@ int sed_main (int argc, qse_char_t* argv[]) int qse_main (int argc, qse_achar_t* argv[]) { #if defined(_WIN32) - char locale[100]; + char locale[100]; UINT codepage = GetConsoleOutputCP(); if (codepage == CP_UTF8) { @@ -103,12 +103,12 @@ int qse_main (int argc, qse_achar_t* argv[]) } else { - sprintf (locale, ".%u", (unsigned int)codepage); - setlocale (LC_ALL, locale); + sprintf (locale, ".%u", (unsigned int)codepage); + setlocale (LC_ALL, locale); qse_setdflcmgr (qse_slmbcmgr); } #else - setlocale (LC_ALL, ""); + setlocale (LC_ALL, ""); qse_setdflcmgr (qse_slmbcmgr); #endif return qse_runmain (argc, argv, sed_main);