qse/ase/awk/awk_i.h

342 lines
6.2 KiB
C
Raw Normal View History

2006-03-31 16:35:37 +00:00
/*
2006-12-16 16:14:40 +00:00
* $Id: awk_i.h,v 1.92 2006-12-16 16:12:07 bacon Exp $
2006-03-31 16:35:37 +00:00
*/
2006-10-24 04:10:12 +00:00
#ifndef _ASE_AWK_AWKI_H_
#define _ASE_AWK_AWKI_H_
typedef struct ase_awk_chain_t ase_awk_chain_t;
typedef struct ase_awk_tree_t ase_awk_tree_t;
#include <ase/awk/awk.h>
#include <ase/awk/str.h>
#include <ase/awk/rex.h>
#include <ase/awk/map.h>
#include <ase/awk/tree.h>
#include <ase/awk/val.h>
#include <ase/awk/func.h>
#include <ase/awk/tab.h>
#include <ase/awk/parse.h>
#include <ase/awk/run.h>
#include <ase/awk/extio.h>
#include <ase/awk/misc.h>
2006-06-21 11:45:26 +00:00
2006-10-12 04:17:58 +00:00
#ifdef _MSC_VER
#pragma warning (disable: 4996)
2006-11-24 15:22:33 +00:00
#pragma warning (disable: 4296)
2006-05-12 09:39:20 +00:00
#endif
2006-10-27 10:28:53 +00:00
/* TODO: remove this */
#ifdef _WIN32
#include <tchar.h>
#define xp_printf _tprintf
#endif
2006-10-24 04:10:12 +00:00
#define ASE_AWK_MAX_GLOBALS 9999
#define ASE_AWK_MAX_LOCALS 9999
#define ASE_AWK_MAX_PARAMS 9999
2006-08-06 15:03:42 +00:00
2006-11-29 03:19:49 +00:00
#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
2006-10-12 04:17:58 +00:00
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
2006-10-24 04:10:12 +00:00
#define ASE_AWK_MALLOC(awk,size) malloc (size)
#define ASE_AWK_REALLOC(awk,ptr,size) realloc (ptr, size)
#define ASE_AWK_FREE(awk,ptr) free (ptr)
2006-09-01 04:03:28 +00:00
#else
2006-10-24 04:10:12 +00:00
#define ASE_AWK_MALLOC(awk,size) \
2006-12-13 14:13:07 +00:00
(awk)->sysfns.malloc (size, (awk)->sysfns.custom_data)
2006-10-24 04:10:12 +00:00
#define ASE_AWK_REALLOC(awk,ptr,size) \
2006-12-13 14:13:07 +00:00
(awk)->sysfns.realloc (ptr, size, (awk)->sysfns.custom_data)
2006-10-24 04:10:12 +00:00
#define ASE_AWK_FREE(awk,ptr) \
2006-12-13 14:13:07 +00:00
(awk)->sysfns.free (ptr, (awk)->sysfns.custom_data)
2006-09-01 04:03:28 +00:00
#endif
2006-10-24 04:10:12 +00:00
#define ASE_AWK_LOCK(awk) \
2006-09-01 04:03:28 +00:00
do { \
2006-12-13 14:13:07 +00:00
if ((awk)->sysfns.lock != ASE_NULL) \
2006-12-16 16:14:40 +00:00
(awk)->sysfns.lock ((awk)->sysfns.custom_data); \
2006-09-01 04:03:28 +00:00
} while (0)
2006-10-24 04:10:12 +00:00
#define ASE_AWK_UNLOCK(awk) \
2006-09-01 04:03:28 +00:00
do { \
2006-12-13 14:13:07 +00:00
if ((awk)->sysfns.unlock != ASE_NULL) \
2006-12-16 16:14:40 +00:00
(awk)->sysfns.unlock ((awk)->sysfns.custom_data); \
2006-09-01 04:03:28 +00:00
} while (0)
2006-08-31 14:52:12 +00:00
2006-12-13 14:13:07 +00:00
#define ASE_AWK_ISUPPER(awk,c) (awk)->sysfns.is_upper(c)
#define ASE_AWK_ISLOWER(awk,c) (awk)->sysfns.is_lower(c)
#define ASE_AWK_ISALPHA(awk,c) (awk)->sysfns.is_alpha(c)
#define ASE_AWK_ISDIGIT(awk,c) (awk)->sysfns.is_digit(c)
#define ASE_AWK_ISXDIGIT(awk,c) (awk)->sysfns.is_xdigit(c)
#define ASE_AWK_ISALNUM(awk,c) (awk)->sysfns.is_alnum(c)
#define ASE_AWK_ISSPACE(awk,c) (awk)->sysfns.is_space(c)
#define ASE_AWK_ISPRINT(awk,c) (awk)->sysfns.is_print(c)
#define ASE_AWK_ISGRAPH(awk,c) (awk)->sysfns.is_graph(c)
#define ASE_AWK_ISCNTRL(awk,c) (awk)->sysfns.is_cntrl(c)
#define ASE_AWK_ISPUNCT(awk,c) (awk)->sysfns.is_punct(c)
#define ASE_AWK_TOUPPER(awk,c) (awk)->sysfns.to_upper(c)
#define ASE_AWK_TOLOWER(awk,c) (awk)->sysfns.to_lower(c)
#define ASE_AWK_MEMCPY(awk,dst,src,len) (awk)->sysfns.memcpy (dst, src, len)
#define ASE_AWK_MEMSET(awk,dst,val,len) (awk)->sysfns.memset (dst, val, len)
2006-10-24 04:10:12 +00:00
struct ase_awk_tree_t
2006-04-21 17:24:31 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t nglobals; /* total number of globals */
ase_size_t nbglobals; /* number of builtin globals */
ase_awk_map_t afns; /* awk function map */
ase_awk_nde_t* begin;
ase_awk_nde_t* end;
ase_awk_chain_t* chain;
ase_awk_chain_t* chain_tail;
ase_size_t chain_size; /* number of nodes in the chain */
2006-12-12 05:16:30 +00:00
int ok;
2006-04-21 17:24:31 +00:00
};
2006-10-24 04:10:12 +00:00
struct ase_awk_t
2006-03-31 16:35:37 +00:00
{
2006-12-13 14:13:07 +00:00
ase_awk_sysfns_t sysfns;
2006-08-31 15:09:24 +00:00
2006-03-31 16:35:37 +00:00
/* options */
2006-08-04 17:36:40 +00:00
int option;
2006-03-31 16:35:37 +00:00
/* parse tree */
2006-10-24 04:10:12 +00:00
ase_awk_tree_t tree;
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;
2006-10-28 12:17:57 +00:00
int stmnt; /* statement */
2006-08-01 15:57:43 +00:00
} id;
struct
{
2006-11-25 15:51:57 +00:00
struct
{
ase_size_t block;
ase_size_t loop;
ase_size_t expr; /* expression */
} cur;
struct
{
ase_size_t block;
ase_size_t expr;
} max;
2006-08-01 15:57:43 +00:00
} depth;
2006-10-24 04:10:12 +00:00
ase_awk_tab_t globals;
ase_awk_tab_t locals;
ase_awk_tab_t params;
ase_size_t nlocals_max;
2006-10-15 15:46:14 +00:00
2006-11-25 15:51:57 +00:00
ase_awk_nde_t* (*parse_block) (ase_awk_t*,ase_bool_t);
2006-03-31 16:35:37 +00:00
} parse;
2006-08-06 08:16:03 +00:00
/* source code management */
struct
2006-03-31 16:35:37 +00:00
{
2006-10-28 12:17:57 +00:00
ase_awk_srcios_t ios;
2006-08-06 08:16:03 +00:00
struct
{
2006-10-24 04:10:12 +00:00
ase_cint_t curc;
ase_cint_t ungotc[5];
ase_size_t ungotc_count;
2006-05-10 16:02:39 +00:00
2006-10-24 04:10:12 +00:00
ase_size_t line;
ase_size_t column;
2006-08-06 08:16:03 +00:00
} lex;
2006-05-13 16:33:07 +00:00
2006-08-06 08:16:03 +00:00
struct
{
2006-10-24 04:10:12 +00:00
ase_char_t buf[512];
ase_size_t buf_pos;
ase_size_t buf_len;
2006-08-06 08:16:03 +00:00
} shared;
} src;
2006-03-31 16:35:37 +00:00
/* token */
struct
{
2006-12-16 14:48:31 +00:00
struct
{
int type;
ase_size_t line;
ase_size_t column;
} prev;
2006-10-26 08:17:38 +00:00
int type;
2006-10-24 04:10:12 +00:00
ase_awk_str_t name;
ase_size_t line;
ase_size_t column;
2006-03-31 16:35:37 +00:00
} token;
2006-07-13 15:43:39 +00:00
/* builtin functions */
struct
{
2006-10-24 04:10:12 +00:00
ase_awk_bfn_t* sys;
ase_awk_bfn_t* user;
2006-07-13 15:43:39 +00:00
} bfn;
2006-08-10 16:02:15 +00:00
struct
{
2006-10-24 04:10:12 +00:00
ase_size_t count;
ase_awk_run_t* ptr;
2006-12-04 12:59:01 +00:00
struct
{
struct
{
ase_size_t block;
ase_size_t expr;
} cur;
struct
{
ase_size_t block;
ase_size_t expr;
} max;
} depth;
2006-08-10 16:02:15 +00:00
} run;
2006-03-31 16:35:37 +00:00
/* housekeeping */
2006-08-10 16:02:15 +00:00
int errnum;
2006-03-31 16:35:37 +00:00
};
2006-10-24 04:10:12 +00:00
struct ase_awk_chain_t
2006-03-31 16:35:37 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_nde_t* pattern;
ase_awk_nde_t* action;
ase_awk_chain_t* next;
2006-03-31 16:35:37 +00:00
};
2006-10-24 04:10:12 +00:00
struct ase_awk_run_t
2006-04-21 16:21:27 +00:00
{
2006-08-10 16:02:15 +00:00
int id;
2006-10-24 04:10:12 +00:00
ase_awk_map_t named;
2006-04-21 16:21:27 +00:00
void** stack;
2006-10-24 04:10:12 +00:00
ase_size_t stack_top;
ase_size_t stack_base;
ase_size_t stack_limit;
2006-04-21 16:21:27 +00:00
int exit_level;
2006-11-17 07:06:53 +00:00
ase_awk_val_int_t* icache[200]; /* TODO: choose the optimal size */
ase_awk_val_real_t* rcache[200]; /* TODO: choose the optimal size */
ase_awk_val_ref_t* fcache[200]; /* TODO: choose the optimal size */
2006-10-24 04:10:12 +00:00
ase_size_t icache_count;
ase_size_t rcache_count;
ase_size_t fcache_count;
2006-04-21 16:21:27 +00:00
2006-10-24 04:10:12 +00:00
ase_awk_nde_blk_t* active_block;
ase_byte_t* pattern_range_state;
2006-08-03 15:50:04 +00:00
2006-04-22 13:54:53 +00:00
struct
{
2006-10-24 04:10:12 +00:00
ase_char_t buf[1024];
ase_size_t buf_pos;
ase_size_t buf_len;
ase_bool_t eof;
2006-07-05 16:20:23 +00:00
2006-10-24 04:10:12 +00:00
ase_awk_str_t line;
ase_awk_val_t* d0; /* $0 */
2006-07-06 15:54:41 +00:00
2006-10-24 04:10:12 +00:00
ase_size_t maxflds;
ase_size_t nflds; /* NF */
2006-07-05 16:20:23 +00:00
struct
{
2006-10-24 04:10:12 +00:00
ase_char_t* ptr;
ase_size_t len;
ase_awk_val_t* val; /* $1 .. $NF */
2006-07-05 16:20:23 +00:00
}* flds;
2006-09-05 04:11:11 +00:00
2006-07-03 04:09:56 +00:00
} inrec;
2006-04-22 13:54:53 +00:00
2006-09-05 04:11:11 +00:00
struct
{
void* rs;
void* fs;
2006-09-08 15:26:49 +00:00
int ignorecase;
2006-10-24 04:10:12 +00:00
ase_size_t fnr;
2006-09-22 14:05:30 +00:00
2006-10-11 15:02:26 +00:00
struct
{
2006-10-24 04:10:12 +00:00
ase_char_t* ptr;
ase_size_t len;
2006-10-11 15:02:26 +00:00
} convfmt;
2006-09-29 11:18:13 +00:00
struct
{
2006-10-24 04:10:12 +00:00
ase_char_t* ptr;
ase_size_t len;
2006-09-29 11:18:13 +00:00
} ofmt;
2006-09-22 14:05:30 +00:00
struct
{
2006-10-24 04:10:12 +00:00
ase_char_t* ptr;
ase_size_t len;
2006-09-22 14:05:30 +00:00
} ofs;
struct
2006-09-29 11:18:13 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t* ptr;
ase_size_t len;
2006-09-29 11:18:13 +00:00
} ors;
struct
2006-09-22 14:05:30 +00:00
{
2006-10-24 04:10:12 +00:00
ase_char_t* ptr;
ase_size_t len;
2006-09-22 14:05:30 +00:00
} subsep;
} global;
2006-09-05 04:11:11 +00:00
2006-06-21 13:52:15 +00:00
/* extio chain */
2006-08-10 16:02:15 +00:00
struct
{
2006-10-24 04:10:12 +00:00
ase_awk_io_t handler[ASE_AWK_EXTIO_NUM];
2006-10-13 10:18:39 +00:00
void* custom_data;
2006-10-24 04:10:12 +00:00
ase_awk_extio_t* chain;
2006-08-10 16:02:15 +00:00
} extio;
2006-06-16 07:37:27 +00:00
2006-11-12 15:10:41 +00:00
struct
{
2006-11-13 15:08:54 +00:00
ase_awk_str_t fmt;
ase_awk_str_t out;
2006-11-18 15:36:57 +00:00
struct
{
ase_char_t* ptr;
ase_size_t len;
2006-11-19 10:03:18 +00:00
ase_size_t inc;
2006-11-18 15:36:57 +00:00
} tmp;
2006-11-19 10:03:18 +00:00
} format;
2006-11-12 15:10:41 +00:00
2006-12-04 12:59:01 +00:00
struct
{
struct
{
ase_size_t block;
ase_size_t expr; /* expression */
} cur;
struct
{
ase_size_t block;
ase_size_t expr;
} max;
} depth;
2006-08-10 16:02:15 +00:00
int errnum;
2006-12-16 14:48:31 +00:00
ase_char_t errmsg[256];
2006-11-28 04:30:57 +00:00
void* custom_data;
2006-10-24 04:10:12 +00:00
ase_awk_t* awk;
2006-11-28 04:30:57 +00:00
2006-10-24 04:10:12 +00:00
ase_awk_run_t* prev;
ase_awk_run_t* next;
2006-06-16 07:37:27 +00:00
};
2006-03-31 16:35:37 +00:00
#endif