Recovered from cvs revision 2007-09-27 11:04:00

This commit is contained in:
hyung-hwan 2007-09-27 20:33:00 +00:00
parent d3cdbc62f1
commit d1546c0b7a
12 changed files with 632 additions and 422 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.58 2007/09/24 11:22:22 bacon Exp $
* $Id: Awk.cpp,v 1.59 2007/09/25 07:17:30 bacon Exp $
*
* {License}
*/
@ -257,6 +257,10 @@ int Awk::Argument::init (run_t* run, val_t* v)
this->str.ptr = ase_awk_valtostr (run, v, 0, ASE_NULL, &this->str.len);
if (this->str.ptr != ASE_NULL) return 0;
}
else if (v->type == ASE_AWK_VAL_MAP)
{
// TODO: support this propertly...
}
ase_awk_refdownval (run, v);
this->run = ASE_NULL;

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp,v 1.60 2007/09/24 11:22:22 bacon Exp $
* $Id: Awk.hpp,v 1.61 2007/09/25 15:27:54 bacon Exp $
*
* {License}
*/
@ -531,7 +531,9 @@ public:
* as the second and the third parameter are passed to
* the function specified as the first parameter.
*/
OPT_ARGSTOMAIN = ASE_AWK_ARGSTOMAIN
OPT_ARGSTOMAIN = ASE_AWK_ARGSTOMAIN,
/** Enables the keyword 'reset' */
OPT_RESET = ASE_AWK_RESET
};
// end of enum Option

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h,v 1.12 2007/09/23 16:48:55 bacon Exp $
* $Id: awk.h,v 1.14 2007/09/25 15:27:54 bacon Exp $
*
* {License}
*/
@ -7,6 +7,9 @@
#ifndef _ASE_AWK_AWK_H_
#define _ASE_AWK_AWK_H_
// TODO: REMOVE THIS. MOVE IT SOMEWHRE ELSE OR CHANGE THE SCHEME
//#define PROHIBIT_MAP_ASSIGNMENT_TO_VARIABLE
#include <ase/cmn/types.h>
#include <ase/cmn/macros.h>
@ -190,7 +193,10 @@ enum ase_awk_option_t
ASE_AWK_CRLF = (1 << 13),
/* pass the arguments to the main function */
ASE_AWK_ARGSTOMAIN = (1 << 14)
ASE_AWK_ARGSTOMAIN = (1 << 14),
/* enable the non-standard keyworkd reset */
ASE_AWK_RESET = (1 << 15)
};
/* error code */
@ -275,6 +281,7 @@ enum ase_awk_errnum_t
ASE_AWK_ELCLTM, /* too many local variables */
ASE_AWK_EPARTM, /* too many parameters */
ASE_AWK_EDELETE, /* delete not followed by a variable */
ASE_AWK_ERESET, /* reset not followed by a variable */
ASE_AWK_EBREAK, /* break outside a loop */
ASE_AWK_ECONTINUE, /* continue outside a loop */
ASE_AWK_ENEXTBEG, /* next illegal in BEGIN block */
@ -307,6 +314,7 @@ enum ase_awk_errnum_t
ASE_AWK_EMAPNOTALLOWED, /* a map is not allowed */
ASE_AWK_EVALTYPE, /* wrong value type */
ASE_AWK_ERDELETE, /* delete called with a wrong target */
ASE_AWK_ERRESET, /* reset called with a wrong target */
ASE_AWK_ERNEXTBEG, /* next called from BEGIN */
ASE_AWK_ERNEXTEND, /* next called from END */
ASE_AWK_ERNEXTFBEG, /* nextfile called from BEGIN */

View File

@ -1,5 +1,5 @@
/*
* $Id: err.c,v 1.7 2007/09/23 16:48:55 bacon Exp $
* $Id: err.c,v 1.8 2007/09/25 15:27:54 bacon Exp $
*
* {License}
*/
@ -89,6 +89,7 @@ static const ase_char_t* __geterrstr (int errnum)
ASE_T("too many local variables"),
ASE_T("too many parameters"),
ASE_T("delete statement not followed by a normal variable"),
ASE_T("reset statement not followed by a normal variable"),
ASE_T("break statement outside a loop"),
ASE_T("continue statement outside a loop"),
ASE_T("next statement illegal in the BEGIN block"),
@ -119,6 +120,7 @@ static const ase_char_t* __geterrstr (int errnum)
ASE_T("a map is not allowed"),
ASE_T("invalid value type"),
ASE_T("delete statement called with a wrong target"),
ASE_T("reset statement called with a wrong target"),
ASE_T("next statement called from the BEGIN block"),
ASE_T("next statement called from the END block"),
ASE_T("nextfile statement called from the BEGIN block"),

View File

@ -1,5 +1,5 @@
/*
* $Id: func.c,v 1.9 2007/09/23 16:48:55 bacon Exp $
* $Id: func.c,v 1.10 2007/09/25 11:25:48 bacon Exp $
*
* {License}
*/
@ -53,6 +53,12 @@ void* ase_awk_addfunc (
/* TODO: make function table hash-accessable */
if (name_len <= 0)
{
ase_awk_seterror (awk, ASE_AWK_EINVAL, 0, ASE_NULL, 0);
return ASE_NULL;
}
if (ase_awk_getbfn (awk, name, name_len) != ASE_NULL)
{
ase_cstr_t errarg;

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.15 2007/09/24 08:21:25 bacon Exp $
* $Id: parse.c,v 1.18 2007/09/25 15:27:54 bacon Exp $
*
* {License}
*/
@ -85,6 +85,7 @@ enum
TOKEN_NEXTINFILE,
TOKEN_NEXTOFILE,
TOKEN_DELETE,
TOKEN_RESET,
TOKEN_PRINT,
TOKEN_PRINTF,
@ -195,6 +196,7 @@ static ase_awk_nde_t* parse_exit (ase_awk_t* awk, ase_size_t line);
static ase_awk_nde_t* parse_next (ase_awk_t* awk, ase_size_t line);
static ase_awk_nde_t* parse_nextfile (ase_awk_t* awk, ase_size_t line, int out);
static ase_awk_nde_t* parse_delete (ase_awk_t* awk, ase_size_t line);
static ase_awk_nde_t* parse_reset (ase_awk_t* awk, ase_size_t line);
static ase_awk_nde_t* parse_print (ase_awk_t* awk, ase_size_t line, int type);
static int get_token (ase_awk_t* awk);
@ -258,6 +260,7 @@ static kwent_t kwtab[] =
{ ASE_T("nextfile"), 8, TOKEN_NEXTFILE, 0 },
{ ASE_T("nextofile"), 9, TOKEN_NEXTOFILE, ASE_AWK_NEXTOFILE },
{ ASE_T("delete"), 6, TOKEN_DELETE, 0 },
{ ASE_T("reset"), 5, TOKEN_RESET, ASE_AWK_RESET },
{ ASE_T("print"), 5, TOKEN_PRINT, ASE_AWK_EXTIO },
{ ASE_T("printf"), 6, TOKEN_PRINTF, ASE_AWK_EXTIO },
@ -393,8 +396,15 @@ void ase_awk_setmaxdepth (ase_awk_t* awk, int types, ase_size_t depth)
const ase_char_t* ase_awk_getglobalname (
ase_awk_t* awk, ase_size_t idx, ase_size_t* len)
{
/*
*len = gtab[idx].name_len;
return gtab[idx].name;
*/
ASE_ASSERT (idx < ase_awk_tab_getsize(&awk->parse.globals));
*len = awk->parse.globals.buf[idx].name.len;
return awk->parse.globals.buf[idx].name.ptr;
}
@ -1368,6 +1378,12 @@ int ase_awk_addglobal (
{
int n;
if (len <= 0)
{
SETERR (awk, ASE_AWK_EINVAL);
return -1;
}
if (awk->tree.nglobals > awk->tree.nbglobals)
{
/* this function is not allow after ase_awk_parse is called */
@ -1708,6 +1724,11 @@ static ase_awk_nde_t* parse_statement_nb (ase_awk_t* awk, ase_size_t line)
if (get_token(awk) == -1) return ASE_NULL;
nde = parse_delete (awk, line);
}
else if (MATCH(awk,TOKEN_RESET))
{
if (get_token(awk) == -1) return ASE_NULL;
nde = parse_reset (awk, line);
}
else if (MATCH(awk,TOKEN_PRINT))
{
if (get_token(awk) == -1) return ASE_NULL;
@ -3880,6 +3901,46 @@ static ase_awk_nde_t* parse_delete (ase_awk_t* awk, ase_size_t line)
return (ase_awk_nde_t*)nde;
}
static ase_awk_nde_t* parse_reset (ase_awk_t* awk, ase_size_t line)
{
ase_awk_nde_reset_t* nde;
ase_awk_nde_t* var;
ASE_ASSERT (awk->token.prev.type == TOKEN_RESET);
if (!MATCH(awk,TOKEN_IDENT))
{
SETERRTOK (awk, ASE_AWK_EIDENT);
return ASE_NULL;
}
var = parse_primary_ident (awk, awk->token.line);
if (var == ASE_NULL) return ASE_NULL;
/* unlike delete, it must be followed by a plain variable only */
if (!is_plain_var (var))
{
/* a normal identifier is expected */
ase_awk_clrpt (awk, var);
SETERRLIN (awk, ASE_AWK_ERESET, line);
return ASE_NULL;
}
nde = (ase_awk_nde_reset_t*) ASE_AWK_MALLOC (
awk, ASE_SIZEOF(ase_awk_nde_reset_t));
if (nde == ASE_NULL)
{
SETERRLIN (awk, ASE_AWK_ENOMEM, line);
return ASE_NULL;
}
nde->type = ASE_AWK_NDE_RESET;
nde->line = line;
nde->next = ASE_NULL;
nde->var = var;
return (ase_awk_nde_t*)nde;
}
static ase_awk_nde_t* parse_print (ase_awk_t* awk, ase_size_t line, int type)
{
ase_awk_nde_print_t* nde;

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.c,v 1.4 2007/05/13 14:43:58 bacon Exp $
* $Id: tree.c,v 1.5 2007/09/25 15:27:54 bacon Exp $
*
* {License}
*/
@ -833,6 +833,14 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
break;
}
case ASE_AWK_NDE_RESET:
{
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("reset "));
ase_awk_prnpt (awk, ((ase_awk_nde_reset_t*)p)->var);
break;
}
case ASE_AWK_NDE_PRINT:
case ASE_AWK_NDE_PRINTF:
{
@ -1011,6 +1019,13 @@ void ase_awk_clrpt (ase_awk_t* awk, ase_awk_nde_t* tree)
break;
}
case ASE_AWK_NDE_RESET:
{
ase_awk_clrpt (awk, ((ase_awk_nde_reset_t*)p)->var);
ASE_AWK_FREE (awk, p);
break;
}
case ASE_AWK_NDE_PRINT:
case ASE_AWK_NDE_PRINTF:
{

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.h,v 1.4 2007/09/23 16:48:55 bacon Exp $
* $Id: tree.h,v 1.5 2007/09/25 15:27:54 bacon Exp $
*
* {License}
*/
@ -29,6 +29,7 @@ enum ase_awk_nde_type_t
ASE_AWK_NDE_NEXT,
ASE_AWK_NDE_NEXTFILE,
ASE_AWK_NDE_DELETE,
ASE_AWK_NDE_RESET,
ASE_AWK_NDE_PRINT,
ASE_AWK_NDE_PRINTF,
@ -127,6 +128,7 @@ typedef struct ase_awk_nde_exit_t ase_awk_nde_exit_t;
typedef struct ase_awk_nde_next_t ase_awk_nde_next_t;
typedef struct ase_awk_nde_nextfile_t ase_awk_nde_nextfile_t;
typedef struct ase_awk_nde_delete_t ase_awk_nde_delete_t;
typedef struct ase_awk_nde_reset_t ase_awk_nde_reset_t;
typedef struct ase_awk_nde_print_t ase_awk_nde_print_t;
struct ase_awk_afn_t
@ -378,6 +380,13 @@ struct ase_awk_nde_delete_t
ase_awk_nde_t* var;
};
/* ASE_AWK_NDE_RESET */
struct ase_awk_nde_reset_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* var;
};
/* ASE_AWK_NDE_PRINT */
struct ase_awk_nde_print_t
{

View File

@ -1,9 +1,15 @@
[0.3.1]
* added to the awk interpreter the capibility to manipulate global variables
- ase_awk_addglobal, ase_awk_delglobal (awk/parse.c)
- Awk::addGlobal, Awk::deleteGlobal (awk/Awk.hpp, awk/Awk.cpp)
- Awk::Run::setGlobal, Awk::Run::getGlobal (awk/Awk.hpp, awk/Awk.cpp)
- added ase_awk_addglobal, ase_awk_delglobal (awk/parse.c)
- added Awk::addGlobal, Awk::deleteGlobal (awk/Awk.hpp, awk/Awk.cpp)
- added Awk::Run::setGlobal, Awk::Run::getGlobal (awk/Awk.hpp, awk/Awk.cpp)
- enhanced ase_awk_getglobalname
* added an option
- ASE_AWK_RESET (awk/awk.h)
- Awk::OPT_RESET (awk/Awk.hpp)
- Awk::OPTION::RESET (net/Awk.hpp)
- TODO: add it to com&java
* enhanced Awk::dispatchFunction to set a more accurate error code (awk/Awk.cpp)

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp,v 1.25 2007/09/25 05:49:55 bacon Exp $
* $Id: Awk.hpp,v 1.26 2007/09/25 15:27:54 bacon Exp $
*
* {License}
*/
@ -390,7 +390,8 @@ namespace ASE
STRIPSPACES = ASE::Awk::OPT_STRIPSPACES,
NEXTOFILE = ASE::Awk::OPT_NEXTOFILE,
CRLF = ASE::Awk::OPT_CRLF,
ARGSTOMAIN = ASE::Awk::OPT_ARGSTOMAIN
ARGSTOMAIN = ASE::Awk::OPT_ARGSTOMAIN,
RESET = ASE::Awk::OPT_RESET
};
enum class DEPTH: int

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.34 2007/09/24 08:21:25 bacon Exp $
* $Id: Awk.cpp,v 1.35 2007/09/25 15:27:54 bacon Exp $
*/
#include <ase/awk/StdAwk.hpp>
@ -593,6 +593,10 @@ int awk_main (int argc, ase_char_t* argv[])
{
awk.setOption (awk.getOption () & ~TestAwk::OPT_SHADING);
}
else if (ase_strcmp(argv[i], ASE_T("-reset")) == 0)
{
awk.setOption (awk.getOption () | TestAwk::OPT_RESET);
}
else
{
print_usage (argv[0]);