#ifndef DEFS_H
#define DEFS_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <ctype.h>
#ifndef ___P
#if PROTOTYPES
#define ___P(protos) protos
#else
#define ___P(protos) ()
#endif
#endif
#if STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#else
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#ifndef HAVE_STRCHR
#define strchr index
#define strrchr rindex
#endif
char *strchr ();
char *strrchr ();
#ifndef HAVE_STRERROR
extern char *strerror ___P ((int));
#endif
#ifndef HAVE_MEMMOVE
extern void *memmove ___P ((void *, void *, size_t));
#endif
#ifndef HAVE_MEMCPY
extern void *memcpy ___P ((void *, void *, size_t));
#endif
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#if ENABLE_NLS
#include <libintl.h>
#define _(String) gettext (String)
#else
#define _(String) String
#endif
#if HAVE_LC_MESSAGES
#include <locale.h>
#endif
#include "regex.h"
#include "xalloc.h"
#include "strhash.h"
#define RULE_BEGIN ((void *) 0)
#define RULE_END ((void *) 1)
#define INBUFSIZE (20 * 1024)
#define IS_TRUE(n) ((n)->type != nINTEGER || (n)->u.integer != 0)
#define REGEXP(regexp) \
((regexp)->u.re.compiled.fastmap_accurate \
? (&(regexp)->u.re.compiled) \
: (compile_regexp (regexp), &(regexp)->u.re.compiled))
#define fRE_CASE_INSENSITIVE 1
struct list_item_st
{
struct list_item_st *next;
void *data;
};
typedef struct list_item_st ListItem;
struct list_st
{
ListItem *head;
ListItem *tail;
};
typedef struct list_st List;
typedef enum
{
nVOID,
nSTRING,
nREGEXP,
nINTEGER,
nREAL,
nSYMBOL,
nARRAY
} NodeType;
struct node_st
{
NodeType type;
unsigned int refcount;
unsigned int linenum;
union
{
struct
{
char *data;
unsigned int len;
} str;
struct
{
char *data;
unsigned int len;
unsigned int flags;
regex_t compiled;
struct re_registers matches;
} re;
int integer;
double real;
char *sym;
struct
{
struct node_st **array;
unsigned int len;
unsigned int allocated;
} array;
} u;
};
typedef struct node_st Node;
struct cons_st
{
void *car;
void *cdr;
};
typedef struct cons_st Cons;
typedef enum
{
eSTRING,
eREGEXP,
eINTEGER,
eREAL,
eSYMBOL,
eNOT,
eAND,
eOR,
eFCALL,
eASSIGN,
eADDASSIGN,
eSUBASSIGN,
eMULASSIGN,
eDIVASSIGN,
ePOSTFIXADD,
ePOSTFIXSUB,
ePREFIXADD,
ePREFIXSUB,
eARRAYASSIGN,
eARRAYREF,
eQUESTCOLON,
eMULT,
eDIV,
ePLUS,
eMINUS,
eLT,
eGT,
eEQ,
eNE,
eGE,
eLE
} ExprType;
struct expr_st
{
ExprType type;
unsigned int linenum;
union
{
Node *node;
struct expr_st *not;
struct
{
Node *name;
List *args;
} fcall;
struct
{
Node *sym;
struct expr_st *expr;
} assign;
struct
{
struct expr_st *expr1;
struct expr_st *expr2;
struct expr_st *expr3;
} arrayassign;
struct
{
struct expr_st *expr1;
struct expr_st *expr2;
} arrayref;
struct
{
struct expr_st *cond;
struct expr_st *expr1;
struct expr_st *expr2;
} questcolon;
struct
{
struct expr_st *left;
struct expr_st *right;
} op;
} u;
};
typedef struct expr_st Expr;
typedef enum
{
sRETURN,
sDEFSUB,
sBLOCK,
sIF,
sEXPR,
sWHILE,
sFOR
} StmtType;
struct stmt_st
{
StmtType type;
unsigned int linenum;
union
{
Expr *expr;
struct
{
Node *name;
Cons *closure;
} defsub;
struct
{
Expr *expr;
struct stmt_st *then_stmt;
struct stmt_st *else_stmt;
} stmt_if;
struct
{
Expr *expr;
struct stmt_st *body;
} stmt_while;
struct
{
Expr *init;
Expr *cond;
Expr *incr;
struct stmt_st *body;
} stmt_for;
List *block;
} u;
};
typedef struct stmt_st Stmt;
struct environment_st
{
struct environment_st *next;
char *name;
Node *val;
};
typedef struct environment_st Environment;
typedef Node *(*Primitive) ___P ((char *prim_name, List *args,
Environment *env, unsigned int linenum));
struct variable_definition_st
{
struct variable_definition_st *next;
char *sym;
char *val;
};
typedef struct variable_definition_st VariableDef;
typedef enum
{
WARN_LIGHT = 10,
WARN_ALL = 100
} WarningLevel;
extern char *program;
extern FILE *yyin;
extern FILE *ofp;
extern char *defs_file;
extern unsigned int linenum;
extern WarningLevel warning_level;
extern StringHashPtr ns_prims;
extern StringHashPtr ns_vars;
extern StringHashPtr ns_subs;
extern StringHashPtr ns_states;
extern List *global_stmts;
extern List *start_stmts;
extern List *startrules;
extern List *namerules;
extern Node *nvoid;
extern FILE *ifp;
extern char *inbuf;
extern unsigned int data_in_buffer;
extern unsigned int bufpos;
extern int eof_seen;
extern char *current_fname;
extern unsigned int current_linenum;
extern struct re_registers *current_match;
extern char *current_match_buf;
extern char *start_state_arg;
extern char *start_state;
void init_primitives ();
int yyparse ();
int yylex ();
void yyerror ___P ((char *msg));
List *list ();
void list_prepend ___P ((List *list, void *data));
void list_append ___P ((List *list, void *data));
Node *node_alloc ___P ((NodeType type));
Node *node_copy ___P ((Node *node));
void node_reference ___P ((Node *node));
void node_free ___P ((Node *node));
void enter_system_variable ___P ((char *name, char *value));
void compile_regexp ___P ((Node *regexp));
Stmt *mk_stmt ___P ((StmtType type, void *arg1, void *arg2, void *arg3,
void *arg4));
Expr *mk_expr ___P ((ExprType type, void *arg1, void *arg2, void *arg3));
Cons *cons ___P ((void *car, void *cdr));
void define_state ___P ((Node *sym, List *rules));
Node *eval_expr ___P ((Expr *expr, Environment *env));
Node *eval_statement ___P ((Stmt *stmt, Environment *env, int *return_seen));
Node *eval_statement_list ___P ((List *lst, Environment *env,
int *return_seen));
void process_file ___P ((char *fname));
Node *execute_state ___P ((char *name));
#endif