-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtools.h
More file actions
128 lines (109 loc) · 3.11 KB
/
tools.h
File metadata and controls
128 lines (109 loc) · 3.11 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* License:
* This Source Code Form is subject to the terms of
* the Mozilla Public License, v. 2.0. If a copy of
* the MPL was not distributed with this file, You
* can obtain one at http://mozilla.org/MPL/2.0/.
*
* Authors:
* David Ellsworth <davide.by.zero@gmail.com>
*/
#include <stdio.h>
#include <malloc.h>
typedef signed char int8;
typedef unsigned char Uint8;
typedef signed short int int16;
typedef unsigned short int Uint16;
typedef signed long int int32;
typedef unsigned long int Uint32;
typedef signed long long int int64;
typedef unsigned long long int Uint64;
typedef unsigned char Uchar;
typedef unsigned int Uint;
typedef Uint8 bool8;
#define inrange(n,a,b) ((Uint)((n)-(a))<=(Uint)((b)-(a)))
#define inrangex(n,a,b) ((Uint)((n)-(a))<(Uint)((b)-(a)))
#define inrange64(n,a,b) ((Uint64)((n)-(a))<=(Uint64)((b)-(a)))
#define inrangex64(n,a,b) ((Uint64)((n)-(a))<(Uint64)((b)-(a)))
#define MAX_EXTEND(n) ((Uint64)((n)+1)-1)
template <size_t size>
char (*__strlength_helper(char const (&_String)[size]))[size];
#define strlength(_String) (sizeof(*__strlength_helper(_String))-1)
#ifdef __has_builtin
#define HAS_BUILTIN(x) __has_builtin(x)
#else
#define HAS_BUILTIN(x) 0
#endif
#ifdef _MSC_VER
#define UNREACHABLE_CODE __assume(0)
#elif defined(__GNUC__) || HAS_BUILTIN(__builtin_unreachable)
#define UNREACHABLE_CODE __builtin_unreachable()
#else
#endif
#ifdef _MSC_VER
#define ALWAYS_INLINE __forceinline
#elif __has_attribute(always_inline)
#define ALWAYS_INLINE __attribute__((always_inline))
#else
#define ALWAYS_INLINE
#endif
#if defined(_MSC_VER) && _MSC_VER < 1900
#define FLEXIBLE_SIZE_ARRAY 1
#else
#define FLEXIBLE_SIZE_ARRAY
#endif
#ifdef _MSC_VER
#define PRIptrdiff_t "Iu"
#define PRIsize_t "Iu"
#else
#define PRIptrdiff_t "tu"
#define PRIsize_t "zu"
#endif
template <typename UINT_TYPE>
UINT_TYPE readNumericConstant(const char *&buf);
Uint intLength(Uint32 i);
Uint intLength(Uint64 i);
class ParsingError {};
template <typename TYPE>
inline void tellCompilerVariableIsntUninitialized(TYPE &n)
{
}
#ifdef _MSC_VER
#define GETC _getc_nolock // using this results in a huge speed-up under MS Visual C++
#else
#define GETC getc
#endif
class LineGetter
{
char *buf;
size_t currentSize;
public:
LineGetter(size_t initialSize) : currentSize(initialSize) // initialSize must be nonzero
{
buf = (char*)malloc(initialSize);
}
char *fgets(FILE *f)
{
int ch = GETC(f);
if (ch == EOF)
return NULL;
size_t count = currentSize;
char *pos = buf;
for (;;)
{
if (ch == '\n' || ch == EOF)
{
*pos = '\0';
return buf;
}
*pos++ = ch;
ch = GETC(f);
if (--count == 0)
{
count = currentSize;
buf = (char*)realloc(buf, currentSize *= 2);
pos = buf + count;
}
}
}
};