6e403221 |
1 | /* -*-c-*- |
2 | * |
345f33ea |
3 | * $Id: anag.h,v 1.5 2004/04/08 01:36:19 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 | |
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 | |
51 | typedef struct node { |
52 | int (*func)(struct node */*n*/, const char */*p*/, size_t /*sz*/); |
53 | } node; |
54 | |
55 | typedef 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 | |
65 | extern node *anagram(const char *const */*av*/); |
66 | extern node *subgram(const char *const */*av*/); |
67 | extern node *wildcard(const char *const */*av*/); |
68 | extern node *trackword(const char *const */*av*/); |
fe9969ff |
69 | extern node *mono(const char *const */*av*/); |
a10122de |
70 | extern node *regexp(const char *const */*av*/); |
d9af4a2b |
71 | extern node *pcrenode(const char *const */*av*/); |
6e403221 |
72 | |
73 | /*----- Error reporting ---------------------------------------------------*/ |
74 | |
75 | /* --- @ego@ --- * |
76 | * |
77 | * Arguments: @const char *p@ = pointer to program name |
78 | * |
79 | * Returns: --- |
80 | * |
81 | * Use: Stores what the program's name is. |
82 | */ |
83 | |
84 | extern void ego(const char */*p*/); |
85 | |
86 | /* --- @pquis@ --- * |
87 | * |
88 | * Arguments: @FILE *fp@ = output stream to write on |
89 | * @const char *p@ = pointer to string to write |
90 | * |
91 | * Returns: Zero if everything worked, EOF if not. |
92 | * |
93 | * Use: Writes the string @p@ to the output stream @fp@. Occurrences |
94 | * of the character `$' in @p@ are replaced by the program name |
95 | * as reported by @quis@. A `$$' is replaced by a single `$' |
96 | * sign. |
97 | */ |
98 | |
99 | extern int pquis(FILE */*fp*/, const char */*p*/); |
100 | |
101 | /* --- @die@ --- * |
102 | * |
103 | * Arguments: @const char *f@ = a @printf@-style format string |
104 | * @...@ = other arguments |
105 | * |
106 | * Returns: Never. |
107 | * |
108 | * Use: Reports an error and exits. |
109 | */ |
110 | |
111 | extern void die(const char */*f*/, ...); |
112 | |
113 | /*----- Memory allocation -------------------------------------------------*/ |
114 | |
115 | /* --- @xmalloc@ --- * |
116 | * |
117 | * Arguments: @size_t sz@ = size of block to allocate |
118 | * |
119 | * Returns: Pointer to allocated block. |
120 | * |
121 | * Use: Allocates memory. If there's not enough memory, the |
122 | * program exits. |
123 | */ |
124 | |
125 | extern void *xmalloc(size_t /*sz*/); |
126 | |
127 | /* --- @xrealloc@ --- * |
128 | * |
129 | * Arguments: @void *p@ = a pointer to allocated memory |
130 | * @size_t sz@ = new size of block wanted |
131 | * |
132 | * Returns: Pointer to resized block. |
133 | * |
134 | * Use: Resizes an allocated block. If there's not enough memory, |
135 | * the program exits. |
136 | */ |
137 | |
138 | extern void *xrealloc(void */*p*/, size_t /*sz*/); |
139 | |
140 | /*----- Dynamic string handling -------------------------------------------*/ |
141 | |
142 | /* --- @dstr_destroy@ --- * |
143 | * |
144 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
145 | * |
146 | * Returns: --- |
147 | * |
148 | * Use: Reclaims the space used by a dynamic string. |
149 | */ |
150 | |
151 | extern void dstr_destroy(dstr */*d*/); |
152 | |
153 | /* --- @dstr_reset@ --- * |
154 | * |
155 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
156 | * |
157 | * Returns: --- |
158 | * |
159 | * Use: Resets a string so that new data gets put at the beginning. |
160 | */ |
161 | |
162 | extern void dstr_reset(dstr */*d*/); |
163 | |
164 | /* --- @dstr_ensure@ --- * |
165 | * |
166 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
167 | * @size_t sz@ = amount of free space to ensure |
168 | * |
169 | * Returns: --- |
170 | * |
171 | * Use: Ensures that at least @sz@ bytes are available in the |
172 | * given string. |
173 | */ |
174 | |
175 | extern void dstr_ensure(dstr */*d*/, size_t /*sz*/); |
176 | |
177 | /* --- @dstr_putline@ --- * |
178 | * |
179 | * Arguments: @dstr *d@ = pointer to a dynamic string block |
180 | * @FILE *fp@ = a stream to read from |
181 | * |
182 | * Returns: The number of characters read into the buffer, or @EOF@ if |
183 | * end-of-file was reached before any characters were read. |
184 | * |
185 | * Use: Appends the next line from the given input stream to the |
186 | * string. A trailing newline is not added; a trailing null |
187 | * byte is appended, as for @dstr_putz@. |
188 | */ |
189 | |
190 | extern int dstr_putline(dstr */*d*/, FILE */*fp*/); |
191 | |
192 | /*----- That's all, folks -------------------------------------------------*/ |
193 | |
194 | #ifdef __cplusplus |
195 | } |
196 | #endif |
197 | |
198 | #endif |