enhanced code
- changed qse_strfcpy() and qse_strxfcpy() to accept a string array - removed the data field from qse_awk_prm_t - made relevant changes
This commit is contained in:
parent
c86350bfde
commit
3ab84046b7
@ -64,6 +64,8 @@ public:
|
|||||||
typedef qse_awk_rtx_t run_t;
|
typedef qse_awk_rtx_t run_t;
|
||||||
/** Represents the underlying interpreter */
|
/** Represents the underlying interpreter */
|
||||||
typedef qse_awk_t awk_t;
|
typedef qse_awk_t awk_t;
|
||||||
|
/** Represents the underlying runtime context */
|
||||||
|
typedef qse_awk_rtx_t rtx_t;
|
||||||
|
|
||||||
enum ccls_type_t
|
enum ccls_type_t
|
||||||
{
|
{
|
||||||
@ -793,6 +795,7 @@ protected:
|
|||||||
|
|
||||||
void clearError ();
|
void clearError ();
|
||||||
void retrieveError ();
|
void retrieveError ();
|
||||||
|
void retrieveError (rtx_t* rtx);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -1088,8 +1091,8 @@ protected:
|
|||||||
static bool_t isType (void* data, cint_t c, qse_ccls_type_t type);
|
static bool_t isType (void* data, cint_t c, qse_ccls_type_t type);
|
||||||
static cint_t transCase (void* data, cint_t c, qse_ccls_type_t type);
|
static cint_t transCase (void* data, cint_t c, qse_ccls_type_t type);
|
||||||
|
|
||||||
static real_t pow (void* data, real_t x, real_t y);
|
static real_t pow (awk_t* data, real_t x, real_t y);
|
||||||
static int sprintf (void* data, char_t* buf, size_t size,
|
static int sprintf (awk_t* data, char_t* buf, size_t size,
|
||||||
const char_t* fmt, ...);
|
const char_t* fmt, ...);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -59,13 +59,13 @@ typedef struct qse_awk_rcb_t qse_awk_rcb_t;
|
|||||||
typedef struct qse_awk_rexfns_t qse_awk_rexfns_t;
|
typedef struct qse_awk_rexfns_t qse_awk_rexfns_t;
|
||||||
|
|
||||||
typedef qse_real_t (*qse_awk_pow_t) (
|
typedef qse_real_t (*qse_awk_pow_t) (
|
||||||
void* data,
|
qse_awk_t* awk,
|
||||||
qse_real_t x,
|
qse_real_t x,
|
||||||
qse_real_t y
|
qse_real_t y
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef int (*qse_awk_sprintf_t) (
|
typedef int (*qse_awk_sprintf_t) (
|
||||||
void* data,
|
qse_awk_t* awk,
|
||||||
qse_char_t* buf,
|
qse_char_t* buf,
|
||||||
qse_size_t size,
|
qse_size_t size,
|
||||||
const qse_char_t* fmt,
|
const qse_char_t* fmt,
|
||||||
@ -112,9 +112,6 @@ struct qse_awk_prm_t
|
|||||||
{
|
{
|
||||||
qse_awk_pow_t pow; /* required */
|
qse_awk_pow_t pow; /* required */
|
||||||
qse_awk_sprintf_t sprintf; /* required */
|
qse_awk_sprintf_t sprintf; /* required */
|
||||||
|
|
||||||
/* user-defined data passed to the functions above */
|
|
||||||
void* data; /* optional */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct qse_awk_sio_t
|
struct qse_awk_sio_t
|
||||||
|
@ -177,7 +177,7 @@ qse_size_t qse_strxncpy (
|
|||||||
qse_size_t qse_strfcpy (
|
qse_size_t qse_strfcpy (
|
||||||
qse_char_t* buf,
|
qse_char_t* buf,
|
||||||
const qse_char_t* fmt,
|
const qse_char_t* fmt,
|
||||||
...
|
const qse_char_t* str[]
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ qse_size_t qse_strfcpy (
|
|||||||
qse_size_t qse_strfncpy (
|
qse_size_t qse_strfncpy (
|
||||||
qse_char_t* buf,
|
qse_char_t* buf,
|
||||||
const qse_char_t* fmt,
|
const qse_char_t* fmt,
|
||||||
const qse_cstr_t* str
|
const qse_cstr_t str[]
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ qse_size_t qse_strxfcpy (
|
|||||||
qse_char_t* buf,
|
qse_char_t* buf,
|
||||||
qse_size_t bsz,
|
qse_size_t bsz,
|
||||||
const qse_char_t* fmt,
|
const qse_char_t* fmt,
|
||||||
...
|
const qse_char_t* str[]
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ qse_size_t qse_strxfncpy (
|
|||||||
qse_char_t* buf,
|
qse_char_t* buf,
|
||||||
qse_size_t bsz,
|
qse_size_t bsz,
|
||||||
const qse_char_t* fmt,
|
const qse_char_t* fmt,
|
||||||
const qse_cstr_t* str
|
const qse_cstr_t str[]
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <qse/cmn/str.h>
|
#include <qse/cmn/str.h>
|
||||||
#include "../cmn/mem.h"
|
#include "../cmn/mem.h"
|
||||||
|
|
||||||
|
#include <qse/utl/stdio.h>
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
QSE_BEGIN_NAMESPACE(QSE)
|
QSE_BEGIN_NAMESPACE(QSE)
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
@ -28,6 +29,11 @@ QSE_BEGIN_NAMESPACE(QSE)
|
|||||||
// Awk::Source
|
// Awk::Source
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct xtn_t
|
||||||
|
{
|
||||||
|
Awk* awk;
|
||||||
|
};
|
||||||
|
|
||||||
Awk::Source::Source (Mode mode): mode (mode), handle (QSE_NULL)
|
Awk::Source::Source (Mode mode): mode (mode), handle (QSE_NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -464,7 +470,7 @@ int Awk::Argument::getIndexed (long_t idx, Argument& val) const
|
|||||||
char_t ri[128];
|
char_t ri[128];
|
||||||
|
|
||||||
int rl = Awk::sprintf (
|
int rl = Awk::sprintf (
|
||||||
this->run->awk, ri, QSE_COUNTOF(ri),
|
(awk_t*)this->run->awk, ri, QSE_COUNTOF(ri),
|
||||||
#if QSE_SIZEOF_LONG_LONG > 0
|
#if QSE_SIZEOF_LONG_LONG > 0
|
||||||
QSE_T("%lld"), (long long)idx
|
QSE_T("%lld"), (long long)idx
|
||||||
#elif QSE_SIZEOF___INT64 > 0
|
#elif QSE_SIZEOF___INT64 > 0
|
||||||
@ -811,7 +817,7 @@ int Awk::Return::setIndexed (long_t idx, long_t v)
|
|||||||
char_t ri[128];
|
char_t ri[128];
|
||||||
|
|
||||||
int rl = Awk::sprintf (
|
int rl = Awk::sprintf (
|
||||||
this->run->awk, ri, QSE_COUNTOF(ri),
|
(awk_t*)this->run->awk, ri, QSE_COUNTOF(ri),
|
||||||
#if QSE_SIZEOF_LONG_LONG > 0
|
#if QSE_SIZEOF_LONG_LONG > 0
|
||||||
QSE_T("%lld"), (long long)idx
|
QSE_T("%lld"), (long long)idx
|
||||||
#elif QSE_SIZEOF___INT64 > 0
|
#elif QSE_SIZEOF___INT64 > 0
|
||||||
@ -839,7 +845,7 @@ int Awk::Return::setIndexed (long_t idx, real_t v)
|
|||||||
char_t ri[128];
|
char_t ri[128];
|
||||||
|
|
||||||
int rl = Awk::sprintf (
|
int rl = Awk::sprintf (
|
||||||
this->run->awk, ri, QSE_COUNTOF(ri),
|
(awk_t*)this->run->awk, ri, QSE_COUNTOF(ri),
|
||||||
#if QSE_SIZEOF_LONG_LONG > 0
|
#if QSE_SIZEOF_LONG_LONG > 0
|
||||||
QSE_T("%lld"), (long long)idx
|
QSE_T("%lld"), (long long)idx
|
||||||
#elif QSE_SIZEOF___INT64 > 0
|
#elif QSE_SIZEOF___INT64 > 0
|
||||||
@ -867,7 +873,7 @@ int Awk::Return::setIndexed (long_t idx, const char_t* str, size_t sln)
|
|||||||
char_t ri[128];
|
char_t ri[128];
|
||||||
|
|
||||||
int rl = Awk::sprintf (
|
int rl = Awk::sprintf (
|
||||||
this->run->awk, ri, QSE_COUNTOF(ri),
|
(awk_t*)this->run->awk, ri, QSE_COUNTOF(ri),
|
||||||
#if QSE_SIZEOF_LONG_LONG > 0
|
#if QSE_SIZEOF_LONG_LONG > 0
|
||||||
QSE_T("%lld"), (long long)idx
|
QSE_T("%lld"), (long long)idx
|
||||||
#elif QSE_SIZEOF___INT64 > 0
|
#elif QSE_SIZEOF___INT64 > 0
|
||||||
@ -958,20 +964,20 @@ const Awk::char_t* Awk::Run::getErrorMessage () const
|
|||||||
void Awk::Run::setError (ErrorCode code)
|
void Awk::Run::setError (ErrorCode code)
|
||||||
{
|
{
|
||||||
QSE_ASSERT (this->run != QSE_NULL);
|
QSE_ASSERT (this->run != QSE_NULL);
|
||||||
qse_awk_rtx_seterror (this->run, code, 0, QSE_NULL, 0);
|
qse_awk_rtx_seterror (this->run, code, 0, QSE_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Awk::Run::setError (ErrorCode code, size_t line)
|
void Awk::Run::setError (ErrorCode code, size_t line)
|
||||||
{
|
{
|
||||||
QSE_ASSERT (this->run != QSE_NULL);
|
QSE_ASSERT (this->run != QSE_NULL);
|
||||||
qse_awk_rtx_seterror (this->run, code, line, QSE_NULL, 0);
|
qse_awk_rtx_seterror (this->run, code, line, QSE_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Awk::Run::setError (ErrorCode code, size_t line, const char_t* arg)
|
void Awk::Run::setError (ErrorCode code, size_t line, const char_t* arg)
|
||||||
{
|
{
|
||||||
QSE_ASSERT (this->run != QSE_NULL);
|
QSE_ASSERT (this->run != QSE_NULL);
|
||||||
qse_cstr_t x = { arg, qse_strlen(arg) };
|
qse_cstr_t x = { arg, qse_strlen(arg) };
|
||||||
qse_awk_rtx_seterror (this->run, code, line, &x, 1);
|
qse_awk_rtx_seterror (this->run, code, line, &x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Awk::Run::setError (
|
void Awk::Run::setError (
|
||||||
@ -979,7 +985,7 @@ void Awk::Run::setError (
|
|||||||
{
|
{
|
||||||
QSE_ASSERT (this->run != QSE_NULL);
|
QSE_ASSERT (this->run != QSE_NULL);
|
||||||
qse_cstr_t x = { arg, len };
|
qse_cstr_t x = { arg, len };
|
||||||
qse_awk_rtx_seterror (this->run, code, line, &x, 1);
|
qse_awk_rtx_seterror (this->run, code, line, &x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Awk::Run::setErrorWithMessage (
|
void Awk::Run::setErrorWithMessage (
|
||||||
@ -1075,7 +1081,6 @@ Awk::Awk (): awk (QSE_NULL), functionMap (QSE_NULL),
|
|||||||
|
|
||||||
prm.pow = pow;
|
prm.pow = pow;
|
||||||
prm.sprintf = sprintf;
|
prm.sprintf = sprintf;
|
||||||
prm.data = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Awk::~Awk ()
|
Awk::~Awk ()
|
||||||
@ -1122,7 +1127,7 @@ void Awk::setError (ErrorCode code, size_t line, const char_t* arg, size_t len)
|
|||||||
if (awk != QSE_NULL)
|
if (awk != QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_cstr_t x = { arg, len };
|
qse_cstr_t x = { arg, len };
|
||||||
qse_awk_seterror (awk, code, line, &x, 1);
|
qse_awk_seterror (awk, code, line, &x);
|
||||||
retrieveError ();
|
retrieveError ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1174,21 +1179,34 @@ void Awk::retrieveError ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Awk::retrieveError (rtx_t* rtx)
|
||||||
|
{
|
||||||
|
int num;
|
||||||
|
const char_t* msg;
|
||||||
|
|
||||||
|
qse_awk_rtx_geterror (rtx, &num, &this->errlin, &msg);
|
||||||
|
this->errnum = (ErrorCode)num;
|
||||||
|
qse_strxcpy (this->errmsg, QSE_COUNTOF(this->errmsg), msg);
|
||||||
|
}
|
||||||
|
|
||||||
int Awk::open ()
|
int Awk::open ()
|
||||||
{
|
{
|
||||||
QSE_ASSERT (awk == QSE_NULL && functionMap == QSE_NULL);
|
QSE_ASSERT (awk == QSE_NULL && functionMap == QSE_NULL);
|
||||||
|
|
||||||
awk = qse_awk_open (&mmgr, 0);
|
awk = qse_awk_open (&mmgr, QSE_SIZEOF(xtn_t));
|
||||||
if (awk == QSE_NULL)
|
if (awk == QSE_NULL)
|
||||||
{
|
{
|
||||||
setError (ERR_NOMEM);
|
setError (ERR_NOMEM);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// associate this Awk object with the underlying awk object
|
||||||
|
xtn_t* xtn = (xtn_t*)qse_awk_getxtn (awk);
|
||||||
|
xtn->awk = this;
|
||||||
|
|
||||||
qse_awk_setccls (awk, &ccls);
|
qse_awk_setccls (awk, &ccls);
|
||||||
qse_awk_setprm (awk, &prm);
|
qse_awk_setprm (awk, &prm);
|
||||||
|
|
||||||
|
|
||||||
//functionMap = qse_map_open (
|
//functionMap = qse_map_open (
|
||||||
// this, 512, 70, freeFunctionMapValue, QSE_NULL,
|
// this, 512, 70, freeFunctionMapValue, QSE_NULL,
|
||||||
// qse_awk_getmmgr(awk));
|
// qse_awk_getmmgr(awk));
|
||||||
@ -1386,7 +1404,7 @@ int Awk::run (const char_t** args, size_t nargs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
qse_awk_rtx_t* rtx = qse_awk_rtx_open (
|
rtx_t* rtx = qse_awk_rtx_open (
|
||||||
awk, QSE_SIZEOF(Run*), &rio,
|
awk, QSE_SIZEOF(Run*), &rio,
|
||||||
(qse_cstr_t*)runarg
|
(qse_cstr_t*)runarg
|
||||||
);
|
);
|
||||||
@ -1402,7 +1420,7 @@ int Awk::run (const char_t** args, size_t nargs)
|
|||||||
|
|
||||||
if (runCallback) qse_awk_rtx_setrcb (rtx, &rcb);
|
if (runCallback) qse_awk_rtx_setrcb (rtx, &rcb);
|
||||||
n = qse_awk_rtx_loop (rtx);
|
n = qse_awk_rtx_loop (rtx);
|
||||||
if (n == -1) retrieveError ();
|
if (n == -1) retrieveError (rtx);
|
||||||
qse_awk_rtx_close (rtx);
|
qse_awk_rtx_close (rtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1799,17 +1817,20 @@ Awk::cint_t Awk::transCase (void* data, cint_t c, qse_ccls_type_t type)
|
|||||||
return ((Awk*)data)->transCase (c, (ccls_type_t)type);
|
return ((Awk*)data)->transCase (c, (ccls_type_t)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
Awk::real_t Awk::pow (void* data, real_t x, real_t y)
|
Awk::real_t Awk::pow (awk_t* awk, real_t x, real_t y)
|
||||||
{
|
{
|
||||||
return ((Awk*)data)->pow (x, y);
|
xtn_t* xtn = (xtn_t*) qse_awk_getxtn (awk);
|
||||||
|
return xtn->awk->pow (x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Awk::sprintf (void* data, char_t* buf, size_t size,
|
int Awk::sprintf (awk_t* awk, char_t* buf, size_t size,
|
||||||
const char_t* fmt, ...)
|
const char_t* fmt, ...)
|
||||||
{
|
{
|
||||||
|
xtn_t* xtn = (xtn_t*) qse_awk_getxtn (awk);
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start (ap, fmt);
|
va_start (ap, fmt);
|
||||||
int n = ((Awk*)data)->vsprintf (buf, size, fmt, ap);
|
int n = xtn->awk->vsprintf (buf, size, fmt, ap);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -342,14 +342,14 @@ void qse_awk_setccls (qse_awk_t* awk, qse_ccls_t* ccls)
|
|||||||
|
|
||||||
qse_awk_prm_t* qse_awk_getprm (qse_awk_t* awk)
|
qse_awk_prm_t* qse_awk_getprm (qse_awk_t* awk)
|
||||||
{
|
{
|
||||||
return awk->prm;
|
return &awk->prm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qse_awk_setprm (qse_awk_t* awk, qse_awk_prm_t* prm)
|
void qse_awk_setprm (qse_awk_t* awk, qse_awk_prm_t* prm)
|
||||||
{
|
{
|
||||||
QSE_ASSERT (prm->pow != QSE_NULL);
|
QSE_ASSERT (prm->pow != QSE_NULL);
|
||||||
QSE_ASSERT (prm->sprintf != QSE_NULL);
|
QSE_ASSERT (prm->sprintf != QSE_NULL);
|
||||||
awk->prm = prm;
|
awk->prm = *prm;
|
||||||
}
|
}
|
||||||
|
|
||||||
int qse_awk_getoption (qse_awk_t* awk)
|
int qse_awk_getoption (qse_awk_t* awk)
|
||||||
|
@ -87,7 +87,7 @@ struct qse_awk_t
|
|||||||
{
|
{
|
||||||
qse_mmgr_t* mmgr;
|
qse_mmgr_t* mmgr;
|
||||||
qse_ccls_t* ccls;
|
qse_ccls_t* ccls;
|
||||||
qse_awk_prm_t* prm;
|
qse_awk_prm_t prm;
|
||||||
|
|
||||||
/* options */
|
/* options */
|
||||||
int option;
|
int option;
|
||||||
|
@ -470,7 +470,6 @@ int qse_awk_parse (qse_awk_t* awk, qse_awk_sio_t* sio)
|
|||||||
int n;
|
int n;
|
||||||
|
|
||||||
QSE_ASSERTX (awk->ccls != QSE_NULL, "Call qse_setccls() first");
|
QSE_ASSERTX (awk->ccls != QSE_NULL, "Call qse_setccls() first");
|
||||||
QSE_ASSERTX (awk->prm != QSE_NULL, "Call qse_setprm() first");
|
|
||||||
|
|
||||||
QSE_ASSERTX (
|
QSE_ASSERTX (
|
||||||
sio != QSE_NULL && sio->in != QSE_NULL,
|
sio != QSE_NULL && sio->in != QSE_NULL,
|
||||||
|
@ -642,7 +642,8 @@ qse_awk_rtx_t* qse_awk_rtx_open (
|
|||||||
qse_awk_rtx_t* rtx;
|
qse_awk_rtx_t* rtx;
|
||||||
|
|
||||||
QSE_ASSERTX (awk->ccls != QSE_NULL, "Call qse_awk_setccls() first");
|
QSE_ASSERTX (awk->ccls != QSE_NULL, "Call qse_awk_setccls() first");
|
||||||
QSE_ASSERTX (awk->prm != QSE_NULL, "Call qse_awk_setprm() first");
|
QSE_ASSERTX (awk->prm.pow != QSE_NULL, "Call qse_awk_setprm() first");
|
||||||
|
QSE_ASSERTX (awk->prm.sprintf != QSE_NULL, "Call qse_awk_setprm() first");
|
||||||
|
|
||||||
/* clear the awk error code */
|
/* clear the awk error code */
|
||||||
qse_awk_seterror (awk, QSE_AWK_ENOERR, 0, QSE_NULL);
|
qse_awk_seterror (awk, QSE_AWK_ENOERR, 0, QSE_NULL);
|
||||||
@ -4536,7 +4537,7 @@ static qse_awk_val_t* eval_binop_exp (
|
|||||||
qse_real_t r1, r2;
|
qse_real_t r1, r2;
|
||||||
qse_awk_val_t* res;
|
qse_awk_val_t* res;
|
||||||
|
|
||||||
QSE_ASSERTX (run->awk->prm->pow != QSE_NULL,
|
QSE_ASSERTX (run->awk->prm.pow != QSE_NULL,
|
||||||
"the pow function should be provided when the awk object is created to make the exponentiation work properly.");
|
"the pow function should be provided when the awk object is created to make the exponentiation work properly.");
|
||||||
|
|
||||||
n1 = qse_awk_rtx_valtonum (run, left, &l1, &r1);
|
n1 = qse_awk_rtx_valtonum (run, left, &l1, &r1);
|
||||||
@ -4597,18 +4598,20 @@ static qse_awk_val_t* eval_binop_exp (
|
|||||||
{
|
{
|
||||||
/* left - int, right - real */
|
/* left - int, right - real */
|
||||||
res = qse_awk_rtx_makerealval (run,
|
res = qse_awk_rtx_makerealval (run,
|
||||||
run->awk->prm->pow (
|
run->awk->prm.pow (
|
||||||
run->awk->prm->data,
|
run->awk, (qse_real_t)l1, (qse_real_t)r2
|
||||||
(qse_real_t)l1,(qse_real_t)r2));
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* left - real, right - real */
|
/* left - real, right - real */
|
||||||
QSE_ASSERT (n3 == 3);
|
QSE_ASSERT (n3 == 3);
|
||||||
res = qse_awk_rtx_makerealval (run,
|
res = qse_awk_rtx_makerealval (run,
|
||||||
run->awk->prm->pow(
|
run->awk->prm.pow (
|
||||||
run->awk->prm->data,
|
run->awk, (qse_real_t)r1,(qse_real_t)r2
|
||||||
(qse_real_t)r1,(qse_real_t)r2));
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -6729,8 +6732,8 @@ qse_char_t* qse_awk_rtx_format (
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
n = run->awk->prm->sprintf (
|
n = run->awk->prm.sprintf (
|
||||||
run->awk->prm->data,
|
run->awk,
|
||||||
run->format.tmp.ptr,
|
run->format.tmp.ptr,
|
||||||
run->format.tmp.len,
|
run->format.tmp.len,
|
||||||
#if QSE_SIZEOF_LONG_LONG > 0
|
#if QSE_SIZEOF_LONG_LONG > 0
|
||||||
@ -6835,8 +6838,8 @@ qse_char_t* qse_awk_rtx_format (
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
n = run->awk->prm->sprintf (
|
n = run->awk->prm.sprintf (
|
||||||
run->awk->prm->data,
|
run->awk,
|
||||||
run->format.tmp.ptr,
|
run->format.tmp.ptr,
|
||||||
run->format.tmp.len,
|
run->format.tmp.len,
|
||||||
#if QSE_SIZEOF_LONG_LONG > 0
|
#if QSE_SIZEOF_LONG_LONG > 0
|
||||||
@ -6956,8 +6959,8 @@ qse_char_t* qse_awk_rtx_format (
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
n = run->awk->prm->sprintf (
|
n = run->awk->prm.sprintf (
|
||||||
run->awk->prm->data,
|
run->awk,
|
||||||
run->format.tmp.ptr,
|
run->format.tmp.ptr,
|
||||||
run->format.tmp.len,
|
run->format.tmp.len,
|
||||||
QSE_STR_PTR(fbu),
|
QSE_STR_PTR(fbu),
|
||||||
@ -7044,8 +7047,8 @@ qse_char_t* qse_awk_rtx_format (
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
n = run->awk->prm->sprintf (
|
n = run->awk->prm.sprintf (
|
||||||
run->awk->prm->data,
|
run->awk,
|
||||||
run->format.tmp.ptr,
|
run->format.tmp.ptr,
|
||||||
run->format.tmp.len,
|
run->format.tmp.len,
|
||||||
QSE_STR_PTR(fbu),
|
QSE_STR_PTR(fbu),
|
||||||
|
@ -88,7 +88,6 @@ qse_awk_t* qse_awk_opensimple (void)
|
|||||||
|
|
||||||
x->prm.pow = custom_awk_pow;
|
x->prm.pow = custom_awk_pow;
|
||||||
x->prm.sprintf = custom_awk_sprintf;
|
x->prm.sprintf = custom_awk_sprintf;
|
||||||
x->prm.data = QSE_NULL;
|
|
||||||
qse_awk_setprm (awk, &x->prm);
|
qse_awk_setprm (awk, &x->prm);
|
||||||
|
|
||||||
qse_awk_setoption (awk,
|
qse_awk_setoption (awk,
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <qse/cmn/str.h>
|
#include <qse/cmn/str.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include "chr.h"
|
#include "chr.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
|
||||||
@ -107,7 +106,8 @@ qse_size_t qse_strxncpy (
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_size_t qse_strfcpy (qse_char_t* buf, const qse_char_t* fmt, ...)
|
qse_size_t qse_strfcpy (
|
||||||
|
qse_char_t* buf, const qse_char_t* fmt, const qse_char_t* str[])
|
||||||
{
|
{
|
||||||
qse_char_t* b = buf;
|
qse_char_t* b = buf;
|
||||||
const qse_char_t* f = fmt;
|
const qse_char_t* f = fmt;
|
||||||
@ -119,7 +119,6 @@ qse_size_t qse_strfcpy (qse_char_t* buf, const qse_char_t* fmt, ...)
|
|||||||
if (f[1] == QSE_T('{') &&
|
if (f[1] == QSE_T('{') &&
|
||||||
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
|
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
|
||||||
{
|
{
|
||||||
va_list ap;
|
|
||||||
const qse_char_t* tmp;
|
const qse_char_t* tmp;
|
||||||
qse_size_t idx = 0;
|
qse_size_t idx = 0;
|
||||||
|
|
||||||
@ -137,14 +136,7 @@ qse_size_t qse_strfcpy (qse_char_t* buf, const qse_char_t* fmt, ...)
|
|||||||
|
|
||||||
f++;
|
f++;
|
||||||
|
|
||||||
/* TODO: some optimization in getting the argument */
|
tmp = str[idx];
|
||||||
va_start (ap, fmt);
|
|
||||||
|
|
||||||
do tmp = va_arg(ap,const qse_char_t*);
|
|
||||||
while (idx-- > 0);
|
|
||||||
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
while (*tmp != QSE_T('\0')) *b++ = *tmp++;
|
while (*tmp != QSE_T('\0')) *b++ = *tmp++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -159,7 +151,8 @@ qse_size_t qse_strfcpy (qse_char_t* buf, const qse_char_t* fmt, ...)
|
|||||||
return b - buf;
|
return b - buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_size_t qse_strfncpy (qse_char_t* buf, const qse_char_t* fmt, const qse_cstr_t* str)
|
qse_size_t qse_strfncpy (
|
||||||
|
qse_char_t* buf, const qse_char_t* fmt, const qse_cstr_t str[])
|
||||||
{
|
{
|
||||||
qse_char_t* b = buf;
|
qse_char_t* b = buf;
|
||||||
const qse_char_t* f = fmt;
|
const qse_char_t* f = fmt;
|
||||||
@ -206,7 +199,8 @@ qse_size_t qse_strfncpy (qse_char_t* buf, const qse_char_t* fmt, const qse_cstr_
|
|||||||
}
|
}
|
||||||
|
|
||||||
qse_size_t qse_strxfcpy (
|
qse_size_t qse_strxfcpy (
|
||||||
qse_char_t* buf, qse_size_t bsz, const qse_char_t* fmt, ...)
|
qse_char_t* buf, qse_size_t bsz,
|
||||||
|
const qse_char_t* fmt, const qse_char_t* str[])
|
||||||
{
|
{
|
||||||
qse_char_t* b = buf;
|
qse_char_t* b = buf;
|
||||||
qse_char_t* end = buf + bsz - 1;
|
qse_char_t* end = buf + bsz - 1;
|
||||||
@ -221,7 +215,6 @@ qse_size_t qse_strxfcpy (
|
|||||||
if (f[1] == QSE_T('{') &&
|
if (f[1] == QSE_T('{') &&
|
||||||
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
|
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
|
||||||
{
|
{
|
||||||
va_list ap;
|
|
||||||
const qse_char_t* tmp;
|
const qse_char_t* tmp;
|
||||||
qse_size_t idx = 0;
|
qse_size_t idx = 0;
|
||||||
|
|
||||||
@ -239,14 +232,7 @@ qse_size_t qse_strxfcpy (
|
|||||||
|
|
||||||
f++;
|
f++;
|
||||||
|
|
||||||
/* TODO: some optimization in getting the argument */
|
tmp = str[idx];
|
||||||
va_start (ap, fmt);
|
|
||||||
|
|
||||||
do tmp = va_arg(ap,const qse_char_t*);
|
|
||||||
while (idx-- > 0);
|
|
||||||
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
while (*tmp != QSE_T('\0'))
|
while (*tmp != QSE_T('\0'))
|
||||||
{
|
{
|
||||||
if (b >= end) goto fini;
|
if (b >= end) goto fini;
|
||||||
@ -269,7 +255,7 @@ fini:
|
|||||||
|
|
||||||
qse_size_t qse_strxfncpy (
|
qse_size_t qse_strxfncpy (
|
||||||
qse_char_t* buf, qse_size_t bsz,
|
qse_char_t* buf, qse_size_t bsz,
|
||||||
const qse_char_t* fmt, const qse_cstr_t* str)
|
const qse_char_t* fmt, const qse_cstr_t str[])
|
||||||
{
|
{
|
||||||
qse_char_t* b = buf;
|
qse_char_t* b = buf;
|
||||||
qse_char_t* end = buf + bsz - 1;
|
qse_char_t* end = buf + bsz - 1;
|
||||||
|
@ -418,36 +418,48 @@ static int test9 (void)
|
|||||||
static int test10 (void)
|
static int test10 (void)
|
||||||
{
|
{
|
||||||
qse_char_t buf[1000];
|
qse_char_t buf[1000];
|
||||||
qse_strfcpy (buf, QSE_T("${2}${1}${0}"),
|
const qse_char_t* arg3[] =
|
||||||
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
|
{
|
||||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
QSE_T("00000"),
|
||||||
qse_strfcpy (buf, QSE_T("${2}/${1}/${0}"),
|
QSE_T("11111"),
|
||||||
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
|
QSE_T("22222")
|
||||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
};
|
||||||
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/"),
|
|
||||||
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
|
const qse_char_t* arg12[] =
|
||||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
{
|
||||||
qse_strfcpy (buf, QSE_T("/$${2}/$${1}/$${0}/"),
|
|
||||||
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
|
|
||||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
|
||||||
qse_strfcpy (buf, QSE_T("/${2/${1}/${0}/"),
|
|
||||||
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
|
|
||||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
|
||||||
qse_strfcpy (buf, QSE_T("/$2}/${1}/${0}/"),
|
|
||||||
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
|
|
||||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
|
||||||
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/${3}/${4}/${5}/${6}/${7}/${8}/${9}/${10}/${11}/"),
|
|
||||||
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"),
|
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"),
|
||||||
QSE_T("33333"), QSE_T("44444"), QSE_T("55555"),
|
QSE_T("33333"), QSE_T("44444"), QSE_T("55555"),
|
||||||
QSE_T("66666"), QSE_T("77777"), QSE_T("88888"),
|
QSE_T("66666"), QSE_T("77777"), QSE_T("88888"),
|
||||||
QSE_T("99999"), QSE_T("aaaaa"), QSE_T("bbbbb"));
|
QSE_T("99999"), QSE_T("aaaaa"), QSE_T("bbbbb")
|
||||||
|
};
|
||||||
|
|
||||||
|
qse_strfcpy (buf, QSE_T("${2}${1}${0}"), arg3);
|
||||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||||
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/${2}/${1}/${0}/"),
|
|
||||||
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
|
qse_strfcpy (buf, QSE_T("${2}/${1}/${0}"), arg3);
|
||||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||||
qse_strfcpy (buf, QSE_T("/${002}/${001}/${000}/"),
|
|
||||||
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
|
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/"), arg3);
|
||||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||||
|
|
||||||
|
qse_strfcpy (buf, QSE_T("/$${2}/$${1}/$${0}/"), arg3);
|
||||||
|
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||||
|
|
||||||
|
qse_strfcpy (buf, QSE_T("/${2/${1}/${0}/"), arg3);
|
||||||
|
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||||
|
|
||||||
|
qse_strfcpy (buf, QSE_T("/$2}/${1}/${0}/"), arg3);
|
||||||
|
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||||
|
|
||||||
|
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/${3}/${4}/${5}/${6}/${7}/${8}/${9}/${10}/${11}/"), arg12);
|
||||||
|
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||||
|
|
||||||
|
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/${0}/${1}/${2}/"), arg3);
|
||||||
|
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||||
|
|
||||||
|
qse_strfcpy (buf, QSE_T("/${002}/${001}/${000}/"), arg3);
|
||||||
|
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,11 +467,18 @@ static int test11 (void)
|
|||||||
{
|
{
|
||||||
qse_char_t buf[20];
|
qse_char_t buf[20];
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
|
const qse_char_t* arg3[] =
|
||||||
|
{
|
||||||
|
QSE_T("00000"),
|
||||||
|
QSE_T("11111"),
|
||||||
|
QSE_T("22222")
|
||||||
|
};
|
||||||
|
|
||||||
for (i = 0; i <= QSE_COUNTOF(buf); i++)
|
for (i = 0; i <= QSE_COUNTOF(buf); i++)
|
||||||
{
|
{
|
||||||
qse_strcpy (buf, QSE_T("AAAAAAAAAAAAAAAAAAA"));
|
qse_strcpy (buf, QSE_T("AAAAAAAAAAAAAAAAAAA"));
|
||||||
qse_strxfcpy (buf, i, QSE_T("${2}${1}${0}"),
|
qse_strxfcpy (buf, i, QSE_T("${2}${1}${0}"), arg3);
|
||||||
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
|
|
||||||
qse_printf (QSE_T("bufsize=%02d, buf=[%-20s] "), i, buf);
|
qse_printf (QSE_T("bufsize=%02d, buf=[%-20s] "), i, buf);
|
||||||
|
|
||||||
qse_printf (QSE_T("["));
|
qse_printf (QSE_T("["));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user