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