Recovered from cvs revision 2007-10-11 13:33:00
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp,v 1.70 2007/10/10 03:37:49 bacon Exp $
|
||||
* $Id: Awk.cpp,v 1.72 2007/10/10 13:22:12 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -911,10 +911,16 @@ Awk::Run::operator Awk::run_t* () const
|
||||
return this->run;
|
||||
}
|
||||
|
||||
int Awk::Run::stop () const
|
||||
void Awk::Run::stop () const
|
||||
{
|
||||
ASE_ASSERT (this->run != ASE_NULL);
|
||||
return ase_awk_stop (this->run);
|
||||
ase_awk_stop (this->run);
|
||||
}
|
||||
|
||||
bool Awk::Run::isStop () const
|
||||
{
|
||||
ASE_ASSERT (this->run != ASE_NULL);
|
||||
return ase_awk_isstop (this->run);
|
||||
}
|
||||
|
||||
Awk::ErrorCode Awk::Run::getErrorCode () const
|
||||
@ -1208,7 +1214,8 @@ int Awk::open ()
|
||||
OPT_SHADING |
|
||||
OPT_EXTIO |
|
||||
OPT_BLOCKLESS |
|
||||
OPT_BASEONE;
|
||||
OPT_BASEONE |
|
||||
OPT_PABLOCK;
|
||||
ase_awk_setoption (awk, opt);
|
||||
|
||||
runCallback = false;
|
||||
@ -1384,6 +1391,12 @@ int Awk::run (const char_t* main, const char_t** args, size_t nargs)
|
||||
return n;
|
||||
}
|
||||
|
||||
void Awk::stop ()
|
||||
{
|
||||
ASE_ASSERT (awk != ASE_NULL);
|
||||
ase_awk_stopall (awk);
|
||||
}
|
||||
|
||||
int Awk::dispatchFunction (Run* run, const char_t* name, size_t len)
|
||||
{
|
||||
pair_t* pair;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp,v 1.71 2007/10/10 03:37:49 bacon Exp $
|
||||
* $Id: Awk.hpp,v 1.73 2007/10/10 13:22:12 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -441,6 +441,7 @@ public:
|
||||
ERR_IN = ASE_AWK_EIN,
|
||||
ERR_NOTVAR = ASE_AWK_ENOTVAR,
|
||||
ERR_EXPRES = ASE_AWK_EEXPRES,
|
||||
ERR_FUNC = ASE_AWK_EFUNC,
|
||||
ERR_WHILE = ASE_AWK_EWHILE,
|
||||
ERR_ASSIGN = ASE_AWK_EASSIGN,
|
||||
ERR_IDENT = ASE_AWK_EIDENT,
|
||||
@ -552,7 +553,9 @@ public:
|
||||
/** Enables the keyword 'reset' */
|
||||
OPT_RESET = ASE_AWK_RESET,
|
||||
/** Allows the assignment of a map value to a variable */
|
||||
OPT_MAPTOVAR = ASE_AWK_MAPTOVAR
|
||||
OPT_MAPTOVAR = ASE_AWK_MAPTOVAR,
|
||||
/** Allows BEGIN, END, pattern-action blocks */
|
||||
OPT_PABLOCK = ASE_AWK_PABLOCK
|
||||
};
|
||||
// end of enum Option
|
||||
|
||||
@ -572,7 +575,8 @@ public:
|
||||
operator Awk* () const;
|
||||
operator run_t* () const;
|
||||
|
||||
int stop () const;
|
||||
void stop () const;
|
||||
bool isStop () const;
|
||||
|
||||
ErrorCode getErrorCode () const;
|
||||
size_t getErrorLine () const;
|
||||
@ -817,6 +821,11 @@ public:
|
||||
virtual int run (const char_t* main = ASE_NULL,
|
||||
const char_t** args = ASE_NULL, size_t nargs = 0);
|
||||
|
||||
/**
|
||||
* Requests aborting execution of the parse tree
|
||||
*/
|
||||
virtual void stop ();
|
||||
|
||||
/**
|
||||
* Adds a intrinsic global variable.
|
||||
*/
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.java,v 1.15 2007/09/27 11:04:10 bacon Exp $
|
||||
* $Id: Awk.java,v 1.16 2007/10/10 07:03:56 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -40,6 +40,7 @@ public abstract class Awk
|
||||
public static final int OPTION_ARGSTOMAIN = (1 << 14);
|
||||
public static final int OPTION_RESET = (1 << 15);
|
||||
public static final int OPTION_MAPTOVAR = (1 << 16);
|
||||
public static final int OPTION_PABLOCK = (1 << 17);
|
||||
|
||||
protected final static Reader stdin =
|
||||
new BufferedReader (new InputStreamReader (System.in));
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Exception.java,v 1.5 2007/06/29 11:36:45 bacon Exp $
|
||||
* $Id: Exception.java,v 1.6 2007/10/10 07:03:56 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -60,84 +60,87 @@ public class Exception extends java.lang.Exception
|
||||
public static final int IN = 45;
|
||||
public static final int NOTVAR = 46;
|
||||
public static final int EXPRES = 47;
|
||||
public static final int WHILE = 48;
|
||||
public static final int ASSIGN = 49;
|
||||
public static final int IDENT = 50;
|
||||
public static final int FNNAME = 51;
|
||||
public static final int BLKBEG = 52;
|
||||
public static final int BLKEND = 53;
|
||||
public static final int DUPBEG = 54;
|
||||
public static final int DUPEND = 55;
|
||||
public static final int BFNRED = 56;
|
||||
public static final int AFNRED = 57;
|
||||
public static final int GBLRED = 58;
|
||||
public static final int PARRED = 59;
|
||||
public static final int DUPPAR = 60;
|
||||
public static final int DUPGBL = 61;
|
||||
public static final int DUPLCL = 62;
|
||||
public static final int BADPAR = 63;
|
||||
public static final int BADVAR = 64;
|
||||
public static final int UNDEF = 65;
|
||||
public static final int LVALUE = 66;
|
||||
public static final int GBLTM = 67;
|
||||
public static final int LCLTM = 68;
|
||||
public static final int PARTM = 69;
|
||||
public static final int DELETE = 70;
|
||||
public static final int BREAK = 71;
|
||||
public static final int CONTINUE = 72;
|
||||
public static final int NEXTBEG = 73;
|
||||
public static final int NEXTEND = 74;
|
||||
public static final int NEXTFBEG = 75;
|
||||
public static final int NEXTFEND = 76;
|
||||
public static final int PRINTFARG = 77;
|
||||
public static final int PREPST = 78;
|
||||
public static final int GLNCPS = 79;
|
||||
public static final int DIVBY0 = 80;
|
||||
public static final int OPERAND = 81;
|
||||
public static final int POSIDX = 82;
|
||||
public static final int ARGTF = 83;
|
||||
public static final int ARGTM = 84;
|
||||
public static final int FNNONE = 85;
|
||||
public static final int NOTIDX = 86;
|
||||
public static final int NOTDEL = 87;
|
||||
public static final int NOTMAP = 88;
|
||||
public static final int NOTMAPIN = 89;
|
||||
public static final int NOTMAPNILIN = 90;
|
||||
public static final int NOTREF = 91;
|
||||
public static final int NOTASS = 92;
|
||||
public static final int IDXVALASSMAP = 93;
|
||||
public static final int POSVALASSMAP = 94;
|
||||
public static final int MAPTOSCALAR = 95;
|
||||
public static final int SCALARTOMAP = 96;
|
||||
public static final int MAPNOTALLOWED = 97;
|
||||
public static final int VALTYPE = 98;
|
||||
public static final int RDELETE = 99;
|
||||
public static final int RNEXTBEG = 100;
|
||||
public static final int RNEXTEND = 101;
|
||||
public static final int RNEXTFBEG = 102;
|
||||
public static final int RNEXTFEND = 103;
|
||||
public static final int BFNUSER = 104;
|
||||
public static final int BFNIMPL = 105;
|
||||
public static final int IOUSER = 106;
|
||||
public static final int IONONE = 107;
|
||||
public static final int IOIMPL = 108;
|
||||
public static final int IONMEM = 109;
|
||||
public static final int IONMNL = 110;
|
||||
public static final int FMTARG = 111;
|
||||
public static final int FMTCNV = 112;
|
||||
public static final int CONVFMTCHR = 113;
|
||||
public static final int OFMTCHR = 114;
|
||||
public static final int REXRECUR = 115;
|
||||
public static final int REXRPAREN = 116;
|
||||
public static final int REXRBRACKET = 117;
|
||||
public static final int REXRBRACE = 118;
|
||||
public static final int REXUNBALPAR = 119;
|
||||
public static final int REXCOLON = 120;
|
||||
public static final int REXCRANGE = 121;
|
||||
public static final int REXCCLASS = 122;
|
||||
public static final int REXBRANGE = 123;
|
||||
public static final int REXEND = 124;
|
||||
public static final int REXGARBAGE = 125;
|
||||
public static final int FUNC = 48;
|
||||
public static final int WHILE = 49;
|
||||
public static final int ASSIGN = 50;
|
||||
public static final int IDENT = 51;
|
||||
public static final int FNNAME = 52;
|
||||
public static final int BLKBEG = 53;
|
||||
public static final int BLKEND = 54;
|
||||
public static final int DUPBEG = 55;
|
||||
public static final int DUPEND = 56;
|
||||
public static final int BFNRED = 57;
|
||||
public static final int AFNRED = 58;
|
||||
public static final int GBLRED = 59;
|
||||
public static final int PARRED = 60;
|
||||
public static final int DUPPAR = 61;
|
||||
public static final int DUPGBL = 62;
|
||||
public static final int DUPLCL = 63;
|
||||
public static final int BADPAR = 64;
|
||||
public static final int BADVAR = 65;
|
||||
public static final int UNDEF = 66;
|
||||
public static final int LVALUE = 67;
|
||||
public static final int GBLTM = 68;
|
||||
public static final int LCLTM = 69;
|
||||
public static final int PARTM = 70;
|
||||
public static final int DELETE = 71;
|
||||
public static final int RESET = 72;
|
||||
public static final int BREAK = 73;
|
||||
public static final int CONTINUE = 74;
|
||||
public static final int NEXTBEG = 75;
|
||||
public static final int NEXTEND = 76;
|
||||
public static final int NEXTFBEG = 77;
|
||||
public static final int NEXTFEND = 78;
|
||||
public static final int PRINTFARG = 79;
|
||||
public static final int PREPST = 80;
|
||||
public static final int GLNCPS = 81;
|
||||
public static final int DIVBY0 = 82;
|
||||
public static final int OPERAND = 83;
|
||||
public static final int POSIDX = 84;
|
||||
public static final int ARGTF = 85;
|
||||
public static final int ARGTM = 86;
|
||||
public static final int FNNONE = 87;
|
||||
public static final int NOTIDX = 88;
|
||||
public static final int NOTDEL = 89;
|
||||
public static final int NOTMAP = 90;
|
||||
public static final int NOTMAPIN = 91;
|
||||
public static final int NOTMAPNILIN = 92;
|
||||
public static final int NOTREF = 93;
|
||||
public static final int NOTASS = 94;
|
||||
public static final int IDXVALASSMAP = 95;
|
||||
public static final int POSVALASSMAP = 96;
|
||||
public static final int MAPTOSCALAR = 97;
|
||||
public static final int SCALARTOMAP = 98;
|
||||
public static final int MAPNOTALLOWED = 99;
|
||||
public static final int VALTYPE = 100;
|
||||
public static final int RDELETE = 101;
|
||||
public static final int RRESET = 102;
|
||||
public static final int RNEXTBEG = 103;
|
||||
public static final int RNEXTEND = 104;
|
||||
public static final int RNEXTFBEG = 105;
|
||||
public static final int RNEXTFEND = 106;
|
||||
public static final int BFNUSER = 107;
|
||||
public static final int BFNIMPL = 108;
|
||||
public static final int IOUSER = 109;
|
||||
public static final int IONONE = 110;
|
||||
public static final int IOIMPL = 111;
|
||||
public static final int IONMEM = 112;
|
||||
public static final int IONMNL = 113;
|
||||
public static final int FMTARG = 114;
|
||||
public static final int FMTCNV = 115;
|
||||
public static final int CONVFMTCHR = 116;
|
||||
public static final int OFMTCHR = 117;
|
||||
public static final int REXRECUR = 118;
|
||||
public static final int REXRPAREN = 119;
|
||||
public static final int REXRBRACKET = 120;
|
||||
public static final int REXRBRACE = 121;
|
||||
public static final int REXUNBALPAR = 122;
|
||||
public static final int REXCOLON = 123;
|
||||
public static final int REXCRANGE = 124;
|
||||
public static final int REXCCLASS = 125;
|
||||
public static final int REXBRANGE = 126;
|
||||
public static final int REXEND = 127;
|
||||
public static final int REXGARBAGE = 128;
|
||||
// end of error codes
|
||||
|
||||
public Exception ()
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c,v 1.10 2007/09/24 08:21:25 bacon Exp $
|
||||
* $Id: awk.c,v 1.11 2007/10/10 13:22:12 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -109,6 +109,7 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
|
||||
awk->option = 0;
|
||||
awk->errnum = ASE_AWK_ENOERR;
|
||||
awk->errlin = 0;
|
||||
awk->stopall = ase_false;
|
||||
|
||||
awk->parse.nlocals_max = 0;
|
||||
|
||||
@ -212,6 +213,8 @@ int ase_awk_close (ase_awk_t* awk)
|
||||
|
||||
int ase_awk_clear (ase_awk_t* awk)
|
||||
{
|
||||
awk->stopall = ase_false;
|
||||
|
||||
ase_memset (&awk->src.ios, 0, ASE_SIZEOF(awk->src.ios));
|
||||
awk->src.lex.curc = ASE_CHAR_EOF;
|
||||
awk->src.lex.ungotc_count = 0;
|
||||
@ -290,3 +293,8 @@ void* ase_awk_getcustomdata (ase_awk_t* awk)
|
||||
{
|
||||
return awk->custom_data;
|
||||
}
|
||||
|
||||
void ase_awk_stopall (ase_awk_t* awk)
|
||||
{
|
||||
awk->stopall = ase_true;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h,v 1.17 2007/10/10 03:37:49 bacon Exp $
|
||||
* $Id: awk.h,v 1.19 2007/10/10 13:22:12 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -264,6 +264,7 @@ enum ase_awk_errnum_t
|
||||
ASE_AWK_ENOTVAR, /* not a variable name after 'in' */
|
||||
ASE_AWK_EEXPRES, /* expression expected */
|
||||
|
||||
ASE_AWK_EFUNC, /* keyword 'func' is expected */
|
||||
ASE_AWK_EWHILE, /* keyword 'while' is expected */
|
||||
ASE_AWK_EASSIGN, /* assignment statement expected */
|
||||
ASE_AWK_EIDENT, /* identifier expected */
|
||||
@ -476,7 +477,11 @@ int ase_awk_run (
|
||||
ase_awk_runios_t* runios, ase_awk_runcbs_t* runcbs,
|
||||
ase_awk_runarg_t* runarg, void* custom_data);
|
||||
|
||||
int ase_awk_stop (ase_awk_run_t* run);
|
||||
void ase_awk_stop (ase_awk_run_t* run);
|
||||
void ase_awk_stopall (ase_awk_t* awk);
|
||||
|
||||
ase_bool_t ase_awk_isstop (ase_awk_run_t* run);
|
||||
|
||||
|
||||
/* functions to access internal stack structure */
|
||||
ase_size_t ase_awk_getnargs (ase_awk_run_t* run);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk_i.h,v 1.7 2007/09/23 16:48:55 bacon Exp $
|
||||
* $Id: awk_i.h,v 1.8 2007/10/10 13:22:12 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -196,8 +196,9 @@ struct ase_awk_t
|
||||
int errnum;
|
||||
ase_size_t errlin;
|
||||
ase_char_t errmsg[256];
|
||||
|
||||
ase_char_t* errstr[ASE_AWK_NUMERRNUM];
|
||||
|
||||
ase_bool_t stopall;
|
||||
};
|
||||
|
||||
struct ase_awk_chain_t
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: err.c,v 1.8 2007/09/25 15:27:54 bacon Exp $
|
||||
* $Id: err.c,v 1.9 2007/10/10 07:03:56 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -66,6 +66,7 @@ static const ase_char_t* __geterrstr (int errnum)
|
||||
ASE_T("right-hand side of the 'in' operator not a variable"),
|
||||
ASE_T("invalid expression"),
|
||||
|
||||
ASE_T("keyword 'func' expected in place of '%.*s'"),
|
||||
ASE_T("keyword 'while' expected in place of '%.*s'"),
|
||||
ASE_T("invalid assignment statement"),
|
||||
ASE_T("an identifier expected in place of '%.*s'"),
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: jni.c,v 1.16 2007/10/10 03:37:49 bacon Exp $
|
||||
* $Id: jni.c,v 1.17 2007/10/10 07:03:56 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -388,17 +388,12 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
|
||||
(*env)->SetLongField (env, obj, handle, (jlong)awk);
|
||||
|
||||
opt = ASE_AWK_IMPLICIT |
|
||||
ASE_AWK_EXPLICIT |
|
||||
ASE_AWK_UNIQUEFN |
|
||||
ASE_AWK_IDIV |
|
||||
ASE_AWK_SHADING |
|
||||
ASE_AWK_SHIFT |
|
||||
ASE_AWK_EXTIO |
|
||||
ASE_AWK_BLOCKLESS |
|
||||
ASE_AWK_BASEONE |
|
||||
ASE_AWK_STRIPSPACES |
|
||||
ASE_AWK_NEXTOFILE |
|
||||
ASE_AWK_ARGSTOMAIN;
|
||||
ASE_AWK_PABLOCK;
|
||||
|
||||
ase_awk_setoption (awk, opt);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.c,v 1.19 2007/10/10 03:37:49 bacon Exp $
|
||||
* $Id: parse.c,v 1.20 2007/10/10 07:03:56 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -590,6 +590,12 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk)
|
||||
}
|
||||
else if (MATCH(awk,TOKEN_BEGIN))
|
||||
{
|
||||
if ((awk->option & ASE_AWK_PABLOCK) == 0)
|
||||
{
|
||||
SETERRTOK (awk, ASE_AWK_EFUNC);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
if (awk->tree.begin != ASE_NULL)
|
||||
{
|
||||
SETERRLIN (awk, ASE_AWK_EDUPBEG, awk->token.prev.line);
|
||||
@ -619,6 +625,12 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk)
|
||||
}
|
||||
else if (MATCH(awk,TOKEN_END))
|
||||
{
|
||||
if ((awk->option & ASE_AWK_PABLOCK) == 0)
|
||||
{
|
||||
SETERRTOK (awk, ASE_AWK_EFUNC);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
if (awk->tree.end != ASE_NULL)
|
||||
{
|
||||
SETERRLIN (awk, ASE_AWK_EDUPEND, awk->token.prev.line);
|
||||
@ -651,7 +663,6 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk)
|
||||
/* patternless block */
|
||||
if ((awk->option & ASE_AWK_PABLOCK) == 0)
|
||||
{
|
||||
/* TODO: SET ERROR */
|
||||
SETERRTOK (awk, ASE_AWK_EFUNC);
|
||||
return ASE_NULL;
|
||||
}
|
||||
@ -675,7 +686,6 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk)
|
||||
|
||||
if ((awk->option & ASE_AWK_PABLOCK) == 0)
|
||||
{
|
||||
/* TODO: SET ERROR */
|
||||
SETERRTOK (awk, ASE_AWK_EFUNC);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c,v 1.16 2007/09/27 11:04:10 bacon Exp $
|
||||
* $Id: run.c,v 1.17 2007/10/10 13:22:12 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -689,10 +689,14 @@ int ase_awk_run (ase_awk_t* awk,
|
||||
return n;
|
||||
}
|
||||
|
||||
int ase_awk_stop (ase_awk_run_t* run)
|
||||
void ase_awk_stop (ase_awk_run_t* run)
|
||||
{
|
||||
run->exit_level = EXIT_ABORT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ase_bool_t ase_awk_isstop (ase_awk_run_t* run)
|
||||
{
|
||||
return (run->exit_level == EXIT_ABORT || run->awk->stopall);
|
||||
}
|
||||
|
||||
static void free_namedval (void* run, void* val)
|
||||
@ -1705,7 +1709,7 @@ static int run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde)
|
||||
ase_dprintf (ASE_T("executing block statements\n"));
|
||||
#endif
|
||||
|
||||
while (p != ASE_NULL && run->exit_level == EXIT_NONE)
|
||||
while (p != ASE_NULL && run->exit_level == EXIT_NONE)
|
||||
{
|
||||
if (run_statement (run, p) == -1)
|
||||
{
|
||||
@ -1731,6 +1735,7 @@ static int run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde)
|
||||
}
|
||||
|
||||
#define ON_STATEMENT(run,nde) \
|
||||
if ((run)->awk->stopall) (run)->exit_level = EXIT_ABORT; \
|
||||
if ((run)->cbs != ASE_NULL && \
|
||||
(run)->cbs->on_statement != ASE_NULL) \
|
||||
{ \
|
||||
|
Reference in New Issue
Block a user