reworked on HCL_LOG_TARGET

This commit is contained in:
hyung-hwan 2021-07-19 07:11:41 +00:00
parent 59be44fa34
commit 08cf4548bb
3 changed files with 55 additions and 35 deletions

View File

@ -315,16 +315,16 @@ void hcl_fini (hcl_t* hcl)
hcl->log.len = 0;
}
if (hcl->option.log_target)
if (hcl->option.log_target_u)
{
hcl_freemem (hcl, hcl->option.log_target);
hcl->option.log_target = HCL_NULL;
hcl_freemem (hcl, hcl->option.log_target_u);
hcl->option.log_target_u = HCL_NULL;
}
if (hcl->option.log_targetx)
if (hcl->option.log_target_b)
{
hcl_freemem (hcl, hcl->option.log_targetx);
hcl->option.log_targetx = HCL_NULL;
hcl_freemem (hcl, hcl->option.log_target_b);
hcl->option.log_target_b = HCL_NULL;
}
if (hcl->inttostr.xbuf.ptr)
@ -406,33 +406,46 @@ int hcl_setoption (hcl_t* hcl, hcl_option_t id, const void* value)
hcl->option.log_maxcapa = *(hcl_oow_t*)value;
break;
case HCL_LOG_TARGET:
{
hcl_ooch_t* v1;
#if defined(HCL_OOCH_IS_UCH)
hcl_bch_t* v2;
#else
hcl_uch_t* v2;
#endif
v1 = hcl_dupoochars(hcl, value, hcl_count_oocstr(value));
case HCL_LOG_TARGET_B:
{
hcl_bch_t* v1;
hcl_uch_t* v2;
v1 = hcl_dupbcstr(hcl, value, HCL_NULL);
if (HCL_UNLIKELY(!v1)) return -1;
#if defined(HCL_OOCH_IS_UCH)
v2 = hcl_dupootobcstr(hcl, value, HCL_NULL);
#else
v2 = hcl_dupootoucstr(hcl, value, HCL_NULL);
#endif
v2 = hcl_dupbtoucstr(hcl, value, HCL_NULL);
if (HCL_UNLIKELY(!v2))
{
hcl_freemem (hcl, v1);
return -1;
}
hcl->option.log_targetx = v2;
hcl->option.log_target = v1;
hcl->option.log_target_u = v2;
hcl->option.log_target_b = v1;
break;
}
case HCL_LOG_TARGET_U:
{
hcl_uch_t* v1;
hcl_bch_t* v2;
v1 = hcl_dupucstr(hcl, value, HCL_NULL);
if (HCL_UNLIKELY(!v1)) return -1;
v2 = hcl_duputobcstr(hcl, value, 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:
{
@ -504,8 +517,12 @@ 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:
*(hcl_ooch_t**)value = hcl->option.log_target;
case HCL_LOG_TARGET_B:
*(hcl_bch_t**)value = hcl->option.log_target_b;
return 0;
case HCL_LOG_TARGET_U:
*(hcl_uch_t**)value = hcl->option.log_target_u;
return 0;
case HCL_SYMTAB_SIZE:

View File

@ -169,7 +169,14 @@ enum hcl_option_t
HCL_TRAIT,
HCL_LOG_MASK,
HCL_LOG_MAXCAPA,
HCL_LOG_TARGET,
HCL_LOG_TARGET_B,
HCL_LOG_TARGET_U,
#if defined(HCL_OOCH_IS_UCH)
# define HCL_LOG_TARGET HCL_LOG_TARGET_U
#else
# define HCL_LOG_TARGET HCL_LOG_TARGET_B
#endif
HCL_SYMTAB_SIZE, /* default system table size */
HCL_SYSDIC_SIZE, /* default system dictionary size */
HCL_PROCSTK_SIZE, /* default process stack size */
@ -1466,12 +1473,8 @@ struct hcl_t
hcl_bitmask_t trait;
hcl_bitmask_t log_mask;
hcl_oow_t log_maxcapa;
hcl_ooch_t* log_target;
#if defined(HCL_OOCH_IS_UCH)
hcl_bch_t* log_targetx;
#else
hcl_uch_t* log_targetx;
#endif
hcl_bch_t* log_target_b;
hcl_uch_t* log_target_u;
hcl_oow_t dfl_symtab_size;
hcl_oow_t dfl_sysdic_size;
hcl_oow_t dfl_procstk_size;

View File

@ -2744,13 +2744,13 @@ static void cb_opt_set (hcl_t* hcl, hcl_option_t id, const void* value)
if (id != HCL_LOG_TARGET) return; /* return success. not interested */
#if defined(_WIN32)
fd = _open(hcl->option.log_target, _O_CREAT | _O_WRONLY | _O_APPEND | _O_BINARY , 0644);
#else
#if defined(HCL_OOCH_IS_UCH)
fd = open(hcl->option.log_targetx, O_CREAT | O_WRONLY | O_APPEND , 0644);
fd = _open(hcl->option.log_target_u, _O_CREAT | _O_WRONLY | _O_APPEND | _O_BINARY , 0644);
#else
fd = open(hcl->option.log_target, O_CREAT | O_WRONLY | O_APPEND , 0644);
fd = _open(hcl->option.log_target_b, _O_CREAT | _O_WRONLY | _O_APPEND | _O_BINARY , 0644);
#endif
#else
fd = open(hcl->option.log_target_b, O_CREAT | O_WRONLY | O_APPEND , 0644);
#endif
if (fd == -1)
{