*** empty log message ***

This commit is contained in:
hyung-hwan 2006-05-04 15:59:43 +00:00
parent ae6e9c26a9
commit e3b6a4adcc
3 changed files with 100 additions and 47 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.84 2006-05-03 15:54:20 bacon Exp $ * $Id: run.c,v 1.85 2006-05-04 15:59:43 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -138,7 +138,7 @@ static void __raw_pop_times (xp_awk_run_t* run, xp_size_t times);
static int __read_text_input (xp_awk_run_t* run); static int __read_text_input (xp_awk_run_t* run);
static int __val_to_num (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r); static int __val_to_num (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r);
static xp_char_t* __val_to_str (xp_awk_val_t* v, int* errnum); static xp_char_t* __val_to_str (xp_awk_val_t* v, int* errnum, xp_str_t* buf);
static xp_char_t* __idxnde_to_str (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_char_t* __idxnde_to_str (xp_awk_run_t* run, xp_awk_nde_t* nde);
typedef xp_awk_val_t* (*binop_func_t) ( typedef xp_awk_val_t* (*binop_func_t) (
@ -1086,7 +1086,6 @@ static xp_awk_val_t* __do_assignment_map (
xp_awk_run_t* run, xp_awk_nde_var_t* var, xp_awk_val_t* val) xp_awk_run_t* run, xp_awk_nde_var_t* var, xp_awk_val_t* val)
{ {
xp_awk_val_map_t* map; xp_awk_val_map_t* map;
xp_awk_nde_t* nde;
xp_char_t* str; xp_char_t* str;
int n; int n;
@ -2636,9 +2635,8 @@ static xp_awk_val_t* __eval_arg (xp_awk_run_t* run, xp_awk_nde_t* nde)
static xp_awk_val_t* __eval_indexed ( static xp_awk_val_t* __eval_indexed (
xp_awk_run_t* run, xp_awk_nde_var_t* nde, xp_awk_val_map_t* map) xp_awk_run_t* run, xp_awk_nde_var_t* nde, xp_awk_val_map_t* map)
{ {
xp_awk_val_t* idx, *res; xp_awk_val_t* res;
xp_awk_pair_t* pair; xp_awk_pair_t* pair;
xp_awk_nde_t* tmp;
xp_char_t* str; xp_char_t* str;
/* TODO: should it be an error? should it return nil? */ /* TODO: should it be an error? should it return nil? */
@ -2812,7 +2810,7 @@ static int __val_to_num (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r)
return -1; /* error */ return -1; /* error */
} }
static xp_char_t* __val_to_str (xp_awk_val_t* v, int* errnum) static xp_char_t* __val_to_str (xp_awk_val_t* v, int* errnum, xp_str_t* buf)
{ {
if (v->type == XP_AWK_VAL_INT) if (v->type == XP_AWK_VAL_INT)
{ {
@ -2824,33 +2822,63 @@ static xp_char_t* __val_to_str (xp_awk_val_t* v, int* errnum)
if (t == 0) if (t == 0)
{ {
/* handle zero */ /* handle zero */
tmp = xp_malloc (2 * xp_sizeof(xp_char_t)); if (buf == XP_NULL)
if (tmp == XP_NULL)
{ {
*errnum = XP_AWK_ENOMEM; tmp = xp_malloc (2 * xp_sizeof(xp_char_t));
return XP_NULL; if (tmp == XP_NULL)
} {
*errnum = XP_AWK_ENOMEM;
return XP_NULL;
}
tmp[0] = XP_CHAR('0'); tmp[0] = XP_CHAR('0');
tmp[1] = XP_CHAR('\0'); tmp[1] = XP_CHAR('\0');
return tmp; return tmp;
}
else
{
if (xp_str_cat (buf, XP_TEXT("0")) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
return XP_NULL;
}
return XP_STR_BUF(buf);
}
} }
/* non-zero values */ /* non-zero values */
if (t < 0) { t = -t; len++; } if (t < 0) { t = -t; len++; }
while (t > 0) { len++; t /= 10; } while (t > 0) { len++; t /= 10; }
tmp = xp_malloc (len + 1 * xp_sizeof(xp_char_t)); if (buf == XP_NULL)
if (tmp == XP_NULL)
{ {
*errnum = XP_AWK_ENOMEM; tmp = xp_malloc (len + 1 * xp_sizeof(xp_char_t));
return XP_NULL; if (tmp == XP_NULL)
{
*errnum = XP_AWK_ENOMEM;
return XP_NULL;
}
tmp[len] = XP_CHAR('\0');
}
else
{
/* get the current end of the buffer */
tmp = XP_STR_BUF(buf) + XP_STR_LEN(buf);
/* extend the buffer */
if (xp_str_nccat (
buf, XP_CHAR(' '), len) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
return XP_NULL;
}
} }
t = ((xp_awk_val_int_t*)v)->val; t = ((xp_awk_val_int_t*)v)->val;
if (t < 0) t = -t; if (t < 0) t = -t;
tmp[len] = XP_CHAR('\0');
while (t > 0) while (t > 0)
{ {
tmp[--len] = (xp_char_t)(t % 10) + XP_CHAR('0'); tmp[--len] = (xp_char_t)(t % 10) + XP_CHAR('0');
@ -2858,17 +2886,36 @@ static xp_char_t* __val_to_str (xp_awk_val_t* v, int* errnum)
} }
if (((xp_awk_val_int_t*)v)->val < 0) tmp[--len] = XP_CHAR('-'); if (((xp_awk_val_int_t*)v)->val < 0) tmp[--len] = XP_CHAR('-');
/*return (buf == XP_NULL) tmp: XP_STR_BUF(buf);*/
return tmp; return tmp;
} }
if (v->type == XP_AWK_VAL_STR) if (v->type == XP_AWK_VAL_STR)
{ {
xp_char_t* tmp; xp_char_t* tmp;
tmp = xp_strxdup (
((xp_awk_val_str_t*)v)->buf,
((xp_awk_val_str_t*)v)->len);
if (tmp == XP_NULL) *errnum = XP_AWK_ENOMEM; if (buf == XP_NULL)
{
tmp = xp_strxdup (
((xp_awk_val_str_t*)v)->buf,
((xp_awk_val_str_t*)v)->len);
if (tmp == XP_NULL) *errnum = XP_AWK_ENOMEM;
}
else
{
tmp = XP_STR_BUF(buf) + XP_STR_LEN(buf);
if (xp_str_ncat (buf,
((xp_awk_val_str_t*)v)->buf,
((xp_awk_val_str_t*)v)->len) == (xp_size_t)-1)
{
*errnum = XP_AWK_ENOMEM;
tmp = XP_NULL;
}
}
return tmp; return tmp;
} }
@ -2895,7 +2942,7 @@ static xp_char_t* __idxnde_to_str (xp_awk_run_t* run, xp_awk_nde_t* nde)
xp_awk_refupval (idx); xp_awk_refupval (idx);
str = __val_to_str (idx, &errnum); str = __val_to_str (idx, &errnum, XP_NULL);
if (str == XP_NULL) if (str == XP_NULL)
{ {
xp_awk_refdownval (run, idx); xp_awk_refdownval (run, idx);
@ -2925,8 +2972,16 @@ static xp_char_t* __idxnde_to_str (xp_awk_run_t* run, xp_awk_nde_t* nde)
xp_awk_refupval (idx); xp_awk_refupval (idx);
str = __val_to_str (idx, &errnum); /* TODO: configurable index seperator */
if (str == XP_NULL) if (XP_STR_LEN(&idxstr) > 0 &&
xp_str_cat (&idxstr, XP_TEXT(",")) == (xp_size_t)-1)
{
xp_awk_refdownval (run, idx);
xp_str_close (&idxstr);
PANIC (run, XP_AWK_ENOMEM);
}
if (__val_to_str (idx, &errnum, &idxstr) == XP_NULL)
{ {
xp_awk_refdownval (run, idx); xp_awk_refdownval (run, idx);
xp_str_close (&idxstr); xp_str_close (&idxstr);
@ -2934,25 +2989,6 @@ static xp_char_t* __idxnde_to_str (xp_awk_run_t* run, xp_awk_nde_t* nde)
} }
xp_awk_refdownval (run, idx); xp_awk_refdownval (run, idx);
/* TODO: configurable index seperator */
if (XP_STR_LEN(&idxstr) > 0 &&
xp_str_cat (&idxstr, XP_TEXT(",")) == (xp_size_t)-1)
{
xp_free (str);
xp_str_close (&idxstr);
PANIC (run, XP_AWK_ENOMEM);
}
if (xp_str_cat (&idxstr, str) == (xp_size_t)-1)
{
xp_free (str);
xp_str_close (&idxstr);
PANIC (run, XP_AWK_ENOMEM);
}
xp_free (str);
nde = nde->next; nde = nde->next;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: sa.c,v 1.19 2006-04-30 18:05:07 bacon Exp $ * $Id: sa.c,v 1.20 2006-05-04 15:59:43 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -225,6 +225,20 @@ xp_size_t xp_str_ccat (xp_str_t* str, xp_char_t c)
return xp_str_ncat (str, &c, 1); return xp_str_ncat (str, &c, 1);
} }
xp_size_t xp_str_nccat (xp_str_t* str, xp_char_t c, xp_size_t len)
{
while (len > 0)
{
if (xp_str_ncat (str, &c, 1) == (xp_size_t)-1)
{
return (xp_size_t)-1;
}
len--;
}
return str->size;
}
void xp_str_clear (xp_str_t* str) void xp_str_clear (xp_str_t* str)
{ {
str->size = 0; str->size = 0;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: sa.h,v 1.22 2006-04-16 04:31:38 bacon Exp $ * $Id: sa.h,v 1.23 2006-05-04 15:59:43 bacon Exp $
*/ */
#ifndef _XP_AWK_SA_H_ #ifndef _XP_AWK_SA_H_
@ -141,6 +141,9 @@ xp_size_t xp_str_ncat (xp_str_t* str, const xp_char_t* s, xp_size_t len);
#define xp_str_ccat xp_awk_str_ccat #define xp_str_ccat xp_awk_str_ccat
xp_size_t xp_str_ccat (xp_str_t* str, xp_char_t c); xp_size_t xp_str_ccat (xp_str_t* str, xp_char_t c);
#define xp_str_nccat xp_awk_str_nccat
xp_size_t xp_str_nccat (xp_str_t* str, xp_char_t c, xp_size_t len);
#define xp_str_clear xp_awk_str_clear #define xp_str_clear xp_awk_str_clear
void xp_str_clear (xp_str_t* str); void xp_str_clear (xp_str_t* str);