6e403221 |
1 | /* -*-c-*- |
2 | * |
d9af4a2b |
3 | * $Id: anag.h,v 1.4 2003/11/29 23:38:37 mdw Exp $ |
6e403221 |
4 | * |
5 | * External definitions for Anag |
6 | * |
7 | * (c) 2001 Mark Wooding |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Anag: a simple wordgame helper. |
13 | * |
14 | * Anag is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU General Public License as published by |
16 | * the Free Software Foundation; either version 2 of the License, or |
17 | * (at your option) any later version. |
18 | * |
19 | * Anag is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU General Public License |
25 | * along with Anag; if not, write to the Free Software Foundation, |
26 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
27 | */ |
28 | |
29 | /*----- Revision history --------------------------------------------------* |
30 | * |
31 | * $Log: anag.h,v $ |
d9af4a2b |
32 | * Revision 1.4 2003/11/29 23:38:37 mdw |
33 | * Debianization. |
34 | * |
fe9969ff |
35 | * Revision 1.3 2003/09/15 02:48:55 mdw |
36 | * Monoalphabetic match filter. |
37 | * |
a10122de |
38 | * Revision 1.2 2002/08/11 12:58:09 mdw |
39 | * Added support for regular expression matching, if supported by the C |
40 | * library. |
41 | * |
6e403221 |
42 | * Revision 1.1 2001/02/04 17:14:42 mdw |
43 | * Initial checkin |
44 | * |
45 | */ |
46 | |
47 | #ifndef ANAG_H |
48 | #define ANAG_H |
49 | |
50 | #ifdef __cplusplus |
51 | extern "C" { |
52 | #endif |
53 | |
54 | /*----- Header files ------------------------------------------------------*/ |
55 | |
56 | #include "config.h" |
57 | |
58 | #include <assert.h> |
59 | #include <ctype.h> |
60 | #include <errno.h> |
61 | #include <limits.h> |
62 | #include <stdarg.h> |
63 | #include <stdio.h> |
64 | #include <stdlib.h> |
65 | #include <string.h> |
66 | |
67 | /*----- Data structures ---------------------------------------------------*/ |
68 | |
69 | typedef struct node { |
70 | int (*func)(struct node */*n*/, const char */*p*/, size_t /*sz*/); |
71 | } node; |
72 | |
73 | typedef struct dstr { |
74 | char *buf; |
75 | size_t len; |
76 | size_t sz; |
77 | } dstr; |
78 | |
79 | #define DSTR_INIT { 0, 0, 0 } |
80 | |
81 | /*----- Node types --------------------------------------------------------*/ |
82 | |
83 | extern node *anagram(const char *const */*av*/); |
84 | extern node *subgram(const char *const */*av*/); |
85 | extern node *wildcard(const char *const */*av*/); |
86 | extern node *trackword(const char *const */*av*/); |
fe9969ff |
87 | extern node *mono(const char *const */*av*/); |
a10122de |
88 | extern node *regexp(const char *const */*av*/); |
d9af4a2b |
89 | extern node *pcrenode(const char *const */*av*/); |
6e403221 |
90 | |
91 | /*----- Error reporting ---------------------------------------------------*/ |
92 | |
93 | /* --- @ego@ --- * |
94 | * |
95 | * Arguments: @const char *p@ = pointer to program name |
96 | * |
97 | * Returns: --- |
98 | * |
99 | * Use: Stores what the program's name is. |
100 | */ |
101 | |
102 | extern void ego(const char */*p*/); |
103 | |
104 | /* --- @pquis@ --- * |
105 | * |
106 | * Arguments: @FILE *fp@ = output stream to write on |
107 | * @const char *p@ = pointer to string to write |
108 | * |
109 | * Returns: Zero if everything worked, EOF if not. |
110 | * |
111 | * Use: Writes the string @p@ to the output stream @fp@. Occurrences |
112 | * of the character `$' in @p@ are replaced by the program name |
113 | * as reported by @quis@. A `$$' is replaced by a single `$' |
114 | * sign. |
115 | */ |
116 | |
117 | extern int pquis(FILE */*fp*/, const char */*p*/); |
118 | |
119 | /* --- @die@ --- * |
120 | * |
121 | * Arguments: @const char *f@ = a @printf@-style format string |
122 | * @...@ = other arguments |
123 | * |
124 | * Returns: Never. |
125 | * |
126 | * Use: Reports an error and exits. |
127 | */ |
128 | |
129 | extern void die(const char */*f*/, ...); |
130 | |
131 | /*----- Memory allocation -------------------------------------------------*/ |
132 | |
133 | /* --- @xmalloc@ --- * |
134 | * |
135 | * Arguments: @size_t sz@ = size of block to allocate |
136 | * |
137 | * Returns: Pointer to allocated block. |
138 | * |
139 | * Use: Allocates memory. If there's not enough memory, the |
140 | * program exits. |
141 | */ |
142 | |
143 | extern void *xmalloc(size_t /*sz*/); |
144 | |
145 | /* --- @xrealloc@ --- * |
146 | * |
147 | * Arguments: @void *p@ = a pointer to allocated memory |
148 | * @size_t sz@ = new size of block wanted |
149 | * |
150 | * Returns: Pointer to resized block. |
151 | * |
152 | * Use: Resizes an allocated block. If there's not enough memory, |
153 | * the program exits. |
154 | */ |
155 | |
156 | extern void *xrealloc(void */*p*/, size_t /*sz*/); |
157 | |
158 | /*----- Dynamic string handling -------------------------------------------*/ |
159 | |
160 | /* --- @dstr_destroy@ --- * |
161 | * |
162 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
163 | * |
164 | * Returns: --- |
165 | * |
166 | * Use: Reclaims the space used by a dynamic string. |
167 | */ |
168 | |
169 | extern void dstr_destroy(dstr */*d*/); |
170 | |
171 | /* --- @dstr_reset@ --- * |
172 | * |
173 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
174 | * |
175 | * Returns: --- |
176 | * |
177 | * Use: Resets a string so that new data gets put at the beginning. |
178 | */ |
179 | |
180 | extern void dstr_reset(dstr */*d*/); |
181 | |
182 | /* --- @dstr_ensure@ --- * |
183 | * |
184 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
185 | * @size_t sz@ = amount of free space to ensure |
186 | * |
187 | * Returns: --- |
188 | * |
189 | * Use: Ensures that at least @sz@ bytes are available in the |
190 | * given string. |
191 | */ |
192 | |
193 | extern void dstr_ensure(dstr */*d*/, size_t /*sz*/); |
194 | |
195 | /* --- @dstr_putline@ --- * |
196 | * |
197 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
198 | * @FILE *fp@ = a stream to read from |
199 | * |
200 | * Returns: The number of characters read into the buffer, or @EOF@ if |
201 | * end-of-file was reached before any characters were read. |
202 | * |
203 | * Use: Appends the next line from the given input stream to the |
204 | * string. A trailing newline is not added; a trailing null |
205 | * byte is appended, as for @dstr_putz@. |
206 | */ |
207 | |
208 | extern int dstr_putline(dstr */*d*/, FILE */*fp*/); |
209 | |
210 | /*----- That's all, folks -------------------------------------------------*/ |
211 | |
212 | #ifdef __cplusplus |
213 | } |
214 | #endif |
215 | |
216 | #endif |