added qse_awk_rtx_callwithstrs()
This commit is contained in:
parent
e2f152c927
commit
3cec861547
@ -420,7 +420,7 @@ struct opttab_t
|
||||
{ QSE_T("rwpipe"), QSE_AWK_RWPIPE, QSE_T("allow a dual-directional pipe") },
|
||||
{ QSE_T("newline"), QSE_AWK_NEWLINE, QSE_T("enable a newline to terminate a statement") },
|
||||
{ QSE_T("striprecspc"), QSE_AWK_STRIPRECSPC, QSE_T("strip spaces in splitting a record") },
|
||||
{ QSE_T("stripstrspc"), QSE_AWK_STRIPSTRSPC, QSE_T("strip spaces in converting a string to a number") },
|
||||
{ QSE_T("stripstrspc"), QSE_AWK_STRIPSTRSPC, QSE_T("strip spaces in string-to-number conversion") },
|
||||
{ QSE_T("nextofile"), QSE_AWK_NEXTOFILE, QSE_T("enable 'nextofile'") },
|
||||
{ QSE_T("reset"), QSE_AWK_RESET, QSE_T("enable 'reset'") },
|
||||
{ QSE_T("crlf"), QSE_AWK_CRLF, QSE_T("use CRLF for a newline") },
|
||||
@ -447,7 +447,8 @@ static void print_usage (QSE_FILE* out, const qse_char_t* argv0)
|
||||
qse_fprintf (out, QSE_T(" --version print version\n"));
|
||||
qse_fprintf (out, QSE_T(" -D show extra information\n"));
|
||||
qse_fprintf (out, QSE_T(" -c/--call name call a function instead of entering\n"));
|
||||
qse_fprintf (out, QSE_T(" the pattern-action loop\n"));
|
||||
qse_fprintf (out, QSE_T(" the pattern-action loop. [datafile]* is\n"));
|
||||
qse_fprintf (out, QSE_T(" passed to the function as parameters\n"));
|
||||
qse_fprintf (out, QSE_T(" -f/--file sourcefile set the source script file\n"));
|
||||
qse_fprintf (out, QSE_T(" -d/--deparsed-file deparsedfile set the deparsing output file\n"));
|
||||
qse_fprintf (out, QSE_T(" -F/--field-separator string set a field separator(FS)\n"));
|
||||
@ -1078,7 +1079,7 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
}
|
||||
|
||||
if (qse_awk_parsestd (awk, &psin,
|
||||
((arg.osf == QSE_NULL)? QSE_NULL: &psout)) == -1)
|
||||
((arg.osf == QSE_NULL)? QSE_NULL: &psout)) <= -1)
|
||||
{
|
||||
print_awkerr (awk);
|
||||
goto oops;
|
||||
@ -1086,8 +1087,10 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
|
||||
rtx = qse_awk_rtx_openstd (
|
||||
awk, 0, QSE_T("qseawk"),
|
||||
(const qse_char_t*const*)arg.icf.ptr,
|
||||
QSE_NULL, arg.console_cmgr);
|
||||
(arg.call? QSE_NULL: arg.icf.ptr), /* console input */
|
||||
QSE_NULL, /* console output */
|
||||
arg.console_cmgr
|
||||
);
|
||||
if (rtx == QSE_NULL)
|
||||
{
|
||||
print_awkerr (awk);
|
||||
@ -1107,9 +1110,9 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
|
||||
set_intr_run ();
|
||||
|
||||
retv = (arg.call == QSE_NULL)?
|
||||
qse_awk_rtx_loop (rtx):
|
||||
qse_awk_rtx_call (rtx, arg.call, QSE_NULL, 0);
|
||||
retv = arg.call?
|
||||
qse_awk_rtx_callwithstrs (rtx, arg.call, arg.icf.ptr, arg.icf.size):
|
||||
qse_awk_rtx_loop (rtx);
|
||||
if (retv)
|
||||
{
|
||||
qse_long_t tmp;
|
||||
|
@ -1742,6 +1742,19 @@ qse_awk_val_t* qse_awk_rtx_call (
|
||||
qse_size_t nargs /**< the number of arguments */
|
||||
);
|
||||
|
||||
/**
|
||||
* 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
|
||||
* from the null-terminated strings and calls qse_awk_rtx_call() with the
|
||||
* values created.
|
||||
*/
|
||||
qse_awk_val_t* qse_awk_rtx_callwithstrs (
|
||||
qse_awk_rtx_t* rtx, /**< runtime context */
|
||||
const qse_char_t* name, /**< function name */
|
||||
const qse_char_t** args, /**< arguments to the function */
|
||||
qse_size_t nargs /**< the number of arguments */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_stopall() function aborts all active runtime contexts
|
||||
* associated with @a awk.
|
||||
|
@ -162,12 +162,12 @@ int qse_awk_parsestd (
|
||||
* streams created with @a icf and @a ocf if it is not #QSE_NULL.
|
||||
*/
|
||||
qse_awk_rtx_t* qse_awk_rtx_openstd (
|
||||
qse_awk_t* awk,
|
||||
qse_size_t xtn,
|
||||
const qse_char_t* id,
|
||||
const qse_char_t*const icf[],
|
||||
const qse_char_t*const ocf[],
|
||||
qse_cmgr_t* cmgr
|
||||
qse_awk_t* awk,
|
||||
qse_size_t xtn,
|
||||
const qse_char_t* id,
|
||||
const qse_char_t* icf[],
|
||||
const qse_char_t* ocf[],
|
||||
qse_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -1518,6 +1518,43 @@ qse_awk_val_t* qse_awk_rtx_call (
|
||||
return qse_awk_rtx_callfun (rtx, fun, args, nargs);
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_callwithstrs (
|
||||
qse_awk_rtx_t* rtx, const qse_char_t* name,
|
||||
const qse_char_t** args, qse_size_t nargs)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
for (i = 0; i < nargs; i++)
|
||||
{
|
||||
v[i] = qse_awk_rtx_makestrval0 (rtx, args[i]);
|
||||
if (v[i] == QSE_NULL)
|
||||
{
|
||||
ret = QSE_NULL;
|
||||
goto oops;
|
||||
}
|
||||
|
||||
qse_awk_rtx_refupval (rtx, v[i]);
|
||||
}
|
||||
|
||||
ret = qse_awk_rtx_call (rtx, name, v, nargs);
|
||||
|
||||
oops:
|
||||
while (i > 0)
|
||||
{
|
||||
qse_awk_rtx_refdownval (rtx, v[--i]);
|
||||
}
|
||||
QSE_MMGR_FREE (rtx->awk->mmgr, v);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int run_pblocks (qse_awk_rtx_t* run)
|
||||
{
|
||||
int n;
|
||||
|
@ -1867,12 +1867,12 @@ static int make_additional_globals (
|
||||
}
|
||||
|
||||
qse_awk_rtx_t* qse_awk_rtx_openstd (
|
||||
qse_awk_t* awk,
|
||||
qse_size_t xtnsize,
|
||||
const qse_char_t* id,
|
||||
const qse_char_t*const icf[],
|
||||
const qse_char_t*const ocf[],
|
||||
qse_cmgr_t* cmgr)
|
||||
qse_awk_t* awk,
|
||||
qse_size_t xtnsize,
|
||||
const qse_char_t* id,
|
||||
const qse_char_t* icf[],
|
||||
const qse_char_t* ocf[],
|
||||
qse_cmgr_t* cmgr)
|
||||
{
|
||||
static qse_awk_rtx_ecb_t ecb =
|
||||
{
|
||||
|
24
qse/regress/awk/lang-048.awk
Normal file
24
qse/regress/awk/lang-048.awk
Normal file
@ -0,0 +1,24 @@
|
||||
function ip2int(ip) {
|
||||
ret=0;
|
||||
n=split(ip,a,".");
|
||||
for (x=1;x<=n;x++) ret= ((ret << 8) | a[x])
|
||||
return ret
|
||||
}
|
||||
|
||||
function int2ip(ip, ret,x) {
|
||||
ret = ip & 255;
|
||||
ip = ip >> 8;
|
||||
for(;x<3;x++) {
|
||||
ret=(ip & 255)"."ret;
|
||||
ip=ip >> 8;
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
print int2ip(ip2int("255.255.255.0"));
|
||||
print int2ip(ip2int("255.0.255.0"));
|
||||
print int2ip(ip2int("127.0.0.1"));
|
||||
print int2ip(ip2int("192.168.1.1"));
|
||||
}
|
||||
|
@ -2419,6 +2419,41 @@ that is wonderful
|
||||
hello world 45
|
||||
1
|
||||
--------------------------------------------------------------------------------
|
||||
[CMD] qseawk --newline=on --extraops=on -d- -f lang-048.awk </dev/stdin 2>&1
|
||||
--------------------------------------------------------------------------------
|
||||
function int2ip (__p0, __p1, __p2)
|
||||
{
|
||||
__p1 = (__p0 & 255);
|
||||
__p0 = (__p0 >> 8);
|
||||
for (; (__p2 < 3); (__p2)++)
|
||||
{
|
||||
__p1 = (((__p0 & 255) ".") __p1);
|
||||
__p0 = (__p0 >> 8);
|
||||
}
|
||||
return __p1;
|
||||
}
|
||||
|
||||
function ip2int (__p0)
|
||||
{
|
||||
ret = 0;
|
||||
n = split(__p0,a,".");
|
||||
for (x = 1; (x <= n); (x)++)
|
||||
ret = ((ret << 8) | a[x]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
print int2ip(ip2int("255.255.255.0"));
|
||||
print int2ip(ip2int("255.0.255.0"));
|
||||
print int2ip(ip2int("127.0.0.1"));
|
||||
print int2ip(ip2int("192.168.1.1"));
|
||||
}
|
||||
|
||||
255.255.255.0
|
||||
255.0.255.0
|
||||
127.0.0.1
|
||||
192.168.1.1
|
||||
--------------------------------------------------------------------------------
|
||||
[CMD] qseawk --newline=on -F: -f columnate.awk passwd.dat </dev/stdin 2>&1
|
||||
--------------------------------------------------------------------------------
|
||||
root x 0 0 root /root /bin/bash
|
||||
|
@ -2419,6 +2419,41 @@ that is wonderful
|
||||
hello world 45
|
||||
1
|
||||
--------------------------------------------------------------------------------
|
||||
[CMD] qseawk -m 500000 --newline=on --extraops=on -d- -f lang-048.awk </dev/stdin 2>&1
|
||||
--------------------------------------------------------------------------------
|
||||
function int2ip (__p0, __p1, __p2)
|
||||
{
|
||||
__p1 = (__p0 & 255);
|
||||
__p0 = (__p0 >> 8);
|
||||
for (; (__p2 < 3); (__p2)++)
|
||||
{
|
||||
__p1 = (((__p0 & 255) ".") __p1);
|
||||
__p0 = (__p0 >> 8);
|
||||
}
|
||||
return __p1;
|
||||
}
|
||||
|
||||
function ip2int (__p0)
|
||||
{
|
||||
ret = 0;
|
||||
n = split(__p0,a,".");
|
||||
for (x = 1; (x <= n); (x)++)
|
||||
ret = ((ret << 8) | a[x]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
print int2ip(ip2int("255.255.255.0"));
|
||||
print int2ip(ip2int("255.0.255.0"));
|
||||
print int2ip(ip2int("127.0.0.1"));
|
||||
print int2ip(ip2int("192.168.1.1"));
|
||||
}
|
||||
|
||||
255.255.255.0
|
||||
255.0.255.0
|
||||
127.0.0.1
|
||||
192.168.1.1
|
||||
--------------------------------------------------------------------------------
|
||||
[CMD] qseawk -m 500000 --newline=on -F: -f columnate.awk passwd.dat </dev/stdin 2>&1
|
||||
--------------------------------------------------------------------------------
|
||||
root x 0 0 root /root /bin/bash
|
||||
|
@ -174,6 +174,7 @@ PROGS="
|
||||
lang-045.awk!!!--newline=on -d-
|
||||
lang-046.awk!lang-046.dat2!!--newline=on -d- -vdatadir=@abs_srcdir@ -vdatafile=lang-046.dat1
|
||||
lang-047.awk!!!--newline=on --tolerant=on -d-
|
||||
lang-048.awk!!!--newline=on --extraops=on -d-
|
||||
|
||||
columnate.awk!passwd.dat!!--newline=on -F:
|
||||
levenshtein-utests.awk!!!--newline=on --include=on
|
||||
|
Loading…
Reference in New Issue
Block a user