*** empty log message ***

This commit is contained in:
hyung-hwan 2006-07-17 04:17:40 +00:00
parent bc06fd0557
commit 3ffaab0599
12 changed files with 220 additions and 119 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk_i.h,v 1.30 2006-07-13 15:43:39 bacon Exp $
* $Id: awk_i.h,v 1.31 2006-07-17 04:17:40 bacon Exp $
*/
#ifndef _XP_AWK_AWKI_H_
@ -24,6 +24,7 @@ typedef struct xp_awk_tree_t xp_awk_tree_t;
#include <xp/awk/tab.h>
#include <xp/awk/run.h>
#include <xp/awk/extio.h>
#include <xp/awk/rex.h>
#ifdef _WIN32
#pragma warning (disable: 4996)

View File

@ -1,5 +1,5 @@
/*
* $Id: func.c,v 1.10 2006-07-14 05:21:30 bacon Exp $
* $Id: func.c,v 1.11 2006-07-17 04:17:40 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -11,13 +11,27 @@
#include <xp/bas/str.h>
#endif
#ifdef _WIN32
#include <tchar.h>
#include <math.h>
#else
#include <stdlib.h>
#endif
static int __bfn_close (void* run);
static int __bfn_system (void* run);
static int __bfn_sin (void* run);
/* TODO: move it under the awk structure... */
static xp_awk_bfn_t __sys_bfn[] =
{
{ XP_T("system"), (1 << 5), 1, 1, XP_NULL },
/* ensure that this matches XP_AWK_BNF_XXX in func.h */
{ XP_T("close"), XP_AWK_EXTIO, 1, 1, __bfn_close },
{ XP_T("system"), 0, 1, 1, __bfn_system },
{ XP_T("sin"), 0, 1, 1, __bfn_sin },
{ XP_NULL, 0, 0, 0, XP_NULL }
};
@ -151,3 +165,74 @@ static int __bfn_close (void* run)
xp_awk_setretval (run, v);
return 0;
}
static int __bfn_system (void* run)
{
xp_size_t nargs;
xp_char_t* cmd;
xp_awk_val_t* v;
int errnum, n;
nargs = xp_awk_getnargs (run);
xp_assert (nargs == 1);
cmd = xp_awk_valtostr (
xp_awk_getarg(run, 0), &errnum, XP_NULL, XP_NULL);
if (cmd == XP_NULL)
{
xp_awk_seterrnum (run, XP_AWK_ENOMEM);
return -1;
}
#ifdef _WIN32
n = _tsystem (cmd);
#else
#error NOT SUPPORTED ...
#endif
xp_free (cmd);
v = xp_awk_makeintval (run, n);
if (v == XP_NULL)
{
xp_awk_seterrnum (run, XP_AWK_ENOMEM);
return -1;
}
xp_awk_setretval (run, v);
return 0;
}
/* math functions */
static int __bfn_sin (void* run)
{
xp_size_t nargs;
xp_awk_val_t* v;
int n;
xp_long_t lv;
xp_real_t rv;
nargs = xp_awk_getnargs (run);
xp_assert (nargs == 1);
n = xp_awk_valtonum (
xp_awk_getarg(run, 0), &lv, &rv);
if (n == -1)
{
/* wrong value */
xp_awk_seterrnum (run, XP_AWK_EVALTYPE);
return -1;
}
if (n == 0) rv = (xp_real_t)lv;
v = xp_awk_makerealval (run, sin(rv));
if (v == XP_NULL)
{
xp_awk_seterrnum (run, XP_AWK_ENOMEM);
return -1;
}
xp_awk_setretval (run, v);
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: func.h,v 1.6 2006-07-14 05:21:30 bacon Exp $
* $Id: func.h,v 1.7 2006-07-17 04:17:40 bacon Exp $
*/
#ifndef _XP_AWK_FUNC_H_
@ -23,6 +23,17 @@ struct xp_awk_bfn_t
xp_awk_bfn_t* next;
};
enum
{
/* ensure that this matches __sys_bfn in func.c */
XP_AWK_BFN_CLOSE,
XP_AWK_BFN_SYSTEM,
XP_AWK_BFN_SIN
};
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -1,4 +1,4 @@
SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c func.c misc.c extio.c
SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c func.c misc.c extio.c rex.c
OBJS = $(SRCS:.c=.obj)
OUT = xpawk

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.137 2006-07-14 05:21:30 bacon Exp $
* $Id: parse.c,v 1.138 2006-07-17 04:17:40 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -3748,7 +3748,7 @@ 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'))
if (awk->lex.curc == XP_T('\n'))
{
awk->lex.line++;
awk->lex.column = 1;
@ -3787,7 +3787,7 @@ static int __skip_comment (xp_awk_t* awk)
{
GET_CHAR_TO (awk, c);
}
while (c != '\n' && c != XP_CHAR_EOF);
while (c != XP_T('\n') && c != XP_CHAR_EOF);
GET_CHAR (awk);
return 1; /* comment by # */
@ -3802,7 +3802,7 @@ static int __skip_comment (xp_awk_t* awk)
{
GET_CHAR_TO (awk, c);
}
while (c != '\n' && c != XP_CHAR_EOF);
while (c != XP_T('\n') && c != XP_CHAR_EOF);
GET_CHAR (awk);
return 1; /* comment by // */

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.134 2006-07-14 04:19:21 bacon Exp $
* $Id: run.c,v 1.135 2006-07-17 04:17:40 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -164,7 +164,6 @@ 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);
typedef xp_awk_val_t* (*binop_func_t) (
@ -612,7 +611,7 @@ static int __run_pattern_block_chain (xp_awk_run_t* run, xp_awk_chain_t* chain)
xp_assert (ptn->next->next == XP_NULL);
/* TODO: implement this */
xp_awk_refdownval (run, v1);
xp_printf (XP_TEXT("ERROR: pattern, pattern NOT OMPLEMENTED\n"));
xp_printf (XP_T("ERROR: pattern, pattern NOT OMPLEMENTED\n"));
PANIC_I (run, XP_AWK_EINTERNAL);
}
}
@ -1750,7 +1749,7 @@ static xp_awk_val_t* __do_assignment_pos (
if (v == XP_NULL) return XP_NULL;
xp_awk_refupval (v);
n = __val_to_num (v, &lv, &rv);
n = xp_awk_valtonum (v, &lv, &rv);
xp_awk_refdownval (run, v);
if (n == -1) PANIC (run, XP_AWK_EPOSIDX);
@ -2444,8 +2443,8 @@ static xp_awk_val_t* __eval_binop_lshift (
xp_real_t r1, r2;
xp_awk_val_t* res;
n1 = __val_to_num (left, &l1, &r1);
n2 = __val_to_num (right, &l2, &r2);
n1 = xp_awk_valtonum (left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -2469,8 +2468,8 @@ static xp_awk_val_t* __eval_binop_rshift (
xp_real_t r1, r2;
xp_awk_val_t* res;
n1 = __val_to_num (left, &l1, &r1);
n2 = __val_to_num (right, &l2, &r2);
n1 = xp_awk_valtonum (left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -2494,8 +2493,8 @@ static xp_awk_val_t* __eval_binop_plus (
xp_real_t r1, r2;
xp_awk_val_t* res;
n1 = __val_to_num (left, &l1, &r1);
n2 = __val_to_num (right, &l2, &r2);
n1 = xp_awk_valtonum (left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
/*
@ -2524,8 +2523,8 @@ static xp_awk_val_t* __eval_binop_minus (
xp_real_t r1, r2;
xp_awk_val_t* res;
n1 = __val_to_num (left, &l1, &r1);
n2 = __val_to_num (right, &l2, &r2);
n1 = xp_awk_valtonum (left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -2548,8 +2547,8 @@ static xp_awk_val_t* __eval_binop_mul (
xp_real_t r1, r2;
xp_awk_val_t* res;
n1 = __val_to_num (left, &l1, &r1);
n2 = __val_to_num (right, &l2, &r2);
n1 = xp_awk_valtonum (left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -2572,8 +2571,8 @@ static xp_awk_val_t* __eval_binop_div (
xp_real_t r1, r2;
xp_awk_val_t* res;
n1 = __val_to_num (left, &l1, &r1);
n2 = __val_to_num (right, &l2, &r2);
n1 = xp_awk_valtonum (left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -2609,8 +2608,8 @@ static xp_awk_val_t* __eval_binop_mod (
xp_real_t r1, r2;
xp_awk_val_t* res;
n1 = __val_to_num (left, &l1, &r1);
n2 = __val_to_num (right, &l2, &r2);
n1 = xp_awk_valtonum (left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -2634,8 +2633,8 @@ static xp_awk_val_t* __eval_binop_exp (
xp_real_t r1, r2;
xp_awk_val_t* res;
n1 = __val_to_num (left, &l1, &r1);
n2 = __val_to_num (right, &l2, &r2);
n1 = xp_awk_valtonum (left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -3450,7 +3449,7 @@ static xp_awk_val_t* __eval_pos (xp_awk_run_t* run, xp_awk_nde_t* nde)
if (v == XP_NULL) return XP_NULL;
xp_awk_refupval (v);
n = __val_to_num (v, &lv, &rv);
n = xp_awk_valtonum (v, &lv, &rv);
xp_awk_refdownval (run, v);
if (n == -1) PANIC (run, XP_AWK_EPOSIDX);
@ -3913,47 +3912,6 @@ static int __recomp_record_fields (xp_awk_run_t* run,
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)
{
*l = 0;
return 0;
}
if (v->type == XP_AWK_VAL_INT)
{
*l = ((xp_awk_val_int_t*)v)->val;
return 0; /* long */
}
if (v->type == XP_AWK_VAL_REAL)
{
*r = ((xp_awk_val_real_t*)v)->val;
return 1; /* real */
}
if (v->type == XP_AWK_VAL_STR)
{
const xp_char_t* endptr;
/* don't care about val->len */
*l = xp_awk_strtolong (((xp_awk_val_str_t*)v)->buf, 0, &endptr);
if (*endptr == XP_T('.') ||
*endptr == XP_T('E') ||
*endptr == XP_T('e'))
{
*r = xp_awk_strtoreal (((xp_awk_val_str_t*)v)->buf);
return 1; /* real */
}
return 0; /* long */
}
return -1; /* error */
}
static xp_char_t* __idxnde_to_str (xp_awk_run_t* run, xp_awk_nde_t* nde)
{
xp_char_t* str;

View File

@ -1,5 +1,5 @@
/*
* $Id: sa.c,v 1.27 2006-07-07 09:48:23 bacon Exp $
* $Id: sa.c,v 1.28 2006-07-17 04:17:40 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -355,7 +355,7 @@ xp_size_t xp_str_ncpy (xp_str_t* str, const xp_char_t* s, xp_size_t len)
}
str->size = xp_strncpy (str->buf, s, len);
str->buf[str->size] = XP_CHAR('\0');
str->buf[str->size] = XP_T('\0');
return str->size;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c,v 1.41 2006-07-13 03:10:35 bacon Exp $
* $Id: val.c,v 1.42 2006-07-17 04:17:40 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -425,6 +425,11 @@ xp_char_t* xp_awk_valtostr (
return tmp;
}
/* TODO:
if (v->type == XP_AWK_VAL_REAL)
{
}*/
if (v->type == XP_AWK_VAL_STR)
{
xp_char_t* tmp;
@ -457,11 +462,53 @@ xp_char_t* xp_awk_valtostr (
/* TODO: process more value types */
xp_printf (XP_TEXT("*** ERROR: WRONG VALUE TYPE [%d] in xp_awk_valtostr v=> %p***\n"), v->type, v);
xp_printf (XP_T("*** ERROR: WRONG VALUE TYPE [%d] in xp_awk_valtostr v=> %p***\n"), v->type, v);
*errnum = XP_AWK_EVALTYPE;
return XP_NULL;
}
int xp_awk_valtonum (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r)
{
if (v->type == XP_AWK_VAL_NIL)
{
*l = 0;
return 0;
}
if (v->type == XP_AWK_VAL_INT)
{
*l = ((xp_awk_val_int_t*)v)->val;
return 0; /* long */
}
if (v->type == XP_AWK_VAL_REAL)
{
*r = ((xp_awk_val_real_t*)v)->val;
return 1; /* real */
}
if (v->type == XP_AWK_VAL_STR)
{
const xp_char_t* endptr;
/* don't care about val->len */
*l = xp_awk_strtolong (((xp_awk_val_str_t*)v)->buf, 0, &endptr);
if (*endptr == XP_T('.') ||
*endptr == XP_T('E') ||
*endptr == XP_T('e'))
{
*r = xp_awk_strtoreal (((xp_awk_val_str_t*)v)->buf);
return 1; /* real */
}
return 0; /* long */
}
xp_printf (XP_T("*** ERROR: WRONG VALUE TYPE [%d] in xp_awk_valtostr v=> %p***\n"), v->type, v);
return -1; /* error */
}
static int __print_pair (xp_awk_pair_t* pair, void* arg)
{
xp_printf (XP_T(" %s=>"), pair->key);

View File

@ -1,5 +1,5 @@
/*
* $Id: val.h,v 1.30 2006-07-13 03:10:35 bacon Exp $
* $Id: val.h,v 1.31 2006-07-17 04:17:40 bacon Exp $
*/
#ifndef _XP_AWK_VAL_H_
@ -117,6 +117,7 @@ void xp_awk_refdownval_nofree (xp_awk_run_t* run, xp_awk_val_t* val);
xp_bool_t xp_awk_valtobool (xp_awk_val_t* val);
xp_char_t* xp_awk_valtostr (
xp_awk_val_t* val, int* errnum, xp_str_t* buf, xp_size_t* len);
int xp_awk_valtonum (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r);
void xp_awk_printval (xp_awk_val_t* val);

View File

@ -1,5 +1,5 @@
/*
* $Id: macros.h,v 1.34 2006-06-23 11:50:34 bacon Exp $
* $Id: macros.h,v 1.35 2006-07-17 04:17:39 bacon Exp $
*/
#ifndef _XP_MACROS_H_
@ -60,12 +60,14 @@
} while (0);
/* obsolete */
#define XP_MQUOTE(val) #val
#define XP_MQUOTE_I(val) #val
#define XP_MQUOTE(val) XP_MQUOTE_I(val)
#define XP_MCHAR(ch) ((xp_mchar_t)ch)
#define XP_MTEXT(txt) ((const xp_mchar_t*)txt)
/* new short form */
#define XP_MQ(val) #val
#define XP_MQ_I(val) #val
#define XP_MQ(val) XP_MQ_I(val)
#define XP_MC(ch) ((xp_mchar_t)ch)
#define XP_MS(str) ((const xp_mchar_t*)str)
#define XP_MT(txt) (txt)
@ -77,12 +79,14 @@
*/
/* obsolete */
#define XP_WQUOTE(val) ((const xp_char_t*)L###val)
#define XP_WQUOTE_I(val) (L###val)
#define XP_WQUOTE(val) XP_WQUOTE_I(val)
#define XP_WCHAR(ch) ((xp_wchar_t)L##ch)
#define XP_WTEXT(txt) ((const xp_wchar_t*)L##txt)
/* new short form */
#define XP_WQ(val) ((const xp_char_t*)L###val)
#define XP_WQ_I(val) (L###val)
#define XP_WQ(val) XP_WQ_I(val)
#define XP_WC(ch) ((xp_wchar_t)L##ch)
#define XP_WS(str) ((const xp_wchar_t*)L##str)
#define XP_WT(txt) (L##txt)

View File

@ -21,3 +21,5 @@ global x, y;
print "NF ===>>> " NF;
print "====================";
}
END { system ("dir /w/p"); print sin(10); }

View File

@ -1,5 +1,5 @@
/*
* $Id: types.h,v 1.49 2006-06-09 06:17:24 bacon Exp $
* $Id: types.h,v 1.50 2006-07-17 04:17:40 bacon Exp $
*/
#ifndef _XP_TYPES_H_
@ -77,17 +77,9 @@
*/
/* boolean type */
/*
#ifdef __cplusplus
typedef bool xp_bool_t;
#define xp_true true
#define xp_false false
#else
*/
typedef int xp_bool_t;
#define xp_true (0 == 0)
#define xp_false (0 != 0)
/*#endif*/
typedef int xp_bool_t;
#define xp_true (0 == 0)
#define xp_false (0 != 0)
/* tri-state type */
typedef int xp_tri_t;