From 28bac46b39881c3ad2599e5b9e892668e51b5936 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 19 Jul 2021 18:59:17 +0000 Subject: [PATCH] added HCL_LOG_TARGET_BCS and HCL_LOG_TARGET_UCS --- bin/main.c | 83 +++++++++++++++++++++++++++--------------------------- lib/hcl.c | 60 ++++++++++++++++++++++++++++++++++++--- lib/hcl.h | 15 +++++++--- lib/std.c | 3 +- 4 files changed, 111 insertions(+), 50 deletions(-) diff --git a/bin/main.c b/bin/main.c index 238229c..3bb59ea 100644 --- a/bin/main.c +++ b/bin/main.c @@ -431,58 +431,61 @@ static void gc_hcl (hcl_t* hcl) /* ========================================================================= */ -static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str) +static int handle_logopt (hcl_t* hcl, const hcl_bch_t* logstr) { - hcl_ooch_t* xstr, * cm, * flt; + hcl_bch_t* cm, * flt; hcl_bitmask_t logmask; + hcl_oow_t tlen; + hcl_bcs_t fname; - xstr = hcl_dupbtooochars(hcl, str, hcl_count_bcstr(str), HCL_NULL); - if (!xstr) - { - fprintf (stderr, "ERROR: out of memory in duplicating %s\n", str); - return -1; - } - - cm = hcl_find_oochar_in_oocstr(xstr, ','); + cm = hcl_find_bchar_in_bcstr(logstr, ','); if (cm) { - /* i duplicate this string for open() below as open() doesn't - * accept a length-bounded string */ - cm = hcl_find_oochar_in_oocstr(xstr, ','); - *cm = '\0'; - + fname.len = cm - logstr; logmask = 0; + do { flt = cm + 1; - cm = hcl_find_oochar_in_oocstr(flt, ','); - if (cm) *cm = '\0'; + cm = hcl_find_bchar_in_bcstr(flt, ','); + tlen = (cm)? (cm - flt): hcl_count_bcstr(flt); - if (hcl_comp_oocstr_bcstr(flt, "app") == 0) logmask |= HCL_LOG_APP; - else if (hcl_comp_oocstr_bcstr(flt, "compiler") == 0) logmask |= HCL_LOG_COMPILER; - else if (hcl_comp_oocstr_bcstr(flt, "vm") == 0) logmask |= HCL_LOG_VM; - else if (hcl_comp_oocstr_bcstr(flt, "mnemonic") == 0) logmask |= HCL_LOG_MNEMONIC; - else if (hcl_comp_oocstr_bcstr(flt, "gc") == 0) logmask |= HCL_LOG_GC; - else if (hcl_comp_oocstr_bcstr(flt, "ic") == 0) logmask |= HCL_LOG_IC; - else if (hcl_comp_oocstr_bcstr(flt, "primitive") == 0) logmask |= HCL_LOG_PRIMITIVE; + if (hcl_comp_bchars_bcstr(flt, tlen, "app") == 0) logmask |= HCL_LOG_APP; + else if (hcl_comp_bchars_bcstr(flt, tlen, "compiler") == 0) logmask |= HCL_LOG_COMPILER; + else if (hcl_comp_bchars_bcstr(flt, tlen, "vm") == 0) logmask |= HCL_LOG_VM; + else if (hcl_comp_bchars_bcstr(flt, tlen, "mnemonic") == 0) logmask |= HCL_LOG_MNEMONIC; + else if (hcl_comp_bchars_bcstr(flt, tlen, "gc") == 0) logmask |= HCL_LOG_GC; + else if (hcl_comp_bchars_bcstr(flt, tlen, "ic") == 0) logmask |= HCL_LOG_IC; + else if (hcl_comp_bchars_bcstr(flt, tlen, "primitive") == 0) logmask |= HCL_LOG_PRIMITIVE; - else if (hcl_comp_oocstr_bcstr(flt, "fatal") == 0) logmask |= HCL_LOG_FATAL; - else if (hcl_comp_oocstr_bcstr(flt, "error") == 0) logmask |= HCL_LOG_ERROR; - else if (hcl_comp_oocstr_bcstr(flt, "warn") == 0) logmask |= HCL_LOG_WARN; - else if (hcl_comp_oocstr_bcstr(flt, "info") == 0) logmask |= HCL_LOG_INFO; - else if (hcl_comp_oocstr_bcstr(flt, "debug") == 0) logmask |= HCL_LOG_DEBUG; + else if (hcl_comp_bchars_bcstr(flt, tlen, "fatal") == 0) logmask |= HCL_LOG_FATAL; + else if (hcl_comp_bchars_bcstr(flt, tlen, "error") == 0) logmask |= HCL_LOG_ERROR; + else if (hcl_comp_bchars_bcstr(flt, tlen, "warn") == 0) logmask |= HCL_LOG_WARN; + else if (hcl_comp_bchars_bcstr(flt, tlen, "info") == 0) logmask |= HCL_LOG_INFO; + else if (hcl_comp_bchars_bcstr(flt, tlen, "debug") == 0) logmask |= HCL_LOG_DEBUG; - else if (hcl_comp_oocstr_bcstr(flt, "fatal+") == 0) logmask |= HCL_LOG_FATAL; - else if (hcl_comp_oocstr_bcstr(flt, "error+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR; - else if (hcl_comp_oocstr_bcstr(flt, "warn+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN; - else if (hcl_comp_oocstr_bcstr(flt, "info+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO; - else if (hcl_comp_oocstr_bcstr(flt, "debug+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO | HCL_LOG_DEBUG; + else if (hcl_comp_bchars_bcstr(flt, tlen, "fatal+") == 0) logmask |= HCL_LOG_FATAL; + else if (hcl_comp_bchars_bcstr(flt, tlen, "error+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR; + else if (hcl_comp_bchars_bcstr(flt, tlen, "warn+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN; + else if (hcl_comp_bchars_bcstr(flt, tlen, "info+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO; + else if (hcl_comp_bchars_bcstr(flt, tlen, "debug+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO | HCL_LOG_DEBUG; + + else if (hcl_comp_bchars_bcstr(flt, tlen, "fatal-") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO | HCL_LOG_DEBUG; + else if (hcl_comp_bchars_bcstr(flt, tlen, "error-") == 0) logmask |= HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO | HCL_LOG_DEBUG; + else if (hcl_comp_bchars_bcstr(flt, tlen, "warn-") == 0) logmask |= HCL_LOG_WARN | HCL_LOG_INFO | HCL_LOG_DEBUG; + else if (hcl_comp_bchars_bcstr(flt, tlen, "info-") == 0) logmask |= HCL_LOG_INFO | HCL_LOG_DEBUG; + else if (hcl_comp_bchars_bcstr(flt, tlen, "debug-") == 0) logmask |= HCL_LOG_DEBUG; + + else if (hcl_comp_bchars_bcstr(flt, tlen, "-fatal") == 0) logmask &= (~HCL_LOG_FATAL & HCL_LOG_ALL_LEVELS); + else if (hcl_comp_bchars_bcstr(flt, tlen, "-error") == 0) logmask &= (~HCL_LOG_ERROR & HCL_LOG_ALL_LEVELS); + else if (hcl_comp_bchars_bcstr(flt, tlen, "-warn") == 0) logmask &= (~HCL_LOG_WARN & HCL_LOG_ALL_LEVELS); + else if (hcl_comp_bchars_bcstr(flt, tlen, "-info") == 0) logmask &= (~HCL_LOG_INFO & HCL_LOG_ALL_LEVELS); + else if (hcl_comp_bchars_bcstr(flt, tlen, "-debug") == 0) logmask &= (~HCL_LOG_DEBUG & HCL_LOG_ALL_LEVELS); else { - fprintf (stderr, "ERROR: invalid value - %s\n", str); - hcl_freemem (hcl, xstr); + fprintf (stderr, "ERROR: invalid value - %s\n", logstr); return -1; } } @@ -495,13 +498,11 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str) else { logmask = HCL_LOG_ALL_LEVELS | HCL_LOG_ALL_TYPES; + fname.len = hcl_count_bcstr(logstr); } - - hcl_setoption (hcl, HCL_LOG_TARGET, xstr); - hcl_freemem (hcl, xstr); - - + fname.ptr = logstr; + hcl_setoption (hcl, HCL_LOG_TARGET_BCS, &fname); hcl_setoption (hcl, HCL_LOG_MASK, &logmask); return 0; } diff --git a/lib/hcl.c b/lib/hcl.c index 9f20573..eb2539d 100644 --- a/lib/hcl.c +++ b/lib/hcl.c @@ -407,7 +407,7 @@ int hcl_setoption (hcl_t* hcl, hcl_option_t id, const void* value) break; - case HCL_LOG_TARGET_B: + case HCL_LOG_TARGET_BCSTR: { hcl_bch_t* v1; hcl_uch_t* v2; @@ -427,7 +427,7 @@ int hcl_setoption (hcl_t* hcl, hcl_option_t id, const void* value) break; } - case HCL_LOG_TARGET_U: + case HCL_LOG_TARGET_UCSTR: { hcl_uch_t* v1; hcl_bch_t* v2; @@ -447,6 +447,48 @@ int hcl_setoption (hcl_t* hcl, hcl_option_t id, const void* value) break; } + case HCL_LOG_TARGET_BCS: + { + hcl_bch_t* v1; + hcl_uch_t* v2; + hcl_bcs_t* v = (hcl_bcs_t*)value; + + v1 = hcl_dupbchars(hcl, v->ptr, v->len); + if (HCL_UNLIKELY(!v1)) return -1; + + v2 = hcl_dupbtouchars(hcl, v->ptr, v->len, HCL_NULL); + if (HCL_UNLIKELY(!v2)) + { + hcl_freemem (hcl, v1); + return -1; + } + + hcl->option.log_target_u = v2; + hcl->option.log_target_b = v1; + break; + } + + case HCL_LOG_TARGET_UCS: + { + hcl_uch_t* v1; + hcl_bch_t* v2; + hcl_ucs_t* v = (hcl_bcs_t*)value; + + v1 = hcl_dupuchars(hcl, v->ptr, v->len); + if (HCL_UNLIKELY(!v1)) return -1; + + v2 = hcl_duputobchars(hcl, v->ptr, v->len, HCL_NULL); + if (HCL_UNLIKELY(!v2)) + { + hcl_freemem (hcl, v1); + return -1; + } + + hcl->option.log_target_u = v1; + hcl->option.log_target_b = v2; + break; + } + case HCL_SYMTAB_SIZE: { hcl_oow_t w; @@ -517,14 +559,24 @@ int hcl_getoption (hcl_t* hcl, hcl_option_t id, void* value) *(hcl_oow_t*)value = hcl->option.log_maxcapa; return 0; - case HCL_LOG_TARGET_B: + case HCL_LOG_TARGET_BCSTR: *(hcl_bch_t**)value = hcl->option.log_target_b; return 0; - case HCL_LOG_TARGET_U: + case HCL_LOG_TARGET_UCSTR: *(hcl_uch_t**)value = hcl->option.log_target_u; return 0; + case HCL_LOG_TARGET_BCS: + ((hcl_bcs_t*)value)->ptr = hcl->option.log_target_b; + ((hcl_bcs_t*)value)->len = hcl_count_bcstr(hcl->option.log_target_b); + return 0; + + case HCL_LOG_TARGET_UCS: + ((hcl_ucs_t*)value)->ptr = hcl->option.log_target_u; + ((hcl_ucs_t*)value)->len = hcl_count_ucstr(hcl->option.log_target_u); + return 0; + case HCL_SYMTAB_SIZE: *(hcl_oow_t*)value = hcl->option.dfl_symtab_size; return 0; diff --git a/lib/hcl.h b/lib/hcl.h index 34264c2..410639f 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -169,12 +169,19 @@ enum hcl_option_t HCL_TRAIT, HCL_LOG_MASK, HCL_LOG_MAXCAPA, - HCL_LOG_TARGET_B, - HCL_LOG_TARGET_U, + + HCL_LOG_TARGET_BCSTR, + HCL_LOG_TARGET_UCSTR, + HCL_LOG_TARGET_BCS, + HCL_LOG_TARGET_UCS, #if defined(HCL_OOCH_IS_UCH) -# define HCL_LOG_TARGET HCL_LOG_TARGET_U +# define HCL_LOG_TARGET HCL_LOG_TARGET_UCSTR +# define HCL_LOG_TARGET_OOCSTR HCL_LOG_TARGET_UCSTR +# define HCL_LOG_TARGET_OOCS HCL_LOG_TARGET_UCS #else -# define HCL_LOG_TARGET HCL_LOG_TARGET_B +# define HCL_LOG_TARGET HCL_LOG_TARGET_BCSTR +# define HCL_LOG_TARGET_OOCSTR HCL_LOG_TARGET_BCSTR +# define HCL_LOG_TARGET_OOCS HCL_LOG_TARGET_BCS #endif HCL_SYMTAB_SIZE, /* default system table size */ diff --git a/lib/std.c b/lib/std.c index 74d6db2..322b987 100644 --- a/lib/std.c +++ b/lib/std.c @@ -2741,7 +2741,8 @@ static void cb_opt_set (hcl_t* hcl, hcl_option_t id, const void* value) xtn_t* xtn = GET_XTN(hcl); int fd; - if (id != HCL_LOG_TARGET) return; /* return success. not interested */ + if (id != HCL_LOG_TARGET_BCSTR && id != HCL_LOG_TARGET_UCSTR && + id != HCL_LOG_TARGET_BCS && id != HCL_LOG_TARGET_UCS) return; /* return success. not interested */ #if defined(_WIN32) #if defined(HCL_OOCH_IS_UCH)