diff --git a/qse/cmd/awk/awk.c b/qse/cmd/awk/awk.c index 1d97e490..30e06e16 100644 --- a/qse/cmd/awk/awk.c +++ b/qse/cmd/awk/awk.c @@ -27,12 +27,15 @@ #include #include #include +#include #include + #include #include #include #include +#include #define ENABLE_CALLBACK #define ABORT(label) goto label @@ -1008,6 +1011,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, awk_main); } diff --git a/qse/cmd/sed/sed.c b/qse/cmd/sed/sed.c index 82bc2344..b7102f31 100644 --- a/qse/cmd/sed/sed.c +++ b/qse/cmd/sed/sed.c @@ -29,6 +29,9 @@ #include #include #include +#include + +#include #if defined(_WIN32) # include @@ -815,5 +818,23 @@ 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, sed_main); } diff --git a/qse/include/qse/cmn/Makefile.am b/qse/include/qse/cmn/Makefile.am index b0bab34f..a4b1112e 100644 --- a/qse/include/qse/cmn/Makefile.am +++ b/qse/include/qse/cmn/Makefile.am @@ -25,6 +25,7 @@ pkginclude_HEADERS = \ rex.h \ sio.h \ sll.h \ + slmb.h \ stdio.h \ str.h \ time.h \ diff --git a/qse/include/qse/cmn/Makefile.in b/qse/include/qse/cmn/Makefile.in index 7269b96a..5cde6535 100644 --- a/qse/include/qse/cmn/Makefile.in +++ b/qse/include/qse/cmn/Makefile.in @@ -53,8 +53,9 @@ SOURCES = DIST_SOURCES = am__pkginclude_HEADERS_DIST = alg.h chr.h dll.h env.h fio.h fma.h \ fmt.h fs.h gdl.h htb.h lda.h main.h map.h mbwc.h mem.h oht.h \ - opt.h path.h pio.h pma.h rbt.h rex.h sio.h sll.h stdio.h str.h \ - time.h tio.h tre.h utf8.h xma.h Mmgr.hpp StdMmgr.hpp Mmged.hpp + opt.h path.h pio.h pma.h rbt.h rex.h sio.h sll.h slmb.h \ + stdio.h str.h time.h tio.h tre.h utf8.h xma.h Mmgr.hpp \ + StdMmgr.hpp Mmged.hpp am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -225,8 +226,8 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ pkginclude_HEADERS = alg.h chr.h dll.h env.h fio.h fma.h fmt.h fs.h \ gdl.h htb.h lda.h main.h map.h mbwc.h mem.h oht.h opt.h path.h \ - pio.h pma.h rbt.h rex.h sio.h sll.h stdio.h str.h time.h tio.h \ - tre.h utf8.h xma.h $(am__append_1) + pio.h pma.h rbt.h rex.h sio.h sll.h slmb.h stdio.h str.h \ + time.h tio.h tre.h utf8.h xma.h $(am__append_1) all: all-am .SUFFIXES: diff --git a/qse/include/qse/cmn/mbwc.h b/qse/include/qse/cmn/mbwc.h index f5776613..3cc9923e 100644 --- a/qse/include/qse/cmn/mbwc.h +++ b/qse/include/qse/cmn/mbwc.h @@ -24,26 +24,12 @@ #include #include -/** - * The qse_mbstate_t type defines a structure large enough to hold - * the standard mbstate_t. - */ -typedef struct qse_mbstate_t qse_mbstate_t; -struct qse_mbstate_t -{ -#if defined(QSE_SIZEOF_MBSTATE_T) && (QSE_SIZEOF_MBSTATE_T > 0) - char dummy[QSE_SIZEOF_MBSTATE_T]; -#else - char dummy[1]; -#endif -}; - #ifdef __cplusplus extern "C" { #endif extern qse_cmgr_t* qse_utf8cmgr; -extern qse_cmgr_t* qse_loccmgr; +extern qse_cmgr_t* qse_slmbcmgr; qse_cmgr_t* qse_getdflcmgr ( void @@ -54,81 +40,6 @@ void qse_setdflcmgr ( ); -/* --------------------------------------------------- */ -/* CHARACTER CONVERSION */ -/* --------------------------------------------------- */ - -qse_size_t qse_mbrlen ( - const qse_mchar_t* mb, - qse_size_t mblen, - qse_mbstate_t* state -); - -qse_size_t qse_mbrtowc ( - const qse_mchar_t* mb, - qse_size_t mblen, - qse_wchar_t* wc, - qse_mbstate_t* state -); - -qse_size_t qse_wcrtomb ( - qse_wchar_t wc, - qse_mchar_t* mb, - qse_size_t mblen, - qse_mbstate_t* state -); - -/** - * The qse_mblen() function scans a multibyte sequence to get the number of - * bytes needed to form a wide character. It does not scan more than @a mblen - * bytes. - * @return number of bytes processed on success, - * 0 for invalid sequences, - * mblen + 1 for incomplete sequences - * @note This function can not handle conversion producing non-initial - * states. For each call, it assumes initial state. - */ -qse_size_t qse_mblen ( - const qse_mchar_t* mb, - qse_size_t mblen -); - -/** - * The qse_mbtowc() function converts a multibyte sequence to a wide character. - * It returns 0 if an invalid multibyte sequence is detected, mblen + 1 if the - * sequence is incomplete. It returns the number of bytes processed to form a - * wide character. - * @note This function can not handle conversion producing non-initial - * states. For each call, it assumes initial state. - */ -qse_size_t qse_mbtowc ( - const qse_mchar_t* mb, - qse_size_t mblen, - qse_wchar_t* wc -); - -/** - * The qse_wctomb() function converts a wide character to a multibyte sequence. - * It returns 0 if the wide character is illegal, mblen + 1 if mblen is not - * large enough to hold the multibyte sequence. On successful conversion, it - * returns the number of bytes in the sequence. - * @note This function can not handle conversion producing non-initial - * states. For each call, it assumes initial state. - */ -qse_size_t qse_wctomb ( - qse_wchar_t wc, - qse_mchar_t* mb, - qse_size_t mblen -); - -/** - * The qse_getmbcurmax() function returns the value of MB_CUR_MAX. - * Note that QSE_MBLEN_MAX defines MB_LEN_MAX. - */ -int qse_getmbcurmax ( - void -); - /* --------------------------------------------------- */ /* STRING CONVERSION USING CMGR */ /* --------------------------------------------------- */ diff --git a/qse/include/qse/cmn/slmb.h b/qse/include/qse/cmn/slmb.h new file mode 100644 index 00000000..e5fe60a7 --- /dev/null +++ b/qse/include/qse/cmn/slmb.h @@ -0,0 +1,126 @@ +/* + * $Id$ + * + Copyright 2006-2011 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 . + */ + +#ifndef _QSE_CMN_SLMB_H_ +#define _QSE_CMN_SLMB_H_ + +#include +#include + + +/** + * The qse_mbstate_t type defines a structure large enough to hold + * the standard mbstate_t. + */ +typedef struct qse_mbstate_t qse_mbstate_t; +struct qse_mbstate_t +{ +#if defined(QSE_SIZEOF_MBSTATE_T) && (QSE_SIZEOF_MBSTATE_T > 0) + char dummy[QSE_SIZEOF_MBSTATE_T]; +#else + char dummy[1]; +#endif +}; + +/* --------------------------------------------------- */ +/* SYSTEM LOCALE BASED CHARACTER CONVERSION */ +/* --------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#endif + +qse_size_t qse_slmbrlen ( + const qse_mchar_t* mb, + qse_size_t mblen, + qse_mbstate_t* state +); + +qse_size_t qse_slmbrtoslwc ( + const qse_mchar_t* mb, + qse_size_t mblen, + qse_wchar_t* wc, + qse_mbstate_t* state +); + +qse_size_t qse_slwcrtoslmb ( + qse_wchar_t wc, + qse_mchar_t* mb, + qse_size_t mblen, + qse_mbstate_t* state +); + +/** + * The qse_slmbtoslwc() function converts a multibyte sequence to a wide character. + * It returns 0 if an invalid multibyte sequence is detected, mblen + 1 if the + * sequence is incomplete. It returns the number of bytes processed to form a + * wide character. + * @note This function can not handle conversion producing non-initial + * states. For each call, it assumes initial state. + */ +qse_size_t qse_slmbtoslwc ( + const qse_mchar_t* mb, + qse_size_t mblen, + qse_wchar_t* wc +); + +/** + * The qse_slwctoslmb() function converts a wide character to a multibyte sequence. + * It returns 0 if the wide character is illegal, mblen + 1 if mblen is not + * large enough to hold the multibyte sequence. On successful conversion, it + * returns the number of bytes in the sequence. + * @note This function can not handle conversion producing non-initial + * states. For each call, it assumes initial state. + */ +qse_size_t qse_slwctoslmb ( + qse_wchar_t wc, + qse_mchar_t* mb, + qse_size_t mblen +); + +/** + * The qse_slmblen() function scans a multibyte sequence to get the number of + * bytes needed to form a wide character. It does not scan more than @a mblen + * bytes. + * @return number of bytes processed on success, + * 0 for invalid sequences, + * mblen + 1 for incomplete sequences + * @note This function can not handle conversion producing non-initial + * states. For each call, it assumes initial state. + */ +qse_size_t qse_slmblen ( + const qse_mchar_t* mb, + qse_size_t mblen +); + +/** + * The qse_slmblenmax() function returns the value of MB_CUR_MAX. + * Note that QSE_MBLEN_MAX defines MB_LEN_MAX. + */ +int qse_slmblenmax ( + void +); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/qse/lib/cmn/Makefile.am b/qse/lib/cmn/Makefile.am index 039ca8ee..d388e09a 100644 --- a/qse/lib/cmn/Makefile.am +++ b/qse/lib/cmn/Makefile.am @@ -38,7 +38,6 @@ libqsecmn_la_SOURCES = \ fs-move.c \ main.c \ mbwc.c \ - mbwc-chr.c \ mbwc-str.c \ mem.c \ oht.c \ @@ -51,6 +50,7 @@ libqsecmn_la_SOURCES = \ rex.c \ sio.c \ sll.c \ + slmb.c \ stdio.c \ str-beg.c \ str-cat.c \ diff --git a/qse/lib/cmn/Makefile.in b/qse/lib/cmn/Makefile.in index 4a2f5e92..8576f795 100644 --- a/qse/lib/cmn/Makefile.in +++ b/qse/lib/cmn/Makefile.in @@ -78,9 +78,9 @@ libqsecmn_la_DEPENDENCIES = am_libqsecmn_la_OBJECTS = alg-rand.lo alg-search.lo alg-sort.lo \ assert.lo chr.lo dll.lo env.lo gdl.lo htb.lo lda.lo fio.lo \ fma.lo fmt.lo fs.lo fs-err.lo fs-move.lo main.lo mbwc.lo \ - mbwc-chr.lo mbwc-str.lo mem.lo oht.lo opt.lo path-basename.lo \ + mbwc-str.lo mem.lo oht.lo opt.lo path-basename.lo \ path-canon.lo pio.lo pma.lo rbt.lo rex.lo sio.lo sll.lo \ - stdio.lo str-beg.lo str-cat.lo str-chr.lo str-cnv.lo \ + slmb.lo stdio.lo str-beg.lo str-cat.lo str-chr.lo str-cnv.lo \ str-cmp.lo str-cpy.lo str-del.lo str-dup.lo str-dynm.lo \ str-dynw.lo str-end.lo str-excl.lo str-fcpy.lo str-fnmat.lo \ str-incl.lo str-len.lo str-pac.lo str-pbrk.lo str-put.lo \ @@ -308,7 +308,6 @@ libqsecmn_la_SOURCES = \ fs-move.c \ main.c \ mbwc.c \ - mbwc-chr.c \ mbwc-str.c \ mem.c \ oht.c \ @@ -321,6 +320,7 @@ libqsecmn_la_SOURCES = \ rex.c \ sio.c \ sll.c \ + slmb.c \ stdio.c \ str-beg.c \ str-cat.c \ @@ -466,7 +466,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htb.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lda.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbwc-chr.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbwc-str.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbwc.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Plo@am__quote@ @@ -480,6 +479,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rex.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sio.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sll.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/slmb.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdio.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str-beg.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str-cat.Plo@am__quote@ diff --git a/qse/lib/cmn/env.c b/qse/lib/cmn/env.c index 9d1e2db9..20e0fb2e 100644 --- a/qse/lib/cmn/env.c +++ b/qse/lib/cmn/env.c @@ -352,9 +352,9 @@ int qse_env_insertm ( qse_wchar_t* namedup, * valuedup; int n; - namedup = qse_mbstowcsdup (name, env->mmgr); + namedup = qse_mbstowcsdup (name, env->mmgr); /* TODO: ignroe mbwcerr */ if (namedup == QSE_NULL) return -1; - valuedup = qse_mbstowcsdup (value, env->mmgr); + valuedup = qse_mbstowcsdup (value, env->mmgr); /* TODO: ignroe mbwcerr */ if (valuedup == QSE_NULL) { QSE_MMGR_FREE (env->mmgr, namedup); @@ -398,7 +398,7 @@ int qse_env_deletem (qse_env_t* env, const qse_mchar_t* name) qse_wchar_t* namedup; int n; - namedup = qse_mbstowcsdup (name, env->mmgr); + namedup = qse_mbstowcsdup (name, env->mmgr); /* TODO: ignroe mbwcerr */ if (namedup == QSE_NULL) return -1; n = deletew (env, namedup); @@ -466,7 +466,7 @@ static qse_wchar_t* get_env (qse_env_t* env, const qse_wchar_t* name, int* free) qse_wchar_t* dup; qse_wchar_t* eq; - dup = qse_mbstowcsdup (*p, env->mmgr); + dup = qse_mbstowcsdup (*p, env->mmgr); /* TODO: ignroe mbwcerr */ if (dup == QSE_NULL) return QSE_NULL; eq = qse_wcsbeg (dup, name); @@ -544,7 +544,7 @@ int qse_env_insertsysm (qse_env_t* env, const qse_mchar_t* name) qse_wchar_t* namedup; int ret = -1; - namedup = qse_mbstowcsdup (name, env->mmgr); + namedup = qse_mbstowcsdup (name, env->mmgr); /* TODO: ignroe mbwcerr */ if (namedup) { ret = qse_env_insertsysw (env, namedup); @@ -627,7 +627,7 @@ done: qse_wchar_t* dup; int n; - dup = qse_mbstowcsdup (*p, env->mmgr); + dup = qse_mbstowcsdup (*p, env->mmgr); /* TODO: ignroe mbwcerr */ if (dup == QSE_NULL) return -1; n = add_envstrw (env, dup); QSE_MMGR_FREE (env->mmgr, dup); diff --git a/qse/lib/cmn/main.c b/qse/lib/cmn/main.c index 8de57236..8edd5a3c 100644 --- a/qse/lib/cmn/main.c +++ b/qse/lib/cmn/main.c @@ -20,15 +20,11 @@ #include #include -#include #include "mem.h" int qse_runmain ( int argc, qse_achar_t* argv[], qse_runmain_handler_t handler) { - /* TODO: remove dependency on setlocale */ - setlocale (LC_ALL, ""); - #if (defined(QSE_ACHAR_IS_MCHAR) && defined(QSE_CHAR_IS_MCHAR)) || \ (defined(QSE_ACHAR_IS_WCHAR) && defined(QSE_CHAR_IS_WCHAR)) { @@ -75,8 +71,6 @@ int qse_runmainwithenv ( int argc, qse_achar_t* argv[], qse_achar_t* envp[], qse_runmainwithenv_handler_t handler) { - setlocale (LC_ALL, ""); /* TODO: remove dependency on setlocale */ - #if (defined(QSE_ACHAR_IS_MCHAR) && defined(QSE_CHAR_IS_MCHAR)) || \ (defined(QSE_ACHAR_IS_WCHAR) && defined(QSE_CHAR_IS_WCHAR)) { diff --git a/qse/lib/cmn/mbwc.c b/qse/lib/cmn/mbwc.c index 939a2aba..3421eecc 100644 --- a/qse/lib/cmn/mbwc.c +++ b/qse/lib/cmn/mbwc.c @@ -19,13 +19,21 @@ */ #include +#include #include +/* TODO: there is no guarantee that slwc is a unicode charater or vice versa. + * the ctype handling functions should be made wide-character + * dependent. + */ + +/* TODO: binary cmgr -> simply expands a byte to wchar and vice versa. */ + static qse_cmgr_t builtin_cmgr[] = { { - qse_mbtowc, - qse_wctomb + qse_slmbtoslwc, + qse_slwctoslmb }, { @@ -34,7 +42,7 @@ static qse_cmgr_t builtin_cmgr[] = } }; -qse_cmgr_t* qse_loccmgr = &builtin_cmgr[0]; +qse_cmgr_t* qse_slmbcmgr = &builtin_cmgr[0]; qse_cmgr_t* qse_utf8cmgr = &builtin_cmgr[1]; static qse_cmgr_t* dfl_cmgr = &builtin_cmgr[0]; diff --git a/qse/lib/cmn/mbwc-chr.c b/qse/lib/cmn/slmb.c similarity index 84% rename from qse/lib/cmn/mbwc-chr.c rename to qse/lib/cmn/slmb.c index 85d819b6..bfb11a72 100644 --- a/qse/lib/cmn/mbwc-chr.c +++ b/qse/lib/cmn/slmb.c @@ -1,5 +1,5 @@ /* - * $Id: chr-cnv.c 556 2011-08-31 15:43:46Z hyunghwan.chung $ + * $Id$ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -18,8 +18,7 @@ License along with QSE. If not, see . */ -#include -#include +#include #include "mem.h" #if !defined(QSE_HAVE_CONFIG_H) @@ -39,7 +38,7 @@ # include #endif -qse_size_t qse_mbrlen ( +qse_size_t qse_slmbrlen ( const qse_mchar_t* mb, qse_size_t mbl, qse_mbstate_t* state) { #if defined(HAVE_MBRLEN) @@ -64,7 +63,7 @@ qse_size_t qse_mbrlen ( #endif } -qse_size_t qse_mbrtowc ( +qse_size_t qse_slmbrtoslwc ( const qse_mchar_t* mb, qse_size_t mbl, qse_wchar_t* wc, qse_mbstate_t* state) { @@ -86,7 +85,7 @@ qse_size_t qse_mbrtowc ( #endif } -qse_size_t qse_wcrtomb ( +qse_size_t qse_slwcrtoslmb ( qse_wchar_t wc, qse_mchar_t* mb, qse_size_t mbl, qse_mbstate_t* state) { @@ -132,26 +131,25 @@ qse_size_t qse_wcrtomb ( * mbrtowc(3) do produce non-initial states when interrupted in the middle * of a character. */ -qse_size_t qse_mblen (const qse_mchar_t* mb, qse_size_t mbl) +qse_size_t qse_slmblen (const qse_mchar_t* mb, qse_size_t mbl) { qse_mbstate_t state = { { 0, } }; - return qse_mbrlen (mb, mbl, &state); + return qse_slmbrlen (mb, mbl, &state); } -qse_size_t qse_mbtowc (const qse_mchar_t* mb, qse_size_t mbl, qse_wchar_t* wc) +qse_size_t qse_slmbtoslwc (const qse_mchar_t* mb, qse_size_t mbl, qse_wchar_t* wc) { qse_mbstate_t state = { { 0, } }; - return qse_mbrtowc (mb, mbl, wc, &state); + return qse_slmbrtoslwc (mb, mbl, wc, &state); } -qse_size_t qse_wctomb (qse_wchar_t wc, qse_mchar_t* mb, qse_size_t mbl) +qse_size_t qse_slwctoslmb (qse_wchar_t wc, qse_mchar_t* mb, qse_size_t mbl) { qse_mbstate_t state = { { 0, } }; - return qse_wcrtomb (wc, mb, mbl, &state); + return qse_slwcrtoslmb (wc, mb, mbl, &state); } -int qse_mbcurmax (void) +int qse_slmblenmax (void) { -/* TODO: consider other encodings */ - return (QSE_UTF8LEN_MAX > MB_CUR_MAX)? QSE_UTF8LEN_MAX: MB_CUR_MAX; + return MB_CUR_MAX; } diff --git a/qse/lib/cmn/tio.c b/qse/lib/cmn/tio.c index fca4070c..3ab9951c 100644 --- a/qse/lib/cmn/tio.c +++ b/qse/lib/cmn/tio.c @@ -19,7 +19,7 @@ */ #include -#include +#include #include "mem.h" QSE_IMPLEMENT_COMMON_FUNCTIONS (tio) @@ -52,18 +52,10 @@ int qse_tio_close (qse_tio_t* tio) int qse_tio_init (qse_tio_t* tio, qse_mmgr_t* mmgr, int flags) { - /* TODO: set this default_cmgr differently depending on - * build options and platforms */ - static qse_cmgr_t default_cmgr = - { - qse_utf8touc, - qse_uctoutf8 - }; - QSE_MEMSET (tio, 0, QSE_SIZEOF(*tio)); tio->mmgr = mmgr; - tio->cmgr = &default_cmgr; + tio->cmgr = qse_getdflcmgr(); /* mask off internal bits when storing the flags for safety */ tio->flags = flags & ~(QSE_TIO_DYNINBUF | QSE_TIO_DYNOUTBUF); diff --git a/qse/lib/cmn/tre-compile.c b/qse/lib/cmn/tre-compile.c index 264a4766..d6af5430 100644 --- a/qse/lib/cmn/tre-compile.c +++ b/qse/lib/cmn/tre-compile.c @@ -2083,6 +2083,9 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags) /* If in eight bit mode, compute a table of characters that can be the first character of a match. */ tnfa->first_char = -1; + +/* QSE: deleted */ +/* if (TRE_MB_CUR_MAX == 1 && !tmp_ast_l->nullable) { int count = 0; @@ -2125,6 +2128,8 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags) } else tnfa->firstpos_chars = NULL; +*/ +/* END QSE */ p = tree->firstpos; @@ -2273,8 +2278,12 @@ void tre_free (regex_t *preg) if (tnfa->tag_directions) xfree(preg->mmgr,tnfa->tag_directions); +/* QSE: deleted */ +/* if (tnfa->firstpos_chars) xfree(preg->mmgr,tnfa->firstpos_chars); +*/ +/* END QSE */ if (tnfa->minimal_tags) xfree(preg->mmgr,tnfa->minimal_tags); xfree(preg->mmgr,tnfa); diff --git a/qse/lib/cmn/tre-parse.c b/qse/lib/cmn/tre-parse.c index da97e45e..623b8676 100644 --- a/qse/lib/cmn/tre-parse.c +++ b/qse/lib/cmn/tre-parse.c @@ -166,6 +166,7 @@ tre_new_item(tre_mem_t mem, int min, int max, int *i, int *max_i, } +#if defined(QSE_CHAR_IS_MCHAR) /* Expands a character class to character ranges. */ static reg_errcode_t tre_expand_ctype(tre_mem_t mem, tre_ctype_t class, tre_ast_node_t ***items, @@ -174,7 +175,9 @@ tre_expand_ctype(tre_mem_t mem, tre_ctype_t class, tre_ast_node_t ***items, reg_errcode_t status = REG_OK; tre_cint_t c; int j, min = -1, max = 0; - assert(TRE_MB_CUR_MAX == 1); + /* QSE: deleted */ + /*assert(TRE_MB_CUR_MAX == 1);*/ + /* END QSE */ DPRINT((" expanding class to character ranges\n")); for (j = 0; (j < 256) && (status == REG_OK); j++) @@ -198,6 +201,7 @@ tre_expand_ctype(tre_mem_t mem, tre_ctype_t class, tre_ast_node_t ***items, status = tre_new_item(mem, min, max, i, max_i, items); return status; } +#endif static int @@ -294,13 +298,20 @@ tre_parse_bracket_items(tre_parse_ctx_t *ctx, int negate, if (qse_getctypebyxname (re + 2, len, &class) <= -1) status = REG_ECTYPE; /* Optimize character classes for 8 bit character sets. */ - if (status == REG_OK && TRE_MB_CUR_MAX == 1) +#if defined(QSE_CHAR_IS_MCHAR) + /* QSE: not possible to count on MB_CUR_MAX since + * this library is designed to support per-object + * or per-context character encoding using qse_cmgr_t */ + /* if (status == REG_OK && TRE_MB_CUR_MAX == 1) */ + /* END QSE */ + if (status == REG_OK) { status = tre_expand_ctype(ctx->mem, class, items, &i, &max_i, ctx->cflags); class = (tre_ctype_t)0; skip = 1; } +#endif re = endptr + 2; } } diff --git a/qse/lib/cmn/tre.h b/qse/lib/cmn/tre.h index 4624a9cc..69feadbc 100644 --- a/qse/lib/cmn/tre.h +++ b/qse/lib/cmn/tre.h @@ -135,10 +135,9 @@ SUBMATCH[4] = [defg] #ifdef QSE_CHAR_IS_WCHAR # define TRE_WCHAR -/* -# define TRE_MULTIBYTE -# define TRE_MBSTATE -*/ + +/*# define TRE_MULTIBYTE*/ +/*# define TRE_MBSTATE*/ #endif #define TRE_REGEX_T_FIELD value @@ -261,14 +260,16 @@ typedef qse_pma_t* tre_mem_t; /* Define the character types and functions. */ #ifdef TRE_WCHAR # define TRE_CHAR_MAX QSE_TYPE_MAX(qse_wchar_t) +/* # ifdef TRE_MULTIBYTE # define TRE_MB_CUR_MAX (qse_getmbcurmax()) -# else /* !TRE_MULTIBYTE */ +# else # define TRE_MB_CUR_MAX 1 -# endif /* !TRE_MULTIBYTE */ +# endif +*/ #else /* !TRE_WCHAR */ # define TRE_CHAR_MAX 255 -# define TRE_MB_CUR_MAX 1 +/*# define TRE_MB_CUR_MAX 1*/ #endif /* !TRE_WCHAR */ #define DPRINT(msg) @@ -394,7 +395,9 @@ struct tnfa tre_tnfa_transition_t *initial; tre_tnfa_transition_t *final; tre_submatch_data_t *submatch_data; +#if 0 char *firstpos_chars; +#endif int first_char; unsigned int num_submatches; tre_tag_direction_t *tag_directions; diff --git a/qse/samples/awk/awk05.cpp b/qse/samples/awk/awk05.cpp index 45d6f25e..10410d19 100644 --- a/qse/samples/awk/awk05.cpp +++ b/qse/samples/awk/awk05.cpp @@ -21,6 +21,12 @@ #include #include #include +#include + +#include +#if defined(_WIN32) +# include +#endif static void print_error ( const QSE::StdAwk::loc_t& loc, const QSE::StdAwk::char_t* msg) @@ -76,5 +82,23 @@ 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]; + 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,awk_main); } diff --git a/qse/samples/awk/awk06.cpp b/qse/samples/awk/awk06.cpp index 3c82407b..d69f99bc 100644 --- a/qse/samples/awk/awk06.cpp +++ b/qse/samples/awk/awk06.cpp @@ -21,6 +21,12 @@ #include #include #include +#include + +#include +#if defined(_WIN32) +# include +#endif static void print_error ( const QSE::StdAwk::loc_t& loc, const QSE::StdAwk::char_t* msg) @@ -103,5 +109,23 @@ 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]; + 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,awk_main); } diff --git a/qse/samples/awk/awk07.cpp b/qse/samples/awk/awk07.cpp index 4c094bd9..71241775 100644 --- a/qse/samples/awk/awk07.cpp +++ b/qse/samples/awk/awk07.cpp @@ -21,6 +21,13 @@ #include #include #include +#include + +#include +#if defined(_WIN32) +# include +#endif + static void print_error ( const QSE::StdAwk::loc_t& loc, const QSE::StdAwk::char_t* msg) @@ -147,5 +154,23 @@ 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]; + 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,awk_main); } diff --git a/qse/samples/awk/awk08.cpp b/qse/samples/awk/awk08.cpp index 60e190c1..b8c76f0c 100644 --- a/qse/samples/awk/awk08.cpp +++ b/qse/samples/awk/awk08.cpp @@ -21,9 +21,12 @@ #include #include #include +#include #include #include +#include + #if defined(_WIN32) # include #elif defined(__OS2__) diff --git a/qse/samples/cmn/Makefile.am b/qse/samples/cmn/Makefile.am index 6f053ca1..d9b55bad 100644 --- a/qse/samples/cmn/Makefile.am +++ b/qse/samples/cmn/Makefile.am @@ -7,46 +7,70 @@ AM_CPPFLAGS = \ bin_PROGRAMS = \ - xma fma pma chr \ + chr01 \ + env \ + dll \ + fio01 \ + fio02 \ + fma \ + fmt01 \ + fmt02 \ + fs01 \ + htb \ + lda \ + main01 \ + main02 \ + mbwc01 \ + mbwc02 \ + oht \ + path01 \ + pio \ + pma \ + rex01 \ + rbt \ + sio01 \ + sio02 \ + sio03 \ + sll \ + slmb01 \ str01 \ - mbwc01 mbwc02 \ - sll dll lda oht htb rbt fio01 fio02 pio \ - sio01 sio02 sio03 \ - time main main2 rex01 env path01 tre01 \ - fmt01 fmt02 fs01 - + time \ + tre01 \ + xma + LDFLAGS = -L../../lib/cmn LDADD = -lqsecmn -xma_SOURCES = xma.c -fma_SOURCES = fma.c -pma_SOURCES = pma.c -chr_SOURCES = chr.c -str01_SOURCES = str01.c -mbwc01_SOURCES = mbwc01.c -mbwc02_SOURCES = mbwc02.c -sll_SOURCES = sll.c +chr01_SOURCES = chr01.c +env_SOURCES = env.c dll_SOURCES = dll.c -lda_SOURCES = lda.c -oht_SOURCES = oht.c -htb_SOURCES = htb.c -rbt_SOURCES = rbt.c fio01_SOURCES = fio01.c fio02_SOURCES = fio02.c -pio_SOURCES = pio.c -sio01_SOURCES = sio01.c -sio02_SOURCES = sio02.c -sio03_SOURCES = sio03.c -time_SOURCES = time.c -main_SOURCES = main.c -main2_SOURCES = main2.c -rex01_SOURCES = rex01.c -env_SOURCES = env.c -path01_SOURCES = path01.c -tre01_SOURCES = tre01.c +fma_SOURCES = fma.c fmt01_SOURCES = fmt01.c fmt02_SOURCES = fmt02.c fs01_SOURCES = fs01.c +htb_SOURCES = htb.c +lda_SOURCES = lda.c +main01_SOURCES = main01.c +main02_SOURCES = main02.c +mbwc01_SOURCES = mbwc01.c +mbwc02_SOURCES = mbwc02.c +oht_SOURCES = oht.c +path01_SOURCES = path01.c +pio_SOURCES = pio.c +pma_SOURCES = pma.c +rex01_SOURCES = rex01.c +rbt_SOURCES = rbt.c +sio01_SOURCES = sio01.c +sio02_SOURCES = sio02.c +sio03_SOURCES = sio03.c +sll_SOURCES = sll.c +slmb01_SOURCES = slmb01.c +str01_SOURCES = str01.c +time_SOURCES = time.c +tre01_SOURCES = tre01.c +xma_SOURCES = xma.c if ENABLE_CXX diff --git a/qse/samples/cmn/Makefile.in b/qse/samples/cmn/Makefile.in index dfadd000..706a285e 100644 --- a/qse/samples/cmn/Makefile.in +++ b/qse/samples/cmn/Makefile.in @@ -34,14 +34,14 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -bin_PROGRAMS = xma$(EXEEXT) fma$(EXEEXT) pma$(EXEEXT) chr$(EXEEXT) \ - str01$(EXEEXT) mbwc01$(EXEEXT) mbwc02$(EXEEXT) sll$(EXEEXT) \ - dll$(EXEEXT) lda$(EXEEXT) oht$(EXEEXT) htb$(EXEEXT) \ - rbt$(EXEEXT) fio01$(EXEEXT) fio02$(EXEEXT) pio$(EXEEXT) \ - sio01$(EXEEXT) sio02$(EXEEXT) sio03$(EXEEXT) time$(EXEEXT) \ - main$(EXEEXT) main2$(EXEEXT) rex01$(EXEEXT) env$(EXEEXT) \ - path01$(EXEEXT) tre01$(EXEEXT) fmt01$(EXEEXT) fmt02$(EXEEXT) \ - fs01$(EXEEXT) +bin_PROGRAMS = chr01$(EXEEXT) env$(EXEEXT) dll$(EXEEXT) fio01$(EXEEXT) \ + fio02$(EXEEXT) fma$(EXEEXT) fmt01$(EXEEXT) fmt02$(EXEEXT) \ + fs01$(EXEEXT) htb$(EXEEXT) lda$(EXEEXT) main01$(EXEEXT) \ + main02$(EXEEXT) mbwc01$(EXEEXT) mbwc02$(EXEEXT) oht$(EXEEXT) \ + path01$(EXEEXT) pio$(EXEEXT) pma$(EXEEXT) rex01$(EXEEXT) \ + rbt$(EXEEXT) sio01$(EXEEXT) sio02$(EXEEXT) sio03$(EXEEXT) \ + sll$(EXEEXT) slmb01$(EXEEXT) str01$(EXEEXT) time$(EXEEXT) \ + tre01$(EXEEXT) xma$(EXEEXT) subdir = samples/cmn DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -58,10 +58,10 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) -am_chr_OBJECTS = chr.$(OBJEXT) -chr_OBJECTS = $(am_chr_OBJECTS) -chr_LDADD = $(LDADD) -chr_DEPENDENCIES = +am_chr01_OBJECTS = chr01.$(OBJEXT) +chr01_OBJECTS = $(am_chr01_OBJECTS) +chr01_LDADD = $(LDADD) +chr01_DEPENDENCIES = am_dll_OBJECTS = dll.$(OBJEXT) dll_OBJECTS = $(am_dll_OBJECTS) dll_LDADD = $(LDADD) @@ -102,14 +102,14 @@ am_lda_OBJECTS = lda.$(OBJEXT) lda_OBJECTS = $(am_lda_OBJECTS) lda_LDADD = $(LDADD) lda_DEPENDENCIES = -am_main_OBJECTS = main.$(OBJEXT) -main_OBJECTS = $(am_main_OBJECTS) -main_LDADD = $(LDADD) -main_DEPENDENCIES = -am_main2_OBJECTS = main2.$(OBJEXT) -main2_OBJECTS = $(am_main2_OBJECTS) -main2_LDADD = $(LDADD) -main2_DEPENDENCIES = +am_main01_OBJECTS = main01.$(OBJEXT) +main01_OBJECTS = $(am_main01_OBJECTS) +main01_LDADD = $(LDADD) +main01_DEPENDENCIES = +am_main02_OBJECTS = main02.$(OBJEXT) +main02_OBJECTS = $(am_main02_OBJECTS) +main02_LDADD = $(LDADD) +main02_DEPENDENCIES = am_mbwc01_OBJECTS = mbwc01.$(OBJEXT) mbwc01_OBJECTS = $(am_mbwc01_OBJECTS) mbwc01_LDADD = $(LDADD) @@ -158,6 +158,10 @@ am_sll_OBJECTS = sll.$(OBJEXT) sll_OBJECTS = $(am_sll_OBJECTS) sll_LDADD = $(LDADD) sll_DEPENDENCIES = +am_slmb01_OBJECTS = slmb01.$(OBJEXT) +slmb01_OBJECTS = $(am_slmb01_OBJECTS) +slmb01_LDADD = $(LDADD) +slmb01_DEPENDENCIES = am_str01_OBJECTS = str01.$(OBJEXT) str01_OBJECTS = $(am_str01_OBJECTS) str01_LDADD = $(LDADD) @@ -187,24 +191,26 @@ CCLD = $(CC) LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ -SOURCES = $(chr_SOURCES) $(dll_SOURCES) $(env_SOURCES) \ +SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \ $(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \ $(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \ - $(htb_SOURCES) $(lda_SOURCES) $(main_SOURCES) $(main2_SOURCES) \ - $(mbwc01_SOURCES) $(mbwc02_SOURCES) $(oht_SOURCES) \ - $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) $(rbt_SOURCES) \ - $(rex01_SOURCES) $(sio01_SOURCES) $(sio02_SOURCES) \ - $(sio03_SOURCES) $(sll_SOURCES) $(str01_SOURCES) \ - $(time_SOURCES) $(tre01_SOURCES) $(xma_SOURCES) -DIST_SOURCES = $(chr_SOURCES) $(dll_SOURCES) $(env_SOURCES) \ + $(htb_SOURCES) $(lda_SOURCES) $(main01_SOURCES) \ + $(main02_SOURCES) $(mbwc01_SOURCES) $(mbwc02_SOURCES) \ + $(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \ + $(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \ + $(sio02_SOURCES) $(sio03_SOURCES) $(sll_SOURCES) \ + $(slmb01_SOURCES) $(str01_SOURCES) $(time_SOURCES) \ + $(tre01_SOURCES) $(xma_SOURCES) +DIST_SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \ $(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \ $(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \ - $(htb_SOURCES) $(lda_SOURCES) $(main_SOURCES) $(main2_SOURCES) \ - $(mbwc01_SOURCES) $(mbwc02_SOURCES) $(oht_SOURCES) \ - $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) $(rbt_SOURCES) \ - $(rex01_SOURCES) $(sio01_SOURCES) $(sio02_SOURCES) \ - $(sio03_SOURCES) $(sll_SOURCES) $(str01_SOURCES) \ - $(time_SOURCES) $(tre01_SOURCES) $(xma_SOURCES) + $(htb_SOURCES) $(lda_SOURCES) $(main01_SOURCES) \ + $(main02_SOURCES) $(mbwc01_SOURCES) $(mbwc02_SOURCES) \ + $(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \ + $(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \ + $(sio02_SOURCES) $(sio03_SOURCES) $(sll_SOURCES) \ + $(slmb01_SOURCES) $(str01_SOURCES) $(time_SOURCES) \ + $(tre01_SOURCES) $(xma_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -356,35 +362,36 @@ AM_CPPFLAGS = \ -I$(includedir) LDADD = -lqsecmn -xma_SOURCES = xma.c -fma_SOURCES = fma.c -pma_SOURCES = pma.c -chr_SOURCES = chr.c -str01_SOURCES = str01.c -mbwc01_SOURCES = mbwc01.c -mbwc02_SOURCES = mbwc02.c -sll_SOURCES = sll.c +chr01_SOURCES = chr01.c +env_SOURCES = env.c dll_SOURCES = dll.c -lda_SOURCES = lda.c -oht_SOURCES = oht.c -htb_SOURCES = htb.c -rbt_SOURCES = rbt.c fio01_SOURCES = fio01.c fio02_SOURCES = fio02.c -pio_SOURCES = pio.c -sio01_SOURCES = sio01.c -sio02_SOURCES = sio02.c -sio03_SOURCES = sio03.c -time_SOURCES = time.c -main_SOURCES = main.c -main2_SOURCES = main2.c -rex01_SOURCES = rex01.c -env_SOURCES = env.c -path01_SOURCES = path01.c -tre01_SOURCES = tre01.c +fma_SOURCES = fma.c fmt01_SOURCES = fmt01.c fmt02_SOURCES = fmt02.c fs01_SOURCES = fs01.c +htb_SOURCES = htb.c +lda_SOURCES = lda.c +main01_SOURCES = main01.c +main02_SOURCES = main02.c +mbwc01_SOURCES = mbwc01.c +mbwc02_SOURCES = mbwc02.c +oht_SOURCES = oht.c +path01_SOURCES = path01.c +pio_SOURCES = pio.c +pma_SOURCES = pma.c +rex01_SOURCES = rex01.c +rbt_SOURCES = rbt.c +sio01_SOURCES = sio01.c +sio02_SOURCES = sio02.c +sio03_SOURCES = sio03.c +sll_SOURCES = sll.c +slmb01_SOURCES = slmb01.c +str01_SOURCES = str01.c +time_SOURCES = time.c +tre01_SOURCES = tre01.c +xma_SOURCES = xma.c all: all-am .SUFFIXES: @@ -462,9 +469,9 @@ clean-binPROGRAMS: list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list -chr$(EXEEXT): $(chr_OBJECTS) $(chr_DEPENDENCIES) - @rm -f chr$(EXEEXT) - $(LINK) $(chr_OBJECTS) $(chr_LDADD) $(LIBS) +chr01$(EXEEXT): $(chr01_OBJECTS) $(chr01_DEPENDENCIES) + @rm -f chr01$(EXEEXT) + $(LINK) $(chr01_OBJECTS) $(chr01_LDADD) $(LIBS) dll$(EXEEXT): $(dll_OBJECTS) $(dll_DEPENDENCIES) @rm -f dll$(EXEEXT) $(LINK) $(dll_OBJECTS) $(dll_LDADD) $(LIBS) @@ -495,12 +502,12 @@ htb$(EXEEXT): $(htb_OBJECTS) $(htb_DEPENDENCIES) lda$(EXEEXT): $(lda_OBJECTS) $(lda_DEPENDENCIES) @rm -f lda$(EXEEXT) $(LINK) $(lda_OBJECTS) $(lda_LDADD) $(LIBS) -main$(EXEEXT): $(main_OBJECTS) $(main_DEPENDENCIES) - @rm -f main$(EXEEXT) - $(LINK) $(main_OBJECTS) $(main_LDADD) $(LIBS) -main2$(EXEEXT): $(main2_OBJECTS) $(main2_DEPENDENCIES) - @rm -f main2$(EXEEXT) - $(LINK) $(main2_OBJECTS) $(main2_LDADD) $(LIBS) +main01$(EXEEXT): $(main01_OBJECTS) $(main01_DEPENDENCIES) + @rm -f main01$(EXEEXT) + $(LINK) $(main01_OBJECTS) $(main01_LDADD) $(LIBS) +main02$(EXEEXT): $(main02_OBJECTS) $(main02_DEPENDENCIES) + @rm -f main02$(EXEEXT) + $(LINK) $(main02_OBJECTS) $(main02_LDADD) $(LIBS) mbwc01$(EXEEXT): $(mbwc01_OBJECTS) $(mbwc01_DEPENDENCIES) @rm -f mbwc01$(EXEEXT) $(LINK) $(mbwc01_OBJECTS) $(mbwc01_LDADD) $(LIBS) @@ -537,6 +544,9 @@ sio03$(EXEEXT): $(sio03_OBJECTS) $(sio03_DEPENDENCIES) sll$(EXEEXT): $(sll_OBJECTS) $(sll_DEPENDENCIES) @rm -f sll$(EXEEXT) $(LINK) $(sll_OBJECTS) $(sll_LDADD) $(LIBS) +slmb01$(EXEEXT): $(slmb01_OBJECTS) $(slmb01_DEPENDENCIES) + @rm -f slmb01$(EXEEXT) + $(LINK) $(slmb01_OBJECTS) $(slmb01_LDADD) $(LIBS) str01$(EXEEXT): $(str01_OBJECTS) $(str01_DEPENDENCIES) @rm -f str01$(EXEEXT) $(LINK) $(str01_OBJECTS) $(str01_LDADD) $(LIBS) @@ -556,7 +566,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chr.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chr01.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dll.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/env.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fio01.Po@am__quote@ @@ -567,8 +577,8 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs01.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htb.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lda.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main2.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main01.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main02.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbwc01.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbwc02.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oht.Po@am__quote@ @@ -581,6 +591,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sio02.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sio03.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sll.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/slmb01.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str01.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tre01.Po@am__quote@ diff --git a/qse/samples/cmn/chr01.c b/qse/samples/cmn/chr01.c new file mode 100644 index 00000000..bbe08e77 --- /dev/null +++ b/qse/samples/cmn/chr01.c @@ -0,0 +1,53 @@ +#include +#include +#include + +#include + +#if defined(_WIN32) +# include +#endif + +#define R(f) \ + do { \ + qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \ + if (f() == -1) return -1; \ + } while (0) + +static int test1 (void) +{ + qse_char_t c; + + for (c = QSE_T('a'); c <= QSE_T('z'); c++) + { + qse_printf (QSE_T("%c => %c\n"), c, QSE_TOUPPER(c)); + } + + return 0; +} + +int main () +{ +#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 + + R (test1); + + return 0; +} diff --git a/qse/samples/cmn/fmt01.c b/qse/samples/cmn/fmt01.c index f3c0d09f..11b2f214 100644 --- a/qse/samples/cmn/fmt01.c +++ b/qse/samples/cmn/fmt01.c @@ -1,7 +1,13 @@ #include #include +#include #include +#include +#if defined(_WIN32) +# include +#endif + static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[]) { qse_char_t buf[19]; @@ -50,6 +56,24 @@ static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[]) int qse_main (int argc, qse_achar_t* argv[], qse_achar_t* envp[]) { +#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_runmainwithenv (argc, argv, envp, test_main); } diff --git a/qse/samples/cmn/fmt02.c b/qse/samples/cmn/fmt02.c index c617cbde..c0a6d679 100644 --- a/qse/samples/cmn/fmt02.c +++ b/qse/samples/cmn/fmt02.c @@ -1,7 +1,14 @@ #include #include +#include #include +#include +#if defined(_WIN32) +# include +#endif + + static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[]) { qse_char_t buf[129]; @@ -69,6 +76,24 @@ static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[]) int qse_main (int argc, qse_achar_t* argv[], qse_achar_t* envp[]) { +#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_runmainwithenv (argc, argv, envp, test_main); } diff --git a/qse/samples/cmn/fs01.c b/qse/samples/cmn/fs01.c index 53fa8144..3691911b 100644 --- a/qse/samples/cmn/fs01.c +++ b/qse/samples/cmn/fs01.c @@ -1,7 +1,14 @@ #include #include -#include #include +#include +#include + +#include +#if defined(_WIN32) +# include +#endif + static void list (qse_fs_t* fs, const qse_char_t* name) { @@ -68,6 +75,24 @@ int fs_main (int argc, qse_char_t* argv[]) 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, fs_main); } diff --git a/qse/samples/cmn/main.c b/qse/samples/cmn/main.c deleted file mode 100644 index 4ab2acbc..00000000 --- a/qse/samples/cmn/main.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -static int test_main (int argc, qse_char_t* argv[]) -{ - int i; - - for (i = 0; i < argc; i++) - { - qse_printf (QSE_T("%d => [%s]\n"), i, argv[i]); - } - - return 0; -} - -int qse_main (int argc, qse_achar_t* argv[]) -{ - return qse_runmain (argc, argv, test_main); -} - diff --git a/qse/samples/cmn/main01.c b/qse/samples/cmn/main01.c new file mode 100644 index 00000000..341680f1 --- /dev/null +++ b/qse/samples/cmn/main01.c @@ -0,0 +1,47 @@ +#include +#include +#include + +#include + +#if defined(_WIN32) +# include +#endif + + +static int test_main (int argc, qse_char_t* argv[]) +{ + int i; + + for (i = 0; i < argc; i++) + { + qse_printf (QSE_T("%d => [%s]\n"), i, argv[i]); + } + + return 0; +} + +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, test_main); +} + diff --git a/qse/samples/cmn/main02.c b/qse/samples/cmn/main02.c new file mode 100644 index 00000000..99821a17 --- /dev/null +++ b/qse/samples/cmn/main02.c @@ -0,0 +1,51 @@ +#include +#include +#include + +#include + +#if defined(_WIN32) +# include +#endif + +static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[]) +{ + int i; + + for (i = 0; i < argc; i++) + { + qse_printf (QSE_T("ARG %d => [%s]\n"), i, argv[i]); + } + + for (i = 0; envp[i]; i++) + { + qse_printf (QSE_T("ENV %d => [%s]\n"), i, envp[i]); + } + + return 0; +} + +int qse_main (int argc, qse_achar_t* argv[], qse_achar_t* envp[]) +{ +#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_runmainwithenv (argc, argv, envp, test_main); +} + diff --git a/qse/samples/cmn/main2.c b/qse/samples/cmn/main2.c deleted file mode 100644 index 2a1b57fb..00000000 --- a/qse/samples/cmn/main2.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[]) -{ - int i; - - for (i = 0; i < argc; i++) - { - qse_printf (QSE_T("ARG %d => [%s]\n"), i, argv[i]); - } - - for (i = 0; envp[i]; i++) - { - qse_printf (QSE_T("ENV %d => [%s]\n"), i, envp[i]); - } - - return 0; -} - -int qse_main (int argc, qse_achar_t* argv[], qse_achar_t* envp[]) -{ - return qse_runmainwithenv (argc, argv, envp, test_main); -} - diff --git a/qse/samples/cmn/path01.c b/qse/samples/cmn/path01.c index 6965ad76..6b9ab00e 100644 --- a/qse/samples/cmn/path01.c +++ b/qse/samples/cmn/path01.c @@ -1,10 +1,15 @@ - #include #include #include +#include #include #include +#include +#if defined(_WIN32) +# include +#endif + int path_main (int argc, qse_char_t* argv[]) { qse_char_t* canon; @@ -60,6 +65,24 @@ int path_main (int argc, qse_char_t* argv[]) 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, path_main); } diff --git a/qse/samples/cmn/rex01.c b/qse/samples/cmn/rex01.c index 011a154c..a34a8c4c 100644 --- a/qse/samples/cmn/rex01.c +++ b/qse/samples/cmn/rex01.c @@ -2,9 +2,15 @@ #include #include #include +#include #include #include +#include +#if defined(_WIN32) +# include +#endif + static int rex_main (int argc, qse_char_t* argv[]) { qse_rex_t* rex; @@ -27,7 +33,7 @@ static int rex_main (int argc, qse_char_t* argv[]) return -1; } -qse_rex_setoption (rex, QSE_REX_STRICT); + qse_rex_setoption (rex, QSE_REX_STRICT); start = qse_rex_comp (rex, argv[1], qse_strlen(argv[1])); if (start == QSE_NULL) @@ -64,6 +70,24 @@ qse_rex_setoption (rex, QSE_REX_STRICT); 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, rex_main); } diff --git a/qse/samples/cmn/sio02.c b/qse/samples/cmn/sio02.c index 097adcf0..ad3d04c1 100644 --- a/qse/samples/cmn/sio02.c +++ b/qse/samples/cmn/sio02.c @@ -157,11 +157,11 @@ int main () { sprintf (locale, ".%u", (unsigned int)codepage); setlocale (LC_ALL, locale); - qse_setdflcmgr (qse_loccmgr); + qse_setdflcmgr (qse_slmbcmgr); } #else setlocale (LC_ALL, ""); - qse_setdflcmgr (qse_loccmgr); + qse_setdflcmgr (qse_slmbcmgr); #endif setlocale (LC_ALL, ""); diff --git a/qse/samples/cmn/sio03.c b/qse/samples/cmn/sio03.c index bfef2a16..e4b5c38d 100644 --- a/qse/samples/cmn/sio03.c +++ b/qse/samples/cmn/sio03.c @@ -72,6 +72,8 @@ static int test1 (void) static int test2 (void) { + /* this file is in utf8, the following strings may not be shown properly + * if your locale/codepage is not utf8 */ const qse_mchar_t* x[] = { QSE_MT("\0\0\0"), @@ -100,6 +102,8 @@ static int test2 (void) static int test3 (void) { + /* this file is in utf8, the following strings may not be shown properly + * if your locale/codepage is not utf8 */ const qse_mchar_t* x[] = { QSE_MT("\0\0\0"), @@ -141,11 +145,11 @@ int main () { sprintf (locale, ".%u", (unsigned int)codepage); setlocale (LC_ALL, locale); - qse_setdflcmgr (qse_loccmgr); + qse_setdflcmgr (qse_slmbcmgr); } #else setlocale (LC_ALL, ""); - qse_setdflcmgr (qse_loccmgr); + qse_setdflcmgr (qse_slmbcmgr); #endif qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); diff --git a/qse/samples/cmn/chr.c b/qse/samples/cmn/slmb01.c similarity index 61% rename from qse/samples/cmn/chr.c rename to qse/samples/cmn/slmb01.c index 0c4ba9f1..9cdde221 100644 --- a/qse/samples/cmn/chr.c +++ b/qse/samples/cmn/slmb01.c @@ -1,10 +1,15 @@ +#include +#include #include -#include #include #include #include +#if defined(_WIN32) +# include +#endif + #define R(f) \ do { \ qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \ @@ -12,24 +17,12 @@ } while (0) static int test1 (void) -{ - qse_char_t c; - - for (c = QSE_T('a'); c <= QSE_T('z'); c++) - { - qse_printf (QSE_T("%c => %c\n"), c, QSE_TOUPPER(c)); - } - - return 0; -} - -static int test2 (void) { int i; const qse_mchar_t* x[] = { "\0", - "뛰어 올라봐", + "뛰어 올라봐", /* this text is in utf8. so some conversions fail on a non-utf8 locale */ "Fly to the universe" }; @@ -44,7 +37,7 @@ static int test2 (void) qse_printf (QSE_T("[")); while (j < k) { - qse_size_t y = qse_mblen (&x[i][j], k-j); + qse_size_t y = qse_slmblen (&x[i][j], k-j); if (y == 0) { @@ -58,7 +51,7 @@ static int test2 (void) } else { - qse_size_t y2 = qse_mbtowc (&x[i][j], y, &wc); + qse_size_t y2 = qse_slmbtoslwc (&x[i][j], y, &wc); if (y2 != y) { qse_printf (QSE_T("***y(%d) != y2(%d). something is wrong*** "), (int)y, (int)y2); @@ -87,26 +80,44 @@ static int test2 (void) return 0; } -static int test3 (void) +static int test2 (void) { + const qse_wchar_t unistr[] = + { + /*L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4!",*/ + 0xB108, + L' ', + 0xBB50, + 0xAC00, + L' ', + 0xC798, + 0xB0AC, + 0xC5B4, + L'!', + L'\0' + }; + const qse_wchar_t* x[] = { L"\0", - L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?", + L"", L"Fly to the universe" }; char buf[100]; int i, j; + x[1] = unistr; + for (i = 0; i < QSE_COUNTOF(x); i++) { + int nbytes = 0; int len = qse_wcslen (x[i]); if (len == 0) len++; /* for x[0] */ qse_printf (QSE_T("[")); for (j = 0; j < len; j++) { - qse_size_t n = qse_wctomb (x[i][j], buf, sizeof(buf)); + qse_size_t n = qse_slwctoslmb (x[i][j], buf, sizeof(buf) - 1); if (n == 0) { @@ -124,30 +135,40 @@ static int test3 (void) } else { - #ifdef QSE_CHAR_IS_MCHAR - qse_printf (QSE_T("%.*s"), (int)n, buf); - #else - qse_printf (QSE_T("%.*S"), (int)n, buf); - #endif + buf[n] = QSE_MT('\0'); + qse_printf (QSE_T("%hs"), buf); } + nbytes += n; } } - qse_printf (QSE_T("] => %d chars\n"), (int)len); + qse_printf (QSE_T("] => %d chars, %d bytes\n"), (int)len, (int)nbytes); } return 0; } int main () { - setlocale (LC_ALL, ""); - - qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); - qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n")); - qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); +#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 R (test1); R (test2); - R (test3); return 0; } diff --git a/qse/samples/cmn/tre01.c b/qse/samples/cmn/tre01.c index 1c02264c..93921e46 100644 --- a/qse/samples/cmn/tre01.c +++ b/qse/samples/cmn/tre01.c @@ -1,10 +1,17 @@ -#include #include #include #include +#include +#include #include +#include +#if defined(_WIN32) +# include +#endif + + static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[]) { qse_tre_t tre; @@ -70,6 +77,24 @@ oops: int qse_main (int argc, qse_achar_t* argv[], qse_achar_t* envp[]) { +#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_runmainwithenv (argc, argv, envp, test_main); } diff --git a/qse/samples/sed/sed01.c b/qse/samples/sed/sed01.c index ad2372b1..b11786d5 100644 --- a/qse/samples/sed/sed01.c +++ b/qse/samples/sed/sed01.c @@ -20,8 +20,14 @@ #include #include +#include #include +#include +#if defined(_WIN32) +# include +#endif + int sed_main (int argc, qse_char_t* argv[]) { qse_sed_t* sed = QSE_NULL; @@ -64,6 +70,25 @@ 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, sed_main); } diff --git a/qse/samples/sed/sed02.cpp b/qse/samples/sed/sed02.cpp index 18a53c49..fc284007 100644 --- a/qse/samples/sed/sed02.cpp +++ b/qse/samples/sed/sed02.cpp @@ -20,8 +20,15 @@ #include #include +#include #include +#include +#if defined(_WIN32) +# include +#endif + + #ifdef QSE_CHAR_IS_MCHAR # define xcout std::cout #else @@ -71,5 +78,23 @@ int sed_main (int argc, qse_char_t* argv[]) 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, sed_main); } diff --git a/qse/samples/sed/sed03.cpp b/qse/samples/sed/sed03.cpp index 0d4edc5d..c46bbee7 100644 --- a/qse/samples/sed/sed03.cpp +++ b/qse/samples/sed/sed03.cpp @@ -20,9 +20,16 @@ #include #include +#include #include #include +#include +#if defined(_WIN32) +# include +#endif + + #ifdef QSE_CHAR_IS_MCHAR # define xcout std::cout #else @@ -86,5 +93,23 @@ int sed_main (int argc, qse_char_t* argv[]) 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, sed_main); }