From 1ef7fc2569424bf3698050b8dc1dfb5038ab9ab2 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 15 Dec 2014 04:26:41 +0000 Subject: [PATCH] touched up glob.c and glob.h --- qse/bld/watcom.txt | 45 ++++++++++++++++++++++++++++++++++++++++ qse/lib/cmn/glob.c | 6 +++--- qse/lib/cmn/glob.h | 9 ++++---- qse/lib/cmn/mbwc.c | 1 - qse/lib/http/httpd-dir.c | 6 ++++-- qse/samples/cmn/fs03.c | 1 - qse/samples/cmn/glob01.c | 27 +++++++++++++++++------- 7 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 qse/bld/watcom.txt diff --git a/qse/bld/watcom.txt b/qse/bld/watcom.txt new file mode 100644 index 00000000..6d8ce93c --- /dev/null +++ b/qse/bld/watcom.txt @@ -0,0 +1,45 @@ +Here are sample commands and linker files to use sample programs +using the watcom compiler and linker. + +------------------------------------------------------------------------ + +wcc386 -bt=os2 -zq -i=..\..\include -DNDEBUG -DQSE_CHAR_IS_WCHAR=1 -wx -d0 -bm -ot -ox ..\..\samples\cmn\dir01.c + +>>> dir01.lbc +option quiet +name dir01.exe +option caseexact + system os2v2 +file dir01.obj +library release-wchar-shared\qsecmn.lib + + +wlink @dir01.lbc + +------------------------------------------------------------------------ + +wcc386 -bt=dos -dDOS4GW -zq -i=..\..\include -DNDEBUG -DQSE_CHAR_IS_WCHAR=1 -wx -d0 -bm -ot -ox ..\..\samples\cmn\dir01.c + +>>> dir01.lbc +option quiet +name dir01.exe +option caseexact + system DOS4G +file dir01.obj +library release-wchar-static\qsecmn.lib +option stack=256k + +wlink @dir01.lbc +------------------------------------------------------------------------ + +wcc386 -bt=nt -zq -i=..\..\include -DNDEBUG -DQSE_CHAR_IS_WCHAR=1 -wx -d0 -bm -ot -ox ..\..\samples\cmn\dir01.c + +>>> dir01.lbc +option quiet +name dir01.exe +option caseexact + system nt ref 'main_' +file dir01.obj +library release-wchar-shared\qsecmn.lib + +wlink @dir01.lbc diff --git a/qse/lib/cmn/glob.c b/qse/lib/cmn/glob.c index 7b3b6f58..5e8a6761 100644 --- a/qse/lib/cmn/glob.c +++ b/qse/lib/cmn/glob.c @@ -115,7 +115,7 @@ typedef enum segment_type_t segment_type_t; #define get_next_segment mbs_get_next_segment #define handle_non_wild_segments mbs_handle_non_wild_segments #define CHAR_IS_MCHAR -#undef DECLARE_MBUF +#undef INCLUDE_MBUF #include "glob.h" /* -------------------------------------------------------------------- */ @@ -156,7 +156,7 @@ typedef enum segment_type_t segment_type_t; #undef get_next_segment #undef handle_non_wild_segments #undef CHAR_IS_MCHAR -#undef DECLARE_MBUF +#undef INCLUDE_MBUF /* -------------------------------------------------------------------- */ @@ -198,6 +198,6 @@ typedef enum segment_type_t segment_type_t; #define handle_non_wild_segments wcs_handle_non_wild_segments #undef CHAR_IS_MCHAR #if !defined(_WIN32) -# define DECLARE_MBUF 1 +# define INCLUDE_MBUF 1 #endif #include "glob.h" diff --git a/qse/lib/cmn/glob.h b/qse/lib/cmn/glob.h index d9fc626e..a3da9433 100644 --- a/qse/lib/cmn/glob.h +++ b/qse/lib/cmn/glob.h @@ -41,7 +41,7 @@ struct glob_t str_t path; str_t tbuf; /* temporary buffer */ -#if defined(DECLARE_MBUF) +#if defined(INCLUDE_MBUF) qse_mbs_t mbuf; #endif @@ -83,7 +83,7 @@ struct stack_node_t }; #endif -#if defined(DECLARE_MBUF) +#if defined(INCLUDE_MBUF) static qse_mchar_t* wcs_to_mbuf (glob_t* g, const qse_wchar_t* wcs, qse_mbs_t* mbs) { qse_size_t ml, wl; @@ -104,6 +104,7 @@ static int path_exists (glob_t* g, const char_t* name) #if !defined(INVALID_FILE_ATTRIBUTES) #define INVALID_FILE_ATTRIBUTES ((DWORD)-1) #endif + #if defined(CHAR_IS_MCHAR) return (GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES)? 1: 0; #else @@ -563,7 +564,7 @@ int glob (const char_t* pattern, cbimpl_t cbimpl, void* cbctx, int flags, qse_mm return -1; } -#if defined(DECLARE_MBUF) +#if defined(INCLUDE_MBUF) if (qse_mbs_init (&g.mbuf, mmgr, 512) <= -1) { str_fini (&g.path); @@ -579,7 +580,7 @@ int glob (const char_t* pattern, cbimpl_t cbimpl, void* cbctx, int flags, qse_mm x = search (&g, &seg); -#if defined(DECLARE_MBUF) +#if defined(INCLUDE_MBUF) qse_mbs_fini (&g.mbuf); #endif str_fini (&g.tbuf); diff --git a/qse/lib/cmn/mbwc.c b/qse/lib/cmn/mbwc.c index 932a6b08..702ed58e 100644 --- a/qse/lib/cmn/mbwc.c +++ b/qse/lib/cmn/mbwc.c @@ -48,7 +48,6 @@ static qse_cmgr_t builtin_cmgr[] = { qse_cp949touc, qse_uctocp949 }, { qse_cp950touc, qse_uctocp950 } #endif - }; static qse_cmgr_t* dfl_cmgr = &builtin_cmgr[QSE_CMGR_SLMB]; diff --git a/qse/lib/http/httpd-dir.c b/qse/lib/http/httpd-dir.c index 86a6586b..75ed4685 100644 --- a/qse/lib/http/httpd-dir.c +++ b/qse/lib/http/httpd-dir.c @@ -148,7 +148,6 @@ static qse_size_t format_dirent ( const qse_httpd_dirent_t* dirent, qse_mchar_t* buf, int bufsz) { -/* TODO: page encoding?? utf-8??? or derive name from cmgr or current locale??? */ qse_size_t x; qse_mchar_t* encname; @@ -332,8 +331,11 @@ static int task_main_dseg ( qpath_esc = qse_httpd_escapehtml (httpd, ctx->qpath.ptr); if (qpath_esc == QSE_NULL) return -1; + /* TODO: page encoding?? utf-8??? or derive name from cmgr or current locale??? */ + /* TODO: SUPPORT character set. DON't HARD_CODE it to UTF8 */ x = qse_mbsxfmts (&ctx->buf[ctx->buflen], ctx->bufrem, - QSE_MT("%s\n\n
%s
\n
%s"), ctx->head.ptr, qpath_esc, + QSE_MT("\n%s\n\n
%s
\n
%s"), + ctx->head.ptr, qpath_esc, (is_root? QSE_MT(""): QSE_MT("\n")) ); diff --git a/qse/samples/cmn/fs03.c b/qse/samples/cmn/fs03.c index 7d1e3906..674ee332 100644 --- a/qse/samples/cmn/fs03.c +++ b/qse/samples/cmn/fs03.c @@ -22,7 +22,6 @@ static void print_usage (const qse_char_t* argv0) qse_fprintf (QSE_STDERR, QSE_T(" -p preserve\n")); qse_fprintf (QSE_STDERR, QSE_T(" -r recursive\n")); qse_fprintf (QSE_STDERR, QSE_T(" -s symlink\n")); - } static int fs_main (int argc, qse_char_t* argv[]) diff --git a/qse/samples/cmn/glob01.c b/qse/samples/cmn/glob01.c index 9d380cee..8404681a 100644 --- a/qse/samples/cmn/glob01.c +++ b/qse/samples/cmn/glob01.c @@ -1,12 +1,12 @@ #include -#include +#include #include #include #include #include +#include #include - #include #if defined(_WIN32) # include @@ -30,7 +30,8 @@ static int glob_main (int argc, qse_char_t* argv[]) for (i = 1; i < argc; i++) { - if (qse_glob (argv[i], print, QSE_NULL, QSE_GLOB_PERIOD, QSE_MMGR_GETDFL()) <= -1) return -1; + if (qse_glob (argv[i], print, QSE_NULL, QSE_GLOB_PERIOD, + qse_getdflmmgr(), qse_getdflcmgr()) <= -1) return -1; } return 0; @@ -38,9 +39,10 @@ static int glob_main (int argc, qse_char_t* argv[]) int qse_main (int argc, qse_achar_t* argv[]) { + int x; #if defined(_WIN32) char locale[100]; - UINT codepage = GetConsoleOutputCP(); + UINT codepage = GetConsoleOutputCP(); if (codepage == CP_UTF8) { /*SetConsoleOUtputCP (CP_UTF8);*/ @@ -48,14 +50,23 @@ int qse_main (int argc, qse_achar_t* argv[]) } else { - sprintf (locale, ".%u", (unsigned int)codepage); - setlocale (LC_ALL, locale); + /* .codepage */ + qse_fmtuintmaxtombs (locale, QSE_COUNTOF(locale), + codepage, 10, -1, QSE_MT('\0'), QSE_MT(".")); + setlocale (LC_ALL, locale); qse_setdflcmgrbyid (QSE_CMGR_SLMB); } #else - setlocale (LC_ALL, ""); + setlocale (LC_ALL, ""); qse_setdflcmgrbyid (QSE_CMGR_SLMB); #endif - return qse_runmain (argc, argv, glob_main); + + qse_openstdsios (); + + x = qse_runmain (argc, argv, glob_main); + + qse_closestdsios (); + + return x; }
..