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