*** empty log message ***

This commit is contained in:
hyung-hwan 2006-06-21 15:37:51 +00:00
parent 0bef35ac1c
commit fbfceeda5f
10 changed files with 108 additions and 80 deletions

View File

@ -255,6 +255,10 @@ SOURCE=.\awk_i.h
# End Source File
# Begin Source File
SOURCE=.\extio.h
# End Source File
# Begin Source File
SOURCE=.\func.h
# End Source File
# Begin Source File

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h,v 1.69 2006-06-21 13:52:15 bacon Exp $
* $Id: awk.h,v 1.70 2006-06-21 15:37:51 bacon Exp $
*/
#ifndef _XP_AWK_AWK_H_
@ -104,6 +104,7 @@ enum
XP_AWK_EDUPNAME, /* duplicate name - function, variable, etc */
XP_AWK_EUNDEF, /* undefined identifier */
XP_AWK_ELVALUE, /* l-value required */
XP_AWK_ETOOFEWARGS, /* too few arguments */
XP_AWK_ETOOMANYARGS, /* too many arguments */
XP_AWK_EGETLINE, /* getline expected */

View File

@ -1,5 +1,5 @@
/*
* $Id: err.c,v 1.21 2006-06-19 09:08:50 bacon Exp $
* $Id: err.c,v 1.22 2006-06-21 15:37:51 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -56,6 +56,7 @@ const xp_char_t* xp_awk_geterrstr (xp_awk_t* awk)
XP_T("duplicate name"),
XP_T("undefined identifier"),
XP_T("l-value required"),
XP_T("too few arguments"),
XP_T("too many arguments"),
XP_T("getline expected"),

View File

@ -1,5 +1,5 @@
/*
* $Id: extio.c,v 1.6 2006-06-21 13:52:15 bacon Exp $
* $Id: extio.c,v 1.7 2006-06-21 15:37:51 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -15,7 +15,13 @@ int xp_awk_readextio (
{
xp_awk_extio_t* p = run->extio;
xp_awk_io_t handler = run->awk->extio[type];
xp_bool_t extio_created = xp_false;
if (handler == XP_NULL)
{
/* no io handler provided */
*errnum = XP_AWK_EIOIMPL; /* TODO: change the error code */
return -1;
}
while (p != XP_NULL)
{
@ -44,18 +50,11 @@ int xp_awk_readextio (
p->type = type;
p->handle = XP_NULL;
p->next = XP_NULL;
extio_created = xp_true;
}
if (p->handle == XP_NULL)
{
if (handler (XP_AWK_INPUT_OPEN, p, XP_NULL, 0) == -1)
{
if (extio_created)
{
xp_free (p->name);
xp_free (p);
}
/* TODO: set ERRNO */
*errnum = XP_AWK_ENOERR;
@ -63,12 +62,9 @@ int xp_awk_readextio (
}
if (p->handle == XP_NULL)
{
if (extio_created)
{
xp_free (p->name);
xp_free (p);
}
/* wrong implementation of user io handler.
* the correct io handler should set p->handle to
@ -76,11 +72,8 @@ int xp_awk_readextio (
*errnum = XP_AWK_EIOIMPL;
return -1;
}
}
/* link it to the extio chain */
if (extio_created)
{
/* chain it */
p->next = run->extio;
run->extio = p;
}
@ -106,30 +99,29 @@ int xp_awk_closeextio (xp_awk_run_t* run, const xp_char_t* name, int* errnum)
while (p != XP_NULL)
{
/* it handles the first name that matches
/* it handles the first that matches the given name
* regardless of the extio type */
if (xp_strcmp(p->name,name) == 0)
{
xp_awk_io_t handler = run->awk->extio[p->type];
if (handler != NULL)
{
/* TODO: io command should not be XP_AWK_INPUT_CLOSE
* it should have more generic form than this... */
* it should be more generic form than this... */
if (handler (XP_AWK_INPUT_CLOSE, p, XP_NULL, 0) == -1)
{
/* this is not a run-time error.*/
*errnum = XP_AWK_ENOERR;
return -1;
}
}
p->handle = XP_NULL;
//if (opt_remove_closed_extio) // TODO:...
//{
if (px != XP_NULL) px->next = p->next;
else run->extio = p->next;
xp_free (p->name);
xp_free (p);
//}
return 0;
}
@ -142,39 +134,32 @@ int xp_awk_closeextio (xp_awk_run_t* run, const xp_char_t* name, int* errnum)
return -1;
}
int xp_awk_clearextio (xp_awk_run_t* run, int* errnum)
void xp_awk_clearextio (xp_awk_run_t* run)
{
xp_awk_extio_t* p = run->extio;
xp_awk_extio_t* next;
xp_awk_io_t handler;
int n;
while (p != XP_NULL)
while (run->extio != XP_NULL)
{
handler = run->awk->extio[p->type];
next = p->next;
handler = run->awk->extio[run->extio->type];
next = run->extio->next;
if (handler != XP_NULL)
{
/* TODO: io command should not be XP_AWK_INPUT_CLOSE
* it should have more generic form than this... */
if (handler (XP_AWK_INPUT_CLOSE, p, XP_NULL, 0) == -1)
* it should be more generic form than this... */
n = handler (XP_AWK_INPUT_CLOSE, run->extio, XP_NULL, 0);
if (n == -1)
{
/* TODO: should it be removed from the chain???? */
/* this is not a run-time error.*/
*errnum = XP_AWK_ENOERR;
return -1;
/* TODO:
* some warning actions need to be taken */
}
}
p->handle = XP_NULL;
//if (opt_remove_closed_extio) // TODO:...
//{
if (px != XP_NULL) px->next = p->next;
else run->extio = p->next;
xp_free (run->extio->name);
xp_free (run->extio);
xp_free (p->name);
xp_free (p);
//}
p = next;
run->extio = next;
}
return 0;
}

View File

@ -15,6 +15,8 @@ int xp_awk_readextio (
int xp_awk_closeextio (
xp_awk_run_t* run, const xp_char_t* name, int* errnum);
void xp_awk_clearextio (xp_awk_run_t* run);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/*
* $Id: func.c,v 1.4 2006-06-21 13:52:15 bacon Exp $
* $Id: func.c,v 1.5 2006-06-21 15:37:51 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -12,21 +12,31 @@
static int __bfn_close (void* run);
/* TODO: move it under the awk structure... */
static xp_awk_bfn_t __bfn[] =
{
{ XP_T("system"), 0, 1, 1, XP_NULL },
{ XP_T("close"), XP_AWK_EXTIO, 1, 2, __bfn_close },
{ XP_T("system"), (1 << 5), 1, 1, XP_NULL },
{ XP_T("close"), XP_AWK_EXTIO, 1, 1, __bfn_close },
{ XP_NULL, 0, 0, 0, XP_NULL }
};
xp_awk_bfn_t* xp_awk_getbfn (const xp_char_t* name)
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*))
{
xp_awk_bfn_t* p = __bfn;
/* TODO */
}
while (p->name != XP_NULL)
xp_awk_bfn_t* xp_awk_getbfn (xp_awk_t* awk, const xp_char_t* name)
{
xp_awk_bfn_t* p;
for (p = __bfn; p->name != XP_NULL; p++)
{
if (p->valid != 0 &&
(awk->opt.parse & p->valid) == 0) continue;
if (xp_strcmp (p->name, name) == 0) return p;
p++;
}
return XP_NULL;
@ -41,6 +51,7 @@ static int __bfn_close (void* run)
nargs = xp_awk_getnargs (run);
xp_assert (nargs == 1);
/* TODO: support close (xxx, "to"/"from") like gawk */
if (xp_str_open (&buf, 256) == XP_NULL)
{

View File

@ -1,5 +1,5 @@
/*
* $Id: func.h,v 1.2 2006-06-20 15:27:50 bacon Exp $
* $Id: func.h,v 1.3 2006-06-21 15:37:51 bacon Exp $
*/
#ifndef _XP_AWK_FUNC_H_
@ -16,8 +16,8 @@ struct xp_awk_bfn_t
const xp_char_t* name;
int valid; /* the entry is valid when this option is set */
int max_args;
int min_args;
xp_size_t min_args;
xp_size_t max_args;
int (*handler) (void* run);
};
@ -25,7 +25,7 @@ struct xp_awk_bfn_t
extern "C" {
#endif
xp_awk_bfn_t* xp_awk_getbfn (const xp_char_t* name);
xp_awk_bfn_t* xp_awk_getbfn (xp_awk_t* awk, const xp_char_t* name);
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.118 2006-06-20 15:27:50 bacon Exp $
* $Id: parse.c,v 1.119 2006-06-21 15:37:51 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -2039,7 +2039,7 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
}
/* what if name_dup is a built-in function name */
bfn = xp_awk_getbfn (name_dup);
bfn = xp_awk_getbfn (awk, name_dup);
if (bfn != XP_NULL)
{
xp_awk_nde_t* nde;
@ -3564,10 +3564,8 @@ static int __classify_ident (xp_awk_t* awk, const xp_char_t* ident)
for (kwp = __kwtab; kwp->name != XP_NULL; kwp++)
{
if (kwp->valid != 0 && (awk->opt.parse & kwp->valid) == 0)
{
continue;
}
if (kwp->valid != 0 &&
(awk->opt.parse & kwp->valid) == 0) continue;
if (xp_strcmp(kwp->name, ident) == 0) return kwp->type;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.103 2006-06-21 13:52:15 bacon Exp $
* $Id: run.c,v 1.104 2006-06-21 15:37:51 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -267,6 +267,10 @@ static int __open_run (
static void __close_run (xp_awk_run_t* run)
{
/* close all pending eio's */
/* TODO: what if this operation fails? */
xp_awk_clearextio (run);
/* destroy run stack */
if (run->stack != XP_NULL)
{
@ -2556,6 +2560,19 @@ static xp_awk_val_t* __eval_cnd (xp_awk_run_t* run, xp_awk_nde_t* nde)
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)
{
PANIC (run, XP_AWK_ETOOFEWARGS);
}
if (call->nargs > call->what.bfn->max_args)
{
PANIC (run, XP_AWK_ETOOMANYARGS);
}
return __eval_call (run, nde, XP_NULL);
}
@ -2716,7 +2733,7 @@ static xp_awk_val_t* __eval_call (
if (afn != XP_NULL)
{
/* normal awk function */
/* extra step for normal awk functions */
while (nargs < afn->nargs)
{
@ -2757,6 +2774,9 @@ 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);
if (call->what.bfn->handler != XP_NULL)
{
n = call->what.bfn->handler (run);

View File

@ -7,4 +7,10 @@ BEGIN
a = close ("abc"); /* close(4) */
//print "hey"
b = close ("abc"); /* close(3) */
getline x < "Makefile.cl";
getline y < "awk.c";
c = close ("Makefile.cl");
d = close ("awk.c");
}