0
|
1 /*
|
|
2 * Generic utility-functions, macros and defaults
|
|
3 * Programmed and designed by Matti 'ccr' Hamalainen
|
|
4 * (C) Copyright 2002-2008 Tecnic Software productions (TNSP)
|
|
5 *
|
|
6 * Please read file 'COPYING' for information on license and distribution.
|
|
7 */
|
|
8 #ifndef _TH_UTIL_H
|
|
9 #define _TH_UTIL_H
|
|
10
|
|
11 #ifdef __cplusplus
|
|
12 extern "C" {
|
|
13 #endif
|
|
14
|
|
15 #include "th_types.h"
|
|
16 #include <stdarg.h>
|
|
17 #include <stdlib.h>
|
|
18 #ifndef HAVE_NO_ASSERT
|
|
19 #include <assert.h>
|
|
20 #endif
|
|
21
|
|
22 #ifdef HAVE_STRING_H
|
|
23 #include <string.h>
|
|
24 #define HAVE_MEMSET 1
|
|
25 #else
|
|
26 #ifdef HAVE_STRINGS_H
|
|
27 #include <strings.h>
|
|
28 #endif
|
|
29 #endif
|
|
30
|
|
31 #ifdef HAVE_MEMORY_H
|
|
32 #include <memory.h>
|
|
33 #endif
|
|
34
|
|
35
|
20
|
36 #ifdef TH_NO_DEFAULTS
|
37
|
37 #define TH_PROG_AUTHOR NULL
|
|
38 #define TH_PROG_LICENSE NULL
|
20
|
39 #else
|
37
|
40 #define TH_PROG_AUTHOR "By Matti 'ccr' Hämäläinen (C) Copyright 2008 TNSP"
|
|
41 #define TH_PROG_LICENSE "This software is licensed under GNU GPL version 2"
|
20
|
42 #endif
|
|
43
|
|
44
|
0
|
45 /* Replacement for assert() */
|
|
46 #ifdef HAVE_NO_ASSERT
|
|
47 # ifdef NDEBUG
|
|
48 # define assert(NEXPR) /* stub */
|
|
49 # else
|
|
50 # define assert(NEXPR) do { if (!(NEXPR)) { fprintf(stderr, "[%s:%d] assert(" # NEXPR ") failed!\n", __FILE__, __LINE__); abort(); } } while (0)
|
|
51 # endif
|
|
52 #endif
|
|
53
|
|
54 /* Global variables
|
|
55 */
|
37
|
56 extern int th_verbosityLevel;
|
|
57 extern char *th_prog_name,
|
|
58 *th_prog_fullname,
|
|
59 *th_prog_version,
|
|
60 *th_prog_author,
|
|
61 *th_prog_license;
|
0
|
62
|
|
63 /* Functions
|
|
64 */
|
37
|
65 void th_init(char *progName, char *progFullName, char *progVersion,
|
|
66 char *progAuthor, char *progLicense);
|
|
67 void THERR(const char *, ...);
|
|
68 void THMSG(int, const char *, ...);
|
|
69 void THPRINT(int, const char *, ...);
|
0
|
70
|
37
|
71 void *th_malloc(size_t);
|
|
72 void *th_calloc(size_t, size_t);
|
|
73 void *th_realloc(void *, size_t);
|
|
74 void th_free(void *);
|
0
|
75
|
|
76 #ifdef HAVE_MEMSET
|
37
|
77 #define th_memset memset
|
0
|
78 #else
|
37
|
79 void *th_memset(void *, int, size_t);
|
0
|
80 #endif
|
|
81
|
|
82 #ifdef __cplusplus
|
|
83 }
|
|
84 #endif
|
|
85 #endif /* _TH_UTIL_H */
|