enhanced parsing getline
added qse_cstrdup()/qse_wcstrdup()/qse_mcstrdup()
This commit is contained in:
parent
4e92c0ef1c
commit
18ab6aaf8d
@ -1657,6 +1657,16 @@ void* qse_awk_reallocmem (
|
||||
qse_size_t size /**< new block size in bytes */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_callocmem() function allocates a memory block of
|
||||
* the size of @a size bytes and initializes it with 0.
|
||||
* @return a pointer to a memory block on success, #QSE_NULL on failure
|
||||
*/
|
||||
void* qse_awk_callocmem (
|
||||
qse_awk_t* awk, /**< awk */
|
||||
qse_size_t size /**< size of memory to allocate in bytes */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_freemem() function frees dynamic memory allocated.
|
||||
*/
|
||||
@ -1668,7 +1678,8 @@ void qse_awk_freemem (
|
||||
/**
|
||||
* The qse_awk_strdup() function is used to duplicate a string using
|
||||
* the memory manager used by the associated qse_awk_t instance.
|
||||
* The new string should be freed using the qse_awk_free() function.
|
||||
* The new string must be freed using the qse_awk_freemem() function when
|
||||
* it's not needed any more.
|
||||
*
|
||||
* @return a pointer to a new string duplicated of @a s on success,
|
||||
* #QSE_NULL on failure.
|
||||
@ -1681,8 +1692,8 @@ qse_char_t* qse_awk_strdup (
|
||||
/**
|
||||
* The qse_awk_strxdup() function is used to duplicate a string whose length
|
||||
* is as long as len characters using the memory manager used by the
|
||||
* qse_awk_t instance. The new string should be freed using the qse_awk_free()
|
||||
* function.
|
||||
* qse_awk_t instance. The new string must be freed using the qse_awk_freemem()
|
||||
* function it's not needed any more.
|
||||
*
|
||||
* @return a pointer to a new string duplicated of @a s on success,
|
||||
* #QSE_NULL on failure.
|
||||
@ -1693,6 +1704,19 @@ qse_char_t* qse_awk_strxdup (
|
||||
qse_size_t len /**< string length */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_cstrdup() funcation duplicates @a str->len characters from a
|
||||
* string pointed to by @str->ptr. The duplicated string must be freed with
|
||||
* the qse_awk_freemem() function when it's not needed any more.
|
||||
*
|
||||
* @return pointer to a duplicated string on success,
|
||||
* #QSE_NULL on failure.
|
||||
*/
|
||||
qse_char_t* qse_awk_cstrdup (
|
||||
qse_awk_t* awk, /**< awk */
|
||||
const qse_cstr_t* str /**< string */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_strxtolong() function converts a string to an integer.
|
||||
*/
|
||||
@ -2524,6 +2548,16 @@ void* qse_awk_rtx_reallocmem (
|
||||
qse_size_t size /**< block size in bytes */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_callocmem() function allocates a memory block of
|
||||
* the size of @a size bytes and initializes it with 0.
|
||||
* @return a pointer to a memory block on success, #QSE_NULL on failure
|
||||
*/
|
||||
void* qse_awk_rtx_callocmem (
|
||||
qse_awk_rtx_t* rtx, /**< runtime context */
|
||||
qse_size_t size /**< block size in bytes */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_freemem() function frees a memory block pointed to by @a ptr
|
||||
* using the memory manager of a runtime ocntext @a rtx.
|
||||
|
@ -998,12 +998,6 @@ qse_mchar_t* qse_mbsadup (
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_mchar_t* qse_mbsxadup (
|
||||
const qse_mcstr_t str[],
|
||||
qse_size_t* len,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_wchar_t* qse_wcsdup (
|
||||
const qse_wchar_t* str,
|
||||
qse_mmgr_t* mmgr
|
||||
@ -1035,26 +1029,48 @@ qse_wchar_t* qse_wcsadup (
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_wchar_t* qse_wcsxadup (
|
||||
const qse_wcstr_t str[],
|
||||
qse_size_t* len,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
# define qse_strdup(s,mmgr) qse_mbsdup(s,mmgr)
|
||||
# define qse_strdup2(s1,s2,mmgr) qse_mbsdup2(s1,s2,mmgr)
|
||||
# define qse_strxdup(s,l,mmgr) qse_mbsxdup(s,l,mmgr)
|
||||
# define qse_strxdup2(s1,l1,s2,l2,mmgr) qse_mbsxdup(s1,l1,s2,l2,mmgr)
|
||||
# define qse_stradup(sa,len,mmgr) qse_mbsadup(sa,len,mmgr)
|
||||
# define qse_strxadup(sa,len,mmgr) qse_mbsxadup(sa,len,mmgr)
|
||||
#else
|
||||
# define qse_strdup(s,mmgr) qse_wcsdup(s,mmgr)
|
||||
# define qse_strdup2(s1,s2,mmgr) qse_wcsdup2(s1,s2,mmgr)
|
||||
# define qse_strxdup(s,l,mmgr) qse_wcsxdup(s,l,mmgr)
|
||||
# define qse_strxdup2(s1,l1,s2,l2,mmgr) qse_wcsxdup(s1,l1,s2,l2,mmgr)
|
||||
# define qse_stradup(sa,len,mmgr) qse_wcsadup(sa,len,mmgr)
|
||||
# define qse_strxadup(sa,len,mmgr) qse_wcsxadup(sa,len,mmgr)
|
||||
#endif
|
||||
|
||||
qse_mchar_t* qse_mcstrdup (
|
||||
const qse_mcstr_t* str,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_mchar_t* qse_mcstradup (
|
||||
const qse_mcstr_t str[],
|
||||
qse_size_t* len,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_wchar_t* qse_wcstrdup (
|
||||
const qse_wcstr_t* str,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_wchar_t* qse_wcstradup (
|
||||
const qse_wcstr_t str[],
|
||||
qse_size_t* len,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
# define qse_cstrdup(sa,mmgr) qse_mcstrdup(sa,mmgr)
|
||||
# define qse_cstradup(sa,len,mmgr) qse_mcstradup(sa,len,mmgr)
|
||||
#else
|
||||
# define qse_cstrdup(sa,mmgr) qse_wcstrdup(sa,mmgr)
|
||||
# define qse_cstradup(sa,len,mmgr) qse_wcstradup(sa,len,mmgr)
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -27,6 +27,14 @@ void* qse_awk_allocmem (qse_awk_t* awk, qse_size_t size)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* qse_awk_callocmem (qse_awk_t* awk, qse_size_t size)
|
||||
{
|
||||
void* ptr = QSE_AWK_ALLOC (awk, size);
|
||||
if (ptr) QSE_MEMSET (ptr, 0, size);
|
||||
else qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* qse_awk_reallocmem (qse_awk_t* awk, void* ptr, qse_size_t size)
|
||||
{
|
||||
void* nptr = QSE_AWK_REALLOC (awk, ptr, size);
|
||||
@ -53,6 +61,13 @@ qse_char_t* qse_awk_strxdup (qse_awk_t* awk, const qse_char_t* s, qse_size_t l)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
qse_char_t* qse_awk_cstrdup (qse_awk_t* awk, const qse_cstr_t* s)
|
||||
{
|
||||
qse_char_t* ptr = qse_cstrdup (s, awk->mmgr);
|
||||
if (ptr == QSE_NULL) qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
qse_long_t qse_awk_strxtolong (
|
||||
qse_awk_t* awk, const qse_char_t* str, qse_size_t len,
|
||||
int base, const qse_char_t** endptr)
|
||||
@ -1095,17 +1110,29 @@ int qse_awk_matchrex (
|
||||
|
||||
void* qse_awk_rtx_allocmem (qse_awk_rtx_t* rtx, qse_size_t size)
|
||||
{
|
||||
return qse_awk_allocmem (rtx->awk, size);
|
||||
void* ptr = QSE_AWK_ALLOC (rtx->awk, size);
|
||||
if (ptr == QSE_NULL) qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* qse_awk_rtx_reallocmem (qse_awk_rtx_t* rtx, void* ptr, qse_size_t size)
|
||||
{
|
||||
return qse_awk_reallocmem (rtx->awk, ptr, size);
|
||||
void* nptr = QSE_AWK_REALLOC (rtx->awk, ptr, size);
|
||||
if (nptr == QSE_NULL) qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return nptr;
|
||||
}
|
||||
|
||||
void* qse_awk_rtx_callocmem (qse_awk_rtx_t* rtx, qse_size_t size)
|
||||
{
|
||||
void* ptr = QSE_AWK_ALLOC (rtx->awk, size);
|
||||
if (ptr) QSE_MEMSET (ptr, 0, size);
|
||||
else qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void qse_awk_rtx_freemem (qse_awk_rtx_t* rtx, void* ptr)
|
||||
{
|
||||
qse_awk_freemem (rtx->awk, ptr);
|
||||
QSE_AWK_FREE (rtx->awk, ptr);
|
||||
}
|
||||
|
||||
int qse_awk_sprintflt (
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1595,12 +1595,8 @@ qse_awk_val_t* qse_awk_rtx_callwithstrs (
|
||||
qse_size_t i;
|
||||
qse_awk_val_t** v, * ret;
|
||||
|
||||
v = QSE_MMGR_ALLOC (rtx->awk->mmgr, QSE_SIZEOF(*v) * nargs);
|
||||
if (v == QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return QSE_NULL;
|
||||
}
|
||||
v = qse_awk_rtx_allocmem (rtx, QSE_SIZEOF(*v) * nargs);
|
||||
if (v == QSE_NULL) return QSE_NULL;
|
||||
|
||||
for (i = 0; i < nargs; i++)
|
||||
{
|
||||
|
@ -607,15 +607,10 @@ static qse_ssize_t sf_in_open (
|
||||
totlen = qse_strlen(arg->name) + xtn->s.in.u.file.dir.len;
|
||||
if (totlen >= QSE_COUNTOF(fbuf))
|
||||
{
|
||||
dbuf = QSE_MMGR_ALLOC (
|
||||
awk->mmgr,
|
||||
QSE_SIZEOF(qse_char_t) * (totlen + 1)
|
||||
dbuf = qse_awk_allocmem (
|
||||
awk, QSE_SIZEOF(qse_char_t) * (totlen + 1)
|
||||
);
|
||||
if (dbuf == QSE_NULL)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
if (dbuf == QSE_NULL) return -1;
|
||||
|
||||
file = dbuf;
|
||||
}
|
||||
@ -2626,7 +2621,7 @@ static int query_module (
|
||||
tmp[3].len = namelen;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
modpath = qse_mbsxadup (tmp, QSE_NULL, awk->mmgr);
|
||||
modpath = qse_mcstradup (tmp, QSE_NULL, awk->mmgr);
|
||||
#else
|
||||
modpath = qse_wcsnatombsdup (tmp, QSE_NULL, awk->mmgr);
|
||||
#endif
|
||||
|
@ -92,7 +92,21 @@ qse_mchar_t* qse_mbsadup (const qse_mchar_t* str[], qse_size_t* len, qse_mmgr_t*
|
||||
return buf;
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_mbsxadup (const qse_mcstr_t str[], qse_size_t* len, qse_mmgr_t* mmgr)
|
||||
qse_mchar_t* qse_mcstrdup (const qse_mcstr_t* str, qse_mmgr_t* mmgr)
|
||||
{
|
||||
qse_mchar_t* buf;
|
||||
|
||||
QSE_ASSERT (mmgr != QSE_NULL);
|
||||
|
||||
buf = (qse_mchar_t*) QSE_MMGR_ALLOC (
|
||||
mmgr, (str->len + 1) * QSE_SIZEOF(*buf));
|
||||
if (buf == QSE_NULL) return QSE_NULL;
|
||||
|
||||
qse_mbsncpy (buf, str->ptr, str->len);
|
||||
return buf;
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_mcstradup (const qse_mcstr_t str[], qse_size_t* len, qse_mmgr_t* mmgr)
|
||||
{
|
||||
qse_mchar_t* buf, * ptr;
|
||||
qse_size_t i;
|
||||
@ -187,7 +201,21 @@ qse_wchar_t* qse_wcsadup (const qse_wchar_t* str[], qse_size_t* len, qse_mmgr_t*
|
||||
return buf;
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_wcsxadup (const qse_wcstr_t str[], qse_size_t* len, qse_mmgr_t* mmgr)
|
||||
qse_wchar_t* qse_wcstrdup (const qse_wcstr_t* str, qse_mmgr_t* mmgr)
|
||||
{
|
||||
qse_wchar_t* buf;
|
||||
|
||||
QSE_ASSERT (mmgr != QSE_NULL);
|
||||
|
||||
buf = (qse_wchar_t*) QSE_MMGR_ALLOC (
|
||||
mmgr, (str->len + 1) * QSE_SIZEOF(*buf));
|
||||
if (buf == QSE_NULL) return QSE_NULL;
|
||||
|
||||
qse_wcsncpy (buf, str->ptr, str->len);
|
||||
return buf;
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_wcstradup (const qse_wcstr_t str[], qse_size_t* len, qse_mmgr_t* mmgr)
|
||||
{
|
||||
qse_wchar_t* buf, * ptr;
|
||||
qse_size_t i;
|
||||
|
@ -2176,7 +2176,7 @@ qse_httpd_server_t* qse_httpd_attachserverstd (
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
server_xtn->cfg[SERVER_XTN_CFG_DOCROOT] = qse_mbsxdup (xuri.path.ptr, xuri.path.len, httpd->mmgr);
|
||||
if (xuri.frag.ptr) server_xtn->cfg[SERVER_XTN_CFG_REALM] = qse_mbsxdup (xuri.frag.ptr, xuri.frag.len, httpd->mmgr);
|
||||
ba.ptr = qse_mbsxadup (tmp, &ba.len, httpd->mmgr);
|
||||
ba.ptr = qse_mcstradup (tmp, &ba.len, httpd->mmgr);
|
||||
|
||||
#else
|
||||
server_xtn->cfg[SERVER_XTN_CFG_DOCROOT] = qse_wcsntombsdup (xuri.path.ptr, xuri.path.len, QSE_NULL, httpd->mmgr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user