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*/);
99 extern node *regexp(const char *const */*av*/);
101 #if defined(HAVE_PCRE) || defined(HAVE_PCRE2)
102 extern node *pcrenode(const char *const */*av*/);
104 extern node *longest(const char *const */*av*/);
105 extern node *shortest(const char *const */*av*/);
107 /*----- Exit codes --------------------------------------------------------*/
113 /*----- Error reporting ---------------------------------------------------*/
117 * Arguments: @const char *p@ = pointer to program name
121 * Use: Stores what the program's name is.
124 extern void ego(const char */*p*/);
128 * Arguments: @FILE *fp@ = output stream to write on
129 * @const char *p@ = pointer to string to write
131 * Returns: Zero if everything worked, EOF if not.
133 * Use: Writes the string @p@ to the output stream @fp@. Occurrences
134 * of the character `$' in @p@ are replaced by the program name
135 * as reported by @quis@. A `$$' is replaced by a single `$'
139 extern int pquis(FILE */*fp*/, const char */*p*/);
143 * Arguments: @const char *f@ = a @printf@-style format string
144 * @...@ = other arguments
148 * Use: Reports an error and exits.
151 extern PRINTF_LIKE(1, 2) NORETURN void die(const char */*f*/, ...);
153 /*----- Memory allocation -------------------------------------------------*/
155 /* --- @xmalloc@ --- *
157 * Arguments: @size_t sz@ = size of block to allocate
159 * Returns: Pointer to allocated block.
161 * Use: Allocates memory. If there's not enough memory, the
165 extern void *xmalloc(size_t /*sz*/);
167 /* --- @xrealloc@ --- *
169 * Arguments: @void *p@ = a pointer to allocated memory
170 * @size_t sz@ = new size of block wanted
172 * Returns: Pointer to resized block.
174 * Use: Resizes an allocated block. If there's not enough memory,
178 extern void *xrealloc(void */*p*/, size_t /*sz*/);
180 /*----- Dynamic string handling -------------------------------------------*/
182 /* --- @dstr_destroy@ --- *
184 * Arguments: @dstr *d@ = pointer to a dynamic string block
188 * Use: Reclaims the space used by a dynamic string.
191 extern void dstr_destroy(dstr */*d*/);
193 /* --- @dstr_reset@ --- *
195 * Arguments: @dstr *d@ = pointer to a dynamic string block
199 * Use: Resets a string so that new data gets put at the beginning.
202 extern void dstr_reset(dstr */*d*/);
204 /* --- @dstr_ensure@ --- *
206 * Arguments: @dstr *d@ = pointer to a dynamic string block
207 * @size_t sz@ = amount of free space to ensure
211 * Use: Ensures that at least @sz@ bytes are available in the
215 extern void dstr_ensure(dstr */*d*/, size_t /*sz*/);
217 /* --- @dstr_putline@ --- *
219 * Arguments: @dstr *d@ = pointer to a dynamic string block
220 * @FILE *fp@ = a stream to read from
222 * Returns: The number of characters read into the buffer, or @EOF@ if
223 * end-of-file was reached before any characters were read.
225 * Use: Appends the next line from the given input stream to the
226 * string. A trailing newline is not added; a trailing null
227 * byte is appended, as for @dstr_putz@.
230 extern int dstr_putline(dstr */*d*/, FILE */*fp*/);
232 /*----- Infrastructure ----------------------------------------------------*/
234 /* --- @atend_register@ --- *
236 * Arguments: @int (*func)(void *)@ = function to call
237 * @void *p@ = handle to pass to it
241 * Use: Adds a function to the list of things to do at the end of the
242 * program. The function should return nonzero if it produced
246 extern void atend_register(int (*/*func*/)(void */*p*/), void */*p*/);
248 /*----- That's all, folks -------------------------------------------------*/