qse/ase/awk/awk.h

198 lines
5.6 KiB
C
Raw Normal View History

2005-11-05 17:54:00 +00:00
/*
2006-07-05 16:20:23 +00:00
* $Id: awk.h,v 1.77 2006-07-05 16:20:23 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>
2006-01-18 15:16:01 +00:00
2006-03-27 11:43:17 +00:00
typedef struct xp_awk_t xp_awk_t;
2006-06-22 04:25:44 +00:00
typedef struct xp_awk_val_t xp_awk_val_t;
typedef struct xp_awk_extio_t xp_awk_extio_t;
2006-03-27 11:43:17 +00:00
2005-11-05 17:54:00 +00:00
typedef xp_ssize_t (*xp_awk_io_t) (
2006-06-22 04:25:44 +00:00
int cmd, int opt, void* arg, xp_char_t* data, xp_size_t count);
2006-06-19 04:38:51 +00:00
2006-06-19 09:10:57 +00:00
struct xp_awk_extio_t
2006-06-19 04:38:51 +00:00
{
2006-06-21 13:52:15 +00:00
int type;
2006-06-28 14:19:01 +00:00
2006-06-19 04:38:51 +00:00
xp_char_t* name;
void* handle;
2006-06-28 14:19:01 +00:00
/* input buffer */
struct
{
xp_char_t buf[2048];
xp_size_t pos;
xp_size_t len;
xp_bool_t eof;
} in;
2006-06-19 09:10:57 +00:00
xp_awk_extio_t* next;
2006-06-19 04:38:51 +00:00
};
2006-01-19 16:28:21 +00:00
/* io function commands */
2005-11-05 17:54:00 +00:00
enum
{
2006-06-22 04:25:44 +00:00
XP_AWK_IO_OPEN = 0,
XP_AWK_IO_CLOSE = 1,
XP_AWK_IO_READ = 2,
XP_AWK_IO_WRITE = 3,
XP_AWK_IO_NEXT = 4
};
enum
{
2006-06-25 15:26:57 +00:00
XP_AWK_IO_PIPE_READ = 0,
XP_AWK_IO_PIPE_WRITE = 1,
2006-06-22 04:25:44 +00:00
2006-06-25 15:26:57 +00:00
XP_AWK_IO_FILE_READ = 0,
XP_AWK_IO_FILE_WRITE = 1,
XP_AWK_IO_FILE_APPEND = 2,
XP_AWK_IO_CONSOLE_READ = 0,
XP_AWK_IO_CONSOLE_WRITE = 1
2005-11-05 17:54:00 +00:00
};
2006-01-31 16:57:45 +00:00
/* parse options */
2006-01-19 16:28:21 +00:00
enum
{
2006-04-24 11:36:12 +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 */
XP_AWK_SHADING = (1 << 3), /* allow variable shading */
XP_AWK_SHIFT = (1 << 4), /* support shift operators */
XP_AWK_HASHSIGN = (1 << 5), /* support comments by a hash sign */
2006-06-18 11:18:49 +00:00
XP_AWK_DBLSLASHES = (1 << 6), /* support comments by double slashes */
XP_AWK_EXTIO = (1 << 7) /* support getline and print */
2006-01-19 16:28:21 +00:00
};
2006-04-09 15:31:13 +00:00
/* run options */
enum
{
2006-04-14 10:56:42 +00:00
XP_AWK_RUNMAIN = (1 << 0) /* execution starts from main */
2006-04-09 15:31:13 +00:00
};
2006-04-02 12:45:04 +00:00
/* error code */
enum
{
2006-04-17 16:12:02 +00:00
XP_AWK_ENOERR, /* no error */
XP_AWK_ENOMEM, /* out of memory */
2006-06-19 09:10:57 +00:00
XP_AWK_EINVAL, /* invalid parameter */
2006-04-02 12:45:04 +00:00
2006-04-30 15:50:38 +00:00
XP_AWK_ENOSRCIO, /* no source io handler set */
2006-04-22 13:54:53 +00:00
XP_AWK_ESRCINOPEN,
XP_AWK_ESRCINCLOSE,
2006-04-22 16:16:40 +00:00
XP_AWK_ESRCINNEXT,
2006-04-22 13:54:53 +00:00
XP_AWK_ESRCINDATA, /* error in reading source */
XP_AWK_ETXTINOPEN,
XP_AWK_ETXTINCLOSE,
2006-04-22 16:16:40 +00:00
XP_AWK_ETXTINNEXT,
2006-04-22 13:54:53 +00:00
XP_AWK_ETXTINDATA, /* error in reading text */
2006-04-17 16:12:02 +00:00
XP_AWK_ELXCHR, /* lexer came accross an wrong character */
XP_AWK_ELXUNG, /* lexer failed to unget a character */
XP_AWK_EENDSRC, /* unexpected end of source */
XP_AWK_EENDSTR, /* unexpected end of a string */
2006-04-24 11:26:00 +00:00
XP_AWK_EENDREX, /* unexpected end of a regular expression */
2006-04-17 16:12:02 +00:00
XP_AWK_ELBRACE, /* left brace expected */
XP_AWK_ELPAREN, /* left parenthesis expected */
XP_AWK_ERPAREN, /* right parenthesis expected */
XP_AWK_ERBRACK, /* right bracket expected */
XP_AWK_ECOMMA, /* comma expected */
XP_AWK_ESEMICOLON, /* semicolon expected */
XP_AWK_ECOLON, /* colon expected */
2006-04-26 15:53:17 +00:00
XP_AWK_EIN, /* keyword 'in' is expected */
XP_AWK_ENOTVAR, /* not a variable name after 'in' */
2006-04-17 16:12:02 +00:00
XP_AWK_EEXPRESSION, /* expression expected */
XP_AWK_EWHILE, /* keyword 'while' is expected */
XP_AWK_EASSIGNMENT, /* assignment statement expected */
XP_AWK_EIDENT, /* identifier expected */
XP_AWK_EDUPBEGIN, /* duplicate BEGIN */
XP_AWK_EDUPEND, /* duplicate END */
XP_AWK_EDUPFUNC, /* duplicate function name */
XP_AWK_EDUPPARAM, /* duplicate parameter name */
XP_AWK_EDUPVAR, /* duplicate variable name */
XP_AWK_EDUPNAME, /* duplicate name - function, variable, etc */
XP_AWK_EUNDEF, /* undefined identifier */
XP_AWK_ELVALUE, /* l-value required */
2006-06-21 15:37:51 +00:00
XP_AWK_ETOOFEWARGS, /* too few arguments */
2006-04-18 16:04:59 +00:00
XP_AWK_ETOOMANYARGS, /* too many arguments */
2006-06-18 10:53:06 +00:00
XP_AWK_EGETLINE, /* getline expected */
2006-04-05 15:56:20 +00:00
/* run time error */
2006-07-01 16:07:06 +00:00
XP_AWK_EDIVBYZERO, /* divide by zero */
XP_AWK_EOPERAND, /* invalid operand */
2006-07-05 16:20:23 +00:00
XP_AWK_EPOSIDX, /* wrong position index */
2006-07-01 16:07:06 +00:00
XP_AWK_ENOSUCHFUNC, /* no such function */
XP_AWK_ENOTASSIGNABLE, /* value not assignable */
XP_AWK_ENOTINDEXABLE, /* not indexable variable */
XP_AWK_ENOTDELETABLE, /* not deletable variable */
XP_AWK_ENOTSCALARIZABLE, /* not scalarizable variable */
XP_AWK_EVALTYPE, /* wrong value type */
XP_AWK_EPIPE, /* pipe operation error */
XP_AWK_EIOIMPL, /* wrong implementation of user io handler */
XP_AWK_EINTERNAL /* internal error */
2006-04-02 12:45:04 +00:00
};
2006-06-19 09:10:57 +00:00
/* extio types */
enum
{
/* extio types available */
XP_AWK_EXTIO_PIPE,
XP_AWK_EXTIO_COPROC,
XP_AWK_EXTIO_FILE,
2006-06-25 15:26:57 +00:00
XP_AWK_EXTIO_CONSOLE,
2006-06-19 09:10:57 +00:00
/* reserved for internal use only */
XP_AWK_EXTIO_NUM
};
2005-11-05 17:54:00 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2006-03-31 16:35:37 +00:00
xp_awk_t* xp_awk_open (void);
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
void xp_awk_clear (xp_awk_t* awk);
2006-03-31 16:35:37 +00:00
void xp_awk_setparseopt (xp_awk_t* awk, int opt);
2006-04-09 15:31:13 +00:00
void xp_awk_setrunopt (xp_awk_t* awk, int opt);
2006-01-24 16:14:28 +00:00
2005-12-29 12:04:51 +00:00
int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg);
int xp_awk_detsrc (xp_awk_t* awk);
2005-11-07 16:02:44 +00:00
2006-06-19 09:10:57 +00:00
int xp_awk_setextio (xp_awk_t* awk, int id, xp_awk_io_t handler, void* arg);
2006-06-19 04:38:51 +00:00
2006-05-13 16:33:07 +00:00
xp_size_t xp_awk_getsrcline (xp_awk_t* awk);
2006-04-22 13:54:53 +00:00
/* TODO: xp_awk_parse (xp_awk_t* awk, xp_awk_io_t src, void* arg)??? */
2006-01-09 16:03:56 +00:00
int xp_awk_parse (xp_awk_t* awk);
2006-04-22 13:54:53 +00:00
int xp_awk_run (xp_awk_t* awk, xp_awk_io_t txtio, void* txtio_arg);
2006-01-09 16:03:56 +00:00
2006-06-20 15:27:50 +00:00
/* functions to access internal stack structure */
xp_size_t xp_awk_getnargs (void* run);
xp_awk_val_t* xp_awk_getarg (void* run, xp_size_t idx);
void xp_awk_setretval (void* run, xp_awk_val_t* val);
2006-06-21 11:45:26 +00:00
void xp_awk_seterrnum (void* run, int errnum);
2006-06-20 15:27:50 +00:00
2006-04-04 16:03:14 +00:00
/* utility functions exported by awk.h */
2006-04-16 04:31:38 +00:00
xp_long_t xp_awk_strtolong (
const xp_char_t* str, int base, const xp_char_t** endptr);
2006-04-04 16:03:14 +00:00
xp_real_t xp_awk_strtoreal (const xp_char_t* str);
2005-11-05 17:54:00 +00:00
#ifdef __cplusplus
}
#endif
#endif