From 1bbfee29579f61ca1ee1a4de22555da861b8f611 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 12 Sep 2021 02:41:33 +0000 Subject: [PATCH] updated utl-str.m4 and utl-str.c.m4 --- hio/lib/hio-utl.h | 35 +------- hio/lib/utl-str.c | 78 +----------------- hio/lib/utl-str.c.m4 | 34 ++++---- hio/lib/utl-str.m4 | 189 +++++++++++++++++++++---------------------- 4 files changed, 114 insertions(+), 222 deletions(-) diff --git a/hio/lib/hio-utl.h b/hio/lib/hio-utl.h index 262b8b0..dddee11 100644 --- a/hio/lib/hio-utl.h +++ b/hio/lib/hio-utl.h @@ -39,35 +39,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* ========================================================================= * ENDIAN CHANGE OF A CONSTANT * ========================================================================= */ @@ -1142,8 +1113,7 @@ unsigned y = hio_chars_to_uint(L"0x12345", 7, 0, NUL int a = hio_chars_to_int("-0x12345", 8, 0, NULL, NULL); int b = hio_chars_to_int(L"-0x12345", 8, 0, NULL, NULL); */ -template -INT_TYPE hio_chars_to_int (const CHAR_TYPE* str, hio_oow_t len, int option, const CHAR_TYPE** endptr, int* is_sober) +templateINT_TYPE hio_chars_to_int (const CHAR_TYPE* str, hio_oow_t len, int option, const CHAR_TYPE** endptr, int* is_sober) { INT_TYPE n = 0; const CHAR_TYPE* p, * pp; @@ -1258,8 +1228,7 @@ INT_TYPE hio_chars_to_int (const CHAR_TYPE* str, hio_oow_t len, int option, cons return (negative)? -n: n; } -template -UINT_TYPE hio_chars_to_uint (const CHAR_TYPE* str, hio_oow_t len, int option, const CHAR_TYPE** endptr, int* is_sober) +templateUINT_TYPE hio_chars_to_uint (const CHAR_TYPE* str, hio_oow_t len, int option, const CHAR_TYPE** endptr, int* is_sober) { UINT_TYPE n = 0; const CHAR_TYPE* p, * pp; diff --git a/hio/lib/utl-str.c b/hio/lib/utl-str.c index b81de5c..55afb0d 100644 --- a/hio/lib/utl-str.c +++ b/hio/lib/utl-str.c @@ -33,39 +33,6 @@ #include - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - hio_oow_t hio_count_ucstr (const hio_uch_t* str) { const hio_uch_t* ptr = str; @@ -73,7 +40,6 @@ hio_oow_t hio_count_ucstr (const hio_uch_t* str) return ptr - str; } - hio_oow_t hio_count_bcstr (const hio_bch_t* str) { const hio_bch_t* ptr = str; @@ -81,8 +47,6 @@ hio_oow_t hio_count_bcstr (const hio_bch_t* str) return ptr - str; } - - int hio_equal_uchars (const hio_uch_t* str1, const hio_uch_t* str2, hio_oow_t len) { hio_oow_t i; @@ -98,7 +62,6 @@ int hio_equal_uchars (const hio_uch_t* str1, const hio_uch_t* str2, hio_oow_t le return 1; } - int hio_equal_bchars (const hio_bch_t* str1, const hio_bch_t* str2, hio_oow_t len) { hio_oow_t i; @@ -114,8 +77,6 @@ int hio_equal_bchars (const hio_bch_t* str1, const hio_bch_t* str2, hio_oow_t le return 1; } - - int hio_comp_uchars (const hio_uch_t* str1, hio_oow_t len1, const hio_uch_t* str2, hio_oow_t len2, int ignorecase) { hio_uchu_t c1, c2; @@ -156,7 +117,6 @@ int hio_comp_uchars (const hio_uch_t* str1, hio_oow_t len1, const hio_uch_t* str return (str2 < end2)? -1: 0; } - int hio_comp_bchars (const hio_bch_t* str1, hio_oow_t len1, const hio_bch_t* str2, hio_oow_t len2, int ignorecase) { hio_bchu_t c1, c2; @@ -197,8 +157,6 @@ int hio_comp_bchars (const hio_bch_t* str1, hio_oow_t len1, const hio_bch_t* str return (str2 < end2)? -1: 0; } - - int hio_comp_ucstr (const hio_uch_t* str1, const hio_uch_t* str2, int ignorecase) { if (ignorecase) @@ -223,7 +181,6 @@ int hio_comp_ucstr (const hio_uch_t* str1, const hio_uch_t* str2, int ignorecase } } - int hio_comp_bcstr (const hio_bch_t* str1, const hio_bch_t* str2, int ignorecase) { if (ignorecase) @@ -248,8 +205,6 @@ int hio_comp_bcstr (const hio_bch_t* str1, const hio_bch_t* str2, int ignorecase } } - - int hio_comp_ucstr_limited (const hio_uch_t* str1, const hio_uch_t* str2, hio_oow_t maxlen, int ignorecase) { if (maxlen == 0) return 0; @@ -276,7 +231,6 @@ int hio_comp_ucstr_limited (const hio_uch_t* str1, const hio_uch_t* str2, hio_oo } } - int hio_comp_bcstr_limited (const hio_bch_t* str1, const hio_bch_t* str2, hio_oow_t maxlen, int ignorecase) { if (maxlen == 0) return 0; @@ -303,8 +257,7 @@ int hio_comp_bcstr_limited (const hio_bch_t* str1, const hio_bch_t* str2, hio_oo } } - - hio_oow_t hio_concat_uchars_to_ucstr (hio_uch_t* buf, hio_oow_t bsz, const hio_uch_t* str, hio_oow_t len) +hio_oow_t hio_concat_uchars_to_ucstr (hio_uch_t* buf, hio_oow_t bsz, const hio_uch_t* str, hio_oow_t len) { hio_uch_t* p, * p2; const hio_uch_t* end; @@ -328,7 +281,7 @@ int hio_comp_bcstr_limited (const hio_bch_t* str1, const hio_bch_t* str2, hio_oo return p - buf; } - hio_oow_t hio_concat_bchars_to_bcstr (hio_bch_t* buf, hio_oow_t bsz, const hio_bch_t* str, hio_oow_t len) +hio_oow_t hio_concat_bchars_to_bcstr (hio_bch_t* buf, hio_oow_t bsz, const hio_bch_t* str, hio_oow_t len) { hio_bch_t* p, * p2; const hio_bch_t* end; @@ -352,8 +305,6 @@ int hio_comp_bcstr_limited (const hio_bch_t* str1, const hio_bch_t* str2, hio_oo return p - buf; } - - hio_oow_t hio_concat_ucstr (hio_uch_t* buf, hio_oow_t bsz, const hio_uch_t* str) { hio_uch_t* p, * p2; @@ -375,7 +326,6 @@ hio_oow_t hio_concat_ucstr (hio_uch_t* buf, hio_oow_t bsz, const hio_uch_t* str) return p - buf; } - hio_oow_t hio_concat_bcstr (hio_bch_t* buf, hio_oow_t bsz, const hio_bch_t* str) { hio_bch_t* p, * p2; @@ -397,23 +347,18 @@ hio_oow_t hio_concat_bcstr (hio_bch_t* buf, hio_oow_t bsz, const hio_bch_t* str) return p - buf; } - - void hio_fill_uchars (hio_uch_t* dst, hio_uch_t ch, hio_oow_t len) { hio_oow_t i; for (i = 0; i < len; i++) dst[i] = ch; } - void hio_fill_bchars (hio_bch_t* dst, hio_bch_t ch, hio_oow_t len) { hio_oow_t i; for (i = 0; i < len; i++) dst[i] = ch; } - - hio_uch_t* hio_find_uchar (const hio_uch_t* ptr, hio_oow_t len, hio_uch_t c) { const hio_uch_t* end; @@ -428,7 +373,6 @@ hio_uch_t* hio_find_uchar (const hio_uch_t* ptr, hio_oow_t len, hio_uch_t c) return HIO_NULL; } - hio_bch_t* hio_find_bchar (const hio_bch_t* ptr, hio_oow_t len, hio_bch_t c) { const hio_bch_t* end; @@ -443,8 +387,6 @@ hio_bch_t* hio_find_bchar (const hio_bch_t* ptr, hio_oow_t len, hio_bch_t c) return HIO_NULL; } - - hio_uch_t* hio_rfind_uchar (const hio_uch_t* ptr, hio_oow_t len, hio_uch_t c) { const hio_uch_t* cur; @@ -459,7 +401,6 @@ hio_uch_t* hio_rfind_uchar (const hio_uch_t* ptr, hio_oow_t len, hio_uch_t c) return HIO_NULL; } - hio_bch_t* hio_rfind_bchar (const hio_bch_t* ptr, hio_oow_t len, hio_bch_t c) { const hio_bch_t* cur; @@ -474,8 +415,6 @@ hio_bch_t* hio_rfind_bchar (const hio_bch_t* ptr, hio_oow_t len, hio_bch_t c) return HIO_NULL; } - - hio_uch_t* hio_find_uchar_in_ucstr (const hio_uch_t* ptr, hio_uch_t c) { while (*ptr != '\0') @@ -487,7 +426,6 @@ hio_uch_t* hio_find_uchar_in_ucstr (const hio_uch_t* ptr, hio_uch_t c) return HIO_NULL; } - hio_bch_t* hio_find_bchar_in_bcstr (const hio_bch_t* ptr, hio_bch_t c) { while (*ptr != '\0') @@ -499,8 +437,6 @@ hio_bch_t* hio_find_bchar_in_bcstr (const hio_bch_t* ptr, hio_bch_t c) return HIO_NULL; } - - hio_uch_t* hio_trim_uchars (const hio_uch_t* str, hio_oow_t* len, int flags) { const hio_uch_t* p = str, * end = str + *len; @@ -543,7 +479,6 @@ hio_uch_t* hio_trim_uchars (const hio_uch_t* str, hio_oow_t* len, int flags) return (hio_uch_t*)str; } - hio_bch_t* hio_trim_bchars (const hio_bch_t* str, hio_oow_t* len, int flags) { const hio_bch_t* p = str, * end = str + *len; @@ -586,8 +521,6 @@ hio_bch_t* hio_trim_bchars (const hio_bch_t* str, hio_oow_t* len, int flags) return (hio_bch_t*)str; } - - int hio_split_ucstr (hio_uch_t* s, const hio_uch_t* delim, hio_uch_t lquote, hio_uch_t rquote, hio_uch_t escape) { hio_uch_t* p = s, *d; @@ -826,7 +759,6 @@ exit_point: return cnt; } - int hio_split_bcstr (hio_bch_t* s, const hio_bch_t* delim, hio_bch_t lquote, hio_bch_t rquote, hio_bch_t escape) { hio_bch_t* p = s, *d; @@ -1065,8 +997,6 @@ exit_point: return cnt; } - - hio_intmax_t hio_uchars_to_intmax (const hio_uch_t* str, hio_oow_t len, int option, const hio_uch_t** endptr, int* is_sober) { hio_intmax_t n = 0; @@ -1182,7 +1112,6 @@ hio_intmax_t hio_uchars_to_intmax (const hio_uch_t* str, hio_oow_t len, int opti return (negative)? -n: n; } - hio_intmax_t hio_bchars_to_intmax (const hio_bch_t* str, hio_oow_t len, int option, const hio_bch_t** endptr, int* is_sober) { hio_intmax_t n = 0; @@ -1298,8 +1227,6 @@ hio_intmax_t hio_bchars_to_intmax (const hio_bch_t* str, hio_oow_t len, int opti return (negative)? -n: n; } - - hio_uintmax_t hio_uchars_to_uintmax (const hio_uch_t* str, hio_oow_t len, int option, const hio_uch_t** endptr, int* is_sober) { hio_uintmax_t n = 0; @@ -1410,7 +1337,6 @@ hio_uintmax_t hio_uchars_to_uintmax (const hio_uch_t* str, hio_oow_t len, int op return n; } - hio_uintmax_t hio_bchars_to_uintmax (const hio_bch_t* str, hio_oow_t len, int option, const hio_bch_t** endptr, int* is_sober) { hio_uintmax_t n = 0; diff --git a/hio/lib/utl-str.c.m4 b/hio/lib/utl-str.c.m4 index 869b886..25ed1a6 100644 --- a/hio/lib/utl-str.c.m4 +++ b/hio/lib/utl-str.c.m4 @@ -31,52 +31,52 @@ #include "hio-prv.h" #include - +dnl dnl --------------------------------------------------------------------------- -include(`utl-str.m4') +include(`utl-str.m4')dnl dnl --------------------------------------------------------------------------- - +dnl fn_count_cstr(hio_count_ucstr, hio_uch_t) fn_count_cstr(hio_count_bcstr, hio_bch_t) - +dnl -- fn_equal_chars(hio_equal_uchars, hio_uch_t) fn_equal_chars(hio_equal_bchars, hio_bch_t) - +dnl -- fn_comp_chars(hio_comp_uchars, hio_uch_t, hio_uchu_t, hio_to_uch_lower) fn_comp_chars(hio_comp_bchars, hio_bch_t, hio_bchu_t, hio_to_bch_lower) - +dnl -- fn_comp_cstr(hio_comp_ucstr, hio_uch_t, hio_uchu_t, hio_to_uch_lower) fn_comp_cstr(hio_comp_bcstr, hio_bch_t, hio_bchu_t, hio_to_bch_lower) - +dnl -- fn_comp_cstr_limited(hio_comp_ucstr_limited, hio_uch_t, hio_uchu_t, hio_to_uch_lower) fn_comp_cstr_limited(hio_comp_bcstr_limited, hio_bch_t, hio_bchu_t, hio_to_bch_lower) - +dnl -- fn_concat_chars_to_cstr(hio_concat_uchars_to_ucstr, hio_uch_t, hio_count_ucstr) fn_concat_chars_to_cstr(hio_concat_bchars_to_bcstr, hio_bch_t, hio_count_bcstr) - +dnl -- fn_concat_cstr(hio_concat_ucstr, hio_uch_t, hio_count_ucstr) fn_concat_cstr(hio_concat_bcstr, hio_bch_t, hio_count_bcstr) - +dnl -- fn_fill_chars(hio_fill_uchars, hio_uch_t) fn_fill_chars(hio_fill_bchars, hio_bch_t) - +dnl -- fn_find_char(hio_find_uchar, hio_uch_t) fn_find_char(hio_find_bchar, hio_bch_t) - +dnl -- fn_rfind_char(hio_rfind_uchar, hio_uch_t) fn_rfind_char(hio_rfind_bchar, hio_bch_t) - +dnl -- fn_find_char_in_cstr(hio_find_uchar_in_ucstr, hio_uch_t) fn_find_char_in_cstr(hio_find_bchar_in_bcstr, hio_bch_t) - +dnl -- fn_trim_chars(hio_trim_uchars, hio_uch_t, hio_is_uch_space, HIO_TRIM_UCHARS) fn_trim_chars(hio_trim_bchars, hio_bch_t, hio_is_bch_space, HIO_TRIM_BCHARS) - +dnl -- fn_split_cstr(hio_split_ucstr, hio_uch_t, hio_is_uch_space, hio_copy_ucstr_unlimited) fn_split_cstr(hio_split_bcstr, hio_bch_t, hio_is_bch_space, hio_copy_bcstr_unlimited) - +dnl -- fn_chars_to_int(hio_uchars_to_intmax, hio_uch_t, hio_intmax_t, hio_is_uch_space, HIO_UCHARS_TO_INTMAX) fn_chars_to_int(hio_bchars_to_intmax, hio_bch_t, hio_intmax_t, hio_is_bch_space, HIO_BCHARS_TO_INTMAX) - +dnl -- fn_chars_to_uint(hio_uchars_to_uintmax, hio_uch_t, hio_uintmax_t, hio_is_uch_space, HIO_UCHARS_TO_UINTMAX) fn_chars_to_uint(hio_bchars_to_uintmax, hio_bch_t, hio_uintmax_t, hio_is_bch_space, HIO_BCHARS_TO_UINTMAX) diff --git a/hio/lib/utl-str.m4 b/hio/lib/utl-str.m4 index aa5d5c3..af333a7 100644 --- a/hio/lib/utl-str.m4 +++ b/hio/lib/utl-str.m4 @@ -1,18 +1,17 @@ dnl --------------------------------------------------------------------------- -changequote(`[[', `]]') - +changequote(`[[', `]]')dnl dnl --------------------------------------------------------------------------- -define([[fn_count_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) +define([[fn_count_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl hio_oow_t _fn_name_ (const _char_type_* str) { const _char_type_* ptr = str; while (*ptr != '\0') ptr++; return ptr - str; } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -define([[fn_equal_chars]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) +define([[fn_equal_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t len) { hio_oow_t i; @@ -27,10 +26,10 @@ int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t len) return 1; } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -define([[fn_comp_chars]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[_chau_type_]], $3) +define([[fn_comp_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_chau_type_]], $3)pushdef([[_to_lower_]], $4)dnl int _fn_name_ (const _char_type_* str1, hio_oow_t len1, const _char_type_* str2, hio_oow_t len2, int ignorecase) { _chau_type_ c1, c2; @@ -41,10 +40,10 @@ int _fn_name_ (const _char_type_* str1, hio_oow_t len1, const _char_type_* str2, { while (str1 < end1) { - c1 = $4(*str1); + c1 = _to_lower_()(*str1); if (str2 < end2) { - c2 = $4(*str2); + c2 = _to_lower_()(*str2); if (c1 > c2) return 1; if (c1 < c2) return -1; } @@ -70,21 +69,21 @@ int _fn_name_ (const _char_type_* str1, hio_oow_t len1, const _char_type_* str2, return (str2 < end2)? -1: 0; } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_chau_type_]])popdef([[_to_lower_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -define([[fn_comp_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[_chau_type_]], $3) +define([[fn_comp_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_chau_type_]], $3)pushdef([[_to_lower_]], $4)dnl int _fn_name_ (const _char_type_* str1, const _char_type_* str2, int ignorecase) { if (ignorecase) { - while ($4(*str1) == $4(*str2)) + while (_to_lower_()(*str1) == _to_lower_()(*str2)) { if (*str1 == '\0') return 0; str1++; str2++; } - return ((_chau_type_)$4(*str1) > (_chau_type_)$4(*str2))? 1: -1; + return ((_chau_type_)_to_lower_()(*str1) > (_chau_type_)_to_lower_()(*str2))? 1: -1; } else { @@ -97,23 +96,23 @@ int _fn_name_ (const _char_type_* str1, const _char_type_* str2, int ignorecase) return ((_chau_type_)*str1 > (_chau_type_)*str2)? 1: -1; } } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_chau_type_]])popdef([[_to_lower_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -define([[fn_comp_cstr_limited]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[_chau_type_]], $3) +define([[fn_comp_cstr_limited]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_chau_type_]], $3)pushdef([[_to_lower_]], $4)dnl int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t maxlen, int ignorecase) { if (maxlen == 0) return 0; if (ignorecase) { - while ($4(*str1) == $4(*str2)) + while (_to_lower_()(*str1) == _to_lower_()(*str2)) { if (*str1 == '\0' || maxlen == 1) return 0; str1++; str2++; maxlen--; } - return ((_chau_type_)$4(*str1) > (_chau_type_)$4(*str2))? 1: -1; + return ((_chau_type_)_to_lower_()(*str1) > (_chau_type_)_to_lower_()(*str2))? 1: -1; } else { @@ -126,17 +125,17 @@ int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t maxle return ((_chau_type_)*str1 > (_chau_type_)*str2)? 1: -1; } } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_chau_type_]])popdef([[_to_lower_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -define([[fn_concat_chars_to_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) dnl: $3 count_str +define([[fn_concat_chars_to_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_count_str_]], $3)dnl hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str, hio_oow_t len) { _char_type_* p, * p2; const _char_type_* end; hio_oow_t blen; - blen = $3(buf); + blen = _count_str_()(buf); if (blen >= bsz) return blen; /* something wrong */ p = buf + blen; @@ -153,17 +152,17 @@ hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str, hi if (bsz > 0) *p = '\0'; return p - buf; } -]]) +popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_count_str_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -dnl $3: count_str -define([[fn_concat_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) +define([[fn_concat_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_count_str_]], $3)dnl hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str) { _char_type_* p, * p2; hio_oow_t blen; - blen = $3(buf); + blen = _count_str_()(buf); if (blen >= bsz) return blen; /* something wrong */ p = buf + blen; @@ -178,19 +177,19 @@ hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str) if (bsz > 0) *p = '\0'; return p - buf; } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_count_str_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -define([[fn_fill_chars]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) +define([[fn_fill_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl void _fn_name_ (_char_type_* dst, _char_type_ ch, hio_oow_t len) { hio_oow_t i; for (i = 0; i < len; i++) dst[i] = ch; } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -define([[fn_find_char]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) +define([[fn_find_char]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl _char_type_* _fn_name_ (const _char_type_* ptr, hio_oow_t len, _char_type_ c) { const _char_type_* end; @@ -204,10 +203,10 @@ _char_type_* _fn_name_ (const _char_type_* ptr, hio_oow_t len, _char_type_ c) return HIO_NULL; } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -define([[fn_rfind_char]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) +define([[fn_rfind_char]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl _char_type_* _fn_name_ (const _char_type_* ptr, hio_oow_t len, _char_type_ c) { const _char_type_* cur; @@ -221,10 +220,10 @@ _char_type_* _fn_name_ (const _char_type_* ptr, hio_oow_t len, _char_type_ c) return HIO_NULL; } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -define([[fn_find_char_in_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) +define([[fn_find_char_in_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl _char_type_* _fn_name_ (const _char_type_* ptr, _char_type_ c) { while (*ptr != '\0') @@ -235,11 +234,10 @@ _char_type_* _fn_name_ (const _char_type_* ptr, _char_type_ c) return HIO_NULL; } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -dnl $3: is_space $4: prefix for option values -define([[fn_trim_chars]], [[define([[_fn_name_]], $1) define([[_char_type_]], $2) +define([[fn_trim_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_is_space_]], $3)pushdef([[_prefix_]], $4)dnl _char_type_* _fn_name_ (const _char_type_* str, hio_oow_t* len, int flags) { const _char_type_* p = str, * end = str + *len; @@ -250,7 +248,7 @@ _char_type_* _fn_name_ (const _char_type_* str, hio_oow_t* len, int flags) do { - if (!$3(*p)) + if (!_is_space_()(*p)) { if (s == HIO_NULL) s = p; e = p; @@ -261,11 +259,11 @@ _char_type_* _fn_name_ (const _char_type_* str, hio_oow_t* len, int flags) if (e) { - if (flags & $4_RIGHT) + if (flags & _prefix_()_RIGHT) { *len -= end - e - 1; } - if (flags & $4_LEFT) + if (flags & _prefix_()_LEFT) { *len -= s - str; str = s; @@ -274,18 +272,17 @@ _char_type_* _fn_name_ (const _char_type_* str, hio_oow_t* len, int flags) else { /* the entire string need to be deleted */ - if ((flags & $4_RIGHT) || - (flags & $4_LEFT)) *len = 0; + if ((flags & _prefix_()_RIGHT) || + (flags & _prefix_()_LEFT)) *len = 0; } } return (_char_type_*)str; } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_is_space_]])popdef([[_prefix_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -dnl $3 is_space $4: copy_str_unlimited -define([[fn_split_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) +define([[fn_split_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_is_space_]], $3)pushdef([[_copy_str_unlimited_]], $4)dnl int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _char_type_ rquote, _char_type_ escape) { _char_type_* p = s, *d; @@ -298,19 +295,19 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch { delim_mode = 1; for (d = (_char_type_*)delim; *d != '\0'; d++) - if (!$3(*d)) delim_mode = 2; + if (!_is_space_()(*d)) delim_mode = 2; } if (delim_mode == 0) { /* skip preceding space characters */ - while ($3(*p)) p++; + while (_is_space_()(*p)) p++; /* when 0 is given as "delim", it has an effect of cutting preceding and trailing space characters off "s". */ if (lquote != '\0' && *p == lquote) { - $4 (p, p + 1); + _copy_str_unlimited_ (p, p + 1); for (;;) { @@ -318,7 +315,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch if (escape != '\0' && *p == escape) { - $4 (p, p + 1); + _copy_str_unlimited_ (p, p + 1); } else { @@ -333,14 +330,14 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch ep = p; p++; } - while ($3(*p)) p++; + while (_is_space_()(*p)) p++; if (*p != '\0') return -1; if (sp == 0 && ep == 0) s[0] = '\0'; else { ep[1] = '\0'; - if (s != (_char_type_*)sp) $4 (s, sp); + if (s != (_char_type_*)sp) _copy_str_unlimited_ (s, sp); cnt++; } } @@ -348,7 +345,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch { while (*p) { - if (!$3(*p)) + if (!_is_space_()(*p)) { if (sp == 0) sp = p; ep = p; @@ -360,7 +357,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch else { ep[1] = '\0'; - if (s != (_char_type_*)sp) $4 (s, sp); + if (s != (_char_type_*)sp) _copy_str_unlimited_ (s, sp); cnt++; } } @@ -372,12 +369,12 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch while (*p) { o = p; - while ($3(*p)) p++; - if (o != p) { $4 (o, p); p = o; } + while (_is_space_()(*p)) p++; + if (o != p) { _copy_str_unlimited_ (o, p); p = o; } if (lquote != '\0' && *p == lquote) { - $4 (p, p + 1); + _copy_str_unlimited_ (p, p + 1); for (;;) { @@ -385,7 +382,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch if (escape != '\0' && *p == escape) { - $4 (p, p + 1); + _copy_str_unlimited_ (p, p + 1); } else { @@ -409,7 +406,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch if (o != p) cnt++; break; } - if ($3(*p)) + if (_is_space_()(*p)) { *p++ = '\0'; cnt++; @@ -428,12 +425,12 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch while (*p != '\0') { o = p; - while ($3(*p)) p++; - if (o != p) { $4 (o, p); p = o; } + while (_is_space_()(*p)) p++; + if (o != p) { _copy_str_unlimited_ (o, p); p = o; } if (lquote != '\0' && *p == lquote) { - $4 (p, p + 1); + _copy_str_unlimited_ (p, p + 1); for (;;) { @@ -441,7 +438,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch if (escape != '\0' && *p == escape) { - $4 (p, p + 1); + _copy_str_unlimited_ (p, p + 1); } else { @@ -456,14 +453,14 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch } ok = 0; - while ($3(*p)) p++; + while (_is_space_()(*p)) p++; if (*p == '\0') ok = 1; for (d = (_char_type_*)delim; *d != '\0'; d++) { if (*p == *d) { ok = 1; - $4 (p, p + 1); + _copy_str_unlimited_ (p, p + 1); break; } } @@ -491,13 +488,13 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch { if (sp == HIO_NULL) { - $4 (o, p); p = o; + _copy_str_unlimited_ (o, p); p = o; *p++ = '\0'; } else { - $4 (&ep[1], p); - $4 (o, sp); + _copy_str_unlimited_ (&ep[1], p); + _copy_str_unlimited_ (o, sp); o[ep - sp + 1] = '\0'; p = &o[ep - sp + 2]; } @@ -508,7 +505,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch } } - if (!$3(*p)) + if (!_is_space_()(*p)) { if (sp == HIO_NULL) sp = p; ep = p; @@ -523,10 +520,10 @@ exit_point: return cnt; } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_is_space_]])popdef([[_copy_str_unlimited_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -define([[fn_chars_to_int]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[_int_type_]], $3) +define([[fn_chars_to_int]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_int_type_]], $3)pushdef([[_is_space_]], $4)pushdef([[_prefix_]], $5)dnl _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _char_type_** endptr, int* is_sober) { _int_type_ n = 0; @@ -534,15 +531,15 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _ const _char_type_* end; hio_oow_t rem; int digit, negative = 0; - int base = $5_GET_OPTION_BASE(option); + int base = _prefix_()_GET_OPTION_BASE(option); p = str; end = str + len; - if ($5_GET_OPTION_LTRIM(option)) + if (_prefix_()_GET_OPTION_LTRIM(option)) { /* strip off leading spaces */ - while (p < end && $4(*p)) p++; + while (p < end && _is_space_()(*p)) p++; } /* check for a sign */ @@ -599,7 +596,7 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _ p++; } - if ($5_GET_OPTION_E(option)) + if (_prefix_()_GET_OPTION_E(option)) { if (*p == 'E' || *p == 'e') { @@ -632,20 +629,19 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _ * other case: p > pp to be able to have at least 1 meaningful digit. */ if (is_sober) *is_sober = (base == 8 || p > pp); - if ($5_GET_OPTION_RTRIM(option)) + if (_prefix_()_GET_OPTION_RTRIM(option)) { /* consume trailing spaces */ - while (p < end && $4(*p)) p++; + while (p < end && _is_space_()(*p)) p++; } if (endptr) *endptr = p; return (negative)? -n: n; } -]]) - +popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_int_type_]])popdef([[_is_space_]])popdef([[_prefix_]])dnl +]])dnl dnl --------------------------------------------------------------------------- -dnl $4: is_space $5: prefix for some macros -define([[fn_chars_to_uint]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[_int_type_]], $3) +define([[fn_chars_to_uint]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_int_type_]], $3)pushdef([[_is_space_]], $4)pushdef([[_prefix_]], $5)dnl _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _char_type_** endptr, int* is_sober) { _int_type_ n = 0; @@ -653,15 +649,15 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _ const _char_type_* end; hio_oow_t rem; int digit; - int base = $5_GET_OPTION_BASE(option); + int base = _prefix_()_GET_OPTION_BASE(option); p = str; end = str + len; - if ($5_GET_OPTION_LTRIM(option)) + if (_prefix_()_GET_OPTION_LTRIM(option)) { /* strip off leading spaces */ - while (p < end && $4(*p)) p++; + while (p < end && _is_space_()(*p)) p++; } /* check for a sign */ @@ -713,7 +709,7 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _ p++; } - if ($5_GET_OPTION_E(option)) + if (_prefix_()_GET_OPTION_E(option)) { if (*p == 'E' || *p == 'e') { @@ -746,13 +742,14 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _ * other case: p > pp to be able to have at least 1 meaningful digit. */ if (is_sober) *is_sober = (base == 8 || p > pp); - if ($5_GET_OPTION_RTRIM(option)) + if (_prefix_()_GET_OPTION_RTRIM(option)) { /* consume trailing spaces */ - while (p < end && $4(*p)) p++; + while (p < end && _is_space_()(*p)) p++; } if (endptr) *endptr = p; return n; } +popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_int_type_]])popdef([[_is_space_]])popdef([[_prefix_]])dnl ]])