*** 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> #include <xp/awk/awk_i.h>
@ -25,7 +25,8 @@ xp_awk_t* xp_awk_open (void)
} }
/* TODO: initial map size?? */ /* 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_str_close (&awk->token.name);
xp_free (awk); xp_free (awk);
@ -73,10 +74,15 @@ xp_awk_t* xp_awk_open (void)
awk->tree.chain = XP_NULL; awk->tree.chain = XP_NULL;
awk->tree.chain_tail = XP_NULL; awk->tree.chain_tail = XP_NULL;
awk->token.line = 1;
awk->token.column = 1;
awk->lex.curc = XP_CHAR_EOF; awk->lex.curc = XP_CHAR_EOF;
awk->lex.ungotc_count = 0; awk->lex.ungotc_count = 0;
awk->lex.buf_pos = 0; awk->lex.buf_pos = 0;
awk->lex.buf_len = 0; awk->lex.buf_len = 0;
awk->lex.line = 1;
awk->lex.column = 1;
return awk; 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.ungotc_count = 0;
awk->lex.buf_pos = 0; awk->lex.buf_pos = 0;
awk->lex.buf_len = 0; awk->lex.buf_len = 0;
awk->lex.line = 1;
awk->lex.column = 1;
return 0; return 0;
} }
@ -190,6 +198,8 @@ int xp_awk_detsrc (xp_awk_t* awk)
awk->lex.ungotc_count = 0; awk->lex.ungotc_count = 0;
awk->lex.buf_pos = 0; awk->lex.buf_pos = 0;
awk->lex.buf_len = 0; awk->lex.buf_len = 0;
awk->lex.line = 1;
awk->lex.column = 1;
} }
return 0; return 0;
@ -205,3 +215,8 @@ static void __free_func (void* owner, void* func)
xp_awk_clrpt (f->body); xp_awk_clrpt (f->body);
xp_free (f); 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_ #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_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg);
int xp_awk_detsrc (xp_awk_t* awk); 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)??? */ /* 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_parse (xp_awk_t* awk);
int xp_awk_run (xp_awk_t* awk, xp_awk_io_t txtio, void* txtio_arg); 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_ #ifndef _XP_AWK_AWKI_H_
@ -107,6 +107,9 @@ struct xp_awk_t
xp_char_t buf[512]; xp_char_t buf[512];
xp_size_t buf_pos; xp_size_t buf_pos;
xp_size_t buf_len; xp_size_t buf_len;
xp_size_t line;
xp_size_t column;
} lex; } lex;
/* token */ /* token */
@ -114,6 +117,8 @@ struct xp_awk_t
{ {
int type; int type;
xp_str_t name; xp_str_t name;
xp_size_t line;
xp_size_t column;
} token; } token;
/* housekeeping */ /* 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> #include <xp/awk/awk_i.h>
@ -1193,7 +1193,8 @@ static xp_awk_nde_t* __parse_basic_expr (xp_awk_t* awk)
return XP_NULL; 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) if (tmp == XP_NULL)
{ {
xp_awk_clrpt (nde); 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_awk_nde_var_t* nde;
xp_size_t idxa; 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) if (nde == XP_NULL)
{ {
xp_free (name_dup); 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; 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); if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_INT; 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; 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); if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_STR; 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; if (__get_regex(awk) == -1) return XP_NULL;
xp_assert (MATCH(awk,TOKEN_REX)); 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); if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
nde->type = XP_AWK_NDE_REX; 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); prim = __parse_primary (awk);
if (prim == XP_NULL) return XP_NULL; 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) if (nde == XP_NULL)
{ {
xp_awk_clrpt (prim); xp_awk_clrpt (prim);
@ -1902,7 +1908,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
PANIC (awk, XP_AWK_EIN); 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) if (tmp == XP_NULL)
{ {
xp_awk_clrpt (nde); xp_awk_clrpt (nde);
@ -2166,8 +2173,7 @@ static xp_awk_nde_t* __parse_if (xp_awk_t* awk)
} }
else else_part = XP_NULL; else else_part = XP_NULL;
nde = (xp_awk_nde_if_t*) nde = (xp_awk_nde_if_t*) xp_malloc (xp_sizeof(xp_awk_nde_if_t));
xp_malloc (xp_sizeof(xp_awk_nde_if_t));
if (nde == XP_NULL) if (nde == XP_NULL)
{ {
xp_awk_clrpt (else_part); xp_awk_clrpt (else_part);
@ -2215,8 +2221,7 @@ static xp_awk_nde_t* __parse_while (xp_awk_t* awk)
return XP_NULL; return XP_NULL;
} }
nde = (xp_awk_nde_while_t*) nde = (xp_awk_nde_while_t*) xp_malloc (xp_sizeof(xp_awk_nde_while_t));
xp_malloc (xp_sizeof(xp_awk_nde_while_t));
if (nde == XP_NULL) if (nde == XP_NULL)
{ {
xp_awk_clrpt (body); xp_awk_clrpt (body);
@ -2585,6 +2590,9 @@ static int __get_token (xp_awk_t* awk)
while (n == 1); while (n == 1);
xp_str_clear (&awk->token.name); xp_str_clear (&awk->token.name);
awk->token.line = awk->lex.line;
awk->token.column = awk->lex.column;
c = awk->lex.curc; c = awk->lex.curc;
if (c == XP_CHAR_EOF) 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++]; 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; 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> #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; 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_awk_printval (val);
xp_printf (XP_T("\n")); xp_printf (XP_T("\n"));*/
switch (val->type) switch (val->type)
{ {
case XP_AWK_VAL_NIL: 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> #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) #if defined(__STAND_ALONE) && !defined(_WIN32) && defined(XP_CHAR_IS_WCHAR)
xp_printf ( 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)); xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
#else #else
xp_printf ( 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)); xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
#endif #endif
xp_awk_close (awk); xp_awk_close (awk);