-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasics.h
97 lines (85 loc) · 2.47 KB
/
basics.h
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
93
94
95
96
97
#define print(str) printf("%s", (str))
#define printl(str) printf("%s\n", (str))
#ifndef EOL
# define EOL '\n'
#endif
#ifndef NULLCHAR
# define NULLCHAR '\0'
#endif
#ifndef var
# define var extern
#endif
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef signed char int8;
typedef unsigned char uint8;
typedef signed short int int16;
typedef unsigned short int uint16;
typedef signed int int32;
typedef unsigned int uint32;
typedef signed long int int64;
typedef unsigned long int uint64;
/*
* Boolean constants
*/
#ifndef TRUE
# define FALSE 0 // note: this is an int, not a long!
# define TRUE 1
#endif
/*
* Some usefull constants for strings :D
*/
#ifndef IN
# define OUT 0
# define IN 1
#endif
/*
* Min and Max :D
*/
#ifndef MAX
# define MAX(a, b) ((a) < (b) ? (b) : (a))
#endif
#ifndef MIN
# define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
/*
* Two string Concatination
*/
#ifndef CONCAT
# define CONCAT(a, b) a##b
#endif
/*
* n string concatination
*/
#define strcpyall(buf, offset, ...) \
do { \
char *bp = (char *)(buf + offset); /*so we can add to the end of a string*/ \
const char *s, \
*a[] = {__VA_ARGS__, NULL}, \
**ss = a; \
while ((s = *ss++)) \
while ((*s) && ((++offset) < (int)sizeof(buf))) \
*bp++ = *s++; \
if (offset != sizeof(buf)) *bp = 0; \
} while (0)
/*
* foreach in c haha
*/
#define foreach(item, array) \
for (int keep = 1, \
count = 0, \
size = sizeof(array) / sizeof *(array); \
keep && count != size; \
keep = !keep, count++) \
for (item = (array) + count; keep; keep = !keep)
/*
* LENGTH of an array
*/
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
/*
* is even and odd for number
*/
#define IS_EVEN(num) (!IS_ODD((num)))
#define IS_ODD(num) ((num)&1)