cleaned up code a little
This commit is contained in:
parent
782f17c7e1
commit
e149b933f7
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp 232 2009-07-14 08:06:14Z hyunghwan.chung $
|
||||
* $Id: Awk.hpp 234 2009-07-14 14:08:48Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -30,7 +30,7 @@ QSE_BEGIN_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
/**
|
||||
* Represents the AWK interpreter engine
|
||||
* Represents the AWK interpreter engine.
|
||||
*/
|
||||
class Awk: public Mmgr
|
||||
{
|
||||
@ -63,8 +63,8 @@ protected:
|
||||
|
||||
public:
|
||||
/**
|
||||
* The Awk::Source class is an abstract class to encapsulate
|
||||
* source script I/O. The Awk::parse function requires a concrete
|
||||
* 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
|
||||
@ -251,6 +251,9 @@ public:
|
||||
char_t* filename;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a value.
|
||||
*/
|
||||
class Value
|
||||
{
|
||||
public:
|
||||
@ -693,9 +696,9 @@ public:
|
||||
void stop () const;
|
||||
bool isStop () const;
|
||||
|
||||
ErrorNumber getErrorNumber () const;
|
||||
size_t getErrorLine () const;
|
||||
const char_t* getErrorMessage () const;
|
||||
ErrorNumber errorNumber () const throw ();
|
||||
size_t errorLine () const throw ();
|
||||
const char_t* errorMessage () const throw ();
|
||||
|
||||
void setError (ErrorNumber code);
|
||||
void setError (ErrorNumber code, size_t line);
|
||||
@ -751,49 +754,88 @@ public:
|
||||
/** Returns the underlying handle */
|
||||
operator awk_t* () const;
|
||||
|
||||
/** Returns the error code */
|
||||
ErrorNumber getErrorNumber () const;
|
||||
|
||||
/** Returns the line of the source code where the error occurred */
|
||||
size_t getErrorLine () const ;
|
||||
|
||||
/** Returns the error message */
|
||||
const char_t* getErrorMessage () const;
|
||||
|
||||
mmgr_t* getMmgr()
|
||||
{
|
||||
return qse_awk_getmmgr (awk);
|
||||
}
|
||||
|
||||
const mmgr_t* getMmgr() const
|
||||
{
|
||||
return qse_awk_getmmgr (awk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Error Handling
|
||||
*/
|
||||
/*@{*/
|
||||
protected:
|
||||
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 ();
|
||||
void retrieveError ();
|
||||
void retrieveError (rtx_t* rtx);
|
||||
/**
|
||||
* 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 ();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Opens the interpreter.
|
||||
*
|
||||
* An application should call this method before doing anything
|
||||
* meaningful to the instance of this class.
|
||||
*
|
||||
* @return
|
||||
* On success, 0 is returned. On failure -1 is returned and
|
||||
* extended error information is set. Call Awk::getErrorNumber
|
||||
* to get it.
|
||||
* 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 ();
|
||||
|
||||
@ -822,30 +864,11 @@ public:
|
||||
/** Gets the maximum depth */
|
||||
virtual size_t getMaxDepth (int id) const;
|
||||
|
||||
virtual const char_t* getErrorString (
|
||||
ErrorNumber num
|
||||
) const;
|
||||
|
||||
virtual int getWord (
|
||||
const char_t* ow, qse_size_t owl,
|
||||
const char_t** nw, qse_size_t* nwl);
|
||||
virtual int setWord (
|
||||
const char_t* ow, const char_t* nw);
|
||||
virtual int setWord (
|
||||
const char_t* ow, qse_size_t owl,
|
||||
const char_t* nw, qse_size_t nwl);
|
||||
|
||||
virtual int unsetWord (const char_t* ow);
|
||||
virtual int unsetWord (const char_t* ow, qse_size_t owl);
|
||||
virtual int unsetAllWords ();
|
||||
|
||||
/**
|
||||
* Parses the source code.
|
||||
*
|
||||
* Awk::parse 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.
|
||||
* 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
|
||||
*/
|
||||
@ -873,15 +896,21 @@ public:
|
||||
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.
|
||||
* Adds an ARGV string as long as @a len characters pointed to
|
||||
* by @a arg. loop() and call() make a string added available
|
||||
* to a script through ARGV.
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
virtual int addArgument (
|
||||
const char_t* arg,
|
||||
size_t len
|
||||
);
|
||||
|
||||
/**
|
||||
* Adds a null-terminated string @a arg. loop() and call()
|
||||
* make a string added available to a script through ARGV.
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
virtual int addArgument (const char_t* arg);
|
||||
|
||||
/**
|
||||
@ -902,17 +931,17 @@ public:
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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.
|
||||
* 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
|
||||
* 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.
|
||||
* prior to Awk::parse().
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
virtual int getGlobal (int id, Value& v);
|
||||
@ -946,12 +975,41 @@ public:
|
||||
*/
|
||||
virtual void disableRunCallback ();
|
||||
|
||||
/**
|
||||
* @name Word Substitution
|
||||
*/
|
||||
/*@{*/
|
||||
virtual int getWord (
|
||||
const char_t* ow, qse_size_t owl,
|
||||
const char_t** nw, qse_size_t* nwl
|
||||
) throw ();
|
||||
|
||||
virtual int setWord (
|
||||
const char_t* ow, const char_t* nw
|
||||
) throw ();
|
||||
|
||||
virtual int setWord (
|
||||
const char_t* ow, qse_size_t owl,
|
||||
const char_t* nw, qse_size_t nwl
|
||||
) throw ();
|
||||
|
||||
virtual int unsetWord (
|
||||
const char_t* ow
|
||||
) throw ();
|
||||
|
||||
virtual int unsetWord (
|
||||
const char_t* ow, qse_size_t owl
|
||||
) throw ();
|
||||
|
||||
virtual int unsetAllWords () throw ();
|
||||
/*@}*/
|
||||
|
||||
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 methods.
|
||||
* Pipe operations are achieved through the following functions.
|
||||
*/
|
||||
/*@{*/
|
||||
virtual int openPipe (Pipe& io) = 0;
|
||||
@ -963,7 +1021,7 @@ protected:
|
||||
|
||||
/**
|
||||
* @name File I/O handlers
|
||||
* File operations are achieved through the following methods.
|
||||
* File operations are achieved through the following functions.
|
||||
*/
|
||||
/*@{*/
|
||||
virtual int openFile (File& io) = 0;
|
||||
@ -975,7 +1033,7 @@ protected:
|
||||
|
||||
/**
|
||||
* @name Console I/O handlers
|
||||
* Console operations are achieved through the following methods.
|
||||
* Console operations are achieved through the following functions.
|
||||
*/
|
||||
virtual int openConsole (Console& io) = 0;
|
||||
virtual int closeConsole (Console& io) = 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp 232 2009-07-14 08:06:14Z hyunghwan.chung $
|
||||
* $Id: Awk.cpp 234 2009-07-14 14:08:48Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -375,7 +375,7 @@ int Awk::Value::getInt (long_t* v) const
|
||||
int n = qse_awk_rtx_valtonum (run->rtx, val, &lv, &rv);
|
||||
if (n <= -1)
|
||||
{
|
||||
run->awk->retrieveError (run->rtx);
|
||||
run->awk->retrieveError (run);
|
||||
return -1;
|
||||
}
|
||||
if (n >= 1) lv = rv;
|
||||
@ -399,7 +399,7 @@ int Awk::Value::getReal (real_t* v) const
|
||||
int n = qse_awk_rtx_valtonum (run->rtx, val, &lv, &rv);
|
||||
if (n <= -1)
|
||||
{
|
||||
run->awk->retrieveError (run->rtx);
|
||||
run->awk->retrieveError (run);
|
||||
return -1;
|
||||
}
|
||||
if (n == 0) rv = lv;
|
||||
@ -434,7 +434,7 @@ int Awk::Value::getStr (const char_t** str, size_t* len) const
|
||||
if (qse_awk_rtx_valtostr (
|
||||
run->rtx, val, &out) == QSE_NULL)
|
||||
{
|
||||
run->awk->retrieveError (run->rtx);
|
||||
run->awk->retrieveError (run);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -498,7 +498,7 @@ int Awk::Value::setInt (Run* r, long_t v)
|
||||
tmp = qse_awk_rtx_makeintval (r->rtx, v);
|
||||
if (tmp == QSE_NULL)
|
||||
{
|
||||
r->awk->retrieveError (r->rtx);
|
||||
r->awk->retrieveError (r);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -519,7 +519,7 @@ int Awk::Value::setReal (Run* r, real_t v)
|
||||
tmp = qse_awk_rtx_makerealval (r->rtx, v);
|
||||
if (tmp == QSE_NULL)
|
||||
{
|
||||
r->awk->retrieveError (r->rtx);
|
||||
r->awk->retrieveError (r);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -540,7 +540,7 @@ int Awk::Value::setStr (Run* r, const char_t* str, size_t len)
|
||||
tmp = qse_awk_rtx_makestrval (r->rtx, str, len);
|
||||
if (tmp == QSE_NULL)
|
||||
{
|
||||
r->awk->retrieveError (r->rtx);
|
||||
r->awk->retrieveError (r);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -561,7 +561,7 @@ int Awk::Value::setStr (Run* r, const char_t* str)
|
||||
tmp = qse_awk_rtx_makestrval0 (r->rtx, str);
|
||||
if (tmp == QSE_NULL)
|
||||
{
|
||||
r->awk->retrieveError (r->rtx);
|
||||
r->awk->retrieveError (r);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -587,7 +587,7 @@ int Awk::Value::setIndexedVal (Run* r, const Index& idx, val_t* v)
|
||||
val_t* map = qse_awk_rtx_makemapval (r->rtx);
|
||||
if (map == QSE_NULL)
|
||||
{
|
||||
r->awk->retrieveError (r->rtx);
|
||||
r->awk->retrieveError (r);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -603,7 +603,7 @@ int Awk::Value::setIndexedVal (Run* r, const Index& idx, val_t* v)
|
||||
qse_awk_rtx_refdownval (r->rtx, v);
|
||||
qse_awk_rtx_refdownval (r->rtx, map);
|
||||
r->setError (ERR_NOMEM, 0, QSE_NULL, 0);
|
||||
r->awk->retrieveError (r->rtx);
|
||||
r->awk->retrieveError (r);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -624,7 +624,7 @@ int Awk::Value::setIndexedVal (Run* r, const Index& idx, val_t* v)
|
||||
{
|
||||
// it can't span across multiple runtime contexts
|
||||
run->setError (ERR_INVAL);
|
||||
run->awk->retrieveError (run->rtx);
|
||||
run->awk->retrieveError (run);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -637,7 +637,7 @@ int Awk::Value::setIndexedVal (Run* r, const Index& idx, val_t* v)
|
||||
{
|
||||
qse_awk_rtx_refdownval (r->rtx, v);
|
||||
run->setError (ERR_NOMEM);
|
||||
run->awk->retrieveError (run->rtx);
|
||||
run->awk->retrieveError (run);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -657,7 +657,7 @@ int Awk::Value::setIndexedInt (Run* r, const Index& idx, long_t v)
|
||||
tmp = qse_awk_rtx_makeintval (r->rtx, v);
|
||||
if (tmp == QSE_NULL)
|
||||
{
|
||||
r->awk->retrieveError (r->rtx);
|
||||
r->awk->retrieveError (r);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -680,7 +680,7 @@ int Awk::Value::setIndexedReal (Run* r, const Index& idx, real_t v)
|
||||
tmp = qse_awk_rtx_makerealval (r->rtx, v);
|
||||
if (tmp == QSE_NULL)
|
||||
{
|
||||
r->awk->retrieveError (r->rtx);
|
||||
r->awk->retrieveError (r);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -704,7 +704,7 @@ int Awk::Value::setIndexedStr (
|
||||
tmp = qse_awk_rtx_makestrval (r->rtx, str, len);
|
||||
if (tmp == QSE_NULL)
|
||||
{
|
||||
r->awk->retrieveError (r->rtx);
|
||||
r->awk->retrieveError (r);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -727,7 +727,7 @@ int Awk::Value::setIndexedStr (Run* r, const Index& idx, const char_t* str)
|
||||
tmp = qse_awk_rtx_makestrval0 (r->rtx, str);
|
||||
if (tmp == QSE_NULL)
|
||||
{
|
||||
r->awk->retrieveError (r->rtx);
|
||||
r->awk->retrieveError (r);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -899,19 +899,19 @@ bool Awk::Run::isStop () const
|
||||
return qse_awk_rtx_shouldstop (this->rtx)? true: false;
|
||||
}
|
||||
|
||||
Awk::ErrorNumber Awk::Run::getErrorNumber () const
|
||||
Awk::ErrorNumber Awk::Run::errorNumber () const throw ()
|
||||
{
|
||||
QSE_ASSERT (this->rtx != QSE_NULL);
|
||||
return (ErrorNumber)qse_awk_rtx_geterrnum (this->rtx);
|
||||
}
|
||||
|
||||
Awk::size_t Awk::Run::getErrorLine () const
|
||||
Awk::size_t Awk::Run::errorLine () const throw ()
|
||||
{
|
||||
QSE_ASSERT (this->rtx != QSE_NULL);
|
||||
return qse_awk_rtx_geterrlin (this->rtx);
|
||||
}
|
||||
|
||||
const Awk::char_t* Awk::Run::getErrorMessage () const
|
||||
const Awk::char_t* Awk::Run::errorMessage () const throw ()
|
||||
{
|
||||
QSE_ASSERT (this->rtx != QSE_NULL);
|
||||
return qse_awk_rtx_geterrmsg (this->rtx);
|
||||
@ -1027,17 +1027,31 @@ Awk::operator Awk::awk_t* () const
|
||||
return this->awk;
|
||||
}
|
||||
|
||||
Awk::ErrorNumber Awk::getErrorNumber () const
|
||||
const Awk::char_t* Awk::errorString (ErrorNumber num) const throw ()
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
QSE_ASSERT (dflerrstr != QSE_NULL);
|
||||
return dflerrstr (awk, (errnum_t)num);
|
||||
}
|
||||
|
||||
const Awk::char_t* Awk::xerrstr (awk_t* a, errnum_t num) throw ()
|
||||
{
|
||||
Awk* awk = *(Awk**)QSE_XTN(a);
|
||||
return awk->errorString ((ErrorNumber)num);
|
||||
}
|
||||
|
||||
|
||||
Awk::ErrorNumber Awk::errorNumber () const throw ()
|
||||
{
|
||||
return this->errnum;
|
||||
}
|
||||
|
||||
Awk::size_t Awk::getErrorLine () const
|
||||
Awk::size_t Awk::errorLine () const throw ()
|
||||
{
|
||||
return this->errlin;
|
||||
}
|
||||
|
||||
const Awk::char_t* Awk::getErrorMessage () const
|
||||
const Awk::char_t* Awk::errorMessage () const throw ()
|
||||
{
|
||||
return this->errmsg;
|
||||
}
|
||||
@ -1119,12 +1133,15 @@ void Awk::retrieveError ()
|
||||
}
|
||||
}
|
||||
|
||||
void Awk::retrieveError (rtx_t* rtx)
|
||||
void Awk::retrieveError (Run* run)
|
||||
{
|
||||
errnum_t num;
|
||||
const char_t* msg;
|
||||
|
||||
qse_awk_rtx_geterror (rtx, &num, &this->errlin, &msg);
|
||||
QSE_ASSERT (run != QSE_NULL);
|
||||
if (run->rtx == QSE_NULL) return;
|
||||
|
||||
qse_awk_rtx_geterror (run->rtx, &num, &this->errlin, &msg);
|
||||
this->errnum = (ErrorNumber)num;
|
||||
qse_strxcpy (this->errmsg, QSE_COUNTOF(this->errmsg), msg);
|
||||
}
|
||||
@ -1137,7 +1154,7 @@ int Awk::open ()
|
||||
prm.pow = pow;
|
||||
prm.sprintf = sprintf;
|
||||
|
||||
awk = qse_awk_open (this, QSE_SIZEOF(xtn_t), &prm);
|
||||
awk = qse_awk_open ((qse_mmgr_t*)this, QSE_SIZEOF(xtn_t), &prm);
|
||||
if (awk == QSE_NULL)
|
||||
{
|
||||
setError (ERR_NOMEM);
|
||||
@ -1151,9 +1168,6 @@ int Awk::open ()
|
||||
dflerrstr = qse_awk_geterrstr (awk);
|
||||
qse_awk_seterrstr (awk, xerrstr);
|
||||
|
||||
//functionMap = qse_map_open (
|
||||
// this, 512, 70, freeFunctionMapValue, QSE_NULL,
|
||||
// qse_awk_getmmgr(awk));
|
||||
functionMap = qse_map_open (
|
||||
qse_awk_getmmgr(awk), QSE_SIZEOF(this), 512, 70);
|
||||
if (functionMap == QSE_NULL)
|
||||
@ -1219,63 +1233,6 @@ Awk::size_t Awk::getMaxDepth (int id) const
|
||||
return qse_awk_getmaxdepth (awk, id);
|
||||
}
|
||||
|
||||
const Awk::char_t* Awk::getErrorString (ErrorNumber num) const
|
||||
{
|
||||
QSE_ASSERT (dflerrstr != QSE_NULL);
|
||||
return dflerrstr (awk, (errnum_t)num);
|
||||
}
|
||||
|
||||
const Awk::char_t* Awk::xerrstr (awk_t* a, errnum_t num) throw ()
|
||||
{
|
||||
Awk* awk = *(Awk**)QSE_XTN(a);
|
||||
try
|
||||
{
|
||||
return awk->getErrorString ((ErrorNumber)num);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return awk->dflerrstr (a, num);
|
||||
}
|
||||
}
|
||||
|
||||
int Awk::getWord (
|
||||
const char_t* ow, qse_size_t owl,
|
||||
const char_t** nw, qse_size_t* nwl)
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
return qse_awk_getword (awk, ow, owl, nw, nwl);
|
||||
}
|
||||
|
||||
int Awk::setWord (const char_t* ow, const char_t* nw)
|
||||
{
|
||||
return setWord (ow, qse_strlen(ow), nw, qse_strlen(nw));
|
||||
}
|
||||
|
||||
int Awk::setWord (
|
||||
const char_t* ow, qse_size_t owl,
|
||||
const char_t* nw, qse_size_t nwl)
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
return qse_awk_setword (awk, ow, owl, nw, nwl);
|
||||
}
|
||||
|
||||
int Awk::unsetWord (const char_t* ow)
|
||||
{
|
||||
return unsetWord (ow, qse_strlen(ow));
|
||||
}
|
||||
|
||||
int Awk::unsetWord (const char_t* ow, qse_size_t owl)
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
return qse_awk_setword (awk, ow, owl, QSE_NULL, 0);
|
||||
}
|
||||
|
||||
int Awk::unsetAllWords ()
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
return qse_awk_setword (awk, QSE_NULL, 0, QSE_NULL, 0);
|
||||
}
|
||||
|
||||
Awk::Run* Awk::parse (Source& in, Source& out)
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
@ -1358,7 +1315,7 @@ int Awk::loop ()
|
||||
QSE_ASSERT (runctx.rtx != QSE_NULL);
|
||||
|
||||
int n = qse_awk_rtx_loop (runctx.rtx);
|
||||
if (n <= -1) retrieveError (runctx.rtx);
|
||||
if (n <= -1) retrieveError (&runctx);
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -1380,7 +1337,7 @@ int Awk::call (const char_t* name, Value* ret, const Value* args, size_t nargs)
|
||||
if (ptr == QSE_NULL)
|
||||
{
|
||||
runctx.setError (ERR_NOMEM);
|
||||
retrieveError (runctx.rtx);
|
||||
retrieveError (&runctx);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1394,7 +1351,7 @@ int Awk::call (const char_t* name, Value* ret, const Value* args, size_t nargs)
|
||||
|
||||
if (rv == QSE_NULL)
|
||||
{
|
||||
retrieveError (runctx.rtx);
|
||||
retrieveError (&runctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1634,6 +1591,45 @@ void Awk::disableRunCallback ()
|
||||
runCallback = false;
|
||||
}
|
||||
|
||||
int Awk::getWord (
|
||||
const char_t* ow, qse_size_t owl,
|
||||
const char_t** nw, qse_size_t* nwl) throw ()
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
return qse_awk_getword (awk, ow, owl, nw, nwl);
|
||||
}
|
||||
|
||||
int Awk::setWord (const char_t* ow, const char_t* nw) throw ()
|
||||
{
|
||||
return setWord (ow, qse_strlen(ow), nw, qse_strlen(nw));
|
||||
}
|
||||
|
||||
int Awk::setWord (
|
||||
const char_t* ow, qse_size_t owl,
|
||||
const char_t* nw, qse_size_t nwl) throw ()
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
return qse_awk_setword (awk, ow, owl, nw, nwl);
|
||||
}
|
||||
|
||||
int Awk::unsetWord (const char_t* ow) throw ()
|
||||
{
|
||||
return unsetWord (ow, qse_strlen(ow));
|
||||
}
|
||||
|
||||
int Awk::unsetWord (const char_t* ow, qse_size_t owl) throw ()
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
return qse_awk_setword (awk, ow, owl, QSE_NULL, 0);
|
||||
}
|
||||
|
||||
int Awk::unsetAllWords () throw ()
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
return qse_awk_setword (awk, QSE_NULL, 0, QSE_NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
bool Awk::onLoopEnter (Run& run)
|
||||
{
|
||||
return true;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: StdAwk.cpp 229 2009-07-12 13:06:01Z hyunghwan.chung $
|
||||
* $Id: StdAwk.cpp 234 2009-07-14 14:08:48Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -302,7 +302,7 @@ int StdAwk::openPipe (Pipe& io)
|
||||
}
|
||||
|
||||
pio = qse_pio_open (
|
||||
((Awk*)io)->getMmgr(),
|
||||
(qse_mmgr_t*)this,
|
||||
0,
|
||||
io.getName(),
|
||||
flags
|
||||
@ -357,7 +357,7 @@ int StdAwk::openFile (File& io)
|
||||
}
|
||||
|
||||
fio = qse_fio_open (
|
||||
((Awk*)io)->getMmgr(),
|
||||
(qse_mmgr_t*)this,
|
||||
0,
|
||||
io.getName(),
|
||||
flags,
|
||||
|
@ -65,7 +65,7 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
int ret = awk.open ();
|
||||
if (ret >= 0) ret = run_awk (awk);
|
||||
|
||||
if (ret <= -1) print_error (awk.getErrorLine(), awk.getErrorMessage());
|
||||
if (ret <= -1) print_error (awk.errorLine(), awk.errorMessage());
|
||||
|
||||
awk.close ();
|
||||
return ret;
|
||||
|
@ -78,7 +78,7 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
int ret = awk.open();
|
||||
|
||||
if (ret >= 0) ret = run_awk (awk);
|
||||
if (ret <= -1) print_error (awk.getErrorLine(), awk.getErrorMessage());
|
||||
if (ret <= -1) print_error (awk.errorLine(), awk.errorMessage());
|
||||
|
||||
awk.close ();
|
||||
return -1;
|
||||
|
@ -123,7 +123,7 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
QSE::StdAwk::OPT_RESET);
|
||||
|
||||
if (ret >= 0) ret = run_awk (awk);
|
||||
if (ret <= -1) print_error (awk.getErrorLine(), awk.getErrorMessage());
|
||||
if (ret <= -1) print_error (awk.errorLine(), awk.errorMessage());
|
||||
|
||||
awk.close ();
|
||||
return -1;
|
||||
|
@ -481,14 +481,14 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
|
||||
if (awk.open() <= -1)
|
||||
{
|
||||
print_error (awk.getErrorMessage());
|
||||
print_error (awk.errorMessage());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ARGV[0]
|
||||
if (awk.addArgument (QSE_T("awk05")) <= -1)
|
||||
{
|
||||
print_error (awk.getErrorMessage());
|
||||
print_error (awk.errorMessage());
|
||||
awk.close ();
|
||||
return -1;
|
||||
}
|
||||
@ -629,7 +629,7 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
if (run == QSE_NULL)
|
||||
{
|
||||
qse_fprintf (stderr, QSE_T("cannot parse: LINE[%d] %s\n"),
|
||||
awk.getErrorLine(), awk.getErrorMessage());
|
||||
awk.errorLine(), awk.errorMessage());
|
||||
awk.close ();
|
||||
return -1;
|
||||
}
|
||||
@ -640,7 +640,7 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
if (awk.loop () <= -1)
|
||||
{
|
||||
qse_fprintf (stderr, QSE_T("cannot run: LINE[%d] %s\n"),
|
||||
awk.getErrorLine(), awk.getErrorMessage());
|
||||
awk.errorLine(), awk.errorMessage());
|
||||
awk.close ();
|
||||
return -1;
|
||||
}
|
||||
@ -654,7 +654,7 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
if (awk.call (QSE_T("add"), args, 2) <= -1)
|
||||
{
|
||||
qse_fprintf (stderr, QSE_T("cannot run: LINE[%d] %s\n"),
|
||||
awk.getErrorLine(), awk.getErrorMessage());
|
||||
awk.errorLine(), awk.errorMessage());
|
||||
awk.close ();
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user