From 69a5ef94bd277d161750a8ccca3fe2840d674d45 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 6 Apr 2018 14:59:44 +0000 Subject: [PATCH] changed hcl_seterrxxx() functions not to set the errnum field again for failures in internal operations, especially in hcl_convxxx() --- lib/err.c | 1 + lib/hcl.h | 1 + lib/logfmtv.h | 15 ++++++++++----- lib/read.c | 3 +-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/err.c b/lib/err.c index 8255419..4f4f0ad 100644 --- a/lib/err.c +++ b/lib/err.c @@ -85,6 +85,7 @@ static char* synerrstr[] = { "no error", "illegal character", + "illegal token", "comment not closed", "string/character not closed", "invalid hashed literal", diff --git a/lib/hcl.h b/lib/hcl.h index f642a8b..bc991cd 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -96,6 +96,7 @@ enum hcl_synerrnum_t { HCL_SYNERR_NOERR, HCL_SYNERR_ILCHR, /* illegal character */ + HCL_SYNERR_ILTOK, /* invalid token */ HCL_SYNERR_CMTNC, /* comment not closed */ HCL_SYNERR_STRCHRNC, /* string/character not closed */ HCL_SYNERR_HASHLIT, /* wrong hashed literal */ diff --git a/lib/logfmtv.h b/lib/logfmtv.h index a64ad57..5764e3b 100644 --- a/lib/logfmtv.h +++ b/lib/logfmtv.h @@ -165,7 +165,8 @@ static int logfmtv (hcl_t* hcl, const fmtchar_t* fmt, hcl_fmtout_t* data, va_lis /* fmtchar is uch. ooch is bch. convert uch to bch */ ucslen = 1; bcslen = HCL_COUNTOF(bcsbuf); - if (hcl_convutooochars(hcl, &fch, &ucslen, bcsbuf, &bcslen) <= -1) goto oops; + /*if (hcl_convutooochars(hcl, &fch, &ucslen, bcsbuf, &bcslen) <= -1) goto oops;*/ + if (hcl_conv_ucsn_to_bcsn_with_cmgr( &fch, &ucslen, bcsbuf, &bcslen, hcl->cmgr) <= -1) goto oops; PUT_OOCS (bcsbuf, bcslen); } #endif @@ -467,7 +468,8 @@ static int logfmtv (hcl_t* hcl, const fmtchar_t* fmt, hcl_fmtout_t* data, va_lis /* get the length */ for (bslen = 0; bsp[bslen]; bslen++); - if (hcl_convbtooochars(hcl, bsp, &bslen, HCL_NULL, &slen) <= -1) goto oops; + /*if (hcl_convbtooochars(hcl, bsp, &bslen, HCL_NULL, &slen) <= -1) goto oops;*/ + if (hcl_conv_bcsn_to_ucsn_with_cmgr(bsp, &bslen, HCL_NULL, &slen, hcl->cmgr, 0) <= -1) goto oops; /* slen holds the length after conversion */ n = slen; @@ -487,7 +489,8 @@ static int logfmtv (hcl_t* hcl, const fmtchar_t* fmt, hcl_fmtout_t* data, va_lis conv_len = HCL_COUNTOF(conv_buf); /* this must not fail since the dry-run above was successful */ - hcl_convbtooochars (hcl, &bsp[tot_len], &src_len, conv_buf, &conv_len); + /*hcl_convbtooochars (hcl, &bsp[tot_len], &src_len, conv_buf, &conv_len);*/ + hcl_conv_bcsn_to_ucsn_with_cmgr (&bsp[tot_len], &src_len, conv_buf, &conv_len, hcl->cmgr, 0); tot_len += src_len; if (conv_len > n) conv_len = n; @@ -536,7 +539,8 @@ static int logfmtv (hcl_t* hcl, const fmtchar_t* fmt, hcl_fmtout_t* data, va_lis /* get the length */ for (uslen = 0; usp[uslen]; uslen++); - if (hcl_convutooochars(hcl, usp, &uslen, HCL_NULL, &slen) <= -1) goto oops; + /*if (hcl_convutooochars(hcl, usp, &uslen, HCL_NULL, &slen) <= -1) goto oops;*/ + if (hcl_conv_ucsn_to_bcsn_with_cmgr(usp, &uslen, HCL_NULL, &slen, hcl->cmgr) <= -1) goto oops; /* slen holds the length after conversion */ n = slen; @@ -555,7 +559,8 @@ static int logfmtv (hcl_t* hcl, const fmtchar_t* fmt, hcl_fmtout_t* data, va_lis conv_len = HCL_COUNTOF(conv_buf); /* this must not fail since the dry-run above was successful */ - hcl_convutooochars (hcl, &usp[tot_len], &src_len, conv_buf, &conv_len); + /*hcl_convutooochars (hcl, &usp[tot_len], &src_len, conv_buf, &conv_len);*/ + hcl_conv_ucsn_to_bcsn_with_cmgr (hcl, &usp[tot_len], &src_len, conv_buf, &conv_len, hcl->cmgr); tot_len += src_len; if (conv_len > n) conv_len = n; diff --git a/lib/read.c b/lib/read.c index 5769ff1..6a02942 100644 --- a/lib/read.c +++ b/lib/read.c @@ -1810,8 +1810,7 @@ static int read_object (hcl_t* hcl) switch (TOKEN_TYPE(hcl)) { default: - hcl_seterrbfmt (hcl, HCL_EINTERN, "invalid token(type %d) encountered - %.*js", - TOKEN_TYPE(hcl), TOKEN_NAME_LEN(hcl), TOKEN_NAME_PTR(hcl)); + hcl_setsynerr (hcl, HCL_SYNERR_ILTOK, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); return -1; case HCL_IOTOK_EOF: