*** empty log message ***

This commit is contained in:
hyung-hwan 2006-05-13 16:33:07 +00:00
parent 53a5fca55e
commit 7aa5501055
6 changed files with 85 additions and 46 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.49 2006-05-11 17:32:37 bacon Exp $
* $Id: awk.c,v 1.50 2006-05-13 16:33:06 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -18,21 +18,22 @@ xp_awk_t* xp_awk_open (void)
awk = (xp_awk_t*) xp_malloc (xp_sizeof(xp_awk_t));
if (awk == XP_NULL) return XP_NULL;
if (xp_str_open(&awk->token.name, 128) == XP_NULL)
if (xp_str_open (&awk->token.name, 128) == XP_NULL)
{
xp_free (awk);
return XP_NULL;
}
/* TODO: initial map size?? */
if (xp_awk_map_open(&awk->tree.funcs,awk,256,__free_func) == XP_NULL)
if (xp_awk_map_open (
&awk->tree.funcs, awk, 256, __free_func) == XP_NULL)
{
xp_str_close (&awk->token.name);
xp_free (awk);
return XP_NULL;
}
if (xp_awk_tab_open(&awk->parse.globals) == XP_NULL)
if (xp_awk_tab_open (&awk->parse.globals) == XP_NULL)
{
xp_str_close (&awk->token.name);
xp_awk_map_close (&awk->tree.funcs);
@ -40,7 +41,7 @@ xp_awk_t* xp_awk_open (void)
return XP_NULL;
}
if (xp_awk_tab_open(&awk->parse.locals) == XP_NULL)
if (xp_awk_tab_open (&awk->parse.locals) == XP_NULL)
{
xp_str_close (&awk->token.name);
xp_awk_map_close (&awk->tree.funcs);
@ -49,7 +50,7 @@ xp_awk_t* xp_awk_open (void)
return XP_NULL;
}
if (xp_awk_tab_open(&awk->parse.params) == XP_NULL)
if (xp_awk_tab_open (&awk->parse.params) == XP_NULL)
{
xp_str_close (&awk->token.name);
xp_awk_map_close (&awk->tree.funcs);
@ -73,10 +74,15 @@ xp_awk_t* xp_awk_open (void)
awk->tree.chain = XP_NULL;
awk->tree.chain_tail = XP_NULL;
awk->token.line = 1;
awk->token.column = 1;
awk->lex.curc = XP_CHAR_EOF;
awk->lex.ungotc_count = 0;
awk->lex.buf_pos = 0;
awk->lex.buf_len = 0;
awk->lex.line = 1;
awk->lex.column = 1;
return awk;
}
@ -168,6 +174,8 @@ int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg)
awk->lex.ungotc_count = 0;
awk->lex.buf_pos = 0;
awk->lex.buf_len = 0;
awk->lex.line = 1;
awk->lex.column = 1;
return 0;
}
@ -190,6 +198,8 @@ int xp_awk_detsrc (xp_awk_t* awk)
awk->lex.ungotc_count = 0;
awk->lex.buf_pos = 0;
awk->lex.buf_len = 0;
awk->lex.line = 1;
awk->lex.column = 1;
}
return 0;
@ -205,3 +215,8 @@ static void __free_func (void* owner, void* func)
xp_awk_clrpt (f->body);
xp_free (f);
}
xp_size_t xp_awk_getsrcline (xp_awk_t* awk)
{
return awk->token.line;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h,v 1.60 2006-04-30 17:10:30 bacon Exp $
* $Id: awk.h,v 1.61 2006-05-13 16:33:07 bacon Exp $
*/
#ifndef _XP_AWK_AWK_H_
@ -119,6 +119,7 @@ void xp_awk_setrunopt (xp_awk_t* awk, int opt);
int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg);
int xp_awk_detsrc (xp_awk_t* awk);
xp_size_t xp_awk_getsrcline (xp_awk_t* awk);
/* TODO: xp_awk_parse (xp_awk_t* awk, xp_awk_io_t src, void* arg)??? */
int xp_awk_parse (xp_awk_t* awk);
int xp_awk_run (xp_awk_t* awk, xp_awk_io_t txtio, void* txtio_arg);

View File

@ -1,5 +1,5 @@
/*
* $Id: awk_i.h,v 1.11 2006-05-12 09:39:20 bacon Exp $
* $Id: awk_i.h,v 1.12 2006-05-13 16:33:07 bacon Exp $
*/
#ifndef _XP_AWK_AWKI_H_
@ -107,6 +107,9 @@ struct xp_awk_t
xp_char_t buf[512];
xp_size_t buf_pos;
xp_size_t buf_len;
xp_size_t line;
xp_size_t column;
} lex;
/* token */
@ -114,6 +117,8 @@ struct xp_awk_t
{
int type;
xp_str_t name;
xp_size_t line;
xp_size_t column;
} token;
/* housekeeping */

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.105 2006-05-12 09:39:20 bacon Exp $
* $Id: parse.c,v 1.106 2006-05-13 16:33:07 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -231,26 +231,26 @@ static struct __kwent __bvtab[] =
do { if (__get_char(awk) == -1) return -1; } while(0)
#define GET_CHAR_TO(awk,c) \
do { \
if (__get_char(awk) == -1) return -1; \
c = (awk)->lex.curc; \
} while(0)
do { \
if (__get_char(awk) == -1) return -1; \
c = (awk)->lex.curc; \
} while(0)
#define SET_TOKEN_TYPE(awk,code) ((awk)->token.type = code)
#define ADD_TOKEN_CHAR(awk,c) \
do { \
if (xp_str_ccat(&(awk)->token.name,(c)) == (xp_size_t)-1) { \
(awk)->errnum = XP_AWK_ENOMEM; return -1; \
} \
} while (0)
do { \
if (xp_str_ccat(&(awk)->token.name,(c)) == (xp_size_t)-1) { \
(awk)->errnum = XP_AWK_ENOMEM; return -1; \
} \
} while (0)
#define ADD_TOKEN_STR(awk,str) \
do { \
if (xp_str_cat(&(awk)->token.name,(str)) == (xp_size_t)-1) { \
(awk)->errnum = XP_AWK_ENOMEM; return -1; \
} \
} while (0)
do { \
if (xp_str_cat(&(awk)->token.name,(str)) == (xp_size_t)-1) { \
(awk)->errnum = XP_AWK_ENOMEM; return -1; \
} \
} while (0)
#define GET_TOKEN(awk) \
do { if (__get_token(awk) == -1) return -1; } while (0)
@ -647,7 +647,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
/* parameter names are not required anymore. clear them */
xp_awk_tab_clear (&awk->parse.params);
func = (xp_awk_func_t*)xp_malloc(xp_sizeof(xp_awk_func_t));
func = (xp_awk_func_t*) xp_malloc (xp_sizeof(xp_awk_func_t));
if (func == XP_NULL)
{
xp_free (name_dup);
@ -826,7 +826,7 @@ static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top)
curr = nde;
}
block = (xp_awk_nde_blk_t*)xp_malloc(xp_sizeof(xp_awk_nde_blk_t));
block = (xp_awk_nde_blk_t*) xp_malloc (xp_sizeof(xp_awk_nde_blk_t));
if (block == XP_NULL)
{
xp_awk_tab_remove (
@ -986,7 +986,7 @@ static xp_awk_nde_t* __parse_statement (xp_awk_t* awk)
if (MATCH(awk,TOKEN_SEMICOLON))
{
/* null statement */
nde = (xp_awk_nde_t*)xp_malloc(xp_sizeof(xp_awk_nde_t));
nde = (xp_awk_nde_t*) xp_malloc (xp_sizeof(xp_awk_nde_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_NULL;
@ -1193,7 +1193,8 @@ static xp_awk_nde_t* __parse_basic_expr (xp_awk_t* awk)
return XP_NULL;
}
tmp = (xp_awk_nde_cnd_t*)xp_malloc(xp_sizeof(xp_awk_nde_cnd_t));
tmp = (xp_awk_nde_cnd_t*)
xp_malloc (xp_sizeof(xp_awk_nde_cnd_t));
if (tmp == XP_NULL)
{
xp_awk_clrpt (nde);
@ -1644,7 +1645,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
xp_awk_nde_var_t* nde;
xp_size_t idxa;
nde = (xp_awk_nde_var_t*)xp_malloc(xp_sizeof(xp_awk_nde_var_t));
nde = (xp_awk_nde_var_t*)
xp_malloc (xp_sizeof(xp_awk_nde_var_t));
if (nde == XP_NULL)
{
xp_free (name_dup);
@ -1714,7 +1716,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
{
xp_awk_nde_int_t* nde;
nde = (xp_awk_nde_int_t*)xp_malloc(xp_sizeof(xp_awk_nde_int_t));
nde = (xp_awk_nde_int_t*)
xp_malloc (xp_sizeof(xp_awk_nde_int_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_INT;
@ -1762,7 +1765,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
{
xp_awk_nde_str_t* nde;
nde = (xp_awk_nde_str_t*)xp_malloc(xp_sizeof(xp_awk_nde_str_t));
nde = (xp_awk_nde_str_t*)
xp_malloc (xp_sizeof(xp_awk_nde_str_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_STR;
@ -1794,7 +1798,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
if (__get_regex(awk) == -1) return XP_NULL;
xp_assert (MATCH(awk,TOKEN_REX));
nde = (xp_awk_nde_str_t*)xp_malloc(xp_sizeof(xp_awk_nde_rex_t));
nde = (xp_awk_nde_str_t*)
xp_malloc (xp_sizeof(xp_awk_nde_rex_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_REX;
@ -1826,7 +1831,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
prim = __parse_primary (awk);
if (prim == XP_NULL) return XP_NULL;
nde = (xp_awk_nde_pos_t*)xp_malloc(xp_sizeof(xp_awk_nde_pos_t));
nde = (xp_awk_nde_pos_t*)
xp_malloc (xp_sizeof(xp_awk_nde_pos_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (prim);
@ -1902,7 +1908,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
PANIC (awk, XP_AWK_EIN);
}
tmp = (xp_awk_nde_grp_t*) xp_malloc (xp_sizeof(xp_awk_nde_grp_t));
tmp = (xp_awk_nde_grp_t*)
xp_malloc (xp_sizeof(xp_awk_nde_grp_t));
if (tmp == XP_NULL)
{
xp_awk_clrpt (nde);
@ -2099,7 +2106,7 @@ static xp_awk_nde_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name)
}
call = (xp_awk_nde_call_t*)xp_malloc(xp_sizeof(xp_awk_nde_call_t));
call = (xp_awk_nde_call_t*) xp_malloc (xp_sizeof(xp_awk_nde_call_t));
if (call == XP_NULL)
{
if (head != XP_NULL) xp_awk_clrpt (head);
@ -2166,8 +2173,7 @@ static xp_awk_nde_t* __parse_if (xp_awk_t* awk)
}
else else_part = XP_NULL;
nde = (xp_awk_nde_if_t*)
xp_malloc (xp_sizeof(xp_awk_nde_if_t));
nde = (xp_awk_nde_if_t*) xp_malloc (xp_sizeof(xp_awk_nde_if_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (else_part);
@ -2215,8 +2221,7 @@ static xp_awk_nde_t* __parse_while (xp_awk_t* awk)
return XP_NULL;
}
nde = (xp_awk_nde_while_t*)
xp_malloc (xp_sizeof(xp_awk_nde_while_t));
nde = (xp_awk_nde_while_t*) xp_malloc (xp_sizeof(xp_awk_nde_while_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (body);
@ -2443,7 +2448,7 @@ static xp_awk_nde_t* __parse_dowhile (xp_awk_t* awk)
return XP_NULL;
}
nde = (xp_awk_nde_while_t*)xp_malloc(xp_sizeof(xp_awk_nde_while_t));
nde = (xp_awk_nde_while_t*) xp_malloc (xp_sizeof(xp_awk_nde_while_t));
if (nde == XP_NULL)
{
xp_awk_clrpt (body);
@ -2463,7 +2468,7 @@ static xp_awk_nde_t* __parse_break (xp_awk_t* awk)
{
xp_awk_nde_break_t* nde;
nde = (xp_awk_nde_break_t*)xp_malloc(xp_sizeof(xp_awk_nde_break_t));
nde = (xp_awk_nde_break_t*) xp_malloc (xp_sizeof(xp_awk_nde_break_t));
if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_BREAK;
nde->next = XP_NULL;
@ -2585,6 +2590,9 @@ static int __get_token (xp_awk_t* awk)
while (n == 1);
xp_str_clear (&awk->token.name);
awk->token.line = awk->lex.line;
awk->token.column = awk->lex.column;
c = awk->lex.curc;
if (c == XP_CHAR_EOF)
@ -3159,6 +3167,14 @@ static int __get_char (xp_awk_t* awk)
}
awk->lex.curc = awk->lex.buf[awk->lex.buf_pos++];
if (awk->lex.curc == XP_CHAR('\n'))
{
awk->lex.line++;
awk->lex.column = 1;
}
else awk->lex.column++;
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c,v 1.29 2006-05-06 12:52:36 bacon Exp $
* $Id: val.c,v 1.30 2006-05-13 16:33:07 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -182,9 +182,9 @@ void xp_awk_freeval (xp_awk_run_t* run, xp_awk_val_t* val, xp_bool_t cache)
{
if (xp_awk_isbuiltinval(val)) return;
xp_printf (XP_T("freeing [cache=%d] ... "), cache);
/*xp_printf (XP_T("freeing [cache=%d] ... "), cache);
xp_awk_printval (val);
xp_printf (XP_T("\n"));
xp_printf (XP_T("\n"));*/
switch (val->type)
{
case XP_AWK_VAL_NIL:

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.33 2006-05-13 15:51:43 bacon Exp $
* $Id: awk.c,v 1.34 2006-05-13 16:33:07 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -152,11 +152,13 @@ static int __main (int argc, xp_char_t* argv[])
{
#if defined(__STAND_ALONE) && !defined(_WIN32) && defined(XP_CHAR_IS_WCHAR)
xp_printf (
XP_T("error: cannot parse program - [%d] %ls\n"),
XP_T("error: cannot parse program - line %u [%d] %ls\n"),
(unsigned int)xp_awk_getsrcline(awk),
xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
#else
xp_printf (
XP_T("error: cannot parse program - [%d] %s\n"),
XP_T("error: cannot parse program - line %u [%d] %s\n"),
(unsigned int)xp_awk_getsrcline(awk),
xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
#endif
xp_awk_close (awk);