bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
|
21
by Gustav Hartvigsson
Woops! |
1 |
/*
|
2 |
Copyright (c) 2013-2014 Gustav Hartvigsson
|
|
3 |
||
4 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5 |
of this software and associated documentation files (the "Software"), to deal
|
|
6 |
in the Software without restriction, including without limitation the rights
|
|
7 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8 |
copies of the Software, and to permit persons to whom the Software is
|
|
9 |
furnished to do so, subject to the following conditions:
|
|
10 |
||
11 |
The above copyright notice and this permission notice shall be included in
|
|
12 |
all copies or substantial portions of the Software.
|
|
13 |
||
14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20 |
THE SOFTWARE.
|
|
21 |
*/
|
|
22 |
||
23 |
#ifndef __H_UTILS__
|
|
24 |
#define __H_UTILS__
|
|
25 |
||
26 |
#include "defs.h" |
|
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
27 |
#include <stddef.h> |
|
26
by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works. |
28 |
#include "config.h" |
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
29 |
#include <stdio.h> |
|
23
by Gustav Hartvigsson
* Fixed some of the build warnings. |
30 |
|
|
21
by Gustav Hartvigsson
Woops! |
31 |
BEGIN_DECLS
|
32 |
||
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
33 |
/** @file
|
34 |
* A collect of utility functions.
|
|
35 |
*/
|
|
36 |
||
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
37 |
/**
|
38 |
* Creats a new C string with the correct length from a long string.
|
|
39 |
* This may be a costly operation.
|
|
40 |
*
|
|
41 |
* The restulting string must be freed by caller.
|
|
42 |
*/
|
|
|
21
by Gustav Hartvigsson
Woops! |
43 |
char * s_string_new (const char * s); |
|
26
by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works. |
44 |
|
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
45 |
/**
|
46 |
* Creats a new C string with the correct length using standard fprint style
|
|
47 |
* format.
|
|
48 |
*
|
|
49 |
* The restulting string must be freed by caller.
|
|
50 |
*/
|
|
51 |
char * s_string_new_fmt (const char * format, ...); |
|
52 |
||
53 |
/**
|
|
54 |
* Same as s_string_new, but with a set length.
|
|
55 |
*
|
|
56 |
* The restulting string must be freed by caller
|
|
57 |
*/
|
|
|
21
by Gustav Hartvigsson
Woops! |
58 |
char * s_string_new_with_len (const char * s, size_t len); |
59 |
||
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
60 |
/**
|
61 |
* Returns a C string with the current time (as run).
|
|
62 |
*
|
|
63 |
* The restulting string must be freed by caller.
|
|
64 |
*/
|
|
65 |
char * s_current_time (void); |
|
66 |
||
67 |
#ifndef strdup
|
|
68 |
/* strdup is not ISO C, so we have to declare it somewhare, this should work
|
|
69 |
* even if we do not impliment the function ourselfs.
|
|
70 |
*
|
|
71 |
* This just to supress a compiler warning.
|
|
72 |
*/
|
|
73 |
char * strdup(const char *str); |
|
74 |
#endif
|
|
75 |
||
76 |
/** Just a standard print function. */
|
|
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
77 |
#define s_print(p, ...)\
|
78 |
fprintf (stdout, p, ##__VA_ARGS__)
|
|
79 |
||
80 |
/**
|
|
81 |
* Print a yellow warning to stderr.
|
|
82 |
*/
|
|
83 |
#define s_warn_print(p, ...)\
|
|
84 |
fprintf (stderr, BOLDYELLOW "[WARN] " p "\n" RESET, ##__VA_ARGS__)
|
|
|
21
by Gustav Hartvigsson
Woops! |
85 |
|
|
26
by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works. |
86 |
/**
|
87 |
* prints a red message with the prefix [ERR]
|
|
88 |
*/
|
|
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
89 |
#define s_err_print(p, ...)\
|
90 |
fprintf (stderr, RED "[ERR] " p RESET "\n", ##__VA_ARGS__)
|
|
91 |
||
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
92 |
#if DEBUG
|
|
26
by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works. |
93 |
/**
|
94 |
* debug_print is a function that only prints if compiled with the debug
|
|
95 |
* flag not unset.
|
|
96 |
*/
|
|
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
97 |
#define s_dbg_print(M, ...)\ |
98 |
fprintf (stdout, YELLOW "[DEBUG][%s:%d] " M RESET "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
|
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
99 |
#else
|
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
100 |
#define s_dbg_print(M, ...) |
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
101 |
#endif
|
102 |
||
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
103 |
/**
|
104 |
* Round a up a number to a multiple of an other.
|
|
105 |
*
|
|
106 |
* @param num The number to round up.
|
|
107 |
* @param multiple The multiple to round up to.
|
|
108 |
*
|
|
109 |
* See: http://stackoverflow.com/a/9194117
|
|
110 |
*/
|
|
111 |
#define round_up(num, multiple) (((num + multiple - 1) / multiple) * multiple)
|
|
112 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
113 |
BEGIN_DECLS
|
|
21
by Gustav Hartvigsson
Woops! |
114 |
|
115 |
#endif
|