improved numeric string comparison for various contexts.
This commit is contained in:
parent
ed6db12e27
commit
e774c0bbd1
@ -30,7 +30,7 @@ forms:
|
|||||||
- address - specify a single address
|
- address - specify a single address
|
||||||
- address,address - specify an address range
|
- address,address - specify an address range
|
||||||
- start~step - specify a starting line and a step.
|
- start~step - specify a starting line and a step.
|
||||||
#QSE_SED_CLASSIC disables this form.
|
#QSE_SED_STARTSTEP enables this form.
|
||||||
|
|
||||||
An @b address is a line number, a regular expression, or a dollar sign ($)
|
An @b address is a line number, a regular expression, or a dollar sign ($)
|
||||||
while a @b start and a @b step is a line number.
|
while a @b start and a @b step is a line number.
|
||||||
@ -83,11 +83,11 @@ space if #QSE_SED_QUIET is not set.
|
|||||||
Terminates the exection of commands quietly.
|
Terminates the exection of commands quietly.
|
||||||
- <b>a \\ \n text</b>
|
- <b>a \\ \n text</b>
|
||||||
Stores @b text into an append buffer which is printed after the pattern
|
Stores @b text into an append buffer which is printed after the pattern
|
||||||
space for each input line. If #QSE_SED_CLASSIC is specified, an address range
|
space for each input line. If #QSE_SED_STRICT is specified, an address range
|
||||||
is not allowed in the line selector.
|
is not allowed in the line selector.
|
||||||
- <b>i \\ \n text</b>
|
- <b>i \\ \n text</b>
|
||||||
Inserts @b text into an insert buffer which is printed before the pattern
|
Inserts @b text into an insert buffer which is printed before the pattern
|
||||||
space for each input line. If #QSE_SED_CLASSIC is specified, an address range
|
space for each input line. If #QSE_SED_STRICT is specified, an address range
|
||||||
is not allowed in the line selector.
|
is not allowed in the line selector.
|
||||||
- <b>c \\ \n text</b>
|
- <b>c \\ \n text</b>
|
||||||
If a single line is selected for the command (i.e. no line selector, a single
|
If a single line is selected for the command (i.e. no line selector, a single
|
||||||
@ -103,7 +103,7 @@ Deletes the first line of pattern space. If the pattern space is emptied,
|
|||||||
it branches to the end of script. Otherwise, the commands from the first are
|
it branches to the end of script. Otherwise, the commands from the first are
|
||||||
reapplied to the current pattern space.
|
reapplied to the current pattern space.
|
||||||
- <b>=</b>
|
- <b>=</b>
|
||||||
Prints the current line number. If #QSE_SED_CLASSIC is speccified, an address
|
Prints the current line number. If #QSE_SED_STRICT is speccified, an address
|
||||||
range is not allowed in the line selector.
|
range is not allowed in the line selector.
|
||||||
- <b>p</b>
|
- <b>p</b>
|
||||||
Prints pattern space.
|
Prints pattern space.
|
||||||
@ -127,7 +127,7 @@ pattern space.
|
|||||||
- <b>N</b>
|
- <b>N</b>
|
||||||
Prints pattern space and read the next line from the input stream to append it
|
Prints pattern space and read the next line from the input stream to append it
|
||||||
to pattern space with a newline inserted.
|
to pattern space with a newline inserted.
|
||||||
- <b>b/b>
|
- <b>b</b>
|
||||||
Branches to the end of commands.
|
Branches to the end of commands.
|
||||||
- <b>b label</b>
|
- <b>b label</b>
|
||||||
Branches to @b label
|
Branches to @b label
|
||||||
@ -138,11 +138,11 @@ successfully since the last reading of an input line or the last @b t command.
|
|||||||
Branches to @b label if substitution(s//) has been made successfully
|
Branches to @b label if substitution(s//) has been made successfully
|
||||||
since the last reading of an input line or the last @b t command.
|
since the last reading of an input line or the last @b t command.
|
||||||
- <b>r file</b>
|
- <b>r file</b>
|
||||||
Reads text from @ file and prints it after printing pattern space but before
|
Reads text from @b file and prints it after printing pattern space but before
|
||||||
printing append buffer. Failure to read @ file does not cause an error.
|
printing append buffer. Failure to read @b file does not cause an error.
|
||||||
- <b>R file</b>
|
- <b>R file</b>
|
||||||
Reads a line of text from @ file and prints it after printing pattern space
|
Reads a line of text from @b file and prints it after printing pattern space
|
||||||
but before printing append buffer. Failure to read @ file does not cause an
|
but before printing append buffer. Failure to read @b file does not cause an
|
||||||
error.
|
error.
|
||||||
- <b>w file</b>
|
- <b>w file</b>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.hpp 195 2009-06-10 13:18:25Z hyunghwan.chung $
|
* $Id: Awk.hpp 202 2009-06-16 06:05:40Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -51,7 +51,9 @@ public:
|
|||||||
typedef qse_awk_rtx_t rtx_t;
|
typedef qse_awk_rtx_t rtx_t;
|
||||||
|
|
||||||
/** Represents an runtime I/O data */
|
/** Represents an runtime I/O data */
|
||||||
typedef qse_awk_riod_t riod_t;
|
typedef qse_awk_rio_arg_t rio_arg_t;
|
||||||
|
|
||||||
|
typedef qse_awk_rio_cmd_t rio_cmd_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the source code I/O context for Awk::parse.
|
* Represents the source code I/O context for Awk::parse.
|
||||||
@ -192,7 +194,7 @@ public:
|
|||||||
class RIO
|
class RIO
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
RIO (rtx_t* rtx, riod_t* riod);
|
RIO (rtx_t* rtx, rio_arg_t* riod);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const char_t* getName() const;
|
const char_t* getName() const;
|
||||||
@ -201,12 +203,12 @@ public:
|
|||||||
|
|
||||||
operator Awk* () const;
|
operator Awk* () const;
|
||||||
operator awk_t* () const;
|
operator awk_t* () const;
|
||||||
operator riod_t* () const;
|
operator rio_arg_t* () const;
|
||||||
operator rtx_t* () const;
|
operator rtx_t* () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
rtx_t* rtx;
|
rtx_t* rtx;
|
||||||
riod_t* riod;
|
rio_arg_t* riod;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -225,7 +227,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Pipe (rtx_t* rtx, riod_t* riod);
|
Pipe (rtx_t* rtx, rio_arg_t* riod);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Mode getMode () const;
|
Mode getMode () const;
|
||||||
@ -247,7 +249,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
File (rtx_t* rtx, riod_t* riod);
|
File (rtx_t* rtx, rio_arg_t* riod);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Mode getMode () const;
|
Mode getMode () const;
|
||||||
@ -268,7 +270,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Console (rtx_t* rtx, riod_t* riod);
|
Console (rtx_t* rtx, rio_arg_t* riod);
|
||||||
~Console ();
|
~Console ();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -558,7 +560,16 @@ public:
|
|||||||
/** Allows BEGIN, END, pattern-action blocks */
|
/** Allows BEGIN, END, pattern-action blocks */
|
||||||
OPT_PABLOCK = QSE_AWK_PABLOCK,
|
OPT_PABLOCK = QSE_AWK_PABLOCK,
|
||||||
/** Allows {n,m} in a regular expression */
|
/** Allows {n,m} in a regular expression */
|
||||||
OPT_REXBOUND = QSE_AWK_REXBOUND
|
OPT_REXBOUND = QSE_AWK_REXBOUND,
|
||||||
|
/**
|
||||||
|
* Performs numeric comparison when a string convertable
|
||||||
|
* to a number is compared with a number or vice versa.
|
||||||
|
*
|
||||||
|
* For an expression (9 > "10.9"),
|
||||||
|
* - 9 is greater if #QSE_AWK_NUMCMPONSTR is off;
|
||||||
|
* - "10.9" is greater if #QSE_AWK_NUMCMPONSTR is on
|
||||||
|
*/
|
||||||
|
OPT_NUMCMPONSTR = QSE_AWK_NUMCMPONSTR
|
||||||
};
|
};
|
||||||
// end of enum Option
|
// end of enum Option
|
||||||
|
|
||||||
@ -1022,13 +1033,13 @@ protected:
|
|||||||
awk_t* awk, qse_awk_sio_cmd_t cmd, char_t* data, size_t count);
|
awk_t* awk, qse_awk_sio_cmd_t cmd, char_t* data, size_t count);
|
||||||
|
|
||||||
static ssize_t pipeHandler (
|
static ssize_t pipeHandler (
|
||||||
rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
|
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||||
char_t* data, size_t count);
|
char_t* data, size_t count);
|
||||||
static ssize_t fileHandler (
|
static ssize_t fileHandler (
|
||||||
rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
|
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||||
char_t* data, size_t count);
|
char_t* data, size_t count);
|
||||||
static ssize_t consoleHandler (
|
static ssize_t consoleHandler (
|
||||||
rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
|
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||||
char_t* data, size_t count);
|
char_t* data, size_t count);
|
||||||
|
|
||||||
static int functionHandler (
|
static int functionHandler (
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h 200 2009-06-14 13:22:00Z hyunghwan.chung $
|
* $Id: awk.h 202 2009-06-16 06:05:40Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -187,19 +187,19 @@ enum qse_awk_sio_cmd_t
|
|||||||
};
|
};
|
||||||
typedef enum qse_awk_sio_cmd_t qse_awk_sio_cmd_t;
|
typedef enum qse_awk_sio_cmd_t qse_awk_sio_cmd_t;
|
||||||
|
|
||||||
/****t* AWK/qse_awk_siof_t
|
/**
|
||||||
* NAME
|
* The qse_awk_sio_fun_t type defines a source IO function
|
||||||
* qse_awk_siof_t - define a source IO function
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
*/
|
||||||
typedef qse_ssize_t (*qse_awk_siof_t) (
|
typedef qse_ssize_t (*qse_awk_sio_fun_t) (
|
||||||
qse_awk_t* awk,
|
qse_awk_t* awk,
|
||||||
qse_awk_sio_cmd_t cmd,
|
qse_awk_sio_cmd_t cmd,
|
||||||
qse_char_t* data,
|
qse_char_t* data,
|
||||||
qse_size_t count
|
qse_size_t count
|
||||||
);
|
);
|
||||||
/*****/
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The qse_awk_rio_cmd_t type defines runtime IO commands.
|
||||||
|
*/
|
||||||
enum qse_awk_rio_cmd_t
|
enum qse_awk_rio_cmd_t
|
||||||
{
|
{
|
||||||
QSE_AWK_RIO_OPEN = 0,
|
QSE_AWK_RIO_OPEN = 0,
|
||||||
@ -211,12 +211,10 @@ enum qse_awk_rio_cmd_t
|
|||||||
};
|
};
|
||||||
typedef enum qse_awk_rio_cmd_t qse_awk_rio_cmd_t;
|
typedef enum qse_awk_rio_cmd_t qse_awk_rio_cmd_t;
|
||||||
|
|
||||||
/****f* AWK/qse_awk_riod_t
|
/**
|
||||||
* NAME
|
* The qse_awk_rio_arg_t defines the data passed to a rio function
|
||||||
* qse_awk_riod_f - define the data passed to a rio function
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
*/
|
||||||
struct qse_awk_riod_t
|
struct qse_awk_rio_arg_t
|
||||||
{
|
{
|
||||||
int type; /* [IN] console, file, pipe */
|
int type; /* [IN] console, file, pipe */
|
||||||
int mode; /* [IN] read, write, etc */
|
int mode; /* [IN] read, write, etc */
|
||||||
@ -240,30 +238,23 @@ struct qse_awk_riod_t
|
|||||||
qse_bool_t eos;
|
qse_bool_t eos;
|
||||||
} out;
|
} out;
|
||||||
|
|
||||||
struct qse_awk_riod_t* next;
|
struct qse_awk_rio_arg_t* next;
|
||||||
};
|
};
|
||||||
typedef struct qse_awk_riod_t qse_awk_riod_t;
|
typedef struct qse_awk_rio_arg_t qse_awk_rio_arg_t;
|
||||||
/******/
|
|
||||||
|
|
||||||
/****f* AWK/qse_awk_riof_t
|
/**
|
||||||
* NAME
|
* The qse_awk_rio_fun_t type defines a runtime IO function
|
||||||
* qse_awk_riof_t - define a runtime IO function
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
*/
|
||||||
typedef qse_ssize_t (*qse_awk_riof_t) (
|
typedef qse_ssize_t (*qse_awk_rio_fun_t) (
|
||||||
qse_awk_rtx_t* rtx,
|
qse_awk_rtx_t* rtx,
|
||||||
qse_awk_rio_cmd_t cmd,
|
qse_awk_rio_cmd_t cmd,
|
||||||
qse_awk_riod_t* riod,
|
qse_awk_rio_arg_t* riod,
|
||||||
qse_char_t* data,
|
qse_char_t* data,
|
||||||
qse_size_t count
|
qse_size_t count
|
||||||
);
|
);
|
||||||
/******/
|
|
||||||
|
|
||||||
|
/**
|
||||||
/****s* AWK/qse_awk_prm_t
|
* The qse_awk_prm_t type defines primitive functions
|
||||||
* NAME
|
|
||||||
* qse_awk_prm_t - define primitive functions
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
*/
|
||||||
struct qse_awk_prm_t
|
struct qse_awk_prm_t
|
||||||
{
|
{
|
||||||
@ -302,39 +293,30 @@ struct qse_awk_prm_t
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
typedef struct qse_awk_prm_t qse_awk_prm_t;
|
typedef struct qse_awk_prm_t qse_awk_prm_t;
|
||||||
/******/
|
|
||||||
|
|
||||||
/****s* AWK/qse_awk_sio_t
|
/**
|
||||||
* NAME
|
* The qse_awk_sio_t type defines source script IO.
|
||||||
* qse_awk_sio_t - define source code IO
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
*/
|
||||||
struct qse_awk_sio_t
|
struct qse_awk_sio_t
|
||||||
{
|
{
|
||||||
qse_awk_siof_t in;
|
qse_awk_sio_fun_t in;
|
||||||
qse_awk_siof_t out;
|
qse_awk_sio_fun_t out;
|
||||||
};
|
};
|
||||||
typedef struct qse_awk_sio_t qse_awk_sio_t;
|
typedef struct qse_awk_sio_t qse_awk_sio_t;
|
||||||
/******/
|
|
||||||
|
|
||||||
/****s* AWK/qse_awk_rio_t
|
/**
|
||||||
* NAME
|
* The qse_awk_rio_t type defines a runtime IO set.
|
||||||
* qse_awk_rio_t - define runtime IO
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
*/
|
||||||
struct qse_awk_rio_t
|
struct qse_awk_rio_t
|
||||||
{
|
{
|
||||||
qse_awk_riof_t pipe;
|
qse_awk_rio_fun_t pipe;
|
||||||
qse_awk_riof_t file;
|
qse_awk_rio_fun_t file;
|
||||||
qse_awk_riof_t console;
|
qse_awk_rio_fun_t console;
|
||||||
};
|
};
|
||||||
typedef struct qse_awk_rio_t qse_awk_rio_t;
|
typedef struct qse_awk_rio_t qse_awk_rio_t;
|
||||||
/******/
|
|
||||||
|
|
||||||
/****s* AWK/qse_awk_rcb_t
|
/**
|
||||||
* NAME
|
* The qse_awk_rcb_t type defines runtime callbacks
|
||||||
* qse_awk_rcb_t - define runtime callbacks
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
*/
|
||||||
struct qse_awk_rcb_t
|
struct qse_awk_rcb_t
|
||||||
{
|
{
|
||||||
@ -350,70 +332,90 @@ struct qse_awk_rcb_t
|
|||||||
void* data;
|
void* data;
|
||||||
};
|
};
|
||||||
typedef struct qse_awk_rcb_t qse_awk_rcb_t;
|
typedef struct qse_awk_rcb_t qse_awk_rcb_t;
|
||||||
/******/
|
|
||||||
|
|
||||||
/* various options */
|
/**
|
||||||
|
* The qse_awk_option_t type defines various options to change the behavior
|
||||||
|
* of #qse_awk_t.
|
||||||
|
*/
|
||||||
enum qse_awk_option_t
|
enum qse_awk_option_t
|
||||||
{
|
{
|
||||||
/* allow undeclared variables and implicit concatenation */
|
/**
|
||||||
|
* allows undeclared variables and implicit concatenation
|
||||||
|
**/
|
||||||
QSE_AWK_IMPLICIT = (1 << 0),
|
QSE_AWK_IMPLICIT = (1 << 0),
|
||||||
|
|
||||||
/* allow explicit variable declaration, the concatenation
|
/**
|
||||||
* operator(.), and a parse-time function check. */
|
* allows explicit variable declaration, the concatenation
|
||||||
|
* operator, a period, and performs the parse-time function check.
|
||||||
|
*/
|
||||||
QSE_AWK_EXPLICIT = (1 << 1),
|
QSE_AWK_EXPLICIT = (1 << 1),
|
||||||
|
|
||||||
/* change ^ from exponentation to bitwise xor */
|
/** changes @b ^ from exponentation to bitwise xor */
|
||||||
QSE_AWK_BXOR = (1 << 3),
|
QSE_AWK_BXOR = (1 << 3),
|
||||||
|
|
||||||
/* support shift operators */
|
/** supports shift operators: @b << and @b >> */
|
||||||
QSE_AWK_SHIFT = (1 << 4),
|
QSE_AWK_SHIFT = (1 << 4),
|
||||||
|
|
||||||
/* enable the idiv operator (double slashes) */
|
/** enables the idiv operator: @b // */
|
||||||
QSE_AWK_IDIV = (1 << 5),
|
QSE_AWK_IDIV = (1 << 5),
|
||||||
|
|
||||||
/* support getline and print */
|
/** supports @b getline and @b print */
|
||||||
QSE_AWK_RIO = (1 << 7),
|
QSE_AWK_RIO = (1 << 7),
|
||||||
|
|
||||||
/* support dual direction pipe. QSE_AWK_RIO must be on */
|
/** supports dual direction pipe if QSE_AWK_RIO is on */
|
||||||
QSE_AWK_RWPIPE = (1 << 8),
|
QSE_AWK_RWPIPE = (1 << 8),
|
||||||
|
|
||||||
/* can terminate a statement with a new line */
|
/** a new line can terminate a statement */
|
||||||
QSE_AWK_NEWLINE = (1 << 9),
|
QSE_AWK_NEWLINE = (1 << 9),
|
||||||
|
|
||||||
/* strip off leading and trailing spaces when splitting a record
|
/**
|
||||||
|
* strips off leading and trailing spaces when splitting a record
|
||||||
* into fields with a regular expression.
|
* into fields with a regular expression.
|
||||||
*
|
*
|
||||||
* Consider the following program.
|
* @code
|
||||||
* BEGIN { FS="[:[:space:]]+"; }
|
* BEGIN { FS="[:[:space:]]+"; }
|
||||||
* {
|
* {
|
||||||
* print "NF=" NF;
|
* print "NF=" NF;
|
||||||
* for (i = 0; i < NF; i++) print i " [" $(i+1) "]";
|
* for (i = 0; i < NF; i++) print i " [" $(i+1) "]";
|
||||||
* }
|
* }
|
||||||
*
|
* @endcode
|
||||||
* The program splits " a b c " into [a], [b], [c] when this
|
* " a b c " is split to [a], [b], [c] if #QSE_AWK_STRIPSPACES is on.
|
||||||
* option is on while into [], [a], [b], [c], [] when it is off.
|
* Otherwise, it is split to [], [a], [b], [c], [].
|
||||||
*/
|
*/
|
||||||
QSE_AWK_STRIPSPACES = (1 << 11),
|
QSE_AWK_STRIPSPACES = (1 << 11),
|
||||||
|
|
||||||
/* enable the nextoutfile keyword */
|
/** enables @b nextofile */
|
||||||
QSE_AWK_NEXTOFILE = (1 << 12),
|
QSE_AWK_NEXTOFILE = (1 << 12),
|
||||||
|
|
||||||
/* cr + lf by default */
|
/** CR + LF by default */
|
||||||
QSE_AWK_CRLF = (1 << 13),
|
QSE_AWK_CRLF = (1 << 13),
|
||||||
|
|
||||||
/* enable the non-standard keyword reset */
|
/** enables @b reset */
|
||||||
QSE_AWK_RESET = (1 << 14),
|
QSE_AWK_RESET = (1 << 14),
|
||||||
|
|
||||||
/* allows the assignment of a map value to a variable */
|
/** allows the assignment of a map value to a variable */
|
||||||
QSE_AWK_MAPTOVAR = (1 << 15),
|
QSE_AWK_MAPTOVAR = (1 << 15),
|
||||||
|
|
||||||
/* allows BEGIN, END, pattern-action blocks */
|
/** allows @b BEGIN, @b END, pattern-action blocks */
|
||||||
QSE_AWK_PABLOCK = (1 << 16),
|
QSE_AWK_PABLOCK = (1 << 16),
|
||||||
|
|
||||||
/* allow {n,m} in a regular expression */
|
/** allows {n,m} in a regular expression. */
|
||||||
QSE_AWK_REXBOUND = (1 << 17),
|
QSE_AWK_REXBOUND = (1 << 17),
|
||||||
|
|
||||||
/* option aggregtes */
|
/**
|
||||||
|
* performs numeric comparison when a string convertable
|
||||||
|
* to a number is compared with a number or vice versa.
|
||||||
|
*
|
||||||
|
* For an expression (9 > "10.9"),
|
||||||
|
* - 9 is greater if #QSE_AWK_NUMCMPONSTR is off;
|
||||||
|
* - "10.9" is greater if #QSE_AWK_NUMCMPONSTR is on
|
||||||
|
*/
|
||||||
|
QSE_AWK_NUMCMPONSTR = (1 << 18),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* makes #qse_awk_t to behave as compatibly as classical AWK
|
||||||
|
* implementations
|
||||||
|
*/
|
||||||
QSE_AWK_CLASSIC = QSE_AWK_IMPLICIT | QSE_AWK_RIO |
|
QSE_AWK_CLASSIC = QSE_AWK_IMPLICIT | QSE_AWK_RIO |
|
||||||
QSE_AWK_NEWLINE | QSE_AWK_PABLOCK |
|
QSE_AWK_NEWLINE | QSE_AWK_PABLOCK |
|
||||||
QSE_AWK_STRIPSPACES
|
QSE_AWK_STRIPSPACES
|
||||||
@ -795,70 +797,21 @@ int qse_awk_close (
|
|||||||
qse_awk_t* awk /**< an awk object */
|
qse_awk_t* awk /**< an awk object */
|
||||||
);
|
);
|
||||||
|
|
||||||
#if 0
|
/**
|
||||||
/****f* AWK/qse_awk_getmmgr
|
* The qse_awk_getprm() function gets primitive functions
|
||||||
* NAME
|
|
||||||
* qse_awk_getmmgr - get the memory manager
|
|
||||||
* DESCRIPTION
|
|
||||||
* The qse_awk_getmmgr() function returns the pointer to the memory manager.
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
|
||||||
qse_mmgr_t* qse_awk_getmmgr (
|
|
||||||
qse_awk_t* awk
|
|
||||||
);
|
|
||||||
/******/
|
|
||||||
|
|
||||||
/****f* AWK/qse_awk_setmmgr
|
|
||||||
* NAME
|
|
||||||
* qse_awk_setmmgr - set the extension
|
|
||||||
* DESCRIPTION
|
|
||||||
* The qse_awk_setmmgr() specify the memory manager to use. As the memory
|
|
||||||
* manager is specified into qse_awk_open(), you are not encouraged to change
|
|
||||||
* it by calling this function. Doing so may cause a lot of problems.
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
|
||||||
void qse_awk_setmmgr (
|
|
||||||
qse_awk_t* awk,
|
|
||||||
qse_mmgr_t* mmgr
|
|
||||||
);
|
|
||||||
/******/
|
|
||||||
|
|
||||||
/****f* AWK/qse_awk_getxtn
|
|
||||||
* NAME
|
|
||||||
* qse_awk_getxtn - get the extension
|
|
||||||
* DESCRIPTION
|
|
||||||
* The extension area is allocated in the qse_awk_open() function when it is
|
|
||||||
* given a positive extension size. The pointer to the beginning of the area
|
|
||||||
* can be acquired using the qse_awk_getxtn() function and be utilized
|
|
||||||
* for various purposes.
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
|
||||||
void* qse_awk_getxtn (
|
|
||||||
qse_awk_t* awk /* an awk object */
|
|
||||||
);
|
|
||||||
/******/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****f* AWK/qse_awk_getprm
|
|
||||||
* NAME
|
|
||||||
* qse_awk_getprm - get primitive functions
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
*/
|
||||||
qse_awk_prm_t* qse_awk_getprm (
|
qse_awk_prm_t* qse_awk_getprm (
|
||||||
qse_awk_t* awk
|
qse_awk_t* awk
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
/****f* AWK/qse_awk_clear
|
/**
|
||||||
* NAME
|
* The qse_awk_clear() clears the internal state of @a awk. If you want to
|
||||||
* qse_awk_clear - clear a qse_awk_t object
|
* reuse a qse_awk_t instance that finished being used, you may call
|
||||||
* DESCRIPTION
|
* qse_awk_clear() instead of destroying and creating a new
|
||||||
* If you want to reuse a qse_awk_t instance that finished being used,
|
* #qse_awk_t instance using qse_awk_close() and qse_awk_open().
|
||||||
* you may call qse_awk_close instead of destroying and creating a new
|
*
|
||||||
* qse_awk_t instance using qse_awk_close() and qse_awk_open().
|
* @return 0 on success, -1 on failure
|
||||||
* RETURN
|
|
||||||
* 0 on success, -1 on failure
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
*/
|
||||||
int qse_awk_clear (
|
int qse_awk_clear (
|
||||||
qse_awk_t* awk
|
qse_awk_t* awk
|
||||||
@ -980,18 +933,17 @@ void qse_awk_unsetallwords (
|
|||||||
qse_awk_t* awk
|
qse_awk_t* awk
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* NAME:
|
* The qse_awk_setword() function enables replacement of a name of a keyword,
|
||||||
* enable replacement of a name of a keyword, intrinsic global variables,
|
* intrinsic global variables, and intrinsic functions.
|
||||||
* and intrinsic functions.
|
|
||||||
*
|
*
|
||||||
* DESCRIPTION:
|
* If @a nkw is QSE_NULL or @a nlen is zero and @a okw is QSE_NULL or
|
||||||
* If nkw is QSE_NULL or nlen is zero and okw is QSE_NULL or olen is zero,
|
* @a olen is zero, it unsets all word replacements; If @a nkw is QSE_NULL or
|
||||||
* it unsets all word replacements. If nkw is QSE_NULL or nlen is zero,
|
* @a nlen is zero, it unsets the replacement for @a okw and @a olen; If
|
||||||
* it unsets the replacement for okw and olen. If all of them are valid,
|
* all of them are valid, it sets the word replace for @a okw and @a olen
|
||||||
* it sets the word replace for okw and olen to nkw and nlen.
|
* to @a nkw and @a nlen.
|
||||||
*
|
*
|
||||||
* RETURN: 0 on success, -1 on failure
|
* @return 0 on success, -1 on failure
|
||||||
*/
|
*/
|
||||||
int qse_awk_setword (
|
int qse_awk_setword (
|
||||||
/* the pointer to a qse_awk_t instance */
|
/* the pointer to a qse_awk_t instance */
|
||||||
@ -1216,28 +1168,26 @@ int qse_awk_rtx_loop (
|
|||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
/****f* AWK/qse_awk_rtx_call
|
/**
|
||||||
* NAME
|
* The qse_awk_rtx_call() function invokes an AWK function. However, it is
|
||||||
* qse_awk_rtx_call - call a function
|
* not able to invoke an intrinsic function such as split().
|
||||||
* DESCRIPTION
|
* The #QSE_AWK_PABLOCK option can be turned off to make illegal the BEGIN
|
||||||
* The qse_awk_rtx_call() function invokes an AWK function. However, it is
|
* block, pattern-action blocks, and the END block.
|
||||||
* not able to invoke an intrinsic function such as split().
|
*
|
||||||
* The QSE_AWK_PABLOCK option can be turned off to make illegal the BEGIN
|
* The example shows typical usage of the function.
|
||||||
* block, pattern-action blocks, and the END block.
|
* @code
|
||||||
* RETURN
|
* rtx = qse_awk_rtx_open (awk, rio, rcb, QSE_NULL, QSE_NULL);
|
||||||
* The qse_awk_rtx_call() function returns 0 on success and -1 on failure.
|
* if (rtx != QSE_NULL)
|
||||||
* EXAMPLE
|
* {
|
||||||
* The example shows typical usage of the function.
|
* v = qse_awk_rtx_call (rtx, QSE_T("init"), QSE_NULL, 0);
|
||||||
* rtx = qse_awk_rtx_open (awk, rio, rcb, QSE_NULL, QSE_NULL);
|
* if (v != QSE_NULL) qse_awk_rtx_refdownval (rtx, v);
|
||||||
* if (rtx != QSE_NULL)
|
* qse_awk_rtx_call (rtx, QSE_T("fini"), QSE_NULL, 0);
|
||||||
* {
|
* if (v != QSE_NULL) qse_awk_rtx_refdownval (rtx, v);
|
||||||
* v = qse_awk_rtx_call (rtx, QSE_T("init"), QSE_NULL, 0);
|
* qse_awk_rtx_close (rtx);
|
||||||
* if (v != QSE_NULL) qse_awk_rtx_refdownval (rtx, v);
|
* }
|
||||||
* qse_awk_rtx_call (rtx, QSE_T("fini"), QSE_NULL, 0);
|
* @endcode
|
||||||
* if (v != QSE_NULL) qse_awk_rtx_refdownval (rtx, v);
|
*
|
||||||
* qse_awk_rtx_close (rtx);
|
* @return 0 on success, -1 on failure
|
||||||
* }
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
*/
|
||||||
qse_awk_val_t* qse_awk_rtx_call (
|
qse_awk_val_t* qse_awk_rtx_call (
|
||||||
qse_awk_rtx_t* rtx,
|
qse_awk_rtx_t* rtx,
|
||||||
@ -1245,7 +1195,6 @@ qse_awk_val_t* qse_awk_rtx_call (
|
|||||||
qse_awk_val_t** args,
|
qse_awk_val_t** args,
|
||||||
qse_size_t nargs
|
qse_size_t nargs
|
||||||
);
|
);
|
||||||
/******/
|
|
||||||
|
|
||||||
/****f* AWK/qse_awk_stopall
|
/****f* AWK/qse_awk_stopall
|
||||||
* NAME
|
* NAME
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.cpp 199 2009-06-14 08:40:52Z hyunghwan.chung $
|
* $Id: Awk.cpp 202 2009-06-16 06:05:40Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ void Awk::Source::setHandle (void* handle)
|
|||||||
// Awk::RIO
|
// Awk::RIO
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Awk::RIO::RIO (rtx_t* rtx, riod_t* riod): rtx (rtx), riod (riod)
|
Awk::RIO::RIO (rtx_t* rtx, rio_arg_t* riod): rtx (rtx), riod (riod)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ Awk::RIO::operator Awk::awk_t* () const
|
|||||||
return qse_awk_rtx_getawk (this->rtx);
|
return qse_awk_rtx_getawk (this->rtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
Awk::RIO::operator Awk::riod_t* () const
|
Awk::RIO::operator Awk::rio_arg_t* () const
|
||||||
{
|
{
|
||||||
return this->riod;
|
return this->riod;
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ Awk::RIO::operator Awk::rtx_t* () const
|
|||||||
// Awk::Pipe
|
// Awk::Pipe
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Awk::Pipe::Pipe (rtx_t* rtx, riod_t* riod): RIO (rtx, riod)
|
Awk::Pipe::Pipe (rtx_t* rtx, rio_arg_t* riod): RIO (rtx, riod)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ Awk::Pipe::Mode Awk::Pipe::getMode () const
|
|||||||
// Awk::File
|
// Awk::File
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Awk::File::File (rtx_t* rtx, riod_t* riod): RIO (rtx, riod)
|
Awk::File::File (rtx_t* rtx, rio_arg_t* riod): RIO (rtx, riod)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ Awk::File::Mode Awk::File::getMode () const
|
|||||||
// Awk::Console
|
// Awk::Console
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Awk::Console::Console (rtx_t* rtx, riod_t* riod):
|
Awk::Console::Console (rtx_t* rtx, rio_arg_t* riod):
|
||||||
RIO (rtx, riod), filename(QSE_NULL)
|
RIO (rtx, riod), filename(QSE_NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -1635,7 +1635,7 @@ Awk::ssize_t Awk::sourceWriter (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Awk::ssize_t Awk::pipeHandler (
|
Awk::ssize_t Awk::pipeHandler (
|
||||||
rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
|
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||||
char_t* data, size_t count)
|
char_t* data, size_t count)
|
||||||
{
|
{
|
||||||
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
|
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
|
||||||
@ -1668,7 +1668,7 @@ Awk::ssize_t Awk::pipeHandler (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Awk::ssize_t Awk::fileHandler (
|
Awk::ssize_t Awk::fileHandler (
|
||||||
rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
|
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||||
char_t* data, size_t count)
|
char_t* data, size_t count)
|
||||||
{
|
{
|
||||||
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
|
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
|
||||||
@ -1701,7 +1701,7 @@ Awk::ssize_t Awk::fileHandler (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Awk::ssize_t Awk::consoleHandler (
|
Awk::ssize_t Awk::consoleHandler (
|
||||||
rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
|
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
|
||||||
char_t* data, size_t count)
|
char_t* data, size_t count)
|
||||||
{
|
{
|
||||||
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
|
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h 199 2009-06-14 08:40:52Z hyunghwan.chung $
|
* $Id: awk.h 202 2009-06-16 06:05:40Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -332,8 +332,8 @@ struct qse_awk_rtx_t
|
|||||||
/* rio chain */
|
/* rio chain */
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
qse_awk_riof_t handler[QSE_AWK_RIO_NUM];
|
qse_awk_rio_fun_t handler[QSE_AWK_RIO_NUM];
|
||||||
qse_awk_riod_t* chain;
|
qse_awk_rio_arg_t* chain;
|
||||||
} rio;
|
} rio;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: rio.c 199 2009-06-14 08:40:52Z hyunghwan.chung $
|
* $Id: rio.c 202 2009-06-16 06:05:40Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -90,8 +90,8 @@ int qse_awk_rtx_readio (
|
|||||||
qse_awk_rtx_t* run, int in_type,
|
qse_awk_rtx_t* run, int in_type,
|
||||||
const qse_char_t* name, qse_str_t* buf)
|
const qse_char_t* name, qse_str_t* buf)
|
||||||
{
|
{
|
||||||
qse_awk_riod_t* p = run->rio.chain;
|
qse_awk_rio_arg_t* p = run->rio.chain;
|
||||||
qse_awk_riof_t handler;
|
qse_awk_rio_fun_t handler;
|
||||||
int io_type, io_mode, io_mask, ret, n;
|
int io_type, io_mode, io_mask, ret, n;
|
||||||
qse_ssize_t x;
|
qse_ssize_t x;
|
||||||
qse_awk_val_t* rs;
|
qse_awk_val_t* rs;
|
||||||
@ -130,8 +130,8 @@ int qse_awk_rtx_readio (
|
|||||||
{
|
{
|
||||||
/* if the name doesn't exist in the chain, create an entry
|
/* if the name doesn't exist in the chain, create an entry
|
||||||
* to the chain */
|
* to the chain */
|
||||||
p = (qse_awk_riod_t*) QSE_AWK_ALLOC (
|
p = (qse_awk_rio_arg_t*) QSE_AWK_ALLOC (
|
||||||
run->awk, QSE_SIZEOF(qse_awk_riod_t));
|
run->awk, QSE_SIZEOF(qse_awk_rio_arg_t));
|
||||||
if (p == QSE_NULL)
|
if (p == QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM);
|
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM);
|
||||||
@ -443,8 +443,8 @@ int qse_awk_rtx_writeio_str (
|
|||||||
qse_awk_rtx_t* run, int out_type,
|
qse_awk_rtx_t* run, int out_type,
|
||||||
const qse_char_t* name, qse_char_t* str, qse_size_t len)
|
const qse_char_t* name, qse_char_t* str, qse_size_t len)
|
||||||
{
|
{
|
||||||
qse_awk_riod_t* p = run->rio.chain;
|
qse_awk_rio_arg_t* p = run->rio.chain;
|
||||||
qse_awk_riof_t handler;
|
qse_awk_rio_fun_t handler;
|
||||||
int io_type, io_mode, io_mask;
|
int io_type, io_mode, io_mask;
|
||||||
qse_ssize_t n;
|
qse_ssize_t n;
|
||||||
|
|
||||||
@ -486,8 +486,8 @@ int qse_awk_rtx_writeio_str (
|
|||||||
/* if there is not corresponding rio for name, create one */
|
/* if there is not corresponding rio for name, create one */
|
||||||
if (p == QSE_NULL)
|
if (p == QSE_NULL)
|
||||||
{
|
{
|
||||||
p = (qse_awk_riod_t*) QSE_AWK_ALLOC (
|
p = (qse_awk_rio_arg_t*) QSE_AWK_ALLOC (
|
||||||
run->awk, QSE_SIZEOF(qse_awk_riod_t));
|
run->awk, QSE_SIZEOF(qse_awk_rio_arg_t));
|
||||||
if (p == QSE_NULL)
|
if (p == QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_awk_rtx_seterror (
|
qse_awk_rtx_seterror (
|
||||||
@ -582,8 +582,8 @@ int qse_awk_rtx_writeio_str (
|
|||||||
int qse_awk_rtx_flushio (
|
int qse_awk_rtx_flushio (
|
||||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
||||||
{
|
{
|
||||||
qse_awk_riod_t* p = run->rio.chain;
|
qse_awk_rio_arg_t* p = run->rio.chain;
|
||||||
qse_awk_riof_t handler;
|
qse_awk_rio_fun_t handler;
|
||||||
int io_type, /*io_mode,*/ io_mask;
|
int io_type, /*io_mode,*/ io_mask;
|
||||||
qse_ssize_t n;
|
qse_ssize_t n;
|
||||||
qse_bool_t ok = QSE_FALSE;
|
qse_bool_t ok = QSE_FALSE;
|
||||||
@ -637,8 +637,8 @@ int qse_awk_rtx_flushio (
|
|||||||
int qse_awk_rtx_nextio_read (
|
int qse_awk_rtx_nextio_read (
|
||||||
qse_awk_rtx_t* run, int in_type, const qse_char_t* name)
|
qse_awk_rtx_t* run, int in_type, const qse_char_t* name)
|
||||||
{
|
{
|
||||||
qse_awk_riod_t* p = run->rio.chain;
|
qse_awk_rio_arg_t* p = run->rio.chain;
|
||||||
qse_awk_riof_t handler;
|
qse_awk_rio_fun_t handler;
|
||||||
int io_type, /*io_mode,*/ io_mask;
|
int io_type, /*io_mode,*/ io_mask;
|
||||||
qse_ssize_t n;
|
qse_ssize_t n;
|
||||||
|
|
||||||
@ -715,8 +715,8 @@ int qse_awk_rtx_nextio_read (
|
|||||||
int qse_awk_rtx_nextio_write (
|
int qse_awk_rtx_nextio_write (
|
||||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
||||||
{
|
{
|
||||||
qse_awk_riod_t* p = run->rio.chain;
|
qse_awk_rio_arg_t* p = run->rio.chain;
|
||||||
qse_awk_riof_t handler;
|
qse_awk_rio_fun_t handler;
|
||||||
int io_type, /*io_mode,*/ io_mask;
|
int io_type, /*io_mode,*/ io_mask;
|
||||||
qse_ssize_t n;
|
qse_ssize_t n;
|
||||||
|
|
||||||
@ -788,8 +788,8 @@ int qse_awk_rtx_nextio_write (
|
|||||||
int qse_awk_rtx_closio_read (
|
int qse_awk_rtx_closio_read (
|
||||||
qse_awk_rtx_t* run, int in_type, const qse_char_t* name)
|
qse_awk_rtx_t* run, int in_type, const qse_char_t* name)
|
||||||
{
|
{
|
||||||
qse_awk_riod_t* p = run->rio.chain, * px = QSE_NULL;
|
qse_awk_rio_arg_t* p = run->rio.chain, * px = QSE_NULL;
|
||||||
qse_awk_riof_t handler;
|
qse_awk_rio_fun_t handler;
|
||||||
int io_type, /*io_mode,*/ io_mask;
|
int io_type, /*io_mode,*/ io_mask;
|
||||||
|
|
||||||
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_type_map));
|
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_type_map));
|
||||||
@ -814,7 +814,7 @@ int qse_awk_rtx_closio_read (
|
|||||||
if (p->type == (io_type | io_mask) &&
|
if (p->type == (io_type | io_mask) &&
|
||||||
qse_strcmp (p->name, name) == 0)
|
qse_strcmp (p->name, name) == 0)
|
||||||
{
|
{
|
||||||
qse_awk_riof_t handler;
|
qse_awk_rio_fun_t handler;
|
||||||
|
|
||||||
handler = run->rio.handler[p->type & MASK_CLEAR];
|
handler = run->rio.handler[p->type & MASK_CLEAR];
|
||||||
if (handler != QSE_NULL)
|
if (handler != QSE_NULL)
|
||||||
@ -847,8 +847,8 @@ int qse_awk_rtx_closio_read (
|
|||||||
int qse_awk_rtx_closio_write (
|
int qse_awk_rtx_closio_write (
|
||||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
||||||
{
|
{
|
||||||
qse_awk_riod_t* p = run->rio.chain, * px = QSE_NULL;
|
qse_awk_rio_arg_t* p = run->rio.chain, * px = QSE_NULL;
|
||||||
qse_awk_riof_t handler;
|
qse_awk_rio_fun_t handler;
|
||||||
int io_type, /*io_mode,*/ io_mask;
|
int io_type, /*io_mode,*/ io_mask;
|
||||||
|
|
||||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_type_map));
|
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_type_map));
|
||||||
@ -873,7 +873,7 @@ int qse_awk_rtx_closio_write (
|
|||||||
if (p->type == (io_type | io_mask) &&
|
if (p->type == (io_type | io_mask) &&
|
||||||
qse_strcmp (p->name, name) == 0)
|
qse_strcmp (p->name, name) == 0)
|
||||||
{
|
{
|
||||||
qse_awk_riof_t handler;
|
qse_awk_rio_fun_t handler;
|
||||||
|
|
||||||
handler = run->rio.handler[p->type & MASK_CLEAR];
|
handler = run->rio.handler[p->type & MASK_CLEAR];
|
||||||
if (handler != QSE_NULL)
|
if (handler != QSE_NULL)
|
||||||
@ -905,7 +905,7 @@ int qse_awk_rtx_closio_write (
|
|||||||
|
|
||||||
int qse_awk_rtx_closeio (qse_awk_rtx_t* run, const qse_char_t* name)
|
int qse_awk_rtx_closeio (qse_awk_rtx_t* run, const qse_char_t* name)
|
||||||
{
|
{
|
||||||
qse_awk_riod_t* p = run->rio.chain, * px = QSE_NULL;
|
qse_awk_rio_arg_t* p = run->rio.chain, * px = QSE_NULL;
|
||||||
|
|
||||||
while (p != QSE_NULL)
|
while (p != QSE_NULL)
|
||||||
{
|
{
|
||||||
@ -913,7 +913,7 @@ int qse_awk_rtx_closeio (qse_awk_rtx_t* run, const qse_char_t* name)
|
|||||||
* regardless of the io type */
|
* regardless of the io type */
|
||||||
if (qse_strcmp (p->name, name) == 0)
|
if (qse_strcmp (p->name, name) == 0)
|
||||||
{
|
{
|
||||||
qse_awk_riof_t handler;
|
qse_awk_rio_fun_t handler;
|
||||||
|
|
||||||
handler = run->rio.handler[p->type & MASK_CLEAR];
|
handler = run->rio.handler[p->type & MASK_CLEAR];
|
||||||
if (handler != QSE_NULL)
|
if (handler != QSE_NULL)
|
||||||
@ -947,8 +947,8 @@ int qse_awk_rtx_closeio (qse_awk_rtx_t* run, const qse_char_t* name)
|
|||||||
|
|
||||||
void qse_awk_rtx_cleario (qse_awk_rtx_t* run)
|
void qse_awk_rtx_cleario (qse_awk_rtx_t* run)
|
||||||
{
|
{
|
||||||
qse_awk_riod_t* next;
|
qse_awk_rio_arg_t* next;
|
||||||
qse_awk_riof_t handler;
|
qse_awk_rio_fun_t handler;
|
||||||
qse_ssize_t n;
|
qse_ssize_t n;
|
||||||
|
|
||||||
while (run->rio.chain != QSE_NULL)
|
while (run->rio.chain != QSE_NULL)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: run.c 201 2009-06-15 08:22:48Z hyunghwan.chung $
|
* $Id: run.c 202 2009-06-16 06:05:40Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -4019,51 +4019,42 @@ static int __cmp_int_real (
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int __cmp_int_str (
|
static int __cmp_int_str (
|
||||||
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
|
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||||
{
|
{
|
||||||
const qse_char_t* end;
|
|
||||||
qse_awk_rtx_valtostr_out_t out;
|
qse_awk_rtx_valtostr_out_t out;
|
||||||
qse_long_t r;
|
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
r = qse_awk_strxtolong (
|
if (rtx->awk->option & QSE_AWK_NUMCMPONSTR)
|
||||||
run->awk,
|
|
||||||
((qse_awk_val_str_t*)right)->ptr,
|
|
||||||
((qse_awk_val_str_t*)right)->len, 0,
|
|
||||||
&end
|
|
||||||
);
|
|
||||||
if (end == ((qse_awk_val_str_t*)right)->ptr +
|
|
||||||
((qse_awk_val_str_t*)right)->len)
|
|
||||||
{
|
|
||||||
if (((qse_awk_val_int_t*)left)->val > r) return 1;
|
|
||||||
if (((qse_awk_val_int_t*)left)->val < r) return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/* TODO: should i conver it to real and compare? */
|
|
||||||
else if (*end == QSE_T('.') || *end == QSE_T('E') || *end == QSE_T('e'))
|
|
||||||
{
|
{
|
||||||
|
const qse_char_t* end;
|
||||||
|
qse_long_t ll;
|
||||||
qse_real_t rr;
|
qse_real_t rr;
|
||||||
|
|
||||||
rr = qse_awk_strxtoreal (
|
n = qse_awk_rtx_strtonum (
|
||||||
run->awk,
|
rtx, 1,
|
||||||
((qse_awk_val_str_t*)right)->ptr,
|
((qse_awk_val_str_t*)right)->ptr,
|
||||||
((qse_awk_val_str_t*)right)->len,
|
((qse_awk_val_str_t*)right)->len,
|
||||||
&end
|
&ll, &rr
|
||||||
);
|
);
|
||||||
if (end == ((qse_awk_val_str_t*)right)->ptr +
|
if (n == 0)
|
||||||
((qse_awk_val_str_t*)right)->len)
|
|
||||||
{
|
{
|
||||||
if (((qse_awk_val_int_t*)left)->val > rr) return 1;
|
/* a numeric integral string */
|
||||||
if (((qse_awk_val_int_t*)left)->val < rr) return -1;
|
return (((qse_awk_val_int_t*)left)->val > ll)? 1:
|
||||||
return 0;
|
(((qse_awk_val_int_t*)left)->val < ll)? -1: 0;
|
||||||
|
}
|
||||||
|
else if (n > 0)
|
||||||
|
{
|
||||||
|
/* a numeric floating-point string */
|
||||||
|
return (((qse_awk_val_int_t*)left)->val > rr)? 1:
|
||||||
|
(((qse_awk_val_int_t*)left)->val < rr)? -1: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
||||||
if (qse_awk_rtx_valtostr (run, left, &out) == QSE_NULL)
|
if (qse_awk_rtx_valtostr (rtx, left, &out) == QSE_NULL)
|
||||||
return CMP_ERROR;
|
return CMP_ERROR;
|
||||||
|
|
||||||
if (run->gbl.ignorecase)
|
if (rtx->gbl.ignorecase)
|
||||||
{
|
{
|
||||||
n = qse_strxncasecmp (
|
n = qse_strxncasecmp (
|
||||||
out.u.cpldup.ptr,
|
out.u.cpldup.ptr,
|
||||||
@ -4082,7 +4073,7 @@ static int __cmp_int_str (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSE_AWK_FREE (run->awk, out.u.cpldup.ptr);
|
QSE_AWK_FREE (rtx->awk, out.u.cpldup.ptr);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4115,32 +4106,35 @@ static int __cmp_real_real (
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int __cmp_real_str (
|
static int __cmp_real_str (
|
||||||
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
|
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||||
{
|
{
|
||||||
qse_awk_rtx_valtostr_out_t out;
|
qse_awk_rtx_valtostr_out_t out;
|
||||||
const qse_char_t* end;
|
|
||||||
qse_real_t rr;
|
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
rr = qse_awk_strxtoreal (
|
if (rtx->awk->option & QSE_AWK_NUMCMPONSTR)
|
||||||
run->awk,
|
|
||||||
((qse_awk_val_str_t*)right)->ptr,
|
|
||||||
((qse_awk_val_str_t*)right)->len,
|
|
||||||
&end
|
|
||||||
);
|
|
||||||
if (end == ((qse_awk_val_str_t*)right)->ptr +
|
|
||||||
((qse_awk_val_str_t*)right)->len)
|
|
||||||
{
|
{
|
||||||
if (((qse_awk_val_real_t*)left)->val > rr) return 1;
|
const qse_char_t* end;
|
||||||
if (((qse_awk_val_real_t*)left)->val < rr) return -1;
|
qse_real_t rr;
|
||||||
return 0;
|
|
||||||
|
rr = qse_awk_strxtoreal (
|
||||||
|
rtx->awk,
|
||||||
|
((qse_awk_val_str_t*)right)->ptr,
|
||||||
|
((qse_awk_val_str_t*)right)->len,
|
||||||
|
&end
|
||||||
|
);
|
||||||
|
if (end == ((qse_awk_val_str_t*)right)->ptr +
|
||||||
|
((qse_awk_val_str_t*)right)->len)
|
||||||
|
{
|
||||||
|
return (((qse_awk_val_real_t*)left)->val > rr)? 1:
|
||||||
|
(((qse_awk_val_real_t*)left)->val < rr)? -1: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
||||||
if (qse_awk_rtx_valtostr (run, left, &out) == QSE_NULL)
|
if (qse_awk_rtx_valtostr (rtx, left, &out) == QSE_NULL)
|
||||||
return CMP_ERROR;
|
return CMP_ERROR;
|
||||||
|
|
||||||
if (run->gbl.ignorecase)
|
if (rtx->gbl.ignorecase)
|
||||||
{
|
{
|
||||||
n = qse_strxncasecmp (
|
n = qse_strxncasecmp (
|
||||||
out.u.cpldup.ptr,
|
out.u.cpldup.ptr,
|
||||||
@ -4159,7 +4153,7 @@ static int __cmp_real_str (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSE_AWK_FREE (run->awk, out.u.cpldup.ptr);
|
QSE_AWK_FREE (rtx->awk, out.u.cpldup.ptr);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4192,7 +4186,7 @@ static int __cmp_str_str (
|
|||||||
ls = (qse_awk_val_str_t*)left;
|
ls = (qse_awk_val_str_t*)left;
|
||||||
rs = (qse_awk_val_str_t*)right;
|
rs = (qse_awk_val_str_t*)right;
|
||||||
|
|
||||||
if (ls->nstr == 0 && rs->nstr == 0)
|
if (ls->nstr == 0 || rs->nstr == 0)
|
||||||
{
|
{
|
||||||
/* nother are definitely a string */
|
/* nother are definitely a string */
|
||||||
return (rtx->gbl.ignorecase)?
|
return (rtx->gbl.ignorecase)?
|
||||||
@ -4200,17 +4194,68 @@ static int __cmp_str_str (
|
|||||||
qse_strxncmp (ls->ptr, ls->len, rs->ptr, rs->len);
|
qse_strxncmp (ls->ptr, ls->len, rs->ptr, rs->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
n1 = qse_awk_rtx_strtonum (rtx, 0, ls->ptr, ls->len, &l1, &r1);
|
if (ls->nstr == 1)
|
||||||
n2 = qse_awk_rtx_strtonum (rtx, 0, rs->ptr, rs->len, &l2, &r2);
|
|
||||||
|
|
||||||
if (n1 == 0)
|
|
||||||
{
|
{
|
||||||
return (n2 == 0)? (l1 - l2): ((qse_real_t)l1 - r2);
|
qse_long_t ll;
|
||||||
|
|
||||||
|
ll = qse_awk_strxtolong (
|
||||||
|
rtx->awk, ls->ptr, ls->len, 0, QSE_NULL);
|
||||||
|
|
||||||
|
if (rs->nstr == 1)
|
||||||
|
{
|
||||||
|
qse_long_t rr;
|
||||||
|
|
||||||
|
rr = qse_awk_strxtolong (
|
||||||
|
rtx->awk, rs->ptr, rs->len, 0, QSE_NULL);
|
||||||
|
|
||||||
|
return (ll > rr)? 1:
|
||||||
|
(ll < rr)? -1: 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qse_real_t rr;
|
||||||
|
|
||||||
|
QSE_ASSERT (rs->nstr == 2);
|
||||||
|
|
||||||
|
rr = qse_awk_strxtoreal (
|
||||||
|
rtx->awk, rs->ptr, rs->len, QSE_NULL);
|
||||||
|
|
||||||
|
return (ll > rr)? 1:
|
||||||
|
(ll < rr)? -1: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (n2 == 0)? (r1 - (qse_real_t)l2): (r1 - r2);
|
qse_real_t ll;
|
||||||
}
|
|
||||||
|
QSE_ASSERT (ls->nstr == 2);
|
||||||
|
|
||||||
|
ll = qse_awk_strxtoreal (
|
||||||
|
rtx->awk, ls->ptr, ls->len, QSE_NULL);
|
||||||
|
|
||||||
|
if (rs->nstr == 1)
|
||||||
|
{
|
||||||
|
qse_long_t rr;
|
||||||
|
|
||||||
|
rr = qse_awk_strxtolong (
|
||||||
|
rtx->awk, rs->ptr, rs->len, 0, QSE_NULL);
|
||||||
|
|
||||||
|
return (ll > rr)? 1:
|
||||||
|
(ll < rr)? -1: 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qse_real_t rr;
|
||||||
|
|
||||||
|
QSE_ASSERT (rs->nstr == 2);
|
||||||
|
|
||||||
|
rr = qse_awk_strxtoreal (
|
||||||
|
rtx->awk, rs->ptr, rs->len, QSE_NULL);
|
||||||
|
|
||||||
|
return (ll > rr)? 1:
|
||||||
|
(ll < rr)? -1: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __cmp_val (
|
static int __cmp_val (
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: std.c 195 2009-06-10 13:18:25Z hyunghwan.chung $
|
* $Id: std.c 202 2009-06-16 06:05:40Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -406,7 +406,7 @@ int qse_awk_parsestd (
|
|||||||
|
|
||||||
/*** RTX_OPENSTD ***/
|
/*** RTX_OPENSTD ***/
|
||||||
static qse_ssize_t awk_rio_pipe (
|
static qse_ssize_t awk_rio_pipe (
|
||||||
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_riod_t* riod,
|
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod,
|
||||||
qse_char_t* data, qse_size_t size)
|
qse_char_t* data, qse_size_t size)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
@ -489,7 +489,7 @@ static qse_ssize_t awk_rio_pipe (
|
|||||||
}
|
}
|
||||||
|
|
||||||
static qse_ssize_t awk_rio_file (
|
static qse_ssize_t awk_rio_file (
|
||||||
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_riod_t* riod,
|
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod,
|
||||||
qse_char_t* data, qse_size_t size)
|
qse_char_t* data, qse_size_t size)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
@ -579,7 +579,7 @@ static qse_ssize_t awk_rio_file (
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_riod_t* riod)
|
static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
|
||||||
{
|
{
|
||||||
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
|
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
|
||||||
|
|
||||||
@ -696,7 +696,7 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_riod_t* riod)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static qse_ssize_t awk_rio_console (
|
static qse_ssize_t awk_rio_console (
|
||||||
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_riod_t* riod,
|
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod,
|
||||||
qse_char_t* data, qse_size_t size)
|
qse_char_t* data, qse_size_t size)
|
||||||
{
|
{
|
||||||
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
|
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user