qse/ase/awk/awk.h

175 lines
2.9 KiB
C
Raw Normal View History

2005-11-05 17:54:00 +00:00
/*
2006-03-07 15:55:14 +00:00
* $Id: awk.h,v 1.33 2006-03-07 15:55:14 bacon Exp $
2005-11-05 17:54:00 +00:00
*/
#ifndef _XP_AWK_AWK_H_
#define _XP_AWK_AWK_H_
2006-01-18 15:16:01 +00:00
#ifdef __STAND_ALONE
#include <xp/awk/sa.h>
#else
2005-11-05 17:54:00 +00:00
#include <xp/types.h>
#include <xp/macros.h>
2005-12-29 12:04:51 +00:00
#include <xp/bas/str.h>
2006-01-18 15:16:01 +00:00
#endif
2006-03-04 10:08:13 +00:00
#include <xp/awk/err.h>
2006-01-09 12:51:47 +00:00
#include <xp/awk/tree.h>
2006-01-29 18:28:14 +00:00
#include <xp/awk/tab.h>
2006-03-02 15:10:59 +00:00
#include <xp/awk/map.h>
2006-03-03 11:45:45 +00:00
#include <xp/awk/val.h>
2006-03-07 15:55:14 +00:00
#include <xp/awk/run.h>
2005-11-05 17:54:00 +00:00
/*
* TYPE: xp_awk_t
*/
typedef struct xp_awk_t xp_awk_t;
2006-02-07 15:28:05 +00:00
typedef struct xp_awk_chain_t xp_awk_chain_t;
2005-11-05 17:54:00 +00:00
/*
* TYPE: xp_awk_io_t
*/
typedef xp_ssize_t (*xp_awk_io_t) (
int cmd, void* arg, xp_char_t* data, xp_size_t count);
2006-01-19 16:28:21 +00:00
/* io function commands */
2005-11-05 17:54:00 +00:00
enum
{
XP_AWK_IO_OPEN,
XP_AWK_IO_CLOSE,
XP_AWK_IO_DATA
};
2006-01-31 16:57:45 +00:00
/* parse options */
2006-01-19 16:28:21 +00:00
enum
{
2006-02-05 13:45:59 +00:00
XP_AWK_IMPLICIT = (1 << 0), /* allow undeclared variables */
XP_AWK_EXPLICIT = (1 << 1), /* variable requires explicit declaration */
XP_AWK_UNIQUE = (1 << 2), /* a function name should not coincide to be a variable name */
2006-02-08 16:14:31 +00:00
XP_AWK_SHADING = (1 << 3), /* allow variable shading */
XP_AWK_SHIFT = (1 << 4) /* support shift operators */
2006-01-19 16:28:21 +00:00
};
2005-11-05 17:54:00 +00:00
struct xp_awk_t
{
2006-01-19 16:28:21 +00:00
/* options */
2006-01-31 16:57:45 +00:00
struct
{
int parse;
int run;
} opt;
2006-01-19 16:28:21 +00:00
2005-11-05 17:54:00 +00:00
/* io functions */
2005-12-29 12:04:51 +00:00
xp_awk_io_t src_func;
2006-01-19 16:28:21 +00:00
xp_awk_io_t in_func;
xp_awk_io_t out_func;
2005-11-07 16:02:44 +00:00
2005-12-29 12:04:51 +00:00
void* src_arg;
2006-01-19 16:28:21 +00:00
void* in_arg;
void* out_arg;
2005-11-05 17:54:00 +00:00
2006-01-22 15:11:17 +00:00
/* parse tree */
struct
{
2006-02-05 16:00:33 +00:00
xp_size_t nglobals;
2006-03-02 15:10:59 +00:00
xp_awk_map_t funcs;
2006-03-03 11:45:45 +00:00
xp_awk_nde_t* begin;
xp_awk_nde_t* end;
2006-02-07 15:28:05 +00:00
xp_awk_chain_t* chain;
xp_awk_chain_t* chain_tail;
2006-01-22 15:11:17 +00:00
} tree;
2006-01-25 16:11:43 +00:00
/* temporary information that the parser needs */
struct
{
2006-02-04 19:31:51 +00:00
xp_awk_tab_t globals;
xp_awk_tab_t locals;
2006-01-31 16:57:45 +00:00
xp_awk_tab_t params;
2006-02-04 19:31:51 +00:00
xp_size_t nlocals_max;
2006-01-25 16:11:43 +00:00
} parse;
2006-02-23 15:37:34 +00:00
/* run-time data structure */
struct
{
2006-03-02 15:10:59 +00:00
xp_awk_map_t named;
2006-03-07 15:55:14 +00:00
void* stack;
xp_size_t stack_top;
xp_size_t stack_limit;
2006-02-23 15:37:34 +00:00
} run;
2005-11-07 16:02:44 +00:00
/* source buffer management */
2006-01-22 15:11:17 +00:00
struct
{
2005-11-07 16:02:44 +00:00
xp_cint_t curc;
xp_cint_t ungotc[5];
xp_size_t ungotc_count;
} lex;
2005-11-14 15:23:54 +00:00
/* token */
2006-01-22 15:11:17 +00:00
struct
{
2005-11-14 15:23:54 +00:00
int type;
xp_str_t name;
} token;
2005-11-05 17:54:00 +00:00
/* housekeeping */
2005-11-06 12:01:29 +00:00
int errnum;
2005-12-05 15:11:29 +00:00
xp_bool_t __dynamic;
2005-11-05 17:54:00 +00:00
};
2006-02-07 15:28:05 +00:00
struct xp_awk_chain_t
{
2006-03-03 11:45:45 +00:00
xp_awk_nde_t* pattern;
xp_awk_nde_t* action;
2006-02-07 15:28:05 +00:00
xp_awk_chain_t* next;
};
2005-11-05 17:54:00 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2005-12-29 12:04:51 +00:00
/*
* FUNCTION: xp_awk_open
*/
2005-11-05 17:54:00 +00:00
xp_awk_t* xp_awk_open (xp_awk_t* awk);
2005-12-29 12:04:51 +00:00
/*
* FUNCTION: xp_awk_close
*/
2005-11-05 17:54:00 +00:00
int xp_awk_close (xp_awk_t* awk);
2006-01-31 16:57:45 +00:00
int xp_awk_geterrnum (xp_awk_t* awk);
const xp_char_t* xp_awk_geterrstr (xp_awk_t* awk);
2006-01-24 16:14:28 +00:00
/*
* FUNCTION: xp_awk_clear
*/
void xp_awk_clear (xp_awk_t* awk);
2005-12-29 12:04:51 +00:00
/*
* FUNCTION: xp_awk_attsrc
*/
int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg);
/*
* FUNCTION: xp_awk_detsrc
*/
int xp_awk_detsrc (xp_awk_t* awk);
2006-01-19 16:28:21 +00:00
int xp_awk_attin (xp_awk_t* awk, xp_awk_io_t in, void* arg);
int xp_awk_detin (xp_awk_t* awk);
2005-12-29 12:04:51 +00:00
2006-01-19 16:28:21 +00:00
int xp_awk_attout (xp_awk_t* awk, xp_awk_io_t out, void* arg);
int xp_awk_detout (xp_awk_t* awk);
2005-11-07 16:02:44 +00:00
2006-01-09 16:03:56 +00:00
int xp_awk_parse (xp_awk_t* awk);
2006-01-26 15:35:20 +00:00
int xp_awk_run (xp_awk_t* awk);
2006-01-09 16:03:56 +00:00
2005-11-05 17:54:00 +00:00
#ifdef __cplusplus
}
#endif
#endif