*** empty log message ***
This commit is contained in:
parent
b6c7322571
commit
bf8c125f71
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: extio.c,v 1.18 2006-07-13 03:10:34 bacon Exp $
|
||||
* $Id: extio.c,v 1.19 2006-07-14 04:19:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -12,12 +12,14 @@
|
||||
|
||||
enum
|
||||
{
|
||||
__MASK_READ = 0x01FF,
|
||||
__MASK_WRITE = 0x02FF,
|
||||
__MASK_RDWR = 0x04FF,
|
||||
__MASK_CLEAR = 0x00FF
|
||||
__MASK_READ = 0x0100,
|
||||
__MASK_WRITE = 0x0200,
|
||||
__MASK_RDWR = 0x0400,
|
||||
|
||||
__MASK_CLEAR = 0x00FF
|
||||
};
|
||||
|
||||
|
||||
int xp_awk_readextio (
|
||||
xp_awk_run_t* run, int in_type,
|
||||
const xp_char_t* name, xp_str_t* buf, int* errnum)
|
||||
@ -346,12 +348,12 @@ int xp_awk_closeextio (xp_awk_run_t* run, const xp_char_t* name, int* errnum)
|
||||
{
|
||||
/* it handles the first that matches the given name
|
||||
* regardless of the extio type */
|
||||
if (xp_strcmp(p->name,name) == 0)
|
||||
if (xp_strcmp (p->name, name) == 0)
|
||||
{
|
||||
xp_awk_io_t handler;
|
||||
|
||||
handler = run->awk->extio[p->type & __MASK_CLEAR];
|
||||
if (handler != NULL)
|
||||
if (handler != XP_NULL)
|
||||
{
|
||||
/* TODO: io command should not be XP_AWK_IO_CLOSE
|
||||
* it should be more generic form than this... */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: func.c,v 1.8 2006-07-13 15:43:39 bacon Exp $
|
||||
* $Id: func.c,v 1.9 2006-07-14 04:19:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -27,8 +27,70 @@ xp_awk_bfn_t* xp_awk_addbfn (
|
||||
xp_awk_t* awk, const xp_char_t* name, int when_valid,
|
||||
xp_size_t min_args, xp_size_t max_args, int (*handler)(void*))
|
||||
{
|
||||
/* TODO */
|
||||
return XP_NULL;
|
||||
xp_awk_bfn_t* p;
|
||||
|
||||
/* TODO: complete this function??? */
|
||||
|
||||
p = (xp_awk_bfn_t*) xp_malloc (xp_sizeof(xp_awk_bfn_t));
|
||||
if (p == XP_NULL) return XP_NULL;
|
||||
|
||||
p->name = xp_strdup(name);
|
||||
if (p->name == XP_NULL)
|
||||
{
|
||||
xp_free (p);
|
||||
return XP_NULL;
|
||||
}
|
||||
|
||||
p->valid = when_valid;
|
||||
p->min_args = min_args;
|
||||
p->max_args = max_args;
|
||||
p->handler = handler;
|
||||
|
||||
p->next = awk->bfn.user;
|
||||
awk->bfn.user = p;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int xp_awk_delbfn (xp_awk_t* awk, const xp_char_t* name)
|
||||
{
|
||||
xp_awk_bfn_t* p, * pp = XP_NULL;
|
||||
|
||||
for (p = awk->bfn.user; p != XP_NULL; p++)
|
||||
{
|
||||
if (xp_strcmp(p->name, name) == 0)
|
||||
{
|
||||
if (pp == XP_NULL)
|
||||
awk->bfn.user = p->next;
|
||||
else pp->next = p->next;
|
||||
|
||||
xp_free (p->name);
|
||||
xp_free (p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp = p;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void xp_awk_clrbfn (xp_awk_t* awk)
|
||||
{
|
||||
xp_awk_bfn_t* p, * np;
|
||||
|
||||
p = awk->bfn.user;
|
||||
while (p != XP_NULL)
|
||||
{
|
||||
np = p;
|
||||
|
||||
xp_free (p->name);
|
||||
xp_free (p);
|
||||
|
||||
p = np;
|
||||
}
|
||||
|
||||
awk->bfn.user = XP_NULL;
|
||||
}
|
||||
|
||||
xp_awk_bfn_t* xp_awk_getbfn (xp_awk_t* awk, const xp_char_t* name)
|
||||
@ -72,7 +134,8 @@ static int __bfn_close (void* run)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (xp_awk_valtostr (xp_awk_getarg(run, 0), &errnum, &buf, XP_NULL) == XP_NULL)
|
||||
if (xp_awk_valtostr (
|
||||
xp_awk_getarg(run, 0), &errnum, &buf, XP_NULL) == XP_NULL)
|
||||
{
|
||||
xp_str_close (&buf);
|
||||
xp_awk_seterrnum (run, errnum);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: func.h,v 1.4 2006-07-13 15:43:39 bacon Exp $
|
||||
* $Id: func.h,v 1.5 2006-07-14 04:19:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_AWK_FUNC_H_
|
||||
@ -13,7 +13,7 @@ typedef struct xp_awk_bfn_t xp_awk_bfn_t;
|
||||
|
||||
struct xp_awk_bfn_t
|
||||
{
|
||||
const xp_char_t* name;
|
||||
xp_char_t* name;
|
||||
int valid; /* the entry is valid when this option is set */
|
||||
|
||||
xp_size_t min_args;
|
||||
@ -27,6 +27,11 @@ struct xp_awk_bfn_t
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
xp_awk_bfn_t* xp_awk_addbfn (
|
||||
xp_awk_t* awk, const xp_char_t* name, int when_valid,
|
||||
xp_size_t min_args, xp_size_t max_args, int (*handler)(void*));
|
||||
int xp_awk_delbfn (xp_awk_t* awk, const xp_char_t* name);
|
||||
void xp_awk_clrbfn (xp_awk_t* awk);
|
||||
xp_awk_bfn_t* xp_awk_getbfn (xp_awk_t* awk, const xp_char_t* name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.c,v 1.135 2006-07-10 14:28:45 bacon Exp $
|
||||
* $Id: parse.c,v 1.136 2006-07-14 04:19:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -2423,13 +2423,18 @@ static xp_awk_nde_t* __parse_fncall (
|
||||
{
|
||||
call->type = XP_AWK_NDE_BFN;
|
||||
call->next = XP_NULL;
|
||||
call->what.bfn = bfn;
|
||||
|
||||
/*call->what.bfn = bfn; */
|
||||
call->what.bfn.min_args = bfn->min_args;
|
||||
call->what.bfn.max_args = bfn->max_args;
|
||||
call->what.bfn.handler = bfn->handler;
|
||||
|
||||
call->args = head;
|
||||
call->nargs = nargs;
|
||||
}
|
||||
else
|
||||
{
|
||||
call->type = XP_AWK_NDE_UFN;
|
||||
call->type = XP_AWK_NDE_AFN;
|
||||
call->next = XP_NULL;
|
||||
call->what.name = name;
|
||||
call->args = head;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c,v 1.133 2006-07-13 15:43:39 bacon Exp $
|
||||
* $Id: run.c,v 1.134 2006-07-14 04:19:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -382,7 +382,7 @@ static int __run_main (xp_awk_run_t* run)
|
||||
};
|
||||
static xp_awk_nde_call_t nde =
|
||||
{
|
||||
XP_AWK_NDE_UFN, /* type */
|
||||
XP_AWK_NDE_AFN, /* type */
|
||||
XP_NULL, /* next */
|
||||
m_a_i_n, /* name */
|
||||
XP_NULL /* args */
|
||||
@ -3070,12 +3070,12 @@ static xp_awk_val_t* __eval_bfn (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
||||
xp_awk_nde_call_t* call = (xp_awk_nde_call_t*)nde;
|
||||
|
||||
/* built-in function */
|
||||
if (call->nargs < call->what.bfn->min_args)
|
||||
if (call->nargs < call->what.bfn.min_args)
|
||||
{
|
||||
PANIC (run, XP_AWK_ETOOFEWARGS);
|
||||
}
|
||||
|
||||
if (call->nargs > call->what.bfn->max_args)
|
||||
if (call->nargs > call->what.bfn.max_args)
|
||||
{
|
||||
PANIC (run, XP_AWK_ETOOMANYARGS);
|
||||
}
|
||||
@ -3281,12 +3281,12 @@ static xp_awk_val_t* __eval_call (
|
||||
n = 0;
|
||||
|
||||
/* built-in function */
|
||||
xp_assert (call->nargs >= call->what.bfn->min_args &&
|
||||
call->nargs <= call->what.bfn->max_args);
|
||||
xp_assert (call->nargs >= call->what.bfn.min_args &&
|
||||
call->nargs <= call->what.bfn.max_args);
|
||||
|
||||
if (call->what.bfn->handler != XP_NULL)
|
||||
if (call->what.bfn.handler != XP_NULL)
|
||||
{
|
||||
n = call->what.bfn->handler (run);
|
||||
n = call->what.bfn.handler (run);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: tree.c,v 1.63 2006-07-01 16:07:06 bacon Exp $
|
||||
* $Id: tree.c,v 1.64 2006-07-14 04:19:22 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -350,13 +350,14 @@ static int __print_expression (xp_awk_nde_t* nde)
|
||||
case XP_AWK_NDE_BFN:
|
||||
{
|
||||
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)nde;
|
||||
xp_printf (XP_T("%s ("), px->what.bfn->name);
|
||||
/*xp_printf (XP_T("%s ("), px->what.bfn->name);*/
|
||||
xp_printf (XP_T("__bfn ("));
|
||||
if (__print_expression_list (px->args) == -1) return -1;
|
||||
xp_printf (XP_T(")"));
|
||||
break;
|
||||
}
|
||||
|
||||
case XP_AWK_NDE_UFN:
|
||||
case XP_AWK_NDE_AFN:
|
||||
{
|
||||
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)nde;
|
||||
xp_printf (XP_T("%s ("), px->what.name);
|
||||
@ -962,7 +963,7 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
|
||||
break;
|
||||
}
|
||||
|
||||
case XP_AWK_NDE_UFN:
|
||||
case XP_AWK_NDE_AFN:
|
||||
{
|
||||
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)p;
|
||||
xp_free (px->what.name);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: tree.h,v 1.58 2006-07-13 15:43:39 bacon Exp $
|
||||
* $Id: tree.h,v 1.59 2006-07-14 04:19:22 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_AWK_TREE_H_
|
||||
@ -41,7 +41,7 @@ enum
|
||||
XP_AWK_NDE_EXP_INCPST,
|
||||
XP_AWK_NDE_CND,
|
||||
XP_AWK_NDE_BFN,
|
||||
XP_AWK_NDE_UFN,
|
||||
XP_AWK_NDE_AFN,
|
||||
XP_AWK_NDE_INT,
|
||||
XP_AWK_NDE_REAL,
|
||||
XP_AWK_NDE_STR,
|
||||
@ -225,14 +225,23 @@ struct xp_awk_nde_var_t
|
||||
xp_awk_nde_t* idx; /* XP_NULL for non-XXXXIDX */
|
||||
};
|
||||
|
||||
/* XP_AWK_NDE_BFN, XP_AWK_NDE_UFN */
|
||||
/* XP_AWK_NDE_BFN, XP_AWK_NDE_AFN */
|
||||
struct xp_awk_nde_call_t
|
||||
{
|
||||
XP_AWK_NDE_HDR;
|
||||
union
|
||||
{
|
||||
xp_char_t* name;
|
||||
xp_awk_bfn_t* bfn;
|
||||
|
||||
/* minimum information of a built-in function
|
||||
* needed during run-time. */
|
||||
struct
|
||||
{
|
||||
xp_size_t min_args;
|
||||
xp_size_t max_args;
|
||||
int (*handler) (void* run);
|
||||
} bfn;
|
||||
/* xp_awk_bfn_t* bfn; */
|
||||
} what;
|
||||
xp_awk_nde_t* args;
|
||||
xp_size_t nargs;
|
||||
|
@ -10,8 +10,10 @@ BEGIN
|
||||
getline x < "abc";
|
||||
//print x;
|
||||
a = close ("abc"); /* close(4) */
|
||||
print "a=" a;
|
||||
//print "hey"
|
||||
b = close ("abc"); /* close(3) */
|
||||
print "b=" b;
|
||||
|
||||
getline x < "Makefile.cl";
|
||||
getline y < "awk.c";
|
||||
|
Loading…
Reference in New Issue
Block a user