ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libukcprog/src/ukcprog.h
Revision: 1.1
Committed: Sat Mar 29 16:30:33 2003 UTC (21 years, 1 month ago) by tdb
Content type: text/plain
Branch: MAIN
CVS Tags: LIBUKCPROG_1_0_2, LIBUKCPROG_1_0_1, LIBUKCPROG_1_0, HEAD
Log Message:
libukcprog is now a seperate package. I doubt this will be much use to
anyone other than us, but I see no reason why we can't package it up
and distribute it. Obviously we can't attach the GPL to this, as we
don't own it.

File Contents

# Content
1 /* ukcprog.h -- Declarations for UKC programmers' library routines. */
2
3 /* Copyright 1993 Godfrey Paul, University of Kent at Canterbury.
4 *
5 * You can do what you like with this source code as long as
6 * you don't try to make money out of it and you include an
7 * unaltered copy of this message (including the copyright).
8 */
9
10 /* $Id: ukcprog.h,v 1.36 1996/04/10 10:27:17 mtr Exp $ UKC */
11
12 #ifndef UKCPROG_H_DEFINED
13 #define UKCPROG_H_DEFINED
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 #if defined(__GNUC__) && __GNUC_MINOR >= 2
20 #define UKCPROG__NORETURN __attribute__((__noreturn__))
21 #else
22 #define UKCPROG__NORETURN
23 #endif
24
25 #ifdef __STDC__
26 #ifndef PROTO
27 #define PROTO(a) a
28 #endif /* !PROTO */
29
30 typedef void *voidptr;
31 typedef const void *constvoidptr;
32
33 #include <stddef.h> /* needed for size_t */
34
35 #else /* !__STDC__ */
36
37 #include <sys/types.h> /* size_t for old C */
38
39 #ifndef PROTO
40 #define PROTO(a) ()
41 #endif /* !PROTO */
42
43 /* Patch up for things that are missing without ANSI C. */
44 #ifndef const
45 #define const
46 #endif
47 #ifndef volatile
48 #define volatile
49 #endif
50 #ifndef signed
51 #define signed
52 #endif
53
54 typedef char *voidptr;
55 typedef char *constvoidptr;
56
57 #endif /* !__STDC__ */
58
59 /* Defining boolean type. This might cause problems for some ... */
60 #ifndef FALSE
61 #define FALSE 0
62 #endif
63 #ifndef TRUE
64 #define TRUE 1
65 #endif
66 #ifndef bool
67 #define bool int
68 #endif
69
70 /* Macro to get control characters (works for ASCII only). */
71 #define CONTROL(c) ((c) & 0x1f)
72
73 /* Define NULL - this avoids having the whole of stdio.h */
74 #ifndef NULL
75 #define NULL 0
76 #endif
77
78 /* Macro to concatenate two or three names. */
79 #ifdef CAT
80 #undef CAT
81 #endif /* CAT */
82
83 #if defined(__STDC__) && !defined(VMS)
84 #define CAT(a,b) a ## b
85 #define CAT3(a,b,c) a ## b ## c
86 #else
87 #define _IDENT(a) a
88 #define CAT(a,b) _IDENT(a)b
89 #define CAT3(a,b,c) CAT(a,b)c
90 #endif
91
92 /* from panic.c */
93 typedef void (*panic_handler_t) PROTO((const char *message));
94
95 panic_handler_t install_panic_handler PROTO((panic_handler_t handler));
96
97 void panic PROTO((const char *message)) UKCPROG__NORETURN;
98
99
100 /* from e_malloc.c */
101 voidptr e_malloc PROTO((size_t size));
102
103
104 /* from e_realloc.c */
105 voidptr e_realloc PROTO((voidptr old, size_t size));
106
107
108 /* from strsave.c */
109 char *strsave PROTO((const char *s));
110
111
112 /* from config.c */
113 char *config_trim_line PROTO((char *line));
114
115 #ifdef UKC_WANT_FORMF_CHECKS
116 #define FORMF_ARGS(fpos, argpos) __attribute__((format(printf, fpos, argpos)))
117 #else
118
119 #ifdef VMS
120 /* The VMS C compiler with /STANDARD=PORTABLE complains about unused
121 * arguments in macros. This grossness is to shut it up.
122 */
123 #define FORMF_ARGS(fpos, apos) ; extern int CAT(__ukc,fpos), CAT(__ukc,apos)
124 #else
125 #define FORMF_ARGS(fpos, argpos) /* nothing */
126 #endif
127
128 #endif
129
130 /* from formf.c */
131 #ifdef __STDC__
132 #include <stdarg.h> /* nasty, but needed for prototype */
133 #endif
134
135 char *formf PROTO((char *buffer_space, int buffer_size,
136 const char *format, va_list args));
137
138
139 /* from errf.c */
140 typedef void (*errf_ofunc_t) PROTO((const char *string));
141
142 errf_ofunc_t errf_set_ofunc PROTO((errf_ofunc_t func));
143 const char *errf_set_prefix PROTO((const char *prefix));
144 const char *errf_get_prefix PROTO((void));
145 void errf_set_progname PROTO((const char *progname));
146 const char *errf_get_progname PROTO((void));
147 void errf_usage PROTO((const char *usage));
148
149 void errf PROTO((const char *fmt, ...)) FORMF_ARGS(1, 2);
150 char *strf PROTO((const char *fmt, ...)) FORMF_ARGS(1, 2);
151 void strnf PROTO((char *buf, size_t bufsize, const char *fmt, ...))
152 FORMF_ARGS(3, 4);
153
154 /* from log.c */
155 #define LG_ALL 0 /* lowest priority */
156 #define LG_DEBUG 1 /* debugging messages */
157 #define LG_INFO 5 /* information messages */
158 #define LG_ERR 9 /* error messages */
159 #define LG_LOG 10 /* highest priority; messages from the logger */
160
161 int logf_set_ofile PROTO((const char *filename, const char *prefix));
162 void logf PROTO((int level, const char *fmt, ...)) FORMF_ARGS(2, 3);
163 int logf_set_level PROTO((int new_level));
164 void logf_errf_ofunc PROTO((const char *str));
165
166 /* from fpgetline.c
167 *
168 * Only include this prototype if stdio.h has been #included already.
169 * This is to mandating the inclusion of stdio.h unless fpgetline()
170 * is required.
171 */
172 #ifdef EOF
173 char *fpgetline PROTO((FILE *fp));
174 #endif
175
176
177 /* from alloc.c */
178
179 typedef struct alloc_pool_s alloc_pool_t;
180 typedef struct alloc_mark_s alloc_mark_t;
181
182 /* Backwards compatibility.
183 */
184 typedef alloc_pool_t *alloc_id_t;
185 typedef alloc_mark_t *alloc_mark_id_t;
186
187 alloc_pool_t *alloc_create_pool PROTO((void));
188 void alloc_free_pool PROTO((alloc_pool_t *ap));
189 void alloc_reset_pool PROTO((alloc_pool_t *ap));
190
191 /* Various forms of allocation. alloc() aligns like malloc,
192 * allocstr() doesn't. alloc_strdup() is like strdup() but
193 * used allocstr() rather than malloc(). All of the preceding
194 * calls panic if they run out memory. alloc_ck() and allocstr_ck()
195 * are like alloc() and allocstr() except that they return NULL
196 * rather than panicking if memory runs out.
197 */
198 voidptr alloc PROTO((alloc_pool_t *ap, size_t nbytes));
199 char *allocstr PROTO((alloc_pool_t *ap, size_t nbytes));
200 voidptr alloc_ck PROTO((alloc_pool_t *ap, size_t nbytes));
201 char *allocstr_ck PROTO((alloc_pool_t *ap, size_t nbytes));
202 char *alloc_strdup PROTO((alloc_pool_t *ap, const char *s));
203
204 /* Control - set and clear debug flags both globally and per-pool.
205 * If the debug flag is set new memory is initialised to garbage
206 * and set to (different) garbage when a pool is freed.
207 */
208 bool alloc_set_default_debug_flag PROTO((bool val));
209 bool alloc_set_debug_flag PROTO((alloc_pool_t *ap, bool val));
210
211 /* alloc_mark() returns an alloc_mark_id that represents the current
212 * state of the alloc pool. alloc_release() releases any memory
213 * allocated since the alloc_mark() call.
214 */
215 alloc_mark_t *alloc_mark PROTO((alloc_pool_t *ap));
216 void alloc_release PROTO((alloc_pool_t *ap, alloc_mark_t *am));
217
218
219 /* from ssplit.c */
220
221 char **ssplit PROTO((const char *line, const char *delimiters));
222
223 /* from ip.c */
224
225 #ifdef IPPROTO_TCP
226 int get_host_addr PROTO((const char *hostname, struct in_addr *p_addr));
227 int get_service_port PROTO((const char *servname, int *p_port));
228 #endif
229
230 /* from ebuf.c */
231
232 typedef struct ebuf_s ebuf_t;
233
234 void ebuf_reset PROTO((ebuf_t *eb));
235 ebuf_t *ebuf_create PROTO((bool errors_are_fatal));
236 ebuf_t *ebuf_start PROTO((ebuf_t *ebuf, bool errors_are_fatal));
237 int ebuf_add PROTO((ebuf_t *eb, constvoidptr buf, size_t count));
238 int ebuf_addstr PROTO((ebuf_t *eb, const char *str));
239 voidptr ebuf_get PROTO((ebuf_t *eb, int *p_len));
240 void ebuf_free PROTO((ebuf_t *eb));
241
242 /* from sccsdata.c */
243 const char *ukcprog_version PROTO((void));
244
245 #ifdef __cplusplus
246 }
247 #endif
248
249 #endif /* !UKCPROG_H_DEFINED */