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 * Enscript 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 3 of the License, or
14 * (at your option) any later version.
16 * Enscript 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 Enscript. If not, see <http://www.gnu.org/licenses/>.
41 #define ___P(protos) protos
42 #else /* no PROTOTYPES */
43 #define ___P(protos) ()
44 #endif /* no PROTOTYPES */
52 #else /* no STDC_HEADERS */
64 #define strrchr rindex
70 extern char *strerror ___P ((int));
74 extern void *memmove ___P ((void *, void *, size_t));
78 extern void *memcpy ___P ((void *, void *, size_t));
81 #endif /* no STDC_HEADERS */
90 #include <sys/types.h>
99 #define _(String) gettext (String)
101 #define _(String) String
113 * Types and definitions.
116 #define RULE_BEGIN ((void *) 0)
117 #define RULE_END ((void *) 1)
119 #define INBUFSIZE (20 * 1024)
121 #define IS_TRUE(n) ((n)->type != nINTEGER || (n)->u.integer != 0)
123 #define REGEXP(regexp) \
124 ((regexp)->u.re.compiled.fastmap_accurate \
125 ? (&(regexp)->u.re.compiled) \
126 : (compile_regexp (regexp), &(regexp)->u.re.compiled))
128 /* Flags for regular expressions. */
129 #define fRE_CASE_INSENSITIVE 1
131 /* Generic linked list. */
135 struct list_item_st *next;
139 typedef struct list_item_st ListItem;
147 typedef struct list_st List;
155 struct state_st *super;
159 typedef struct state_st State;
178 unsigned int refcount;
179 unsigned int linenum;
195 struct re_registers matches;
202 struct node_st **array;
204 unsigned int allocated;
209 typedef struct node_st Node;
218 typedef struct cons_st Cons;
260 unsigned int linenum;
275 struct expr_st *expr;
279 struct expr_st *expr1;
280 struct expr_st *expr2;
281 struct expr_st *expr3;
285 struct expr_st *expr1;
286 struct expr_st *expr2;
290 struct expr_st *cond;
291 struct expr_st *expr1;
292 struct expr_st *expr2;
296 struct expr_st *left;
297 struct expr_st *right;
302 typedef struct expr_st Expr;
318 unsigned int linenum;
332 struct stmt_st *then_stmt;
333 struct stmt_st *else_stmt;
338 struct stmt_st *body;
345 struct stmt_st *body;
351 typedef struct stmt_st Stmt;
353 struct environment_st
355 struct environment_st *next;
360 typedef struct environment_st Environment;
362 /* Primitive procedure. */
363 typedef Node *(*Primitive) ___P ((char *prim_name, List *args,
364 Environment *env, char *filename,
365 unsigned int linenum));
367 /* Variable definition chain. */
368 struct variable_definition_st
370 struct variable_definition_st *next;
375 typedef struct variable_definition_st VariableDef;
377 /* Grammar and execution warning levels. */
389 extern char *program;
393 extern char *defs_file;
394 extern unsigned int linenum;
395 extern char *yyin_name;
396 extern WarningLevel warning_level;
398 extern unsigned int verbose;
401 extern StringHashPtr ns_prims;
402 extern StringHashPtr ns_vars;
403 extern StringHashPtr ns_subs;
404 extern StringHashPtr ns_states;
406 extern List *global_stmts;
407 extern List *start_stmts;
408 extern List *startrules;
409 extern List *namerules;
411 /* Void node value. There is only nvoid instance. */
416 extern unsigned int data_in_buffer;
417 extern unsigned int bufpos;
419 extern char *current_fname;
420 extern unsigned int current_linenum;
422 extern struct re_registers *current_match;
423 extern char *current_match_buf;
427 extern char *start_state_arg;
428 extern char *start_state;
432 * Prototypes for global functions.
435 void init_primitives ();
437 /* Parser & lexer. */
440 void yyerror ___P ((char *msg));
442 /* Generic linked list. */
444 /* Create a new linked list. */
447 /* Add a new element <data> to the beginning of list <list>. */
448 void list_prepend ___P ((List *list, void *data));
450 /* Add a new element <data> to the end of list <list>. */
451 void list_append ___P ((List *list, void *data));
454 /* Node manipulators. */
456 Node *node_alloc ___P ((NodeType type));
458 Node *node_copy ___P ((Node *node));
460 void node_reference ___P ((Node *node));
462 void node_free ___P ((Node *node));
464 void enter_system_variable ___P ((char *name, char *value));
466 void compile_regexp ___P ((Node *regexp));
469 /* Grammar constructors. */
471 Stmt *mk_stmt ___P ((StmtType type, void *arg1, void *arg2, void *arg3,
474 Expr *mk_expr ___P ((ExprType type, void *arg1, void *arg2, void *arg3));
476 Cons *cons ___P ((void *car, void *cdr));
478 void define_state ___P ((Node *sym, Node *super, List *rules));
482 Node *eval_expr ___P ((Expr *expr, Environment *env));
484 Node *eval_statement ___P ((Stmt *stmt, Environment *env, int *return_seen));
486 Node *eval_statement_list ___P ((List *lst, Environment *env,
489 void process_file ___P ((char *fname));
491 Node *execute_state ___P ((char *name));
493 void load_states_file ___P ((char *name));
496 * Lookup state <name> and return its handle. If the state is
497 * undefined, the function tries to autoload it.
499 State *lookup_state ___P ((char *name));
501 #endif /* not DEFS_H */