annotate th_util.h @ 237:52a2f06fd41c

Update copyright years.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 19 Apr 2011 12:00:50 +0300
parents c136e668d9ac
children 578730eebe07
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
136
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
4 * (C) Copyright 2002-2010 Tecnic Software productions (TNSP)
0
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>
152
900768340e65 Including sys/types.h is required here.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
18 #include <sys/types.h>
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 #ifndef HAVE_NO_ASSERT
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 #include <assert.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 #ifdef HAVE_STRING_H
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 #include <string.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 #define HAVE_MEMSET 1
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #ifdef HAVE_STRINGS_H
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #include <strings.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 #ifdef HAVE_MEMORY_H
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 #include <memory.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
20
323c98360d8b Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
37 #ifdef TH_NO_DEFAULTS
37
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
38 #define TH_PROG_AUTHOR NULL
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
39 #define TH_PROG_LICENSE NULL
20
323c98360d8b Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
40 #else
237
52a2f06fd41c Update copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 193
diff changeset
41 #define TH_PROG_AUTHOR "By Matti 'ccr' Hämäläinen (C) Copyright 2011 TNSP"
37
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
42 #define TH_PROG_LICENSE "This software is licensed under GNU GPL version 2"
20
323c98360d8b Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
43 #endif
323c98360d8b Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
44
323c98360d8b Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
45
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 /* Replacement for assert() */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 #ifdef HAVE_NO_ASSERT
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 # ifdef NDEBUG
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 # define assert(NEXPR) /* stub */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 # else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 # 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
52 # endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 /* Global variables
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 */
169
fd93de78a115 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
57 extern int th_verbosityLevel;
37
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
58 extern char *th_prog_name,
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
59 *th_prog_fullname,
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
60 *th_prog_version,
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
61 *th_prog_author,
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
62 *th_prog_license;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 /* Functions
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 */
37
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
66 void th_init(char *progName, char *progFullName, char *progVersion,
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
67 char *progAuthor, char *progLicense);
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
68 void THERR(const char *, ...);
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
69 void THMSG(int, const char *, ...);
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
70 void THPRINT(int, const char *, ...);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
99
0313fabd8049 Added varargs versions of some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
72 void THERR_V(const char *, va_list);
0313fabd8049 Added varargs versions of some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
73 void THMSG_V(int, const char *, va_list);
0313fabd8049 Added varargs versions of some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
74 void THPRINT_V(int, const char *, va_list);
0313fabd8049 Added varargs versions of some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
75
37
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
76 void *th_malloc(size_t);
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
77 void *th_calloc(size_t, size_t);
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
78 void *th_realloc(void *, size_t);
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
79 void th_free(void *);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 #ifdef HAVE_MEMSET
37
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
82 #define th_memset memset
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 #else
37
8749f6517491 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
84 void *th_memset(void *, int, size_t);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86
136
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
87
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
88 /* Doubly linked list handling
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
89 */
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
90 typedef struct _qlist_t {
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
91 void *data;
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
92 size_t num;
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
93 struct _qlist_t *prev, *next;
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
94 } qlist_t;
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
95
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
96
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
97 qlist_t * th_llist_new(void *data);
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
98 void th_llist_free(qlist_t *list);
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
99 void th_llist_free_func(qlist_t *list, void (*freefunc)(void *data));
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
100
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
101 qlist_t * th_llist_append(qlist_t **list, void *data);
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
102 qlist_t * th_llist_prepend(qlist_t **list, void *data);
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
103 void th_llist_delete(qlist_t **list, const void *data);
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
104 void th_llist_delete_node(qlist_t **list, qlist_t *node);
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
105
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
106 qlist_t * th_llist_get_nth(qlist_t *list, const size_t n);
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
107 size_t th_llist_length(const qlist_t *list);
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
108 ssize_t th_llist_position(const qlist_t *list, const qlist_t *node);
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
109
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
110 qlist_t * th_llist_find(qlist_t *list, const void *data);
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
111 qlist_t * th_llist_find_func(qlist_t *list, const void *userdata, int (compare)(const void *, const void *));
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
112
4ec36204d34e Add doubly linked list handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
113
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 #ifdef __cplusplus
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 #endif /* _TH_UTIL_H */