[go: up one dir, main page]

Menu

[4f9184]: / src / base.h  Maximize  Restore  History

Download this file

93 lines (69 with data), 2.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef __BASE_H
#define __BASE_H
#ifdef NEED_BOOL
typedef { false = 0, true = 1 } bool;
#endif
char *newstr(char const *str);
char *newstr(char const *str, int len);
char *strJoin(char const *str, ...);
bool isempty(char const *str);
bool isreg(char const *path);
void die(int exitcode, char const *msg, ...);
void warn(char const *msg, ...);
void msg(char const *msg, ...);
// !!! remove this
void *MALLOC(unsigned int len);
void *REALLOC(void *p, unsigned int new_len);
void FREE(void *p);
#define ACOUNT(x) (sizeof(x)/sizeof(x[0]))
#ifndef DIR_DELIMINATOR
# define DIR_DELIMINATOR '/'
#endif
#ifndef ISBLANK
# define ISBLANK(c) (((c) == ' ') || ((c) == '\t'))
#endif
extern "C" {
#ifdef __EMX__
char* __XOS2RedirRoot(char const*);
#define REDIR_ROOT(path) __XOS2RedirRoot(path)
#else
#define REDIR_ROOT(path) (path)
#endif
}
//!!! clean these up
#define KEY_MODMASK(x) ((x) & (app->KeyMask))
#define BUTTON_MASK(x) ((x) & (app->ButtonMask))
#define BUTTON_MODMASK(x) ((x) & (app->ButtonKeyMask))
#define IS_BUTTON(s,b) (BUTTON_MODMASK(s) == (b))
#define ISMASK(w,e,n) (((w) & ~(n)) == (e))
#define HASMASK(w,e,n) ((((w) & ~(n)) & (e)) == (e))
#define ISLOWER(c) ((c) >= 'a' && (c) <= 'z')
#define TOUPPER(c) (ISLOWER(c) ? (c) - 'a' + 'A' : (c))
inline bool strIsEmpty(char const *str) {
if (str) while (*str)
if (*str++ > ' ') return false;
return true;
}
int strpcmp(char const *str, char const *pfx, char const *dlim = "=");
#ifndef HAVE_BASENAME
char *basename(char const *filename);
#endif
inline int unhex(char c) {
return ((c >= '0' && c <= '9') ? c - '0' :
(c >= 'A' && c <= 'F') ? c - 'A' + 10 :
(c >= 'a' && c <= 'f') ? c - 'a' + 10 : -1);
}
template <class T>
inline T min(T a, T b) {
return (a < b ? a : b);
}
template <class T>
inline T max(T a, T b) {
return (a > b ? a : b);
}
template <class T>
inline T clamp(T value, T minimum, T maximum) {
return max(min(value, maximum), minimum);
}
#include "debug.h"
#endif