cleaned up code

This commit is contained in:
2009-07-16 04:43:31 +00:00
parent e149b933f7
commit f0f2db5e8a
22 changed files with 781 additions and 796 deletions

View File

@ -42,7 +42,7 @@ public:
* The Mmgr() function builds a memory manager composed of bridge
* functions connecting itself with it.
*/
Mmgr () throw ()
Mmgr ()
{
this->alloc = alloc_mem;
this->realloc = realloc_mem;
@ -63,7 +63,7 @@ protected:
*/
virtual void* allocMem (
qse_size_t n /**< the size of allocate in bytes */
) throw () = 0;
) = 0;
/**
* The reallocMem() function resizes a chunk of memory previously
@ -74,7 +74,7 @@ protected:
virtual void* reallocMem (
void* ptr, /**< a pointer to a memory chunk to resize */
qse_size_t n /**< new size in bytes */
) throw () = 0;
) = 0;
/**
* The freeMem() function frees a chunk of memory allocated with
@ -82,13 +82,13 @@ protected:
*/
virtual void freeMem (
void* ptr /**< a pointer to a memory chunk to free */
) throw () = 0;
) = 0;
protected:
/**
* a bridge function from the qse_mmgr_t type the allocMem() function.
*/
static void* alloc_mem (void* udd, qse_size_t n) throw ()
static void* alloc_mem (void* udd, qse_size_t n)
{
return ((Mmgr*)udd)->allocMem (n);
}
@ -96,7 +96,7 @@ protected:
/**
* a bridge function from the qse_mmgr_t type the reallocMem() function.
*/
static void* realloc_mem (void* udd, void* ptr, qse_size_t n) throw ()
static void* realloc_mem (void* udd, void* ptr, qse_size_t n)
{
return ((Mmgr*)udd)->reallocMem (ptr, n);
}
@ -104,7 +104,7 @@ protected:
/**
* a bridge function from the qse_mmgr_t type the freeMem() function.
*/
static void free_mem (void* udd, void* ptr) throw ()
static void free_mem (void* udd, void* ptr)
{
return ((Mmgr*)udd)->freeMem (ptr);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp 234 2009-07-14 14:08:48Z hyunghwan.chung $
* $Id: Awk.hpp 235 2009-07-15 10:43:31Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -38,11 +38,12 @@ public:
typedef qse_map_t map_t;
typedef qse_map_pair_t pair_t;
/** Represents a underlying interpreter */
/** Defines a primitive handle */
typedef qse_awk_t awk_t;
typedef qse_awk_errnum_t errnum_t;
typedef qse_awk_errstr_t errstr_t;
typedef qse_awk_errinf_t errinf_t;
/** Represents an internal awk value */
typedef qse_awk_val_t val_t;
@ -58,13 +59,207 @@ public:
class Run;
friend class Run;
/**
* @name Error Handling
*/
/*@{*/
/**
* Defines error numbers.
*/
enum ErrorNumber
{
ERR_NOERR = QSE_AWK_ENOERR,
ERR_UNKNOWN = QSE_AWK_EUNKNOWN,
ERR_INVAL = QSE_AWK_EINVAL,
ERR_NOMEM = QSE_AWK_ENOMEM,
ERR_NOSUP = QSE_AWK_ENOSUP,
ERR_NOPER = QSE_AWK_ENOPER,
ERR_NOENT = QSE_AWK_ENOENT,
ERR_EXIST = QSE_AWK_EEXIST,
ERR_IOERR = QSE_AWK_EIOERR,
ERR_OPEN = QSE_AWK_EOPEN,
ERR_READ = QSE_AWK_EREAD,
ERR_WRITE = QSE_AWK_EWRITE,
ERR_CLOSE = QSE_AWK_ECLOSE,
ERR_INTERN = QSE_AWK_EINTERN,
ERR_RUNTIME = QSE_AWK_ERUNTIME,
ERR_BLKNST = QSE_AWK_EBLKNST,
ERR_EXPRNST = QSE_AWK_EEXPRNST,
ERR_SINOP = QSE_AWK_ESINOP,
ERR_SINCL = QSE_AWK_ESINCL,
ERR_SINRD = QSE_AWK_ESINRD,
ERR_SOUTOP = QSE_AWK_ESOUTOP,
ERR_SOUTCL = QSE_AWK_ESOUTCL,
ERR_SOUTWR = QSE_AWK_ESOUTWR,
ERR_LXCHR = QSE_AWK_ELXCHR,
ERR_LXDIG = QSE_AWK_ELXDIG,
ERR_LXUNG = QSE_AWK_ELXUNG,
ERR_ENDSRC = QSE_AWK_EENDSRC,
ERR_ENDCMT = QSE_AWK_EENDCMT,
ERR_ENDSTR = QSE_AWK_EENDSTR,
ERR_ENDREX = QSE_AWK_EENDREX,
ERR_LBRACE = QSE_AWK_ELBRACE,
ERR_LPAREN = QSE_AWK_ELPAREN,
ERR_RPAREN = QSE_AWK_ERPAREN,
ERR_RBRACK = QSE_AWK_ERBRACK,
ERR_COMMA = QSE_AWK_ECOMMA,
ERR_SCOLON = QSE_AWK_ESCOLON,
ERR_COLON = QSE_AWK_ECOLON,
ERR_STMEND = QSE_AWK_ESTMEND,
ERR_IN = QSE_AWK_EIN,
ERR_NOTVAR = QSE_AWK_ENOTVAR,
ERR_EXPRES = QSE_AWK_EEXPRES,
ERR_FUNCTION = QSE_AWK_EFUNCTION,
ERR_WHILE = QSE_AWK_EWHILE,
ERR_ASSIGN = QSE_AWK_EASSIGN,
ERR_IDENT = QSE_AWK_EIDENT,
ERR_FUNNAME = QSE_AWK_EFUNNAME,
ERR_BLKBEG = QSE_AWK_EBLKBEG,
ERR_BLKEND = QSE_AWK_EBLKEND,
ERR_DUPBEG = QSE_AWK_EDUPBEG,
ERR_DUPEND = QSE_AWK_EDUPEND,
ERR_KWRED = QSE_AWK_EKWRED,
ERR_FNCRED = QSE_AWK_EFNCRED,
ERR_FUNRED = QSE_AWK_EFUNRED,
ERR_GBLRED = QSE_AWK_EGBLRED,
ERR_PARRED = QSE_AWK_EPARRED,
ERR_VARRED = QSE_AWK_EVARRED,
ERR_DUPPAR = QSE_AWK_EDUPPAR,
ERR_DUPGBL = QSE_AWK_EDUPGBL,
ERR_DUPLCL = QSE_AWK_EDUPLCL,
ERR_BADPAR = QSE_AWK_EBADPAR,
ERR_BADVAR = QSE_AWK_EBADVAR,
ERR_UNDEF = QSE_AWK_EUNDEF,
ERR_LVALUE = QSE_AWK_ELVALUE,
ERR_GBLTM = QSE_AWK_EGBLTM,
ERR_LCLTM = QSE_AWK_ELCLTM,
ERR_PARTM = QSE_AWK_EPARTM,
ERR_DELETE = QSE_AWK_EDELETE,
ERR_BREAK = QSE_AWK_EBREAK,
ERR_CONTINUE = QSE_AWK_ECONTINUE,
ERR_NEXTBEG = QSE_AWK_ENEXTBEG,
ERR_NEXTEND = QSE_AWK_ENEXTEND,
ERR_NEXTFBEG = QSE_AWK_ENEXTFBEG,
ERR_NEXTFEND = QSE_AWK_ENEXTFEND,
ERR_PRINTFARG = QSE_AWK_EPRINTFARG,
ERR_PREPST = QSE_AWK_EPREPST,
ERR_INCDECOPR = QSE_AWK_EINCDECOPR,
ERR_DIVBY0 = QSE_AWK_EDIVBY0,
ERR_OPERAND = QSE_AWK_EOPERAND,
ERR_POSIDX = QSE_AWK_EPOSIDX,
ERR_ARGTF = QSE_AWK_EARGTF,
ERR_ARGTM = QSE_AWK_EARGTM,
ERR_FUNNF = QSE_AWK_EFUNNF,
ERR_NOTIDX = QSE_AWK_ENOTIDX,
ERR_NOTDEL = QSE_AWK_ENOTDEL,
ERR_NOTMAP = QSE_AWK_ENOTMAP,
ERR_NOTMAPIN = QSE_AWK_ENOTMAPIN,
ERR_NOTMAPNILIN = QSE_AWK_ENOTMAPNILIN,
ERR_NOTREF = QSE_AWK_ENOTREF,
ERR_NOTASS = QSE_AWK_ENOTASS,
ERR_IDXVALASSMAP = QSE_AWK_EIDXVALASSMAP,
ERR_POSVALASSMAP = QSE_AWK_EPOSVALASSMAP,
ERR_MAPTOSCALAR = QSE_AWK_EMAPTOSCALAR,
ERR_SCALARTOMAP = QSE_AWK_ESCALARTOMAP,
ERR_MAPNOTALLOWED = QSE_AWK_EMAPNOTALLOWED,
ERR_VALTYPE = QSE_AWK_EVALTYPE,
ERR_RDELETE = QSE_AWK_ERDELETE,
ERR_RNEXTBEG = QSE_AWK_ERNEXTBEG,
ERR_RNEXTEND = QSE_AWK_ERNEXTEND,
ERR_RNEXTFBEG = QSE_AWK_ERNEXTFBEG,
ERR_RNEXTFEND = QSE_AWK_ERNEXTFEND,
ERR_FNCIMPL = QSE_AWK_EFNCIMPL,
ERR_IOUSER = QSE_AWK_EIOUSER,
ERR_IOIMPL = QSE_AWK_EIOIMPL,
ERR_IONMNF = QSE_AWK_EIONMNF,
ERR_IONMEM = QSE_AWK_EIONMEM,
ERR_IONMNL = QSE_AWK_EIONMNL,
ERR_FMTARG = QSE_AWK_EFMTARG,
ERR_FMTCNV = QSE_AWK_EFMTCNV,
ERR_CONVFMTCHR = QSE_AWK_ECONVFMTCHR,
ERR_OFMTCHR = QSE_AWK_EOFMTCHR,
ERR_REXRECUR = QSE_AWK_EREXRECUR,
ERR_REXRPAREN = QSE_AWK_EREXRPAREN,
ERR_REXRBRACKET = QSE_AWK_EREXRBRACKET,
ERR_REXRBRACE = QSE_AWK_EREXRBRACE,
ERR_REXUNBALPAREN = QSE_AWK_EREXUNBALPAREN,
ERR_REXINVALBRACE = QSE_AWK_EREXINVALBRACE,
ERR_REXCOLON = QSE_AWK_EREXCOLON,
ERR_REXCRANGE = QSE_AWK_EREXCRANGE,
ERR_REXCCLASS = QSE_AWK_EREXCCLASS,
ERR_REXBRANGE = QSE_AWK_EREXBRANGE,
ERR_REXEND = QSE_AWK_EREXEND,
ERR_REXGARBAGE = QSE_AWK_EREXGARBAGE,
};
protected:
class NoSource;
/**
* The Awk::getErrorString() function returns a formatting string
* for an error code @a num. You can override this function
* to customize an error message. You must include the same numbers
* of ${X}'s as the orginal formatting string. Their order may be
* different. The example below changes the formatting string for
* ERR_NOENT.
* @code
* const MyAwk::char_t* MyAwk::getErrorString (ErrorNumber num) const
* {
* if (num == ERR_NOENT) return QSE_T("cannot find '${0}'");
* return Awk::getErrorString (num);
* }
* @endcode
*/
virtual const char_t* getErrorString (
ErrorNumber num
) const;
public:
/**
* The Awk::getErrorNumber() function returns the number of the last
* error occurred.
*/
ErrorNumber getErrorNumber () const;
/**
* The Awk::getErrorLine() function returns the line number of the last
* error occurred.
*/
size_t getErrorLine () const;
/**
* The Awk::getErrorMessage() function returns a message describing
* the last error occurred.
*/
const char_t* getErrorMessage () const;
/**
* Set error information.
*/
void setError (
ErrorNumber code,
size_t line = 0,
const cstr_t* args = QSE_NULL
);
void setErrorWithMessage (
ErrorNumber code,
size_t line,
const char_t* msg
);
/** clears error information */
void clearError ();
protected:
void retrieveError ();
void retrieveError (Run* run);
/*@}*/
class NoSource;
public:
/**
* The Source class is an abstract class to encapsulate
* source script I/O. The Awk::parse() function requires a concrete
* source script I/O. The Awk::parse function requires a concrete
* object instantiated from its child class.
*/
class Source
@ -265,13 +460,13 @@ public:
#if !defined(__BORLANDC__)
// deletion when initialization fails
void operator delete (void* p, Run* run) throw ();
void operator delete[] (void* p, Run* run) throw ();
void operator delete (void* p, Run* run);
void operator delete[] (void* p, Run* run);
#endif
// normal deletion
void operator delete (void* p) throw ();
void operator delete[] (void* p) throw ();
void operator delete (void* p);
void operator delete[] (void* p);
class Index
{
@ -482,180 +677,9 @@ public:
static const char_t* EMPTY_STRING;
};
// generated by generrcode.awk
/** Defines the error code */
enum ErrorNumber
{
ERR_NOERR = QSE_AWK_ENOERR,
ERR_UNKNOWN = QSE_AWK_EUNKNOWN,
ERR_INVAL = QSE_AWK_EINVAL,
ERR_NOMEM = QSE_AWK_ENOMEM,
ERR_NOSUP = QSE_AWK_ENOSUP,
ERR_NOPER = QSE_AWK_ENOPER,
ERR_NOENT = QSE_AWK_ENOENT,
ERR_EXIST = QSE_AWK_EEXIST,
ERR_IOERR = QSE_AWK_EIOERR,
ERR_OPEN = QSE_AWK_EOPEN,
ERR_READ = QSE_AWK_EREAD,
ERR_WRITE = QSE_AWK_EWRITE,
ERR_CLOSE = QSE_AWK_ECLOSE,
ERR_INTERN = QSE_AWK_EINTERN,
ERR_RUNTIME = QSE_AWK_ERUNTIME,
ERR_BLKNST = QSE_AWK_EBLKNST,
ERR_EXPRNST = QSE_AWK_EEXPRNST,
ERR_SINOP = QSE_AWK_ESINOP,
ERR_SINCL = QSE_AWK_ESINCL,
ERR_SINRD = QSE_AWK_ESINRD,
ERR_SOUTOP = QSE_AWK_ESOUTOP,
ERR_SOUTCL = QSE_AWK_ESOUTCL,
ERR_SOUTWR = QSE_AWK_ESOUTWR,
ERR_LXCHR = QSE_AWK_ELXCHR,
ERR_LXDIG = QSE_AWK_ELXDIG,
ERR_LXUNG = QSE_AWK_ELXUNG,
ERR_ENDSRC = QSE_AWK_EENDSRC,
ERR_ENDCMT = QSE_AWK_EENDCMT,
ERR_ENDSTR = QSE_AWK_EENDSTR,
ERR_ENDREX = QSE_AWK_EENDREX,
ERR_LBRACE = QSE_AWK_ELBRACE,
ERR_LPAREN = QSE_AWK_ELPAREN,
ERR_RPAREN = QSE_AWK_ERPAREN,
ERR_RBRACK = QSE_AWK_ERBRACK,
ERR_COMMA = QSE_AWK_ECOMMA,
ERR_SCOLON = QSE_AWK_ESCOLON,
ERR_COLON = QSE_AWK_ECOLON,
ERR_STMEND = QSE_AWK_ESTMEND,
ERR_IN = QSE_AWK_EIN,
ERR_NOTVAR = QSE_AWK_ENOTVAR,
ERR_EXPRES = QSE_AWK_EEXPRES,
ERR_FUNCTION = QSE_AWK_EFUNCTION,
ERR_WHILE = QSE_AWK_EWHILE,
ERR_ASSIGN = QSE_AWK_EASSIGN,
ERR_IDENT = QSE_AWK_EIDENT,
ERR_FUNNAME = QSE_AWK_EFUNNAME,
ERR_BLKBEG = QSE_AWK_EBLKBEG,
ERR_BLKEND = QSE_AWK_EBLKEND,
ERR_DUPBEG = QSE_AWK_EDUPBEG,
ERR_DUPEND = QSE_AWK_EDUPEND,
ERR_KWRED = QSE_AWK_EKWRED,
ERR_FNCRED = QSE_AWK_EFNCRED,
ERR_FUNRED = QSE_AWK_EFUNRED,
ERR_GBLRED = QSE_AWK_EGBLRED,
ERR_PARRED = QSE_AWK_EPARRED,
ERR_VARRED = QSE_AWK_EVARRED,
ERR_DUPPAR = QSE_AWK_EDUPPAR,
ERR_DUPGBL = QSE_AWK_EDUPGBL,
ERR_DUPLCL = QSE_AWK_EDUPLCL,
ERR_BADPAR = QSE_AWK_EBADPAR,
ERR_BADVAR = QSE_AWK_EBADVAR,
ERR_UNDEF = QSE_AWK_EUNDEF,
ERR_LVALUE = QSE_AWK_ELVALUE,
ERR_GBLTM = QSE_AWK_EGBLTM,
ERR_LCLTM = QSE_AWK_ELCLTM,
ERR_PARTM = QSE_AWK_EPARTM,
ERR_DELETE = QSE_AWK_EDELETE,
ERR_BREAK = QSE_AWK_EBREAK,
ERR_CONTINUE = QSE_AWK_ECONTINUE,
ERR_NEXTBEG = QSE_AWK_ENEXTBEG,
ERR_NEXTEND = QSE_AWK_ENEXTEND,
ERR_NEXTFBEG = QSE_AWK_ENEXTFBEG,
ERR_NEXTFEND = QSE_AWK_ENEXTFEND,
ERR_PRINTFARG = QSE_AWK_EPRINTFARG,
ERR_PREPST = QSE_AWK_EPREPST,
ERR_INCDECOPR = QSE_AWK_EINCDECOPR,
ERR_DIVBY0 = QSE_AWK_EDIVBY0,
ERR_OPERAND = QSE_AWK_EOPERAND,
ERR_POSIDX = QSE_AWK_EPOSIDX,
ERR_ARGTF = QSE_AWK_EARGTF,
ERR_ARGTM = QSE_AWK_EARGTM,
ERR_FUNNF = QSE_AWK_EFUNNF,
ERR_NOTIDX = QSE_AWK_ENOTIDX,
ERR_NOTDEL = QSE_AWK_ENOTDEL,
ERR_NOTMAP = QSE_AWK_ENOTMAP,
ERR_NOTMAPIN = QSE_AWK_ENOTMAPIN,
ERR_NOTMAPNILIN = QSE_AWK_ENOTMAPNILIN,
ERR_NOTREF = QSE_AWK_ENOTREF,
ERR_NOTASS = QSE_AWK_ENOTASS,
ERR_IDXVALASSMAP = QSE_AWK_EIDXVALASSMAP,
ERR_POSVALASSMAP = QSE_AWK_EPOSVALASSMAP,
ERR_MAPTOSCALAR = QSE_AWK_EMAPTOSCALAR,
ERR_SCALARTOMAP = QSE_AWK_ESCALARTOMAP,
ERR_MAPNOTALLOWED = QSE_AWK_EMAPNOTALLOWED,
ERR_VALTYPE = QSE_AWK_EVALTYPE,
ERR_RDELETE = QSE_AWK_ERDELETE,
ERR_RNEXTBEG = QSE_AWK_ERNEXTBEG,
ERR_RNEXTEND = QSE_AWK_ERNEXTEND,
ERR_RNEXTFBEG = QSE_AWK_ERNEXTFBEG,
ERR_RNEXTFEND = QSE_AWK_ERNEXTFEND,
ERR_FNCUSER = QSE_AWK_EFNCUSER,
ERR_FNCIMPL = QSE_AWK_EFNCIMPL,
ERR_IOUSER = QSE_AWK_EIOUSER,
ERR_IOIMPL = QSE_AWK_EIOIMPL,
ERR_IONMNF = QSE_AWK_EIONMNF,
ERR_IONMEM = QSE_AWK_EIONMEM,
ERR_IONMNL = QSE_AWK_EIONMNL,
ERR_FMTARG = QSE_AWK_EFMTARG,
ERR_FMTCNV = QSE_AWK_EFMTCNV,
ERR_CONVFMTCHR = QSE_AWK_ECONVFMTCHR,
ERR_OFMTCHR = QSE_AWK_EOFMTCHR,
ERR_REXRECUR = QSE_AWK_EREXRECUR,
ERR_REXRPAREN = QSE_AWK_EREXRPAREN,
ERR_REXRBRACKET = QSE_AWK_EREXRBRACKET,
ERR_REXRBRACE = QSE_AWK_EREXRBRACE,
ERR_REXUNBALPAREN = QSE_AWK_EREXUNBALPAREN,
ERR_REXINVALBRACE = QSE_AWK_EREXINVALBRACE,
ERR_REXCOLON = QSE_AWK_EREXCOLON,
ERR_REXCRANGE = QSE_AWK_EREXCRANGE,
ERR_REXCCLASS = QSE_AWK_EREXCCLASS,
ERR_REXBRANGE = QSE_AWK_EREXBRANGE,
ERR_REXEND = QSE_AWK_EREXEND,
ERR_REXGARBAGE = QSE_AWK_EREXGARBAGE,
};
// end of enum ErrorNumber
// generated by genoptcode.awk
/** Defines options */
enum Option
{
OPT_IMPLICIT = QSE_AWK_IMPLICIT,
OPT_EXPLICIT = QSE_AWK_EXPLICIT,
OPT_BXOR = QSE_AWK_BXOR,
OPT_SHIFT = QSE_AWK_SHIFT,
OPT_IDIV = QSE_AWK_IDIV,
OPT_RIO = QSE_AWK_RIO,
OPT_RWPIPE = QSE_AWK_RWPIPE,
/** Can terminate a statement with a new line */
OPT_NEWLINE = QSE_AWK_NEWLINE,
OPT_STRIPSPACES = QSE_AWK_STRIPSPACES,
/** Support the nextofile statement */
OPT_NEXTOFILE = QSE_AWK_NEXTOFILE,
/** Enables the keyword 'reset' */
OPT_RESET = QSE_AWK_RESET,
/** Use CR+LF instead of LF for line breaking. */
OPT_CRLF = QSE_AWK_CRLF,
/** Allows the assignment of a map value to a variable */
OPT_MAPTOVAR = QSE_AWK_MAPTOVAR,
/** Allows BEGIN, END, pattern-action blocks */
OPT_PABLOCK = QSE_AWK_PABLOCK,
/** Allows {n,m} in a regular expression */
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_NCMPONSTR is off;
* - "10.9" is greater if #QSE_AWK_NCMPONSTR is on
*/
OPT_NCMPONSTR = QSE_AWK_NCMPONSTR
};
// end of enum Option
/**
* Defines an identifier of predefined global variables.
* Awk::setGlobal and Awk::getGlobal can take one of these enumeration.
* Awk::setGlobal and Awk::getGlobal can take one of these enumerators.
*/
enum Global
{
@ -694,16 +718,17 @@ public:
operator rtx_t* () const;
void stop () const;
bool isStop () const;
bool shouldStop () const;
ErrorNumber errorNumber () const throw ();
size_t errorLine () const throw ();
const char_t* errorMessage () const throw ();
ErrorNumber getErrorNumber () const;
size_t getErrorLine () const;
const char_t* getErrorMessage () const;
void setError (ErrorNumber code);
void setError (ErrorNumber code, size_t line);
void setError (ErrorNumber code, size_t line, const char_t* arg);
void setError (ErrorNumber code, size_t line, const char_t* arg, size_t len);
void setError (
ErrorNumber code,
size_t line = 0,
const cstr_t* args = QSE_NULL
);
void setErrorWithMessage (
ErrorNumber code, size_t line, const char_t* msg);
@ -748,105 +773,111 @@ public:
rtx_t* rtx;
};
/** Constructor */
Awk () throw ();
/** Returns the underlying handle */
/** Returns the primitive handle */
operator awk_t* () const;
/**
* @name Error Handling
* @name Basic Functions
*/
/*@{*/
protected:
/**
* The Awk::errorString() function returns a formatting string
* for an error code @a num. You can override this function
* to customize an error message. You must include the same numbers
* of ${X}'s as the orginal formatting string. Their order may be
* different. The example below changes the formatting string for
* ERR_NOENT.
* @code
* const MyAwk::char_t* MyAwk::errorString (ErrorNumber num) const throw ()
* {
* if (num == ERR_NOENT) return QSE_T("cannot find '${0}'");
* return Awk::errorString (num);
* }
* @endcode
*/
virtual const char_t* errorString (
ErrorNumber num
) const throw ();
/** Constructor */
Awk ();
public:
/**
* The Awk::errorNumber() function returns the number of the last
* error occurred.
*/
ErrorNumber errorNumber () const throw ();
/**
* The Awk::errorLine() function returns the line number of the last
* error occurred.
*/
size_t errorLine () const throw ();
/**
* The Awk::errorMessage() function returns a message describing
* the last error occurred.
*/
const char_t* errorMessage () const throw ();
void setError (
ErrorNumber code
);
void setError (
ErrorNumber code, size_t line
);
void setError (
ErrorNumber code,
size_t line,
const char_t* arg
);
void setError (
ErrorNumber code,
size_t line,
const char_t* arg,
size_t len
);
void setErrorWithMessage (
ErrorNumber code,
size_t line,
const char_t* msg
);
void clearError ();
protected:
void retrieveError ();
void retrieveError (Run* run);
/*@}*/
public:
/**
* The Awk::open() function initializes an interpreter.
* You must call this function before doing anything meaningful.
* @return 0 on success, -1 on failure
*/
virtual int open ();
int open ();
/** Closes the interpreter. */
virtual void close ();
void close ();
/**
* The Awk::parse() function parses the source code read from the input
* stream @a in and writes the parse tree to the output stream @out.
* To disable deparsing, you may set @a out to Awk::Source::NONE.
* However, it is not legal to specify Awk::Source::NONE for @a in.
*
* @return a Run object on success, #QSE_NULL on failure
*/
Awk::Run* parse (
Source& in, /**< script to parse */
Source& out /**< deparsing target */
);
/**
* Executes the BEGIN block, pattern-action blocks, and the END block.
* @return 0 on succes, -1 on failure
*/
int loop ();
/**
* Calls a function
*/
int call (
const char_t* name,
Value* ret,
const Value* args,
size_t nargs
);
/**
* Makes request to abort execution
*/
void stop ();
/*@}*/
/**
* @name Configuration
*/
/*@{*/
/** Defines options */
enum Option
{
OPT_IMPLICIT = QSE_AWK_IMPLICIT,
OPT_EXPLICIT = QSE_AWK_EXPLICIT,
OPT_BXOR = QSE_AWK_BXOR,
OPT_SHIFT = QSE_AWK_SHIFT,
OPT_IDIV = QSE_AWK_IDIV,
OPT_RIO = QSE_AWK_RIO,
OPT_RWPIPE = QSE_AWK_RWPIPE,
/** Can terminate a statement with a new line */
OPT_NEWLINE = QSE_AWK_NEWLINE,
OPT_STRIPSPACES = QSE_AWK_STRIPSPACES,
/** Support the nextofile statement */
OPT_NEXTOFILE = QSE_AWK_NEXTOFILE,
/** Enables the keyword 'reset' */
OPT_RESET = QSE_AWK_RESET,
/** Use CR+LF instead of LF for line breaking. */
OPT_CRLF = QSE_AWK_CRLF,
/** Allows the assignment of a map value to a variable */
OPT_MAPTOVAR = QSE_AWK_MAPTOVAR,
/** Allows BEGIN, END, pattern-action blocks */
OPT_PABLOCK = QSE_AWK_PABLOCK,
/** Allows {n,m} in a regular expression */
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_NCMPONSTR is off;
* - "10.9" is greater if #QSE_AWK_NCMPONSTR is on
*/
OPT_NCMPONSTR = QSE_AWK_NCMPONSTR
};
/** Gets the option */
int getOption () const;
/** Sets the option */
virtual void setOption (int opt);
/** Gets the option */
virtual int getOption () const;
void setOption (
int opt
);
/** Defines the depth ID */
enum Depth
@ -860,40 +891,9 @@ public:
};
/** Sets the maximum depth */
virtual void setMaxDepth (int ids, size_t depth);
void setMaxDepth (int ids, size_t depth);
/** Gets the maximum depth */
virtual size_t getMaxDepth (int id) const;
/**
* The Awk::parse() function parses the source code read from the input
* stream @a in and writes the parse tree to the output stream @out.
* To disable deparsing, you may set @a out to Awk::Source::NONE.
* However, it is not legal to specify Awk::Source::NONE for @a in.
*
* @return a Run object on success, #QSE_NULL on failure
*/
virtual Awk::Run* parse (Source& in, Source& out);
/**
* Executes the BEGIN block, pattern-action blocks, and the END block.
* @return 0 on succes, -1 on failure
*/
virtual int loop ();
/**
* Calls a function
*/
virtual int call (
const char_t* name,
Value* ret,
const Value* args,
size_t nargs
);
/**
* Makes request to abort execution
*/
virtual void stop ();
size_t getMaxDepth (int id) const;
/**
* Adds an ARGV string as long as @a len characters pointed to
@ -901,7 +901,7 @@ public:
* to a script through ARGV.
* @return 0 on success, -1 on failure
*/
virtual int addArgument (
int addArgument (
const char_t* arg,
size_t len
);
@ -911,102 +911,117 @@ public:
* make a string added available to a script through ARGV.
* @return 0 on success, -1 on failure
*/
virtual int addArgument (const char_t* arg);
int addArgument (const char_t* arg);
/**
* Deletes all ARGV strings.
*/
virtual void clearArguments ();
void clearArguments ();
/**
* Adds a intrinsic global variable.
* Registers an intrinsic global variable.
* @return integer >= 0 on success, -1 on failure.
*/
virtual int addGlobal (const char_t* name);
int addGlobal (
const char_t* name ///< variable name
);
/**
* Deletes a intrinsic global variable.
* Unregisters an intrinsic global variable.
* @return 0 on success, -1 on failure.
*/
virtual int deleteGlobal (const char_t* name);
int deleteGlobal (
const char_t* name ///< variable name
);
/**
* Sets the value of a global variable identified by @a id.
* The @a id is either a value returned by Awk::addGlobal() or one of
* Awk::Global enumerations. It is not legal to call this function
* prior to Awk::parse().
* The @a id is either a value returned by Awk::addGlobal or one of
* Awk::Global enumerators. It is not legal to call this function
* prior to Awk::parse.
* @return 0 on success, -1 on failure
*/
virtual int setGlobal (int id, const Value& v);
/**
* Gets the value of a global riable identified by @a id.
* The @a id is either a value returned by Awk::addGlobal() or one of
* Awk::Global enumerations. It is not legal to call this function
* prior to Awk::parse().
* @return 0 on success, -1 on failure
*/
virtual int getGlobal (int id, Value& v);
int setGlobal (
int id, ///< numeric identifier
const Value& v ///< value
);
/**
* Represents a user-defined intrinsic function.
* Gets the value of a global riable identified by @a id.
* The @a id is either a value returned by Awk::addGlobal or one of
* Awk::::Global enumerators. It is not legal to call this function
* prior to Awk::parse.
* @return 0 on success, -1 on failure
*/
int getGlobal (
int id, ///< numeric identifier
Value& v ///< value store
);
/**
* Defines a intrinsic function handler.
*/
typedef int (Awk::*FunctionHandler) (
Run& run, Value& ret, const Value* args, size_t nargs,
const char_t* name, size_t len);
Run& run,
Value& ret,
const Value* args,
size_t nargs,
const cstr_t* name
);
/**
* Adds a new user-defined intrinsic function.
*/
virtual int addFunction (
int addFunction (
const char_t* name, size_t minArgs, size_t maxArgs,
FunctionHandler handler);
/**
* Deletes a user-defined intrinsic function
*/
virtual int deleteFunction (const char_t* name);
int deleteFunction (const char_t* name);
/*@}*/
/**
* Enables the run-time callback
*/
virtual void enableRunCallback ();
void enableRunCallback ();
/**
* Disables the run-time callback
*/
virtual void disableRunCallback ();
void disableRunCallback ();
/**
* @name Word Substitution
*/
/*@{*/
virtual int getWord (
int getWord (
const char_t* ow, qse_size_t owl,
const char_t** nw, qse_size_t* nwl
) throw ();
);
virtual int setWord (
int setWord (
const char_t* ow, const char_t* nw
) throw ();
);
virtual int setWord (
int setWord (
const char_t* ow, qse_size_t owl,
const char_t* nw, qse_size_t nwl
) throw ();
);
virtual int unsetWord (
int unsetWord (
const char_t* ow
) throw ();
);
virtual int unsetWord (
int unsetWord (
const char_t* ow, qse_size_t owl
) throw ();
);
virtual int unsetAllWords () throw ();
int unsetAllWords ();
/*@}*/
protected:
virtual int dispatchFunction (Run* run, const char_t* name, size_t len);
/**
* @name Pipe I/O handlers
* Pipe operations are achieved through the following functions.
@ -1069,9 +1084,7 @@ protected:
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
char_t* data, size_t count);
static int functionHandler (
rtx_t* rtx, const char_t* name, size_t len);
static void freeFunctionMapValue (map_t* map, void* dptr, size_t dlen);
static int functionHandler (rtx_t* rtx, const cstr_t* name);
static int onLoopEnter (rtx_t* run, void* data);
static void onLoopExit (rtx_t* run, val_t* ret, void* data);
@ -1083,7 +1096,10 @@ protected:
protected:
awk_t* awk;
errstr_t dflerrstr;
errinf_t errinf;
map_t* functionMap;
Source::Data sourceIn;
@ -1092,11 +1108,7 @@ protected:
Source* sourceReader;
Source* sourceWriter;
ErrorNumber errnum;
size_t errlin;
char_t errmsg[256];
bool runCallback;
bool runCallback;
struct xstrs_t
{
@ -1118,7 +1130,9 @@ private:
int init_runctx ();
void fini_runctx ();
static const char_t* xerrstr (awk_t* a, errnum_t num) throw ();
int dispatch_function (Run* run, const cstr_t* name);
static const char_t* xerrstr (awk_t* a, errnum_t num);
private:
Awk (const Awk&);

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.hpp 230 2009-07-13 08:51:23Z hyunghwan.chung $
* $Id: StdAwk.hpp 235 2009-07-15 10:43:31Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -74,9 +74,9 @@ public:
int open ();
void close ();
virtual int addConsoleOutput (const char_t* arg, size_t len);
virtual int addConsoleOutput (const char_t* arg);
virtual void clearConsoleOutputs ();
int addConsoleOutput (const char_t* arg, size_t len);
int addConsoleOutput (const char_t* arg);
void clearConsoleOutputs ();
protected:
// intrinsic functions
@ -128,9 +128,9 @@ protected:
int nextConsole (Console& io);
// primitive handlers
void* allocMem (size_t n) throw ();
void* reallocMem (void* ptr, size_t n) throw ();
void freeMem (void* ptr) throw ();
void* allocMem (size_t n);
void* reallocMem (void* ptr, size_t n);
void freeMem (void* ptr);
real_t pow (real_t x, real_t y);
int vsprintf (char_t* buf, size_t size,

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 232 2009-07-14 08:06:14Z hyunghwan.chung $
* $Id: awk.h 235 2009-07-15 10:43:31Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -254,8 +254,7 @@ typedef int (*qse_awk_sprintf_t) (
*/
typedef int (*qse_awk_fnc_fun_t) (
qse_awk_rtx_t* rtx, /**< runtime context */
const qse_char_t* name, /**< function name */
qse_size_t len /**< name length */
const qse_cstr_t* name /**< function name */
);
/**
@ -710,8 +709,7 @@ enum qse_awk_errnum_t
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_EFNCIMPL, /**< intrinsic function handler for '${0}' 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 */
@ -1036,6 +1034,9 @@ void qse_awk_geterror (
const qse_char_t** errmsg
);
/**
* The qse_awk_seterror() functon sets
*/
void qse_awk_seterror (
qse_awk_t* awk,
qse_awk_errnum_t errnum,

View File

@ -1,5 +1,5 @@
/*
* $Id: Sed.hpp 191 2009-06-07 13:09:14Z hyunghwan.chung $
* $Id: Sed.hpp 235 2009-07-15 10:43:31Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -54,7 +54,7 @@ public:
/**
* The Sed() function creates an uninitialized stream editor.
*/
Sed () throw (): sed (QSE_NULL), dflerrstr (QSE_NULL) {}
Sed (): sed (QSE_NULL), dflerrstr (QSE_NULL) {}
/**
* The ~Sed() function destroys a stream editor.
@ -70,12 +70,12 @@ public:
* ready for subsequent use.
* @return 0 on success, -1 on failure.
*/
int open () throw ();
int open ();
/**
* The close() function finalizes a stream editor.
*/
void close () throw ();
void close ();
/**
* The compile() function compiles a null-terminated string pointed
@ -84,7 +84,7 @@ public:
*/
int compile (
const char_t* sptr ///< a pointer to a null-terminated string
) throw ();
);
/**
* The compile() function compiles a string pointed to by @a sptr
@ -94,20 +94,20 @@ public:
int compile (
const char_t* sptr, ///< a pointer to a string
size_t slen ///< the number of characters in the string
) throw ();
);
/**
* The execute() function executes compiled commands over the IO
* streams defined through IO handlers
* @return 0 on success, -1 on failure
*/
int execute () throw ();
int execute ();
/**
* The getOption() function gets the current options.
* @return current option code
*/
int getOption () const throw ();
int getOption () const;
/**
* The setOption() function sets options for a stream editor.
@ -115,12 +115,12 @@ public:
*/
void setOption (
int opt ///< option code
) throw ();
);
/**
* The getMaxDepth() function gets the maximum processing depth.
*/
size_t getMaxDepth (depth_t id) const throw ();
size_t getMaxDepth (depth_t id) const;
/**
* The setMaxDepth() function gets the maximum processing depth.
@ -128,35 +128,28 @@ public:
void setMaxDepth (
int ids, ///< 0 or a number OR'ed of depth_t values
size_t depth ///< 0 maximum depth
) throw ();
);
/**
* The getErrorMessage() function gets the description of the last
* error occurred. It returns an empty string if the stream editor
* has not been initialized with the open() function.
*/
const char_t* getErrorMessage() const throw ();
const char_t* getErrorMessage() const;
/**
* The getErrorLine() function gets the number of the line where
* the last error occurred. It returns 0 if the stream editor has
* not been initialized with the open() function.
*/
size_t getErrorLine () const throw ();
size_t getErrorLine () const;
/**
* The getErrorNumber() function gets the number of the last
* error occurred. It returns QSE_SED_ENOERR if the stream editor
* has not been initialized with the open() function.
*/
errnum_t getErrorNumber () const throw ();
/**
* The getConsoleLine() function returns the current line
* number from an input console.
* @return current line number
*/
size_t getConsoleLine () throw ();
errnum_t getErrorNumber () const;
/**
* The setError() function sets information on an error occurred.
@ -167,13 +160,20 @@ public:
const cstr_t* args = QSE_NULL ///< strings for formatting an error message
);
/**
* The getConsoleLine() function returns the current line
* number from an input console.
* @return current line number
*/
size_t getConsoleLine ();
/**
* The setConsoleLine() function changes the current line
* number from an input console.
*/
void setConsoleLine (
size_t num ///< a line number
) throw ();
);
protected:
/**
@ -194,7 +194,7 @@ protected:
};
protected:
IOBase (io_arg_t* arg, Mode mode) throw ():
IOBase (io_arg_t* arg, Mode mode):
arg(arg), mode (mode) {}
public:
@ -204,7 +204,7 @@ protected:
* an assoicated IO handler closes it or changes it with
* another call to setHandle().
*/
const void* getHandle () const throw ()
const void* getHandle () const
{
return arg->handle;
}
@ -215,7 +215,7 @@ protected:
* and Sed::openFile(). You can get the handle with the
* getHandle() function as needed.
*/
void setHandle (void* handle) throw ()
void setHandle (void* handle)
{
arg->handle = handle;
}
@ -225,7 +225,7 @@ protected:
* A stream opening function can inspect the mode requested and
* open a stream properly
*/
Mode getMode () throw ()
Mode getMode ()
{
return this->mode;
}
@ -244,7 +244,7 @@ protected:
{
protected:
friend class Sed;
Console (io_arg_t* arg, Mode mode) throw ():
Console (io_arg_t* arg, Mode mode):
IOBase (arg, mode) {}
};
@ -256,7 +256,7 @@ protected:
{
protected:
friend class Sed;
File (io_arg_t* arg, Mode mode) throw ():
File (io_arg_t* arg, Mode mode):
IOBase (arg, mode) {}
public:
@ -265,7 +265,7 @@ protected:
* You can call this function from the openFile() function
* to determine a file to open.
*/
const char_t* getName () const throw ()
const char_t* getName () const
{
return arg->path;
}
@ -395,9 +395,9 @@ protected:
errstr_t dflerrstr;
private:
static ssize_t xin (sed_t* s, io_cmd_t cmd, io_arg_t* arg) throw ();
static ssize_t xout (sed_t* s, io_cmd_t cmd, io_arg_t* arg) throw ();
static const char_t* xerrstr (sed_t* s, errnum_t num) throw ();
static ssize_t xin (sed_t* s, io_cmd_t cmd, io_arg_t* arg);
static ssize_t xout (sed_t* s, io_cmd_t cmd, io_arg_t* arg);
static const char_t* xerrstr (sed_t* s, errnum_t num);
private:
Sed (const Sed&);

View File

@ -1,5 +1,5 @@
/*
* $Id: StdSed.hpp 191 2009-06-07 13:09:14Z hyunghwan.chung $
* $Id: StdSed.hpp 235 2009-07-15 10:43:31Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -33,9 +33,9 @@ QSE_BEGIN_NAMESPACE(QSE)
class StdSed: public Sed
{
protected:
void* allocMem (qse_size_t n) throw ();
void* reallocMem (void* ptr, qse_size_t n) throw ();
void freeMem (void* ptr) throw ();
void* allocMem (qse_size_t n);
void* reallocMem (void* ptr, qse_size_t n);
void freeMem (void* ptr);
int openConsole (Console& io);
int closeConsole (Console& io);