6e403221 |
1 | /* -*-c-*- |
2 | * |
a10122de |
3 | * $Id: anag.h,v 1.2 2002/08/11 12:58:09 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 $ |
a10122de |
32 | * Revision 1.2 2002/08/11 12:58:09 mdw |
33 | * Added support for regular expression matching, if supported by the C |
34 | * library. |
35 | * |
6e403221 |
36 | * Revision 1.1 2001/02/04 17:14:42 mdw |
37 | * Initial checkin |
38 | * |
39 | */ |
40 | |
41 | #ifndef ANAG_H |
42 | #define ANAG_H |
43 | |
44 | #ifdef __cplusplus |
45 | extern "C" { |
46 | #endif |
47 | |
48 | /*----- Header files ------------------------------------------------------*/ |
49 | |
50 | #include "config.h" |
51 | |
52 | #include <assert.h> |
53 | #include <ctype.h> |
54 | #include <errno.h> |
55 | #include <limits.h> |
56 | #include <stdarg.h> |
57 | #include <stdio.h> |
58 | #include <stdlib.h> |
59 | #include <string.h> |
60 | |
61 | /*----- Data structures ---------------------------------------------------*/ |
62 | |
63 | typedef struct node { |
64 | int (*func)(struct node */*n*/, const char */*p*/, size_t /*sz*/); |
65 | } node; |
66 | |
67 | typedef struct dstr { |
68 | char *buf; |
69 | size_t len; |
70 | size_t sz; |
71 | } dstr; |
72 | |
73 | #define DSTR_INIT { 0, 0, 0 } |
74 | |
75 | /*----- Node types --------------------------------------------------------*/ |
76 | |
77 | extern node *anagram(const char *const */*av*/); |
78 | extern node *subgram(const char *const */*av*/); |
79 | extern node *wildcard(const char *const */*av*/); |
80 | extern node *trackword(const char *const */*av*/); |
a10122de |
81 | extern node *regexp(const char *const */*av*/); |
6e403221 |
82 | |
83 | /*----- Error reporting ---------------------------------------------------*/ |
84 | |
85 | /* --- @ego@ --- * |
86 | * |
87 | * Arguments: @const char *p@ = pointer to program name |
88 | * |
89 | * Returns: --- |
90 | * |
91 | * Use: Stores what the program's name is. |
92 | */ |
93 | |
94 | extern void ego(const char */*p*/); |
95 | |
96 | /* --- @pquis@ --- * |
97 | * |
98 | * Arguments: @FILE *fp@ = output stream to write on |
99 | * @const char *p@ = pointer to string to write |
100 | * |
101 | * Returns: Zero if everything worked, EOF if not. |
102 | * |
103 | * Use: Writes the string @p@ to the output stream @fp@. Occurrences |
104 | * of the character `$' in @p@ are replaced by the program name |
105 | * as reported by @quis@. A `$$' is replaced by a single `$' |
106 | * sign. |
107 | */ |
108 | |
109 | extern int pquis(FILE */*fp*/, const char */*p*/); |
110 | |
111 | /* --- @die@ --- * |
112 | * |
113 | * Arguments: @const char *f@ = a @printf@-style format string |
114 | * @...@ = other arguments |
115 | * |
116 | * Returns: Never. |
117 | * |
118 | * Use: Reports an error and exits. |
119 | */ |
120 | |
121 | extern void die(const char */*f*/, ...); |
122 | |
123 | /*----- Memory allocation -------------------------------------------------*/ |
124 | |
125 | /* --- @xmalloc@ --- * |
126 | * |
127 | * Arguments: @size_t sz@ = size of block to allocate |
128 | * |
129 | * Returns: Pointer to allocated block. |
130 | * |
131 | * Use: Allocates memory. If there's not enough memory, the |
132 | * program exits. |
133 | */ |
134 | |
135 | extern void *xmalloc(size_t /*sz*/); |
136 | |
137 | /* --- @xrealloc@ --- * |
138 | * |
139 | * Arguments: @void *p@ = a pointer to allocated memory |
140 | * @size_t sz@ = new size of block wanted |
141 | * |
142 | * Returns: Pointer to resized block. |
143 | * |
144 | * Use: Resizes an allocated block. If there's not enough memory, |
145 | * the program exits. |
146 | */ |
147 | |
148 | extern void *xrealloc(void */*p*/, size_t /*sz*/); |
149 | |
150 | /*----- Dynamic string handling -------------------------------------------*/ |
151 | |
152 | /* --- @dstr_destroy@ --- * |
153 | * |
154 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
155 | * |
156 | * Returns: --- |
157 | * |
158 | * Use: Reclaims the space used by a dynamic string. |
159 | */ |
160 | |
161 | extern void dstr_destroy(dstr */*d*/); |
162 | |
163 | /* --- @dstr_reset@ --- * |
164 | * |
165 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
166 | * |
167 | * Returns: --- |
168 | * |
169 | * Use: Resets a string so that new data gets put at the beginning. |
170 | */ |
171 | |
172 | extern void dstr_reset(dstr */*d*/); |
173 | |
174 | /* --- @dstr_ensure@ --- * |
175 | * |
176 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
177 | * @size_t sz@ = amount of free space to ensure |
178 | * |
179 | * Returns: --- |
180 | * |
181 | * Use: Ensures that at least @sz@ bytes are available in the |
182 | * given string. |
183 | */ |
184 | |
185 | extern void dstr_ensure(dstr */*d*/, size_t /*sz*/); |
186 | |
187 | /* --- @dstr_putline@ --- * |
188 | * |
189 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
190 | * @FILE *fp@ = a stream to read from |
191 | * |
192 | * Returns: The number of characters read into the buffer, or @EOF@ if |
193 | * end-of-file was reached before any characters were read. |
194 | * |
195 | * Use: Appends the next line from the given input stream to the |
196 | * string. A trailing newline is not added; a trailing null |
197 | * byte is appended, as for @dstr_putz@. |
198 | */ |
199 | |
200 | extern int dstr_putline(dstr */*d*/, FILE */*fp*/); |
201 | |
202 | /*----- That's all, folks -------------------------------------------------*/ |
203 | |
204 | #ifdef __cplusplus |
205 | } |
206 | #endif |
207 | |
208 | #endif |