touched up code a little

This commit is contained in:
2009-07-02 07:14:39 +00:00
parent dd36ca0725
commit d725c01bac
15 changed files with 858 additions and 438 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp 213 2009-06-26 13:05:19Z hyunghwan.chung $
* $Id: Awk.hpp 220 2009-07-01 13:14:39Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -405,17 +405,9 @@ public:
ERR_NOMEM = QSE_AWK_ENOMEM,
ERR_NOSUP = QSE_AWK_ENOSUP,
ERR_NOPER = QSE_AWK_ENOPER,
ERR_NODEV = QSE_AWK_ENODEV,
ERR_NOSPC = QSE_AWK_ENOSPC,
ERR_MFILE = QSE_AWK_EMFILE,
ERR_MLINK = QSE_AWK_EMLINK,
ERR_AGAIN = QSE_AWK_EAGAIN,
ERR_NOENT = QSE_AWK_ENOENT,
ERR_EXIST = QSE_AWK_EEXIST,
ERR_FTBIG = QSE_AWK_EFTBIG,
ERR_TBUSY = QSE_AWK_ETBUSY,
ERR_ISDIR = QSE_AWK_EISDIR,
ERR_IOERR = QSE_AWK_RIOERR,
ERR_IOERR = QSE_AWK_EIOERR,
ERR_OPEN = QSE_AWK_EOPEN,
ERR_READ = QSE_AWK_EREAD,
ERR_WRITE = QSE_AWK_EWRITE,
@ -487,7 +479,7 @@ public:
ERR_POSIDX = QSE_AWK_EPOSIDX,
ERR_ARGTF = QSE_AWK_EARGTF,
ERR_ARGTM = QSE_AWK_EARGTM,
ERR_FUNNONE = QSE_AWK_EFUNNONE,
ERR_FUNNF = QSE_AWK_EFUNNF,
ERR_NOTIDX = QSE_AWK_ENOTIDX,
ERR_NOTDEL = QSE_AWK_ENOTDEL,
ERR_NOTMAP = QSE_AWK_ENOTMAP,
@ -835,39 +827,38 @@ public:
* override Awk::openSource, Awk::closeSource, Awk::readSource,
* Awk::writeSource to implement the source code stream.
*
* @return
* On success, 0 is returned. On failure, -1 is returned and
* extended error information is set. Call Awk::getErrorNumber
* to get it.
* @return 0 on success, -1 on failure
*/
virtual int parse ();
/**
* Executes the parse tree.
*
* This method executes the parse tree formed by Awk::parse.
*
* @param args Pointer to an array of character strings.
* If it is specified, the charater strings are passed to
* an AWK program. The values can be accesed with ARGC & ARGV
* inside the AWK program.
* @param nargs Number of character strings in the array
*
* @return
* On success, 0 is returned. On failure, -1 is returned if
* the run-time callback is not enabled. If the run-time callback
* is enabled, 0 is returned and the error is indicated through
* Awk::onRunEnd. The run-time callback is enabled and disbaled
* with Awk::enableRunCallback and Awk::disableRunCallback.
* Call Awk::getErrorNumber to get extended error information.
* Executes the BEGIN block, pattern-action blocks, and the END block.
* @return 0 on succes, -1 on failure
*/
virtual int run (const char_t** args = QSE_NULL, size_t nargs = 0);
virtual int loop ();
/**
* Requests aborting execution of the parse tree
* Makes request to abort execution
*/
virtual void stop ();
/**
* Adds a string for ARGV. loop() and call() makes a string added
* available to a script through ARGV. Note this is not related to
* the Awk::Argument class.
*/
virtual int addArgument (
const char_t* arg,
size_t len
);
virtual int addArgument (const char_t* arg);
/**
* Deletes all ARGV strings.
*/
virtual void clearArguments ();
/**
* Adds a intrinsic global variable.
*/
@ -1018,9 +1009,9 @@ protected:
/*@}*/
// run-time callbacks
virtual bool onRunEnter (Run& run);
virtual void onRunExit (Run& run, const Argument& ret);
virtual void onRunStatement (Run& run, size_t line);
virtual bool onLoopEnter (Run& run);
virtual void onLoopExit (Run& run, const Argument& ret);
virtual void onStatement (Run& run, size_t line);
// primitive handlers
virtual real_t pow (real_t x, real_t y) = 0;
@ -1047,9 +1038,9 @@ protected:
rtx_t* rtx, const char_t* name, size_t len);
static void freeFunctionMapValue (map_t* map, void* dptr, size_t dlen);
static int onRunEnter (rtx_t* run, void* data);
static void onRunExit (rtx_t* run, val_t* ret, void* data);
static void onRunStatement (rtx_t* run, size_t line, void* data);
static int onLoopEnter (rtx_t* run, void* data);
static void onLoopExit (rtx_t* run, val_t* ret, void* data);
static void onStatement (rtx_t* run, size_t line, void* data);
static real_t pow (awk_t* data, real_t x, real_t y);
static int sprintf (awk_t* data, char_t* buf, size_t size,
@ -1069,6 +1060,13 @@ protected:
bool runCallback;
struct
{
qse_xstr_t* ptr;
size_t len;
size_t capa;
} runarg;
private:
static const char_t* xerrstr (awk_t* a, errnum_t num) throw ();

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.hpp 211 2009-06-24 09:50:10Z hyunghwan.chung $
* $Id: StdAwk.hpp 220 2009-07-01 13:14:39Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -39,7 +39,6 @@ class StdAwk: public Awk
{
public:
int open ();
int run (const char_t** args, size_t nargs);
protected:
@ -83,6 +82,16 @@ protected:
ssize_t writeFile (File& io, const char_t* buf, size_t len);
int flushFile (File& io);
#if 0
// console io handlers
int openConsole (Console& io);
int closeConsole (Console& io);
ssize_t readConsole (Console& io, char_t* buf, size_t len);
ssize_t writeConsole (Console& io, const char_t* buf, size_t len);
int flushConsole (Console& io);
int nextConsole (Console& io);
#endif
// primitive handlers
void* allocMem (size_t n) throw ();
void* reallocMem (void* ptr, size_t n) throw ();
@ -94,6 +103,7 @@ protected:
protected:
unsigned int seed;
size_t runarg_index;
};
/////////////////////////////////

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 217 2009-06-28 13:41:47Z hyunghwan.chung $
* $Id: awk.h 220 2009-07-01 13:14:39Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -25,7 +25,7 @@
#include <qse/cmn/str.h>
/** @file
* An embeddable AWK interpreter is defined in this header files.
* An embeddable AWK interpreter is defined in this header file.
*
* @example awk.c
* This program demonstrates how to build a complete awk interpreter.
@ -51,10 +51,13 @@
* @code
* qse_awk_t* awk;
* qse_awk_rtx_t* rtx;
* qse_awk_sio_t sio; // need to initialize it with callback functions
* qse_awk_rio_t rio; // need to initialize it with callback functions
* qse_cstr_t args[5]; // need to initialize it with strings
*
* awk = qse_awk_open (mmgr, 0, prm); // create an interpreter
* qse_awk_parse (awk, sio); // parse a script
* rtx = qse_awk_rtx_open (awk, 0, rio, args); // create a runtime context
* qse_awk_parse (awk, &sio); // parse a script
* rtx = qse_awk_rtx_open (awk, 0, &rio, args); // create a runtime context
* qse_awk_rtx_loop (rtx); // run a standard AWK loop
* qse_awk_rtx_close (rtx); // destroy the runtime context
* qse_awk_close (awk); // destroy the interpreter
@ -78,14 +81,30 @@ typedef struct qse_awk_t qse_awk_t;
* qse_awk_rtx_open().
*
* I/O handlers are categoriezed into three kinds: console, file, pipe.
* The #qse_awk_rio_t type defines a set of I/O handlers as a callback.
* The #qse_awk_rio_t type defines as a callback a set of I/O handlers
* to handle runtime I/O:
* - getline piped in from a command reads from a pipe.
* ("ls -l" | getline line)
* - print and printf piped out to a command writes to a pipe.
* (print 2 | "sort")
* - getline redirected in reads from a file.
* (getline line < "file")
* - print and printf redirected out writes to a file.
* (print num > "file")
* - The pattern-action loop and getline with no redirected input
* reads from a console. (/susie/ { ... })
* - print and printf writes to a console. (print "hello, world")
*
* @sa qse_awk_t qse_awk_rtx_open qse_awk_rio_t
*/
typedef struct qse_awk_rtx_t qse_awk_rtx_t;
/**
* The QSE_AWK_VAL_HDR defines the common header of a value type.
* The QSE_AWK_VAL_HDR defines the common header for a value.
* Three common fields are:
* - type - type of a value from #qse_awk_val_type_t
* - ref - reference count
* - nstr - numeric string marker
*/
#if QSE_SIZEOF_INT == 2
# define QSE_AWK_VAL_HDR \
@ -99,8 +118,6 @@ typedef struct qse_awk_rtx_t qse_awk_rtx_t;
unsigned int nstr: 2
#endif
#define QSE_AWK_VAL_TYPE(x) ((x)->type)
/**
* The qse_awk_val_t type is an abstract value type. A value commonly contains:
* - type of a value
@ -196,7 +213,21 @@ struct qse_awk_val_ref_t
{
QSE_AWK_VAL_HDR;
int id;
enum
{
/* keep these items in the same order as corresponding items
* in tree.h */
QSE_AWK_VAL_REF_NAMED, /**< plain named variable */
QSE_AWK_VAL_REF_GBL, /**< plain global variable */
QSE_AWK_VAL_REF_LCL, /**< plain local variable */
QSE_AWK_VAL_REF_ARG, /**< plain function argument */
QSE_AWK_VAL_REF_NAMEDIDX, /**< member of named map variable */
QSE_AWK_VAL_REF_GBLIDX, /**< member of global map variable */
QSE_AWK_VAL_REF_LCLIDX, /**< member of local map variable */
QSE_AWK_VAL_REF_ARGIDX, /**< member of map argument */
QSE_AWK_VAL_REF_POS /**< positional variable */
} id;
/* if id is QSE_AWK_VAL_REF_POS, adr holds an index of the
* positional variable. Otherwise, adr points to the value
* directly. */
@ -250,36 +281,46 @@ typedef qse_ssize_t (*qse_awk_sio_fun_t) (
);
/**
* The qse_awk_rio_cmd_t type defines runtime IO commands.
* The qse_awk_rio_cmd_t type defines runtime I/O request types.
*/
enum qse_awk_rio_cmd_t
{
QSE_AWK_RIO_OPEN = 0,
QSE_AWK_RIO_CLOSE = 1,
QSE_AWK_RIO_READ = 2,
QSE_AWK_RIO_WRITE = 3,
QSE_AWK_RIO_FLUSH = 4,
QSE_AWK_RIO_NEXT = 5
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_NEXT = 5 /**< close the current stream and
open the next stream. only for console */
};
typedef enum qse_awk_rio_cmd_t qse_awk_rio_cmd_t;
/**
* The qse_awk_rio_mode_t type defines the I/O modes used by I/O handlers.
* Each I/O handler should inspect the requested mode and open an I/O
* stream accordingly for subsequent operations.
*/
enum qse_awk_rio_mode_t
{
QSE_AWK_RIO_PIPE_READ = 0,
QSE_AWK_RIO_PIPE_WRITE = 1,
QSE_AWK_RIO_PIPE_RW = 2,
QSE_AWK_RIO_PIPE_READ = 0, /**< open a pipe for read */
QSE_AWK_RIO_PIPE_WRITE = 1, /**< open a pipe for write */
QSE_AWK_RIO_PIPE_RW = 2, /**< open a pipe for read and write */
QSE_AWK_RIO_FILE_READ = 0,
QSE_AWK_RIO_FILE_WRITE = 1,
QSE_AWK_RIO_FILE_APPEND = 2,
QSE_AWK_RIO_FILE_READ = 0, /**< open a file for read */
QSE_AWK_RIO_FILE_WRITE = 1, /**< open a file for write */
QSE_AWK_RIO_FILE_APPEND = 2, /**< open a file for append */
QSE_AWK_RIO_CONSOLE_READ = 0,
QSE_AWK_RIO_CONSOLE_WRITE = 1
QSE_AWK_RIO_CONSOLE_READ = 0, /**< open a console for read */
QSE_AWK_RIO_CONSOLE_WRITE = 1 /**< open a console for write */
};
typedef enum qse_awk_rio_mode_t qse_awk_rio_mode_t;
/**
* The qse_awk_rio_arg_t defines the data passed to a rio function
* The qse_awk_rio_arg_t defines the data structure passed to a runtime
* I/O handler. An I/O handler should inspect the @a mode field and the
* @a name field and store an open handle to the @handle field when
* #QSE_AWK_RIO_OPEN is requested. For other request type, it can refer
* to the handle field set previously.
*/
struct qse_awk_rio_arg_t
{
@ -288,7 +329,6 @@ struct qse_awk_rio_arg_t
void* handle; /**< [OUT] I/O handle set by a handler */
/*-- from here down, internal use only --*/
int type;
struct
@ -411,30 +451,47 @@ typedef struct qse_awk_sio_t qse_awk_sio_t;
/**
* The qse_awk_rio_t type defines a runtime I/O handler set.
* @sa qse_awk_rtx_t
*/
struct qse_awk_rio_t
{
qse_awk_rio_fun_t pipe;
qse_awk_rio_fun_t file;
qse_awk_rio_fun_t console;
qse_awk_rio_fun_t pipe; /**< pipe handler */
qse_awk_rio_fun_t file; /**< file handler */
qse_awk_rio_fun_t console; /**< console handler */
};
typedef struct qse_awk_rio_t qse_awk_rio_t;
/**
* The qse_awk_rcb_t type defines runtime callbacks
* The qse_awk_rcb_t type defines runtime callbacks. You may set callbacks
* with qse_awk_rtx_setrcb() to be informed of important events during runtime.
*/
struct qse_awk_rcb_t
{
/**
* called by qse_awk_rtx_loop() before entering pattern-action loop.
* A @b BEGIN block is executed after this callback.
*/
int (*on_loop_enter) (
qse_awk_rtx_t* rtx, void* data);
qse_awk_rtx_t* rtx, void* udd);
/**
* called by qse_awk_rtx_loop() when exiting pattern-action loop.
* An @b END block is executed before this callback.
*/
void (*on_loop_exit) (
qse_awk_rtx_t* rtx, qse_awk_val_t* ret, void* data);
qse_awk_rtx_t* rtx, qse_awk_val_t* ret, void* udd);
/**
* called by qse_awk_rtx_loop() and qse_awk_rtx_call() for
* each statement executed.
*/
void (*on_statement) (
qse_awk_rtx_t* rtx, qse_size_t line, void* data);
qse_awk_rtx_t* rtx, qse_size_t line, void* udd);
void* data;
/**
* A caller may store a custom data pointer into this field.
*/
void* udd;
};
typedef struct qse_awk_rcb_t qse_awk_rcb_t;
@ -467,7 +524,7 @@ enum qse_awk_option_t
/** supports @b getline and @b print */
QSE_AWK_RIO = (1 << 7),
/** supports dual direction pipe if QSE_AWK_RIO is on */
/** supports dual direction pipe if #QSE_AWK_RIO is on */
QSE_AWK_RWPIPE = (1 << 8),
/** a new line can terminate a statement */
@ -518,7 +575,7 @@ enum qse_awk_option_t
QSE_AWK_NCMPONSTR = (1 << 17),
/**
* strict naming rule
* enables the strict naming rule.
* - a parameter can not be the same as the owning function name.
* - a local variable can not be the same as the owning function name.
*/
@ -538,154 +595,145 @@ enum qse_awk_option_t
*/
enum qse_awk_errnum_t
{
QSE_AWK_ENOERR, /* no error */
QSE_AWK_EUNKNOWN, /* unknown error */
QSE_AWK_ENOERR, /**< no error */
QSE_AWK_EUNKNOWN,/**< unknown error */
/* common errors */
QSE_AWK_EINVAL, /* invalid parameter or data */
QSE_AWK_ENOMEM, /* out of memory */
QSE_AWK_ENOSUP, /* not supported */
QSE_AWK_ENOPER, /* operation not allowed */
QSE_AWK_ENODEV, /* no such device */
QSE_AWK_ENOSPC, /* no space left on device */
QSE_AWK_EMFILE, /* too many open files */
QSE_AWK_EMLINK, /* too many links */
QSE_AWK_EAGAIN, /* resource temporarily unavailable */
QSE_AWK_ENOENT, /* '${1}' not existing */
QSE_AWK_EEXIST, /* file or data exists */
QSE_AWK_EFTBIG, /* file or data too big */
QSE_AWK_ETBUSY, /* system too busy */
QSE_AWK_EISDIR, /* is a directory */
QSE_AWK_RIOERR, /* i/o error */
QSE_AWK_EINVAL, /**< invalid parameter or data */
QSE_AWK_ENOMEM, /**< insufficient memory */
QSE_AWK_ENOSUP, /**< not supported */
QSE_AWK_ENOPER, /**< operation not allowed */
QSE_AWK_ENOENT, /**< '${0}' not found */
QSE_AWK_EEXIST, /**< '${0}' already exists */
QSE_AWK_EIOERR, /**< I/O error */
/* mostly parse errors */
QSE_AWK_EOPEN, /* cannot open */
QSE_AWK_EREAD, /* cannot read */
QSE_AWK_EWRITE, /* cannot write */
QSE_AWK_ECLOSE, /* cannot close */
QSE_AWK_EOPEN, /**< cannot open '${0}' */
QSE_AWK_EREAD, /**< cannot read '${0}' */
QSE_AWK_EWRITE, /**< cannot write '${0}' */
QSE_AWK_ECLOSE, /**< cannot close '${0}' */
QSE_AWK_EINTERN, /* internal error */
QSE_AWK_ERUNTIME, /* run-time error */
QSE_AWK_EBLKNST, /* blocke nested too deeply */
QSE_AWK_EEXPRNST, /* expression nested too deeply */
QSE_AWK_EINTERN, /**< internal error */
QSE_AWK_ERUNTIME,/**< general run-time error */
QSE_AWK_EBLKNST, /**< block nested too deeply */
QSE_AWK_EEXPRNST,/**< expression nested too deeply */
QSE_AWK_ESINOP, /* failed to open source input */
QSE_AWK_ESINCL, /* failed to close source output */
QSE_AWK_ESINRD, /* failed to read source input */
QSE_AWK_ESINOP, /**< failed to open source input */
QSE_AWK_ESINCL, /**< failed to close source output */
QSE_AWK_ESINRD, /**< failed to read source input */
QSE_AWK_ESOUTOP, /* failed to open source output */
QSE_AWK_ESOUTCL, /* failed to close source output */
QSE_AWK_ESOUTWR, /* failed to write source output */
QSE_AWK_ESOUTOP, /**< failed to open source output */
QSE_AWK_ESOUTCL, /**< failed to close source output */
QSE_AWK_ESOUTWR, /**< failed to write source output */
QSE_AWK_ELXCHR, /* lexer came accross an wrong character */
QSE_AWK_ELXDIG, /* invalid digit */
QSE_AWK_ELXUNG, /* lexer failed to unget a character */
QSE_AWK_ELXCHR, /**< invalid character '${0}' */
QSE_AWK_ELXDIG, /**< invalid digit '${0}' */
QSE_AWK_ELXUNG, /**< failed to unget character */
QSE_AWK_EENDSRC, /* unexpected end of source */
QSE_AWK_EENDCMT, /* a comment not closed properly */
QSE_AWK_EENDSTR, /* a string not closed with a quote */
QSE_AWK_EENDREX, /* unexpected end of a regular expression */
QSE_AWK_ELBRACE, /* left brace expected */
QSE_AWK_ELPAREN, /* left parenthesis expected */
QSE_AWK_ERPAREN, /* right parenthesis expected */
QSE_AWK_ERBRACK, /* right bracket expected */
QSE_AWK_ECOMMA, /* comma expected */
QSE_AWK_ESCOLON, /* semicolon expected */
QSE_AWK_ECOLON, /* colon expected */
QSE_AWK_ESTMEND, /* statement not ending with a semicolon */
QSE_AWK_EIN, /* keyword 'in' is expected */
QSE_AWK_ENOTVAR, /* not a variable name after 'in' */
QSE_AWK_EEXPRES, /* expression expected */
QSE_AWK_EENDSRC, /**< unexpected end of source */
QSE_AWK_EENDCMT, /**< comment not closed properly */
QSE_AWK_EENDSTR, /**< string or regular expression not closed */
QSE_AWK_EENDREX, /**< unexpected end of regular expression */
QSE_AWK_ELBRACE, /**< left brace expected in place of '${0}' */
QSE_AWK_ELPAREN, /**< left parenthesis expected in place of '${0}' */
QSE_AWK_ERPAREN, /**< right parenthesis expected in place of '${0}' */
QSE_AWK_ERBRACK, /**< right bracket expected in place of '${0}' */
QSE_AWK_ECOMMA, /**< comma expected in place of '${0}' */
QSE_AWK_ESCOLON, /**< semicolon expected in place of '${0}' */
QSE_AWK_ECOLON, /**< colon expected in place of '${0}' */
QSE_AWK_ESTMEND, /**< statement not ending with a semicolon */
QSE_AWK_EIN, /**< 'in' expected in place of '${0}' */
QSE_AWK_ENOTVAR, /**< right-hand side of 'in' not a variable */
QSE_AWK_EEXPRES, /**< invalid expression */
QSE_AWK_EFUNCTION, /* keyword 'function' is expected */
QSE_AWK_EWHILE, /* keyword 'while' is expected */
QSE_AWK_EASSIGN, /* assignment statement expected */
QSE_AWK_EIDENT, /* identifier expected */
QSE_AWK_EFUNNAME, /* not a valid function name */
QSE_AWK_EBLKBEG, /* BEGIN requires an action block */
QSE_AWK_EBLKEND, /* END requires an action block */
QSE_AWK_EDUPBEG, /* duplicate BEGIN */
QSE_AWK_EDUPEND, /* duplicate END */
QSE_AWK_EKWRED, /* keyword redefined */
QSE_AWK_EFNCRED, /* intrinsic function redefined */
QSE_AWK_EFUNRED, /* function redefined */
QSE_AWK_EGBLRED, /* global variable redefined */
QSE_AWK_EPARRED, /* parameter redefined */
QSE_AWK_EVARRED, /* named variable redefined */
QSE_AWK_EDUPPAR, /* duplicate parameter name */
QSE_AWK_EDUPGBL, /* duplicate global variable name */
QSE_AWK_EDUPLCL, /* duplicate local variable name */
QSE_AWK_EBADPAR, /* not a valid parameter name */
QSE_AWK_EBADVAR, /* not a valid variable name */
QSE_AWK_EVARMS, /* variable name missing */
QSE_AWK_EUNDEF, /* undefined identifier */
QSE_AWK_ELVALUE, /* l-value required */
QSE_AWK_EGBLTM, /* too many global variables */
QSE_AWK_ELCLTM, /* too many local variables */
QSE_AWK_EPARTM, /* too many parameters */
QSE_AWK_EDELETE, /* delete not followed by a variable */
QSE_AWK_ERESET, /* reset not followed by a variable */
QSE_AWK_EBREAK, /* break outside a loop */
QSE_AWK_ECONTINUE, /* continue outside a loop */
QSE_AWK_ENEXTBEG, /* next illegal in BEGIN block */
QSE_AWK_ENEXTEND, /* next illegal in END block */
QSE_AWK_ENEXTFBEG, /* nextfile illegal in BEGIN block */
QSE_AWK_ENEXTFEND, /* nextfile illegal in END block */
QSE_AWK_EPRINTFARG, /* printf not followed by any arguments */
QSE_AWK_EPREPST, /* both prefix and postfix increment/decrement
operator present */
QSE_AWK_EFUNCTION, /**< 'function' is expected in place of '${0}' */
QSE_AWK_EWHILE, /**< 'while' is expected in place of '${0}' */
QSE_AWK_EASSIGN, /**< assignment statement expected */
QSE_AWK_EIDENT, /**< identifier expected in place of '${0}' */
QSE_AWK_EFUNNAME, /**< '${0}' not a valid function name */
QSE_AWK_EBLKBEG, /**< BEGIN not followed by left bracket on the same line */
QSE_AWK_EBLKEND, /**< END not followed by left bracket on the same line */
QSE_AWK_EDUPBEG, /**< duplicate BEGIN */
QSE_AWK_EDUPEND, /**< duplicate END */
QSE_AWK_EKWRED, /**< keyword '${0}' redefined */
QSE_AWK_EFNCRED, /**< intrinsic function '${0}' redefined */
QSE_AWK_EFUNRED, /**< function '${0}' redefined */
QSE_AWK_EGBLRED, /**< global variable '${0}' redefined */
QSE_AWK_EPARRED, /**< parameter '${0}' redefined */
QSE_AWK_EVARRED, /**< variable '${0}' redefined */
QSE_AWK_EDUPPAR, /**< duplicate parameter name '${0}' */
QSE_AWK_EDUPGBL, /**< duplicate global variable name '${0}' */
QSE_AWK_EDUPLCL, /**< duplicate local variable name '${0}' */
QSE_AWK_EBADPAR, /**< '${0}' not a valid parameter name */
QSE_AWK_EBADVAR, /**< '${0}' not a valid variable name */
QSE_AWK_EVARMS, /**< variable name missing */
QSE_AWK_EUNDEF, /**< undefined identifier '${0}' */
QSE_AWK_ELVALUE, /**< l-value required */
QSE_AWK_EGBLTM, /**< too many global variables */
QSE_AWK_ELCLTM, /**< too many local variables */
QSE_AWK_EPARTM, /**< too many parameters */
QSE_AWK_EDELETE, /**< 'delete' not followed by variable */
QSE_AWK_ERESET, /**< 'reset' not followed by variable */
QSE_AWK_EBREAK, /**< 'break' outside a loop */
QSE_AWK_ECONTINUE, /**< 'continue' outside a loop */
QSE_AWK_ENEXTBEG, /**< 'next' illegal in BEGIN block */
QSE_AWK_ENEXTEND, /**< 'next' illegal in END block */
QSE_AWK_ENEXTFBEG, /**< 'nextfile' illegal in BEGIN block */
QSE_AWK_ENEXTFEND, /**< 'nextfile' illegal in END block */
QSE_AWK_EPRINTFARG,/**< 'printf' not followed by argument */
QSE_AWK_EPREPST, /**< both prefix and postfix incr/decr operator present */
/* run time error */
QSE_AWK_EDIVBY0, /* divide by zero */
QSE_AWK_EOPERAND, /* invalid operand */
QSE_AWK_EPOSIDX, /* wrong position index */
QSE_AWK_EARGTF, /* too few arguments */
QSE_AWK_EARGTM, /* too many arguments */
QSE_AWK_EFUNNONE, /* function '${1}' not found */
QSE_AWK_ENOTIDX, /* variable not indexable */
QSE_AWK_ENOTDEL, /* variable not deletable */
QSE_AWK_ENOTMAP, /* value not a map */
QSE_AWK_ENOTMAPIN, /* right-hand side of 'in' not a map */
QSE_AWK_ENOTMAPNILIN, /* right-hand side of 'in' not a map nor nil */
QSE_AWK_ENOTREF, /* value not referenceable */
QSE_AWK_ENOTASS, /* value not assignable */
QSE_AWK_EIDXVALASSMAP, /* indexed value cannot be assigned a map */
QSE_AWK_EPOSVALASSMAP, /* a positional cannot be assigned a map */
QSE_AWK_EMAPTOSCALAR, /* cannot change a map to a scalar value */
QSE_AWK_ESCALARTOMAP, /* cannot change a scalar value to a map */
QSE_AWK_EMAPNOTALLOWED, /* a map is not allowed */
QSE_AWK_EVALTYPE, /* invalid value type */
QSE_AWK_ERDELETE, /* delete called with a wrong target */
QSE_AWK_ERRESET, /* reset called with a wrong target */
QSE_AWK_ERNEXTBEG, /* next called from BEGIN */
QSE_AWK_ERNEXTEND, /* next called from END */
QSE_AWK_ERNEXTFBEG, /* nextfile called from BEGIN */
QSE_AWK_ERNEXTFEND, /* nextfile called from END */
QSE_AWK_EFNCUSER, /* wrong intrinsic function implementation */
QSE_AWK_EFNCIMPL, /* intrinsic function handler failed */
QSE_AWK_EIOUSER, /* wrong user io handler implementation */
QSE_AWK_EIOIMPL, /* i/o callback returned an error */
QSE_AWK_EIONMNF, /* no such io name found */
QSE_AWK_EIONMEM, /* i/o name empty */
QSE_AWK_EIONMNL, /* i/o name contains '\0' */
QSE_AWK_EFMTARG, /* arguments to format string not sufficient */
QSE_AWK_EFMTCNV, /* recursion detected in format conversion */
QSE_AWK_ECONVFMTCHR, /* an invalid character found in CONVFMT */
QSE_AWK_EOFMTCHR, /* an invalid character found in OFMT */
QSE_AWK_EDIVBY0, /**< divide by zero */
QSE_AWK_EOPERAND, /**< invalid operand */
QSE_AWK_EPOSIDX, /**< wrong position index */
QSE_AWK_EARGTF, /**< too few arguments */
QSE_AWK_EARGTM, /**< too many arguments */
QSE_AWK_EFUNNF, /**< function '${0}' not found */
QSE_AWK_ENOTIDX, /**< variable not indexable */
QSE_AWK_ENOTDEL, /**< variable '${0}' not deletable */
QSE_AWK_ENOTMAP, /**< value not a map */
QSE_AWK_ENOTMAPIN, /**< right-hand side of 'in' not a map */
QSE_AWK_ENOTMAPNILIN, /**< right-hand side of 'in' not a map nor nil */
QSE_AWK_ENOTREF, /**< value not referenceable */
QSE_AWK_ENOTASS, /**< value not assignable */
QSE_AWK_EIDXVALASSMAP, /**< an indexed value cannot be assigned a map */
QSE_AWK_EPOSVALASSMAP, /**< a positional cannot be assigned a map */
QSE_AWK_EMAPTOSCALAR, /**< map '${0}' not assignable with a scalar */
QSE_AWK_ESCALARTOMAP, /**< cannot change a scalar value to a map */
QSE_AWK_EMAPNOTALLOWED,/**< map not allowed */
QSE_AWK_EVALTYPE, /**< invalid value type */
QSE_AWK_ERDELETE, /**< 'delete' called with wrong target */
QSE_AWK_ERRESET, /**< 'reset' called with wrong target */
QSE_AWK_ERNEXTBEG, /**< 'next' called from BEGIN block */
QSE_AWK_ERNEXTEND, /**< 'next' called from END block */
QSE_AWK_ERNEXTFBEG, /**< 'nextfile' called from BEGIN block */
QSE_AWK_ERNEXTFEND, /**< 'nextfile' called from END block */
QSE_AWK_EFNCUSER, /**< wrong intrinsic function implementation */
QSE_AWK_EFNCIMPL, /**< intrinsic function handler failed */
QSE_AWK_EIOUSER, /**< wrong user io handler implementation */
QSE_AWK_EIOIMPL, /**< I/O callback returned an error */
QSE_AWK_EIONMNF, /**< no such I/O name found */
QSE_AWK_EIONMEM, /**< I/O name empty */
QSE_AWK_EIONMNL, /**< I/O name '${0}' containing '\\0' */
QSE_AWK_EFMTARG, /**< not sufficient arguments to formatting sequence */
QSE_AWK_EFMTCNV, /**< recursion detected in format conversion */
QSE_AWK_ECONVFMTCHR, /**< invalid character in CONVFMT */
QSE_AWK_EOFMTCHR, /**< invalid character in OFMT */
/* regular expression error */
QSE_AWK_EREXRECUR, /* recursion too deep */
QSE_AWK_EREXRPAREN, /* a right parenthesis is expected */
QSE_AWK_EREXRBRACKET, /* a right bracket is expected */
QSE_AWK_EREXRBRACE, /* a right brace is expected */
QSE_AWK_EREXUNBALPAREN, /* unbalanced parenthesis */
QSE_AWK_EREXINVALBRACE, /* invalid brace */
QSE_AWK_EREXCOLON, /* a colon is expected */
QSE_AWK_EREXCRANGE, /* invalid character range */
QSE_AWK_EREXCCLASS, /* invalid character class */
QSE_AWK_EREXBRANGE, /* invalid boundary range */
QSE_AWK_EREXEND, /* unexpected end of the pattern */
QSE_AWK_EREXGARBAGE, /* garbage after the pattern */
QSE_AWK_EREXRECUR, /**< recursion too deep */
QSE_AWK_EREXRPAREN, /**< a right parenthesis is expected */
QSE_AWK_EREXRBRACKET, /**< a right bracket is expected */
QSE_AWK_EREXRBRACE, /**< a right brace is expected */
QSE_AWK_EREXUNBALPAREN,/**< unbalanced parenthesis */
QSE_AWK_EREXINVALBRACE,/**< invalid brace */
QSE_AWK_EREXCOLON, /**< a colon is expected */
QSE_AWK_EREXCRANGE, /**< invalid character range */
QSE_AWK_EREXCCLASS, /**< invalid character class */
QSE_AWK_EREXBRANGE, /**< invalid boundary range */
QSE_AWK_EREXEND, /**< unexpected end of the pattern */
QSE_AWK_EREXGARBAGE, /**< garbage after the pattern */
/* the number of error numbers, internal use only */
QSE_AWK_NUMERRNUM
@ -705,7 +753,7 @@ struct qse_awk_errinf_t
typedef struct qse_awk_errinf_t qse_awk_errinf_t;
/**
* The qse_awk_errstr_t type defines a error string getter. It should return
* The qse_awk_errstr_t type defines an error string getter. It should return
* an error formatting string for an error number requested. A new string
* should contain the same number of positional parameters (${X}) as in the
* default error formatting string. You can set a new getter into an awk
@ -761,34 +809,24 @@ enum qse_awk_gbl_id_t
QSE_AWK_MAX_GBL_ID = QSE_AWK_GBL_SUBSEP
};
/**
* The qse_awk_val_type_t type defines types of AWK values. Each value
* allocated is tagged with a value type in the @a type field.
* @sa qse_awk_val_t QSE_AWK_VAL_HDR
*/
enum qse_awk_val_type_t
{
/* the values between QSE_AWK_VAL_NIL and QSE_AWK_VAL_STR inclusive
* must be synchronized with an internal table of the __cmp_val
* function in run.c */
QSE_AWK_VAL_NIL = 0,
QSE_AWK_VAL_INT = 1,
QSE_AWK_VAL_REAL = 2,
QSE_AWK_VAL_STR = 3,
QSE_AWK_VAL_NIL = 0, /**< nil */
QSE_AWK_VAL_INT = 1, /**< integer */
QSE_AWK_VAL_REAL = 2, /**< floating-pointer number */
QSE_AWK_VAL_STR = 3, /**< string */
QSE_AWK_VAL_REX = 4,
QSE_AWK_VAL_MAP = 5,
QSE_AWK_VAL_REF = 6
};
enum qse_awk_val_ref_id_t
{
/* keep these items in the same order as corresponding items
* in tree.h */
QSE_AWK_VAL_REF_NAMED,
QSE_AWK_VAL_REF_GBL,
QSE_AWK_VAL_REF_LCL,
QSE_AWK_VAL_REF_ARG,
QSE_AWK_VAL_REF_NAMEDIDX,
QSE_AWK_VAL_REF_GBLIDX,
QSE_AWK_VAL_REF_LCLIDX,
QSE_AWK_VAL_REF_ARGIDX,
QSE_AWK_VAL_REF_POS
QSE_AWK_VAL_REX = 4, /**< regular expression */
QSE_AWK_VAL_MAP = 5, /**< map */
QSE_AWK_VAL_REF = 6 /**< reference to other types */
};
/**
@ -1166,19 +1204,30 @@ int qse_awk_parse (
/**
* The qse_awk_alloc() function allocates dynamic memory.
* @return a pointer to memory space allocated on success, #QSE_NULL on failure
* @return a pointer to a memory block on success, #QSE_NULL on failure
*/
void* qse_awk_alloc (
qse_awk_t* awk, /**< awk object */
qse_size_t size /**< size of memory to allocate in bytes */
);
/**
* The qse_awk_realloc() function resizes a dynamic memory block.
* @return a pointer to a memory block on success, #QSE_NULL on failure
*/
void* qse_awk_realloc (
qse_awk_t* awk, /**< awk object */
void* ptr, /**< memory block */
qse_size_t size /**< new block size in bytes */
);
/**
* The qse_awk_free() function frees dynamic memory allocated.
*/
void qse_awk_free (
qse_awk_t* awk, /**< awk object */
void* ptr /**< memory space to free */
void* ptr /**< memory block to free */
);
/**
@ -1245,8 +1294,7 @@ qse_awk_rtx_t* qse_awk_rtx_open (
);
/**
* The qse_awk_rtx_close() function destroys a runtime context
* SYNOPSIS
* The qse_awk_rtx_close() function destroys a runtime context.
*/
void qse_awk_rtx_close (
qse_awk_rtx_t* rtx /**< runtime context */
@ -1325,18 +1373,22 @@ void qse_awk_rtx_stop (
);
/**
* The qse_awk_rtx_setrcb() function gets runtime callback.
* 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
qse_awk_rtx_t* rtx /**< runtime context */
);
/**
* The qse_awk_rtx_setrcb() function sets runtime callback.
* The qse_awk_rtx_setrcb() function sets runtime callbacks.
* @sa qse_awk_rtx_getrcb
*/
void qse_awk_rtx_setrcb (
qse_awk_rtx_t* rtx,
qse_awk_rcb_t* rcb
qse_awk_rtx_t* rtx, /**< runtime context */
qse_awk_rcb_t* rcb /**< callback set */
);
/**

View File

@ -1,5 +1,5 @@
/*
* $Id: types.h 204 2009-06-18 12:08:06Z hyunghwan.chung $
* $Id: types.h 220 2009-07-01 13:14:39Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -371,11 +371,12 @@ typedef int qse_mcint_t;
/**
* The qse_xstr_t type defines a structure combining a pointer to a character
* string and the number of characters.
* string and the number of characters. It is designed to be interchangeable
* with the #qse_cstr_t type except the constness on the @a ptr field.
*/
struct qse_xstr_t
{
qse_char_t* ptr; /**< a pointer to a character string */
qse_char_t* ptr; /**< pointer to a character string */
qse_size_t len; /**< the number of characters */
};
typedef struct qse_xstr_t qse_xstr_t;
@ -383,10 +384,12 @@ typedef struct qse_xstr_t qse_xstr_t;
/**
* The qse_cstr_t type defines a structure combining a pointer to
* a constant character string and the number of characters.
* It is designed to be interchangeable with the #qse_xstr_t type
* except the constness on the @a ptr field.
*/
struct qse_cstr_t
{
const qse_char_t* ptr; /**< a pointer to a const character string */
const qse_char_t* ptr; /**< pointer to a const character string */
qse_size_t len; /**< the number of characters */
};
typedef struct qse_cstr_t qse_cstr_t;