2006-03-31 16:35:37 +00:00
|
|
|
/*
|
2006-08-01 15:57:43 +00:00
|
|
|
* $Id: awk_i.h,v 1.36 2006-08-01 15:57:42 bacon Exp $
|
2006-03-31 16:35:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _XP_AWK_AWKI_H_
|
|
|
|
#define _XP_AWK_AWKI_H_
|
|
|
|
|
2006-04-21 17:24:31 +00:00
|
|
|
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;
|
2006-05-12 09:39:20 +00:00
|
|
|
|
2006-03-31 16:35:37 +00:00
|
|
|
#include <xp/awk/awk.h>
|
|
|
|
|
2006-04-16 04:31:38 +00:00
|
|
|
#ifdef XP_AWK_STAND_ALONE
|
2006-03-31 16:35:37 +00:00
|
|
|
#include <xp/awk/sa.h>
|
|
|
|
#else
|
|
|
|
#include <xp/bas/str.h>
|
|
|
|
#endif
|
|
|
|
|
2006-07-25 16:41:40 +00:00
|
|
|
#include <xp/awk/rex.h>
|
2006-06-21 11:45:26 +00:00
|
|
|
#include <xp/awk/map.h>
|
|
|
|
#include <xp/awk/val.h>
|
|
|
|
#include <xp/awk/func.h>
|
|
|
|
#include <xp/awk/tree.h>
|
|
|
|
#include <xp/awk/tab.h>
|
|
|
|
#include <xp/awk/run.h>
|
|
|
|
#include <xp/awk/extio.h>
|
|
|
|
|
2006-06-30 04:18:47 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma warning (disable: 4996)
|
|
|
|
#endif
|
|
|
|
|
2006-05-12 09:39:20 +00:00
|
|
|
#if defined(_WIN32) && defined(XP_AWK_STAND_ALONE) && defined(_DEBUG)
|
|
|
|
#define _CRTDBG_MAP_ALLOC
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#endif
|
|
|
|
|
2006-04-21 06:06:32 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
struct xp_awk_parse_t
|
|
|
|
{
|
|
|
|
int opt;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xp_awk_run_t
|
|
|
|
{
|
|
|
|
int opt;
|
|
|
|
};
|
|
|
|
|
|
|
|
awk = xp_awk_open ();
|
2006-04-21 16:21:27 +00:00
|
|
|
xp_awk_parse (awk, source_input, source_output);
|
2006-04-21 06:06:32 +00:00
|
|
|
thr = create_thread (5);
|
|
|
|
|
2006-04-21 16:21:27 +00:00
|
|
|
thr[0]->xp_awk_run (awk, input_stream1, output_stream1);
|
|
|
|
thr[1]->xp_awk_run (awk, input_stream2, output_stream2);
|
|
|
|
thr[2]->xp_awk_run (awk, input_stream3, output_stream3);
|
2006-04-21 06:06:32 +00:00
|
|
|
|
|
|
|
xp_awk_setcallback (void* __command_callback (int cmd, void* arg), void* arg);
|
|
|
|
xp_awk_run (awk)
|
|
|
|
{
|
|
|
|
run_stack = malloc (run_stack_size);
|
|
|
|
while ()
|
|
|
|
{
|
|
|
|
if (command_callback) if (command_callback (XP_AWK_ABORT) == yes) break;
|
|
|
|
run with run_stack
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2006-04-21 17:24:31 +00:00
|
|
|
struct xp_awk_tree_t
|
|
|
|
{
|
|
|
|
xp_size_t nglobals;
|
2006-06-20 15:27:50 +00:00
|
|
|
xp_awk_map_t afns; /* awk function map */
|
2006-04-21 17:24:31 +00:00
|
|
|
xp_awk_nde_t* begin;
|
|
|
|
xp_awk_nde_t* end;
|
|
|
|
xp_awk_chain_t* chain;
|
|
|
|
xp_awk_chain_t* chain_tail;
|
|
|
|
};
|
|
|
|
|
2006-03-31 16:35:37 +00:00
|
|
|
struct xp_awk_t
|
|
|
|
{
|
|
|
|
/* options */
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
int parse;
|
|
|
|
int run;
|
|
|
|
} opt;
|
|
|
|
|
|
|
|
/* io functions */
|
2006-04-22 13:54:53 +00:00
|
|
|
xp_awk_io_t srcio;
|
|
|
|
void* srcio_arg;
|
2006-03-31 16:35:37 +00:00
|
|
|
|
|
|
|
/* parse tree */
|
2006-04-21 17:24:31 +00:00
|
|
|
xp_awk_tree_t tree;
|
2006-08-01 15:57:43 +00:00
|
|
|
int state;
|
2006-03-31 16:35:37 +00:00
|
|
|
|
|
|
|
/* temporary information that the parser needs */
|
|
|
|
struct
|
|
|
|
{
|
2006-08-01 15:57:43 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
int block;
|
|
|
|
int loop;
|
|
|
|
} id;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
xp_size_t loop;
|
|
|
|
} depth;
|
|
|
|
|
2006-03-31 16:35:37 +00:00
|
|
|
xp_awk_tab_t globals;
|
|
|
|
xp_awk_tab_t locals;
|
|
|
|
xp_awk_tab_t params;
|
|
|
|
xp_size_t nlocals_max;
|
|
|
|
} parse;
|
|
|
|
|
|
|
|
/* source buffer management */
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
xp_cint_t curc;
|
|
|
|
xp_cint_t ungotc[5];
|
|
|
|
xp_size_t ungotc_count;
|
2006-05-10 16:02:39 +00:00
|
|
|
|
|
|
|
xp_char_t buf[512];
|
|
|
|
xp_size_t buf_pos;
|
|
|
|
xp_size_t buf_len;
|
2006-05-13 16:33:07 +00:00
|
|
|
|
|
|
|
xp_size_t line;
|
|
|
|
xp_size_t column;
|
2006-03-31 16:35:37 +00:00
|
|
|
} lex;
|
|
|
|
|
2006-06-19 09:10:57 +00:00
|
|
|
xp_awk_io_t extio[XP_AWK_EXTIO_NUM];
|
2006-06-18 13:43:28 +00:00
|
|
|
|
2006-03-31 16:35:37 +00:00
|
|
|
/* token */
|
|
|
|
struct
|
|
|
|
{
|
2006-06-27 10:53:04 +00:00
|
|
|
int prev;
|
2006-03-31 16:35:37 +00:00
|
|
|
int type;
|
|
|
|
xp_str_t name;
|
2006-05-13 16:33:07 +00:00
|
|
|
xp_size_t line;
|
|
|
|
xp_size_t column;
|
2006-03-31 16:35:37 +00:00
|
|
|
} token;
|
|
|
|
|
2006-07-13 15:43:39 +00:00
|
|
|
/* builtin functions */
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
xp_awk_bfn_t* sys;
|
|
|
|
xp_awk_bfn_t* user;
|
|
|
|
} bfn;
|
|
|
|
|
2006-03-31 16:35:37 +00:00
|
|
|
/* housekeeping */
|
2006-07-26 16:43:35 +00:00
|
|
|
short errnum;
|
|
|
|
short suberrnum;
|
2006-03-31 16:35:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct xp_awk_chain_t
|
|
|
|
{
|
|
|
|
xp_awk_nde_t* pattern;
|
|
|
|
xp_awk_nde_t* action;
|
|
|
|
xp_awk_chain_t* next;
|
|
|
|
};
|
|
|
|
|
2006-04-21 16:21:27 +00:00
|
|
|
struct xp_awk_run_t
|
|
|
|
{
|
|
|
|
xp_awk_map_t named;
|
|
|
|
|
|
|
|
void** stack;
|
|
|
|
xp_size_t stack_top;
|
|
|
|
xp_size_t stack_base;
|
|
|
|
xp_size_t stack_limit;
|
|
|
|
int exit_level;
|
|
|
|
|
2006-07-01 16:07:06 +00:00
|
|
|
xp_awk_val_int_t* icache[100]; /* TODO: choose the optimal size */
|
|
|
|
xp_awk_val_real_t* rcache[100]; /* TODO: choose the optimal size */
|
2006-04-21 16:21:27 +00:00
|
|
|
xp_size_t icache_count;
|
|
|
|
xp_size_t rcache_count;
|
|
|
|
|
2006-04-22 13:54:53 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
xp_char_t buf[1024];
|
|
|
|
xp_size_t buf_pos;
|
|
|
|
xp_size_t buf_len;
|
|
|
|
xp_bool_t eof;
|
2006-07-05 16:20:23 +00:00
|
|
|
|
2006-07-06 15:54:41 +00:00
|
|
|
xp_str_t line;
|
|
|
|
xp_awk_val_t* d0; /* $0 */
|
|
|
|
|
2006-07-07 09:48:23 +00:00
|
|
|
xp_size_t maxflds;
|
2006-07-06 15:54:41 +00:00
|
|
|
xp_size_t nflds; /* NF */
|
2006-07-05 16:20:23 +00:00
|
|
|
struct
|
|
|
|
{
|
2006-07-06 15:54:41 +00:00
|
|
|
xp_char_t* ptr;
|
|
|
|
xp_size_t len;
|
|
|
|
xp_awk_val_t* val; /* $1 .. $NF */
|
2006-07-05 16:20:23 +00:00
|
|
|
}* flds;
|
2006-07-03 04:09:56 +00:00
|
|
|
} inrec;
|
2006-04-22 13:54:53 +00:00
|
|
|
|
2006-06-21 13:52:15 +00:00
|
|
|
/* extio chain */
|
|
|
|
xp_awk_extio_t* extio;
|
2006-06-16 07:37:27 +00:00
|
|
|
|
2006-04-21 17:24:31 +00:00
|
|
|
int opt;
|
2006-07-26 16:43:35 +00:00
|
|
|
short errnum;
|
|
|
|
short suberrnum;
|
2006-04-21 16:21:27 +00:00
|
|
|
|
2006-06-19 09:10:57 +00:00
|
|
|
/*xp_awk_tree_t* tree;
|
|
|
|
xp_size_t nglobals;*/
|
2006-06-19 04:38:51 +00:00
|
|
|
xp_awk_t* awk;
|
2006-06-16 07:37:27 +00:00
|
|
|
};
|
|
|
|
|
2006-03-31 16:35:37 +00:00
|
|
|
#endif
|