qse/ase/awk/awk.h

139 lines
2.4 KiB
C
Raw Normal View History

2005-11-05 17:54:00 +00:00
/*
2006-01-19 16:28:21 +00:00
* $Id: awk.h,v 1.15 2006-01-19 16:28:21 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-01-09 12:51:47 +00:00
#include <xp/awk/tree.h>
2005-11-05 17:54:00 +00:00
2005-11-06 12:01:29 +00:00
enum
{
2005-11-07 16:02:44 +00:00
XP_AWK_ENOERR,
2005-11-14 15:23:54 +00:00
XP_AWK_ENOMEM, /* out of memory */
2005-11-07 16:02:44 +00:00
XP_AWK_ESRCOP,
2005-11-14 15:23:54 +00:00
XP_AWK_ESRCCL,
XP_AWK_ESRCDT, /* error in reading source */
2006-01-09 12:51:47 +00:00
2005-11-14 15:23:54 +00:00
XP_AWK_ELXCHR, /* lexer came accross an wrong character */
2006-01-09 12:51:47 +00:00
XP_AWK_ELXUNG, /* lexer failed to unget a character */
2006-01-09 16:03:56 +00:00
XP_AWK_EENDSRC, /* unexpected end of source */
XP_AWK_ELBRACE, /* left brace expected */
2006-01-14 16:09:58 +00:00
XP_AWK_ELPAREN, /* left parenthesis expected */
2006-01-11 14:03:17 +00:00
XP_AWK_ERPAREN, /* right parenthesis expected */
2006-01-19 16:28:21 +00:00
XP_AWK_ERBRACK, /* right bracket expected */
2006-01-13 14:16:56 +00:00
XP_AWK_ECOMMA, /* comma expected */
2006-01-10 13:57:54 +00:00
XP_AWK_ESEMICOLON, /* semicolon expected */
2006-01-19 10:56:35 +00:00
XP_AWK_EEXPR, /* expression expected */
2006-01-19 16:28:21 +00:00
XP_AWK_EWHILE, /* keyword 'while' is expected */
XP_AWK_EASSIGN /* assignment statement expected */
2005-11-06 12:01:29 +00:00
};
2005-11-05 17:54:00 +00:00
/*
* TYPE: xp_awk_t
*/
typedef struct xp_awk_t xp_awk_t;
/*
* 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-19 16:28:21 +00:00
/* options */
enum
{
XP_AWK_ASSIGN_ONLY /* a non-assignment expression cannot be used as a statement */
};
2005-11-05 17:54:00 +00:00
struct xp_awk_t
{
2006-01-19 16:28:21 +00:00
/* options */
int opt;
2006-01-09 12:51:47 +00:00
/* parse tree */
xp_awk_node_t* tree;
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
2005-11-07 16:02:44 +00:00
/* source buffer management */
struct {
xp_cint_t curc;
xp_cint_t ungotc[5];
xp_size_t ungotc_count;
} lex;
2005-11-14 15:23:54 +00:00
/* token */
struct {
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
};
#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);
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);
2005-11-05 17:54:00 +00:00
#ifdef __cplusplus
}
#endif
#endif