*** empty log message ***

This commit is contained in:
hyung-hwan 2006-06-16 07:37:27 +00:00
parent 0a22297056
commit 0bf0776ef6
8 changed files with 165 additions and 11 deletions

View File

@ -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_ #ifndef _XP_AWK_AWK_H_
@ -99,6 +99,7 @@ enum
XP_AWK_ENOTASSIGNABLE, /* value not assignable */ XP_AWK_ENOTASSIGNABLE, /* value not assignable */
XP_AWK_ENOTINDEXABLE, /* not indexable value */ XP_AWK_ENOTINDEXABLE, /* not indexable value */
XP_AWK_EWRONGINDEX, /* wrong index */ XP_AWK_EWRONGINDEX, /* wrong index */
XP_AWK_EPIPE, /* pipe operation error */
XP_AWK_EINTERNAL /* internal error */ XP_AWK_EINTERNAL /* internal error */
}; };

View File

@ -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_ #ifndef _XP_AWK_AWKI_H_
@ -8,8 +8,7 @@
typedef struct xp_awk_chain_t xp_awk_chain_t; typedef struct xp_awk_chain_t xp_awk_chain_t;
typedef struct xp_awk_run_t xp_awk_run_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_tree_t xp_awk_tree_t;
typedef struct xp_awk_cmd_t xp_awk_cmd_t;
#include <xp/awk/awk.h> #include <xp/awk/awk.h>
#include <xp/awk/tree.h> #include <xp/awk/tree.h>
@ -132,6 +131,7 @@ struct xp_awk_chain_t
xp_awk_chain_t* next; xp_awk_chain_t* next;
}; };
struct xp_awk_run_t struct xp_awk_run_t
{ {
xp_awk_map_t named; xp_awk_map_t named;
@ -159,10 +159,25 @@ struct xp_awk_run_t
xp_str_t line; xp_str_t line;
} input; } 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 opt;
int errnum; int errnum;
xp_awk_tree_t* tree; xp_awk_tree_t* tree;
xp_size_t nglobals; xp_size_t nglobals;
}; };
struct xp_awk_cmd_t
{
xp_char_t* name;
void* handle;
xp_awk_cmd_t* next;
};
#endif #endif

View File

@ -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 <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -63,6 +63,7 @@ const xp_char_t* xp_awk_geterrstr (xp_awk_t* awk)
XP_T("value not assignable"), XP_T("value not assignable"),
XP_T("value not indexable"), XP_T("value not indexable"),
XP_T("wrong index value"), XP_T("wrong index value"),
XP_T("pipe operation error"),
XP_T("internal error that should never have happened") XP_T("internal error that should never have happened")
}; };

95
ase/awk/extio.c Normal file
View File

@ -0,0 +1,95 @@
/*
* $Id: extio.c,v 1.1 2006-06-16 07:35:07 bacon Exp $
*/
#include <xp/awk/awk_i.h>
#ifndef XP_AWK_STAND_ALONE
#include <xp/bas/assert.h>
#include <xp/bas/string.h>
#include <xp/bas/memory.h>
#endif
/* TODO: a lot of todo's here... */
#include <tchar.h>
#include <stdio.h>
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;
}

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 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) OBJS = $(SRCS:.c=.obj)
OUT = xpawk OUT = xpawk

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 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) OBJS = $(SRCS:.c=.o)
OUT = libxpawk.a OUT = libxpawk.a

View File

@ -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 <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -194,6 +194,8 @@ static void __free_namedval (void* run, void* val)
static int __open_run ( static int __open_run (
xp_awk_run_t* run, xp_awk_t* awk, xp_awk_io_t txtio, void* txtio_arg) 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 = XP_NULL;
run->stack_top = 0; run->stack_top = 0;
run->stack_base = 0; run->stack_base = 0;
@ -228,6 +230,11 @@ static int __open_run (
return -1; return -1;
} }
/* TODO: */
run->extio.incmd = XP_NULL;
run->extio.iocmd = XP_NULL;
run->extio.outcmd = XP_NULL;
return 0; return 0;
} }
@ -2849,9 +2856,42 @@ 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) 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")); 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; 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) static int __raw_push (xp_awk_run_t* run, void* val)
{ {

View File

@ -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_ #ifndef _XP_AWK_SA_H_
@ -34,6 +34,8 @@
#define xp_malloc malloc #define xp_malloc malloc
#define xp_realloc realloc #define xp_realloc realloc
#define xp_free free #define xp_free free
#define xp_memset memset
#define xp_memcpy memcpy
#define xp_assert assert #define xp_assert assert
#ifdef XP_CHAR_IS_MCHAR #ifdef XP_CHAR_IS_MCHAR