| 1 |
/* routines.h: Generating the finite state automaton |
| 2 |
|
| 3 |
This file is part of Omega, |
| 4 |
which is based on the web2c distribution of TeX, |
| 5 |
|
| 6 |
Copyright (c) 1994--2001 John Plaice and Yannis Haralambous |
| 7 |
Copyright (C) 2005 Roozbeh Pournader |
| 8 |
|
| 9 |
Omega is free software; you can redistribute it and/or modify |
| 10 |
it under the terms of the GNU General Public License as published by |
| 11 |
the Free Software Foundation; either version 2 of the License, or |
| 12 |
(at your option) any later version. |
| 13 |
|
| 14 |
Omega is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
GNU General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License |
| 20 |
along with Omega; if not, write to the Free Software Foundation, Inc., |
| 21 |
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
| 22 |
|
| 23 |
*/ |
| 24 |
|
| 25 |
#ifdef HAVE_CONFIG_H |
| 26 |
#include <w2c/config.h> |
| 27 |
#endif |
| 28 |
#ifdef KPATHSEA |
| 29 |
#include <kpathsea/config.h> |
| 30 |
#include <kpathsea/c-memstr.h> |
| 31 |
#include <kpathsea/c-std.h> |
| 32 |
#else /* !KPATHSEA */ |
| 33 |
#include <stdio.h> |
| 34 |
#include <string.h> |
| 35 |
#ifdef __STDC__ |
| 36 |
#include <stdlib.h> |
| 37 |
#else |
| 38 |
extern void exit(); |
| 39 |
#endif |
| 40 |
#endif /* KPATHSEA */ |
| 41 |
|
| 42 |
#define nil 0 |
| 43 |
|
| 44 |
#define WILDCARD 0 |
| 45 |
#define STRINGLEFT 1 |
| 46 |
#define SINGLELEFT 2 |
| 47 |
#define DOUBLELEFT 3 |
| 48 |
#define CHOICELEFT 4 |
| 49 |
#define NOTCHOICELEFT 5 |
| 50 |
#define PLUSLEFT 6 |
| 51 |
#define COMPLETELEFT 7 |
| 52 |
#define BEGINNINGLEFT 8 |
| 53 |
#define ENDLEFT 9 |
| 54 |
|
| 55 |
extern int yyparse(void); |
| 56 |
extern int yylex(void); |
| 57 |
extern int yywrap(void); |
| 58 |
|
| 59 |
extern int line_number; |
| 60 |
|
| 61 |
/* linked list of ints */ |
| 62 |
typedef struct cell_struct {struct cell_struct *ptr; |
| 63 |
int val; } cell; |
| 64 |
typedef cell *list; |
| 65 |
|
| 66 |
typedef struct left_cell { |
| 67 |
int kind; |
| 68 |
int val1, val2; |
| 69 |
char *valstr; |
| 70 |
struct lcell_struct *more_lefts; |
| 71 |
struct left_cell *one_left; |
| 72 |
} lft_cell; |
| 73 |
typedef lft_cell *left; |
| 74 |
|
| 75 |
/* linked list of lefts */ |
| 76 |
typedef struct lcell_struct {struct lcell_struct *ptr; |
| 77 |
left val; } lcell; |
| 78 |
typedef lcell *llist; |
| 79 |
|
| 80 |
extern list cons(int x, list L); |
| 81 |
extern list list1(int x); |
| 82 |
extern list list2(int x, int y); |
| 83 |
extern list append(list K, list L); |
| 84 |
extern list append1(list L, int x); |
| 85 |
|
| 86 |
extern llist lcons(left x, llist L); |
| 87 |
extern llist llist1(left x); |
| 88 |
extern llist llist2(left x, left y); |
| 89 |
extern llist lappend(llist K, llist L); |
| 90 |
extern llist lappend1(llist L, left x); |
| 91 |
|
| 92 |
extern left WildCard(void); |
| 93 |
extern left StringLeft(char *x); |
| 94 |
extern left SingleLeft(int x); |
| 95 |
extern left DoubleLeft(int x, int y); |
| 96 |
extern left ChoiceLeft(llist L); |
| 97 |
extern left NotChoiceLeft(llist L); |
| 98 |
extern left PlusLeft(left l, int n); |
| 99 |
extern left CompleteLeft(left l, int n, int m); |
| 100 |
extern left BeginningLeft(void); |
| 101 |
extern left EndLeft(void); |
| 102 |
extern list gen_left(left arg); |
| 103 |
|
| 104 |
extern int no_lefts; |
| 105 |
extern void store_alias(string str, left l); |
| 106 |
extern left lookup_alias(string str); |
| 107 |
extern void out_left(llist L); |
| 108 |
extern void fill_in_left(void); |
| 109 |
|
| 110 |
#define ARRAY_SIZE 50000 |
| 111 |
typedef struct { |
| 112 |
int length; |
| 113 |
char * str; |
| 114 |
int table[ARRAY_SIZE]; |
| 115 |
} table_type; |
| 116 |
|
| 117 |
extern int no_tables; |
| 118 |
extern int cur_table; |
| 119 |
extern int room_for_tables; |
| 120 |
extern table_type tables[]; |
| 121 |
extern void add_to_table(int x); |
| 122 |
|
| 123 |
typedef struct { |
| 124 |
int length; |
| 125 |
char * str; |
| 126 |
int no_exprs; |
| 127 |
int instrs[ARRAY_SIZE]; |
| 128 |
} state_type; |
| 129 |
|
| 130 |
extern int no_states; |
| 131 |
extern int cur_state; |
| 132 |
extern int room_for_states; |
| 133 |
extern state_type states[]; |
| 134 |
extern void add_to_state(int x); |
| 135 |
|
| 136 |
extern void fill_in(list L); |
| 137 |
extern void out_int(int instr, int val); |
| 138 |
extern void out_right(int instr, int val); |
| 139 |
|
| 140 |
extern void store_state(const_string str); |
| 141 |
extern int lookup_state(string str); |
| 142 |
extern void store_table(string str, int len); |
| 143 |
extern int lookup_table(string str); |
| 144 |
|
| 145 |
typedef struct { char * str; left left_val; } alias_pair; |
| 146 |
|
| 147 |
extern alias_pair aliases[]; |
| 148 |
|
| 149 |
extern int right_offset; |
| 150 |
extern int input_bytes; |
| 151 |
extern int output_bytes; |
| 152 |
|