*** empty log message ***

This commit is contained in:
hyung-hwan 2006-07-10 14:28:46 +00:00
parent 494061b3c0
commit ba4ea092ce
6 changed files with 223 additions and 175 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: map.c,v 1.19 2006-05-06 12:52:36 bacon Exp $
* $Id: map.c,v 1.20 2006-07-10 14:28:45 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -81,7 +81,7 @@ void xp_awk_map_clear (xp_awk_map_t* map)
xp_assert (map->size == 0);
}
xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, xp_char_t* key)
xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, const xp_char_t* key)
{
xp_awk_pair_t* pair;
xp_size_t hc;
@ -171,13 +171,14 @@ xp_awk_pair_t* xp_awk_map_set (xp_awk_map_t* map, xp_char_t* key, void* val)
}
xp_awk_pair_t* xp_awk_map_getpair (
xp_awk_map_t* map, xp_char_t* key, void** val)
xp_awk_map_t* map, const xp_char_t* key, void** val)
{
xp_awk_pair_t* pair;
pair = xp_awk_map_get (map, key);
if (pair == XP_NULL) return XP_NULL;
*val = pair->val;
return pair;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: map.h,v 1.12 2006-06-16 14:31:42 bacon Exp $
* $Id: map.h,v 1.13 2006-07-10 14:28:45 bacon Exp $
*/
#ifndef _XP_AWK_MAP_H_
@ -39,13 +39,13 @@ void xp_awk_map_close (xp_awk_map_t* map);
void xp_awk_map_clear (xp_awk_map_t* map);
xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, xp_char_t* key);
xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, const xp_char_t* key);
xp_awk_pair_t* xp_awk_map_put (xp_awk_map_t* map, xp_char_t* key, void* val);
int xp_awk_map_putx (xp_awk_map_t* map, xp_char_t* key, void* val, xp_awk_pair_t** px);
xp_awk_pair_t* xp_awk_map_set (xp_awk_map_t* map, xp_char_t* key, void* val);
xp_awk_pair_t* xp_awk_map_getpair (
xp_awk_map_t* map, xp_char_t* key, void** val);
xp_awk_map_t* map, const xp_char_t* key, void** val);
xp_awk_pair_t* xp_awk_map_setpair (
xp_awk_map_t* map, xp_awk_pair_t* pair, void* val);

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.134 2006-07-07 09:48:23 bacon Exp $
* $Id: parse.c,v 1.135 2006-07-10 14:28:45 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -107,6 +107,8 @@ struct __binmap_t
static xp_awk_t* __parse_progunit (xp_awk_t* awk);
static xp_awk_t* __collect_globals (xp_awk_t* awk);
static xp_awk_t* __add_builtin_globals (xp_awk_t* awk);
static xp_awk_t* __add_global (xp_awk_t* awk, const xp_char_t* name);
static xp_awk_t* __collect_locals (xp_awk_t* awk, xp_size_t nlocals);
static xp_awk_nde_t* __parse_function (xp_awk_t* awk);
@ -220,33 +222,37 @@ static struct __kwent __kwtab[] =
{ XP_NULL, 0, 0 }
};
/* TODO:
static struct __kwent __bvtab[] =
struct __bvent
{
{ XP_T("ARGC"), TOKEN_ARGC, 0 },
{ XP_T("ARGIND"), TOKEN_ARGIND, 0 },
{ XP_T("ARGV"), TOKEN_ARGV, 0 },
{ XP_T("CONVFMT"), TOKEN_CONVFMT, 0 },
{ XP_T("FIELDWIDTHS"), TOKEN_FIELDWIDTHS, 0 },
{ XP_T("ENVIRON"), TOKEN_ENVIRON, 0 },
{ XP_T("ERRNO"), TOKEN_ERRNO, 0 },
{ XP_T("FILENAME"), TOKEN_FILENAME, 0 },
{ XP_T("FNR"), TOKEN_FNR, 0 },
{ XP_T("FS"), TOKEN_FS, 0 },
{ XP_T("IGNORECASE"), TOKEN_IGNORECASE, 0 },
{ XP_T("NF"), TOKEN_NF, 0 },
{ XP_T("NR"), TOKEN_NR, 0 },
{ XP_T("OFMT"), TOKEN_OFMT, 0 },
{ XP_T("OFS"), TOKEN_OFS, 0 },
{ XP_T("ORS"), TOKEN_ORS, 0 },
{ XP_T("RS"), TOKEN_RS, 0 },
{ XP_T("RT"), TOKEN_RT, 0 },
{ XP_T("RSTART"), TOKEN_RSTART, 0 },
{ XP_T("RLENGTH"), TOKEN_RLENGTH, 0 },
{ XP_T("SUBSEP"), TOKEN_SUBSEP, 0 },
{ XP_NULL, 0, 0 }
const xp_char_t* name;
int valid;
};
static struct __bvent __bvtab[] =
{
{ XP_T("ARGC"), 0 },
{ XP_T("ARGIND"), 0 },
{ XP_T("ARGV"), 0 },
{ XP_T("CONVFMT"), 0 },
{ XP_T("FIELDWIDTHS"), 0 },
{ XP_T("ENVIRON"), 0 },
{ XP_T("ERRNO"), 0 },
{ XP_T("FILENAME"), 0 },
{ XP_T("FNR"), 0 },
{ XP_T("FS"), 0 },
{ XP_T("IGNORECASE"), 0 },
{ XP_T("NF"), 0 },
{ XP_T("NR"), 0 },
{ XP_T("OFMT"), 0 },
{ XP_T("OFS"), 0 },
{ XP_T("ORS"), 0 },
{ XP_T("RS"), 0 },
{ XP_T("RT"), 0 },
{ XP_T("RSTART"), 0 },
{ XP_T("RLENGTH"), 0 },
{ XP_T("SUBSEP"), 0 },
{ XP_NULL, 0 }
};
*/
#define GET_CHAR(awk) \
do { if (__get_char(awk) == -1) return -1; } while(0)
@ -373,6 +379,8 @@ int xp_awk_parse (xp_awk_t* awk)
xp_awk_clear (awk);
if (__add_builtin_globals (awk) == XP_NULL) return -1;
GET_CHAR (awk);
GET_TOKEN (awk);
@ -894,6 +902,44 @@ and merged to top-level block */
return (xp_awk_nde_t*)block;
}
static xp_awk_t* __add_builtin_globals (xp_awk_t* awk)
{
struct __bvent* p = __bvtab;
while (p->name != XP_NULL)
{
if (__add_global (awk, p->name) == XP_NULL) return XP_NULL;
p++;
}
return awk;
}
static xp_awk_t* __add_global (xp_awk_t* awk, const xp_char_t* name)
{
if (awk->opt.parse & XP_AWK_UNIQUE)
{
/* check if it conflict with a function name */
if (xp_awk_map_get(&awk->tree.afns, name) != XP_NULL)
{
PANIC (awk, XP_AWK_EDUPNAME);
}
}
/* check if it conflicts with other global variable names */
if (xp_awk_tab_find(&awk->parse.globals, name, 0) != (xp_size_t)-1)
{
PANIC (awk, XP_AWK_EDUPVAR);
}
if (xp_awk_tab_add(&awk->parse.globals, name) == (xp_size_t)-1)
{
PANIC (awk, XP_AWK_ENOMEM);
}
return awk;
}
static xp_awk_t* __collect_globals (xp_awk_t* awk)
{
xp_char_t* global;
@ -907,25 +953,7 @@ static xp_awk_t* __collect_globals (xp_awk_t* awk)
global = XP_STR_BUF(&awk->token.name);
if (awk->opt.parse & XP_AWK_UNIQUE)
{
/* check if it conflict with a function name */
if (xp_awk_map_get(&awk->tree.afns, global) != XP_NULL)
{
PANIC (awk, XP_AWK_EDUPNAME);
}
}
/* check if it conflicts with other global variable names */
if (xp_awk_tab_find(&awk->parse.globals, global, 0) != (xp_size_t)-1)
{
PANIC (awk, XP_AWK_EDUPVAR);
}
if (xp_awk_tab_add(&awk->parse.globals, global) == (xp_size_t)-1)
{
PANIC (awk, XP_AWK_ENOMEM);
}
if (__add_global (awk, global) == XP_NULL) return XP_NULL;
if (__get_token(awk) == -1) return XP_NULL;
@ -2132,6 +2160,14 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
PANIC (awk, XP_AWK_ENOMEM);
}
/* TODO: search in the builtin variable name list */
/*
idxa = ....
if (idxa != (xp_size_t)-1)
{
}
*/
/* search the parameter name list */
idxa = xp_awk_tab_find(&awk->parse.params, name_dup, 0);
if (idxa != (xp_size_t)-1)
@ -2250,6 +2286,14 @@ static xp_awk_nde_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name)
PANIC (awk, XP_AWK_ENOMEM);
}
/* TODO: search in the builtin variable name list */
/*
idxa = xp_awk_tab_find (&awk->parse.params, name, 0);
if (idxa != (xp_size_t)-1)
{
}
*/
/* search the parameter name list */
idxa = xp_awk_tab_find (&awk->parse.params, name, 0);
if (idxa != (xp_size_t)-1)

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.129 2006-07-10 05:20:46 bacon Exp $
* $Id: run.c,v 1.130 2006-07-10 14:28:45 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -80,10 +80,6 @@ static xp_awk_val_t* __do_assignment_map (
static xp_awk_val_t* __do_assignment_pos (
xp_awk_run_t* run, xp_awk_nde_pos_t* pos, xp_awk_val_t* val);
static int __recomp_record_fields (
xp_awk_run_t* run, xp_size_t lv,
xp_char_t* str, xp_size_t len, int* errnum);
static xp_awk_val_t* __eval_binary (
xp_awk_run_t* run, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_binop_lor (
@ -165,6 +161,9 @@ static void __raw_pop_times (xp_awk_run_t* run, xp_size_t times);
static int __read_record (xp_awk_run_t* run);
static int __split_record (xp_awk_run_t* run);
static void __clear_record (xp_awk_run_t* run, xp_bool_t noline);
static int __recomp_record_fields (xp_awk_run_t* run,
xp_size_t lv, xp_char_t* str, xp_size_t len, int* errnum);
static int __val_to_num (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r);
static xp_char_t* __idxnde_to_str (xp_awk_run_t* run, xp_awk_nde_t* nde);
@ -1815,114 +1814,6 @@ static xp_awk_val_t* __do_assignment_pos (
return val;
}
static int __recomp_record_fields (
xp_awk_run_t* run, xp_size_t lv,
xp_char_t* str, xp_size_t len, int* errnum)
{
xp_size_t max, i, nflds;
xp_assert (lv > 0);
max = (lv > run->inrec.nflds)? lv: run->inrec.nflds;
nflds = run->inrec.nflds;
if (max > run->inrec.maxflds)
{
void* tmp = xp_realloc (
run->inrec.flds, xp_sizeof(*run->inrec.flds) * max);
if (tmp == XP_NULL) PANIC_I (run, XP_AWK_ENOMEM);
run->inrec.flds = tmp;
run->inrec.maxflds = max;
}
lv = lv - 1; /* adjust the value to 0-based index */
xp_str_clear (&run->inrec.line);
for (i = 0; i < max; i++)
{
if (i > 0)
{
/* TODO: use OFS */
if (xp_str_ccat (
&run->inrec.line, XP_T(' ')) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
}
if (i == lv)
{
xp_awk_val_t* tmp;
run->inrec.flds[i].ptr =
XP_STR_BUF(&run->inrec.line) +
XP_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = len;
if (xp_str_ncat (
&run->inrec.line, str, len) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
tmp = xp_awk_makestrval (str,len);
if (tmp == XP_NULL)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
if (i < nflds)
xp_awk_refdownval (run, run->inrec.flds[i].val);
else run->inrec.nflds++;
run->inrec.flds[i].val = tmp;
xp_awk_refupval (tmp);
}
else if (i >= nflds)
{
run->inrec.flds[i].ptr =
XP_STR_BUF(&run->inrec.line) +
XP_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = 0;
if (xp_str_cat (
&run->inrec.line, XP_T("")) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
/*xp_awk_refdownval (run, run->inrec.flds[i].val);*/
run->inrec.flds[i].val = xp_awk_val_zls;
xp_awk_refupval (xp_awk_val_zls);
run->inrec.nflds++;
}
else
{
xp_awk_val_str_t* tmp;
tmp = (xp_awk_val_str_t*)run->inrec.flds[i].val;
run->inrec.flds[i].ptr =
XP_STR_BUF(&run->inrec.line) +
XP_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = tmp->len;
if (xp_str_ncat (&run->inrec.line,
tmp->buf, tmp->len) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
}
}
return 0;
}
static xp_awk_val_t* __eval_binary (xp_awk_run_t* run, xp_awk_nde_t* nde)
{
static binop_func_t __binop_func[] =
@ -3800,6 +3691,8 @@ static int __split_record (xp_awk_run_t* run)
xp_sizeof(*run->inrec.flds) * nflds);
if (tmp == XP_NULL) PANIC_I (run, XP_AWK_ENOMEM);
if (run->inrec.flds != NULL)
xp_free (run->inrec.flds);
run->inrec.flds = tmp;
run->inrec.maxflds = nflds;
}
@ -3858,6 +3751,113 @@ static void __clear_record (xp_awk_run_t* run, xp_bool_t noline)
if (!noline) xp_str_clear (&run->inrec.line);
}
static int __recomp_record_fields (xp_awk_run_t* run,
xp_size_t lv, xp_char_t* str, xp_size_t len, int* errnum)
{
xp_size_t max, i, nflds;
xp_assert (lv > 0);
max = (lv > run->inrec.nflds)? lv: run->inrec.nflds;
nflds = run->inrec.nflds;
if (max > run->inrec.maxflds)
{
void* tmp = xp_realloc (
run->inrec.flds, xp_sizeof(*run->inrec.flds) * max);
if (tmp == XP_NULL) PANIC_I (run, XP_AWK_ENOMEM);
run->inrec.flds = tmp;
run->inrec.maxflds = max;
}
lv = lv - 1; /* adjust the value to 0-based index */
xp_str_clear (&run->inrec.line);
for (i = 0; i < max; i++)
{
if (i > 0)
{
/* TODO: use OFS */
if (xp_str_ccat (
&run->inrec.line, XP_T(' ')) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
}
if (i == lv)
{
xp_awk_val_t* tmp;
run->inrec.flds[i].ptr =
XP_STR_BUF(&run->inrec.line) +
XP_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = len;
if (xp_str_ncat (
&run->inrec.line, str, len) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
tmp = xp_awk_makestrval (str,len);
if (tmp == XP_NULL)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
if (i < nflds)
xp_awk_refdownval (run, run->inrec.flds[i].val);
else run->inrec.nflds++;
run->inrec.flds[i].val = tmp;
xp_awk_refupval (tmp);
}
else if (i >= nflds)
{
run->inrec.flds[i].ptr =
XP_STR_BUF(&run->inrec.line) +
XP_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = 0;
if (xp_str_cat (
&run->inrec.line, XP_T("")) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
/*xp_awk_refdownval (run, run->inrec.flds[i].val);*/
run->inrec.flds[i].val = xp_awk_val_zls;
xp_awk_refupval (xp_awk_val_zls);
run->inrec.nflds++;
}
else
{
xp_awk_val_str_t* tmp;
tmp = (xp_awk_val_str_t*)run->inrec.flds[i].val;
run->inrec.flds[i].ptr =
XP_STR_BUF(&run->inrec.line) +
XP_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = tmp->len;
if (xp_str_ncat (&run->inrec.line,
tmp->buf, tmp->len) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
}
}
return 0;
}
static int __val_to_num (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r)
{
if (v->type == XP_AWK_VAL_NIL)

View File

@ -17,19 +17,22 @@ END
print "\a";
}
*/
{
//$3 = "10";
//print $0, $2, $5;
//print $0 = "wow this is just a test";
//print $0 = "";
//print $0;
$7="abcdefghi";
print a = $6;
print "[" $0 "],[" a "]";
global x, y;
{
for (i = 0; i < 10; i++)
{
print $i;
if (i == 3) a = $i;
}
/*
print $6;
$1 = $2;
$3 = $2;
$2 = $2;
print $0;
*/
print "--------------------";
print NF;
print "====================";
}

View File

@ -1,4 +1,4 @@
/*global x, j;*/
//global x, j;
func func1 (x)
{