added qse_strxtrmx()
added sys::trim(). allowed a singled quoted string in awk
This commit is contained in:
parent
f04bea44e1
commit
1ad89afa99
@ -78,7 +78,7 @@ typedef qse_size_t (*qse_wcs_sizer_t) (
|
||||
qse_size_t hint
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define QSE_STR_XSTR(s) ((qse_xstr_t*)QSE_MBS_XSTR(s))
|
||||
# define QSE_STR_CSTR(s) ((qse_cstr_t*)QSE_MBS_XSTR(s))
|
||||
# define QSE_STR_LEN(s) QSE_MBS_LEN(s)
|
||||
@ -147,7 +147,7 @@ typedef qse_wchar_t* (*qse_wcsxsubst_subst_t) (
|
||||
void* ctx
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strxsubst_subst_t qse_mbsxsubst_subst_t
|
||||
#else
|
||||
# define qse_strxsubst_subst_t qse_wcsxsubst_subst_t
|
||||
@ -298,9 +298,9 @@ typedef qse_wchar_t* (*qse_wcsxsubst_subst_t) (
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* The qse_mbstrmx_op_t defines a string trimming operation.
|
||||
* The qse_mbstrmx_flag_t defines a string trimming operation.
|
||||
*/
|
||||
enum qse_mbstrmx_op_t
|
||||
enum qse_mbstrmx_flag_t
|
||||
{
|
||||
QSE_MBSTRMX_LEFT = (1 << 0), /**< trim leading spaces */
|
||||
#define QSE_MBSTRMX_LEFT QSE_MBSTRMX_LEFT
|
||||
@ -309,9 +309,9 @@ enum qse_mbstrmx_op_t
|
||||
};
|
||||
|
||||
/**
|
||||
* The qse_wcstrmx_op_t defines a string trimming operation.
|
||||
* The qse_wcstrmx_flag_t defines a string trimming operation.
|
||||
*/
|
||||
enum qse_wcstrmx_op_t
|
||||
enum qse_wcstrmx_flag_t
|
||||
{
|
||||
QSE_WCSTRMX_LEFT = (1 << 0), /**< trim leading spaces */
|
||||
#define QSE_WCSTRMX_LEFT QSE_WCSTRMX_LEFT
|
||||
@ -319,7 +319,7 @@ enum qse_wcstrmx_op_t
|
||||
#define QSE_WCSTRMX_RIGHT QSE_WCSTRMX_RIGHT
|
||||
};
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define QSE_STRTRMX_LEFT QSE_MBSTRMX_LEFT
|
||||
# define QSE_STRTRMX_RIGHT QSE_MBSTRMX_RIGHT
|
||||
#else
|
||||
@ -351,7 +351,7 @@ enum qse_wcsfnmat_flag_t
|
||||
#define QSE_WCSFNMAT_IGNORECASE QSE_WCSFNMAT_IGNORECASE
|
||||
};
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define QSE_STRFNMAT_PATHNAME QSE_MBSFNMAT_PATHNAME
|
||||
# define QSE_STRFNMAT_NOESCAPE QSE_MBSFNMAT_NOESCAPE
|
||||
# define QSE_STRFNMAT_PERIOD QSE_MBSFNMAT_PERIOD
|
||||
@ -405,7 +405,7 @@ qse_size_t qse_wcsbytes (
|
||||
const qse_wchar_t* str
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strlen(str) qse_mbslen(str)
|
||||
# define qse_strbytes(str) qse_mbsbytes(str)
|
||||
#else
|
||||
@ -477,7 +477,7 @@ qse_size_t qse_wcsxncpy (
|
||||
qse_size_t len /**< string length */
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strcpy(buf,str) qse_mbscpy(buf,str)
|
||||
# define qse_strxcpy(buf,bsz,str) qse_mbsxcpy(buf,bsz,str)
|
||||
# define qse_strncpy(buf,str,len) qse_mbsncpy(buf,str,len)
|
||||
@ -535,7 +535,7 @@ qse_size_t qse_wcsxnput (
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strput(buf,str) qse_mbsput(buf,str)
|
||||
# define qse_strxput(buf,bsz,str) qse_mbsxput(buf,bsz,str)
|
||||
# define qse_strxnput(buf,bsz,str,len) qse_mbsxnput(buf,bsz,str,len)
|
||||
@ -667,7 +667,7 @@ qse_size_t qse_wcsxfncpy (
|
||||
const qse_wcstr_t str[]
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strfcpy(buf,fmt,str) qse_mbsfcpy(buf,fmt,str)
|
||||
# define qse_strfncpy(buf,fmt,str) qse_mbsfncpy(buf,fmt,str)
|
||||
# define qse_strxfcpy(buf,bsz,fmt,str) qse_mbsxfcpy(buf,bsz,fmt,str)
|
||||
@ -731,7 +731,7 @@ qse_size_t qse_wcsxsubst (
|
||||
void* ctx
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strxsubst(buf,bsz,fmt,subst,ctx) qse_mbsxsubst(buf,bsz,fmt,subst,ctx)
|
||||
#else
|
||||
# define qse_strxsubst(buf,bsz,fmt,subst,ctx) qse_wcsxsubst(buf,bsz,fmt,subst,ctx)
|
||||
@ -797,7 +797,7 @@ qse_size_t qse_wcsxncat (
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strcat(buf,str) qse_mbscat(buf,str)
|
||||
# define qse_strncat(buf,str,len) qse_mbsncat(buf,str,len)
|
||||
# define qse_strcatn(buf,str,n) qse_mbscatn(buf,str,n)
|
||||
@ -947,7 +947,7 @@ int qse_wcszcasecmp (
|
||||
qse_size_t n
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strcmp(s1,s2) qse_mbscmp(s1,s2)
|
||||
# define qse_strxcmp(s1,ln1,s2) qse_mbsxcmp(s1,ln1,s2)
|
||||
# define qse_strxncmp(s1,ln1,s2,ln2) qse_mbsxncmp(s1,ln1,s2,ln2)
|
||||
@ -1029,7 +1029,7 @@ qse_wchar_t* qse_wcsadup (
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(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)
|
||||
@ -1065,7 +1065,7 @@ qse_wchar_t* qse_wcstradup (
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(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
|
||||
@ -1241,7 +1241,7 @@ qse_wchar_t* qse_wcsxnrcasestr (
|
||||
qse_size_t subsz
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strstr(str,sub) qse_mbsstr(str,sub)
|
||||
# define qse_strxstr(str,size,sub) qse_mbsxstr(str,size,sub)
|
||||
# define qse_strxnstr(str,strsz,sub,subsz) qse_mbsxnstr(str,strsz,sub,subsz)
|
||||
@ -1327,7 +1327,7 @@ const qse_wchar_t* qse_wcsxcaseword (
|
||||
const qse_wchar_t* word
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strword(str,word) qse_mbsword(str,word)
|
||||
# define qse_strxword(str,len,word) qse_mbsxword(str,len,word)
|
||||
# define qse_strcaseword(str,word) qse_mbscaseword(str,word)
|
||||
@ -1389,7 +1389,7 @@ qse_wchar_t* qse_wcsxrchr (
|
||||
qse_wcint_t c
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strchr(str,c) qse_mbschr(str,c)
|
||||
# define qse_strxchr(str,len,c) qse_mbsxchr(str,len,c)
|
||||
# define qse_strrchr(str,c) qse_mbsrchr(str,c)
|
||||
@ -1469,7 +1469,7 @@ qse_wchar_t* qse_wcscasebeg (
|
||||
const qse_wchar_t* sub
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strbeg(str,sub) qse_mbsbeg(str,sub)
|
||||
# define qse_strxbeg(str,len,sub) qse_mbsxbeg(str,len,sub)
|
||||
# define qse_strnbeg(str,sub,len) qse_mbsnbeg(str,sub,len)
|
||||
@ -1541,7 +1541,7 @@ qse_wchar_t* qse_wcsxnend (
|
||||
qse_size_t len2
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strend(str,sub) qse_mbsxend(str,sub)
|
||||
# define qse_strxend(str,len,sub) qse_mbsxend(str,len,sub)
|
||||
# define qse_strnend(str,sub,len) qse_mbsnend(str,sub,len)
|
||||
@ -1573,7 +1573,7 @@ qse_size_t qse_wcscspn (
|
||||
const qse_wchar_t* str2
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strspn(str1,str2) qse_mbsspn(str1,str2)
|
||||
# define qse_strcspn(str1,str2) qse_mbscspn(str1,str2)
|
||||
#else
|
||||
@ -1637,7 +1637,7 @@ qse_wchar_t* qse_wcsxrpbrk (
|
||||
const qse_wchar_t* str2
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strpbrk(str1,str2) qse_mbspbrk(str1,str2)
|
||||
# define qse_strxpbrk(str1,len,str2) qse_mbsxpbrk(str1,len,str2)
|
||||
# define qse_strrpbrk(str1,str2) qse_mbsrpbrk(str1,str2)
|
||||
@ -1751,7 +1751,7 @@ qse_size_t qse_wcsxdel (
|
||||
qse_size_t n
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strdel(str,pos,n) qse_mbsdel(str,pos,n)
|
||||
# define qse_strxdel(str,len,pos,n) qse_mbsxdel(str,len,pos,n)
|
||||
#else
|
||||
@ -1782,7 +1782,7 @@ qse_size_t qse_wcsxexcl (
|
||||
const qse_wchar_t* cs
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strexcl(str,cs) qse_mbsexcl(str,cs)
|
||||
# define qse_strxexcl(str,len,cs) qse_mbsxexcl(str,len,cs)
|
||||
#else
|
||||
@ -1812,7 +1812,7 @@ qse_size_t qse_wcsxincl (
|
||||
const qse_wchar_t* cs
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strincl(str,cs) qse_mbsincl(str,cs)
|
||||
# define qse_strxincl(str,len,cs) qse_mbsxincl(str,len,cs)
|
||||
#else
|
||||
@ -1847,7 +1847,7 @@ qse_size_t qse_wcsxset (
|
||||
qse_size_t n
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strset(buf,c,n) qse_mbsset(buf,c,n)
|
||||
# define qse_strxset(buf,bsz,c,n) qse_mbsxset(buf,bsz,c,n)
|
||||
#else
|
||||
@ -1873,7 +1873,7 @@ qse_size_t qse_wcsupr (
|
||||
qse_wchar_t* str
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strlwr(str) qse_mbslwr(str);
|
||||
# define qse_strupr(str) qse_mbsupr(str);
|
||||
#else
|
||||
@ -1900,7 +1900,7 @@ qse_size_t qse_wcsxrev (
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strrev(str) qse_mbsrev(str)
|
||||
# define qse_strxrev(str,len) qse_mbsxrev(str,len)
|
||||
#else
|
||||
@ -1934,7 +1934,7 @@ qse_size_t qse_wcsxrot (
|
||||
qse_size_t n
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strrot(str,dir,n) qse_mbsrot(str,dir,n)
|
||||
# define qse_strxrot(str,len,dir,n) qse_mbsrot(str,len,dir,n)
|
||||
#else
|
||||
@ -2028,7 +2028,7 @@ int qse_wcsspltrn (
|
||||
const qse_wchar_t* trset
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strspl(str,delim,lquote,rquote,escape) qse_mbsspl(str,delim,lquote,rquote,escape)
|
||||
# define qse_strspltrn(str,delim,lquote,rquote,escape,trset) qse_mbsspltrn(str,delim,lquote,rquote,escape,trset)
|
||||
#else
|
||||
@ -2079,7 +2079,7 @@ qse_wchar_t* qse_wcsxntok (
|
||||
qse_wcstr_t* tok
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strtok(s,d,t) qse_mbstok(s,d,t)
|
||||
# define qse_strxtok(s,len,d,t) qse_mbsxtok(s,len,d,t)
|
||||
# define qse_strxntok(s,len,d,dl,t) qse_mbsxntok(s,len,d,dl,t)
|
||||
@ -2112,7 +2112,13 @@ qse_wchar_t* qse_wcsxntok (
|
||||
*/
|
||||
qse_mchar_t* qse_mbstrmx (
|
||||
qse_mchar_t* str, /**< string */
|
||||
int opt /**< option OR'ed of #qse_mbstrmx_op_t values */
|
||||
int flags /**< option OR'ed of #qse_mbstrmx_flag_t values */
|
||||
);
|
||||
|
||||
qse_mchar_t* qse_mbsxtrmx (
|
||||
qse_mchar_t* str, /**< string */
|
||||
qse_size_t* len, /**< [IN/OUT] length */
|
||||
int flags /**< option OR'ed of #qse_mbstrmx_flag_t values */
|
||||
);
|
||||
|
||||
/**
|
||||
@ -2137,8 +2143,14 @@ qse_mchar_t* qse_mbstrmx (
|
||||
* @return pointer to a trimmed string.
|
||||
*/
|
||||
qse_wchar_t* qse_wcstrmx (
|
||||
qse_wchar_t* str, /**< a string */
|
||||
int opt /**< option OR'ed of #qse_wcstrmx_op_t values */
|
||||
qse_wchar_t* str, /**< string */
|
||||
int flags /**< option OR'ed of #qse_wcstrmx_flag_t values */
|
||||
);
|
||||
|
||||
qse_wchar_t* qse_wcsxtrmx (
|
||||
qse_wchar_t* str, /**< string */
|
||||
qse_size_t* len, /**< [IN/OUT] length */
|
||||
int flags /**< option OR'ed of #qse_wcstrmx_flag_t values */
|
||||
);
|
||||
|
||||
/**
|
||||
@ -2187,12 +2199,14 @@ qse_size_t qse_wcsxtrm (
|
||||
qse_size_t len /**< length */
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strtrmx(str,opt) qse_mbstrmx(str,opt)
|
||||
# define qse_strxtrmx(str,len,opt) qse_mbsxtrmx(str,len,opt)
|
||||
# define qse_strtrm(str) qse_mbstrm(str)
|
||||
# define qse_strxtrm(str,len) qse_mbsxtrm(str,len)
|
||||
#else
|
||||
# define qse_strtrmx(str,opt) qse_wcstrmx(str,opt)
|
||||
# define qse_strxtrmx(str,len,opt) qse_wcsxtrmx(str,len,opt)
|
||||
# define qse_strtrm(str) qse_wcstrm(str)
|
||||
# define qse_strxtrm(str,len) qse_wcsxtrm(str,len)
|
||||
#endif
|
||||
@ -2236,7 +2250,7 @@ qse_size_t qse_wcsxpac (
|
||||
qse_size_t len /**< length */
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strpac(str) qse_mbspac(str)
|
||||
# define qse_strxpac(str,len) qse_mbsxpac(str,len)
|
||||
#else
|
||||
@ -2300,7 +2314,7 @@ int qse_wcsxnfnmat (
|
||||
int flags
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_strfnmat(str,ptn,flags) qse_mbsfnmat(str,ptn,flags)
|
||||
# define qse_strxfnmat(str,slen,ptn,flags) qse_mbsxfnmat(str,slen,ptn,flags)
|
||||
# define qse_strnfnmat(str,ptn,plen,flags) qse_mbsnfnmat(str,ptn,plen,flags)
|
||||
@ -2671,7 +2685,7 @@ qse_size_t qse_wcs_pac (
|
||||
qse_wcs_t* str
|
||||
);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_str_setmmgr(str,mmgr) qse_mbs_wetmmgr(str,mmgr)
|
||||
# define qse_str_getmmgr(str) qse_mbs_getmmgr(str)
|
||||
# define qse_str_open(mmgr,ext,capa) qse_mbs_open(mmgr,ext,capa)
|
||||
|
@ -5566,7 +5566,7 @@ static int get_string (
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_charstr (qse_awk_t* awk, qse_awk_tok_t* tok)
|
||||
static int get_charstr (qse_awk_t* awk, qse_awk_tok_t* tok, qse_char_t c)
|
||||
{
|
||||
if (awk->sio.last.c != QSE_T('\"'))
|
||||
{
|
||||
@ -5961,10 +5961,11 @@ retry:
|
||||
type = classify_ident (awk, QSE_STR_CSTR(tok->name));
|
||||
SET_TOKEN_TYPE (awk, tok, type);
|
||||
}
|
||||
else if (c == QSE_T('\"'))
|
||||
else if (c == QSE_T('\"') || c == QSE_T('\''))
|
||||
{
|
||||
SET_TOKEN_TYPE (awk, tok, TOK_STR);
|
||||
if (get_charstr(awk, tok) <= -1) return -1;
|
||||
/*if (get_charstr(awk, tok, c) <= -1) return -1;*/
|
||||
if (get_string (awk, c, QSE_T('\\'), 0, 0, tok) <= -1) return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -274,6 +274,29 @@ void qse_freenwifcfg (qse_nwifcfg_t* cfg)
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__linux)
|
||||
static void read_proc_net_if_inet6 (qse_nwifcfg_t* cfg, struct ifreq* ifr)
|
||||
{
|
||||
#if 0
|
||||
qse_sio_t* sio;
|
||||
qse_mchar_t line[128];
|
||||
|
||||
/* TODO */
|
||||
sio = qse_sio_open (QSE_MMGR_GETDFL(), 0,
|
||||
QSE_T("proc/net/if_inet6"), QSE_SIO_IGNOREMBWCERR | QSE_SIO_READ);
|
||||
if (sio)
|
||||
{
|
||||
qse_ssize_t x;
|
||||
while (1)
|
||||
{
|
||||
x = qse_sio_getmbs (sio, line, QSE_COUNTOF(line));
|
||||
if (x == -1) break;
|
||||
}
|
||||
qse_sio_close (sio);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static int get_nwifcfg (int s, qse_nwifcfg_t* cfg, struct ifreq* ifr)
|
||||
{
|
||||
@ -492,6 +515,15 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg, struct ifreq* ifr)
|
||||
if (ioctl (s, SIOCGIFNETMASK, ifr) >= 0)
|
||||
qse_skadtonwad (&ifr->ifr_addr, &cfg->mask);
|
||||
|
||||
#if defined(__linux)
|
||||
if (cfg->addr.type == QSE_NWAD_NX && cfg->mask.type == QSE_NWAD_NX)
|
||||
{
|
||||
/* access /proc/net/if_inet6 */
|
||||
read_proc_net_if_inet6 (cfg, ifr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if ((cfg->flags & QSE_NWIFCFG_BCAST) &&
|
||||
ioctl (s, SIOCGIFBRDADDR, ifr) >= 0)
|
||||
{
|
||||
@ -589,6 +621,9 @@ for (i = 0; i < drvinfo.n_stats; i++)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* TOOD: consider how to handle multiple IPv6 addresses on a single interfce.
|
||||
* consider how to get IPv4 addresses on an aliased interface? so mutliple ipv4 addresses */
|
||||
|
||||
int qse_getnwifcfg (qse_nwifcfg_t* cfg)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
|
@ -25,9 +25,12 @@
|
||||
qse_mchar_t* qse_mbstrmx (qse_mchar_t* str, int opt)
|
||||
{
|
||||
qse_mchar_t* p = str;
|
||||
|
||||
if (*p != QSE_MT('\0'))
|
||||
{
|
||||
qse_mchar_t* s = QSE_NULL, * e = QSE_NULL;
|
||||
|
||||
while (*p != QSE_MT('\0'))
|
||||
do
|
||||
{
|
||||
if (!QSE_ISMSPACE(*p))
|
||||
{
|
||||
@ -36,13 +39,148 @@ qse_mchar_t* qse_mbstrmx (qse_mchar_t* str, int opt)
|
||||
}
|
||||
p++;
|
||||
}
|
||||
while (*p != QSE_MT('\0'));
|
||||
|
||||
|
||||
if (e)
|
||||
{
|
||||
if (opt & QSE_MBSTRMX_RIGHT) e[1] = QSE_MT('\0');
|
||||
if (opt & QSE_MBSTRMX_LEFT) str = s;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the entire string need to ne deleted */
|
||||
if ((opt & QSE_MBSTRMX_RIGHT) ||
|
||||
(opt && QSE_MBSTRMX_LEFT)) str[0] = QSE_MT('\0');
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_mbsxtrmx (qse_mchar_t* str, qse_size_t* len, int opt)
|
||||
{
|
||||
qse_mchar_t* p = str, * end = str + *len;
|
||||
|
||||
if (p < end)
|
||||
{
|
||||
qse_mchar_t* s = QSE_NULL, * e = QSE_NULL;
|
||||
|
||||
do
|
||||
{
|
||||
if (!QSE_ISMSPACE(*p))
|
||||
{
|
||||
if (s == QSE_NULL) s = p;
|
||||
e = p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
while (p < end);
|
||||
|
||||
if (e)
|
||||
{
|
||||
if (opt & QSE_MBSTRMX_RIGHT)
|
||||
{
|
||||
*len -= end - e - 1;
|
||||
}
|
||||
if (opt & QSE_MBSTRMX_LEFT)
|
||||
{
|
||||
*len -= s - str;
|
||||
str = s;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the entire string need to ne deleted */
|
||||
if ((opt & QSE_MBSTRMX_RIGHT) ||
|
||||
(opt && QSE_MBSTRMX_LEFT)) *len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
qse_wchar_t* qse_wcstrmx (qse_wchar_t* str, int opt)
|
||||
{
|
||||
qse_wchar_t* p = str;
|
||||
|
||||
if (*p != QSE_MT('\0'))
|
||||
{
|
||||
qse_wchar_t* s = QSE_NULL, * e = QSE_NULL;
|
||||
|
||||
do
|
||||
{
|
||||
if (!QSE_ISWSPACE(*p))
|
||||
{
|
||||
if (s == QSE_NULL) s = p;
|
||||
e = p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
while (*p != QSE_MT('\0'));
|
||||
|
||||
|
||||
if (e)
|
||||
{
|
||||
if (opt & QSE_WCSTRMX_RIGHT) e[1] = QSE_MT('\0');
|
||||
if (opt & QSE_WCSTRMX_LEFT) str = s;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the entire string need to ne deleted */
|
||||
if ((opt & QSE_WCSTRMX_RIGHT) ||
|
||||
(opt && QSE_WCSTRMX_LEFT)) str[0] = QSE_MT('\0');
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_wcsxtrmx (qse_wchar_t* str, qse_size_t* len, int opt)
|
||||
{
|
||||
qse_wchar_t* p = str, * end = str + *len;
|
||||
|
||||
if (p < end)
|
||||
{
|
||||
qse_wchar_t* s = QSE_NULL, * e = QSE_NULL;
|
||||
|
||||
do
|
||||
{
|
||||
if (!QSE_ISWSPACE(*p))
|
||||
{
|
||||
if (s == QSE_NULL) s = p;
|
||||
e = p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
while (p < end);
|
||||
|
||||
if (e)
|
||||
{
|
||||
if (opt & QSE_WCSTRMX_RIGHT)
|
||||
{
|
||||
*len -= end - e - 1;
|
||||
}
|
||||
if (opt & QSE_WCSTRMX_LEFT)
|
||||
{
|
||||
*len -= s - str;
|
||||
str = s;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the entire string need to ne deleted */
|
||||
if ((opt & QSE_WCSTRMX_RIGHT) ||
|
||||
(opt && QSE_WCSTRMX_LEFT)) *len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
qse_size_t qse_mbstrm (qse_mchar_t* str)
|
||||
{
|
||||
qse_mchar_t* p = str;
|
||||
@ -58,7 +196,7 @@ qse_size_t qse_mbstrm (qse_mchar_t* str)
|
||||
p++;
|
||||
}
|
||||
|
||||
if (e != QSE_NULL)
|
||||
if (e)
|
||||
{
|
||||
e[1] = QSE_MT('\0');
|
||||
if (str != s)
|
||||
@ -99,27 +237,6 @@ qse_size_t qse_mbsxtrm (qse_mchar_t* str, qse_size_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_wcstrmx (qse_wchar_t* str, int opt)
|
||||
{
|
||||
qse_wchar_t* p = str;
|
||||
qse_wchar_t* s = QSE_NULL, * e = QSE_NULL;
|
||||
|
||||
while (*p != QSE_MT('\0'))
|
||||
{
|
||||
if (!QSE_ISWSPACE(*p))
|
||||
{
|
||||
if (s == QSE_NULL) s = p;
|
||||
e = p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
if (opt & QSE_WCSTRMX_RIGHT) e[1] = QSE_MT('\0');
|
||||
if (opt & QSE_WCSTRMX_LEFT) str = s;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcstrm (qse_wchar_t* str)
|
||||
{
|
||||
qse_wchar_t* p = str;
|
||||
@ -135,7 +252,7 @@ qse_size_t qse_wcstrm (qse_wchar_t* str)
|
||||
p++;
|
||||
}
|
||||
|
||||
if (e != QSE_NULL)
|
||||
if (e)
|
||||
{
|
||||
e[1] = QSE_MT('\0');
|
||||
if (str != s)
|
||||
|
@ -15,6 +15,11 @@ libqseawk_sys_la_SOURCES = sys.c
|
||||
libqseawk_sys_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libqseawk_sys_la_LIBADD = $(LIBADD_COMMON)
|
||||
|
||||
mod_LTLIBRARIES += libqseawk-str.la
|
||||
libqseawk_str_la_SOURCES = str.c
|
||||
libqseawk_str_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libqseawk_str_la_LIBADD = $(LIBADD_COMMON)
|
||||
|
||||
mod_LTLIBRARIES += libqseawk-dir.la
|
||||
libqseawk_dir_la_SOURCES = dir.c
|
||||
libqseawk_dir_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
|
@ -97,6 +97,12 @@ libqseawk_mpi_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libqseawk_mpi_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@HAVE_C_MPI_TRUE@am_libqseawk_mpi_la_rpath = -rpath $(moddir)
|
||||
libqseawk_str_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_libqseawk_str_la_OBJECTS = str.lo
|
||||
libqseawk_str_la_OBJECTS = $(am_libqseawk_str_la_OBJECTS)
|
||||
libqseawk_str_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libqseawk_str_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
libqseawk_sys_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_libqseawk_sys_la_OBJECTS = sys.lo
|
||||
libqseawk_sys_la_OBJECTS = $(am_libqseawk_sys_la_OBJECTS)
|
||||
@ -126,10 +132,11 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(libqseawk_dir_la_SOURCES) $(libqseawk_mpi_la_SOURCES) \
|
||||
$(libqseawk_sys_la_SOURCES) $(libqseawk_uci_la_SOURCES)
|
||||
$(libqseawk_str_la_SOURCES) $(libqseawk_sys_la_SOURCES) \
|
||||
$(libqseawk_uci_la_SOURCES)
|
||||
DIST_SOURCES = $(libqseawk_dir_la_SOURCES) \
|
||||
$(am__libqseawk_mpi_la_SOURCES_DIST) \
|
||||
$(libqseawk_sys_la_SOURCES) \
|
||||
$(libqseawk_str_la_SOURCES) $(libqseawk_sys_la_SOURCES) \
|
||||
$(am__libqseawk_uci_la_SOURCES_DIST)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
@ -314,11 +321,14 @@ AM_CPPFLAGS = \
|
||||
LDFLAGS_COMMON = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../lib/awk -L$(libdir) -no-undefined -version-info 1:0:0
|
||||
LIBADD_COMMON = -lqseawk -lqsecmn
|
||||
moddir = $(libdir)
|
||||
mod_LTLIBRARIES = libqseawk-sys.la libqseawk-dir.la $(am__append_1) \
|
||||
$(am__append_2)
|
||||
mod_LTLIBRARIES = libqseawk-sys.la libqseawk-str.la libqseawk-dir.la \
|
||||
$(am__append_1) $(am__append_2)
|
||||
libqseawk_sys_la_SOURCES = sys.c
|
||||
libqseawk_sys_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libqseawk_sys_la_LIBADD = $(LIBADD_COMMON)
|
||||
libqseawk_str_la_SOURCES = str.c
|
||||
libqseawk_str_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libqseawk_str_la_LIBADD = $(LIBADD_COMMON)
|
||||
libqseawk_dir_la_SOURCES = dir.c
|
||||
libqseawk_dir_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libqseawk_dir_la_LIBADD = $(LIBADD_COMMON)
|
||||
@ -398,6 +408,8 @@ libqseawk-dir.la: $(libqseawk_dir_la_OBJECTS) $(libqseawk_dir_la_DEPENDENCIES) $
|
||||
$(libqseawk_dir_la_LINK) -rpath $(moddir) $(libqseawk_dir_la_OBJECTS) $(libqseawk_dir_la_LIBADD) $(LIBS)
|
||||
libqseawk-mpi.la: $(libqseawk_mpi_la_OBJECTS) $(libqseawk_mpi_la_DEPENDENCIES) $(EXTRA_libqseawk_mpi_la_DEPENDENCIES)
|
||||
$(libqseawk_mpi_la_LINK) $(am_libqseawk_mpi_la_rpath) $(libqseawk_mpi_la_OBJECTS) $(libqseawk_mpi_la_LIBADD) $(LIBS)
|
||||
libqseawk-str.la: $(libqseawk_str_la_OBJECTS) $(libqseawk_str_la_DEPENDENCIES) $(EXTRA_libqseawk_str_la_DEPENDENCIES)
|
||||
$(libqseawk_str_la_LINK) -rpath $(moddir) $(libqseawk_str_la_OBJECTS) $(libqseawk_str_la_LIBADD) $(LIBS)
|
||||
libqseawk-sys.la: $(libqseawk_sys_la_OBJECTS) $(libqseawk_sys_la_DEPENDENCIES) $(EXTRA_libqseawk_sys_la_DEPENDENCIES)
|
||||
$(libqseawk_sys_la_LINK) -rpath $(moddir) $(libqseawk_sys_la_OBJECTS) $(libqseawk_sys_la_LIBADD) $(LIBS)
|
||||
libqseawk-uci.la: $(libqseawk_uci_la_OBJECTS) $(libqseawk_uci_la_DEPENDENCIES) $(EXTRA_libqseawk_uci_la_DEPENDENCIES)
|
||||
@ -411,6 +423,7 @@ distclean-compile:
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dir.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqseawk_mpi_la-mpi.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sys.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uci.Plo@am__quote@
|
||||
|
||||
|
158
qse/mod/awk/str.c
Normal file
158
qse/mod/awk/str.c
Normal file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright 2006-2012 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
|
||||
QSE is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
QSE is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <qse/awk/awk.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include "../../lib/cmn/mem.h"
|
||||
|
||||
static int trim (qse_awk_rtx_t* rtx, int flags)
|
||||
{
|
||||
qse_xstr_t path;
|
||||
qse_char_t* npath;
|
||||
qse_awk_val_t* retv;
|
||||
|
||||
path.ptr = qse_awk_rtx_valtostrdup (
|
||||
rtx, qse_awk_rtx_getarg(rtx, 0), &path.len);
|
||||
if (path.ptr)
|
||||
{
|
||||
npath = qse_strxtrmx (path.ptr, &path.len, flags);
|
||||
|
||||
retv = qse_awk_rtx_makestrval (rtx, npath, path.len);
|
||||
qse_awk_rtx_freemem (rtx, path.ptr);
|
||||
if (retv == QSE_NULL) return -1;
|
||||
|
||||
qse_awk_rtx_setretval (rtx, retv);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fnc_trim (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
{
|
||||
return trim (rtx, QSE_STRTRMX_LEFT | QSE_STRTRMX_RIGHT);
|
||||
}
|
||||
static int fnc_ltrim (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
{
|
||||
return trim (rtx, QSE_STRTRMX_LEFT);
|
||||
}
|
||||
static int fnc_rtrim (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
{
|
||||
return trim (rtx, QSE_STRTRMX_RIGHT);
|
||||
}
|
||||
|
||||
typedef struct fnctab_t fnctab_t;
|
||||
struct fnctab_t
|
||||
{
|
||||
const qse_char_t* name;
|
||||
qse_awk_mod_sym_fnc_t info;
|
||||
};
|
||||
|
||||
static fnctab_t fnctab[] =
|
||||
{
|
||||
/* keep this table sorted for binary search in query(). */
|
||||
{ QSE_T("ltrim"), { { 1, 1, QSE_NULL }, fnc_ltrim, 0 } },
|
||||
{ QSE_T("rtrim"), { { 1, 1, QSE_NULL }, fnc_rtrim, 0 } },
|
||||
{ QSE_T("trim"), { { 1, 1, QSE_NULL }, fnc_trim, 0 } }
|
||||
};
|
||||
|
||||
static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym)
|
||||
{
|
||||
qse_cstr_t ea;
|
||||
int left, right, mid, n;
|
||||
|
||||
left = 0; right = QSE_COUNTOF(fnctab) - 1;
|
||||
|
||||
while (left <= right)
|
||||
{
|
||||
mid = (left + right) / 2;
|
||||
|
||||
n = qse_strcmp (fnctab[mid].name, name);
|
||||
if (n > 0) right = mid - 1;
|
||||
else if (n < 0) left = mid + 1;
|
||||
else
|
||||
{
|
||||
sym->type = QSE_AWK_MOD_FNC;
|
||||
sym->u.fnc = fnctab[mid].info;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
left = 0; right = QSE_COUNTOF(inttab) - 1;
|
||||
while (left <= right)
|
||||
{
|
||||
mid = (left + right) / 2;
|
||||
|
||||
n = qse_strcmp (inttab[mid].name, name);
|
||||
if (n > 0) right = mid - 1;
|
||||
else if (n < 0) left = mid + 1;
|
||||
else
|
||||
{
|
||||
sym->type = QSE_AWK_MOD_INT;
|
||||
sym->u.in = inttab[mid].info;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
ea.ptr = name;
|
||||
ea.len = qse_strlen(name);
|
||||
qse_awk_seterror (awk, QSE_AWK_ENOENT, &ea, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* TODO: proper resource management */
|
||||
|
||||
static int init (qse_awk_mod_t* mod, qse_awk_rtx_t* rtx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fini (qse_awk_mod_t* mod, qse_awk_rtx_t* rtx)
|
||||
{
|
||||
/* TODO:
|
||||
for (each pid for rtx) kill (pid, SIGKILL);
|
||||
for (each pid for rtx) waitpid (pid, QSE_NULL, 0);
|
||||
*/
|
||||
}
|
||||
|
||||
static void unload (qse_awk_mod_t* mod, qse_awk_t* awk)
|
||||
{
|
||||
/* TODO: anything */
|
||||
}
|
||||
|
||||
QSE_EXPORT int load (qse_awk_mod_t* mod, qse_awk_t* awk)
|
||||
{
|
||||
mod->query = query;
|
||||
mod->unload = unload;
|
||||
|
||||
mod->init = init;
|
||||
mod->fini = fini;
|
||||
/*
|
||||
mod->ctx...
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(__DOS__)
|
||||
/* kind of DllMain() for Causeway DLL */
|
||||
int main (int eax) { return 0; }
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user