From aa6a41c009329454dc4ac713e1fe9ac719c0d5c6 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 13 Sep 2017 14:04:01 +0000 Subject: [PATCH] refactored code a little bit --- qse/cmd/xli/xli.c | 6 ++---- qse/configure.ac | 2 +- qse/lib/cmn/str-cnv.c | 31 ++++++++----------------------- qse/lib/xli/write-ini.c | 2 +- 4 files changed, 12 insertions(+), 29 deletions(-) diff --git a/qse/cmd/xli/xli.c b/qse/cmd/xli/xli.c index 80efada3..31ec527a 100644 --- a/qse/cmd/xli/xli.c +++ b/qse/cmd/xli/xli.c @@ -443,9 +443,8 @@ static int xli_main (int argc, qse_char_t* argv[]) if (n <= -1) { const qse_xli_loc_t* errloc; - - errloc = qse_xli_geterrloc (xli); + errloc = qse_xli_geterrloc (xli); if (errloc->line > 0 || errloc->colm > 0) { qse_fprintf (QSE_STDERR, @@ -539,13 +538,12 @@ static int xli_main (int argc, qse_char_t* argv[]) out.type = QSE_XLI_IOSTD_FILE; out.u.file.path = QSE_T("-"); out.u.file.cmgr = g_outfile_cmgr; - qse_xli_writestd (xli, pair->val, &out); + qse_xli_writestd (xli, (qse_xli_list_t*)pair->val, &out); } } } } - out.type = QSE_XLI_IOSTD_FILE; out.u.file.path = g_output_file? g_output_file: QSE_T("-"); out.u.file.cmgr = g_outfile_cmgr; diff --git a/qse/configure.ac b/qse/configure.ac index 511d15f4..f678eb78 100644 --- a/qse/configure.ac +++ b/qse/configure.ac @@ -58,7 +58,7 @@ LT_CONFIG_LTDL_DIR([libltdl]) save_CFLAGS="$CFLAGS" save_LDFLAGS="$LDFLAGS" save_LIBS="$LIBS" -LTDL_INIT +LTDL_INIT(convenience) LDFLAGS="$save_LDFLAGS" CFLAGS="$save_CFLAGS" LIBS="$save_LIBS" diff --git a/qse/lib/cmn/str-cnv.c b/qse/lib/cmn/str-cnv.c index 33d38d2e..5ede4eac 100644 --- a/qse/lib/cmn/str-cnv.c +++ b/qse/lib/cmn/str-cnv.c @@ -291,8 +291,6 @@ qse_size_t qse_wcsupr (qse_wchar_t* str) return p - str; } - - /*--------------------------------------------------------------- * Hexadecimal string conversion *---------------------------------------------------------------*/ @@ -306,21 +304,15 @@ int qse_mbshextobin (const qse_mchar_t* hex, qse_size_t hexlen, qse_uint8_t* buf { int v; - if (*hex >= QSE_MT('0') && *hex <= QSE_MT('9')) v = *hex - QSE_MT('0'); - else if (*hex >= QSE_MT('a') && *hex <= QSE_MT('f')) v = *hex - QSE_MT('a') + 10; - else if (*hex >= QSE_MT('A') && *hex <= QSE_MT('F')) v = *hex - QSE_MT('A') + 10; - else return -1; - + v = QSE_MXDIGITTONUM(*hex); + if (v <= -1) return -1; buf[bi] = buf[bi] * 16 + v; hex++; if (hex >= end) return -1; - if (*hex >= QSE_MT('0') && *hex <= QSE_MT('9')) v = *hex - QSE_MT('0'); - else if (*hex >= QSE_MT('a') && *hex <= QSE_MT('f')) v = *hex - QSE_MT('a') + 10; - else if (*hex >= QSE_MT('A') && *hex <= QSE_MT('F')) v = *hex - QSE_MT('A') + 10; - else return -1; - + v = QSE_MXDIGITTONUM(*hex); + if (v <= -1) return -1; buf[bi] = buf[bi] * 16 + v; hex++; @@ -330,7 +322,6 @@ int qse_mbshextobin (const qse_mchar_t* hex, qse_size_t hexlen, qse_uint8_t* buf return 0; } - int qse_wcshextobin (const qse_wchar_t* hex, qse_size_t hexlen, qse_uint8_t* buf, qse_size_t buflen) { const qse_wchar_t* end = hex + hexlen; @@ -340,21 +331,15 @@ int qse_wcshextobin (const qse_wchar_t* hex, qse_size_t hexlen, qse_uint8_t* buf { int v; - if (*hex >= QSE_WT('0') && *hex <= QSE_WT('9')) v = *hex - QSE_WT('0'); - else if (*hex >= QSE_WT('a') && *hex <= QSE_WT('f')) v = *hex - QSE_WT('a') + 10; - else if (*hex >= QSE_WT('A') && *hex <= QSE_WT('F')) v = *hex - QSE_WT('A') + 10; - else return -1; - + v = QSE_WXDIGITTONUM(*hex); + if (v <= -1) return -1; buf[bi] = buf[bi] * 16 + v; hex++; if (hex >= end) return -1; - if (*hex >= QSE_WT('0') && *hex <= QSE_WT('9')) v = *hex - QSE_WT('0'); - else if (*hex >= QSE_WT('a') && *hex <= QSE_WT('f')) v = *hex - QSE_WT('a') + 10; - else if (*hex >= QSE_WT('A') && *hex <= QSE_WT('F')) v = *hex - QSE_WT('A') + 10; - else return -1; - + v = QSE_WXDIGITTONUM(*hex); + if (v <= -1) return -1; buf[bi] = buf[bi] * 16 + v; hex++; diff --git a/qse/lib/xli/write-ini.c b/qse/lib/xli/write-ini.c index dd48c79c..cc8ea5e5 100644 --- a/qse/lib/xli/write-ini.c +++ b/qse/lib/xli/write-ini.c @@ -91,7 +91,7 @@ static int write_list (qse_xli_t* xli, qse_xli_list_t* list, int depth) { /* key = value is not supported at the top level */ - if (write_to_current_stream (xli, QSE_T(" = "), 3) <= -1) return -1; + if (write_to_current_stream (xli, QSE_T("="), 1) <= -1) return -1; while (1) { if (str->tag)