cleaned up code a little
- deleted the QSE_AWK_ARGSTOMAIN option. - enhanced qse_awk_call() a little
This commit is contained in:
parent
44d4f890f4
commit
924f940fba
@ -716,7 +716,6 @@ static struct
|
||||
{ QSE_T("stripspaces"), TestAwk::OPT_STRIPSPACES },
|
||||
{ QSE_T("nextofile"), TestAwk::OPT_NEXTOFILE },
|
||||
{ QSE_T("crlf"), TestAwk::OPT_CRLF },
|
||||
{ QSE_T("argstomain"), TestAwk::OPT_ARGSTOMAIN },
|
||||
{ QSE_T("reset"), TestAwk::OPT_RESET },
|
||||
{ QSE_T("maptovar"), TestAwk::OPT_MAPTOVAR },
|
||||
{ QSE_T("pablock"), TestAwk::OPT_PABLOCK }
|
||||
|
@ -246,7 +246,6 @@ static struct
|
||||
{ QSE_T("stripspaces"), QSE_AWK_STRIPSPACES },
|
||||
{ QSE_T("nextofile"), QSE_AWK_NEXTOFILE },
|
||||
{ QSE_T("crfl"), QSE_AWK_CRLF },
|
||||
{ QSE_T("argstomain"), QSE_AWK_ARGSTOMAIN },
|
||||
{ QSE_T("reset"), QSE_AWK_RESET },
|
||||
{ QSE_T("maptovar"), QSE_AWK_MAPTOVAR },
|
||||
{ QSE_T("pablock"), QSE_AWK_PABLOCK }
|
||||
|
@ -577,12 +577,6 @@ public:
|
||||
OPT_NEXTOFILE = QSE_AWK_NEXTOFILE,
|
||||
/** Use CR+LF instead of LF for line breaking. */
|
||||
OPT_CRLF = QSE_AWK_CRLF,
|
||||
/**
|
||||
* When set, the values specified in a call to Awk::run
|
||||
* as the second and the third parameter are passed to
|
||||
* the function specified as the first parameter.
|
||||
*/
|
||||
OPT_ARGSTOMAIN = QSE_AWK_ARGSTOMAIN,
|
||||
/** Enables the keyword 'reset' */
|
||||
OPT_RESET = QSE_AWK_RESET,
|
||||
/** Allows the assignment of a map value to a variable */
|
||||
@ -878,12 +872,7 @@ public:
|
||||
* @param args Pointer to an array of character strings.
|
||||
* If it is specified, the charater strings are passed to
|
||||
* an AWK program. The values can be accesed with ARGC & ARGV
|
||||
* inside the AWK program. If Awk::OPT_ARGSTOMAIN is set and
|
||||
* the name of entry point is specified, the values are
|
||||
* accessible as arguments to the entry point function.
|
||||
* In this case, the number of arguments specified in the
|
||||
* function definition should not exceed the number of
|
||||
* character string passed here.
|
||||
* inside the AWK program.
|
||||
* @param nargs Number of character strings in the array
|
||||
*
|
||||
* @return
|
||||
|
@ -247,17 +247,14 @@ enum qse_awk_option_t
|
||||
/* cr + lf by default */
|
||||
QSE_AWK_CRLF = (1 << 13),
|
||||
|
||||
/* pass the arguments to the main function */
|
||||
QSE_AWK_ARGSTOMAIN = (1 << 14),
|
||||
|
||||
/* enable the non-standard keyword reset */
|
||||
QSE_AWK_RESET = (1 << 15),
|
||||
QSE_AWK_RESET = (1 << 14),
|
||||
|
||||
/* allows the assignment of a map value to a variable */
|
||||
QSE_AWK_MAPTOVAR = (1 << 16),
|
||||
QSE_AWK_MAPTOVAR = (1 << 15),
|
||||
|
||||
/* allows BEGIN, END, pattern-action blocks */
|
||||
QSE_AWK_PABLOCK = (1 << 17)
|
||||
QSE_AWK_PABLOCK = (1 << 16)
|
||||
};
|
||||
|
||||
/* error code */
|
||||
@ -1117,8 +1114,8 @@ qse_size_t qse_awk_longtostr (
|
||||
*/
|
||||
qse_awk_rtx_t* qse_awk_rtx_open (
|
||||
qse_awk_t* awk,
|
||||
qse_awk_rio_t* ios,
|
||||
qse_awk_rcb_t* cbs,
|
||||
qse_awk_rio_t* rio,
|
||||
qse_awk_rcb_t* rcb,
|
||||
const qse_cstr_t* arg,
|
||||
void* data
|
||||
);
|
||||
@ -1137,6 +1134,19 @@ void qse_awk_rtx_close (
|
||||
/****f* AWK/qse_awk_rtx_loop
|
||||
* NAME
|
||||
* qse_awk_rtx_loop - run BEGIN/pattern-action/END blocks
|
||||
* DESCRIPTION
|
||||
* The qse_awk_rtx_loop() function executes the BEGIN block, pattern-action
|
||||
* blocks and the END blocks in an AWk program. Multiple invocations of the
|
||||
* function for the lifetime of a runtime context is not desirable.
|
||||
* RETURN
|
||||
* The qse_awk_rtx_loop() function returns 0 on success and -1 on failure.
|
||||
* EXAMPLE
|
||||
* rtx = qse_awk_rtx_open (awk, rio, rcb, QSE_NULL, QSE_NULL);
|
||||
* if (rtx != QSE_NULL)
|
||||
* {
|
||||
* qse_awk_rtx_loop (rtx);
|
||||
* qse_awk_rtx_close (rtx);
|
||||
* }
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_awk_rtx_loop (
|
||||
@ -1147,6 +1157,21 @@ int qse_awk_rtx_loop (
|
||||
/****f* AWK/qse_awk_rtx_call
|
||||
* NAME
|
||||
* qse_awk_rtx_call - call a function
|
||||
* DESCRIPTION
|
||||
* The qse_awk_rtx_call() function invokes an AWK function. 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
|
||||
* block, pattern-action blocks, and the END block.
|
||||
* RETURN
|
||||
* The qse_awk_rtx_call() function returns 0 on success and -1 on failure.
|
||||
* EXAMPLE
|
||||
* rtx = qse_awk_rtx_open (awk, rio, rcb, QSE_NULL, QSE_NULL);
|
||||
* if (rtx != QSE_NULL)
|
||||
* {
|
||||
* qse_awk_rtx_call (rtx, QSE_T("init"), QSE_NULL, 0);
|
||||
* qse_awk_rtx_call (rtx, QSE_T("fini"), QSE_NULL, 0);
|
||||
* qse_awk_rtx_close (rtx);
|
||||
* }
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_awk_rtx_call (
|
||||
@ -1157,7 +1182,6 @@ int qse_awk_rtx_call (
|
||||
);
|
||||
/******/
|
||||
|
||||
|
||||
/****f* AWK/qse_awk_stopall
|
||||
* NAME
|
||||
* qse_awk_stopall - stop all runtime contexts
|
||||
|
@ -1465,7 +1465,14 @@ int qse_awk_rtx_call (
|
||||
struct pafv pafv = { args, nargs };
|
||||
qse_awk_nde_call_t call;
|
||||
|
||||
rtx->exit_level = EXIT_NONE;
|
||||
if (rtx->exit_level >= EXIT_NEXT)
|
||||
{
|
||||
/* cannot call the function again when exit() is called
|
||||
* in an AWK program or qse_awk_rtx_stop() is invoked */
|
||||
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOPER, 0, QSE_NULL, 0);
|
||||
return -1;
|
||||
}
|
||||
/*rtx->exit_level = EXIT_NONE;*/
|
||||
|
||||
/* forge a fake node containing a function call */
|
||||
QSE_MEMSET (&call, 0, QSE_SIZEOF(call));
|
||||
@ -2292,7 +2299,9 @@ static int run_return (qse_awk_rtx_t* run, qse_awk_nde_return_t* nde)
|
||||
|
||||
qse_awk_rtx_refdownval (run, STACK_RETVAL(run));
|
||||
STACK_RETVAL(run) = val;
|
||||
qse_awk_rtx_refupval (run, val); /* see eval_call for the trick */
|
||||
|
||||
/* NOTE: see eval_call() for the trick */
|
||||
qse_awk_rtx_refupval (run, val);
|
||||
}
|
||||
|
||||
run->exit_level = EXIT_FUNCTION;
|
||||
|
Loading…
Reference in New Issue
Block a user