qse/ase/awk/awk_i.h

356 lines
6.4 KiB
C
Raw Normal View History

2006-03-31 16:35:37 +00:00
/*
2007-02-23 15:22:36 +00:00
* $Id: awk_i.h,v 1.103 2007-02-23 15:18:36 bacon Exp $
2007-02-03 10:47:41 +00:00
*
* {License}
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_
2007-02-23 08:17:51 +00:00
#include <ase/cmn/mem.h>
#include <ase/cmn/str.h>
2006-10-24 04:10:12 +00:00
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/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
2007-02-23 15:22:36 +00:00
#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#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)
#else
#define ASE_AWK_MALLOC(awk,size) ASE_MALLOC(&(awk)->prmfns.mmgr,size)
#define ASE_AWK_REALLOC(awk,ptr,size) ASE_REALLOC(&(awk)->prmfns.mmgr,ptr,size)
#define ASE_AWK_FREE(awk,ptr) ASE_FREE(&(awk)->prmfns.mmgr,ptr)
#endif
2007-02-23 08:17:51 +00:00
#define ASE_AWK_ISUPPER(awk,c) ASE_ISUPPER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISLOWER(awk,c) ASE_ISLOWER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISALPHA(awk,c) ASE_ISALPHA(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISDIGIT(awk,c) ASE_ISDIGIT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISXDIGIT(awk,c) ASE_ISXDIGIT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISALNUM(awk,c) ASE_ISALNUM(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISSPACE(awk,c) ASE_ISSPACE(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISPRINT(awk,c) ASE_ISPRINT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISGRAPH(awk,c) ASE_ISGRAPH(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISCNTRL(awk,c) ASE_ISCNTRL(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISPUNCT(awk,c) ASE_ISPUNCT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_TOUPPER(awk,c) ASE_TOUPPER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_TOLOWER(awk,c) ASE_TOLOWER(&(awk)->prmfns.ccls,c)
2006-09-01 04:03:28 +00:00
2006-10-24 04:10:12 +00:00
#define ASE_AWK_LOCK(awk) \
2006-09-01 04:03:28 +00:00
do { \
2007-02-23 08:17:51 +00:00
if ((awk)->prmfns.misc.lock != ASE_NULL) \
(awk)->prmfns.misc.lock ((awk)->prmfns.misc.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 { \
2007-02-23 08:17:51 +00:00
if ((awk)->prmfns.misc.unlock != ASE_NULL) \
(awk)->prmfns.misc.unlock ((awk)->prmfns.misc.custom_data); \
2006-09-01 04:03:28 +00:00
} while (0)
2006-08-31 14:52:12 +00:00
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
{
2007-02-01 08:38:24 +00:00
ase_awk_prmfns_t prmfns;
2007-01-25 14:14:56 +00:00
void* custom_data;
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-12-19 14:20:30 +00:00
ase_awk_nde_t* (*parse_block) (
ase_awk_t*,ase_size_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];
2007-02-07 14:51:44 +00:00
ase_size_t ungotc_line[5];
ase_size_t ungotc_column[5];
2006-10-24 04:10:12 +00:00
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;
2007-02-23 08:17:51 +00:00
ase_str_t name;
2006-10-24 04:10:12 +00:00
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;
2007-01-06 15:45:50 +00:00
ase_size_t expr;
} max;
} depth;
} run;
2006-12-04 12:59:01 +00:00
2007-01-06 15:45:50 +00:00
struct
{
struct
{
2006-12-04 12:59:01 +00:00
struct
{
2007-01-06 15:45:50 +00:00
ase_size_t build;
ase_size_t match;
2006-12-04 12:59:01 +00:00
} max;
} depth;
2007-01-06 15:45:50 +00:00
} rex;
2006-08-10 16:02:15 +00:00
2006-03-31 16:35:37 +00:00
/* housekeeping */
2006-08-10 16:02:15 +00:00
int errnum;
2006-12-19 14:20:30 +00:00
ase_size_t errlin;
ase_char_t errmsg[256];
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
2007-02-23 08:17:51 +00:00
ase_str_t line;
2006-10-24 04:10:12 +00:00
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
{
2007-02-23 08:17:51 +00:00
ase_str_t fmt;
ase_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-12-30 08:54:43 +00:00
ase_size_t runlin; /* line no. of the node being executed currently */
2006-08-10 16:02:15 +00:00
int errnum;
2006-12-17 14:56:07 +00:00
ase_size_t errlin;
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