annotate th_util.h @ 0:728243125263

Import.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 20 Mar 2008 00:15:03 +0000
parents
children 323c98360d8b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Generic utility-functions, macros and defaults
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2002-2008 Tecnic Software productions (TNSP)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #ifndef _TH_UTIL_H
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #define _TH_UTIL_H
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #ifdef __cplusplus
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 extern "C" {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #include "th_types.h"
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #include <stdarg.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #include <stdlib.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 #ifndef HAVE_NO_ASSERT
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 #include <assert.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 #ifdef HAVE_STRING_H
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 #include <string.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 #define HAVE_MEMSET 1
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 #else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #ifdef HAVE_STRINGS_H
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #include <strings.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 #ifdef HAVE_MEMORY_H
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 #include <memory.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 /* Replacement for assert() */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 #ifdef HAVE_NO_ASSERT
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 # ifdef NDEBUG
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 # define assert(NEXPR) /* stub */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 # else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 # define assert(NEXPR) do { if (!(NEXPR)) { fprintf(stderr, "[%s:%d] assert(" # NEXPR ") failed!\n", __FILE__, __LINE__); abort(); } } while (0)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 # endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 /* Global variables
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 extern int th_verbosityLevel;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 extern char *th_prog_name,
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 *th_prog_fullname,
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 *th_prog_version,
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 *th_prog_author,
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 *th_prog_license;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 /* Functions
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 void th_init(char *progName, char *progFullName, char *progVersion,
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 char *progAuthor, char *progLicense);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 void THERR(const char *, ...);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 void THMSG(int, const char *, ...);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 void THPRINT(int, const char *, ...);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 void * th_malloc(size_t);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 void * th_calloc(size_t, size_t);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 void * th_realloc(void *, size_t);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 void th_free(void *);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 #ifdef HAVE_MEMSET
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 #define th_memset memset
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 #else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 void *th_memset(void *, int, size_t);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 #ifdef __cplusplus
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 #endif /* _TH_UTIL_H */