qse/ase/awk/awk.h

118 lines
2.0 KiB
C
Raw Normal View History

2005-11-05 17:54:00 +00:00
/*
2006-01-11 14:03:17 +00:00
* $Id: awk.h,v 1.10 2006-01-11 14:03:17 bacon Exp $
2005-11-05 17:54:00 +00:00
*/
#ifndef _XP_AWK_AWK_H_
#define _XP_AWK_AWK_H_
#include <xp/types.h>
#include <xp/macros.h>
2005-12-29 12:04:51 +00:00
#include <xp/bas/str.h>
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-11 14:03:17 +00:00
XP_AWK_ERPAREN, /* right parenthesis expected */
2006-01-10 13:57:54 +00:00
XP_AWK_ESEMICOLON, /* semicolon expected */
XP_AWK_EEXPR /* expression 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);
enum
{
XP_AWK_IO_OPEN,
XP_AWK_IO_CLOSE,
XP_AWK_IO_DATA
};
struct xp_awk_t
{
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;
xp_awk_io_t inp_func;
xp_awk_io_t outp_func;
2005-11-07 16:02:44 +00:00
2005-12-29 12:04:51 +00:00
void* src_arg;
void* inp_arg;
void* outp_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);
int xp_awk_attinp (xp_awk_t* awk, xp_awk_io_t inp, void* arg);
int xp_awk_detinp (xp_awk_t* awk);
int xp_awk_attoutp (xp_awk_t* awk, xp_awk_io_t outp, void* arg);
int xp_awk_detoutp (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