- added Awk::setGlobal & Awk::getGlobal
- fixed a bug in parsing getline
This commit is contained in:
parent
af6831ed3c
commit
f5e3e53290
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.hpp 231 2009-07-13 10:03:53Z hyunghwan.chung $
|
* $Id: Awk.hpp 232 2009-07-14 08:06:14Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -254,6 +254,8 @@ public:
|
|||||||
class Value
|
class Value
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
friend class Awk;
|
||||||
|
|
||||||
// initialization
|
// initialization
|
||||||
void* operator new (size_t n, Run* run) throw ();
|
void* operator new (size_t n, Run* run) throw ();
|
||||||
void* operator new[] (size_t n, Run* run) throw ();
|
void* operator new[] (size_t n, Run* run) throw ();
|
||||||
@ -556,6 +558,7 @@ public:
|
|||||||
ERR_NEXTFEND = QSE_AWK_ENEXTFEND,
|
ERR_NEXTFEND = QSE_AWK_ENEXTFEND,
|
||||||
ERR_PRINTFARG = QSE_AWK_EPRINTFARG,
|
ERR_PRINTFARG = QSE_AWK_EPRINTFARG,
|
||||||
ERR_PREPST = QSE_AWK_EPREPST,
|
ERR_PREPST = QSE_AWK_EPREPST,
|
||||||
|
ERR_INCDECOPR = QSE_AWK_EINCDECOPR,
|
||||||
ERR_DIVBY0 = QSE_AWK_EDIVBY0,
|
ERR_DIVBY0 = QSE_AWK_EDIVBY0,
|
||||||
ERR_OPERAND = QSE_AWK_EOPERAND,
|
ERR_OPERAND = QSE_AWK_EOPERAND,
|
||||||
ERR_POSIDX = QSE_AWK_EPOSIDX,
|
ERR_POSIDX = QSE_AWK_EPOSIDX,
|
||||||
@ -647,25 +650,29 @@ public:
|
|||||||
};
|
};
|
||||||
// end of enum Option
|
// end of enum Option
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines an identifier of predefined global variables.
|
||||||
|
* Awk::setGlobal and Awk::getGlobal can take one of these enumeration.
|
||||||
|
*/
|
||||||
enum Global
|
enum Global
|
||||||
{
|
{
|
||||||
GBL_ARGC = QSE_AWK_GBL_ARGC,
|
GBL_ARGC = QSE_AWK_GBL_ARGC, /**< ARGC */
|
||||||
GBL_ARGV = QSE_AWK_GBL_ARGV,
|
GBL_ARGV = QSE_AWK_GBL_ARGV, /**< ARGV */
|
||||||
GBL_CONVFMT = QSE_AWK_GBL_CONVFMT,
|
GBL_CONVFMT = QSE_AWK_GBL_CONVFMT, /**< CONVFMT */
|
||||||
GBL_FILENAME = QSE_AWK_GBL_FILENAME,
|
GBL_FILENAME = QSE_AWK_GBL_FILENAME, /**< FILENAME */
|
||||||
GBL_FNR = QSE_AWK_GBL_FNR,
|
GBL_FNR = QSE_AWK_GBL_FNR, /**< FNR */
|
||||||
GBL_FS = QSE_AWK_GBL_FS,
|
GBL_FS = QSE_AWK_GBL_FS, /**< FS */
|
||||||
GBL_IGNORECASE = QSE_AWK_GBL_IGNORECASE,
|
GBL_IGNORECASE = QSE_AWK_GBL_IGNORECASE, /**< IGNORECASE */
|
||||||
GBL_NF = QSE_AWK_GBL_NF,
|
GBL_NF = QSE_AWK_GBL_NF, /**< NF */
|
||||||
GBL_NR = QSE_AWK_GBL_NR,
|
GBL_NR = QSE_AWK_GBL_NR, /**< NR */
|
||||||
GBL_OFILENAME = QSE_AWK_GBL_OFILENAME,
|
GBL_OFILENAME = QSE_AWK_GBL_OFILENAME, /**< OFILENAME */
|
||||||
GBL_OFMT = QSE_AWK_GBL_OFMT,
|
GBL_OFMT = QSE_AWK_GBL_OFMT, /**< OFMT */
|
||||||
GBL_OFS = QSE_AWK_GBL_OFS,
|
GBL_OFS = QSE_AWK_GBL_OFS, /**< OFS */
|
||||||
GBL_ORS = QSE_AWK_GBL_ORS,
|
GBL_ORS = QSE_AWK_GBL_ORS, /**< ORS */
|
||||||
GBL_RLENGTH = QSE_AWK_GBL_RLENGTH,
|
GBL_RLENGTH = QSE_AWK_GBL_RLENGTH, /**< RLENGTH */
|
||||||
GBL_RS = QSE_AWK_GBL_RS,
|
GBL_RS = QSE_AWK_GBL_RS, /**< RS */
|
||||||
GBL_RSTART = QSE_AWK_GBL_RSTART,
|
GBL_RSTART = QSE_AWK_GBL_RSTART, /**< RSTART */
|
||||||
GBL_SUBSEP = QSE_AWK_GBL_SUBSEP
|
GBL_SUBSEP = QSE_AWK_GBL_SUBSEP /**< SUBSEP */
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Represents the execution context */
|
/** Represents the execution context */
|
||||||
@ -699,94 +706,39 @@ public:
|
|||||||
ErrorNumber code, size_t line, const char_t* msg);
|
ErrorNumber code, size_t line, const char_t* msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value of a global variable. The global variable
|
* Sets the value of a global variable identified by @a id
|
||||||
* is indicated by the first parameter.
|
* to @a v.
|
||||||
*
|
* @return 0 on success, -1 on failure
|
||||||
* @param id
|
|
||||||
* The ID to a global variable. This value corresponds
|
|
||||||
* to the predefined global variable IDs or the value
|
|
||||||
* returned by Awk::addGlobal.
|
|
||||||
* @param v
|
|
||||||
* The value to assign to the global variable.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* On success, 0 is returned.
|
|
||||||
* On failure, -1 is returned.
|
|
||||||
*/
|
*/
|
||||||
int setGlobal (int id, long_t v);
|
int setGlobal (int id, long_t v);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value of a global variable. The global variable
|
* Sets the value of a global variable identified by @a id
|
||||||
* is indicated by the first parameter.
|
* to @a v.
|
||||||
*
|
* @return 0 on success, -1 on failure
|
||||||
* @param id
|
|
||||||
* The ID to a global variable. This value corresponds
|
|
||||||
* to the predefined global variable IDs or the value
|
|
||||||
* returned by Awk::addGlobal.
|
|
||||||
* @param v
|
|
||||||
* The value to assign to the global variable.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* On success, 0 is returned.
|
|
||||||
* On failure, -1 is returned.
|
|
||||||
*/
|
*/
|
||||||
int setGlobal (int id, real_t v);
|
int setGlobal (int id, real_t v);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value of a global variable. The global variable
|
* Sets the value of a global variable identified by @a id
|
||||||
* is indicated by the first parameter.
|
* to a string as long as @a len characters pointed to by
|
||||||
*
|
* @a ptr.
|
||||||
* @param id
|
* @return 0 on success, -1 on failure
|
||||||
* The ID to a global variable. This value corresponds
|
|
||||||
* to the predefined global variable IDs or the value
|
|
||||||
* returned by Awk::addGlobal.
|
|
||||||
* @param ptr The pointer to a character array
|
|
||||||
* @param len The number of characters in the array
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* On success, 0 is returned.
|
|
||||||
* On failure, -1 is returned.
|
|
||||||
*/
|
*/
|
||||||
int setGlobal (int id, const char_t* ptr, size_t len);
|
int setGlobal (int id, const char_t* ptr, size_t len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a global variable identified by @a id to a value @a v.
|
||||||
|
* @return 0 on success, -1 on failure
|
||||||
|
*/
|
||||||
|
int setGlobal (int id, const Value& v);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value of a global variable. The global variable
|
* Gets the value of a global variable identified by @a id
|
||||||
* is indicated by the first parameter.
|
* and store it in @a v.
|
||||||
*
|
* @return 0 on success, -1 on failure
|
||||||
* @param id
|
|
||||||
* The ID to a global variable. This value corresponds
|
|
||||||
* to the predefined global variable IDs or the value
|
|
||||||
* returned by Awk::addGlobal.
|
|
||||||
* @param global
|
|
||||||
* The reference to the value holder
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* On success, 0 is returned.
|
|
||||||
* On failure, -1 is returned.
|
|
||||||
*/
|
*/
|
||||||
int setGlobal (int id, const Value& global);
|
int getGlobal (int id, Value& v) const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of a global variable.
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* The ID to a global variable. This value corresponds
|
|
||||||
* to the predefined global variable IDs or the value
|
|
||||||
* returned by Awk::addGlobal.
|
|
||||||
* @param global
|
|
||||||
* The reference to the value holder of a global variable
|
|
||||||
* indicated by id. The parameter is set if this method
|
|
||||||
* returns 0.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* On success, 0 is returned.
|
|
||||||
* On failure, -1 is returned.
|
|
||||||
*/
|
|
||||||
int getGlobal (int id, Value& global) const;
|
|
||||||
|
|
||||||
void* alloc (size_t size);
|
|
||||||
void free (void* ptr);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Awk* awk;
|
Awk* awk;
|
||||||
@ -939,6 +891,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a intrinsic global variable.
|
* Adds a intrinsic global variable.
|
||||||
|
* @return integer >= 0 on success, -1 on failure.
|
||||||
*/
|
*/
|
||||||
virtual int addGlobal (const char_t* name);
|
virtual int addGlobal (const char_t* name);
|
||||||
|
|
||||||
@ -947,6 +900,23 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual int deleteGlobal (const char_t* name);
|
virtual int deleteGlobal (const char_t* 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.
|
||||||
|
* @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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a user-defined intrinsic function.
|
* Represents a user-defined intrinsic function.
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h 230 2009-07-13 08:51:23Z hyunghwan.chung $
|
* $Id: awk.h 232 2009-07-14 08:06:14Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -291,7 +291,7 @@ enum qse_awk_rio_cmd_t
|
|||||||
QSE_AWK_RIO_WRITE = 3, /**< write a stream */
|
QSE_AWK_RIO_WRITE = 3, /**< write a stream */
|
||||||
QSE_AWK_RIO_FLUSH = 4, /**< write buffered data to a stream */
|
QSE_AWK_RIO_FLUSH = 4, /**< write buffered data to a stream */
|
||||||
QSE_AWK_RIO_NEXT = 5 /**< close the current stream and
|
QSE_AWK_RIO_NEXT = 5 /**< close the current stream and
|
||||||
open the next stream. only for console */
|
open the next stream (only for console) */
|
||||||
};
|
};
|
||||||
typedef enum qse_awk_rio_cmd_t qse_awk_rio_cmd_t;
|
typedef enum qse_awk_rio_cmd_t qse_awk_rio_cmd_t;
|
||||||
|
|
||||||
@ -682,6 +682,7 @@ enum qse_awk_errnum_t
|
|||||||
QSE_AWK_ENEXTFEND, /**< 'nextfile' illegal in END block */
|
QSE_AWK_ENEXTFEND, /**< 'nextfile' illegal in END block */
|
||||||
QSE_AWK_EPRINTFARG,/**< 'printf' not followed by argument */
|
QSE_AWK_EPRINTFARG,/**< 'printf' not followed by argument */
|
||||||
QSE_AWK_EPREPST, /**< both prefix and postfix incr/decr operator present */
|
QSE_AWK_EPREPST, /**< both prefix and postfix incr/decr operator present */
|
||||||
|
QSE_AWK_EINCDECOPR,/**< illegal operand for incr/decr operator */
|
||||||
|
|
||||||
/* run time error */
|
/* run time error */
|
||||||
QSE_AWK_EDIVBY0, /**< divide by zero */
|
QSE_AWK_EDIVBY0, /**< divide by zero */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: std.h 212 2009-06-25 07:39:27Z hyunghwan.chung $
|
* $Id: std.h 232 2009-07-14 08:06:14Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -32,7 +32,6 @@
|
|||||||
*
|
*
|
||||||
* @todo
|
* @todo
|
||||||
* - add code to treat a function as a value
|
* - add code to treat a function as a value
|
||||||
* - StdAwk ARGV and console name handling
|
|
||||||
* - add RQ and LQ for more powerful record splitting
|
* - add RQ and LQ for more powerful record splitting
|
||||||
* - improve performance in qse_awk_rtx_readio() if RS is logner than 2 chars.
|
* - improve performance in qse_awk_rtx_readio() if RS is logner than 2 chars.
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.cpp 231 2009-07-13 10:03:53Z hyunghwan.chung $
|
* $Id: Awk.cpp 232 2009-07-14 08:06:14Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -1000,7 +1000,6 @@ int Awk::Run::setGlobal (int id, const char_t* ptr, size_t len)
|
|||||||
int Awk::Run::setGlobal (int id, const Value& gbl)
|
int Awk::Run::setGlobal (int id, const Value& gbl)
|
||||||
{
|
{
|
||||||
QSE_ASSERT (this->rtx != QSE_NULL);
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
||||||
|
|
||||||
return qse_awk_rtx_setgbl (this->rtx, id, (val_t*)gbl);
|
return qse_awk_rtx_setgbl (this->rtx, id, (val_t*)gbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1531,7 +1530,7 @@ int Awk::addGlobal (const char_t* name)
|
|||||||
QSE_ASSERT (awk != QSE_NULL);
|
QSE_ASSERT (awk != QSE_NULL);
|
||||||
|
|
||||||
int n = qse_awk_addgbl (awk, name, qse_strlen(name));
|
int n = qse_awk_addgbl (awk, name, qse_strlen(name));
|
||||||
if (n == -1) retrieveError ();
|
if (n <= -1) retrieveError ();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1539,7 +1538,33 @@ int Awk::deleteGlobal (const char_t* name)
|
|||||||
{
|
{
|
||||||
QSE_ASSERT (awk != QSE_NULL);
|
QSE_ASSERT (awk != QSE_NULL);
|
||||||
int n = qse_awk_delgbl (awk, name, qse_strlen(name));
|
int n = qse_awk_delgbl (awk, name, qse_strlen(name));
|
||||||
if (n == -1) retrieveError ();
|
if (n <= -1) retrieveError ();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Awk::setGlobal (int id, const Value& v)
|
||||||
|
{
|
||||||
|
QSE_ASSERT (awk != QSE_NULL);
|
||||||
|
QSE_ASSERT (runctx.rtx != QSE_NULL);
|
||||||
|
|
||||||
|
if (v.run != &runctx)
|
||||||
|
{
|
||||||
|
setError (ERR_INVAL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int n = runctx.setGlobal (id, v);
|
||||||
|
if (n <= -1) retrieveError ();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Awk::getGlobal (int id, Value& v)
|
||||||
|
{
|
||||||
|
QSE_ASSERT (awk != QSE_NULL);
|
||||||
|
QSE_ASSERT (runctx.rtx != QSE_NULL);
|
||||||
|
|
||||||
|
int n = runctx.getGlobal (id, v);
|
||||||
|
if (n <= -1) retrieveError ();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.c 212 2009-06-25 07:39:27Z hyunghwan.chung $
|
* $Id: awk.c 232 2009-07-14 08:06:14Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -54,6 +54,27 @@ static void free_fnc (qse_map_t* map, void* vptr, qse_size_t vlen)
|
|||||||
QSE_AWK_FREE (awk, f);
|
QSE_AWK_FREE (awk, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int init_token (qse_mmgr_t* mmgr, qse_awk_token_t* token)
|
||||||
|
{
|
||||||
|
token->name = qse_str_open (mmgr, 0, 128);
|
||||||
|
if (token->name == QSE_NULL) return -1;
|
||||||
|
|
||||||
|
token->type = 0;
|
||||||
|
token->line = 0;
|
||||||
|
token->column = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fini_token (qse_awk_token_t* token)
|
||||||
|
{
|
||||||
|
if (token->name != QSE_NULL)
|
||||||
|
{
|
||||||
|
qse_str_close (token->name);
|
||||||
|
token->name = QSE_NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
|
qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
|
||||||
{
|
{
|
||||||
qse_awk_t* awk;
|
qse_awk_t* awk;
|
||||||
@ -91,8 +112,8 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
|
|||||||
}
|
}
|
||||||
awk->prm = *prm;
|
awk->prm = *prm;
|
||||||
|
|
||||||
awk->token.name = qse_str_open (mmgr, 0, 128);
|
if (init_token (mmgr, &awk->token) == -1) goto oops;
|
||||||
if (awk->token.name == QSE_NULL) goto oops;
|
if (init_token (mmgr, &awk->atoken) == -1) goto oops;
|
||||||
|
|
||||||
awk->wtab = qse_map_open (mmgr, QSE_SIZEOF(awk), 512, 70);
|
awk->wtab = qse_map_open (mmgr, QSE_SIZEOF(awk), 512, 70);
|
||||||
if (awk->wtab == QSE_NULL) goto oops;
|
if (awk->wtab == QSE_NULL) goto oops;
|
||||||
@ -170,12 +191,9 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
|
|||||||
awk->tree.chain_tail = QSE_NULL;
|
awk->tree.chain_tail = QSE_NULL;
|
||||||
awk->tree.chain_size = 0;
|
awk->tree.chain_size = 0;
|
||||||
|
|
||||||
awk->token.prev.type = 0;
|
awk->ptoken.type = 0;
|
||||||
awk->token.prev.line = 0;
|
awk->ptoken.line = 0;
|
||||||
awk->token.prev.column = 0;
|
awk->ptoken.column = 0;
|
||||||
awk->token.type = 0;
|
|
||||||
awk->token.line = 0;
|
|
||||||
awk->token.column = 0;
|
|
||||||
|
|
||||||
awk->src.lex.curc = QSE_CHAR_EOF;
|
awk->src.lex.curc = QSE_CHAR_EOF;
|
||||||
awk->src.lex.ungotc_count = 0;
|
awk->src.lex.ungotc_count = 0;
|
||||||
@ -218,7 +236,8 @@ oops:
|
|||||||
if (awk->tree.funs) qse_map_close (awk->tree.funs);
|
if (awk->tree.funs) qse_map_close (awk->tree.funs);
|
||||||
if (awk->rwtab) qse_map_close (awk->rwtab);
|
if (awk->rwtab) qse_map_close (awk->rwtab);
|
||||||
if (awk->wtab) qse_map_close (awk->wtab);
|
if (awk->wtab) qse_map_close (awk->wtab);
|
||||||
if (awk->token.name) qse_str_close (awk->token.name);
|
fini_token (&awk->atoken);
|
||||||
|
fini_token (&awk->token);
|
||||||
QSE_AWK_FREE (awk, awk);
|
QSE_AWK_FREE (awk, awk);
|
||||||
|
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
@ -240,7 +259,8 @@ int qse_awk_close (qse_awk_t* awk)
|
|||||||
qse_map_close (awk->rwtab);
|
qse_map_close (awk->rwtab);
|
||||||
qse_map_close (awk->wtab);
|
qse_map_close (awk->wtab);
|
||||||
|
|
||||||
qse_str_close (awk->token.name);
|
fini_token (&awk->atoken);
|
||||||
|
fini_token (&awk->token);
|
||||||
|
|
||||||
/* QSE_AWK_ALLOC, QSE_AWK_FREE, etc can not be used
|
/* QSE_AWK_ALLOC, QSE_AWK_FREE, etc can not be used
|
||||||
* from the next line onwards */
|
* from the next line onwards */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h 212 2009-06-25 07:39:27Z hyunghwan.chung $
|
* $Id: awk.h 232 2009-07-14 08:06:14Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -96,6 +96,15 @@ struct qse_awk_tree_t
|
|||||||
int ok;
|
int ok;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct qse_awk_token_t qse_awk_token_t;
|
||||||
|
struct qse_awk_token_t
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
qse_str_t* name;
|
||||||
|
qse_size_t line;
|
||||||
|
qse_size_t column;
|
||||||
|
};
|
||||||
|
|
||||||
struct qse_awk_t
|
struct qse_awk_t
|
||||||
{
|
{
|
||||||
QSE_DEFINE_COMMON_FIELDS (sed)
|
QSE_DEFINE_COMMON_FIELDS (sed)
|
||||||
@ -188,21 +197,17 @@ struct qse_awk_t
|
|||||||
} shared;
|
} shared;
|
||||||
} src;
|
} src;
|
||||||
|
|
||||||
/* token */
|
/* previous token info excluding name */
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
struct
|
int type;
|
||||||
{
|
|
||||||
int type;
|
|
||||||
qse_size_t line;
|
|
||||||
qse_size_t column;
|
|
||||||
} prev;
|
|
||||||
|
|
||||||
int type;
|
|
||||||
qse_str_t* name;
|
|
||||||
qse_size_t line;
|
qse_size_t line;
|
||||||
qse_size_t column;
|
qse_size_t column;
|
||||||
} token;
|
} ptoken;
|
||||||
|
|
||||||
|
/* current token */
|
||||||
|
qse_awk_token_t token;
|
||||||
|
qse_awk_token_t atoken;
|
||||||
|
|
||||||
/* intrinsic functions */
|
/* intrinsic functions */
|
||||||
struct
|
struct
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: err.c 220 2009-07-01 13:14:39Z hyunghwan.chung $
|
* $Id: err.c 232 2009-07-14 08:06:14Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -107,6 +107,7 @@ const qse_char_t* qse_awk_dflerrstr (qse_awk_t* awk, qse_awk_errnum_t errnum)
|
|||||||
QSE_T("'nextfile' illegal in the END block"),
|
QSE_T("'nextfile' illegal in the END block"),
|
||||||
QSE_T("'printf' not followed by argument"),
|
QSE_T("'printf' not followed by argument"),
|
||||||
QSE_T("both prefix and postfix increment/decrement operator present"),
|
QSE_T("both prefix and postfix increment/decrement operator present"),
|
||||||
|
QSE_T("illegal operand for increment/decrement operator"),
|
||||||
|
|
||||||
QSE_T("divide by zero"),
|
QSE_T("divide by zero"),
|
||||||
QSE_T("invalid operand"),
|
QSE_T("invalid operand"),
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: run.c 230 2009-07-13 08:51:23Z hyunghwan.chung $
|
* $Id: run.c 232 2009-07-14 08:06:14Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -4021,7 +4021,8 @@ static int __cmp_int_str (
|
|||||||
qse_awk_rtx_valtostr_out_t out;
|
qse_awk_rtx_valtostr_out_t out;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (rtx->awk->option & QSE_AWK_NCMPONSTR || right->nstr > 0)
|
/* SCO CC doesn't seem to handle right->nstr > 0 properly */
|
||||||
|
if (rtx->awk->option & QSE_AWK_NCMPONSTR || right->nstr /*> 0*/)
|
||||||
{
|
{
|
||||||
qse_long_t ll;
|
qse_long_t ll;
|
||||||
qse_real_t rr;
|
qse_real_t rr;
|
||||||
@ -4107,7 +4108,8 @@ static int __cmp_real_str (
|
|||||||
qse_awk_rtx_valtostr_out_t out;
|
qse_awk_rtx_valtostr_out_t out;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (rtx->awk->option & QSE_AWK_NCMPONSTR || right->nstr > 0)
|
/* SCO CC doesn't seem to handle right->nstr > 0 properly */
|
||||||
|
if (rtx->awk->option & QSE_AWK_NCMPONSTR || right->nstr /*> 0*/)
|
||||||
{
|
{
|
||||||
const qse_char_t* end;
|
const qse_char_t* end;
|
||||||
qse_real_t rr;
|
qse_real_t rr;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: tree.c 210 2009-06-24 08:29:33Z hyunghwan.chung $
|
* $Id: tree.c 232 2009-07-14 08:06:14Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -552,6 +552,9 @@ static int print_expression (qse_awk_t* awk, qse_awk_nde_t* nde)
|
|||||||
case QSE_AWK_NDE_GETLINE:
|
case QSE_AWK_NDE_GETLINE:
|
||||||
{
|
{
|
||||||
qse_awk_nde_getline_t* px = (qse_awk_nde_getline_t*)nde;
|
qse_awk_nde_getline_t* px = (qse_awk_nde_getline_t*)nde;
|
||||||
|
|
||||||
|
PUT_SRCSTR (awk, QSE_T("("));
|
||||||
|
|
||||||
if (px->in != QSE_NULL &&
|
if (px->in != QSE_NULL &&
|
||||||
(px->in_type == QSE_AWK_IN_PIPE ||
|
(px->in_type == QSE_AWK_IN_PIPE ||
|
||||||
px->in_type == QSE_AWK_IN_RWPIPE))
|
px->in_type == QSE_AWK_IN_RWPIPE))
|
||||||
@ -578,6 +581,8 @@ static int print_expression (qse_awk_t* awk, qse_awk_nde_t* nde)
|
|||||||
PUT_SRCSTR (awk, QSE_T(" "));
|
PUT_SRCSTR (awk, QSE_T(" "));
|
||||||
PRINT_EXPRESSION (awk, px->in);
|
PRINT_EXPRESSION (awk, px->in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PUT_SRCSTR (awk, QSE_T(")"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
qse/regress/awk/lang-032.awk
Normal file
14
qse/regress/awk/lang-032.awk
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
BEGIN {
|
||||||
|
a=91
|
||||||
|
print a ++10; # print 9110
|
||||||
|
print a ++10; # print 9210
|
||||||
|
print (a) ++10; # print 9310
|
||||||
|
print ((a)) ++10; # print 9410
|
||||||
|
print ((a)++) 10; # print 9510
|
||||||
|
|
||||||
|
print "---------------------"
|
||||||
|
a=91
|
||||||
|
print (++(a)) 10; # print 9210
|
||||||
|
}
|
||||||
|
|
||||||
|
|
4
qse/regress/awk/lang-033.awk
Normal file
4
qse/regress/awk/lang-033.awk
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
BEGIN {
|
||||||
|
while ("cat lang-033.awk" | getline x > 0)
|
||||||
|
print x
|
||||||
|
}
|
@ -1352,7 +1352,7 @@ BEGIN {
|
|||||||
printf ("%s\n",10.34);
|
printf ("%s\n",10.34);
|
||||||
}
|
}
|
||||||
|
|
||||||
ERROR: CODE [110] LINE [3] recursion detected in format conversion
|
ERROR: CODE [111] LINE [3] recursion detected in format conversion
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
../../cmd/awk/qseawk --newline=on -o- -f lang-014.awk </dev/stdin 2>&1
|
../../cmd/awk/qseawk --newline=on -o- -f lang-014.awk </dev/stdin 2>&1
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@ -1520,7 +1520,7 @@ BEGIN {
|
|||||||
delete iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix;
|
delete iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix;
|
||||||
}
|
}
|
||||||
|
|
||||||
ERROR: CODE [84] LINE [3] variable 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix' not deletable
|
ERROR: CODE [85] LINE [3] variable 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix' not deletable
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
../../cmd/awk/qseawk --newline=on -o- -f lang-026.awk </dev/stdin 2>&1
|
../../cmd/awk/qseawk --newline=on -o- -f lang-026.awk </dev/stdin 2>&1
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@ -1532,7 +1532,7 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abc
|
abc
|
||||||
ERROR: CODE [92] LINE [4] map 'abc' not assignable with a scalar
|
ERROR: CODE [93] LINE [4] map 'abc' not assignable with a scalar
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
../../cmd/awk/qseawk --newline=on -o- -f lang-027.awk </dev/stdin 2>&1
|
../../cmd/awk/qseawk --newline=on -o- -f lang-027.awk </dev/stdin 2>&1
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@ -1632,6 +1632,40 @@ BEGIN {
|
|||||||
0 -1
|
0 -1
|
||||||
--------------------------
|
--------------------------
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
../../cmd/awk/qseawk --newline=on -o- -f lang-032.awk </dev/stdin 2>&1
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
BEGIN {
|
||||||
|
a = 91;
|
||||||
|
print ((a)++ 10);
|
||||||
|
print ((a)++ 10);
|
||||||
|
print ((a)++ 10);
|
||||||
|
print ((a)++ 10);
|
||||||
|
print ((a)++ 10);
|
||||||
|
print "---------------------";
|
||||||
|
a = 91;
|
||||||
|
print (++(a) 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
9110
|
||||||
|
9210
|
||||||
|
9310
|
||||||
|
9410
|
||||||
|
9510
|
||||||
|
---------------------
|
||||||
|
9210
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
../../cmd/awk/qseawk --newline=on -o- -f lang-033.awk </dev/stdin 2>&1
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
BEGIN {
|
||||||
|
while ((("cat lang-033.awk" | getline x) > 0))
|
||||||
|
print x;
|
||||||
|
}
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
while ("cat lang-033.awk" | getline x > 0)
|
||||||
|
print x
|
||||||
|
}
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
../../cmd/awk/qseawk -f quicksort.awk quicksort.dat </dev/stdin 2>&1
|
../../cmd/awk/qseawk -f quicksort.awk quicksort.dat </dev/stdin 2>&1
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
0.0000000000
|
0.0000000000
|
||||||
|
@ -134,6 +134,8 @@ PROGS="
|
|||||||
lang-029.awk///--explicit=on --newline=on -o-
|
lang-029.awk///--explicit=on --newline=on -o-
|
||||||
lang-030.awk///--newline=on -o-
|
lang-030.awk///--newline=on -o-
|
||||||
lang-031.awk///--newline=on -o-
|
lang-031.awk///--newline=on -o-
|
||||||
|
lang-032.awk///--newline=on -o-
|
||||||
|
lang-033.awk///--newline=on -o-
|
||||||
|
|
||||||
quicksort.awk/quicksort.dat//
|
quicksort.awk/quicksort.dat//
|
||||||
quicksort2.awk/quicksort2.dat//
|
quicksort2.awk/quicksort2.dat//
|
||||||
|
@ -37,7 +37,7 @@ static int run_awk (QSE::StdAwk& awk)
|
|||||||
"function pa (x) {\n"
|
"function pa (x) {\n"
|
||||||
" reset ret;\n"
|
" reset ret;\n"
|
||||||
" for (i in x) { print i, \"=>\", x[i]; ret += x[i]; }\n"
|
" for (i in x) { print i, \"=>\", x[i]; ret += x[i]; }\n"
|
||||||
" return ret;\n"
|
" return ret + DAMN++;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"function pb (x) {\n"
|
"function pb (x) {\n"
|
||||||
" reset ret;\n"
|
" reset ret;\n"
|
||||||
@ -46,6 +46,10 @@ static int run_awk (QSE::StdAwk& awk)
|
|||||||
"}"
|
"}"
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// add a global variable 'DAMN'
|
||||||
|
int damn = awk.addGlobal (QSE_T("DAMN"));
|
||||||
|
if (damn <= -1) return -1;
|
||||||
|
|
||||||
// parse the script and perform no deparsing
|
// parse the script and perform no deparsing
|
||||||
run = awk.parse (in, QSE::StdAwk::Source::NONE);
|
run = awk.parse (in, QSE::StdAwk::Source::NONE);
|
||||||
if (run == QSE_NULL) return -1;
|
if (run == QSE_NULL) return -1;
|
||||||
@ -59,6 +63,11 @@ static int run_awk (QSE::StdAwk& awk)
|
|||||||
run, QSE::StdAwk::Value::IntIndex(i), i*20) <= -1) return -1;
|
run, QSE::StdAwk::Value::IntIndex(i), i*20) <= -1) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set 'DAMN' to 100000
|
||||||
|
QSE::StdAwk::Value damnv (run);
|
||||||
|
if (damnv.setInt (100000) <= -1) return -1;
|
||||||
|
if (awk.setGlobal (damn, damnv) <= -1) return -1;
|
||||||
|
|
||||||
QSE::StdAwk::Value r;
|
QSE::StdAwk::Value r;
|
||||||
|
|
||||||
// call the 'pa' function
|
// call the 'pa' function
|
||||||
@ -69,6 +78,12 @@ static int run_awk (QSE::StdAwk& awk)
|
|||||||
qse_printf (QSE_T(" (real) [%Lf]\n"), (long double)r.toReal());
|
qse_printf (QSE_T(" (real) [%Lf]\n"), (long double)r.toReal());
|
||||||
qse_printf (QSE_T(" (str) [%s]\n"), r.toStr(QSE_NULL));
|
qse_printf (QSE_T(" (str) [%s]\n"), r.toStr(QSE_NULL));
|
||||||
|
|
||||||
|
// get the value of 'DAMN'
|
||||||
|
if (awk.getGlobal (damn, damnv) <= -1) return -1;
|
||||||
|
qse_printf (QSE_T("DAMN: (int) [%lld]\n"), (long long)damnv.toInt());
|
||||||
|
qse_printf (QSE_T(" (real) [%Lf]\n"), (long double)damnv.toReal());
|
||||||
|
qse_printf (QSE_T(" (str) [%s]\n"), damnv.toStr(QSE_NULL));
|
||||||
|
|
||||||
// call the 'pb' function
|
// call the 'pb' function
|
||||||
if (awk.call (QSE_T("pb"), &r, arg, QSE_COUNTOF(arg)) <= -1) return -1;
|
if (awk.call (QSE_T("pb"), &r, arg, QSE_COUNTOF(arg)) <= -1) return -1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user