0223c54ecc92b757131f8281b3ff4e40870d8524
3 * External definitions for Anag
5 * (c) 2001 Mark Wooding
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Anag: a simple wordgame helper.
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.
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.
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.
34 /*----- Header files ------------------------------------------------------*/
47 /*----- Preliminaries -----------------------------------------------------*/
50 # define GCC_VERSION_P(maj, min) \
51 (__GNUC__ > (maj) || (__GNUC__ == (maj) && __GNUC_MINOR__ >= (min)))
53 # define GCC_VERSION_P(maj, min) 0
57 # define CLANG_VERSION_P(maj, min) \
58 (__clang_major__ > (maj) || (__clang_major__ == (maj) && \
59 __clang_minor__ >= (min)))
61 # define CLANG_VERSION_P(maj, min) 0
64 #if GCC_VERSION_P(2, 5) || CLANG_VERSION_P(3, 3)
65 # define NORETURN __attribute__((noreturn))
66 # define PRINTF_LIKE(fix, aix) __attribute__((format(printf, fix, aix)))
77 /*----- Data structures ---------------------------------------------------*/
80 int (*func
)(struct node */
*n*/
, const char */
*p*/
, size_t /*sz*/);
89 #define DSTR_INIT { 0, 0, 0 }
91 /*----- Node types --------------------------------------------------------*/
93 extern node
*anagram(const char *const */
*av*/
);
94 extern node
*subgram(const char *const */
*av*/
);
95 extern node
*wildcard(const char *const */
*av*/
);
96 extern node
*trackword(const char *const */
*av*/
);
97 extern node
*mono(const char *const */
*av*/
);
98 extern node
*regexp(const char *const */
*av*/
);
99 extern node
*pcrenode(const char *const */
*av*/
);
100 extern node
*longest(const char *const */
*av*/
);
101 extern node
*shortest(const char *const */
*av*/
);
103 /*----- Exit codes --------------------------------------------------------*/
109 /*----- Error reporting ---------------------------------------------------*/
113 * Arguments: @const char *p@ = pointer to program name
117 * Use: Stores what the program's name is.
120 extern void ego(const char */
*p*/
);
124 * Arguments: @FILE *fp@ = output stream to write on
125 * @const char *p@ = pointer to string to write
127 * Returns: Zero if everything worked, EOF if not.
129 * Use: Writes the string @p@ to the output stream @fp@. Occurrences
130 * of the character `$' in @p@ are replaced by the program name
131 * as reported by @quis@. A `$$' is replaced by a single `$'
135 extern int pquis(FILE */
*fp*/
, const char */
*p*/
);
139 * Arguments: @const char *f@ = a @printf@-style format string
140 * @...@ = other arguments
144 * Use: Reports an error and exits.
147 extern PRINTF_LIKE(1, 2) NORETURN
void die(const char */
*f*/
, ...);
149 /*----- Memory allocation -------------------------------------------------*/
151 /* --- @xmalloc@ --- *
153 * Arguments: @size_t sz@ = size of block to allocate
155 * Returns: Pointer to allocated block.
157 * Use: Allocates memory. If there's not enough memory, the
161 extern void *xmalloc(size_t /*sz*/);
163 /* --- @xrealloc@ --- *
165 * Arguments: @void *p@ = a pointer to allocated memory
166 * @size_t sz@ = new size of block wanted
168 * Returns: Pointer to resized block.
170 * Use: Resizes an allocated block. If there's not enough memory,
174 extern void *xrealloc(void */
*p*/
, size_t /*sz*/);
176 /*----- Dynamic string handling -------------------------------------------*/
178 /* --- @dstr_destroy@ --- *
180 * Arguments: @dstr *d@ = pointer to a dynamic string block
184 * Use: Reclaims the space used by a dynamic string.
187 extern void dstr_destroy(dstr */
*d*/
);
189 /* --- @dstr_reset@ --- *
191 * Arguments: @dstr *d@ = pointer to a dynamic string block
195 * Use: Resets a string so that new data gets put at the beginning.
198 extern void dstr_reset(dstr */
*d*/
);
200 /* --- @dstr_ensure@ --- *
202 * Arguments: @dstr *d@ = pointer to a dynamic string block
203 * @size_t sz@ = amount of free space to ensure
207 * Use: Ensures that at least @sz@ bytes are available in the
211 extern void dstr_ensure(dstr */
*d*/
, size_t /*sz*/);
213 /* --- @dstr_putline@ --- *
215 * Arguments: @dstr *d@ = pointer to a dynamic string block
216 * @FILE *fp@ = a stream to read from
218 * Returns: The number of characters read into the buffer, or @EOF@ if
219 * end-of-file was reached before any characters were read.
221 * Use: Appends the next line from the given input stream to the
222 * string. A trailing newline is not added; a trailing null
223 * byte is appended, as for @dstr_putz@.
226 extern int dstr_putline(dstr */
*d*/
, FILE */
*fp*/
);
228 /*----- Infrastructure ----------------------------------------------------*/
230 /* --- @atend_register@ --- *
232 * Arguments: @int (*func)(void *)@ = function to call
233 * @void *p@ = handle to pass to it
237 * Use: Adds a function to the list of things to do at the end of the
238 * program. The function should return nonzero if it produced
242 extern void atend_register(int (*/
*func*/
)(void */
*p*/
), void */
*p*/
);
244 /*----- That's all, folks -------------------------------------------------*/