*** empty log message ***

This commit is contained in:
hyung-hwan 2006-12-04 12:59:01 +00:00
parent 0e8c44fc3d
commit 9847a900fb
9 changed files with 98 additions and 37 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.95 2006-11-29 03:18:18 bacon Exp $
* $Id: awk.c,v 1.96 2006-12-04 12:58:23 bacon Exp $
*/
#if defined(__BORLANDC__)
@ -138,6 +138,8 @@ ase_awk_t* ase_awk_open (const ase_awk_syscas_t* syscas)
ase_awk_setmaxparsedepth (awk, ASE_AWK_DEPTH_BLOCK, 0);
ase_awk_setmaxparsedepth (awk, ASE_AWK_DEPTH_EXPR, 0);
ase_awk_setmaxrundepth (awk, ASE_AWK_DEPTH_BLOCK, 0);
ase_awk_setmaxrundepth (awk, ASE_AWK_DEPTH_EXPR, 0);
awk->run.count = 0;
awk->run.ptr = ASE_NULL;
@ -174,11 +176,6 @@ int ase_awk_clear (ase_awk_t* awk)
return -1;
}
/* TOOD: clear bfns when they can be added dynamically
awk->bfn.sys
awk->bfn.user
*/
ASE_AWK_MEMSET (awk, &awk->src.ios, 0, ASE_SIZEOF(awk->src.ios));
awk->src.lex.curc = ASE_CHAR_EOF;
awk->src.lex.ungotc_count = 0;
@ -258,3 +255,16 @@ ase_size_t ase_awk_getsrcline (ase_awk_t* awk)
return awk->token.line;
}
void ase_awk_setmaxrundepth (ase_awk_t* awk, int types, ase_size_t depth)
{
if (types & ASE_AWK_DEPTH_BLOCK)
{
awk->run.depth.max.block = depth;
}
if (types & ASE_AWK_DEPTH_EXPR)
{
awk->run.depth.max.expr = depth;
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h,v 1.159 2006-12-04 06:04:05 bacon Exp $
* $Id: awk.h,v 1.160 2006-12-04 12:58:23 bacon Exp $
*/
#ifndef _ASE_AWK_AWK_H_
@ -380,6 +380,8 @@ int ase_awk_getopt (ase_awk_t* awk);
void ase_awk_setopt (ase_awk_t* awk, int opt);
void ase_awk_setmaxparsedepth (ase_awk_t*, int types, ase_size_t depth);
void ase_awk_setmaxrundepth (ase_awk_t*, int types, ase_size_t depth);
int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios);
/*

View File

@ -1,5 +1,5 @@
/*
* $Id: awk_i.h,v 1.87 2006-11-29 03:18:18 bacon Exp $
* $Id: awk_i.h,v 1.88 2006-12-04 12:58:23 bacon Exp $
*/
#ifndef _ASE_AWK_AWKI_H_
@ -184,6 +184,21 @@ struct ase_awk_t
{
ase_size_t count;
ase_awk_run_t* ptr;
struct
{
struct
{
ase_size_t block;
ase_size_t expr;
} cur;
struct
{
ase_size_t block;
ase_size_t expr;
} max;
} depth;
} run;
/* housekeeping */
@ -294,6 +309,21 @@ struct ase_awk_run_t
} tmp;
} format;
struct
{
struct
{
ase_size_t block;
ase_size_t expr; /* expression */
} cur;
struct
{
ase_size_t block;
ase_size_t expr;
} max;
} depth;
int errnum;
void* custom_data;
ase_awk_t* awk;

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.215 2006-12-04 06:04:06 bacon Exp $
* $Id: parse.c,v 1.216 2006-12-04 12:58:23 bacon Exp $
*/
#include <ase/awk/awk_i.h>
@ -1424,14 +1424,16 @@ static ase_awk_nde_t* __parse_expression0 (ase_awk_t* awk)
return ASE_NULL;
}
y = __parse_basic_expr (awk);
/*y = __parse_basic_expr (awk);*/
y = __parse_expression (awk);
if (y == ASE_NULL)
{
ase_awk_clrpt (awk, x);
return ASE_NULL;
}
nde = (ase_awk_nde_ass_t*) ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_ass_t));
nde = (ase_awk_nde_ass_t*)
ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_ass_t));
if (nde == ASE_NULL)
{
ase_awk_clrpt (awk, x);
@ -1461,7 +1463,8 @@ static ase_awk_nde_t* __parse_basic_expr (ase_awk_t* awk)
if (__get_token(awk) == -1) return ASE_NULL;
n1 = __parse_basic_expr (awk);
/*n1 = __parse_basic_expr (awk);*/
n1 = __parse_expression (awk);
if (n1 == ASE_NULL)
{
ase_awk_clrpt (awk, nde);
@ -1471,7 +1474,8 @@ static ase_awk_nde_t* __parse_basic_expr (ase_awk_t* awk)
if (!MATCH(awk,TOKEN_COLON)) PANIC (awk, ASE_AWK_ECOLON);
if (__get_token(awk) == -1) return ASE_NULL;
n2 = __parse_basic_expr (awk);
/*n2 = __parse_basic_expr (awk);*/
n2 = __parse_expression (awk);
if (n2 == ASE_NULL)
{
ase_awk_clrpt (awk, nde);

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.292 2006-12-04 06:50:26 bacon Exp $
* $Id: run.c,v 1.293 2006-12-04 12:58:24 bacon Exp $
*/
#include <ase/awk/awk_i.h>
@ -54,8 +54,8 @@ static void __add_run (ase_awk_t* awk, ase_awk_run_t* run);
static void __del_run (ase_awk_t* awk, ase_awk_run_t* run);
static int __init_run (
ase_awk_run_t* run, ase_awk_runios_t* runios,
void* custom_data, int* errnum);
ase_awk_run_t* run, ase_awk_t* awk,
ase_awk_runios_t* runios, void* custom_data, int* errnum);
static void __deinit_run (ase_awk_run_t* run);
static int __build_runarg (ase_awk_run_t* run, ase_awk_runarg_t* runarg);
@ -69,6 +69,7 @@ static int __run_pattern_block_chain (
static int __run_pattern_block (
ase_awk_run_t* run, ase_awk_chain_t* chain, ase_size_t block_no);
static int __run_block (ase_awk_run_t* run, ase_awk_nde_blk_t* nde);
static int __run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde);
static int __run_statement (ase_awk_run_t* run, ase_awk_nde_t* nde);
static int __run_if (ase_awk_run_t* run, ase_awk_nde_if_t* nde);
static int __run_while (ase_awk_run_t* run, ase_awk_nde_while_t* nde);
@ -572,7 +573,7 @@ int ase_awk_run (ase_awk_t* awk,
__add_run (awk, run);
if (__init_run (run, runios, custom_data, &errnum) == -1)
if (__init_run (run, awk, runios, custom_data, &errnum) == -1)
{
awk->errnum = errnum;
__del_run (awk, run);
@ -699,8 +700,8 @@ static void __del_run (ase_awk_t* awk, ase_awk_run_t* run)
}
static int __init_run (
ase_awk_run_t* run, ase_awk_runios_t* runios,
void* custom_data, int* errnum)
ase_awk_run_t* run, ase_awk_t* awk,
ase_awk_runios_t* runios, void* custom_data, int* errnum)
{
run->custom_data = custom_data;
@ -800,6 +801,11 @@ static int __init_run (
run->global.fs = ASE_NULL;
run->global.ignorecase = 0;
run->depth.max.block = awk->run.depth.max.block;
run->depth.max.expr = awk->run.depth.max.expr;
run->depth.cur.block = 0;
run->depth.cur.expr = 0;
return 0;
}
@ -1496,6 +1502,24 @@ static int __run_pattern_block (
}
static int __run_block (ase_awk_run_t* run, ase_awk_nde_blk_t* nde)
{
int n;
if (run->depth.max.block > 0 &&
run->depth.cur.block >= run->depth.max.block)
{
run->errnum = ASE_AWK_ERECURSION;
return -1;;
}
run->depth.cur.block++;
n = __run_block0 (run, nde);
run->depth.cur.block--;
return n;
}
static int __run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde)
{
ase_awk_nde_t* p;
ase_size_t nlocals;
@ -4159,7 +4183,6 @@ static ase_awk_val_t* __eval_binop_match0 (
PANIC (run, errnum);
}
wprintf (L"n=%d, ret=%d\n", n, ret);
res = ase_awk_makeintval (run, (n == ret));
if (res == ASE_NULL)
{

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c,v 1.95 2006-12-02 16:26:03 bacon Exp $
* $Id: val.c,v 1.96 2006-12-04 12:58:24 bacon Exp $
*/
#include <ase/awk/awk_i.h>
@ -718,7 +718,7 @@ int ase_awk_valtonum (
}
int ase_awk_strtonum (
ase_awk_run_t* run, const ase_awk_str_t* ptr, ase_size_t len,
ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len,
ase_long_t* l, ase_real_t* r)
{
const ase_char_t* endptr;

View File

@ -1,5 +1,5 @@
/*
* $Id: val.h,v 1.55 2006-12-02 16:26:03 bacon Exp $
* $Id: val.h,v 1.56 2006-12-04 12:58:24 bacon Exp $
*/
#ifndef _ASE_AWK_VAL_H_
@ -178,7 +178,7 @@ ase_char_t* ase_awk_valtostr (
int ase_awk_valtonum (
ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r);
int ase_awk_strtonum (
ase_awk_run_t* run, const ase_awk_str_t* ptr, ase_size_t len,
ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len,
ase_long_t* l, ase_real_t* r);
void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val);

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.134 2006-12-04 06:04:07 bacon Exp $
* $Id: awk.c,v 1.135 2006-12-04 12:59:00 bacon Exp $
*/
#include <ase/awk/awk.h>
@ -730,12 +730,6 @@ static void __awk_free (void* ptr, void* custom_data)
#define __awk_tolower towlower
#endif
static int __handle_bfn (ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
{
xp_printf (ASE_T("__handle_bfn\n"));
return 0;
}
static int __main (int argc, ase_char_t* argv[])
{
ase_awk_t* awk;
@ -851,12 +845,10 @@ static int __main (int argc, ase_char_t* argv[])
srcios.custom_data = &src_io;
ase_awk_addbfn (awk, ASE_T("bufa"), 4, 0,
1, 1, ASE_NULL, __handle_bfn);
ase_awk_setmaxparsedepth (
awk, ASE_AWK_DEPTH_BLOCK | ASE_AWK_DEPTH_EXPR, 20);
ase_awk_setmaxrundepth (
awk, ASE_AWK_DEPTH_BLOCK | ASE_AWK_DEPTH_EXPR, 50);
if (ase_awk_parse (awk, &srcios) == -1)
{

View File

@ -1,5 +1,5 @@
BEGIN { FS = "\t"; OFS = "\t"; }
#BEGIN { FS = OFS = "\t"; }
#BEGIN { FS = "\t"; OFS = "\t"; }
BEGIN { FS = OFS = "\t"; }
$4 == "North America" { $4 = "NA"; }
$4 == "South America" { $4 = "SA"; }
{ print; }