added hcl_get_base_name_from_path()

merged hclx server and client into a single command
This commit is contained in:
2024-04-27 21:16:00 +09:00
parent e14b8e1e04
commit 8dc884aa7e
12 changed files with 328 additions and 170 deletions

View File

@ -898,6 +898,12 @@ typedef struct hcl_t hcl_t;
# undef HCL_HAVE_INLINE
#endif
#if __has_attribute(__sentinel__) || (defined(__GNUC__) && (__GNUC__ >= 4))
# define HCL_SENTINEL(v) __attribute__((__sentinel__(x)))
#else
# define HCL_SENTINEL(v)
#endif
#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4))
# define HCL_UNUSED __attribute__((__unused__))
#else
@ -962,22 +968,24 @@ typedef struct hcl_t hcl_t;
/* =========================================================================
* COMPILER FEATURE TEST MACROS
* =========================================================================*/
#if !defined(__has_attribute)
#define __has_attribute(x) 0
#endif
#if !defined(__has_builtin) && defined(_INTELC32_)
/* intel c code builder 1.0 ended up with an error without this override */
#define __has_builtin(x) 0
#endif
/*
#if !defined(__has_feature)
#define __has_feature(x) 0
#endif
#if !defined(__is_identifier)
#define __is_identifier(x) 0
#endif
#if !defined(__has_attribute)
#define __has_attribute(x) 0
#endif
*/
#if defined(__has_builtin)
#if __has_builtin(__builtin_ctz)
#define HCL_HAVE_BUILTIN_CTZ

View File

@ -943,6 +943,24 @@ HCL_EXPORT void hcl_sub_ntime (
const hcl_ntime_t* y
);
/* =========================================================================
* PATH NAME
* ========================================================================= */
const hcl_bch_t* hcl_get_base_name_from_bcstr_path (
const hcl_bch_t* path
);
const hcl_uch_t* hcl_get_base_name_from_ucstr_path (
const hcl_uch_t* path
);
#if defined(HCL_OOCH_IS_UCH)
#define hcl_get_base_name_from_path(x) hcl_get_base_name_from_ucstr_path(x)
#else
#define hcl_get_base_name_from_path(x) hcl_get_base_name_from_bcstr_path(x)
#endif
/* =========================================================================
* BIT SWAP
* ========================================================================= */

View File

@ -323,6 +323,10 @@ HCL_EXPORT int hcl_client_start (
int shut_wr_after_req
);
HCL_EXPORT void hcl_client_stop (
hcl_client_t* client
);
HCL_EXPORT int hcl_client_setoption (
hcl_client_t* client,
hcl_client_option_t id,

View File

@ -3291,18 +3291,6 @@ struct bb_t
hcl_bch_t* fn;
};
static const hcl_bch_t* get_base_name (const hcl_bch_t* path)
{
const hcl_bch_t* p, * last = HCL_NULL;
for (p = path; *p != '\0'; p++)
{
if (HCL_IS_PATH_SEP(*p)) last = p;
}
return (last == HCL_NULL)? path: (last + 1);
}
#if defined(__DOS__) || defined(_WIN32) || defined(__OS2__)
#define FOPEN_R_FLAGS "rb"
#else
@ -3329,7 +3317,7 @@ static HCL_INLINE int open_cci_stream (hcl_t* hcl, hcl_io_cciarg_t* arg)
fn = ((bb_t*)arg->includer->handle)->fn;
fb = get_base_name(fn);
fb = hcl_get_base_name_from_bcstr_path(fn);
parlen = fb - fn;
bb = (bb_t*)hcl_callocmem(hcl, HCL_SIZEOF(*bb) + (HCL_SIZEOF(hcl_bch_t) * (parlen + bcslen + 1)));

View File

@ -1330,3 +1330,28 @@ void hcl_sub_ntime (hcl_ntime_t* z, const hcl_ntime_t* x, const hcl_ntime_t* y)
z->nsec = ns;
}
/* ----------------------------------------------------------------------- */
const hcl_bch_t* hcl_get_base_name_from_bcstr_path (const hcl_bch_t* path)
{
const hcl_bch_t* p, * last = HCL_NULL;
for (p = path; *p != '\0'; p++)
{
if (HCL_IS_PATH_SEP(*p)) last = p;
}
return (last == HCL_NULL)? path: (last + 1);
}
const hcl_uch_t* hcl_get_base_name_from_ucstr_path (const hcl_uch_t* path)
{
const hcl_uch_t* p, * last = HCL_NULL;
for (p = path; *p != '\0'; p++)
{
if (HCL_IS_PATH_SEP(*p)) last = p;
}
return (last == HCL_NULL)? path: (last + 1);
}

View File

@ -636,3 +636,8 @@ oops:
return -1;
}
void hcl_client_stop (hcl_client_t* client)
{
/* TODO: */
/* TODO: break the cleint loop */
}

View File

@ -254,18 +254,6 @@ static int send_stdout_chars (hcl_xproto_t* proto, int xpkt_code, const hcl_ooch
/* ========================================================================= */
static const hcl_bch_t* get_base_name (const hcl_bch_t* path)
{
const hcl_bch_t* p, * last = HCL_NULL;
for (p = path; *p != '\0'; p++)
{
if (HCL_IS_PATH_SEP(*p)) last = p;
}
return (last == HCL_NULL)? path: (last + 1);
}
static HCL_INLINE int open_read_stream (hcl_t* hcl, hcl_io_cciarg_t* arg)
{
worker_hcl_xtn_t* xtn = (worker_hcl_xtn_t*)hcl_getxtn(hcl);
@ -299,7 +287,7 @@ static HCL_INLINE int open_read_stream (hcl_t* hcl, hcl_io_cciarg_t* arg)
}
else
{
fb = get_base_name(fn);
fb = hcl_get_base_name_from_bcstr_path(fn);
parlen = fb - fn;
}