From 0bf0776ef6b3b0c2d59f992bbe7c73478cedf174 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 16 Jun 2006 07:37:27 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk.h | 3 +- ase/awk/awk_i.h | 21 ++++++++-- ase/awk/err.c | 3 +- ase/awk/extio.c | 95 +++++++++++++++++++++++++++++++++++++++++++++ ase/awk/makefile.cl | 2 +- ase/awk/makefile.in | 2 +- ase/awk/run.c | 46 ++++++++++++++++++++-- ase/awk/sa.h | 4 +- 8 files changed, 165 insertions(+), 11 deletions(-) create mode 100644 ase/awk/extio.c diff --git a/ase/awk/awk.h b/ase/awk/awk.h index ca524071..f5f36f24 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.61 2006-05-13 16:33:07 bacon Exp $ + * $Id: awk.h,v 1.62 2006-06-16 07:35:06 bacon Exp $ */ #ifndef _XP_AWK_AWK_H_ @@ -99,6 +99,7 @@ enum XP_AWK_ENOTASSIGNABLE, /* value not assignable */ XP_AWK_ENOTINDEXABLE, /* not indexable value */ XP_AWK_EWRONGINDEX, /* wrong index */ + XP_AWK_EPIPE, /* pipe operation error */ XP_AWK_EINTERNAL /* internal error */ }; diff --git a/ase/awk/awk_i.h b/ase/awk/awk_i.h index 8e3c6da0..94a7441c 100644 --- a/ase/awk/awk_i.h +++ b/ase/awk/awk_i.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h,v 1.12 2006-05-13 16:33:07 bacon Exp $ + * $Id: awk_i.h,v 1.13 2006-06-16 07:35:07 bacon Exp $ */ #ifndef _XP_AWK_AWKI_H_ @@ -8,8 +8,7 @@ typedef struct xp_awk_chain_t xp_awk_chain_t; typedef struct xp_awk_run_t xp_awk_run_t; typedef struct xp_awk_tree_t xp_awk_tree_t; - - +typedef struct xp_awk_cmd_t xp_awk_cmd_t; #include #include @@ -132,6 +131,7 @@ struct xp_awk_chain_t xp_awk_chain_t* next; }; + struct xp_awk_run_t { xp_awk_map_t named; @@ -159,10 +159,25 @@ struct xp_awk_run_t xp_str_t line; } input; + struct + { + xp_awk_cmd_t* incmd; + xp_awk_cmd_t* iocmd; + xp_awk_cmd_t* outcmd; + /*xp_awk_infile_t* infile;*/ + } extio; + int opt; int errnum; xp_awk_tree_t* tree; xp_size_t nglobals; }; +struct xp_awk_cmd_t +{ + xp_char_t* name; + void* handle; + xp_awk_cmd_t* next; +}; + #endif diff --git a/ase/awk/err.c b/ase/awk/err.c index be7bd748..250543ca 100644 --- a/ase/awk/err.c +++ b/ase/awk/err.c @@ -1,5 +1,5 @@ /* - * $Id: err.c,v 1.18 2006-05-06 12:52:36 bacon Exp $ + * $Id: err.c,v 1.19 2006-06-16 07:35:07 bacon Exp $ */ #include @@ -63,6 +63,7 @@ const xp_char_t* xp_awk_geterrstr (xp_awk_t* awk) XP_T("value not assignable"), XP_T("value not indexable"), XP_T("wrong index value"), + XP_T("pipe operation error"), XP_T("internal error that should never have happened") }; diff --git a/ase/awk/extio.c b/ase/awk/extio.c new file mode 100644 index 00000000..46907fbe --- /dev/null +++ b/ase/awk/extio.c @@ -0,0 +1,95 @@ +/* + * $Id: extio.c,v 1.1 2006-06-16 07:35:07 bacon Exp $ + */ + +#include + +#ifndef XP_AWK_STAND_ALONE +#include +#include +#include +#endif + +/* TODO: a lot of todo's here... */ +#include +#include + +int xp_awk_readcmd (xp_awk_run_t* run, const xp_char_t* cmd, int* errnum) +{ + xp_awk_cmd_t* p = run->extio.incmd; + + while (p != XP_NULL) + { + if (xp_strcmp(p->name,cmd) == 0) break; + p = p->next; + } + + if (p == XP_NULL) + { + p = (xp_awk_cmd_t*) xp_malloc (xp_sizeof(xp_awk_cmd_t)); + if (p == XP_NULL) + { + *errnum = XP_AWK_EPIPE; + return -1; + } + + p->name = xp_strdup (cmd); + if (p->name == XP_NULL) + { + xp_free (p); + *errnum = XP_AWK_EPIPE; + return -1; + } + + p->handle = XP_NULL; + p->next = run->extio.incmd; + run->extio.incmd = p; + } + + if (p->handle == XP_NULL) + { + p->handle = (void*) _tpopen (p->name, XP_T("r")); + if (p->handle == NULL) + { + *errnum = XP_AWK_EPIPE; + return -1; + } + } + + { + xp_char_t buf[1024]; + if (_fgetts (buf, xp_countof(buf), p->handle) == XP_NULL) return 0; + xp_printf(XP_TEXT("%s"), buf); + } + + + return 1; +} + +int xp_awk_closecmd (xp_awk_run_t* run, const xp_char_t* cmd, int* errnum) +{ + xp_awk_cmd_t* p = run->extio.incmd, * px = XP_NULL; + + while (p != XP_NULL) + { + if (xp_strcmp(p->name,cmd) == 0) + { + fclose ((FILE*)p->handle); + p->handle = XP_NULL; + + //if (opt_remove_closed_cmd) + //{ + if (px != XP_NULL) px->next = p->next; + else run->extio.incmd = p->next; + + xp_free (p->name); + xp_free (p); + //} + } + + px = p; + p = p->next; + } + + return -1; +} diff --git a/ase/awk/makefile.cl b/ase/awk/makefile.cl index 9620a6c7..17838514 100644 --- a/ase/awk/makefile.cl +++ b/ase/awk/makefile.cl @@ -1,4 +1,4 @@ -SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c misc.c +SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c misc.c extio.c OBJS = $(SRCS:.c=.obj) OUT = xpawk diff --git a/ase/awk/makefile.in b/ase/awk/makefile.in index 6505bff2..2b3bba21 100644 --- a/ase/awk/makefile.in +++ b/ase/awk/makefile.in @@ -1,4 +1,4 @@ -SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c misc.c +SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c misc.c extio.c OBJS = $(SRCS:.c=.o) OUT = libxpawk.a diff --git a/ase/awk/run.c b/ase/awk/run.c index 14d5c8b3..8464c7f0 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.95 2006-06-13 15:11:39 bacon Exp $ + * $Id: run.c,v 1.96 2006-06-16 07:35:07 bacon Exp $ */ #include @@ -194,6 +194,8 @@ static void __free_namedval (void* run, void* val) static int __open_run ( xp_awk_run_t* run, xp_awk_t* awk, xp_awk_io_t txtio, void* txtio_arg) { + xp_memset (run, 0, xp_sizeof(*run)); + run->stack = XP_NULL; run->stack_top = 0; run->stack_base = 0; @@ -228,6 +230,11 @@ static int __open_run ( return -1; } + /* TODO: */ + run->extio.incmd = XP_NULL; + run->extio.iocmd = XP_NULL; + run->extio.outcmd = XP_NULL; + return 0; } @@ -2849,8 +2856,41 @@ static xp_awk_val_t* __eval_pos (xp_awk_run_t* run, xp_awk_nde_t* nde) static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde) { - xp_printf (XP_T("eval_getline not competed....\n")); - return XP_NULL; + xp_awk_nde_getline_t* p = (xp_awk_nde_getline_t*)nde; + + if (p->in_type == XP_AWK_GETLINE_PIPE) + { + xp_awk_val_t* in; + xp_char_t* str; + int errnum, n; + + in = __eval_expression (run, p->in); + if (in == XP_NULL) return XP_NULL; + + xp_awk_refupval (in); + str = __val_to_str (in, &errnum, XP_NULL); + if (str == XP_NULL) + { + xp_awk_refdownval (run, in); + PANIC (run, errnum); + } + xp_awk_refdownval (run, in); + + n = xp_awk_readcmd (run, str, &errnum); + xp_free (str); + + return xp_awk_makeintval (run, n); + } + else if (p->in_type == XP_AWK_GETLINE_FILE) + { + xp_printf (XP_T("eval_getline not properly implemented....\n")); + return XP_NULL; + } + else + { + xp_assert (!"should never happen - wrong in_type for getline"); + PANIC (run, XP_AWK_EINTERNAL); + } } static int __raw_push (xp_awk_run_t* run, void* val) diff --git a/ase/awk/sa.h b/ase/awk/sa.h index 01d37a43..07e8ab33 100644 --- a/ase/awk/sa.h +++ b/ase/awk/sa.h @@ -1,5 +1,5 @@ /* - * $Id: sa.h,v 1.23 2006-05-04 15:59:43 bacon Exp $ + * $Id: sa.h,v 1.24 2006-06-16 07:35:07 bacon Exp $ */ #ifndef _XP_AWK_SA_H_ @@ -34,6 +34,8 @@ #define xp_malloc malloc #define xp_realloc realloc #define xp_free free +#define xp_memset memset +#define xp_memcpy memcpy #define xp_assert assert #ifdef XP_CHAR_IS_MCHAR