*** empty log message ***
This commit is contained in:
parent
0bef35ac1c
commit
fbfceeda5f
@ -255,6 +255,10 @@ SOURCE=.\awk_i.h
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\extio.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\func.h
|
SOURCE=.\func.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source 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_
|
#ifndef _XP_AWK_AWK_H_
|
||||||
@ -104,6 +104,7 @@ enum
|
|||||||
XP_AWK_EDUPNAME, /* duplicate name - function, variable, etc */
|
XP_AWK_EDUPNAME, /* duplicate name - function, variable, etc */
|
||||||
XP_AWK_EUNDEF, /* undefined identifier */
|
XP_AWK_EUNDEF, /* undefined identifier */
|
||||||
XP_AWK_ELVALUE, /* l-value required */
|
XP_AWK_ELVALUE, /* l-value required */
|
||||||
|
XP_AWK_ETOOFEWARGS, /* too few arguments */
|
||||||
XP_AWK_ETOOMANYARGS, /* too many arguments */
|
XP_AWK_ETOOMANYARGS, /* too many arguments */
|
||||||
XP_AWK_EGETLINE, /* getline expected */
|
XP_AWK_EGETLINE, /* getline expected */
|
||||||
|
|
||||||
|
@ -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>
|
#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("duplicate name"),
|
||||||
XP_T("undefined identifier"),
|
XP_T("undefined identifier"),
|
||||||
XP_T("l-value required"),
|
XP_T("l-value required"),
|
||||||
|
XP_T("too few arguments"),
|
||||||
XP_T("too many arguments"),
|
XP_T("too many arguments"),
|
||||||
XP_T("getline expected"),
|
XP_T("getline expected"),
|
||||||
|
|
||||||
|
103
ase/awk/extio.c
103
ase/awk/extio.c
@ -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>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -15,7 +15,13 @@ int xp_awk_readextio (
|
|||||||
{
|
{
|
||||||
xp_awk_extio_t* p = run->extio;
|
xp_awk_extio_t* p = run->extio;
|
||||||
xp_awk_io_t handler = run->awk->extio[type];
|
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)
|
while (p != XP_NULL)
|
||||||
{
|
{
|
||||||
@ -44,18 +50,11 @@ int xp_awk_readextio (
|
|||||||
p->type = type;
|
p->type = type;
|
||||||
p->handle = XP_NULL;
|
p->handle = XP_NULL;
|
||||||
p->next = 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 (handler (XP_AWK_INPUT_OPEN, p, XP_NULL, 0) == -1)
|
||||||
{
|
{
|
||||||
if (extio_created)
|
xp_free (p->name);
|
||||||
{
|
xp_free (p);
|
||||||
xp_free (p->name);
|
|
||||||
xp_free (p);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: set ERRNO */
|
/* TODO: set ERRNO */
|
||||||
*errnum = XP_AWK_ENOERR;
|
*errnum = XP_AWK_ENOERR;
|
||||||
@ -64,11 +63,8 @@ int xp_awk_readextio (
|
|||||||
|
|
||||||
if (p->handle == XP_NULL)
|
if (p->handle == XP_NULL)
|
||||||
{
|
{
|
||||||
if (extio_created)
|
xp_free (p->name);
|
||||||
{
|
xp_free (p);
|
||||||
xp_free (p->name);
|
|
||||||
xp_free (p);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* wrong implementation of user io handler.
|
/* wrong implementation of user io handler.
|
||||||
* the correct io handler should set p->handle to
|
* the correct io handler should set p->handle to
|
||||||
@ -76,11 +72,8 @@ int xp_awk_readextio (
|
|||||||
*errnum = XP_AWK_EIOIMPL;
|
*errnum = XP_AWK_EIOIMPL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* link it to the extio chain */
|
/* chain it */
|
||||||
if (extio_created)
|
|
||||||
{
|
|
||||||
p->next = run->extio;
|
p->next = run->extio;
|
||||||
run->extio = p;
|
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)
|
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 */
|
* regardless of the extio type */
|
||||||
if (xp_strcmp(p->name,name) == 0)
|
if (xp_strcmp(p->name,name) == 0)
|
||||||
{
|
{
|
||||||
xp_awk_io_t handler = run->awk->extio[p->type];
|
xp_awk_io_t handler = run->awk->extio[p->type];
|
||||||
|
|
||||||
/* TODO: io command should not be XP_AWK_INPUT_CLOSE
|
if (handler != NULL)
|
||||||
* it should have more generic form than this... */
|
|
||||||
if (handler (XP_AWK_INPUT_CLOSE, p, XP_NULL, 0) == -1)
|
|
||||||
{
|
{
|
||||||
/* this is not a run-time error.*/
|
/* TODO: io command should not be XP_AWK_INPUT_CLOSE
|
||||||
*errnum = XP_AWK_ENOERR;
|
* it should be more generic form than this... */
|
||||||
return -1;
|
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 (px != XP_NULL) px->next = p->next;
|
||||||
//if (opt_remove_closed_extio) // TODO:...
|
else run->extio = p->next;
|
||||||
//{
|
|
||||||
if (px != XP_NULL) px->next = p->next;
|
|
||||||
else run->extio = p->next;
|
|
||||||
|
|
||||||
xp_free (p->name);
|
xp_free (p->name);
|
||||||
xp_free (p);
|
xp_free (p);
|
||||||
//}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,39 +134,32 @@ int xp_awk_closeextio (xp_awk_run_t* run, const xp_char_t* name, int* errnum)
|
|||||||
return -1;
|
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_extio_t* next;
|
||||||
xp_awk_io_t handler;
|
xp_awk_io_t handler;
|
||||||
|
int n;
|
||||||
|
|
||||||
while (p != XP_NULL)
|
while (run->extio != XP_NULL)
|
||||||
{
|
{
|
||||||
handler = run->awk->extio[p->type];
|
handler = run->awk->extio[run->extio->type];
|
||||||
next = p->next;
|
next = run->extio->next;
|
||||||
|
|
||||||
/* TODO: io command should not be XP_AWK_INPUT_CLOSE
|
if (handler != XP_NULL)
|
||||||
* it should have more generic form than this... */
|
|
||||||
if (handler (XP_AWK_INPUT_CLOSE, p, XP_NULL, 0) == -1)
|
|
||||||
{
|
{
|
||||||
/* TODO: should it be removed from the chain???? */
|
/* TODO: io command should not be XP_AWK_INPUT_CLOSE
|
||||||
/* this is not a run-time error.*/
|
* it should be more generic form than this... */
|
||||||
*errnum = XP_AWK_ENOERR;
|
n = handler (XP_AWK_INPUT_CLOSE, run->extio, XP_NULL, 0);
|
||||||
return -1;
|
if (n == -1)
|
||||||
|
{
|
||||||
|
/* TODO:
|
||||||
|
* some warning actions need to be taken */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p->handle = XP_NULL;
|
xp_free (run->extio->name);
|
||||||
//if (opt_remove_closed_extio) // TODO:...
|
xp_free (run->extio);
|
||||||
//{
|
|
||||||
if (px != XP_NULL) px->next = p->next;
|
|
||||||
else run->extio = p->next;
|
|
||||||
|
|
||||||
xp_free (p->name);
|
run->extio = next;
|
||||||
xp_free (p);
|
|
||||||
//}
|
|
||||||
|
|
||||||
p = next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ int xp_awk_readextio (
|
|||||||
int xp_awk_closeextio (
|
int xp_awk_closeextio (
|
||||||
xp_awk_run_t* run, const xp_char_t* name, int* errnum);
|
xp_awk_run_t* run, const xp_char_t* name, int* errnum);
|
||||||
|
|
||||||
|
void xp_awk_clearextio (xp_awk_run_t* run);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -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>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -12,21 +12,31 @@
|
|||||||
|
|
||||||
static int __bfn_close (void* run);
|
static int __bfn_close (void* run);
|
||||||
|
|
||||||
|
/* TODO: move it under the awk structure... */
|
||||||
static xp_awk_bfn_t __bfn[] =
|
static xp_awk_bfn_t __bfn[] =
|
||||||
{
|
{
|
||||||
{ XP_T("system"), 0, 1, 1, XP_NULL },
|
{ XP_T("system"), (1 << 5), 1, 1, XP_NULL },
|
||||||
{ XP_T("close"), XP_AWK_EXTIO, 1, 2, __bfn_close },
|
{ XP_T("close"), XP_AWK_EXTIO, 1, 1, __bfn_close },
|
||||||
{ XP_NULL, 0, 0, 0, XP_NULL }
|
{ 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;
|
if (xp_strcmp (p->name, name) == 0) return p;
|
||||||
p++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return XP_NULL;
|
return XP_NULL;
|
||||||
@ -41,6 +51,7 @@ static int __bfn_close (void* run)
|
|||||||
|
|
||||||
nargs = xp_awk_getnargs (run);
|
nargs = xp_awk_getnargs (run);
|
||||||
xp_assert (nargs == 1);
|
xp_assert (nargs == 1);
|
||||||
|
/* TODO: support close (xxx, "to"/"from") like gawk */
|
||||||
|
|
||||||
if (xp_str_open (&buf, 256) == XP_NULL)
|
if (xp_str_open (&buf, 256) == XP_NULL)
|
||||||
{
|
{
|
||||||
|
@ -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_
|
#ifndef _XP_AWK_FUNC_H_
|
||||||
@ -16,8 +16,8 @@ struct xp_awk_bfn_t
|
|||||||
const xp_char_t* name;
|
const xp_char_t* name;
|
||||||
int valid; /* the entry is valid when this option is set */
|
int valid; /* the entry is valid when this option is set */
|
||||||
|
|
||||||
int max_args;
|
xp_size_t min_args;
|
||||||
int min_args;
|
xp_size_t max_args;
|
||||||
int (*handler) (void* run);
|
int (*handler) (void* run);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ struct xp_awk_bfn_t
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -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>
|
#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 */
|
/* 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)
|
if (bfn != XP_NULL)
|
||||||
{
|
{
|
||||||
xp_awk_nde_t* nde;
|
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++)
|
for (kwp = __kwtab; kwp->name != XP_NULL; kwp++)
|
||||||
{
|
{
|
||||||
if (kwp->valid != 0 && (awk->opt.parse & kwp->valid) == 0)
|
if (kwp->valid != 0 &&
|
||||||
{
|
(awk->opt.parse & kwp->valid) == 0) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (xp_strcmp(kwp->name, ident) == 0) return kwp->type;
|
if (xp_strcmp(kwp->name, ident) == 0) return kwp->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -267,6 +267,10 @@ static int __open_run (
|
|||||||
|
|
||||||
static void __close_run (xp_awk_run_t* 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 */
|
/* destroy run stack */
|
||||||
if (run->stack != XP_NULL)
|
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)
|
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);
|
return __eval_call (run, nde, XP_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2716,7 +2733,7 @@ static xp_awk_val_t* __eval_call (
|
|||||||
|
|
||||||
if (afn != XP_NULL)
|
if (afn != XP_NULL)
|
||||||
{
|
{
|
||||||
/* normal awk function */
|
/* extra step for normal awk functions */
|
||||||
|
|
||||||
while (nargs < afn->nargs)
|
while (nargs < afn->nargs)
|
||||||
{
|
{
|
||||||
@ -2757,6 +2774,9 @@ static xp_awk_val_t* __eval_call (
|
|||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
/* built-in function */
|
/* 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)
|
if (call->what.bfn->handler != XP_NULL)
|
||||||
{
|
{
|
||||||
n = call->what.bfn->handler (run);
|
n = call->what.bfn->handler (run);
|
||||||
|
@ -7,4 +7,10 @@ BEGIN
|
|||||||
a = close ("abc"); /* close(4) */
|
a = close ("abc"); /* close(4) */
|
||||||
//print "hey"
|
//print "hey"
|
||||||
b = close ("abc"); /* close(3) */
|
b = close ("abc"); /* close(3) */
|
||||||
|
|
||||||
|
getline x < "Makefile.cl";
|
||||||
|
getline y < "awk.c";
|
||||||
|
c = close ("Makefile.cl");
|
||||||
|
d = close ("awk.c");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user