diff --git a/qse/doc/page/sed.doc b/qse/doc/page/sed.doc index 718cb1f5..a4ee0681 100644 --- a/qse/doc/page/sed.doc +++ b/qse/doc/page/sed.doc @@ -30,7 +30,7 @@ forms: - address - specify a single address - address,address - specify an address range - 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 ($) 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. - a \\ \n text 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. - i \\ \n text 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. - c \\ \n text 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 reapplied to the current pattern space. - = -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. - p Prints pattern space. @@ -127,7 +127,7 @@ pattern space. - N Prints pattern space and read the next line from the input stream to append it to pattern space with a newline inserted. -- b/b> +- b Branches to the end of commands. - 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 since the last reading of an input line or the last @b t command. - r file -Reads text from @ file and prints it after printing pattern space but before -printing append buffer. Failure to read @ file does not cause an error. +Reads text from @b file and prints it after printing pattern space but before +printing append buffer. Failure to read @b file does not cause an error. - R file -Reads a line of text from @ file and prints it after printing pattern space -but before printing append buffer. Failure to read @ file does not cause an +Reads a line of text from @b file and prints it after printing pattern space +but before printing append buffer. Failure to read @b file does not cause an error. - w file diff --git a/qse/include/qse/awk/Awk.hpp b/qse/include/qse/awk/Awk.hpp index 630a8c1c..b8eb9f39 100644 --- a/qse/include/qse/awk/Awk.hpp +++ b/qse/include/qse/awk/Awk.hpp @@ -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. @@ -51,7 +51,9 @@ public: typedef qse_awk_rtx_t rtx_t; /** 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. @@ -192,7 +194,7 @@ public: class RIO { protected: - RIO (rtx_t* rtx, riod_t* riod); + RIO (rtx_t* rtx, rio_arg_t* riod); public: const char_t* getName() const; @@ -201,12 +203,12 @@ public: operator Awk* () const; operator awk_t* () const; - operator riod_t* () const; + operator rio_arg_t* () const; operator rtx_t* () const; protected: rtx_t* rtx; - riod_t* riod; + rio_arg_t* riod; }; /** @@ -225,7 +227,7 @@ public: }; protected: - Pipe (rtx_t* rtx, riod_t* riod); + Pipe (rtx_t* rtx, rio_arg_t* riod); public: Mode getMode () const; @@ -247,7 +249,7 @@ public: }; protected: - File (rtx_t* rtx, riod_t* riod); + File (rtx_t* rtx, rio_arg_t* riod); public: Mode getMode () const; @@ -268,7 +270,7 @@ public: }; protected: - Console (rtx_t* rtx, riod_t* riod); + Console (rtx_t* rtx, rio_arg_t* riod); ~Console (); public: @@ -558,7 +560,16 @@ public: /** Allows BEGIN, END, pattern-action blocks */ OPT_PABLOCK = QSE_AWK_PABLOCK, /** 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 @@ -1022,13 +1033,13 @@ protected: awk_t* awk, qse_awk_sio_cmd_t cmd, char_t* data, size_t count); 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); 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); 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); static int functionHandler ( diff --git a/qse/include/qse/awk/awk.h b/qse/include/qse/awk/awk.h index 560e387c..46541dfa 100644 --- a/qse/include/qse/awk/awk.h +++ b/qse/include/qse/awk/awk.h @@ -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. @@ -187,19 +187,19 @@ enum qse_awk_sio_cmd_t }; typedef enum qse_awk_sio_cmd_t qse_awk_sio_cmd_t; -/****t* AWK/qse_awk_siof_t - * NAME - * qse_awk_siof_t - define a source IO function - * SYNOPSIS +/** + * The qse_awk_sio_fun_t type defines a source IO function */ -typedef qse_ssize_t (*qse_awk_siof_t) ( +typedef qse_ssize_t (*qse_awk_sio_fun_t) ( qse_awk_t* awk, qse_awk_sio_cmd_t cmd, qse_char_t* data, qse_size_t count ); -/*****/ +/** + * The qse_awk_rio_cmd_t type defines runtime IO commands. + */ enum qse_awk_rio_cmd_t { 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; -/****f* AWK/qse_awk_riod_t - * NAME - * qse_awk_riod_f - define the data passed to a rio function - * SYNOPSIS +/** + * The qse_awk_rio_arg_t defines the data passed to a rio function */ -struct qse_awk_riod_t +struct qse_awk_rio_arg_t { int type; /* [IN] console, file, pipe */ int mode; /* [IN] read, write, etc */ @@ -240,30 +238,23 @@ struct qse_awk_riod_t qse_bool_t eos; } 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 - * qse_awk_riof_t - define a runtime IO function - * SYNOPSIS +/** + * The qse_awk_rio_fun_t type defines a runtime IO function */ -typedef qse_ssize_t (*qse_awk_riof_t) ( - qse_awk_rtx_t* rtx, - qse_awk_rio_cmd_t cmd, - qse_awk_riod_t* riod, - qse_char_t* data, - qse_size_t count +typedef qse_ssize_t (*qse_awk_rio_fun_t) ( + qse_awk_rtx_t* rtx, + qse_awk_rio_cmd_t cmd, + qse_awk_rio_arg_t* riod, + qse_char_t* data, + qse_size_t count ); -/******/ - -/****s* AWK/qse_awk_prm_t - * NAME - * qse_awk_prm_t - define primitive functions - * SYNOPSIS +/** + * The qse_awk_prm_t type defines primitive functions */ struct qse_awk_prm_t { @@ -302,39 +293,30 @@ struct qse_awk_prm_t #endif }; typedef struct qse_awk_prm_t qse_awk_prm_t; -/******/ -/****s* AWK/qse_awk_sio_t - * NAME - * qse_awk_sio_t - define source code IO - * SYNOPSIS +/** + * The qse_awk_sio_t type defines source script IO. */ struct qse_awk_sio_t { - qse_awk_siof_t in; - qse_awk_siof_t out; + qse_awk_sio_fun_t in; + qse_awk_sio_fun_t out; }; typedef struct qse_awk_sio_t qse_awk_sio_t; -/******/ -/****s* AWK/qse_awk_rio_t - * NAME - * qse_awk_rio_t - define runtime IO - * SYNOPSIS +/** + * The qse_awk_rio_t type defines a runtime IO set. */ struct qse_awk_rio_t { - qse_awk_riof_t pipe; - qse_awk_riof_t file; - qse_awk_riof_t console; + qse_awk_rio_fun_t pipe; + qse_awk_rio_fun_t file; + qse_awk_rio_fun_t console; }; typedef struct qse_awk_rio_t qse_awk_rio_t; -/******/ -/****s* AWK/qse_awk_rcb_t - * NAME - * qse_awk_rcb_t - define runtime callbacks - * SYNOPSIS +/** + * The qse_awk_rcb_t type defines runtime callbacks */ struct qse_awk_rcb_t { @@ -350,70 +332,90 @@ struct qse_awk_rcb_t void* data; }; 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 { - /* allow undeclared variables and implicit concatenation */ + /** + * allows undeclared variables and implicit concatenation + **/ 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), - /* change ^ from exponentation to bitwise xor */ + /** changes @b ^ from exponentation to bitwise xor */ QSE_AWK_BXOR = (1 << 3), - /* support shift operators */ + /** supports shift operators: @b << and @b >> */ QSE_AWK_SHIFT = (1 << 4), - /* enable the idiv operator (double slashes) */ + /** enables the idiv operator: @b // */ QSE_AWK_IDIV = (1 << 5), - /* support getline and print */ - QSE_AWK_RIO = (1 << 7), + /** supports @b getline and @b print */ + 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), - /* can terminate a statement with a new line */ + /** a new line can terminate a statement */ 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. * - * Consider the following program. - * BEGIN { FS="[:[:space:]]+"; } - * { - * print "NF=" NF; - * for (i = 0; i < NF; i++) print i " [" $(i+1) "]"; - * } - * - * The program splits " a b c " into [a], [b], [c] when this - * option is on while into [], [a], [b], [c], [] when it is off. + * @code + * BEGIN { FS="[:[:space:]]+"; } + * { + * print "NF=" NF; + * for (i = 0; i < NF; i++) print i " [" $(i+1) "]"; + * } + * @endcode + * " a b c " is split to [a], [b], [c] if #QSE_AWK_STRIPSPACES is on. + * Otherwise, it is split to [], [a], [b], [c], []. */ QSE_AWK_STRIPSPACES = (1 << 11), - /* enable the nextoutfile keyword */ + /** enables @b nextofile */ QSE_AWK_NEXTOFILE = (1 << 12), - /* cr + lf by default */ + /** CR + LF by default */ QSE_AWK_CRLF = (1 << 13), - /* enable the non-standard keyword reset */ + /** enables @b reset */ 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), - /* allows BEGIN, END, pattern-action blocks */ + /** allows @b BEGIN, @b END, pattern-action blocks */ QSE_AWK_PABLOCK = (1 << 16), - /* allow {n,m} in a regular expression */ + /** allows {n,m} in a regular expression. */ 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_NEWLINE | QSE_AWK_PABLOCK | QSE_AWK_STRIPSPACES @@ -795,70 +797,21 @@ int qse_awk_close ( qse_awk_t* awk /**< an awk object */ ); -#if 0 -/****f* AWK/qse_awk_getmmgr - * 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 +/** + * The qse_awk_getprm() function gets primitive functions */ qse_awk_prm_t* qse_awk_getprm ( qse_awk_t* awk ); /******/ -/****f* AWK/qse_awk_clear - * NAME - * qse_awk_clear - clear a qse_awk_t object - * DESCRIPTION - * If you want to reuse a qse_awk_t instance that finished being used, - * 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 - * SYNOPSIS +/** + * The qse_awk_clear() clears the internal state of @a awk. If you want to + * reuse a qse_awk_t instance that finished being used, you may call + * qse_awk_clear() 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 */ int qse_awk_clear ( qse_awk_t* awk @@ -980,18 +933,17 @@ void qse_awk_unsetallwords ( qse_awk_t* awk ); -/* - * NAME: - * enable replacement of a name of a keyword, intrinsic global variables, - * and intrinsic functions. +/** + * The qse_awk_setword() function enables replacement of a name of a keyword, + * intrinsic global variables, and intrinsic functions. * - * DESCRIPTION: - * If nkw is QSE_NULL or nlen is zero and okw is QSE_NULL or olen is zero, - * it unsets all word replacements. If nkw is QSE_NULL or nlen is zero, - * it unsets the replacement for okw and olen. If all of them are valid, - * it sets the word replace for okw and olen to nkw and nlen. + * If @a nkw is QSE_NULL or @a nlen is zero and @a okw is QSE_NULL or + * @a olen is zero, it unsets all word replacements; If @a nkw is QSE_NULL or + * @a nlen is zero, it unsets the replacement for @a okw and @a olen; If + * all of them are valid, it sets the word replace for @a okw and @a olen + * to @a nkw and @a nlen. * - * RETURN: 0 on success, -1 on failure + * @return 0 on success, -1 on failure */ int qse_awk_setword ( /* the pointer to a qse_awk_t instance */ @@ -1216,28 +1168,26 @@ 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 - * The example shows typical usage of the function. - * rtx = qse_awk_rtx_open (awk, rio, rcb, QSE_NULL, QSE_NULL); - * if (rtx != QSE_NULL) - * { - * v = qse_awk_rtx_call (rtx, QSE_T("init"), QSE_NULL, 0); - * if (v != QSE_NULL) qse_awk_rtx_refdownval (rtx, v); - * qse_awk_rtx_call (rtx, QSE_T("fini"), QSE_NULL, 0); - * if (v != QSE_NULL) qse_awk_rtx_refdownval (rtx, v); - * qse_awk_rtx_close (rtx); - * } - * SYNOPSIS +/** + * 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. + * + * The example shows typical usage of the function. + * @code + * rtx = qse_awk_rtx_open (awk, rio, rcb, QSE_NULL, QSE_NULL); + * if (rtx != QSE_NULL) + * { + * v = qse_awk_rtx_call (rtx, QSE_T("init"), QSE_NULL, 0); + * if (v != QSE_NULL) qse_awk_rtx_refdownval (rtx, v); + * qse_awk_rtx_call (rtx, QSE_T("fini"), QSE_NULL, 0); + * if (v != QSE_NULL) qse_awk_rtx_refdownval (rtx, v); + * qse_awk_rtx_close (rtx); + * } + * @endcode + * + * @return 0 on success, -1 on failure */ qse_awk_val_t* qse_awk_rtx_call ( qse_awk_rtx_t* rtx, @@ -1245,7 +1195,6 @@ qse_awk_val_t* qse_awk_rtx_call ( qse_awk_val_t** args, qse_size_t nargs ); -/******/ /****f* AWK/qse_awk_stopall * NAME diff --git a/qse/lib/awk/Awk.cpp b/qse/lib/awk/Awk.cpp index 65b1a8c1..cbd3ce32 100644 --- a/qse/lib/awk/Awk.cpp +++ b/qse/lib/awk/Awk.cpp @@ -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. @@ -62,7 +62,7 @@ void Awk::Source::setHandle (void* handle) // 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); } -Awk::RIO::operator Awk::riod_t* () const +Awk::RIO::operator Awk::rio_arg_t* () const { return this->riod; } @@ -106,7 +106,7 @@ Awk::RIO::operator Awk::rtx_t* () const // 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::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::Console (rtx_t* rtx, riod_t* riod): +Awk::Console::Console (rtx_t* rtx, rio_arg_t* riod): RIO (rtx, riod), filename(QSE_NULL) { } @@ -1635,7 +1635,7 @@ Awk::ssize_t Awk::sourceWriter ( } 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) { rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx); @@ -1668,7 +1668,7 @@ Awk::ssize_t Awk::pipeHandler ( } 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) { rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx); @@ -1701,7 +1701,7 @@ Awk::ssize_t Awk::fileHandler ( } 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) { rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx); diff --git a/qse/lib/awk/awk.h b/qse/lib/awk/awk.h index 6ffbc54b..e7e01040 100644 --- a/qse/lib/awk/awk.h +++ b/qse/lib/awk/awk.h @@ -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. @@ -332,8 +332,8 @@ struct qse_awk_rtx_t /* rio chain */ struct { - qse_awk_riof_t handler[QSE_AWK_RIO_NUM]; - qse_awk_riod_t* chain; + qse_awk_rio_fun_t handler[QSE_AWK_RIO_NUM]; + qse_awk_rio_arg_t* chain; } rio; struct diff --git a/qse/lib/awk/rio.c b/qse/lib/awk/rio.c index 6456f018..320a0cbb 100644 --- a/qse/lib/awk/rio.c +++ b/qse/lib/awk/rio.c @@ -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. @@ -90,8 +90,8 @@ int qse_awk_rtx_readio ( qse_awk_rtx_t* run, int in_type, const qse_char_t* name, qse_str_t* buf) { - qse_awk_riod_t* p = run->rio.chain; - qse_awk_riof_t handler; + qse_awk_rio_arg_t* p = run->rio.chain; + qse_awk_rio_fun_t handler; int io_type, io_mode, io_mask, ret, n; qse_ssize_t x; 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 * to the chain */ - p = (qse_awk_riod_t*) QSE_AWK_ALLOC ( - run->awk, QSE_SIZEOF(qse_awk_riod_t)); + p = (qse_awk_rio_arg_t*) QSE_AWK_ALLOC ( + run->awk, QSE_SIZEOF(qse_awk_rio_arg_t)); if (p == QSE_NULL) { 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, const qse_char_t* name, qse_char_t* str, qse_size_t len) { - qse_awk_riod_t* p = run->rio.chain; - qse_awk_riof_t handler; + qse_awk_rio_arg_t* p = run->rio.chain; + qse_awk_rio_fun_t handler; int io_type, io_mode, io_mask; 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 (p == QSE_NULL) { - p = (qse_awk_riod_t*) QSE_AWK_ALLOC ( - run->awk, QSE_SIZEOF(qse_awk_riod_t)); + p = (qse_awk_rio_arg_t*) QSE_AWK_ALLOC ( + run->awk, QSE_SIZEOF(qse_awk_rio_arg_t)); if (p == QSE_NULL) { qse_awk_rtx_seterror ( @@ -582,8 +582,8 @@ int qse_awk_rtx_writeio_str ( int qse_awk_rtx_flushio ( qse_awk_rtx_t* run, int out_type, const qse_char_t* name) { - qse_awk_riod_t* p = run->rio.chain; - qse_awk_riof_t handler; + qse_awk_rio_arg_t* p = run->rio.chain; + qse_awk_rio_fun_t handler; int io_type, /*io_mode,*/ io_mask; qse_ssize_t n; qse_bool_t ok = QSE_FALSE; @@ -637,8 +637,8 @@ int qse_awk_rtx_flushio ( int qse_awk_rtx_nextio_read ( qse_awk_rtx_t* run, int in_type, const qse_char_t* name) { - qse_awk_riod_t* p = run->rio.chain; - qse_awk_riof_t handler; + qse_awk_rio_arg_t* p = run->rio.chain; + qse_awk_rio_fun_t handler; int io_type, /*io_mode,*/ io_mask; qse_ssize_t n; @@ -715,8 +715,8 @@ int qse_awk_rtx_nextio_read ( int qse_awk_rtx_nextio_write ( qse_awk_rtx_t* run, int out_type, const qse_char_t* name) { - qse_awk_riod_t* p = run->rio.chain; - qse_awk_riof_t handler; + qse_awk_rio_arg_t* p = run->rio.chain; + qse_awk_rio_fun_t handler; int io_type, /*io_mode,*/ io_mask; qse_ssize_t n; @@ -788,8 +788,8 @@ int qse_awk_rtx_nextio_write ( int qse_awk_rtx_closio_read ( 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_riof_t handler; + qse_awk_rio_arg_t* p = run->rio.chain, * px = QSE_NULL; + qse_awk_rio_fun_t handler; int io_type, /*io_mode,*/ io_mask; 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) && 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]; if (handler != QSE_NULL) @@ -847,8 +847,8 @@ int qse_awk_rtx_closio_read ( int qse_awk_rtx_closio_write ( 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_riof_t handler; + qse_awk_rio_arg_t* p = run->rio.chain, * px = QSE_NULL; + qse_awk_rio_fun_t handler; int io_type, /*io_mode,*/ io_mask; 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) && 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]; 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) { - 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) { @@ -913,7 +913,7 @@ int qse_awk_rtx_closeio (qse_awk_rtx_t* run, const qse_char_t* name) * regardless of the io type */ 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]; 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) { - qse_awk_riod_t* next; - qse_awk_riof_t handler; + qse_awk_rio_arg_t* next; + qse_awk_rio_fun_t handler; qse_ssize_t n; while (run->rio.chain != QSE_NULL) diff --git a/qse/lib/awk/run.c b/qse/lib/awk/run.c index 12d0e919..e272a903 100644 --- a/qse/lib/awk/run.c +++ b/qse/lib/awk/run.c @@ -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. @@ -4019,51 +4019,42 @@ static int __cmp_int_real ( } 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_long_t r; int n; - r = qse_awk_strxtolong ( - 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')) + if (rtx->awk->option & QSE_AWK_NUMCMPONSTR) { + const qse_char_t* end; + qse_long_t ll; qse_real_t rr; - rr = qse_awk_strxtoreal ( - run->awk, + n = qse_awk_rtx_strtonum ( + rtx, 1, ((qse_awk_val_str_t*)right)->ptr, ((qse_awk_val_str_t*)right)->len, - &end + &ll, &rr ); - if (end == ((qse_awk_val_str_t*)right)->ptr + - ((qse_awk_val_str_t*)right)->len) + if (n == 0) { - if (((qse_awk_val_int_t*)left)->val > rr) return 1; - if (((qse_awk_val_int_t*)left)->val < rr) return -1; - return 0; + /* a numeric integral string */ + return (((qse_awk_val_int_t*)left)->val > ll)? 1: + (((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; - if (qse_awk_rtx_valtostr (run, left, &out) == QSE_NULL) + if (qse_awk_rtx_valtostr (rtx, left, &out) == QSE_NULL) return CMP_ERROR; - if (run->gbl.ignorecase) + if (rtx->gbl.ignorecase) { n = qse_strxncasecmp ( 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; } @@ -4115,32 +4106,35 @@ static int __cmp_real_real ( } 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; - const qse_char_t* end; - qse_real_t rr; int n; - rr = qse_awk_strxtoreal ( - 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 (rtx->awk->option & QSE_AWK_NUMCMPONSTR) { - if (((qse_awk_val_real_t*)left)->val > rr) return 1; - if (((qse_awk_val_real_t*)left)->val < rr) return -1; - return 0; + const qse_char_t* end; + qse_real_t rr; + + 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; - if (qse_awk_rtx_valtostr (run, left, &out) == QSE_NULL) + if (qse_awk_rtx_valtostr (rtx, left, &out) == QSE_NULL) return CMP_ERROR; - if (run->gbl.ignorecase) + if (rtx->gbl.ignorecase) { n = qse_strxncasecmp ( 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; } @@ -4192,7 +4186,7 @@ static int __cmp_str_str ( ls = (qse_awk_val_str_t*)left; 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 */ return (rtx->gbl.ignorecase)? @@ -4200,17 +4194,68 @@ static int __cmp_str_str ( qse_strxncmp (ls->ptr, ls->len, rs->ptr, rs->len); } - n1 = qse_awk_rtx_strtonum (rtx, 0, ls->ptr, ls->len, &l1, &r1); - n2 = qse_awk_rtx_strtonum (rtx, 0, rs->ptr, rs->len, &l2, &r2); - - if (n1 == 0) + if (ls->nstr == 1) { - 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 { - 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 ( diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index f00f25d7..4530a14e 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -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. @@ -406,7 +406,7 @@ int qse_awk_parsestd ( /*** RTX_OPENSTD ***/ 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) { switch (cmd) @@ -489,7 +489,7 @@ static qse_ssize_t awk_rio_pipe ( } 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) { switch (cmd) @@ -579,7 +579,7 @@ static qse_ssize_t awk_rio_file ( 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); @@ -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 ( - 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) { rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);