fixed error number setting issues in hcl_seterrxxx() functions.

prefixed internally used encoding conversion functions with hcl_
This commit is contained in:
hyunghwan.chung 2018-04-06 15:15:53 +00:00
parent f0de3ae292
commit 454e616e70
4 changed files with 68 additions and 27 deletions

View File

@ -749,8 +749,6 @@ void moo_seterrbfmt (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, ...)
moo_fmtout_t fo; moo_fmtout_t fo;
if (moo->shuterr) return; if (moo->shuterr) return;
moo->errnum = errnum;
moo->errmsg.len = 0; moo->errmsg.len = 0;
fo.mask = 0; /* not used */ fo.mask = 0; /* not used */
@ -760,6 +758,8 @@ void moo_seterrbfmt (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, ...)
va_start (ap, fmt); va_start (ap, fmt);
_errbfmtv (moo, fmt, &fo, ap); _errbfmtv (moo, fmt, &fo, ap);
va_end (ap); va_end (ap);
moo->errnum = errnum;
} }
void moo_seterrufmt (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, ...) void moo_seterrufmt (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, ...)
@ -768,8 +768,6 @@ void moo_seterrufmt (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, ...)
moo_fmtout_t fo; moo_fmtout_t fo;
if (moo->shuterr) return; if (moo->shuterr) return;
moo->errnum = errnum;
moo->errmsg.len = 0; moo->errmsg.len = 0;
fo.mask = 0; /* not used */ fo.mask = 0; /* not used */
@ -779,6 +777,8 @@ void moo_seterrufmt (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, ...)
va_start (ap, fmt); va_start (ap, fmt);
_errufmtv (moo, fmt, &fo, ap); _errufmtv (moo, fmt, &fo, ap);
va_end (ap); va_end (ap);
moo->errnum = errnum;
} }
@ -788,7 +788,6 @@ void moo_seterrbfmtv (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, va_
if (moo->shuterr) return; if (moo->shuterr) return;
moo->errnum = errnum;
moo->errmsg.len = 0; moo->errmsg.len = 0;
fo.mask = 0; /* not used */ fo.mask = 0; /* not used */
@ -796,6 +795,7 @@ void moo_seterrbfmtv (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, va_
fo.putcs = put_errcs; fo.putcs = put_errcs;
_errbfmtv (moo, fmt, &fo, ap); _errbfmtv (moo, fmt, &fo, ap);
moo->errnum = errnum;
} }
void moo_seterrufmtv (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, va_list ap) void moo_seterrufmtv (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, va_list ap)
@ -804,7 +804,6 @@ void moo_seterrufmtv (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, va_
if (moo->shuterr) return; if (moo->shuterr) return;
moo->errnum = errnum;
moo->errmsg.len = 0; moo->errmsg.len = 0;
fo.mask = 0; /* not used */ fo.mask = 0; /* not used */
@ -812,4 +811,5 @@ void moo_seterrufmtv (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, va_
fo.putcs = put_errcs; fo.putcs = put_errcs;
_errufmtv (moo, fmt, &fo, ap); _errufmtv (moo, fmt, &fo, ap);
moo->errnum = errnum;
} }

View File

@ -166,7 +166,7 @@ static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_lis
/* fmtchar is uch. ooch is bch. convert uch to bch */ /* fmtchar is uch. ooch is bch. convert uch to bch */
ucslen = 1; ucslen = 1;
bcslen = MOO_COUNTOF(bcsbuf); bcslen = MOO_COUNTOF(bcsbuf);
if (moo_convutooochars(moo, &fch, &ucslen, bcsbuf, &bcslen) <= -1) goto oops; if (moo_conv_ucsn_to_bcsn_with_cmgr(&fch, &ucslen, bcsbuf, &bcslen, moo->cmgr) <= -1) goto oops;
PUT_OOCS (bcsbuf, bcslen); PUT_OOCS (bcsbuf, bcslen);
} }
#endif #endif
@ -467,7 +467,7 @@ static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_lis
/* get the length */ /* get the length */
for (bslen = 0; bsp[bslen]; bslen++); for (bslen = 0; bsp[bslen]; bslen++);
if (moo_convbtooochars (moo, bsp, &bslen, MOO_NULL, &slen) <= -1) goto oops; if (moo_conv_bcsn_to_ucsn_with_cmgr(bsp, &bslen, MOO_NULL, &slen, moo->cmgr, 0) <= -1) goto oops;
/* slen holds the length after conversion */ /* slen holds the length after conversion */
n = slen; n = slen;
@ -487,7 +487,7 @@ static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_lis
conv_len = MOO_COUNTOF(conv_buf); conv_len = MOO_COUNTOF(conv_buf);
/* this must not fail since the dry-run above was successful */ /* this must not fail since the dry-run above was successful */
moo_convbtooochars (moo, &bsp[tot_len], &src_len, conv_buf, &conv_len); moo_conv_bcsn_to_ucsn_with_cmgr(&bsp[tot_len], &src_len, conv_buf, &conv_len, moo->cmgr, 0);
tot_len += src_len; tot_len += src_len;
if (conv_len > n) conv_len = n; if (conv_len > n) conv_len = n;
@ -536,7 +536,7 @@ static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_lis
/* get the length */ /* get the length */
for (uslen = 0; usp[uslen]; uslen++); for (uslen = 0; usp[uslen]; uslen++);
if (moo_convutooochars (moo, usp, &uslen, MOO_NULL, &slen) <= -1) goto oops; if (moo_conv_ucsn_to_bcsn_with_cmgr(usp, &uslen, MOO_NULL, &slen, moo->cmgr) <= -1) goto oops;
/* slen holds the length after conversion */ /* slen holds the length after conversion */
n = slen; n = slen;
@ -555,7 +555,7 @@ static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_lis
conv_len = MOO_COUNTOF(conv_buf); conv_len = MOO_COUNTOF(conv_buf);
/* this must not fail since the dry-run above was successful */ /* this must not fail since the dry-run above was successful */
moo_convutooochars (moo, &usp[tot_len], &src_len, conv_buf, &conv_len); moo_conv_ucsn_to_bcsn_with_cmgr (&usp[tot_len], &src_len, conv_buf, &conv_len, moo->cmgr);
tot_len += src_len; tot_len += src_len;
if (conv_len > n) conv_len = n; if (conv_len > n) conv_len = n;

View File

@ -345,6 +345,49 @@ MOO_EXPORT int moo_concatoocstrtosbuf (
int id int id
); );
#if defined(MOO_OOCH_IS_UCH)
# define moo_conv_oocs_to_bcs_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) moo_conv_ucs_to_bcs_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr)
# define moo_conv_oocsn_to_bcsn_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) moo_conv_ucsn_to_bcsn_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr)
#else
# define moo_conv_oocs_to_ucs_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) moo_conv_bcs_to_ucs_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0)
# define moo_conv_oocsn_to_ucsn_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) moo_conv_bcsn_to_ucsn_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0)
#endif
MOO_EXPORT int moo_conv_bcs_to_ucs_with_cmgr (
const moo_bch_t* bcs,
moo_oow_t* bcslen,
moo_uch_t* ucs,
moo_oow_t* ucslen,
moo_cmgr_t* cmgr,
int all
);
MOO_EXPORT int moo_conv_bcsn_to_ucsn_with_cmgr (
const moo_bch_t* bcs,
moo_oow_t* bcslen,
moo_uch_t* ucs,
moo_oow_t* ucslen,
moo_cmgr_t* cmgr,
int all
);
MOO_EXPORT int moo_conv_ucs_to_bcs_with_cmgr (
const moo_uch_t* ucs,
moo_oow_t* ucslen,
moo_bch_t* bcs,
moo_oow_t* bcslen,
moo_cmgr_t* cmgr
);
MOO_EXPORT int moo_conv_ucsn_to_bcsn_with_cmgr (
const moo_uch_t* ucs,
moo_oow_t* ucslen,
moo_bch_t* bcs,
moo_oow_t* bcslen,
moo_cmgr_t* cmgr
);
MOO_EXPORT moo_cmgr_t* moo_get_utf8_cmgr ( MOO_EXPORT moo_cmgr_t* moo_get_utf8_cmgr (
void void
); );

View File

@ -327,7 +327,6 @@ moo_bch_t* moo_rfindbchar (const moo_bch_t* ptr, moo_oow_t len, moo_bch_t c)
return MOO_NULL; return MOO_NULL;
} }
moo_uch_t* moo_finducharinucstr (const moo_uch_t* ptr, moo_uch_t c) moo_uch_t* moo_finducharinucstr (const moo_uch_t* ptr, moo_uch_t c)
{ {
while (*ptr != '\0') while (*ptr != '\0')
@ -349,6 +348,7 @@ moo_bch_t* moo_findbcharinbcstr (const moo_bch_t* ptr, moo_bch_t c)
return MOO_NULL; return MOO_NULL;
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
int moo_concatoocstrtosbuf (moo_t* moo, const moo_ooch_t* str, int id) int moo_concatoocstrtosbuf (moo_t* moo, const moo_ooch_t* str, int id)
@ -387,10 +387,9 @@ int moo_copyoocstrtosbuf (moo_t* moo, const moo_ooch_t* str, int id)
return moo_concatoocstrtosbuf (moo, str, id); return moo_concatoocstrtosbuf (moo, str, id);
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static MOO_INLINE int bcsn_to_ucsn_with_cmgr ( MOO_INLINE int moo_conv_bcsn_to_ucsn_with_cmgr (
const moo_bch_t* bcs, moo_oow_t* bcslen, const moo_bch_t* bcs, moo_oow_t* bcslen,
moo_uch_t* ucs, moo_oow_t* ucslen, moo_cmgr_t* cmgr, int all) moo_uch_t* ucs, moo_oow_t* ucslen, moo_cmgr_t* cmgr, int all)
{ {
@ -511,7 +510,7 @@ static MOO_INLINE int bcsn_to_ucsn_with_cmgr (
return ret; return ret;
} }
static MOO_INLINE int bcs_to_ucs_with_cmgr ( MOO_INLINE int moo_conv_bcs_to_ucs_with_cmgr (
const moo_bch_t* bcs, moo_oow_t* bcslen, const moo_bch_t* bcs, moo_oow_t* bcslen,
moo_uch_t* ucs, moo_oow_t* ucslen, moo_cmgr_t* cmgr, int all) moo_uch_t* ucs, moo_oow_t* ucslen, moo_cmgr_t* cmgr, int all)
{ {
@ -522,7 +521,7 @@ static MOO_INLINE int bcs_to_ucs_with_cmgr (
for (bp = bcs; *bp != '\0'; bp++) /* nothing */ ; for (bp = bcs; *bp != '\0'; bp++) /* nothing */ ;
mlen = bp - bcs; wlen = *ucslen; mlen = bp - bcs; wlen = *ucslen;
n = bcsn_to_ucsn_with_cmgr (bcs, &mlen, ucs, &wlen, cmgr, all); n = moo_conv_bcsn_to_ucsn_with_cmgr (bcs, &mlen, ucs, &wlen, cmgr, all);
if (ucs) if (ucs)
{ {
/* null-terminate the target buffer if it has room for it. */ /* null-terminate the target buffer if it has room for it. */
@ -534,7 +533,7 @@ static MOO_INLINE int bcs_to_ucs_with_cmgr (
return n; return n;
} }
static MOO_INLINE int ucsn_to_bcsn_with_cmgr ( MOO_INLINE int moo_conv_ucsn_to_bcsn_with_cmgr (
const moo_uch_t* ucs, moo_oow_t* ucslen, const moo_uch_t* ucs, moo_oow_t* ucslen,
moo_bch_t* bcs, moo_oow_t* bcslen, moo_cmgr_t* cmgr) moo_bch_t* bcs, moo_oow_t* bcslen, moo_cmgr_t* cmgr)
{ {
@ -603,8 +602,7 @@ static MOO_INLINE int ucsn_to_bcsn_with_cmgr (
return ret; return ret;
} }
MOO_INLINE int moo_conv_ucs_to_bcs_with_cmgr (
static int ucs_to_bcs_with_cmgr (
const moo_uch_t* ucs, moo_oow_t* ucslen, const moo_uch_t* ucs, moo_oow_t* ucslen,
moo_bch_t* bcs, moo_oow_t* bcslen, moo_cmgr_t* cmgr) moo_bch_t* bcs, moo_oow_t* bcslen, moo_cmgr_t* cmgr)
{ {
@ -701,25 +699,25 @@ moo_cmgr_t* moo_get_utf8_cmgr (void)
int moo_convutf8touchars (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) int moo_convutf8touchars (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen)
{ {
/* the source is length bound */ /* the source is length bound */
return bcsn_to_ucsn_with_cmgr (bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); return moo_conv_bcsn_to_ucsn_with_cmgr(bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0);
} }
int moo_convutoutf8chars (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) int moo_convutoutf8chars (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen)
{ {
/* length bound */ /* length bound */
return ucsn_to_bcsn_with_cmgr (ucs, ucslen, bcs, bcslen, &utf8_cmgr); return moo_conv_ucsn_to_bcsn_with_cmgr(ucs, ucslen, bcs, bcslen, &utf8_cmgr);
} }
int moo_convutf8toucstr (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) int moo_convutf8toucstr (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen)
{ {
/* null-terminated. */ /* null-terminated. */
return bcs_to_ucs_with_cmgr (bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); return moo_conv_bcs_to_ucs_with_cmgr(bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0);
} }
int moo_convutoutf8cstr (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) int moo_convutoutf8cstr (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen)
{ {
/* null-terminated */ /* null-terminated */
return ucs_to_bcs_with_cmgr (ucs, ucslen, bcs, bcslen, &utf8_cmgr); return moo_conv_ucs_to_bcs_with_cmgr(ucs, ucslen, bcs, bcslen, &utf8_cmgr);
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
@ -729,7 +727,7 @@ int moo_convbtouchars (moo_t* moo, const moo_bch_t* bcs, moo_oow_t* bcslen, moo_
/* length bound */ /* length bound */
int n; int n;
n = bcsn_to_ucsn_with_cmgr(bcs, bcslen, ucs, ucslen, moo->cmgr, 0); n = moo_conv_bcsn_to_ucsn_with_cmgr(bcs, bcslen, ucs, ucslen, moo->cmgr, 0);
if (n <= -1) if (n <= -1)
{ {
@ -745,7 +743,7 @@ int moo_convutobchars (moo_t* moo, const moo_uch_t* ucs, moo_oow_t* ucslen, moo_
/* length bound */ /* length bound */
int n; int n;
n = ucsn_to_bcsn_with_cmgr(ucs, ucslen, bcs, bcslen, moo->cmgr); n = moo_conv_ucsn_to_bcsn_with_cmgr(ucs, ucslen, bcs, bcslen, moo->cmgr);
if (n <= -1) if (n <= -1)
{ {
@ -760,7 +758,7 @@ int moo_convbtoucstr (moo_t* moo, const moo_bch_t* bcs, moo_oow_t* bcslen, moo_u
/* null-terminated. */ /* null-terminated. */
int n; int n;
n = bcs_to_ucs_with_cmgr(bcs, bcslen, ucs, ucslen, moo->cmgr, 0); n = moo_conv_bcs_to_ucs_with_cmgr(bcs, bcslen, ucs, ucslen, moo->cmgr, 0);
if (n <= -1) if (n <= -1)
{ {
@ -775,7 +773,7 @@ int moo_convutobcstr (moo_t* moo, const moo_uch_t* ucs, moo_oow_t* ucslen, moo_b
/* null-terminated */ /* null-terminated */
int n; int n;
n = ucs_to_bcs_with_cmgr(ucs, ucslen, bcs, bcslen, moo->cmgr); n = moo_conv_ucs_to_bcs_with_cmgr(ucs, ucslen, bcs, bcslen, moo->cmgr);
if (n <= -1) if (n <= -1)
{ {