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