renamed Sed::getOption() and Sed::setOption() to Sed::getTrait() and Sed::getTrait() respectively
added qse_sed_opt_t, qse_sed_trait_t renamed qse_sed_exec_op_t to qse_sed_tracer_op_t renamed qse_sed_exec_tracer_t to qse_sed_tracer_t added qse_sed_getopt() and qse_sed_setopt() deleted qse_sed_setlformatter(), qse_sed_getlformatter(), qse_sed_setexectracer(), qse_sed_getexectracer(), qse_sed_setmaxdepth(), qse_sed_getmaxdepth()
This commit is contained in:
parent
92e4134b7d
commit
be6beb61dc
@ -560,20 +560,20 @@ static void unset_intr_run (void)
|
||||
}
|
||||
|
||||
#if defined(QSE_ENABLE_SEDTRACER)
|
||||
static void trace_exec (qse_sed_t* sed, qse_sed_exec_op_t op, const qse_sed_cmd_t* cmd)
|
||||
static void trace_exec (qse_sed_t* sed, qse_sed_tracer_op_t op, const qse_sed_cmd_t* cmd)
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
case QSE_SED_EXEC_READ:
|
||||
case QSE_SED_TRACER_READ:
|
||||
/*qse_fprintf (QSE_STDERR, QSE_T("reading...\n"));*/
|
||||
break;
|
||||
case QSE_SED_EXEC_WRITE:
|
||||
case QSE_SED_TRACER_WRITE:
|
||||
/*qse_fprintf (QSE_STDERR, QSE_T("wrting...\n"));*/
|
||||
break;
|
||||
|
||||
/* TODO: use function to get hold space and pattern space and print them */
|
||||
|
||||
case QSE_SED_EXEC_MATCH:
|
||||
case QSE_SED_TRACER_MATCH:
|
||||
qse_fprintf (QSE_STDERR, QSE_T("%s:%lu [%c] MA\n"),
|
||||
((cmd->lid && cmd->lid[0])? cmd->lid: QSE_T("<<UNKNOWN>>")),
|
||||
(unsigned long)cmd->loc.line,
|
||||
@ -581,7 +581,7 @@ static void trace_exec (qse_sed_t* sed, qse_sed_exec_op_t op, const qse_sed_cmd_
|
||||
);
|
||||
break;
|
||||
|
||||
case QSE_SED_EXEC_EXEC:
|
||||
case QSE_SED_TRACER_EXEC:
|
||||
qse_fprintf (QSE_STDERR, QSE_T("%s:%lu [%c] EC\n"),
|
||||
((cmd->lid && cmd->lid[0])? cmd->lid: QSE_T("<<UNKNOWN>>")),
|
||||
(unsigned long)cmd->loc.line,
|
||||
@ -737,7 +737,7 @@ static int sed_main (int argc, qse_char_t* argv[])
|
||||
goto oops;
|
||||
}
|
||||
|
||||
qse_sed_setoption (sed, g_option);
|
||||
qse_sed_setopt (sed, QSE_SED_TRAIT, &g_option);
|
||||
|
||||
if (qse_sed_compstd (sed, g_script.io, &script_count) <= -1)
|
||||
{
|
||||
@ -780,7 +780,7 @@ static int sed_main (int argc, qse_char_t* argv[])
|
||||
}
|
||||
|
||||
#if defined(QSE_ENABLE_SEDTRACER)
|
||||
if (g_trace) qse_sed_setexectracer (sed, trace_exec);
|
||||
if (g_trace) qse_sed_setopt (sed, QSE_SED_TRACER, trace_exec);
|
||||
#endif
|
||||
|
||||
qse_memset (&xarg, 0, QSE_SIZEOF(xarg));
|
||||
|
@ -1552,7 +1552,7 @@ PREDEFINED = "QSE_BEGIN_NAMESPACE(x)=namespace x {" \
|
||||
"QSE_SIZEOF_OFF_T=@QSE_SIZEOF_OFF_T@" \
|
||||
"QSE_SIZEOF_OFF64_T=@QSE_SIZEOF_OFF64_T@" \
|
||||
"QSE_EXPORT=" \
|
||||
"QSE_ENABLE_SEDTRACER=" \
|
||||
"QSE_ENABLE_SEDTRACER=" \
|
||||
"@CHAR_MODE@"
|
||||
|
||||
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
|
||||
|
@ -66,8 +66,10 @@ Accessing Pattern and Hold Space
|
||||
|
||||
The qse_sed_getspace() allows to you get the pointer and the length
|
||||
of the pattern space and the hold space. It may not be so useful you
|
||||
access them after execution is completed. The qse_sed_setexectracer()
|
||||
function lets you set up a hook function during execution time.
|
||||
access them after execution is completed. The qse_sed_setopt()
|
||||
function called with #QSE_SED_TRACER lets you set up a hook function
|
||||
that can inspect various things during execution time.
|
||||
|
||||
The following sample prints the contents of the pattern space and
|
||||
hold space at each phase of execution.
|
||||
|
||||
|
@ -973,9 +973,12 @@ struct qse_awk_rtx_ecb_t
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* The qse_awk_opt_t type defines various option types.
|
||||
*/
|
||||
enum qse_awk_opt_t
|
||||
{
|
||||
QSE_AWK_TRAIT = 0,
|
||||
QSE_AWK_TRAIT,
|
||||
|
||||
QSE_AWK_MODPREFIX,
|
||||
QSE_AWK_MODPOSTFIX,
|
||||
|
@ -52,8 +52,8 @@ public:
|
||||
typedef qse_sed_io_cmd_t io_cmd_t;
|
||||
/// The io_arg_t type redefines an IO data type
|
||||
typedef qse_sed_io_arg_t io_arg_t;
|
||||
/// The option_t type redefines an option type
|
||||
typedef qse_sed_option_t option_t;
|
||||
/// The trait_t type redefines an trait type
|
||||
typedef qse_sed_trait_t trait_t;
|
||||
#if 0
|
||||
/// The depth_t type redefines an depth IDs
|
||||
typedef qse_sed_depth_t depth_t;
|
||||
@ -204,17 +204,17 @@ public:
|
||||
bool isStop () const;
|
||||
|
||||
///
|
||||
/// The getOption() function gets the current options.
|
||||
/// @return 0 or current options ORed of #option_t enumerators.
|
||||
/// The getTrait() function gets the current traits.
|
||||
/// @return 0 or current options ORed of #trait_t enumerators.
|
||||
///
|
||||
int getOption () const;
|
||||
int getTrait () const;
|
||||
|
||||
///
|
||||
/// The setOption() function sets options for a stream editor.
|
||||
/// The option code @a opt is 0 or OR'ed of #option_t enumerators.
|
||||
/// The setTrait() function sets traits for a stream editor.
|
||||
/// The option code @a opt is 0 or OR'ed of #trait_t enumerators.
|
||||
///
|
||||
void setOption (
|
||||
int opt ///< option code
|
||||
void setTrait (
|
||||
int trait ///< option code
|
||||
);
|
||||
|
||||
#if 0
|
||||
|
@ -38,10 +38,6 @@
|
||||
* qse_sed_exec (sed);
|
||||
* qse_sed_close (sed);
|
||||
* @endcode
|
||||
*
|
||||
* @todo
|
||||
* - enhance execution of the l(ell) command - consider adding a callback
|
||||
*
|
||||
*/
|
||||
|
||||
/** @struct qse_sed_t
|
||||
@ -275,12 +271,26 @@ typedef const qse_char_t* (*qse_sed_errstr_t) (
|
||||
qse_sed_errnum_t num /**< an error number */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_option_t type defines various option codes for a stream editor.
|
||||
* Options can be OR'ed with each other and be passed to a stream editor with
|
||||
* the qse_sed_setoption() function.
|
||||
/**
|
||||
* The qse_sed_opt_t type defines various option types.
|
||||
*/
|
||||
enum qse_sed_option_t
|
||||
enum qse_sed_opt_t
|
||||
{
|
||||
QSE_SED_TRAIT, /**< trait */
|
||||
QSE_SED_TRACER, /**< tracer hook */
|
||||
QSE_SED_LFORMATTER, /**< formatter for the 'l' command */
|
||||
|
||||
QSE_SED_DEPTH_REX_BUILD,
|
||||
QSE_SED_DEPTH_REX_MATCH
|
||||
};
|
||||
typedef enum qse_sed_opt_t qse_sed_opt_t;
|
||||
|
||||
/**
|
||||
* The qse_sed_trait_t type defines various trait codes for a stream editor.
|
||||
* Options can be OR'ed with each other and be passed to a stream editor with
|
||||
* the qse_sed_setopt() function.
|
||||
*/
|
||||
enum qse_sed_trait_t
|
||||
{
|
||||
QSE_SED_STRIPLS = (1 << 0), /**< strip leading spaces from text */
|
||||
QSE_SED_KEEPTBS = (1 << 1), /**< keep an trailing backslash */
|
||||
@ -292,7 +302,7 @@ enum qse_sed_option_t
|
||||
QSE_SED_EXTENDEDREX = (1 << 8), /**< use extended regex */
|
||||
QSE_SED_NONSTDEXTREX = (1 << 9) /**< enable non-standard extensions to regex */
|
||||
};
|
||||
typedef enum qse_sed_option_t qse_sed_option_t;
|
||||
typedef enum qse_sed_trait_t qse_sed_trait_t;
|
||||
|
||||
/**
|
||||
* The qse_sed_io_cmd_t type defines I/O command codes. The code indicates
|
||||
@ -366,22 +376,20 @@ struct qse_sed_ecb_t
|
||||
qse_sed_ecb_t* next;
|
||||
};
|
||||
|
||||
#ifdef QSE_ENABLE_SEDTRACER
|
||||
enum qse_sed_exec_op_t
|
||||
enum qse_sed_tracer_op_t
|
||||
{
|
||||
QSE_SED_EXEC_READ,
|
||||
QSE_SED_EXEC_WRITE,
|
||||
QSE_SED_EXEC_MATCH,
|
||||
QSE_SED_EXEC_EXEC
|
||||
QSE_SED_TRACER_READ,
|
||||
QSE_SED_TRACER_WRITE,
|
||||
QSE_SED_TRACER_MATCH,
|
||||
QSE_SED_TRACER_EXEC
|
||||
};
|
||||
typedef enum qse_sed_exec_op_t qse_sed_exec_op_t;
|
||||
typedef enum qse_sed_tracer_op_t qse_sed_tracer_op_t;
|
||||
|
||||
typedef void (*qse_sed_exec_tracer_t) (
|
||||
typedef void (*qse_sed_tracer_t) (
|
||||
qse_sed_t* sed,
|
||||
qse_sed_exec_op_t op,
|
||||
qse_sed_tracer_op_t op,
|
||||
const qse_sed_cmd_t* cmd
|
||||
);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The qse_sed_space_t type defines the types of
|
||||
@ -420,29 +428,56 @@ QSE_EXPORT void qse_sed_close (
|
||||
qse_sed_t* sed /**< stream editor */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_getmmgr() function returns the memory
|
||||
* manager used in qse_sed_open().
|
||||
*/
|
||||
QSE_EXPORT qse_mmgr_t* qse_sed_getmmgr (
|
||||
qse_sed_t* sed
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_getxtn() function returns the pointer
|
||||
* to the beginning of the extension area created with
|
||||
* qse_sed_open().
|
||||
*/
|
||||
QSE_EXPORT void* qse_sed_getxtn (
|
||||
qse_sed_t* sed
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* The qse_sed_getoption() function retrieves the current options set in
|
||||
* a stream editor.
|
||||
* @return 0 or a number OR'ed of #qse_sed_option_t values
|
||||
* The qse_sed_getopt() function gets the value of an option
|
||||
* specified by \a id into the buffer pointed to by \a value.
|
||||
*
|
||||
* The \a value field is dependent on \a id:
|
||||
* - #QSE_SED_TRAIT - int*
|
||||
* - #QSE_SED_TRACER - qse_sed_tracer_t*
|
||||
* - #QSE_SED_LFORMATTER - qse_sed_lformatter_t*
|
||||
*
|
||||
* \return 0 on success, -1 on failure
|
||||
*/
|
||||
QSE_EXPORT int qse_sed_getoption (
|
||||
const qse_sed_t* sed /**< stream editor */
|
||||
QSE_EXPORT int qse_sed_getopt (
|
||||
qse_sed_t* sed,
|
||||
qse_sed_opt_t id,
|
||||
void* value
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_setoption() function sets the option code.
|
||||
* The qse_sed_setopt() function sets the value of an option
|
||||
* specified by \a id to the value pointed to by \a value.
|
||||
*
|
||||
* The \a value field is dependent on \a id:
|
||||
* - #QSE_SED_TRAIT - const int*
|
||||
* - #QSE_SED_TRACER - qse_sed_tracer_t
|
||||
* - #QSE_SED_LFORMATTER - qse_sed_lformatter_t
|
||||
*
|
||||
* \return 0 on success, -1 on failure
|
||||
*/
|
||||
QSE_EXPORT void qse_sed_setoption (
|
||||
qse_sed_t* sed, /**< stream editor */
|
||||
int opt /**< 0 or a number OR'ed of #qse_sed_option_t values */
|
||||
QSE_EXPORT int qse_sed_setopt (
|
||||
qse_sed_t* sed,
|
||||
qse_sed_opt_t id,
|
||||
const void* value
|
||||
);
|
||||
|
||||
/**
|
||||
@ -483,7 +518,7 @@ QSE_EXPORT void qse_sed_seterrstr (
|
||||
|
||||
/**
|
||||
* The qse_sed_geterrnum() function gets the number of the last error.
|
||||
* @return the number of the last error
|
||||
* @return error number
|
||||
*/
|
||||
QSE_EXPORT qse_sed_errnum_t qse_sed_geterrnum (
|
||||
const qse_sed_t* sed /**< stream editor */
|
||||
@ -500,7 +535,7 @@ QSE_EXPORT const qse_sed_loc_t* qse_sed_geterrloc (
|
||||
|
||||
/**
|
||||
* The qse_sed_geterrmsg() function gets a string describing the last error.
|
||||
* @return a pointer to an error message
|
||||
* @return error message pointer
|
||||
*/
|
||||
QSE_EXPORT const qse_char_t* qse_sed_geterrmsg (
|
||||
const qse_sed_t* sed /**< stream editor */
|
||||
@ -603,24 +638,6 @@ QSE_EXPORT int qse_sed_isstop (
|
||||
qse_sed_t* sed /**< stream editor */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_getlformatter() function gets the text formatter for the 'l'
|
||||
* command.
|
||||
*/
|
||||
QSE_EXPORT qse_sed_lformatter_t qse_sed_getlformatter (
|
||||
qse_sed_t* sed /**< stream editor */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_setlformatter() function sets the text formatter for the 'l'
|
||||
* command. The text formatter must output the text with a character writer
|
||||
* provided and return -1 on failure and 0 on success.
|
||||
*/
|
||||
QSE_EXPORT void qse_sed_setlformatter (
|
||||
qse_sed_t* sed, /**< stream editor */
|
||||
qse_sed_lformatter_t lformatter /**< text formatter */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_getcompid() function returns the latest
|
||||
* identifier successfully set with qse_sed_setcompid().
|
||||
@ -697,25 +714,6 @@ QSE_EXPORT void qse_sed_freemem (
|
||||
void* ptr
|
||||
);
|
||||
|
||||
#ifdef QSE_ENABLE_SEDTRACER
|
||||
/**
|
||||
* The qse_sed_getexectracer() function returns the execution tracer
|
||||
* function.
|
||||
*/
|
||||
QSE_EXPORT qse_sed_exec_tracer_t qse_sed_getexectracer (
|
||||
qse_sed_t* sed
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_setexectracer() function sets a hook function via which
|
||||
* you can trace commands being executed.
|
||||
*/
|
||||
QSE_EXPORT void qse_sed_setexectracer (
|
||||
qse_sed_t* sed,
|
||||
qse_sed_exec_tracer_t tracer
|
||||
);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The qse_sed_getspace() function gets the pointer and the length
|
||||
* to a buffer space specfied by \a space.
|
||||
|
@ -76,18 +76,21 @@ bool Sed::isStop () const
|
||||
return qse_sed_isstop (sed);
|
||||
}
|
||||
|
||||
int Sed::getOption() const
|
||||
int Sed::getTrait () const
|
||||
{
|
||||
QSE_ASSERT (sed != QSE_NULL);
|
||||
return qse_sed_getoption (sed);
|
||||
int val;
|
||||
qse_sed_getopt (sed, QSE_SED_TRAIT, &val);
|
||||
return val;
|
||||
}
|
||||
|
||||
void Sed::setOption (int opt)
|
||||
void Sed::setTrait (int trait)
|
||||
{
|
||||
QSE_ASSERT (sed != QSE_NULL);
|
||||
qse_sed_setoption (sed, opt);
|
||||
qse_sed_setopt (sed, QSE_SED_TRAIT, &trait);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
Sed::size_t Sed::getMaxDepth (depth_t id) const
|
||||
{
|
||||
|
@ -22,8 +22,10 @@
|
||||
#include "../cmn/mem.h"
|
||||
#include <qse/cmn/chr.h>
|
||||
|
||||
/* Define USE_REX to use <qse/cmn/rex.h> */
|
||||
/*#define USE_REX*/
|
||||
/* Define USE_REGEX to use regcomp(), regexec(), regfree() instead of TRE */
|
||||
/* #define USE_REGEX */
|
||||
/*#define USE_REGEX*/
|
||||
|
||||
#if defined(USE_REX)
|
||||
# include <qse/cmn/rex.h>
|
||||
@ -153,29 +155,63 @@ void* qse_sed_getxtn (qse_sed_t* sed)
|
||||
return QSE_XTN (sed);
|
||||
}
|
||||
|
||||
void qse_sed_setoption (qse_sed_t* sed, int option)
|
||||
int qse_sed_setopt (qse_sed_t* sed, qse_sed_opt_t id, const void* value)
|
||||
{
|
||||
sed->option = option;
|
||||
switch (id)
|
||||
{
|
||||
case QSE_SED_TRAIT:
|
||||
sed->opt.trait = *(const int*)value;
|
||||
return 0;
|
||||
|
||||
case QSE_SED_TRACER:
|
||||
sed->opt.tracer = (qse_sed_tracer_t)value;
|
||||
return 0;
|
||||
|
||||
case QSE_SED_LFORMATTER:
|
||||
sed->opt.lformatter = (qse_sed_lformatter_t)value;
|
||||
return 0;
|
||||
|
||||
case QSE_SED_DEPTH_REX_BUILD:
|
||||
sed->opt.depth.rex.build = *(const qse_size_t*)value;
|
||||
return 0;
|
||||
|
||||
case QSE_SED_DEPTH_REX_MATCH:
|
||||
sed->opt.depth.rex.match = *(const qse_size_t*)value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
qse_sed_seterrnum (sed, QSE_SED_EINVAL, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qse_sed_getoption (const qse_sed_t* sed)
|
||||
int qse_sed_getopt (qse_sed_t* sed, qse_sed_opt_t id, void* value)
|
||||
{
|
||||
return sed->option;
|
||||
}
|
||||
switch (id)
|
||||
{
|
||||
case QSE_SED_TRAIT:
|
||||
*(int*)value = sed->opt.trait;
|
||||
return 0;
|
||||
|
||||
#if defined(USE_REX)
|
||||
qse_size_t qse_sed_getmaxdepth (const qse_sed_t* sed, qse_sed_depth_t id)
|
||||
{
|
||||
return (id & QSE_SED_DEPTH_REX_BUILD)? sed->depth.rex.build:
|
||||
(id & QSE_SED_DEPTH_REX_MATCH)? sed->depth.rex.match: 0;
|
||||
}
|
||||
case QSE_SED_TRACER:
|
||||
*(qse_sed_tracer_t*)value = sed->opt.tracer;
|
||||
return 0;
|
||||
|
||||
void qse_sed_setmaxdepth (qse_sed_t* sed, int ids, qse_size_t depth)
|
||||
{
|
||||
if (ids & QSE_SED_DEPTH_REX_BUILD) sed->depth.rex.build = depth;
|
||||
if (ids & QSE_SED_DEPTH_REX_MATCH) sed->depth.rex.match = depth;
|
||||
case QSE_SED_LFORMATTER:
|
||||
*(qse_sed_lformatter_t*)value = sed->opt.lformatter;
|
||||
return 0;
|
||||
|
||||
case QSE_SED_DEPTH_REX_BUILD:
|
||||
*(qse_size_t*)value = sed->opt.depth.rex.build;
|
||||
return 0;
|
||||
|
||||
case QSE_SED_DEPTH_REX_MATCH:
|
||||
*(qse_size_t*)value = sed->opt.depth.rex.match;
|
||||
return 0;
|
||||
};
|
||||
|
||||
qse_sed_seterrnum (sed, QSE_SED_EINVAL, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void* build_rex (
|
||||
qse_sed_t* sed, const qse_cstr_t* str,
|
||||
@ -185,10 +221,10 @@ static void* build_rex (
|
||||
void* rex;
|
||||
int opt = 0;
|
||||
|
||||
if ((sed->option & QSE_SED_EXTENDEDREX) == 0) opt |= QSE_REX_NOBOUND;
|
||||
if ((sed->opt.trait & QSE_SED_EXTENDEDREX) == 0) opt |= QSE_REX_NOBOUND;
|
||||
|
||||
rex = qse_buildrex (
|
||||
sed->mmgr, sed->depth.rex.build,
|
||||
sed->mmgr, sed->opt.depth.rex.build,
|
||||
opt, str->ptr, str->len, QSE_NULL
|
||||
);
|
||||
if (rex == QSE_NULL)
|
||||
@ -205,7 +241,7 @@ static void* build_rex (
|
||||
int xopt = 0;
|
||||
|
||||
if (ignorecase) xopt |= REG_ICASE;
|
||||
if (sed->option & QSE_SED_EXTENDEDREX) xopt |= REG_EXTENDED;
|
||||
if (sed->opt.trait & QSE_SED_EXTENDEDREX) xopt |= REG_EXTENDED;
|
||||
|
||||
rex = QSE_MMGR_ALLOC (sed->mmgr, QSE_SIZEOF(*rex));
|
||||
if (rex == QSE_NULL)
|
||||
@ -247,8 +283,8 @@ static void* build_rex (
|
||||
|
||||
/* ignorecase is a compile option for TRE */
|
||||
if (ignorecase) opt |= QSE_TRE_IGNORECASE;
|
||||
if (sed->option & QSE_SED_EXTENDEDREX) opt |= QSE_TRE_EXTENDED;
|
||||
if (sed->option & QSE_SED_NONSTDEXTREX) opt |= QSE_TRE_NONSTDEXT;
|
||||
if (sed->opt.trait & QSE_SED_EXTENDEDREX) opt |= QSE_TRE_EXTENDED;
|
||||
if (sed->opt.trait & QSE_SED_NONSTDEXTREX) opt |= QSE_TRE_NONSTDEXT;
|
||||
|
||||
if (qse_tre_compx (tre, str->ptr, str->len, QSE_NULL, opt) <= -1)
|
||||
{
|
||||
@ -982,7 +1018,7 @@ do { \
|
||||
|
||||
do
|
||||
{
|
||||
if (sed->option & QSE_SED_STRIPLS)
|
||||
if (sed->opt.trait & QSE_SED_STRIPLS)
|
||||
{
|
||||
/* get the first non-space character */
|
||||
while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops);
|
||||
@ -997,7 +1033,7 @@ do { \
|
||||
NXTSC_GOTO (sed, c, oops);
|
||||
if (c == QSE_CHAR_EOF)
|
||||
{
|
||||
if (sed->option & QSE_SED_KEEPTBS)
|
||||
if (sed->opt.trait & QSE_SED_KEEPTBS)
|
||||
ADD (sed, t, QSE_T('\\'), oops);
|
||||
break;
|
||||
}
|
||||
@ -1028,7 +1064,7 @@ do { \
|
||||
while (c != QSE_CHAR_EOF);
|
||||
|
||||
done:
|
||||
if ((sed->option & QSE_SED_ENSURENL) && c != QSE_T('\n'))
|
||||
if ((sed->opt.trait & QSE_SED_ENSURENL) && c != QSE_T('\n'))
|
||||
{
|
||||
/* TODO: support different line end convension */
|
||||
ADD (sed, t, QSE_T('\n'), oops);
|
||||
@ -1056,7 +1092,7 @@ static int get_label (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
if (!IS_LABCHAR(c))
|
||||
{
|
||||
/* label name is empty */
|
||||
if (sed->option & QSE_SED_STRICT)
|
||||
if (sed->opt.trait & QSE_SED_STRICT)
|
||||
{
|
||||
SETERR0 (sed, QSE_SED_ELABEM, &sed->src.loc);
|
||||
return -1;
|
||||
@ -1811,7 +1847,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
case QSE_T('q'):
|
||||
case QSE_T('Q'):
|
||||
cmd->type = c;
|
||||
if (sed->option & QSE_SED_STRICT &&
|
||||
if (sed->opt.trait & QSE_SED_STRICT &&
|
||||
cmd->a2.type != QSE_SED_ADR_NONE)
|
||||
{
|
||||
SETERR1 (
|
||||
@ -1827,7 +1863,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
|
||||
case QSE_T('a'):
|
||||
case QSE_T('i'):
|
||||
if (sed->option & QSE_SED_STRICT &&
|
||||
if (sed->opt.trait & QSE_SED_STRICT &&
|
||||
cmd->a2.type != QSE_SED_ADR_NONE)
|
||||
{
|
||||
qse_char_t tmpc = c;
|
||||
@ -1846,7 +1882,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
|
||||
if (c != QSE_T('\\'))
|
||||
{
|
||||
if ((sed->option & QSE_SED_SAMELINE) &&
|
||||
if ((sed->opt.trait & QSE_SED_SAMELINE) &&
|
||||
c != QSE_CHAR_EOF && c != QSE_T('\n'))
|
||||
{
|
||||
/* allow text without a starting backslash
|
||||
@ -1863,7 +1899,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
|
||||
if (c != QSE_CHAR_EOF && c != QSE_T('\n'))
|
||||
{
|
||||
if (sed->option & QSE_SED_SAMELINE)
|
||||
if (sed->opt.trait & QSE_SED_SAMELINE)
|
||||
{
|
||||
/* allow text with a starting backslash
|
||||
* on the same line as a command */
|
||||
@ -1884,7 +1920,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
}
|
||||
|
||||
case QSE_T('='):
|
||||
if (sed->option & QSE_SED_STRICT &&
|
||||
if (sed->opt.trait & QSE_SED_STRICT &&
|
||||
cmd->a2.type != QSE_SED_ADR_NONE)
|
||||
{
|
||||
qse_char_t tmpc = c;
|
||||
@ -2031,14 +2067,14 @@ int qse_sed_comp (qse_sed_t* sed, qse_sed_io_impl_t inf)
|
||||
while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops);
|
||||
|
||||
if (c == QSE_T(',') ||
|
||||
((sed->option & QSE_SED_EXTENDEDADR) && c == QSE_T('~')))
|
||||
((sed->opt.trait & QSE_SED_EXTENDEDADR) && c == QSE_T('~')))
|
||||
{
|
||||
qse_char_t delim = c;
|
||||
|
||||
/* maybe an address range */
|
||||
do { NXTSC_GOTO (sed, c, oops); } while (IS_SPACE(c));
|
||||
|
||||
if (get_address (sed, &cmd->a2, (sed->option & QSE_SED_EXTENDEDADR)) == QSE_NULL)
|
||||
if (get_address (sed, &cmd->a2, (sed->opt.trait & QSE_SED_EXTENDEDADR)) == QSE_NULL)
|
||||
{
|
||||
QSE_ASSERT (cmd->a2.type == QSE_SED_ADR_NONE);
|
||||
SETERR0 (sed, QSE_SED_EA2MOI, &sed->src.loc);
|
||||
@ -2062,7 +2098,7 @@ int qse_sed_comp (qse_sed_t* sed, qse_sed_io_impl_t inf)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((sed->option & QSE_SED_EXTENDEDADR) &&
|
||||
else if ((sed->opt.trait & QSE_SED_EXTENDEDADR) &&
|
||||
(delim == QSE_T('~')))
|
||||
{
|
||||
if (cmd->a1.type != QSE_SED_ADR_LINE ||
|
||||
@ -2091,7 +2127,7 @@ int qse_sed_comp (qse_sed_t* sed, qse_sed_io_impl_t inf)
|
||||
if (cmd->a1.type == QSE_SED_ADR_LINE && cmd->a1.u.lno <= 0)
|
||||
{
|
||||
if (cmd->a2.type == QSE_SED_ADR_STEP ||
|
||||
((sed->option & QSE_SED_EXTENDEDADR) &&
|
||||
((sed->opt.trait & QSE_SED_EXTENDEDADR) &&
|
||||
cmd->a2.type == QSE_SED_ADR_REX))
|
||||
{
|
||||
/* 0 as the first address is allowed in this two contexts.
|
||||
@ -2773,7 +2809,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
#if defined(USE_REX)
|
||||
n = qse_matchrex (
|
||||
sed->mmgr,
|
||||
sed->depth.rex.match,
|
||||
sed->opt.depth.rex.match,
|
||||
rex, opt,
|
||||
&str, &cur, &mat, &errnum
|
||||
);
|
||||
@ -3223,7 +3259,7 @@ static int match_a (qse_sed_t* sed, qse_sed_cmd_t* cmd, qse_sed_adr_t* a)
|
||||
#if defined(USE_REX)
|
||||
n = qse_matchrex (
|
||||
sed->mmgr,
|
||||
sed->depth.rex.match,
|
||||
sed->opt.depth.rex.match,
|
||||
rex, 0,
|
||||
&line, &line,
|
||||
&match, &errnum);
|
||||
@ -3517,9 +3553,9 @@ static qse_sed_cmd_t* exec_cmd (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
break;
|
||||
|
||||
case QSE_SED_CMD_PRINT_CLEARLY:
|
||||
if (sed->lformatter)
|
||||
if (sed->opt.lformatter)
|
||||
{
|
||||
n = sed->lformatter (
|
||||
n = sed->opt.lformatter (
|
||||
sed,
|
||||
QSE_STR_PTR(&sed->e.in.line),
|
||||
QSE_STR_LEN(&sed->e.in.line),
|
||||
@ -3741,7 +3777,7 @@ static int init_command_block_for_exec (qse_sed_t* sed, qse_sed_cmd_blk_t* b)
|
||||
/* clear states */
|
||||
c->state.a1_matched = 0;
|
||||
|
||||
if (sed->option & QSE_SED_EXTENDEDADR)
|
||||
if (sed->opt.trait & QSE_SED_EXTENDEDADR)
|
||||
{
|
||||
if (c->a2.type == QSE_SED_ADR_REX &&
|
||||
c->a1.type == QSE_SED_ADR_LINE &&
|
||||
@ -3848,7 +3884,7 @@ static int emit_output (qse_sed_t* sed, int skipline)
|
||||
{
|
||||
int n;
|
||||
|
||||
if (!skipline && !(sed->option & QSE_SED_QUIET))
|
||||
if (!skipline && !(sed->opt.trait & QSE_SED_QUIET))
|
||||
{
|
||||
/* write the pattern space */
|
||||
n = write_str (sed,
|
||||
@ -3885,7 +3921,7 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_impl_t inf, qse_sed_io_impl_t outf)
|
||||
},
|
||||
QSE_MAP_COMPER_DEFAULT,
|
||||
QSE_MAP_KEEPER_DEFAULT
|
||||
#ifdef QSE_MAP_AS_HTB
|
||||
#if defined(QSE_MAP_AS_HTB)
|
||||
,
|
||||
QSE_MAP_SIZER_DEFAULT,
|
||||
QSE_MAP_HASHER_DEFAULT
|
||||
@ -3961,8 +3997,8 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_impl_t inf, qse_sed_io_impl_t outf)
|
||||
|
||||
while (!sed->e.stopreq)
|
||||
{
|
||||
#ifdef QSE_ENABLE_SEDTRACER
|
||||
if (sed->e.tracer) sed->e.tracer (sed, QSE_SED_EXEC_READ, QSE_NULL);
|
||||
#if defined(QSE_ENABLE_SEDTRACER)
|
||||
if (sed->opt.tracer) sed->opt.tracer (sed, QSE_SED_TRACER_READ, QSE_NULL);
|
||||
#endif
|
||||
|
||||
n = read_line (sed, 0);
|
||||
@ -3982,8 +4018,8 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_impl_t inf, qse_sed_io_impl_t outf)
|
||||
|
||||
while (c != &sed->cmd.over)
|
||||
{
|
||||
#ifdef QSE_ENABLE_SEDTRACER
|
||||
if (sed->e.tracer) sed->e.tracer (sed, QSE_SED_EXEC_MATCH, c);
|
||||
#if defined(QSE_ENABLE_SEDTRACER)
|
||||
if (sed->opt.tracer) sed->opt.tracer (sed, QSE_SED_TRACER_MATCH, c);
|
||||
#endif
|
||||
|
||||
n = match_address (sed, c);
|
||||
@ -3996,8 +4032,8 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_impl_t inf, qse_sed_io_impl_t outf)
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef QSE_ENABLE_SEDTRACER
|
||||
if (sed->e.tracer) sed->e.tracer (sed, QSE_SED_EXEC_EXEC, c);
|
||||
#if defined(QSE_ENABLE_SEDTRACER)
|
||||
if (sed->opt.tracer) sed->opt.tracer (sed, QSE_SED_TRACER_EXEC, c);
|
||||
#endif
|
||||
j = exec_cmd (sed, c);
|
||||
if (j == QSE_NULL) { ret = -1; goto done; }
|
||||
@ -4015,8 +4051,8 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_impl_t inf, qse_sed_io_impl_t outf)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef QSE_ENABLE_SEDTRACER
|
||||
if (sed->e.tracer) sed->e.tracer (sed, QSE_SED_EXEC_WRITE, QSE_NULL);
|
||||
#if defined(QSE_ENABLE_SEDTRACER)
|
||||
if (sed->opt.tracer) sed->opt.tracer (sed, QSE_SED_TRACER_WRITE, QSE_NULL);
|
||||
#endif
|
||||
if (emit_output (sed, 0) <= -1) { ret = -1; goto done; }
|
||||
}
|
||||
@ -4042,16 +4078,6 @@ int qse_sed_isstop (qse_sed_t* sed)
|
||||
return sed->e.stopreq;
|
||||
}
|
||||
|
||||
qse_sed_lformatter_t qse_sed_getlformatter (qse_sed_t* sed)
|
||||
{
|
||||
return sed->lformatter;
|
||||
}
|
||||
|
||||
void qse_sed_setlformatter (qse_sed_t* sed, qse_sed_lformatter_t lf)
|
||||
{
|
||||
sed->lformatter = lf;
|
||||
}
|
||||
|
||||
const qse_char_t* qse_sed_getcompid (qse_sed_t* sed)
|
||||
{
|
||||
return sed->src.cid? ((const qse_char_t*)(sed->src.cid + 1)): QSE_NULL;
|
||||
@ -4142,18 +4168,6 @@ void qse_sed_freemem (qse_sed_t* sed, void* ptr)
|
||||
}
|
||||
|
||||
|
||||
#ifdef QSE_ENABLE_SEDTRACER
|
||||
qse_sed_exec_tracer_t qse_sed_getexectracer (qse_sed_t* sed)
|
||||
{
|
||||
return sed->e.tracer;
|
||||
}
|
||||
|
||||
void qse_sed_setexectracer (qse_sed_t* sed, qse_sed_exec_tracer_t tracer)
|
||||
{
|
||||
sed->e.tracer = tracer;
|
||||
}
|
||||
#endif
|
||||
|
||||
void qse_sed_getspace (qse_sed_t* sed, qse_sed_space_t space, qse_cstr_t* str)
|
||||
{
|
||||
switch (space)
|
||||
|
@ -27,19 +27,6 @@
|
||||
#define QSE_MAP_AS_RBT
|
||||
#include <qse/cmn/map.h>
|
||||
|
||||
/*
|
||||
* Define USE_REX to use rex.h on behalf of tre.h
|
||||
* rex.h currently does not support backreference.
|
||||
*/
|
||||
#ifdef USE_REX
|
||||
enum qse_sed_depth_t
|
||||
{
|
||||
QSE_SED_DEPTH_REX_BUILD = (1 << 0),
|
||||
QSE_SED_DEPTH_REX_MATCH = (1 << 1)
|
||||
};
|
||||
typedef enum qse_sed_depth_t qse_sed_depth_t;
|
||||
#endif
|
||||
|
||||
/* structure to maintain data to append
|
||||
* at the end of each cycle, triggered by r, R, and a */
|
||||
typedef struct qse_sed_app_t qse_sed_app_t;
|
||||
@ -86,25 +73,28 @@ struct qse_sed_t
|
||||
qse_char_t errmsg[128]; /**< error message holder */
|
||||
qse_sed_loc_t errloc; /**< location of the last error */
|
||||
|
||||
int option; /**< stores options */
|
||||
|
||||
qse_sed_lformatter_t lformatter;
|
||||
|
||||
struct
|
||||
struct
|
||||
{
|
||||
int trait;
|
||||
qse_sed_tracer_t tracer;
|
||||
qse_sed_lformatter_t lformatter;
|
||||
|
||||
struct
|
||||
{
|
||||
qse_size_t build;
|
||||
qse_size_t match;
|
||||
} rex;
|
||||
} depth;
|
||||
struct
|
||||
{
|
||||
qse_size_t build;
|
||||
qse_size_t match;
|
||||
} rex;
|
||||
} depth; /* useful only for rex.h */
|
||||
} opt;
|
||||
|
||||
qse_sed_ecb_t* ecb;
|
||||
|
||||
/** source text pointers */
|
||||
struct
|
||||
{
|
||||
qse_sed_io_impl_t fun; /**< input stream handler */
|
||||
qse_sed_io_impl_t fun; /**< input stream handler */
|
||||
qse_sed_io_arg_t arg;
|
||||
qse_char_t buf[1024];
|
||||
int eof;
|
||||
@ -223,11 +213,6 @@ struct qse_sed_t
|
||||
|
||||
/** stop requested */
|
||||
int stopreq;
|
||||
|
||||
#ifdef QSE_ENABLE_SEDTRACER
|
||||
/** trace function */
|
||||
qse_sed_exec_tracer_t tracer;
|
||||
#endif
|
||||
} e;
|
||||
};
|
||||
|
||||
@ -249,25 +234,6 @@ const qse_char_t* qse_sed_dflerrstr (
|
||||
qse_sed_errnum_t errnum
|
||||
);
|
||||
|
||||
#ifdef USE_REX
|
||||
/**
|
||||
* The qse_sed_getmaxdepth() gets the maximum processing depth.
|
||||
*/
|
||||
qse_size_t qse_sed_getmaxdepth (
|
||||
const qse_sed_t* sed, /**< stream editor */
|
||||
qse_sed_depth_t id /**< one of qse_sed_depth_t values */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_setmaxdepth() sets the maximum processing depth.
|
||||
*/
|
||||
void qse_sed_setmaxdepth (
|
||||
qse_sed_t* sed, /**< stream editor */
|
||||
int ids, /**< 0 or a number OR'ed of #qse_sed_depth_t values */
|
||||
qse_size_t depth /**< maximum depth level */
|
||||
);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -52,4 +52,3 @@ int qse_main (int argc, qse_achar_t* argv[])
|
||||
init_sed_sample_locale ();
|
||||
return qse_runmain (argc, argv, sed_main);
|
||||
}
|
||||
|
||||
|
@ -65,4 +65,3 @@ int qse_main (int argc, qse_achar_t* argv[])
|
||||
init_sed_sample_locale ();
|
||||
return qse_runmain (argc, argv, sed_main);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <qse/cmn/stdio.h>
|
||||
#include "sed00.h"
|
||||
|
||||
static void trace_exec (qse_sed_t* sed, qse_sed_exec_op_t op, qse_sed_cmd_t* cmd)
|
||||
static void trace_exec (qse_sed_t* sed, qse_sed_tracer_op_t op, qse_sed_cmd_t* cmd)
|
||||
{
|
||||
qse_cstr_t h, p;
|
||||
|
||||
@ -48,7 +48,7 @@ static int sed_main (int argc, qse_char_t* argv[])
|
||||
out.type = QSE_SED_IOSTD_STR;
|
||||
|
||||
/* squeeze in a tracing hook */
|
||||
qse_sed_setexectracer (sed, trace_exec);
|
||||
qse_sed_setopt (sed, QSE_SED_TRACER, trace_exec);
|
||||
|
||||
/* execute the compiled command */
|
||||
if (qse_sed_execstd (sed, in, &out) <= -1)
|
||||
@ -74,4 +74,3 @@ int qse_main (int argc, qse_achar_t* argv[])
|
||||
init_sed_sample_locale ();
|
||||
return qse_runmain (argc, argv, sed_main);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user