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