renamed qse_awk_getwerrmsg() to qse_awk_geterrmsgaswcs.

renamed qse_awk_getmerrmsg() to qse_awk_geterrmsgasmbs()
This commit is contained in:
hyung-hwan 2019-08-28 15:14:22 +00:00
parent 510bde2abc
commit 24bcca71bf
13 changed files with 284 additions and 68 deletions

View File

@ -1126,11 +1126,11 @@ static void open_mpi (mpi_t* mpi, int argc, qse_achar_t* argv[])
#if defined(USE_LTDL) #if defined(USE_LTDL)
#if defined(QSE_ACHAR_IS_MCHAR) #if defined(QSE_ACHAR_IS_MCHAR)
if (qse_mbscmp (qse_mbsbasename(argv[0]), QSE_MT("qseawkmp")) != 0 && if (qse_mbscmp (qse_basenameasmbs(argv[0]), QSE_MT("qseawkmp")) != 0 &&
qse_mbscmp (qse_mbsbasename(argv[0]), QSE_MT("qseawkmpi")) != 0) return; qse_mbscmp (qse_basenameasmbs(argv[0]), QSE_MT("qseawkmpi")) != 0) return;
#else #else
if (qse_wcscmp (qse_wcsbasename(argv[0]), QSE_WT("qseawkmp")) != 0 && if (qse_wcscmp (qse_basenameaswcs(argv[0]), QSE_WT("qseawkmp")) != 0 &&
qse_wcscmp (qse_wcsbasename(argv[0]), QSE_WT("qseawkmpi")) != 0) return; qse_wcscmp (qse_basenameaswcs(argv[0]), QSE_WT("qseawkmpi")) != 0) return;
#endif #endif
if (lt_dlinit () != 0) return; if (lt_dlinit () != 0) return;

View File

@ -879,7 +879,7 @@ found:
if (apath) if (apath)
{ {
const qse_mchar_t* base; const qse_mchar_t* base;
base = qse_mbsbasename (apath); base = qse_basenameasmbs (apath);
for (i = 0; i < QSE_COUNTOF(loccfg->auth_rule); i++) for (i = 0; i < QSE_COUNTOF(loccfg->auth_rule); i++)
{ {
@ -977,7 +977,7 @@ found:
#endif #endif
if (!qinfo->xpath_nx) if (!qinfo->xpath_nx)
{ {
xpath_base = qse_mbsbasename (qinfo->xpath); xpath_base = qse_basenameasmbs (qinfo->xpath);
for (i = 0; i < QSE_COUNTOF(loccfg->cgi); i++) for (i = 0; i < QSE_COUNTOF(loccfg->cgi); i++)
{ {
struct cgi_t* cgi; struct cgi_t* cgi;
@ -1004,7 +1004,7 @@ found:
qse_size_t i; qse_size_t i;
const qse_mchar_t* xpath_base; const qse_mchar_t* xpath_base;
xpath_base = qse_mbsbasename (qinfo->xpath); xpath_base = qse_basenameasmbs (qinfo->xpath);
*(const qse_mchar_t**)result = QSE_NULL; *(const qse_mchar_t**)result = QSE_NULL;
for (i = 0; i < QSE_COUNTOF(loccfg->mime); i++) for (i = 0; i < QSE_COUNTOF(loccfg->mime); i++)
@ -1043,7 +1043,7 @@ found:
id = (code == QSE_HTTPD_SERVERSTD_DIRACC)? 0: 1; id = (code == QSE_HTTPD_SERVERSTD_DIRACC)? 0: 1;
xpath_base = qse_mbsbasename (qinfo->xpath); xpath_base = qse_basenameasmbs (qinfo->xpath);
*(int*)result = 200; *(int*)result = 200;
for (i = 0; i < QSE_COUNTOF(loccfg->access[id]); i++) for (i = 0; i < QSE_COUNTOF(loccfg->access[id]); i++)

View File

@ -1707,30 +1707,30 @@ QSE_EXPORT const qse_awk_loc_t* qse_awk_geterrloc (
); );
/** /**
* The qse_awk_getmerrmsg() function returns the error message describing * The qse_awk_geterrmsgasmbs() function returns the error message describing
* the last error occurred. * the last error occurred.
* *
* \return error message * \return error message
*/ */
QSE_EXPORT const qse_mchar_t* qse_awk_getmerrmsg ( QSE_EXPORT const qse_mchar_t* qse_awk_geterrmsgasmbs (
qse_awk_t* awk /**< awk */ qse_awk_t* awk /**< awk */
); );
/** /**
* The qse_awk_getwerrmsg() function returns the error message describing * The qse_awk_geterrmsgaswcs() function returns the error message describing
* the last error occurred. * the last error occurred.
* *
* \return error message * \return error message
*/ */
QSE_EXPORT const qse_wchar_t* qse_awk_getwerrmsg ( QSE_EXPORT const qse_wchar_t* qse_awk_geterrmsgaswcs (
qse_awk_t* awk /**< awk */ qse_awk_t* awk /**< awk */
); );
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
# define qse_awk_geterrmsg qse_awk_getmerrmsg # define qse_awk_geterrmsg qse_awk_geterrmsgasmbs
#else #else
# define qse_awk_geterrmsg qse_awk_getwerrmsg # define qse_awk_geterrmsg qse_awk_geterrmsgaswcs
#endif #endif
@ -2231,15 +2231,31 @@ QSE_EXPORT qse_awk_val_t* qse_awk_rtx_loop (
); );
/** /**
* The qse_awk_rtx_findfun() function finds the function structure by name * The qse_awk_rtx_findfunwithmbs() function finds the function structure by
* and returns the pointer to it if one is found. It returns #QSE_NULL if * name and returns the pointer to it if one is found. It returns #QSE_NULL
* it fails to find a function by the \a name. * if it fails to find a function by the \a name.
*/ */
QSE_EXPORT qse_awk_fun_t* qse_awk_rtx_findfun ( QSE_EXPORT qse_awk_fun_t* qse_awk_rtx_findfunwithmbs (
qse_awk_rtx_t* rtx, /**< runtime context */ qse_awk_rtx_t* rtx, /**< runtime context */
const qse_char_t* name /**< function name */ const qse_mchar_t* name /**< function name */
); );
/**
* The qse_awk_rtx_findfunwithwcs() function finds the function structure by
* name and returns the pointer to it if one is found. It returns #QSE_NULL
* if it fails to find a function by the \a name.
*/
QSE_EXPORT qse_awk_fun_t* qse_awk_rtx_findfunwithwcs (
qse_awk_rtx_t* rtx, /**< runtime context */
const qse_wchar_t* name /**< function name */
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_awk_rtx_findfun qse_awk_rtx_findfunwithmbs
#else
# define qse_awk_rtx_findfun qse_awk_rtx_findfunwithwcs
#endif
/** /**
* The qse_awk_rtx_callfun() function invokes an AWK function described by * The qse_awk_rtx_callfun() function invokes an AWK function described by
* the structure pointed to by \a fun. * the structure pointed to by \a fun.
@ -2253,7 +2269,7 @@ QSE_EXPORT qse_awk_val_t* qse_awk_rtx_callfun (
); );
/** /**
* The qse_awk_rtx_call() function invokes an AWK function named \a name. * The qse_awk_rtx_callwithmbs() function invokes an AWK function named \a name.
* However, it is not able to invoke an intrinsic function such as split(). * However, it is not able to invoke an intrinsic function such as split().
* The #QSE_AWK_PABLOCK option can be turned off to make illegal the BEGIN * The #QSE_AWK_PABLOCK option can be turned off to make illegal the BEGIN
* blocks, the pattern-action blocks, and the END blocks. * blocks, the pattern-action blocks, and the END blocks.
@ -2263,9 +2279,9 @@ QSE_EXPORT qse_awk_val_t* qse_awk_rtx_callfun (
* rtx = qse_awk_rtx_open (awk, 0, rio); * rtx = qse_awk_rtx_open (awk, 0, rio);
* if (rtx) * if (rtx)
* { * {
* v = qse_awk_rtx_call (rtx, QSE_T("init"), QSE_NULL, 0); * v = qse_awk_rtx_callwithmbs (rtx, QSE_MT("init"), QSE_NULL, 0);
* if (v) qse_awk_rtx_refdownval (rtx, v); * if (v) qse_awk_rtx_refdownval (rtx, v);
* qse_awk_rtx_call (rtx, QSE_T("fini"), QSE_NULL, 0); * qse_awk_rtx_callwithmbs (rtx, QSE_MT("fini"), QSE_NULL, 0);
* if (v) qse_awk_rtx_refdownval (rtx, v); * if (v) qse_awk_rtx_refdownval (rtx, v);
* qse_awk_rtx_close (rtx); * qse_awk_rtx_close (rtx);
* } * }
@ -2273,13 +2289,47 @@ QSE_EXPORT qse_awk_val_t* qse_awk_rtx_callfun (
* *
* \return 0 on success, -1 on failure * \return 0 on success, -1 on failure
*/ */
QSE_EXPORT qse_awk_val_t* qse_awk_rtx_call ( QSE_EXPORT qse_awk_val_t* qse_awk_rtx_callwithmbs (
qse_awk_rtx_t* rtx, /**< runtime context */ qse_awk_rtx_t* rtx, /**< runtime context */
const qse_char_t* name, /**< function name */ const qse_mchar_t* name, /**< function name */
qse_awk_val_t* args[], /**< arguments to the function */ qse_awk_val_t* args[], /**< arguments to the function */
qse_size_t nargs /**< the number of arguments */ qse_size_t nargs /**< the number of arguments */
); );
/**
* The qse_awk_rtx_callwithwcs() function invokes an AWK function named \a name.
* However, it is not able to invoke an intrinsic function such as split().
* The #QSE_AWK_PABLOCK option can be turned off to make illegal the BEGIN
* blocks, the pattern-action blocks, and the END blocks.
*
* The example shows typical usage of the function.
* \code
* rtx = qse_awk_rtx_open (awk, 0, rio);
* if (rtx)
* {
* v = qse_awk_rtx_callwithwcs (rtx, QSE_WT("init"), QSE_NULL, 0);
* if (v) qse_awk_rtx_refdownval (rtx, v);
* qse_awk_rtx_callwithwcs (rtx, QSE_WT("fini"), QSE_NULL, 0);
* if (v) qse_awk_rtx_refdownval (rtx, v);
* qse_awk_rtx_close (rtx);
* }
* \endcode
*
* \return 0 on success, -1 on failure
*/
QSE_EXPORT qse_awk_val_t* qse_awk_rtx_callwithwcs (
qse_awk_rtx_t* rtx, /**< runtime context */
const qse_wchar_t* name, /**< function name */
qse_awk_val_t* args[], /**< arguments to the function */
qse_size_t nargs /**< the number of arguments */
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_awk_rtx_call qse_awk_rtx_callwithmbs
#else
# define qse_awk_rtx_call qse_awk_rtx_callwithwcs
#endif
/** /**
* The qse_awk_rtx_callwithstrs() function is the same as qse_awk_rtx_call() * The qse_awk_rtx_callwithstrs() function is the same as qse_awk_rtx_call()
* except that you pass pointers to null-terminated strings. It creates values * except that you pass pointers to null-terminated strings. It creates values
@ -2501,27 +2551,27 @@ QSE_EXPORT const qse_awk_loc_t* qse_awk_rtx_geterrloc (
); );
/** /**
* The qse_awk_rtx_getmerrmsg() function gets the string describing the last * The qse_awk_rtx_geterrmsgasmbs() function gets the string describing the last
* error occurred during runtime. * error occurred during runtime.
* \return error message * \return error message
*/ */
QSE_EXPORT const qse_mchar_t* qse_awk_rtx_getmerrmsg ( QSE_EXPORT const qse_mchar_t* qse_awk_rtx_geterrmsgasmbs (
qse_awk_rtx_t* rtx /**< runtime context */ qse_awk_rtx_t* rtx /**< runtime context */
); );
/** /**
* The qse_awk_rtx_getwerrmsg() function gets the string describing the last * The qse_awk_rtx_geterrmsgaswcs() function gets the string describing the last
* error occurred during runtime. * error occurred during runtime.
* \return error message * \return error message
*/ */
QSE_EXPORT const qse_wchar_t* qse_awk_rtx_getwerrmsg ( QSE_EXPORT const qse_wchar_t* qse_awk_rtx_geterrmsgaswcs (
qse_awk_rtx_t* rtx /**< runtime context */ qse_awk_rtx_t* rtx /**< runtime context */
); );
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
# define qse_awk_rtx_geterrmsg qse_awk_rtx_getmerrmsg # define qse_awk_rtx_geterrmsg qse_awk_rtx_geterrmsgasmbs
#else #else
# define qse_awk_rtx_geterrmsg qse_awk_rtx_getwerrmsg # define qse_awk_rtx_geterrmsg qse_awk_rtx_geterrmsgaswcs
#endif #endif
QSE_EXPORT const qse_char_t* qse_awk_rtx_backuperrmsg ( QSE_EXPORT const qse_char_t* qse_awk_rtx_backuperrmsg (
@ -3262,6 +3312,34 @@ static QSE_INLINE void qse_awk_rtx_freemem (qse_awk_rtx_t* rtx, void* ptr)
# define qse_awk_rtx_freemem(rtx,ptr) qse_awk_freemem(((qse_awk_rtx_alt_t*)rtx)->awk, ptr) # define qse_awk_rtx_freemem(rtx,ptr) qse_awk_freemem(((qse_awk_rtx_alt_t*)rtx)->awk, ptr)
#endif #endif
QSE_EXPORT qse_wchar_t* qse_awk_rtx_mbstowcsdup (
qse_awk_rtx_t* rtx,
const qse_mchar_t* mbs,
qse_size_t* wcslen
);
QSE_EXPORT qse_wchar_t* qse_awk_rtx_mbsntowcsdup (
qse_awk_rtx_t* rtx,
const qse_mchar_t* mbs,
qse_size_t mbslen,
qse_size_t* wcslen
);
QSE_EXPORT qse_mchar_t* qse_awk_rtx_wcstombsdup (
qse_awk_rtx_t* rtx,
const qse_wchar_t* wcs,
qse_size_t* mbslen
);
qse_mchar_t* qse_awk_rtx_wcsntombsdup (
qse_awk_rtx_t* rtx,
const qse_wchar_t* wcs,
qse_size_t wcslen,
qse_size_t* mbslen
);
/** /**
* The qse_getawknilval() function returns the pointer to the predefined * The qse_getawknilval() function returns the pointer to the predefined
* nil value. you can call this without creating a runtime context. * nil value. you can call this without creating a runtime context.

View File

@ -129,10 +129,10 @@ QSE_EXPORT int qse_ismbsdrivecurpath (
); );
/** /**
* The qse_mbsbasename() function returns the pointer to the file name * The qse_basenameasmbs() function returns the pointer to the file name
* segment in a multibyte path name. * segment in a multibyte path name.
*/ */
QSE_EXPORT const qse_mchar_t* qse_mbsbasename ( QSE_EXPORT const qse_mchar_t* qse_basenameasmbs (
const qse_mchar_t* path const qse_mchar_t* path
); );
@ -237,10 +237,10 @@ QSE_EXPORT int qse_iswcsdrivecurpath (
); );
/** /**
* The qse_wcsbasename() function returns the pointer to the file name * The qse_basenameaswcs() function returns the pointer to the file name
* segment in a wide-character path name. * segment in a wide-character path name.
*/ */
QSE_EXPORT const qse_wchar_t* qse_wcsbasename ( QSE_EXPORT const qse_wchar_t* qse_basenameaswcs (
const qse_wchar_t* path const qse_wchar_t* path
); );
@ -313,7 +313,7 @@ QSE_EXPORT qse_wchar_t* qse_mergewcspathdup (
# define qse_isdrivepath(p) qse_ismbsdrivepath(p) # define qse_isdrivepath(p) qse_ismbsdrivepath(p)
# define qse_isdriveabspath(p) qse_ismbsdriveabspath(p) # define qse_isdriveabspath(p) qse_ismbsdriveabspath(p)
# define qse_isdrivecurpath(p) qse_ismbsdrivecurpath(p) # define qse_isdrivecurpath(p) qse_ismbsdrivecurpath(p)
# define qse_basename(path) qse_mbsbasename(path) # define qse_basename(path) qse_basenameasmbs(path)
# define qse_pathcore(p) qse_mbspathcore(p) # define qse_pathcore(p) qse_mbspathcore(p)
# define qse_canonpath(p,c,f) qse_canonmbspath(p,c,f) # define qse_canonpath(p,c,f) qse_canonmbspath(p,c,f)
# define qse_mergepathdup(d,f,m) qse_mergembspathdup(d,f,m) # define qse_mergepathdup(d,f,m) qse_mergembspathdup(d,f,m)
@ -323,7 +323,7 @@ QSE_EXPORT qse_wchar_t* qse_mergewcspathdup (
# define qse_isdrivepath(p) qse_iswcsdrivepath(p) # define qse_isdrivepath(p) qse_iswcsdrivepath(p)
# define qse_isdriveabspath(p) qse_iswcsdriveabspath(p) # define qse_isdriveabspath(p) qse_iswcsdriveabspath(p)
# define qse_isdrivecurpath(p) qse_iswcsdrivecurpath(p) # define qse_isdrivecurpath(p) qse_iswcsdrivecurpath(p)
# define qse_basename(path) qse_wcsbasename(path) # define qse_basename(path) qse_basenameaswcs(path)
# define qse_pathcore(p) qse_wcspathcore(p) # define qse_pathcore(p) qse_wcspathcore(p)
# define qse_canonpath(p,c,f) qse_canonwcspath(p,c,f) # define qse_canonpath(p,c,f) qse_canonwcspath(p,c,f)
# define qse_mergepathdup(d,f,m) qse_mergewcspathdup(d,f,m) # define qse_mergepathdup(d,f,m) qse_mergewcspathdup(d,f,m)

View File

@ -1208,14 +1208,14 @@ int StdAwk::SourceFile::open (Data& io)
file = ioname; file = ioname;
if (io.getPrevHandle()) if (io.getPrevHandle())
{ {
const char_t* outer; const qse_char_t* outer;
outer = qse_sio_getpath ((qse_sio_t*)io.getPrevHandle()); outer = qse_sio_getpath ((qse_sio_t*)io.getPrevHandle());
if (outer) if (outer)
{ {
const qse_char_t* base; const qse_char_t* base;
base = qse_basename (outer); base = qse_basename(outer);
if (base != outer && ioname[0] != QSE_T('/')) if (base != outer && ioname[0] != QSE_T('/'))
{ {
size_t tmplen, totlen, dirlen; size_t tmplen, totlen, dirlen;
@ -1309,7 +1309,7 @@ int StdAwk::SourceString::open (Data& io)
{ {
const qse_char_t* base; const qse_char_t* base;
base = qse_basename (outer); base = qse_basename(outer);
if (base != outer && ioname[0] != QSE_T('/')) if (base != outer && ioname[0] != QSE_T('/'))
{ {
size_t tmplen, totlen, dirlen; size_t tmplen, totlen, dirlen;
@ -1318,7 +1318,7 @@ int StdAwk::SourceString::open (Data& io)
totlen = qse_strlen(ioname) + dirlen; totlen = qse_strlen(ioname) + dirlen;
if (totlen >= QSE_COUNTOF(fbuf)) if (totlen >= QSE_COUNTOF(fbuf))
{ {
dbuf = (qse_char_t*) QSE_MMGR_ALLOC ( dbuf = (qse_char_t*)QSE_MMGR_ALLOC(
((Awk*)io)->getMmgr(), ((Awk*)io)->getMmgr(),
QSE_SIZEOF(qse_char_t) * (totlen + 1) QSE_SIZEOF(qse_char_t) * (totlen + 1)
); );

View File

@ -194,7 +194,7 @@ const qse_awk_loc_t* qse_awk_geterrloc (qse_awk_t* awk)
return &awk->errinf.loc; return &awk->errinf.loc;
} }
const qse_mchar_t* qse_awk_getmerrmsg (qse_awk_t* awk) const qse_mchar_t* qse_awk_geterrmsgasmbs (qse_awk_t* awk)
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
return (awk->errinf.msg[0] == QSE_T('\0'))? return (awk->errinf.msg[0] == QSE_T('\0'))?
@ -213,7 +213,7 @@ const qse_mchar_t* qse_awk_getmerrmsg (qse_awk_t* awk)
#endif #endif
} }
const qse_wchar_t* qse_awk_getwerrmsg (qse_awk_t* awk) const qse_wchar_t* qse_awk_geterrmsgaswcs (qse_awk_t* awk)
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
const qse_char_t* msg; const qse_char_t* msg;
@ -310,7 +310,7 @@ const qse_awk_loc_t* qse_awk_rtx_geterrloc (qse_awk_rtx_t* rtx)
return &rtx->errinf.loc; return &rtx->errinf.loc;
} }
const qse_mchar_t* qse_awk_rtx_getmerrmsg (qse_awk_rtx_t* rtx) const qse_mchar_t* qse_awk_rtx_geterrmsgasmbs (qse_awk_rtx_t* rtx)
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
return (rtx->errinf.msg[0] == QSE_T('\0')) ? return (rtx->errinf.msg[0] == QSE_T('\0')) ?
@ -329,7 +329,7 @@ const qse_mchar_t* qse_awk_rtx_getmerrmsg (qse_awk_rtx_t* rtx)
#endif #endif
} }
const qse_wchar_t* qse_awk_rtx_getwerrmsg (qse_awk_rtx_t* rtx) const qse_wchar_t* qse_awk_rtx_geterrmsgaswcs (qse_awk_rtx_t* rtx)
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
const qse_char_t* msg; const qse_char_t* msg;

View File

@ -1021,3 +1021,101 @@ void* qse_awk_rtx_callocmem (qse_awk_rtx_t* rtx, qse_size_t size)
return ptr; return ptr;
} }
qse_wchar_t* qse_awk_rtx_mbstowcsdup (qse_awk_rtx_t* rtx, const qse_mchar_t* mbs, qse_size_t* _wcslen)
{
qse_size_t mbslen, wcslen;
qse_wchar_t* wcs;
/* if i use qse_mbstowcsdupwithcmgr(), i cannot pinpoint the exact failure cause.
* let's do it differently. */
if (qse_mbstowcswithcmgr(mbs, &mbslen, QSE_NULL, &wcslen, qse_awk_rtx_getcmgr(rtx)) <= -1)
{
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EINVAL, QSE_NULL);
return QSE_NULL;
}
wcslen = wcslen + 1; /* for terminating null */
wcs = qse_awk_rtx_allocmem(rtx, QSE_SIZEOF(*wcs) * wcslen);
if (!wcs) return QSE_NULL;
qse_mbstowcswithcmgr (mbs, &mbslen, wcs, &wcslen, qse_awk_rtx_getcmgr(rtx));
if (_wcslen) *_wcslen = wcslen;
return wcs;
}
qse_mchar_t* qse_awk_rtx_wcstombsdup (qse_awk_rtx_t* rtx, const qse_wchar_t* wcs, qse_size_t* _mbslen)
{
qse_size_t mbslen, wcslen;
qse_mchar_t* mbs;
if (qse_wcstombswithcmgr(wcs, &wcslen, QSE_NULL, &mbslen, qse_awk_rtx_getcmgr(rtx)) <= -1)
{
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EINVAL, QSE_NULL);
return QSE_NULL;
}
mbslen = mbslen + 1; /* for terminating null */
mbs = qse_awk_rtx_allocmem(rtx, QSE_SIZEOF(*mbs) * mbslen);
if (!mbs) return QSE_NULL;
qse_wcstombswithcmgr (wcs, &wcslen, mbs, &mbslen, qse_awk_rtx_getcmgr(rtx));
if (_mbslen) *_mbslen = mbslen;
return mbs;
}
qse_wchar_t* qse_awk_rtx_mbsntowcsdup (qse_awk_rtx_t* rtx, const qse_mchar_t* mbs, qse_size_t _mbslen, qse_size_t* _wcslen)
{
qse_size_t mbslen, wcslen;
qse_wchar_t* wcs;
/* if i use qse_mbstowcsdupwithcmgr(), i cannot pinpoint the exact failure cause.
* let's do it differently. */
mbslen = _mbslen;
if (qse_mbsntowcsnwithcmgr(mbs, &mbslen, QSE_NULL, &wcslen, qse_awk_rtx_getcmgr(rtx)) <= -1)
{
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EINVAL, QSE_NULL);
return QSE_NULL;
}
wcs = qse_awk_rtx_allocmem(rtx, QSE_SIZEOF(*wcs) * (wcslen + 1));
if (!wcs) return QSE_NULL;
mbslen= _mbslen;
qse_mbsntowcsnwithcmgr (mbs, &mbslen, wcs, &wcslen, qse_awk_rtx_getcmgr(rtx));
wcs[wcslen] = QSE_WT('\0');
if (_wcslen) *_wcslen = wcslen;
return wcs;
}
qse_mchar_t* qse_awk_rtx_wcsntombsdup (qse_awk_rtx_t* rtx, const qse_wchar_t* wcs, qse_size_t _wcslen, qse_size_t* _mbslen)
{
qse_size_t mbslen, wcslen;
qse_mchar_t* mbs;
wcslen = _wcslen;
if (qse_wcsntombsnwithcmgr(wcs, &wcslen, QSE_NULL, &mbslen, qse_awk_rtx_getcmgr(rtx)) <= -1)
{
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EINVAL, QSE_NULL);
return QSE_NULL;
}
mbs = qse_awk_rtx_allocmem(rtx, QSE_SIZEOF(*mbs) * (mbslen + 1));
if (!mbs) return QSE_NULL;
wcslen = _wcslen;
qse_wcsntombsnwithcmgr (wcs, &wcslen, mbs, &mbslen, qse_awk_rtx_getcmgr(rtx));
mbs[mbslen] = QSE_MT('\0');
if (_mbslen) *_mbslen = mbslen;
return mbs;
}

View File

@ -1508,7 +1508,7 @@ qse_awk_val_t* qse_awk_rtx_loop (qse_awk_rtx_t* rtx)
} }
/* find an AWK function by name */ /* find an AWK function by name */
qse_awk_fun_t* qse_awk_rtx_findfun (qse_awk_rtx_t* rtx, const qse_char_t* name) static qse_awk_fun_t* find_fun (qse_awk_rtx_t* rtx, const qse_char_t* name)
{ {
qse_htb_pair_t* pair; qse_htb_pair_t* pair;
@ -1528,6 +1528,36 @@ qse_awk_fun_t* qse_awk_rtx_findfun (qse_awk_rtx_t* rtx, const qse_char_t* name)
return (qse_awk_fun_t*)QSE_HTB_VPTR(pair); return (qse_awk_fun_t*)QSE_HTB_VPTR(pair);
} }
qse_awk_fun_t* qse_awk_rtx_findfunwithmbs (qse_awk_rtx_t* rtx, const qse_mchar_t* name)
{
#if defined(QSE_CHAR_IS_MCHAR)
return find_fun(rtx, name);
#else
qse_mcstr_t mbs;
qse_awk_fun_t* fun;
mbs.ptr = qse_awk_rtx_wcstombsdup(rtx, name, &mbs.len);
if (!mbs.ptr) return -1;
fun = find_fun(rtx, mbs.ptr);
qse_awk_rtx_freemem (rtx, mbs.ptr);
return fun;
#endif
}
qse_awk_fun_t* qse_awk_rtx_findfunwithwcs (qse_awk_rtx_t* rtx, const qse_wchar_t* name)
{
#if defined(QSE_CHAR_IS_MCHAR)
qse_wcstr_t wcs;
qse_awk_fun_t* fun;
wcs.ptr = qse_awk_rtx_mbstowcsdup(rtx, name, &wcs.len);
if (!wcs.ptr) return -1;
fun = find_fun(rtx, wcs.ptr);
qse_awk_rtx_freemem (rtx, wcs.ptr);
return fun;
#else
return find_fun(rtx, name);
#endif
}
/* call an AWK function by the function structure */ /* call an AWK function by the function structure */
qse_awk_val_t* qse_awk_rtx_callfun (qse_awk_rtx_t* rtx, qse_awk_fun_t* fun, qse_awk_val_t* args[], qse_size_t nargs) qse_awk_val_t* qse_awk_rtx_callfun (qse_awk_rtx_t* rtx, qse_awk_fun_t* fun, qse_awk_val_t* args[], qse_size_t nargs)
{ {
@ -1606,11 +1636,21 @@ qse_awk_val_t* qse_awk_rtx_callfun (qse_awk_rtx_t* rtx, qse_awk_fun_t* fun, qse_
} }
/* call an AWK function by name */ /* call an AWK function by name */
qse_awk_val_t* qse_awk_rtx_call (qse_awk_rtx_t* rtx, const qse_char_t* name, qse_awk_val_t* args[], qse_size_t nargs) qse_awk_val_t* qse_awk_rtx_callwithmbs (qse_awk_rtx_t* rtx, const qse_mchar_t* name, qse_awk_val_t* args[], qse_size_t nargs)
{ {
qse_awk_fun_t* fun; qse_awk_fun_t* fun;
fun = qse_awk_rtx_findfun(rtx, name); fun = qse_awk_rtx_findfunwithmbs(rtx, name);
if (!fun) return QSE_NULL;
return qse_awk_rtx_callfun(rtx, fun, args, nargs);
}
qse_awk_val_t* qse_awk_rtx_callwithwcs (qse_awk_rtx_t* rtx, const qse_wchar_t* name, qse_awk_val_t* args[], qse_size_t nargs)
{
qse_awk_fun_t* fun;
fun = qse_awk_rtx_findfunwithwcs(rtx, name);
if (!fun) return QSE_NULL; if (!fun) return QSE_NULL;
return qse_awk_rtx_callfun(rtx, fun, args, nargs); return qse_awk_rtx_callfun(rtx, fun, args, nargs);

View File

@ -30,7 +30,7 @@
#define IS_MSEP(c) QSE_ISPATHMBSEP(c) #define IS_MSEP(c) QSE_ISPATHMBSEP(c)
#define IS_WSEP(c) QSE_ISPATHWCSEP(c) #define IS_WSEP(c) QSE_ISPATHWCSEP(c)
const qse_mchar_t* qse_mbsbasename (const qse_mchar_t* path) const qse_mchar_t* qse_basenameasmbs (const qse_mchar_t* path)
{ {
const qse_mchar_t* p, * last = QSE_NULL; const qse_mchar_t* p, * last = QSE_NULL;
@ -42,7 +42,7 @@ const qse_mchar_t* qse_mbsbasename (const qse_mchar_t* path)
return (last == QSE_NULL)? path: (last + 1); return (last == QSE_NULL)? path: (last + 1);
} }
const qse_wchar_t* qse_wcsbasename (const qse_wchar_t* path) const qse_wchar_t* qse_basenameaswcs (const qse_wchar_t* path)
{ {
const qse_wchar_t* p, * last = QSE_NULL; const qse_wchar_t* p, * last = QSE_NULL;
@ -61,7 +61,7 @@ qse_mchar_t* qse_substmbsbasenamedup (const qse_mchar_t* path, const qse_mchar_t
qse_mcstr_t seg[3]; qse_mcstr_t seg[3];
qse_size_t idx = 0; qse_size_t idx = 0;
b = qse_mbsbasename(path); b = qse_basenameasmbs(path);
if (b) if (b)
{ {
seg[idx].ptr = (qse_mchar_t*)path; seg[idx].ptr = (qse_mchar_t*)path;
@ -85,7 +85,7 @@ qse_wchar_t* qse_substwcsbasenamedup (const qse_wchar_t* path, const qse_wchar_t
qse_wcstr_t seg[3]; qse_wcstr_t seg[3];
qse_size_t idx = 0; qse_size_t idx = 0;
b = qse_wcsbasename(path); b = qse_basenameaswcs(path);
if (b) if (b)
{ {
seg[idx].ptr = (qse_wchar_t*)path; seg[idx].ptr = (qse_wchar_t*)path;

View File

@ -43,12 +43,12 @@
#if defined(QSE_HTTPD_DEBUG) #if defined(QSE_HTTPD_DEBUG)
# include <qse/si/sio.h> # include <qse/si/sio.h>
# include <qse/cmn/path.h> # include <qse/cmn/path.h>
# define HTTPD_DBGOUT0(fmt) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__)) # define HTTPD_DBGOUT0(fmt) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_basenameasmbs(__FILE__))
# define HTTPD_DBGOUT1(fmt,a1) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1)) # define HTTPD_DBGOUT1(fmt,a1) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_basenameasmbs(__FILE__), (a1))
# define HTTPD_DBGOUT2(fmt,a1,a2) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2)) # define HTTPD_DBGOUT2(fmt,a1,a2) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_basenameasmbs(__FILE__), (a1), (a2))
# define HTTPD_DBGOUT3(fmt,a1,a2,a3) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2), (a3)) # define HTTPD_DBGOUT3(fmt,a1,a2,a3) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_basenameasmbs(__FILE__), (a1), (a2), (a3))
# define HTTPD_DBGOUT4(fmt,a1,a2,a3,a4) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2), (a3), (a4)) # define HTTPD_DBGOUT4(fmt,a1,a2,a3,a4) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_basenameasmbs(__FILE__), (a1), (a2), (a3), (a4))
# define HTTPD_DBGOUT5(fmt,a1,a2,a3,a4,a5) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2), (a3), (a4), (a5)) # define HTTPD_DBGOUT5(fmt,a1,a2,a3,a4,a5) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_basenameasmbs(__FILE__), (a1), (a2), (a3), (a4), (a5))
#else #else
# define HTTPD_DBGOUT0(fmt) # define HTTPD_DBGOUT0(fmt)
# define HTTPD_DBGOUT1(fmt,a1) # define HTTPD_DBGOUT1(fmt,a1)

View File

@ -94,14 +94,14 @@
# define canon_fspath(path,canon,flags) qse_canonmbspath(path,canon,flags) # define canon_fspath(path,canon,flags) qse_canonmbspath(path,canon,flags)
# define merge_fspath_dup(dir,file,mmgr) qse_mergembspathdup(dir,file,mmgr) # define merge_fspath_dup(dir,file,mmgr) qse_mergembspathdup(dir,file,mmgr)
# define get_fspath_core(fspath) qse_mbspathcore(fspath) # define get_fspath_core(fspath) qse_mbspathcore(fspath)
# define get_fspath_base(fspath) qse_mbsbasename(fspath) # define get_fspath_base(fspath) qse_basenameasmbs(fspath)
# define IS_FSPATHSEP(x) QSE_ISPATHMBSEP(x) # define IS_FSPATHSEP(x) QSE_ISPATHMBSEP(x)
# define QSE_FS_T(x) QSE_MT(x) # define QSE_FS_T(x) QSE_MT(x)
#else #else
# define canon_fspath(fspath,canon,flags) qse_canonwcspath(fspath,canon,flags) # define canon_fspath(fspath,canon,flags) qse_canonwcspath(fspath,canon,flags)
# define merge_fspath_dup(dir,file,mmgr) qse_mergewcspathdup(dir,file,mmgr) # define merge_fspath_dup(dir,file,mmgr) qse_mergewcspathdup(dir,file,mmgr)
# define get_fspath_core(fspath) qse_wcspathcore(fspath) # define get_fspath_core(fspath) qse_wcspathcore(fspath)
# define get_fspath_base(fspath) qse_wcsbasename(fspath) # define get_fspath_base(fspath) qse_basenameaswcs(fspath)
# define IS_FSPATHSEP(x) QSE_ISPATHWCSEP(x) # define IS_FSPATHSEP(x) QSE_ISPATHWCSEP(x)
# define QSE_FS_T(x) QSE_WT(x) # define QSE_FS_T(x) QSE_WT(x)
#endif #endif

View File

@ -211,7 +211,7 @@ static qse_ssize_t sf_in_open (qse_xli_t* xli, qse_xli_io_arg_t* arg, xtn_t* xtn
const qse_char_t* base; const qse_char_t* base;
/* i'm being included from another file */ /* i'm being included from another file */
base = qse_basename (outer); base = qse_basename(outer);
if (base != outer && arg->name[0] != QSE_T('/')) if (base != outer && arg->name[0] != QSE_T('/'))
{ {
qse_size_t tmplen, totlen, dirlen; qse_size_t tmplen, totlen, dirlen;
@ -438,7 +438,7 @@ static qse_ssize_t sf_out_open (qse_xli_t* xli, qse_xli_io_arg_t* arg, xtn_t* xt
const qse_char_t* base; const qse_char_t* base;
/* i'm being included from another file */ /* i'm being included from another file */
base = qse_basename (outer); base = qse_basename(outer);
if (base != outer && arg->name[0] != QSE_T('/')) if (base != outer && arg->name[0] != QSE_T('/'))
{ {
qse_size_t tmplen, totlen, dirlen; qse_size_t tmplen, totlen, dirlen;

View File

@ -166,7 +166,7 @@ int main (int argc, char* argv[])
switch (c) switch (c)
{ {
case 'h': case 'h':
print_usage (qse_mbsbasename(argv[0])); print_usage (qse_basenameasmbs(argv[0]));
return 0; return 0;
case 'k': case 'k':
@ -200,7 +200,7 @@ int main (int argc, char* argv[])
case '?': case '?':
case ':': case ':':
print_usage (qse_mbsbasename(argv[0])); print_usage (qse_basenameasmbs(argv[0]));
return -1; return -1;
} }
} }