added sys::dirname() and sys::basename()
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-12-22 02:05:09 +09:00
parent 488839f761
commit 33ba979512
8 changed files with 185 additions and 102 deletions

View File

@@ -1,7 +1,8 @@
AUTOMAKE_OPTION = foreign AUTOMAKE_OPTION = foreign
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = EXTRA_DIST = go.mod
SUBDIRS = SUBDIRS =
SUBDIRS += tools lib mod bin samples t SUBDIRS += tools lib mod bin samples t

View File

@@ -374,7 +374,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
AUTOMAKE_OPTION = foreign AUTOMAKE_OPTION = foreign
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = EXTRA_DIST = go.mod
SUBDIRS = tools lib mod bin samples t SUBDIRS = tools lib mod bin samples t
#if ENABLE_STATIC_MODULE #if ENABLE_STATIC_MODULE
#SUBDIRS += tools mod lib bin samples t #SUBDIRS += tools mod lib bin samples t

View File

@@ -162,9 +162,6 @@ static int bpath_exists (hawk_gem_t* g, const hawk_bch_t* name, hawk_becs_t* mbu
#endif #endif
} }
#if defined(NO_RECURSION) #if defined(NO_RECURSION)
typedef struct __u_stack_node_t __u_stack_node_t; typedef struct __u_stack_node_t __u_stack_node_t;
#endif #endif
@@ -802,7 +799,6 @@ static int __b_handle_non_wild_segments (__b_glob_t* g, __b_segment_t* seg)
/* if the segment contains escape sequences, /* if the segment contains escape sequences,
* strip the escape letters off the segment */ * strip the escape letters off the segment */
hawk_bcs_t tmp; hawk_bcs_t tmp;
hawk_oow_t i; hawk_oow_t i;
int escaped = 0; int escaped = 0;

View File

@@ -778,10 +778,23 @@ HAWK_EXPORT const hawk_bch_t* hawk_get_base_name_bcstr (
const hawk_bch_t* path const hawk_bch_t* path
); );
HAWK_EXPORT const hawk_uch_t* hawk_get_base_name_uchars (
const hawk_uch_t* path,
hawk_oow_t len
);
HAWK_EXPORT const hawk_bch_t* hawk_get_base_name_bchars (
const hawk_bch_t* path,
hawk_oow_t len
);
#if defined(HAWK_OOCH_IS_UCH) #if defined(HAWK_OOCH_IS_UCH)
# define hawk_get_base_name_oocstr hawk_get_base_name_ucstr # define hawk_get_base_name_oocstr hawk_get_base_name_ucstr
# define hawk_get_base_name_oochars hawk_get_base_name_uchars
#else #else
# define hawk_get_base_name_oocstr hawk_get_base_name_bcstr # define hawk_get_base_name_oocstr hawk_get_base_name_bcstr
# define hawk_get_base_name_ochars hawk_get_base_name_bchars
#endif #endif
/* ========================================================================= /* =========================================================================

View File

@@ -4618,7 +4618,7 @@ static int fnc_openlog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
log_type = SYSLOG_REMOTE; log_type = SYSLOG_REMOTE;
actual_ident = ident + pfxlen; actual_ident = ident + pfxlen;
actual_ident_len = ident_len - pfxlen; actual_ident_len = ident_len - pfxlen;
slash = hawk_rfind_oochar_in_oochars(actual_ident, actual_ident_len, '/'); // fine the last slash slash = hawk_rfind_oochar_in_oochars(actual_ident, actual_ident_len, '/'); // find the last slash
if (!slash) if (!slash)
{ {
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_T("invalid identifier '%js' with remote address"), ident); rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_T("invalid identifier '%js' with remote address"), ident);
@@ -5867,6 +5867,52 @@ fail:
goto done; goto done;
} }
/* ----------------------------------------------------------------------- */
static int fnc_basename (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{
hawk_val_t* a0, * tmp;
hawk_oocs_t path;
const hawk_ooch_t* ptr;
a0 = hawk_rtx_getarg(rtx, 0);
path.ptr = hawk_rtx_getvaloocstr(rtx, a0, &path.len);
if (HAWK_UNLIKELY(!path.ptr)) return -1;
ptr = hawk_get_base_name_oochars(path.ptr, path.len);
tmp = hawk_rtx_makestrvalwithoocstr(rtx, ptr);
hawk_rtx_freevaloocstr(rtx, a0, path.ptr);
if (HAWK_UNLIKELY(!tmp)) return -1;
hawk_rtx_setretval(rtx, tmp);
return 0;
}
static int fnc_dirname (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{
hawk_val_t* a0, * tmp;
hawk_oocs_t path;
const hawk_ooch_t* ptr;
hawk_oow_t len;
a0 = hawk_rtx_getarg(rtx, 0);
path.ptr = hawk_rtx_getvaloocstr(rtx, a0, &path.len);
if (HAWK_UNLIKELY(!path.ptr)) return -1;
ptr = hawk_get_base_name_oochars(path.ptr, path.len);
len = ptr - path.ptr;
if (len > 1) len--;
tmp = hawk_rtx_makestrvalwithoochars(rtx, path.ptr, len);
hawk_rtx_freevaloocstr(rtx, a0, path.ptr);
if (HAWK_UNLIKELY(!tmp)) return -1;
hawk_rtx_setretval(rtx, tmp);
return 0;
}
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
#define A_MAX HAWK_TYPE_MAX(hawk_oow_t) #define A_MAX HAWK_TYPE_MAX(hawk_oow_t)
@@ -5884,6 +5930,7 @@ static hawk_mod_fnc_tab_t fnctab[] =
{ HAWK_T("WTERMSIG"), { { 1, 1, HAWK_NULL }, fnc_wtermsig, 0 } }, { HAWK_T("WTERMSIG"), { { 1, 1, HAWK_NULL }, fnc_wtermsig, 0 } },
{ HAWK_T("accept"), { { 1, 3, HAWK_T("vvr") }, fnc_accept, 0 } }, { HAWK_T("accept"), { { 1, 3, HAWK_T("vvr") }, fnc_accept, 0 } },
{ HAWK_T("addtomux"), { { 3, 3, HAWK_NULL }, fnc_addtomux, 0 } }, { HAWK_T("addtomux"), { { 3, 3, HAWK_NULL }, fnc_addtomux, 0 } },
{ HAWK_T("basename"), { { 1, 1, HAWK_NULL }, fnc_basename, 0 } },
{ HAWK_T("bind"), { { 2, 2, HAWK_NULL }, fnc_bind, 0 } }, { HAWK_T("bind"), { { 2, 2, HAWK_NULL }, fnc_bind, 0 } },
{ HAWK_T("chmod"), { { 2, 2, HAWK_NULL }, fnc_chmod, 0 } }, { HAWK_T("chmod"), { { 2, 2, HAWK_NULL }, fnc_chmod, 0 } },
{ HAWK_T("chroot"), { { 1, 1, HAWK_NULL }, fnc_chroot, 0 } }, { HAWK_T("chroot"), { { 1, 1, HAWK_NULL }, fnc_chroot, 0 } },
@@ -5893,6 +5940,7 @@ static hawk_mod_fnc_tab_t fnctab[] =
{ HAWK_T("closemux"), { { 1, 1, HAWK_NULL }, fnc_closemux, 0 } }, { HAWK_T("closemux"), { { 1, 1, HAWK_NULL }, fnc_closemux, 0 } },
{ HAWK_T("connect"), { { 2, 2, HAWK_NULL }, fnc_connect, 0 } }, { HAWK_T("connect"), { { 2, 2, HAWK_NULL }, fnc_connect, 0 } },
{ HAWK_T("delfrommux"), { { 2, 2, HAWK_NULL }, fnc_delfrommux, 0 } }, { HAWK_T("delfrommux"), { { 2, 2, HAWK_NULL }, fnc_delfrommux, 0 } },
{ HAWK_T("dirname"), { { 1, 1, HAWK_NULL }, fnc_dirname, 0 } },
{ HAWK_T("dup"), { { 1, 3, HAWK_NULL }, fnc_dup, 0 } }, { HAWK_T("dup"), { { 1, 3, HAWK_NULL }, fnc_dup, 0 } },
{ HAWK_T("errmsg"), { { 0, 0, HAWK_NULL }, fnc_errmsg, 0 } }, { HAWK_T("errmsg"), { { 0, 0, HAWK_NULL }, fnc_errmsg, 0 } },
{ HAWK_T("fchmod"), { { 2, 2, HAWK_NULL }, fnc_fchmod, 0 } }, { HAWK_T("fchmod"), { { 2, 2, HAWK_NULL }, fnc_fchmod, 0 } },

View File

@@ -539,3 +539,28 @@ const hawk_bch_t* hawk_get_base_name_bcstr (const hawk_bch_t* path)
return last? (last + 1): path; return last? (last + 1): path;
} }
const hawk_uch_t* hawk_get_base_name_uchars (const hawk_uch_t* path, hawk_oow_t len)
{
const hawk_uch_t* p, * last = HAWK_NULL;
const hawk_uch_t* end = path + len;
for (p = path; p < end; p++)
{
if (IS_PATH_SEP(*p)) last = p;
}
return last? (last + 1): path;
}
const hawk_bch_t* hawk_get_base_name_bchars (const hawk_bch_t* path, hawk_oow_t len)
{
const hawk_bch_t* p, * last = HAWK_NULL;
const hawk_bch_t* end = path + len;
for (p = path; p < end; p++)
{
if (IS_PATH_SEP(*p)) last = p;
}
return last? (last + 1): path;
}