*** empty log message ***
This commit is contained in:
parent
7066e20309
commit
2881e870c6
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.c,v 1.51 2006-06-18 13:43:28 bacon Exp $
|
* $Id: awk.c,v 1.52 2006-06-19 04:38:51 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -224,3 +224,12 @@ xp_size_t xp_awk_getsrcline (xp_awk_t* awk)
|
|||||||
{
|
{
|
||||||
return awk->token.line;
|
return awk->token.line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* TODO: redo it */
|
||||||
|
int xp_awk_setextio (xp_awk_t* awk, xp_awk_io_t io, void* arg)
|
||||||
|
{
|
||||||
|
awk->extio.pipe = io;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h,v 1.64 2006-06-18 11:18:49 bacon Exp $
|
* $Id: awk.h,v 1.65 2006-06-19 04:38:51 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_AWK_AWK_H_
|
#ifndef _XP_AWK_AWK_H_
|
||||||
@ -13,6 +13,15 @@ typedef struct xp_awk_t xp_awk_t;
|
|||||||
typedef xp_ssize_t (*xp_awk_io_t) (
|
typedef xp_ssize_t (*xp_awk_io_t) (
|
||||||
int cmd, void* arg, xp_char_t* data, xp_size_t count);
|
int cmd, void* arg, xp_char_t* data, xp_size_t count);
|
||||||
|
|
||||||
|
typedef struct xp_awk_cmd_t xp_awk_cmd_t;
|
||||||
|
|
||||||
|
struct xp_awk_cmd_t
|
||||||
|
{
|
||||||
|
xp_char_t* name;
|
||||||
|
void* handle;
|
||||||
|
xp_awk_cmd_t* next;
|
||||||
|
};
|
||||||
|
|
||||||
/* io function commands */
|
/* io function commands */
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -123,6 +132,8 @@ void xp_awk_setrunopt (xp_awk_t* awk, int opt);
|
|||||||
int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg);
|
int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg);
|
||||||
int xp_awk_detsrc (xp_awk_t* awk);
|
int xp_awk_detsrc (xp_awk_t* awk);
|
||||||
|
|
||||||
|
int xp_awk_setextio (xp_awk_t* awk, xp_awk_io_t io, void* arg);
|
||||||
|
|
||||||
xp_size_t xp_awk_getsrcline (xp_awk_t* awk);
|
xp_size_t xp_awk_getsrcline (xp_awk_t* awk);
|
||||||
/* TODO: xp_awk_parse (xp_awk_t* awk, xp_awk_io_t src, void* arg)??? */
|
/* TODO: xp_awk_parse (xp_awk_t* awk, xp_awk_io_t src, void* arg)??? */
|
||||||
int xp_awk_parse (xp_awk_t* awk);
|
int xp_awk_parse (xp_awk_t* awk);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk_i.h,v 1.15 2006-06-18 13:43:28 bacon Exp $
|
* $Id: awk_i.h,v 1.16 2006-06-19 04:38:51 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_AWK_AWKI_H_
|
#ifndef _XP_AWK_AWKI_H_
|
||||||
@ -8,7 +8,6 @@
|
|||||||
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>
|
||||||
@ -177,15 +176,10 @@ struct xp_awk_run_t
|
|||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
int errnum;
|
int errnum;
|
||||||
xp_awk_tree_t* tree;
|
|
||||||
xp_size_t nglobals;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct xp_awk_cmd_t
|
xp_awk_tree_t* tree;
|
||||||
{
|
/*xp_size_t nglobals;*/
|
||||||
xp_char_t* name;
|
xp_awk_t* awk;
|
||||||
void* handle;
|
|
||||||
xp_awk_cmd_t* next;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: extio.c,v 1.3 2006-06-18 13:43:28 bacon Exp $
|
* $Id: extio.c,v 1.4 2006-06-19 04:38:51 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -48,11 +48,9 @@ int xp_awk_readcmd (xp_awk_run_t* run, const xp_char_t* cmd, int* errnum)
|
|||||||
|
|
||||||
if (p->handle == XP_NULL)
|
if (p->handle == XP_NULL)
|
||||||
{
|
{
|
||||||
xp_awk_io_t pipe_io = run->awk.extio.pipe;
|
xp_awk_io_t pipe_io = run->awk->extio.pipe;
|
||||||
|
|
||||||
//p->handle = (void*) _tpopen (p->name, XP_T("r"));
|
if (pipe_io (XP_AWK_INPUT_OPEN, p, XP_NULL, 0) == -1)
|
||||||
p->handle = pipe_io (XP_AWK_INPUT_OPEN, p->name, XP_NULL, 0);
|
|
||||||
if (p->handle == NULL)
|
|
||||||
{
|
{
|
||||||
/* this is treated as pipe open error.
|
/* this is treated as pipe open error.
|
||||||
* the return value of getline should be -1
|
* the return value of getline should be -1
|
||||||
@ -60,12 +58,28 @@ int xp_awk_readcmd (xp_awk_run_t* run, const xp_char_t* cmd, int* errnum)
|
|||||||
*/
|
*/
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p->handle == XP_NULL)
|
||||||
|
{
|
||||||
|
/* TODO: break the chain ... */
|
||||||
|
|
||||||
|
|
||||||
|
/* *errnum = XP_AWK_EEXTIO; external io handler error */
|
||||||
|
*errnum = XP_AWK_EINTERNAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
xp_char_t buf[1024];
|
xp_char_t buf[1024];
|
||||||
if (_fgetts (buf, xp_countof(buf), p->handle) == XP_NULL) return 0;
|
xp_awk_io_t pipe_io = run->awk->extio.pipe;
|
||||||
xp_printf(XP_TEXT("%s"), buf);
|
|
||||||
|
if (pipe_io (XP_AWK_INPUT_DATA, p, buf, xp_countof(buf)) == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
xp_printf(XP_TEXT("%s"), buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -79,9 +93,16 @@ int xp_awk_closecmd (xp_awk_run_t* run, const xp_char_t* cmd, int* errnum)
|
|||||||
{
|
{
|
||||||
if (xp_strcmp(p->name,cmd) == 0)
|
if (xp_strcmp(p->name,cmd) == 0)
|
||||||
{
|
{
|
||||||
fclose ((FILE*)p->handle);
|
xp_awk_io_t pipe_io = run->awk->extio.pipe;
|
||||||
p->handle = XP_NULL;
|
|
||||||
|
|
||||||
|
if (pipe_io (XP_AWK_INPUT_CLOSE, p, XP_NULL, 0) == -1)
|
||||||
|
{
|
||||||
|
/* TODO: how to handle this... */
|
||||||
|
p->handle = XP_NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->handle = XP_NULL;
|
||||||
//if (opt_remove_closed_cmd)
|
//if (opt_remove_closed_cmd)
|
||||||
//{
|
//{
|
||||||
if (px != XP_NULL) px->next = p->next;
|
if (px != XP_NULL) px->next = p->next;
|
||||||
@ -90,6 +111,7 @@ int xp_awk_closecmd (xp_awk_run_t* run, const xp_char_t* cmd, int* errnum)
|
|||||||
xp_free (p->name);
|
xp_free (p->name);
|
||||||
xp_free (p);
|
xp_free (p);
|
||||||
//}
|
//}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
px = p;
|
px = p;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: run.c,v 1.97 2006-06-18 10:53:06 bacon Exp $
|
* $Id: run.c,v 1.98 2006-06-19 04:38:51 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -21,7 +21,8 @@
|
|||||||
#define STACK_LOCAL(run,n) STACK_AT(run,3+(xp_size_t)STACK_NARGS(run)+1+(n))
|
#define STACK_LOCAL(run,n) STACK_AT(run,3+(xp_size_t)STACK_NARGS(run)+1+(n))
|
||||||
#define STACK_RETVAL(run) STACK_AT(run,2)
|
#define STACK_RETVAL(run) STACK_AT(run,2)
|
||||||
#define STACK_GLOBAL(run,n) ((run)->stack[(n)])
|
#define STACK_GLOBAL(run,n) ((run)->stack[(n)])
|
||||||
#define STACK_RETVAL_GLOBAL(run) ((run)->stack[(run)->nglobals+2])
|
/*#define STACK_RETVAL_GLOBAL(run) ((run)->stack[(run)->nglobals+2])*/
|
||||||
|
#define STACK_RETVAL_GLOBAL(run) ((run)->stack[(run)->tree->nglobals+2])
|
||||||
|
|
||||||
#define EXIT_NONE 0
|
#define EXIT_NONE 0
|
||||||
#define EXIT_BREAK 1
|
#define EXIT_BREAK 1
|
||||||
@ -212,7 +213,8 @@ static int __open_run (
|
|||||||
run->opt = awk->opt.run;
|
run->opt = awk->opt.run;
|
||||||
run->errnum = XP_AWK_ENOERR;
|
run->errnum = XP_AWK_ENOERR;
|
||||||
run->tree = &awk->tree;
|
run->tree = &awk->tree;
|
||||||
run->nglobals = awk->tree.nglobals;
|
/*run->nglobals = awk->tree.nglobals;*/
|
||||||
|
run->awk = awk;
|
||||||
|
|
||||||
run->input.buf_pos = 0;
|
run->input.buf_pos = 0;
|
||||||
run->input.buf_len = 0;
|
run->input.buf_len = 0;
|
||||||
@ -284,7 +286,9 @@ static int __run_main (xp_awk_run_t* run)
|
|||||||
/* secure space for global variables */
|
/* secure space for global variables */
|
||||||
saved_stack_top = run->stack_top;
|
saved_stack_top = run->stack_top;
|
||||||
|
|
||||||
nglobals = run->nglobals;
|
/*nglobals = run->nglobals;*/
|
||||||
|
nglobals = run->tree->nglobals;
|
||||||
|
|
||||||
while (nglobals > 0)
|
while (nglobals > 0)
|
||||||
{
|
{
|
||||||
--nglobals;
|
--nglobals;
|
||||||
@ -337,14 +341,16 @@ static int __run_main (xp_awk_run_t* run)
|
|||||||
/* restore the stack top in a cheesy(?) way */
|
/* restore the stack top in a cheesy(?) way */
|
||||||
run->stack_top = saved_stack_top;
|
run->stack_top = saved_stack_top;
|
||||||
/* pops off global variables in a decent way */
|
/* pops off global variables in a decent way */
|
||||||
__raw_pop_times (run, run->nglobals);
|
/*__raw_pop_times (run, run->nglobals);*/
|
||||||
|
__raw_pop_times (run, run->tree->nglobals);
|
||||||
PANIC_I (run, XP_AWK_ENOMEM);
|
PANIC_I (run, XP_AWK_ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__raw_push(run,(void*)saved_stack_top) == -1)
|
if (__raw_push(run,(void*)saved_stack_top) == -1)
|
||||||
{
|
{
|
||||||
run->stack_top = saved_stack_top;
|
run->stack_top = saved_stack_top;
|
||||||
__raw_pop_times (run, run->nglobals);
|
/*__raw_pop_times (run, run->nglobals);*/
|
||||||
|
__raw_pop_times (run, run->tree->nglobals);
|
||||||
PANIC_I (run, XP_AWK_ENOMEM);
|
PANIC_I (run, XP_AWK_ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,7 +358,8 @@ static int __run_main (xp_awk_run_t* run)
|
|||||||
if (__raw_push(run,xp_awk_val_nil) == -1)
|
if (__raw_push(run,xp_awk_val_nil) == -1)
|
||||||
{
|
{
|
||||||
run->stack_top = saved_stack_top;
|
run->stack_top = saved_stack_top;
|
||||||
__raw_pop_times (run, run->nglobals);
|
/*__raw_pop_times (run, run->nglobals);*/
|
||||||
|
__raw_pop_times (run, run->tree->nglobals);
|
||||||
PANIC_I (run, XP_AWK_ENOMEM);
|
PANIC_I (run, XP_AWK_ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,7 +367,8 @@ static int __run_main (xp_awk_run_t* run)
|
|||||||
if (__raw_push(run,xp_awk_val_nil) == -1)
|
if (__raw_push(run,xp_awk_val_nil) == -1)
|
||||||
{
|
{
|
||||||
run->stack_top = saved_stack_top;
|
run->stack_top = saved_stack_top;
|
||||||
__raw_pop_times (run, run->nglobals);
|
/*__raw_pop_times (run, run->nglobals);*/
|
||||||
|
__raw_pop_times (run, run->tree->nglobals);
|
||||||
PANIC_I (run, XP_AWK_ENOMEM);
|
PANIC_I (run, XP_AWK_ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,7 +428,7 @@ xp_printf (XP_T("\n"));
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* pops off the global variables */
|
/* pops off the global variables */
|
||||||
nglobals = run->nglobals;
|
nglobals = run->tree->nglobals; /*run->nglobals */
|
||||||
while (nglobals > 0)
|
while (nglobals > 0)
|
||||||
{
|
{
|
||||||
--nglobals;
|
--nglobals;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.c,v 1.36 2006-06-18 13:43:28 bacon Exp $
|
* $Id: awk.c,v 1.37 2006-06-19 04:38:51 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk.h>
|
#include <xp/awk/awk.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef XP_CHAR_IS_CHAR
|
#ifdef XP_CHAR_IS_WCHAR
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -14,11 +14,17 @@
|
|||||||
#include <xp/bas/string.h>
|
#include <xp/bas/string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <tchar.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __STAND_ALONE
|
#ifdef __STAND_ALONE
|
||||||
#define xp_printf xp_awk_printf
|
#define xp_printf xp_awk_printf
|
||||||
extern int xp_awk_printf (const xp_char_t* fmt, ...);
|
extern int xp_awk_printf (const xp_char_t* fmt, ...);
|
||||||
#define xp_strcmp xp_awk_strcmp
|
#define xp_strcmp xp_awk_strcmp
|
||||||
extern int xp_awk_strcmp (const xp_char_t* s1, const xp_char_t* s2);
|
extern int xp_awk_strcmp (const xp_char_t* s1, const xp_char_t* s2);
|
||||||
|
#define xp_strlen xp_awk_strlen
|
||||||
|
extern int xp_awk_strlen (const xp_char_t* s);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32) && defined(__STAND_ALONE) && defined(_DEBUG)
|
#if defined(_WIN32) && defined(__STAND_ALONE) && defined(_DEBUG)
|
||||||
@ -128,6 +134,52 @@ static xp_ssize_t process_data (
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static xp_ssize_t process_extio_pipe (
|
||||||
|
int cmd, void* arg, xp_char_t* data, xp_size_t size)
|
||||||
|
{
|
||||||
|
xp_awk_cmd_t* epa = (xp_awk_cmd_t*)arg;
|
||||||
|
|
||||||
|
switch (cmd)
|
||||||
|
{
|
||||||
|
case XP_AWK_INPUT_OPEN:
|
||||||
|
{
|
||||||
|
FILE* handle;
|
||||||
|
handle = _tpopen (epa->name, XP_T("r"));
|
||||||
|
if (handle == NULL) return -1;
|
||||||
|
epa->handle = (void*)handle;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case XP_AWK_INPUT_CLOSE:
|
||||||
|
{
|
||||||
|
fclose ((FILE*)epa->handle);
|
||||||
|
epa->handle = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case XP_AWK_INPUT_DATA:
|
||||||
|
{
|
||||||
|
if (_fgetts (data, size, epa->handle) == XP_NULL)
|
||||||
|
return 0;
|
||||||
|
return xp_strlen(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
case XP_AWK_INPUT_NEXT:
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
case XP_AWK_OUTPUT_OPEN:
|
||||||
|
case XP_AWK_OUTPUT_CLOSE:
|
||||||
|
case XP_AWK_OUTPUT_DATA:
|
||||||
|
case XP_AWK_OUTPUT_NEXT:
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(__STAND_ALONE) && !defined(_WIN32)
|
#if defined(__STAND_ALONE) && !defined(_WIN32)
|
||||||
static int __main (int argc, char* argv[])
|
static int __main (int argc, char* argv[])
|
||||||
#else
|
#else
|
||||||
@ -150,6 +202,14 @@ static int __main (int argc, xp_char_t* argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO: */
|
||||||
|
if (xp_awk_setextio (awk, process_extio_pipe, XP_NULL) == -1)
|
||||||
|
{
|
||||||
|
xp_awk_close (awk);
|
||||||
|
xp_printf (XP_T("Error: cannot attach source\n"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
xp_awk_setparseopt (awk,
|
xp_awk_setparseopt (awk,
|
||||||
XP_AWK_EXPLICIT | XP_AWK_UNIQUE |
|
XP_AWK_EXPLICIT | XP_AWK_UNIQUE |
|
||||||
XP_AWK_SHADING | XP_AWK_IMPLICIT | XP_AWK_SHIFT | XP_AWK_EXTIO);
|
XP_AWK_SHADING | XP_AWK_IMPLICIT | XP_AWK_SHIFT | XP_AWK_EXTIO);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user