added hawk_rtx_makenumormbsvalwithuchars(), hawk_rtx_makenumormbsvalwithbchars(), hawk_rtx_makenumorstrvalwithuchars(), hawk_rtx_makenumorstrvalwithbchars()

This commit is contained in:
hyung-hwan 2020-03-06 07:43:53 +00:00
parent 52dea401f8
commit 4bd494d07b
4 changed files with 111 additions and 20 deletions

View File

@ -2688,6 +2688,20 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_makestrvalwithbchars2 (
/* -------------------------------------------------------------------------- */
HAWK_EXPORT hawk_val_t* hawk_rtx_makenumorstrvalwithuchars (
hawk_rtx_t* rtx,
const hawk_uch_t* ptr,
hawk_oow_t len
);
HAWK_EXPORT hawk_val_t* hawk_rtx_makenumorstrvalwithbchars (
hawk_rtx_t* rtx,
const hawk_bch_t* ptr,
hawk_oow_t len
);
/* -------------------------------------------------------------------------- */
HAWK_EXPORT hawk_val_t* hawk_rtx_makenstrvalwithuchars (
hawk_rtx_t* rtx,
const hawk_uch_t* ptr,
@ -2738,6 +2752,9 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_makenstrvalwithbcs (
# define hawk_rtx_makestrvalwithoocs hawk_rtx_makestrvalwithucs
# define hawk_rtx_makestrvalwithoochars2 hawk_rtx_makestrvalwithuchars2
# define hawk_rtx_makenumorstrvalwithoochars hawk_rtx_makenumorstrvalwithuchars
# define hawk_rtx_makenstrvalwithoochars hawk_rtx_makenstrvalwithuchars
# define hawk_rtx_makenstrvalwithoocstr hawk_rtx_makenstrvalwithucstr
# define hawk_rtx_makenstrvalwithoocs hawk_rtx_makenstrvalwithucs
#else
@ -2746,6 +2763,9 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_makenstrvalwithbcs (
# define hawk_rtx_makestrvalwithoocs hawk_rtx_makestrvalwithbcs
# define hawk_rtx_makestrvalwithoochars2 hawk_rtx_makestrvalwithbchars2
# define hawk_rtx_makenumorstrvalwithoochars hawk_rtx_makenumorstrvalwithbchars
# define hawk_rtx_makenstrvalwithoochars hawk_rtx_makenstrvalwithbchars
# define hawk_rtx_makenstrvalwithoocstr hawk_rtx_makenstrvalwithbcstr
# define hawk_rtx_makenstrvalwithoocs hawk_rtx_makenstrvalwithbcs
#endif
@ -2762,17 +2782,17 @@ hawk_val_t* hawk_rtx_makembsvalwithbchars (
hawk_oow_t len
);
hawk_val_t* hawk_rtx_makembsvalwithbcs (
hawk_rtx_t* rtx,
const hawk_bcs_t* bcs
);
hawk_val_t* hawk_rtx_makembsvalwithuchars (
hawk_rtx_t* rtx,
const hawk_uch_t* ptr,
hawk_oow_t len
);
hawk_val_t* hawk_rtx_makembsvalwithbcs (
hawk_rtx_t* rtx,
const hawk_bcs_t* bcs
);
hawk_val_t* hawk_rtx_makembsvalwithucs (
hawk_rtx_t* rtx,
const hawk_ucs_t* ucs

View File

@ -52,7 +52,7 @@ int hawk_rtx_setrec (hawk_rtx_t* rtx, hawk_oow_t idx, const hawk_oocs_t* str)
}
v = hawk_rtx_makenstrvalwithoocs(rtx, str);
if (v == HAWK_NULL)
if (HAWK_UNLIKELY(!v))
{
hawk_rtx_clrrec (rtx, 0);
return -1;
@ -77,10 +77,10 @@ int hawk_rtx_setrec (hawk_rtx_t* rtx, hawk_oow_t idx, const hawk_oocs_t* str)
hawk_rtx_clrrec (rtx, 0);
return -1;
}
/* recompose $0 */
v = hawk_rtx_makestrvalwithoocs (rtx, HAWK_OOECS_OOCS(&rtx->inrec.line));
if (v == HAWK_NULL)
v = hawk_rtx_makestrvalwithoocs(rtx, HAWK_OOECS_OOCS(&rtx->inrec.line));
if (HAWK_UNLIKELY(!v))
{
hawk_rtx_clrrec (rtx, 0);
return -1;
@ -109,7 +109,7 @@ static int split_record (hawk_rtx_t* rtx)
HAWK_ASSERT (rtx->inrec.nflds == 0);
/* get FS */
fs = hawk_rtx_getgbl (rtx, HAWK_GBL_FS);
fs = hawk_rtx_getgbl(rtx, HAWK_GBL_FS);
fsvtype = HAWK_RTX_GETVALTYPE (rtx, fs);
if (fsvtype == HAWK_VAL_NIL)
{
@ -126,7 +126,7 @@ static int split_record (hawk_rtx_t* rtx)
else
{
fs_ptr = hawk_rtx_valtooocstrdup(rtx, fs, &fs_len);
if (fs_ptr == HAWK_NULL) return -1;
if (HAWK_UNLIKELY(!fs_ptr)) return -1;
fs_free = fs_ptr;
}
@ -227,7 +227,7 @@ static int split_record (hawk_rtx_t* rtx)
len = HAWK_OOECS_LEN(&rtx->inrec.line);
#endif
while (p != HAWK_NULL)
while (p)
{
switch (how)
{

View File

@ -4461,7 +4461,7 @@ static HAWK_INLINE int __cmp_flt_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
int n;
/* SCO CC doesn't seem to handle right->nstr > 0 properly */
if (hawk->opt.trait & HAWK_NCMPONSTR || right->nstr /*> 0*/)
if ((hawk->opt.trait & HAWK_NCMPONSTR) || right->nstr /*> 0*/)
{
const hawk_ooch_t* end;
hawk_flt_t rr;
@ -4489,7 +4489,7 @@ static HAWK_INLINE int __cmp_flt_mbs (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
hawk_oow_t len0;
int n;
if (hawk->opt.trait & HAWK_NCMPONSTR || right->nstr /*> 0*/)
if ((hawk->opt.trait & HAWK_NCMPONSTR) || right->nstr /*> 0*/)
{
const hawk_bch_t* end;
hawk_flt_t rr;
@ -6796,8 +6796,10 @@ read_console_again:
{
hawk_val_t* v;
/* treat external input numerically if it can compose a number. */
v = hawk_rtx_makestrvalwithoocs(rtx, HAWK_OOECS_OOCS(buf));
if (v == HAWK_NULL)
/*v = hawk_rtx_makenumorstrvalwithoochars(rtx, HAWK_OOECS_PTR(buf), HAWK_OOECS_LEN(buf));*/
if (HAWK_UNLIKELY(!v))
{
ADJERR_LOC (rtx, &nde->loc);
return HAWK_NULL;
@ -6904,7 +6906,9 @@ read_console_again:
{
hawk_val_t* v;
/* treat external input numerically if it can compose a number. */
v = hawk_rtx_makembsvalwithbcs(rtx, HAWK_BECS_BCS(buf));
/*v = hawk_rtx_makenumormbsvalwithbchars(rtx, HAWK_BECS_PTR(buf), HAWK_BECS_LEN(buf));*/
if (v == HAWK_NULL)
{
ADJERR_LOC (rtx, &nde->loc);

View File

@ -298,6 +298,39 @@ hawk_val_t* hawk_rtx_makestrvalwithbchars2 (hawk_rtx_t* rtx, const hawk_bch_t* b
#endif
}
/* --------------------------------------------------------------------- */
hawk_val_t* hawk_rtx_makenumorstrvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_t* ptr, hawk_oow_t len)
{
hawk_t* hawk = hawk_rtx_gethawk(rtx);
int x;
hawk_int_t l;
hawk_flt_t r;
x = hawk_uchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), ptr, len, &l, &r);
if (x == 0) return hawk_rtx_makeintval(rtx, l);
else if (x >= 1) return hawk_rtx_makefltval(rtx, r);
return hawk_rtx_makestrvalwithuchars(rtx, ptr, len);
}
hawk_val_t* hawk_rtx_makenumorstrvalwithbchars (hawk_rtx_t* rtx, const hawk_bch_t* ptr, hawk_oow_t len)
{
hawk_t* hawk = hawk_rtx_gethawk(rtx);
int x;
hawk_int_t l;
hawk_flt_t r;
x = hawk_bchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), ptr, len, &l, &r);
if (x == 0) return hawk_rtx_makeintval(rtx, l);
else if (x >= 1) return hawk_rtx_makefltval(rtx, r);
return hawk_rtx_makestrvalwithbchars(rtx, ptr, len);
}
/* --------------------------------------------------------------------- */
hawk_val_t* hawk_rtx_makenstrvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_t* ptr, hawk_oow_t len)
{
hawk_t* hawk = hawk_rtx_gethawk(rtx);
@ -322,7 +355,6 @@ hawk_val_t* hawk_rtx_makenstrvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_t* p
return v;
}
hawk_val_t* hawk_rtx_makenstrvalwithbchars (hawk_rtx_t* rtx, const hawk_bch_t* ptr, hawk_oow_t len)
{
hawk_t* hawk = hawk_rtx_gethawk(rtx);
@ -368,6 +400,8 @@ hawk_val_t* hawk_rtx_makenstrvalwithbcs (hawk_rtx_t* rtx, const hawk_bcs_t* str)
}
/* --------------------------------------------------------------------- */
hawk_val_t* hawk_rtx_makembsvalwithbchars (hawk_rtx_t* rtx, const hawk_bch_t* ptr, hawk_oow_t len)
{
hawk_val_mbs_t* val = HAWK_NULL;
@ -393,10 +427,6 @@ hawk_val_t* hawk_rtx_makembsvalwithbchars (hawk_rtx_t* rtx, const hawk_bch_t* pt
return (hawk_val_t*)val;
}
hawk_val_t* hawk_rtx_makembsvalwithbcs (hawk_rtx_t* rtx, const hawk_bcs_t* bcs)
{
return hawk_rtx_makembsvalwithbchars(rtx, bcs->ptr, bcs->len);
}
hawk_val_t* hawk_rtx_makembsvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_t* ucs, hawk_oow_t len)
{
@ -416,11 +446,48 @@ hawk_val_t* hawk_rtx_makembsvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_t* uc
}
hawk_val_t* hawk_rtx_makembsvalwithbcs (hawk_rtx_t* rtx, const hawk_bcs_t* bcs)
{
return hawk_rtx_makembsvalwithbchars(rtx, bcs->ptr, bcs->len);
}
hawk_val_t* hawk_rtx_makembsvalwithucs (hawk_rtx_t* rtx, const hawk_ucs_t* ucs)
{
return hawk_rtx_makembsvalwithuchars(rtx, ucs->ptr, ucs->len);
}
/* --------------------------------------------------------------------- */
hawk_val_t* hawk_rtx_makenumormbsvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_t* ptr, hawk_oow_t len)
{
hawk_t* hawk = hawk_rtx_gethawk(rtx);
int x;
hawk_int_t l;
hawk_flt_t r;
x = hawk_uchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), ptr, len, &l, &r);
if (x == 0) return hawk_rtx_makeintval(rtx, l);
else if (x >= 1) return hawk_rtx_makefltval(rtx, r);
return hawk_rtx_makembsvalwithuchars(rtx, ptr, len);
}
hawk_val_t* hawk_rtx_makenumormbsvalwithbchars (hawk_rtx_t* rtx, const hawk_bch_t* ptr, hawk_oow_t len)
{
hawk_t* hawk = hawk_rtx_gethawk(rtx);
int x;
hawk_int_t l;
hawk_flt_t r;
x = hawk_bchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), ptr, len, &l, &r);
if (x == 0) return hawk_rtx_makeintval(rtx, l);
else if (x >= 1) return hawk_rtx_makefltval(rtx, r);
return hawk_rtx_makembsvalwithbchars(rtx, ptr, len);
}
/* --------------------------------------------------------------------- */
hawk_val_t* hawk_rtx_makerexval (hawk_rtx_t* rtx, const hawk_oocs_t* str, hawk_tre_t* code[2])
{
hawk_val_rex_t* val;