*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-06 16:25:37 +00:00
parent abc5ea4502
commit 11c34a6b0e
8 changed files with 386 additions and 81 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h,v 1.42 2006-04-05 15:56:20 bacon Exp $
* $Id: awk.h,v 1.43 2006-04-06 16:25:37 bacon Exp $
*/
#ifndef _XP_AWK_AWK_H_
@ -66,7 +66,8 @@ enum
XP_AWK_ELVALUE, /* l-value required */
/* run time error */
XP_AWK_EDIVBYZERO /* divide by zero */
XP_AWK_EDIVBYZERO, /* divide by zero */
XP_AWK_EOPERAND /* invalid operand */
};
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/*
* $Id: err.c,v 1.4 2006-04-05 15:56:20 bacon Exp $
* $Id: err.c,v 1.5 2006-04-06 16:25:37 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -40,7 +40,8 @@ const xp_char_t* xp_awk_geterrstr (xp_awk_t* awk)
XP_TEXT("undefined identifier"),
XP_TEXT("l-value required"),
XP_TEXT("divide by zero")
XP_TEXT("divide by zero"),
XP_TEXT("invalid operand")
};
if (awk->errnum >= 0 && awk->errnum < xp_countof(__errstr)) {

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.35 2006-04-05 15:56:20 bacon Exp $
* $Id: run.c,v 1.36 2006-04-06 16:25:37 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -104,6 +104,7 @@ int __printval (xp_awk_pair_t* pair)
int xp_awk_run (xp_awk_t* awk)
{
xp_size_t nglobals;
int n = 0;
// TODO: clear run stack/exit_level
awk->run.exit_level = EXIT_NONE;
@ -122,29 +123,39 @@ int xp_awk_run (xp_awk_t* awk)
}
}
if (awk->tree.begin != XP_NULL)
if (n == 0 && awk->tree.begin != XP_NULL)
{
xp_assert (awk->tree.begin->type == XP_AWK_NDE_BLK);
if (__run_block (awk,
(xp_awk_nde_blk_t*)awk->tree.begin) == -1) return -1;
(xp_awk_nde_blk_t*)awk->tree.begin) == -1) n = -1;
}
if (awk->tree.end != XP_NULL)
if (n == 0 && awk->tree.end != XP_NULL)
{
xp_assert (awk->tree.end->type == XP_AWK_NDE_BLK);
if (__run_block (awk,
(xp_awk_nde_blk_t*)awk->tree.end) == -1) return -1;
(xp_awk_nde_blk_t*)awk->tree.end) == -1) n = -1;
}
xp_printf (XP_TEXT("---------------------------\n"));
nglobals = awk->tree.nglobals;
while (nglobals > 0)
{
--nglobals;
xp_awk_refdownval (awk, STACK_GLOBAL(awk,nglobals));
__raw_pop (awk);
}
xp_printf (XP_TEXT("-BEGIN------------------------\n"));
xp_awk_map_walk (&awk->run.named, __printval);
return 0;
xp_printf (XP_TEXT("-END--------------------------\n"));
return n;
}
static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde)
{
xp_awk_nde_t* p;
xp_size_t nlocals;
int n = 0;
xp_assert (nde->type == XP_AWK_NDE_BLK);
@ -168,7 +179,11 @@ static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde)
//xp_printf (XP_TEXT("executing block statements\n"));
while (p != XP_NULL && awk->run.exit_level == EXIT_NONE)
{
if (__run_statement(awk,p) == -1) return -1;
if (__run_statement(awk,p) == -1)
{
n = -1;
break;
}
p = p->next;
}
@ -182,7 +197,7 @@ static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde)
__raw_pop (awk);
}
return 0;
return n;
}
static int __run_statement (xp_awk_t* awk, xp_awk_nde_t* nde)
@ -812,17 +827,48 @@ static xp_awk_val_t* __eval_binop_eq (
xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right)
{
xp_awk_val_t* res = XP_NULL;
xp_long_t r = 0;
if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_INT)
{
xp_long_t r =
((xp_awk_val_int_t*)left)->val ==
r = ((xp_awk_val_int_t*)left)->val ==
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_real_t*)left)->val ==
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_int_t*)left)->val ==
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_INT)
{
r = ((xp_awk_val_real_t*)left)->val ==
((xp_awk_val_int_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR)
{
r = xp_strxncmp (
((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf,
((xp_awk_val_str_t*)right)->len) == 0;
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
res = xp_awk_makeintval (awk, r);
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -830,17 +876,48 @@ static xp_awk_val_t* __eval_binop_ne (
xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right)
{
xp_awk_val_t* res = XP_NULL;
xp_long_t r = 0;
if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_INT)
{
xp_long_t r =
((xp_awk_val_int_t*)left)->val !=
r = ((xp_awk_val_int_t*)left)->val !=
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_real_t*)left)->val !=
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_int_t*)left)->val !=
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_INT)
{
r = ((xp_awk_val_real_t*)left)->val !=
((xp_awk_val_int_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR)
{
r = xp_strxncmp (
((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf,
((xp_awk_val_str_t*)right)->len) != 0;
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
res = xp_awk_makeintval (awk, r);
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -848,17 +925,48 @@ static xp_awk_val_t* __eval_binop_gt (
xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right)
{
xp_awk_val_t* res = XP_NULL;
xp_long_t r = 0;
if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_INT)
{
xp_long_t r =
((xp_awk_val_int_t*)left)->val >
r = ((xp_awk_val_int_t*)left)->val >
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_real_t*)left)->val >
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_int_t*)left)->val >
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_INT)
{
r = ((xp_awk_val_real_t*)left)->val >
((xp_awk_val_int_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR)
{
r = xp_strxncmp (
((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf,
((xp_awk_val_str_t*)right)->len) > 0;
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
res = xp_awk_makeintval (awk, r);
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -866,17 +974,48 @@ static xp_awk_val_t* __eval_binop_ge (
xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right)
{
xp_awk_val_t* res = XP_NULL;
xp_long_t r = 0;
if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_INT)
{
xp_long_t r =
((xp_awk_val_int_t*)left)->val >=
r = ((xp_awk_val_int_t*)left)->val >=
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_real_t*)left)->val >=
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_int_t*)left)->val >=
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_INT)
{
r = ((xp_awk_val_real_t*)left)->val >=
((xp_awk_val_int_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR)
{
r = xp_strxncmp (
((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf,
((xp_awk_val_str_t*)right)->len) >= 0;
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
res = xp_awk_makeintval (awk, r);
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -884,17 +1023,48 @@ static xp_awk_val_t* __eval_binop_lt (
xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right)
{
xp_awk_val_t* res = XP_NULL;
xp_long_t r = 0;
if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_INT)
{
xp_long_t r =
((xp_awk_val_int_t*)left)->val <
r = ((xp_awk_val_int_t*)left)->val <
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_real_t*)left)->val <
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_int_t*)left)->val <
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_INT)
{
r = ((xp_awk_val_real_t*)left)->val <
((xp_awk_val_int_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR)
{
r = xp_strxncmp (
((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf,
((xp_awk_val_str_t*)right)->len) < 0;
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
res = xp_awk_makeintval (awk, r);
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -902,17 +1072,48 @@ static xp_awk_val_t* __eval_binop_le (
xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right)
{
xp_awk_val_t* res = XP_NULL;
xp_long_t r = 0;
if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_INT)
{
xp_long_t r =
((xp_awk_val_int_t*)left)->val <=
r = ((xp_awk_val_int_t*)left)->val <=
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_real_t*)left)->val <=
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_REAL)
{
r = ((xp_awk_val_int_t*)left)->val <=
((xp_awk_val_real_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_INT)
{
r = ((xp_awk_val_real_t*)left)->val <=
((xp_awk_val_int_t*)right)->val;
}
else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR)
{
r = xp_strxncmp (
((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf,
((xp_awk_val_str_t*)right)->len) <= 0;
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
res = xp_awk_makeintval (awk, r);
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -928,9 +1129,13 @@ static xp_awk_val_t* __eval_binop_lshift (
((xp_awk_val_int_t*)left)->val <<
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -946,9 +1151,13 @@ static xp_awk_val_t* __eval_binop_rshift (
((xp_awk_val_int_t*)left)->val >>
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -964,7 +1173,6 @@ static xp_awk_val_t* __eval_binop_plus (
((xp_awk_val_int_t*)left)->val +
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL)
@ -990,11 +1198,22 @@ static xp_awk_val_t* __eval_binop_plus (
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makerealval (awk, r);
}
else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR)
{
res = xp_awk_makestrval2 (
((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf,
((xp_awk_val_str_t*)right)->len);
}
else
{
/* TODO: trigger error */
PANIC (awk, XP_AWK_EOPERAND);
}
// TODO: addition between integer and astring??? 1 + "123"
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -1010,7 +1229,6 @@ static xp_awk_val_t* __eval_binop_minus (
((xp_awk_val_int_t*)left)->val -
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL)
@ -1038,9 +1256,10 @@ static xp_awk_val_t* __eval_binop_minus (
}
else
{
/* TODO: trigger error */
PANIC (awk, XP_AWK_EOPERAND);
}
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -1052,13 +1271,42 @@ static xp_awk_val_t* __eval_binop_mul (
if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_INT)
{
xp_long_t r =
((xp_awk_val_int_t*)left)->val *
xp_long_t r;
r = ((xp_awk_val_int_t*)left)->val *
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL)
{
xp_real_t r;
r = ((xp_awk_val_real_t*)left)->val *
((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, r);
}
else if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_REAL)
{
xp_real_t r;
r = ((xp_awk_val_int_t*)left)->val *
((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, r);
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_INT)
{
xp_real_t r;
r = ((xp_awk_val_real_t*)left)->val *
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makerealval (awk, r);
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -1080,23 +1328,19 @@ static xp_awk_val_t* __eval_binop_div (
r = ((xp_awk_val_int_t*)left)->val /
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL)
{
xp_real_t r;
r = ((xp_awk_val_real_t*)left)->val /
((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, r);
// TOOD: error handling
}
else if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_REAL)
{
xp_real_t r;
r = ((xp_awk_val_int_t*)left)->val /
((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, r);
@ -1105,16 +1349,16 @@ static xp_awk_val_t* __eval_binop_div (
right->type == XP_AWK_VAL_INT)
{
xp_real_t r;
r = ((xp_awk_val_real_t*)left)->val /
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makerealval (awk, r);
}
else
{
// TODO: invalid operands for div
PANIC (awk, XP_AWK_EOPERAND);
}
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
@ -1136,13 +1380,13 @@ static xp_awk_val_t* __eval_binop_mod (
r = ((xp_awk_val_int_t*)left)->val %
((xp_awk_val_int_t*)right)->val;
res = xp_awk_makeintval (awk, r);
// TOOD: error handling
}
else
{
// TODO: mod is only for integers
PANIC (awk, XP_AWK_EOPERAND);
}
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: sa.c,v 1.14 2006-04-04 16:03:14 bacon Exp $
* $Id: sa.c,v 1.15 2006-04-06 16:25:37 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -34,7 +34,22 @@ xp_char_t* xp_strxdup (const xp_char_t* str, xp_size_t len)
tmp = (xp_char_t*) xp_malloc ((len + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) return XP_NULL;
xp_strxncpy (tmp, len + 1, str, len);
xp_strncpy (tmp, str, len);
return tmp;
}
xp_char_t* xp_strxdup2 (
const xp_char_t* str1, xp_size_t len1,
const xp_char_t* str2, xp_size_t len2)
{
xp_char_t* tmp;
tmp = (xp_char_t*) xp_malloc (
(len1 + len2 + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) return XP_NULL;
xp_strncpy (tmp, str1, len1);
xp_strncpy (tmp + len1, str2, len2);
return tmp;
}
@ -45,17 +60,12 @@ xp_size_t xp_strcpy (xp_char_t* buf, const xp_char_t* str)
return buf - org - 1;
}
xp_size_t xp_strxncpy (
xp_char_t* buf, xp_size_t bsz, const xp_char_t* str, xp_size_t len)
xp_size_t xp_strncpy (xp_char_t* buf, const xp_char_t* str, xp_size_t len)
{
xp_size_t n;
if (bsz <= 0) return 0;
if ((n = bsz - 1) > len) n = len;
xp_memcpy (buf, str, n * xp_sizeof(xp_char_t));
buf[n] = XP_CHAR('\0');
return n;
const xp_char_t* end = str + len;
while (str < end) *buf++ = *str++;
*buf = XP_CHAR('\0');
return len;
}
int xp_strcmp (const xp_char_t* s1, const xp_char_t* s2)
@ -66,6 +76,21 @@ int xp_strcmp (const xp_char_t* s1, const xp_char_t* s2)
return 0;
}
int xp_strxncmp (
const xp_char_t* s1, xp_size_t len1,
const xp_char_t* s2, xp_size_t len2)
{
const xp_char_t* end1 = s1 + len1;
const xp_char_t* end2 = s2 + len2;
while (s1 < end1 && s2 < end2 && *s1 == *s2) {
s1++; s2++;
}
if (s1 == end1 && s2 == end2) return 0;
if (*s1 == *s2) return (s1 < end1)? 1: -1;
return (*s1 > *s2)? 1: -1;
}
int xp_printf (const xp_char_t* fmt, ...)
{
int n;

View File

@ -1,5 +1,5 @@
/*
* $Id: sa.h,v 1.19 2006-04-04 16:03:14 bacon Exp $
* $Id: sa.h,v 1.20 2006-04-06 16:25:37 bacon Exp $
*/
#ifndef _XP_AWK_SA_H_
@ -89,16 +89,25 @@ xp_char_t* xp_strdup (const xp_char_t* str);
#define xp_strxdup xp_awk_strxdup
xp_char_t* xp_strxdup (const xp_char_t* str, xp_size_t len);
#define xp_strxdup2 xp_awk_strxdup2
xp_char_t* xp_strxdup2 (
const xp_char_t* str1, xp_size_t len1,
const xp_char_t* str2, xp_size_t len2);
#define xp_strcpy xp_awk_strcpy
xp_size_t xp_strcpy (xp_char_t* buf, const xp_char_t* str);
#define xp_strxncpy xp_awk_strxncpy
xp_size_t xp_strxncpy (
xp_char_t* buf, xp_size_t bsz, const xp_char_t* str, xp_size_t len);
#define xp_strncpy xp_awk_strncpy
xp_size_t xp_strncpy (xp_char_t* buf, const xp_char_t* str, xp_size_t len);
#define xp_strcmp xp_awk_strcmp
int xp_strcmp (const xp_char_t* s1, const xp_char_t* s2);
#define xp_strxncmp xp_awk_strxncmp
int xp_strxncmp (
const xp_char_t* s1, xp_size_t len1,
const xp_char_t* s2, xp_size_t len2);
#define xp_printf xp_awk_printf
int xp_printf (const xp_char_t* fmt, ...);

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c,v 1.15 2006-04-04 16:50:36 bacon Exp $
* $Id: val.c,v 1.16 2006-04-06 16:25:37 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -97,6 +97,27 @@ xp_awk_val_t* xp_awk_makestrval (const xp_char_t* str, xp_size_t len)
return (xp_awk_val_t*)val;
}
xp_awk_val_t* xp_awk_makestrval2 (
const xp_char_t* str1, xp_size_t len1,
const xp_char_t* str2, xp_size_t len2)
{
xp_awk_val_str_t* val;
val = (xp_awk_val_str_t*)xp_malloc(xp_sizeof(xp_awk_val_str_t));
if (val == XP_NULL) return XP_NULL;
val->type = XP_AWK_VAL_STR;
val->ref = 0;
val->len = len1 + len2;
val->buf = xp_strxdup2 (str1, len1, str2, len2);
if (val->buf == XP_NULL) {
xp_free (val);
return XP_NULL;
}
return (xp_awk_val_t*)val;
}
xp_bool_t xp_awk_isbuiltinval (xp_awk_val_t* val)
{
return val == XP_NULL || val == xp_awk_val_nil ||

View File

@ -1,5 +1,5 @@
/*
* $Id: val.h,v 1.12 2006-03-28 16:33:09 bacon Exp $
* $Id: val.h,v 1.13 2006-04-06 16:25:37 bacon Exp $
*/
#ifndef _XP_AWK_VAL_H_
@ -78,6 +78,9 @@ extern xp_awk_val_t* xp_awk_val_nil;
xp_awk_val_t* xp_awk_makeintval (xp_awk_t* awk, xp_long_t v);
xp_awk_val_t* xp_awk_makerealval (xp_awk_t* awk, xp_real_t v);
xp_awk_val_t* xp_awk_makestrval (const xp_char_t* str, xp_size_t len);
xp_awk_val_t* xp_awk_makestrval2 (
const xp_char_t* str1, xp_size_t len1,
const xp_char_t* str2, xp_size_t len2);
//xp_awk_val_t* xp_awk_makemapval ();
xp_bool_t xp_awk_isbuiltinval (xp_awk_val_t* val);

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.15 2006-03-31 18:09:26 bacon Exp $
* $Id: awk.c,v 1.16 2006-04-06 16:25:37 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -72,7 +72,7 @@ int xp_main (int argc, char* argv[])
xp_awk_setparseopt (awk,
XP_AWK_EXPLICIT | XP_AWK_UNIQUE |
XP_AWK_SHADING | XP_AWK_IMPLICIT);
XP_AWK_SHADING | XP_AWK_IMPLICIT | XP_AWK_SHIFT);
if (xp_awk_parse(awk) == -1) {
xp_printf (
@ -87,6 +87,7 @@ int xp_main (int argc, char* argv[])
XP_TEXT("error: cannot run program - [%d] %s\n"),
xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
xp_awk_close (awk);
return -1;
}
xp_awk_close (awk);