fixed a bug in emitting a string
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp 275 2009-08-30 13:19:02Z hyunghwan.chung $
|
||||
* $Id: Awk.hpp 277 2009-09-02 12:55:55Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -25,7 +25,6 @@
|
||||
#include <qse/Mmgr.hpp>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
/** @file
|
||||
* AWK Interpreter
|
||||
*/
|
||||
@ -271,24 +270,27 @@ protected:
|
||||
class NoSource;
|
||||
|
||||
public:
|
||||
/**
|
||||
* The Source class is an abstract class to encapsulate
|
||||
* source script I/O. The Awk::parse function requires a concrete
|
||||
* object instantiated from its child class.
|
||||
*/
|
||||
///
|
||||
/// The Source class is an abstract class to encapsulate
|
||||
/// source script I/O. The Awk::parse function requires a concrete
|
||||
/// object instantiated from its child class.
|
||||
///
|
||||
class Source
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// The Mode type defines opening mode.
|
||||
///
|
||||
enum Mode
|
||||
{
|
||||
READ, /**< source code read. */
|
||||
WRITE /**< source code write. */
|
||||
READ, ///< open for read
|
||||
WRITE ///< open for write
|
||||
};
|
||||
|
||||
/**
|
||||
* The Awk::Source::Data class is used to deliver information
|
||||
* needed for source script I/O.
|
||||
*/
|
||||
///
|
||||
/// The Data class encapsulates information passed in and out
|
||||
/// for source script I/O.
|
||||
///
|
||||
class Data: protected sio_arg_t
|
||||
{
|
||||
public:
|
||||
@ -345,9 +347,9 @@ public:
|
||||
virtual ssize_t read (Data& io, char_t* buf, size_t len) = 0;
|
||||
virtual ssize_t write (Data& io, char_t* buf, size_t len) = 0;
|
||||
|
||||
/**
|
||||
* special value to indicate no source
|
||||
*/
|
||||
///
|
||||
/// The NONE object indicates no source.
|
||||
///
|
||||
static NoSource NONE;
|
||||
|
||||
private:
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h 275 2009-08-30 13:19:02Z hyunghwan.chung $
|
||||
* $Id: awk.h 277 2009-09-02 12:55:55Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -338,8 +338,8 @@ enum qse_awk_rio_cmd_t
|
||||
QSE_AWK_RIO_OPEN = 0, /**< open a stream */
|
||||
QSE_AWK_RIO_CLOSE = 1, /**< close a stream */
|
||||
QSE_AWK_RIO_READ = 2, /**< read a stream */
|
||||
QSE_AWK_RIO_WRITE = 3, /**< write a stream */
|
||||
QSE_AWK_RIO_FLUSH = 4, /**< write buffered data to a stream */
|
||||
QSE_AWK_RIO_WRITE = 3, /**< write to a stream */
|
||||
QSE_AWK_RIO_FLUSH = 4, /**< flush buffered data to a stream */
|
||||
QSE_AWK_RIO_NEXT = 5 /**< close the current stream and
|
||||
open the next stream (only for console) */
|
||||
};
|
||||
@ -582,7 +582,7 @@ enum qse_awk_option_t
|
||||
/** supports @b getline and @b print */
|
||||
QSE_AWK_RIO = (1 << 3),
|
||||
|
||||
/** supports dual direction pipe if #QSE_AWK_RIO is on */
|
||||
/** enables the two-way pipe if #QSE_AWK_RIO is on */
|
||||
QSE_AWK_RWPIPE = (1 << 4),
|
||||
|
||||
/** a new line can terminate a statement */
|
||||
@ -891,23 +891,28 @@ enum qse_awk_val_type_t
|
||||
|
||||
/**
|
||||
* The values defined are used to set the type field of the
|
||||
* qse_awk_rtx_valtostr_out_t structure. The field should be one of the
|
||||
* #qse_awk_rtx_valtostr_out_t structure. The field should be one of the
|
||||
* following values:
|
||||
*
|
||||
* - QSE_AWK_RTX_VALTOSTR_CPL
|
||||
* - QSE_AWK_RTX_VALTOSTR_CPLDUP
|
||||
* - QSE_AWK_RTX_VALTOSTR_STRP
|
||||
* - QSE_AWK_RTX_VALTOSTR_STRPCAT
|
||||
* - #QSE_AWK_RTX_VALTOSTR_CPL
|
||||
* - #QSE_AWK_RTX_VALTOSTR_CPLDUP
|
||||
* - #QSE_AWK_RTX_VALTOSTR_STRP
|
||||
* - #QSE_AWK_RTX_VALTOSTR_STRPCAT
|
||||
*
|
||||
* and it can optionally be ORed with QSE_AWK_RTX_VALTOSTR_PRINT.
|
||||
* and it can optionally be ORed with #QSE_AWK_RTX_VALTOSTR_PRINT.
|
||||
*/
|
||||
enum qse_awk_rtx_valtostr_type_t
|
||||
{
|
||||
QSE_AWK_RTX_VALTOSTR_CPL = 0x00,
|
||||
{
|
||||
/** use u.cpl of #qse_awk_rtx_valtostr_out_t */
|
||||
QSE_AWK_RTX_VALTOSTR_CPL = 0x00,
|
||||
/** use u.cpldup of #qse_awk_rtx_valtostr_out_t */
|
||||
QSE_AWK_RTX_VALTOSTR_CPLDUP = 0x01,
|
||||
/** use u.strp of #qse_awk_rtx_valtostr_out_t */
|
||||
QSE_AWK_RTX_VALTOSTR_STRP = 0x02,
|
||||
/** use u.strpcat of #qse_awk_rtx_valtostr_out_t */
|
||||
QSE_AWK_RTX_VALTOSTR_STRPCAT = 0x03,
|
||||
QSE_AWK_RTX_VALTOSTR_PRINT = 0x10
|
||||
/** convert for print */
|
||||
QSE_AWK_RTX_VALTOSTR_PRINT = 0x10
|
||||
};
|
||||
|
||||
/**
|
||||
@ -916,7 +921,7 @@ enum qse_awk_rtx_valtostr_type_t
|
||||
*/
|
||||
struct qse_awk_rtx_valtostr_out_t
|
||||
{
|
||||
int type;
|
||||
int type; /**< enum #qse_awk_rtx_valtostr_type_t */
|
||||
|
||||
union
|
||||
{
|
||||
@ -1086,7 +1091,8 @@ void qse_awk_geterrinf (
|
||||
void qse_awk_seterrnum (
|
||||
qse_awk_t* awk, /**< awk object */
|
||||
qse_awk_errnum_t errnum, /**< error number */
|
||||
const qse_cstr_t* errarg /**< arguments to format error message */
|
||||
const qse_cstr_t* errarg /**< argument array for formatting
|
||||
* an error message */
|
||||
);
|
||||
|
||||
void qse_awk_seterrinf (
|
||||
@ -1107,7 +1113,7 @@ void qse_awk_geterror (
|
||||
void qse_awk_seterror (
|
||||
qse_awk_t* awk, /**< awk object */
|
||||
qse_awk_errnum_t errnum, /**< error number */
|
||||
const qse_cstr_t* errarg, /**< array of arguments for formatting
|
||||
const qse_cstr_t* errarg, /**< argument array for formatting
|
||||
* an error message */
|
||||
const qse_awk_loc_t* errloc /**< error location */
|
||||
);
|
||||
@ -1171,7 +1177,7 @@ int qse_awk_setword (
|
||||
*/
|
||||
int qse_awk_addgbl (
|
||||
qse_awk_t* awk, /**< awk object */
|
||||
const qse_char_t* name, /**< a variable name */
|
||||
const qse_char_t* name, /**< variable name */
|
||||
qse_size_t len /**< name length */
|
||||
);
|
||||
|
||||
@ -1181,7 +1187,7 @@ int qse_awk_addgbl (
|
||||
*/
|
||||
int qse_awk_delgbl (
|
||||
qse_awk_t* awk, /**< awk object */
|
||||
const qse_char_t* name, /**< a variable name */
|
||||
const qse_char_t* name, /**< variable name */
|
||||
qse_size_t len /**< name length */
|
||||
);
|
||||
|
||||
@ -1300,7 +1306,7 @@ void qse_awk_free (
|
||||
*/
|
||||
qse_char_t* qse_awk_strdup (
|
||||
qse_awk_t* awk, /**< awk object */
|
||||
const qse_char_t* str /**< a string pointer */
|
||||
const qse_char_t* str /**< string pointer */
|
||||
);
|
||||
|
||||
/**
|
||||
@ -1314,8 +1320,8 @@ qse_char_t* qse_awk_strdup (
|
||||
*/
|
||||
qse_char_t* qse_awk_strxdup (
|
||||
qse_awk_t* awk, /**< awk object */
|
||||
const qse_char_t* str, /**< a string pointer */
|
||||
qse_size_t len /**< the number of character in a string */
|
||||
const qse_char_t* str, /**< string pointer */
|
||||
qse_size_t len /**< string length */
|
||||
);
|
||||
|
||||
qse_long_t qse_awk_strxtolong (
|
||||
@ -1343,14 +1349,21 @@ qse_size_t qse_awk_longtostr (
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_open() creates a runtime context.
|
||||
* @return a runtime context on success, #QSE_NULL on failure
|
||||
* The qse_awk_rtx_open() creates a runtime context associated with @a awk.
|
||||
* It also allocates an extra memory block as large as the @a xtn bytes.
|
||||
* You can get the pointer to the beginning of the block with
|
||||
* qse_awk_rtx_getxtn(). The block is destroyed when the runtime context is
|
||||
* destroyed. The argument array @a arg, if not #QSE_NULL, is used to set
|
||||
* @b ARGV. The @b ptr field and the @b len field of the last member of the
|
||||
* array must be set to #QSE_NULL and 0 respectively.
|
||||
*
|
||||
* @return new runtime context on success, #QSE_NULL on failure
|
||||
*/
|
||||
qse_awk_rtx_t* qse_awk_rtx_open (
|
||||
qse_awk_t* awk, /**< awk object */
|
||||
qse_size_t xtn, /**< size of extension in bytes */
|
||||
qse_awk_rio_t* rio, /**< runtime IO handlers */
|
||||
const qse_cstr_t* arg /**< arguments to set ARGV */
|
||||
const qse_cstr_t* arg /**< argument array to set ARGV */
|
||||
);
|
||||
|
||||
/**
|
||||
@ -1378,7 +1391,7 @@ void qse_awk_rtx_close (
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @return return value on success, QSE_NULL on failure.
|
||||
* @return return value on success, #QSE_NULL on failure.
|
||||
*/
|
||||
qse_awk_val_t* qse_awk_rtx_loop (
|
||||
qse_awk_rtx_t* rtx /**< runtime context */
|
||||
@ -1439,7 +1452,6 @@ void qse_awk_rtx_stop (
|
||||
* The qse_awk_rtx_setrcb() function gets runtime callbacks.
|
||||
* @return #QSE_NULL if no callback is set. Otherwise, the pointer to a
|
||||
* callback set.
|
||||
* @sa qse_awk_rtx_setrcb
|
||||
*/
|
||||
qse_awk_rcb_t* qse_awk_rtx_getrcb (
|
||||
qse_awk_rtx_t* rtx /**< runtime context */
|
||||
@ -1447,7 +1459,6 @@ qse_awk_rcb_t* qse_awk_rtx_getrcb (
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_setrcb() function sets runtime callbacks.
|
||||
* @sa qse_awk_rtx_getrcb
|
||||
*/
|
||||
void qse_awk_rtx_setrcb (
|
||||
qse_awk_rtx_t* rtx, /**< runtime context */
|
||||
@ -1540,7 +1551,7 @@ qse_mmgr_t* qse_awk_rtx_getmmgr (
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_getxtn() function gets the pointer to extension space.
|
||||
* The qse_awk_rtx_getxtn() function gets the pointer to the extension block.
|
||||
*/
|
||||
void* qse_awk_rtx_getxtn (
|
||||
qse_awk_rtx_t* rtx /**< runtime context */
|
||||
@ -1606,7 +1617,7 @@ void qse_awk_rtx_seterrinf (
|
||||
void qse_awk_rtx_seterror (
|
||||
qse_awk_rtx_t* rtx, /**< runtime context */
|
||||
qse_awk_errnum_t errnum, /**< error number */
|
||||
const qse_cstr_t* errarg, /**< array of arguments for formatting
|
||||
const qse_cstr_t* errarg, /**< argument array for formatting
|
||||
* an error message */
|
||||
const qse_awk_loc_t* errloc /**< error line */
|
||||
);
|
||||
@ -1730,23 +1741,23 @@ qse_bool_t qse_awk_rtx_valtobool (
|
||||
/**
|
||||
* The qse_awk_rtx_valtostr() function converts a value @a val to a string as
|
||||
* instructed in the parameter out. Before the call to the function, you
|
||||
* should initialize a variable of the qse_awk_rtx_valtostr_out_t type.
|
||||
* should initialize a variable of the #qse_awk_rtx_valtostr_out_t type.
|
||||
*
|
||||
* The type field is one of the following qse_awk_rtx_valtostr_type_t values:
|
||||
*
|
||||
* - QSE_AWK_RTX_VALTOSTR_CPL
|
||||
* - QSE_AWK_RTX_VALTOSTR_CPLDUP
|
||||
* - QSE_AWK_RTX_VALTOSTR_STRP
|
||||
* - QSE_AWK_RTX_VALTOSTR_STRPCAT
|
||||
* - #QSE_AWK_RTX_VALTOSTR_CPL
|
||||
* - #QSE_AWK_RTX_VALTOSTR_CPLDUP
|
||||
* - #QSE_AWK_RTX_VALTOSTR_STRP
|
||||
* - #QSE_AWK_RTX_VALTOSTR_STRPCAT
|
||||
*
|
||||
* It can optionally be ORed with QSE_AWK_RTX_VALTOSTR_PRINT. The option
|
||||
* It can optionally be ORed with #QSE_AWK_RTX_VALTOSTR_PRINT. The option
|
||||
* causes the function to use OFMT for real number conversion. Otherwise,
|
||||
* it uses CONVFMT.
|
||||
* it uses @b CONVFMT.
|
||||
*
|
||||
* You should initialize or free other fields before and after the call
|
||||
* depending on the type field as shown below:
|
||||
*
|
||||
* If you have a static buffer, use QSE_AWK_RTX_VALTOSTR_CPL.
|
||||
* If you have a static buffer, use #QSE_AWK_RTX_VALTOSTR_CPL.
|
||||
* @code
|
||||
* qse_awk_rtx_valtostr_out_t out;
|
||||
* qse_char_t buf[100];
|
||||
@ -1758,7 +1769,7 @@ qse_bool_t qse_awk_rtx_valtobool (
|
||||
* @endcode
|
||||
*
|
||||
* When unsure of the size of the string after conversion, you can use
|
||||
* QSE_AWK_RTX_VALTOSTR_CPLDUP. However, you should free the memory block
|
||||
* #QSE_AWK_RTX_VALTOSTR_CPLDUP. However, you should free the memory block
|
||||
* pointed to by the u.cpldup.ptr field after use.
|
||||
* @code
|
||||
* qse_awk_rtx_valtostr_out_t out;
|
||||
@ -1769,7 +1780,7 @@ qse_bool_t qse_awk_rtx_valtobool (
|
||||
* @endcode
|
||||
*
|
||||
* You may like to store the result in a dynamically resizable string.
|
||||
* Consider QSE_AWK_RTX_VALTOSTR_STRP.
|
||||
* Consider #QSE_AWK_RTX_VALTOSTR_STRP.
|
||||
* @code
|
||||
* qse_awk_rtx_valtostr_out_t out;
|
||||
* qse_str_t str;
|
||||
@ -1783,15 +1794,16 @@ qse_bool_t qse_awk_rtx_valtobool (
|
||||
* @endcode
|
||||
*
|
||||
* If you want to append the converted string to an existing dynamically
|
||||
* resizable string, QSE_AWK_RTX_VALTOSTR_STRPCAT is the answer. The usage is
|
||||
* the same as QSE_AWK_RTX_VALTOSTR_STRP except that you have to use the
|
||||
* resizable string, #QSE_AWK_RTX_VALTOSTR_STRPCAT is the answer. The usage is
|
||||
* the same as #QSE_AWK_RTX_VALTOSTR_STRP except that you have to use the
|
||||
* u.strpcat field instead of the u.strp field.
|
||||
*
|
||||
* In the context where @a val is determined to be of the type
|
||||
* #QSE_AWK_VAL_STR, you may access its string pointer and length directly
|
||||
* instead of calling this function.
|
||||
*
|
||||
* @return the pointer to a string converted on success, #QSE_NULL on failure
|
||||
* @return character pointer to a string converted on success,
|
||||
* #QSE_NULL on failure
|
||||
*/
|
||||
qse_char_t* qse_awk_rtx_valtostr (
|
||||
qse_awk_rtx_t* rtx, /**< runtime context */
|
||||
@ -1801,7 +1813,7 @@ qse_char_t* qse_awk_rtx_valtostr (
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_valtocpldup() function provides a shortcut to the
|
||||
* qse_awk_rtx_valtostr() function with the QSE_AWK_RTX_VALTOSTR_CPLDUP type.
|
||||
* qse_awk_rtx_valtostr() function with the #QSE_AWK_RTX_VALTOSTR_CPLDUP type.
|
||||
* It returns the pointer to a string converted from @a val and stores its
|
||||
* length to memory pointed to by @a len. You should free the returned
|
||||
* memory block after use. See the code snippet below for a simple usage.
|
||||
@ -1813,7 +1825,8 @@ qse_char_t* qse_awk_rtx_valtostr (
|
||||
* qse_awk_rtx_free (rtx, ptr);
|
||||
* @endcode
|
||||
*
|
||||
* @return the pointer to a string converted on success, #QSE_NULL on failure
|
||||
* @return character pointer to a string converted on success,
|
||||
* #QSE_NULL on failure
|
||||
*/
|
||||
qse_char_t* qse_awk_rtx_valtocpldup (
|
||||
qse_awk_rtx_t* rtx, /**< runtime context */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: std.h 273 2009-08-28 11:58:05Z hyunghwan.chung $
|
||||
* $Id: std.h 277 2009-09-02 12:55:55Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
* - add code to treat a function as a value
|
||||
* - add RQ and LQ for more powerful record splitting
|
||||
* - improve performance in qse_awk_rtx_readio() if RS is logner than 2 chars.
|
||||
* - implement 'include'
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: pio.h 275 2009-08-30 13:19:02Z hyunghwan.chung $
|
||||
* $Id: pio.h 277 2009-09-02 12:55:55Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -27,8 +27,6 @@
|
||||
* This file defines a piped interface to a child process. You can execute
|
||||
* a child process, read and write to its stdin, stdout, stderr, and terminate
|
||||
* it. It provides more advanced interface than popen() and pclose().
|
||||
*
|
||||
* @example pio.c
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: sll.h 90 2009-03-01 09:58:19Z hyunghwan.chung $
|
||||
* $Id: sll.h 277 2009-09-02 12:55:55Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -22,149 +22,102 @@
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/****o* Common/Singly Linked List
|
||||
* DESCRIPTION
|
||||
* <qse/cmn/sll.h> provides a singly linked list.
|
||||
*
|
||||
* #include <qse/cmn/sll.h>
|
||||
******
|
||||
/** @file
|
||||
* Singly linked list
|
||||
*/
|
||||
|
||||
/****t* Common/qse_sll_walk_t
|
||||
* NAME
|
||||
* qse_sll_walk_t - define return values for qse_sll_walker_t
|
||||
* SEE ALSO
|
||||
* qse_sll_walker_t
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_sll_walk_t type defines a value that qse_sll_walker_t can return.
|
||||
*/
|
||||
enum qse_sll_walk_t
|
||||
{
|
||||
QSE_SLL_WALK_STOP = 0,
|
||||
QSE_SLL_WALK_FORWARD = 1
|
||||
QSE_SLL_WALK_STOP = 0, /**< stop traversal */
|
||||
QSE_SLL_WALK_FORWARD = 1 /**< traverse to the next node */
|
||||
};
|
||||
/******/
|
||||
|
||||
typedef struct qse_sll_t qse_sll_t;
|
||||
typedef struct qse_sll_node_t qse_sll_node_t;
|
||||
typedef enum qse_sll_walk_t qse_sll_walk_t;
|
||||
|
||||
/****t* Common/qse_sll_copier_t
|
||||
* NAME
|
||||
* qse_sll_copier_t - define a node contruction callback
|
||||
* DESCRIPTION
|
||||
* The qse_sll_copier_t defines a callback function for node construction.
|
||||
* A node is contructed when a user adds data to a list. The user can
|
||||
* define how the data to add can be maintained in the list. A singly
|
||||
* linked list not specified with any copiers stores the data pointer and
|
||||
* the data length into a node. A special copier QSE_SLL_COPIER_INLINE copies
|
||||
* the contents of the data a user provided into the node. You can use the
|
||||
* qse_sll_setcopier() function to change the copier.
|
||||
/**
|
||||
* The qse_sll_copier_t type defines a callback function for node construction.
|
||||
* A node is contructed when a user adds data to a list. The user can
|
||||
* define how the data to add can be maintained in the list. A singly
|
||||
* linked list not specified with any copiers stores the data pointer and
|
||||
* the data length into a node. A special copier QSE_SLL_COPIER_INLINE copies
|
||||
* the contents of the data a user provided into the node. You can use the
|
||||
* qse_sll_setcopier() function to change the copier.
|
||||
*
|
||||
* A copier should return the pointer to the copied data. If it fails to copy
|
||||
* data, it may return QSE_NULL. You need to set a proper freeer to free up
|
||||
* memory allocated for copy.
|
||||
* SEE ALSO
|
||||
* qse_sll_setcopier, qse_sll_getcopier, QSE_SLL_COPIER
|
||||
* SYNOPSIS
|
||||
* A copier should return the pointer to the copied data. If it fails to copy
|
||||
* data, it may return QSE_NULL. You need to set a proper freeer to free up
|
||||
* memory allocated for copy.
|
||||
*/
|
||||
typedef void* (*qse_sll_copier_t) (
|
||||
qse_sll_t* sll /* a map */,
|
||||
void* dptr /* the pointer to data to copy */,
|
||||
qse_size_t dlen /* the length of data to copy */
|
||||
qse_sll_t* sll, /**< singly linked list */
|
||||
void* dptr, /**< pointer to data to copy */
|
||||
qse_size_t dlen /**< length of data to copy */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* Common/qse_sll_freeer_t
|
||||
* NAME
|
||||
* qse_sll_freeer_t - define a node destruction callback
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_sll_freeer_t type defines a node destruction callback.
|
||||
*/
|
||||
typedef void (*qse_sll_freeer_t) (
|
||||
qse_sll_t* sll /* a map */,
|
||||
void* dptr /* the pointer to data to free */,
|
||||
qse_size_t dlen /* the length of data to free */
|
||||
qse_sll_t* sll, /**< singly linked list */
|
||||
void* dptr, /**< pointer to data to free */
|
||||
qse_size_t dlen /**< length of data to free */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* Common/qse_sll_comper_t
|
||||
* NAME
|
||||
* qse_sll_comper_t - define a data comparator
|
||||
/**
|
||||
* The qse_sll_comper_t type defines a key comparator that is called when
|
||||
* the list needs to compare data. A singly linked list is created with a
|
||||
* default comparator that performs bitwise comparison.
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_comper_t type defines a key comparator that is called when
|
||||
* the list needs to compare data. A singly linked list is created with a
|
||||
* default comparator that performs bitwise comparison.
|
||||
*
|
||||
* The comparator should return 0 if the data are the same and a non-zero
|
||||
* integer otherwise.
|
||||
*
|
||||
* SYNOPSIS
|
||||
* The comparator must return 0 if the data are the same and a non-zero
|
||||
* integer otherwise.
|
||||
*/
|
||||
typedef int (*qse_sll_comper_t) (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
const void* dptr1 /* a data pointer */,
|
||||
qse_size_t dlen1 /* a data length */,
|
||||
const void* dptr2 /* a data pointer */,
|
||||
qse_size_t dlen2 /* a data length */
|
||||
qse_sll_t* sll, /**< singly linked list */
|
||||
const void* dptr1, /**< data pointer */
|
||||
qse_size_t dlen1, /**< data length */
|
||||
const void* dptr2, /**< data pointer */
|
||||
qse_size_t dlen2 /**< data length */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* Common/qse_sll_walker_t
|
||||
* NAME
|
||||
* qse_sll_walker_t - define a list traversal callback for each node
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_walk() calls a callback function of the type qse_sll_walker_t
|
||||
* for each node until it returns QSE_SLL_WALK_STOP. The walker should return
|
||||
* QSE_SLL_WALK_FORWARD to let qse_sll_walk() continue visiting the next node.
|
||||
* The third parameter to qse_sll_walk() is passed to the walker as the third
|
||||
* parameter.
|
||||
*
|
||||
* SEE ALSO
|
||||
* qse_sll_walk, qse_sll_walk_t
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_sll_walker_t type defines a list traversal callback for each node.
|
||||
* The qse_sll_walk() calls a callback function of the type qse_sll_walker_t
|
||||
* for each node until it returns QSE_SLL_WALK_STOP. The walker should return
|
||||
* QSE_SLL_WALK_FORWARD to let qse_sll_walk() continue visiting the next node.
|
||||
* The third parameter to qse_sll_walk() is passed to the walker as the third
|
||||
* parameter.
|
||||
*/
|
||||
typedef qse_sll_walk_t (*qse_sll_walker_t) (
|
||||
qse_sll_t* sll /* a map */,
|
||||
qse_sll_node_t* node /* a visited node */,
|
||||
void* arg /* user-defined data */
|
||||
qse_sll_t* sll, /* singly linked list */
|
||||
qse_sll_node_t* node, /* visited node */
|
||||
void* arg /* user-defined data */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****s* Common/qse_sll_t
|
||||
* NAME
|
||||
* qse_sll_t - define a singly linked list
|
||||
*
|
||||
* DESCRPTION
|
||||
* The qse_sll_t type defines a singly lnked list.
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_sll_t type defines a singly lnked list.
|
||||
*/
|
||||
struct qse_sll_t
|
||||
{
|
||||
QSE_DEFINE_COMMON_FIELDS (sll)
|
||||
|
||||
qse_sll_copier_t copier; /* data copier */
|
||||
qse_sll_freeer_t freeer; /* data freeer */
|
||||
qse_sll_comper_t comper; /* data comparator */
|
||||
qse_byte_t scale; /* scale factor */
|
||||
qse_sll_copier_t copier; /**< data copier */
|
||||
qse_sll_freeer_t freeer; /**< data freeer */
|
||||
qse_sll_comper_t comper; /**< data comparator */
|
||||
qse_byte_t scale; /**< scale factor */
|
||||
|
||||
qse_size_t size; /* the number of nodes */
|
||||
qse_sll_node_t* head; /* the head node */
|
||||
qse_sll_node_t* tail; /* the tail node */
|
||||
qse_size_t size; /**< number of nodes */
|
||||
qse_sll_node_t* head; /**< head node */
|
||||
qse_sll_node_t* tail; /**< tail node */
|
||||
};
|
||||
/******/
|
||||
|
||||
/****s* Common/qse_sll_node_t
|
||||
* NAME
|
||||
* qse_sll_node_t - define a list node
|
||||
* DESCRIPTION
|
||||
* The qse_sll_node_t type defines a list node containing a data pointer and
|
||||
* and data length.
|
||||
* SEE ALSO
|
||||
* QSE_SLL_DPTR, QSE_SLL_DLEN, QSE_SLL_NEXT
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_sll_node_t type defines a list node containing a data pointer and
|
||||
* and data length.
|
||||
*/
|
||||
struct qse_sll_node_t
|
||||
{
|
||||
@ -172,7 +125,6 @@ struct qse_sll_node_t
|
||||
qse_size_t dlen; /* the length of data */
|
||||
qse_sll_node_t* next; /* the pointer to the next node */
|
||||
};
|
||||
/******/
|
||||
|
||||
#define QSE_SLL_COPIER_SIMPLE ((qse_sll_copier_t)1)
|
||||
#define QSE_SLL_COPIER_INLINE ((qse_sll_copier_t)2)
|
||||
@ -186,29 +138,20 @@ struct qse_sll_node_t
|
||||
#define QSE_SLL_SIZE(sll) ((sll)->size)
|
||||
#define QSE_SLL_SCALE(sll) ((sll)->scale)
|
||||
|
||||
/****m* Common/QSE_SLL_DPTR
|
||||
* NAME
|
||||
* QSE_SLL_DPTR - get the data pointer in a node
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The QSE_SLL_DPTR macro gets the data pointer in a node.
|
||||
*/
|
||||
#define QSE_SLL_DPTR(node) ((node)->dptr)
|
||||
/******/
|
||||
|
||||
/****m* Common/QSE_SLL_DLEN
|
||||
* NAME
|
||||
* QSE_SLL_DLEN - get the length of data in a node
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The QSE_SLL_DLEN macro gets the length of data in a node.
|
||||
*/
|
||||
#define QSE_SLL_DLEN(node) ((node)->dlen)
|
||||
/******/
|
||||
|
||||
/****m* Common/QSE_SLL_NEXT
|
||||
* NAME
|
||||
* QSE_SLL_NEXT - get the next node
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The QSE_SLL_NEXT macro gets the next node.
|
||||
*/
|
||||
#define QSE_SLL_NEXT(node) ((node)->next)
|
||||
/******/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -216,35 +159,27 @@ extern "C" {
|
||||
|
||||
QSE_DEFINE_COMMON_FUNCTIONS (sll)
|
||||
|
||||
/****f* Common/qse_sll_open
|
||||
* NAME
|
||||
* qse_sll_open - create a singly linked list with extension area
|
||||
/**
|
||||
* The qse_sll_open() function creates an empty singly linked list.
|
||||
* If the memory manager mmgr is QSE_NULL, the function gets the default
|
||||
* memory manager with QSE_MMGR_GETDFL() and uses it if it is not QSE_NULL.
|
||||
* The extension area is allocated when the positive extension size extension
|
||||
* is specified. It calls the extension initialization function initializer
|
||||
* after initializing the main area. The extension initializer is passed
|
||||
* the pointer to the singly linked list created.
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_open() function creates an empty singly linked list.
|
||||
* If the memory manager mmgr is QSE_NULL, the function gets the default
|
||||
* memory manager with QSE_MMGR_GETMMGR() and uses it if it is not QSE_NULL.
|
||||
* The extension area is allocated when the positive extension size extension
|
||||
* is specified. It calls the extension initialization function initializer
|
||||
* after initializing the main area. The extension initializer is passed
|
||||
* the pointer to the singly linked list created.
|
||||
* @return pointer to a new singly linked list on success,
|
||||
* QSE_NULL on failure
|
||||
*
|
||||
* RETURN
|
||||
* The qse_sll_open() function returns the pointer to a new singly linked
|
||||
* list on success and QSE_NULL on failure.
|
||||
*
|
||||
* NOTES
|
||||
* In the debug build, it fails an assertion if QSE_MMGR_GETMMGR() returns
|
||||
* QSE_NULL when QSE_NULL is passed as the first parameter. In the release
|
||||
* build, it returns QSE_NULL if such a thing happens.
|
||||
*
|
||||
* SYNOPSIS
|
||||
* @note
|
||||
* In the debug build, it fails an assertion if QSE_MMGR_GETDFL() returns
|
||||
* QSE_NULL and @a mmgr is QSE_NULL. In the release build, it returns QSE_NULL
|
||||
* in such case.
|
||||
*/
|
||||
qse_sll_t* qse_sll_open (
|
||||
qse_mmgr_t* mmgr /* memory manager */ ,
|
||||
qse_mmgr_t* mmgr, /* memory manager */
|
||||
qse_size_t ext /* size of extension area in bytes */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_sll_close
|
||||
* NAME
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: str.h 140 2009-05-18 12:55:01Z hyunghwan.chung $
|
||||
* $Id: str.h 277 2009-09-02 12:55:55Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -28,8 +28,6 @@
|
||||
*
|
||||
* The qse_cstr_t type and the qse_xstr_t defined in <qse/types.h> helps you
|
||||
* dealing with a string pointer and length.
|
||||
*
|
||||
* @example str.c
|
||||
*/
|
||||
|
||||
#define QSE_STR_LEN(s) ((s)->len)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: sed.h 276 2009-08-31 13:24:06Z hyunghwan.chung $
|
||||
* $Id: sed.h 277 2009-09-02 12:55:55Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -41,8 +41,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example sed01.c
|
||||
* This example shows how to embed a basic stream editor.
|
||||
* @example sed.c
|
||||
* This example shows how to write a basic stream editor.
|
||||
*/
|
||||
|
||||
/** @struct qse_sed_t
|
||||
@ -200,6 +200,16 @@ typedef qse_ssize_t (*qse_sed_io_fun_t) (
|
||||
qse_sed_io_arg_t* arg
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_lformatter_t type defines a text formatter for the 'l' command.
|
||||
*/
|
||||
typedef int (*qse_sed_lformatter_t) (
|
||||
qse_sed_t* sed,
|
||||
const qse_char_t* str,
|
||||
qse_size_t len,
|
||||
int (*cwriter) (qse_sed_t*, qse_char_t)
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -390,6 +400,24 @@ int qse_sed_exec (
|
||||
qse_sed_io_fun_t outf /**< stream writer */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_getlformatter() function gets the text formatter for the 'l'
|
||||
* command.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
void qse_sed_setlformatter (
|
||||
qse_sed_t* sed, /**< stream editor */
|
||||
qse_sed_lformatter_t lformatter /**< text formatter */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_getlinnum() function gets the current input line number.
|
||||
* @return current input line number
|
||||
|
Reference in New Issue
Block a user