2 * Internal definitions for states.
3 * Copyright (c) 1997-1998 Markku Rossi.
5 * Author: Markku Rossi <mtr@iki.fi>
9 * This file is part of GNU enscript.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
43 #define ___P(protos) protos
44 #else /* no PROTOTYPES */
45 #define ___P(protos) ()
46 #endif /* no PROTOTYPES */
54 #else /* no STDC_HEADERS */
66 #define strrchr rindex
72 extern char *strerror ___P ((int));
76 extern void *memmove ___P ((void *, void *, size_t));
80 extern void *memcpy ___P ((void *, void *, size_t));
83 #endif /* no STDC_HEADERS */
92 #include <sys/types.h>
101 #define _(String) gettext (String)
103 #define _(String) String
115 * Types and definitions.
118 #define RULE_BEGIN ((void *) 0)
119 #define RULE_END ((void *) 1)
121 #define INBUFSIZE (20 * 1024)
123 #define IS_TRUE(n) ((n)->type != nINTEGER || (n)->u.integer != 0)
125 #define REGEXP(regexp) \
126 ((regexp)->u.re.compiled.fastmap_accurate \
127 ? (&(regexp)->u.re.compiled) \
128 : (compile_regexp (regexp), &(regexp)->u.re.compiled))
130 /* Flags for regular expressions. */
131 #define fRE_CASE_INSENSITIVE 1
133 /* Generic linked list. */
137 struct list_item_st *next;
141 typedef struct list_item_st ListItem;
149 typedef struct list_st List;
157 struct state_st *super;
161 typedef struct state_st State;
180 unsigned int refcount;
181 unsigned int linenum;
197 struct re_registers matches;
204 struct node_st **array;
206 unsigned int allocated;
211 typedef struct node_st Node;
220 typedef struct cons_st Cons;
262 unsigned int linenum;
277 struct expr_st *expr;
281 struct expr_st *expr1;
282 struct expr_st *expr2;
283 struct expr_st *expr3;
287 struct expr_st *expr1;
288 struct expr_st *expr2;
292 struct expr_st *cond;
293 struct expr_st *expr1;
294 struct expr_st *expr2;
298 struct expr_st *left;
299 struct expr_st *right;
304 typedef struct expr_st Expr;
320 unsigned int linenum;
334 struct stmt_st *then_stmt;
335 struct stmt_st *else_stmt;
340 struct stmt_st *body;
347 struct stmt_st *body;
353 typedef struct stmt_st Stmt;
355 struct environment_st
357 struct environment_st *next;
362 typedef struct environment_st Environment;
364 /* Primitive procedure. */
365 typedef Node *(*Primitive) ___P ((char *prim_name, List *args,
366 Environment *env, char *filename,
367 unsigned int linenum));
369 /* Variable definition chain. */
370 struct variable_definition_st
372 struct variable_definition_st *next;
377 typedef struct variable_definition_st VariableDef;
379 /* Grammar and execution warning levels. */
391 extern char *program;
395 extern char *defs_file;
396 extern unsigned int linenum;
397 extern char *yyin_name;
398 extern WarningLevel warning_level;
400 extern unsigned int verbose;
403 extern StringHashPtr ns_prims;
404 extern StringHashPtr ns_vars;
405 extern StringHashPtr ns_subs;
406 extern StringHashPtr ns_states;
408 extern List *global_stmts;
409 extern List *start_stmts;
410 extern List *startrules;
411 extern List *namerules;
413 /* Void node value. There is only nvoid instance. */
418 extern unsigned int data_in_buffer;
419 extern unsigned int bufpos;
421 extern char *current_fname;
422 extern unsigned int current_linenum;
424 extern struct re_registers *current_match;
425 extern char *current_match_buf;
429 extern char *start_state_arg;
430 extern char *start_state;
434 * Prototypes for global functions.
437 void init_primitives ();
439 /* Parser & lexer. */
442 void yyerror ___P ((char *msg));
444 /* Generic linked list. */
446 /* Create a new linked list. */
449 /* Add a new element <data> to the beginning of list <list>. */
450 void list_prepend ___P ((List *list, void *data));
452 /* Add a new element <data> to the end of list <list>. */
453 void list_append ___P ((List *list, void *data));
456 /* Node manipulators. */
458 Node *node_alloc ___P ((NodeType type));
460 Node *node_copy ___P ((Node *node));
462 void node_reference ___P ((Node *node));
464 void node_free ___P ((Node *node));
466 void enter_system_variable ___P ((char *name, char *value));
468 void compile_regexp ___P ((Node *regexp));
471 /* Grammar constructors. */
473 Stmt *mk_stmt ___P ((StmtType type, void *arg1, void *arg2, void *arg3,
476 Expr *mk_expr ___P ((ExprType type, void *arg1, void *arg2, void *arg3));
478 Cons *cons ___P ((void *car, void *cdr));
480 void define_state ___P ((Node *sym, Node *super, List *rules));
484 Node *eval_expr ___P ((Expr *expr, Environment *env));
486 Node *eval_statement ___P ((Stmt *stmt, Environment *env, int *return_seen));
488 Node *eval_statement_list ___P ((List *lst, Environment *env,
491 void process_file ___P ((char *fname));
493 Node *execute_state ___P ((char *name));
495 void load_states_file ___P ((char *name));
498 * Lookup state <name> and return its handle. If the state is
499 * undefined, the function tries to autoload it.
501 State *lookup_state ___P ((char *name));
503 #endif /* not DEFS_H */