admin
2023-03-07 8b06b1cbf112d55307ea8a6efe711db4e7506d89
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * This file is part of xlslib -- A multiplatform, C/C++ library
 * for dynamic generation of Excel(TM) files.
 *
 * Copyright 2004 Yeico S. A. de C. V. All Rights Reserved.
 * Copyright 2008-2011 David Hoerl All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 * 
 *    1. Redistributions of source code must retain the above copyright notice, this list of
 *       conditions and the following disclaimer.
 * 
 *    2. Redistributions in binary form must reproduce the above copyright notice, this list
 *       of conditions and the following disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
//#define __DEBUG__
 
#ifndef SYSTYPE_H
#define SYSTYPE_H
 
#if defined(_MSC_VER) && defined(WIN32) && 0
#pragma warning(disable: 4786) // Long debug information related to STL
#pragma warning(disable: 4290) // C++ Exception Specification ignored
#endif
 
//#   define PHPEXT_TSRMLS_C  tsrm_ls
//#   define PHPEXT_TSRMLS_D  void ***tsrm_ls
 
// Global includes
#include <stdio.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#if defined(__cplusplus)                    // ALL C++ users
#include <cstring>
#include <string>
#endif
#ifdef HAVE_STRING_H
#include <string.h>    
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>    
#endif
#ifdef HAVE_MEMORY_H
#include <memory.h>    
#endif
#if defined(__cplusplus)                    // ALL C++ users
#include <iostream>
#include <fstream>  // [i_a] MSVC needs this for cerr (XTRACE() et al)
#include <list>
#include <set>
#include <algorithm>
#endif
//#include <assert.h>
 
//#define INLINE inline
 
//#define NULL ((void*)(0))
 
#define NO_ERRORS         0
#define FILE_ERROR        (-1)
#define GENERAL_ERROR     (-100)
 
#define PTYPE_DIRECTORY   0x01
#define PTYPE_FILE        0x02
#define PTYPE_ROOT        0x05
 
#define PCOLOR_BLACK      0x01
#define PCOLOR_RED          0x00
 
#define PLINK_EMPTY       (-1)
#define PBLOCK_END        (-2)
 
 
#if USE_ALLOCATOR==ALLOCATOR_STL
#define XLSLIB_DFLT_ALLOCATOR
 
#elif USE_ALLOCATOR==ALLOCATOR_BTI
#include "bti_thread_alloc.h"
#define XLSLIB_DFLT_ALLOCATOR ,bti::thr_alloc
 
#else
#   error ERROR: Invalid allocator option
#endif
 
 
 
#include "../common/xlstypes.h"  
/* [i_a]   better to get the definition from a single place */
 
 
 
 
 
#if defined(__cplusplus)                    // ALL C++ users
 
typedef std::list<std::string* XLSLIB_DFLT_ALLOCATOR> StringList_t;
typedef StringList_t::const_iterator StringListItor_t;
 
#endif
 
// Macros
# define MASK_BYTE0 0x00000000000000ffU
# define MASK_BYTE1 0x000000000000ff00U
# define MASK_BYTE2 0x0000000000ff0000U
# define MASK_BYTE3 0x00000000ff000000U
 
#if defined(_MSC_VER) && defined(WIN32) && 0 // [i_a]
 
# define MASK_BYTE4 0x000000ff00000000
# define MASK_BYTE5 0x0000ff0000000000
# define MASK_BYTE6 0x00ff000000000000
# define MASK_BYTE7 0xff00000000000000
 
#else
 
# define MASK_BYTE4 ((unsigned64_t)0x000000ff00000000LL)
# define MASK_BYTE5 ((unsigned64_t)0x0000ff0000000000LL)
# define MASK_BYTE6 ((unsigned64_t)0x00ff000000000000LL)
# define MASK_BYTE7 ((unsigned64_t)0xff00000000000000ULL)
 
#endif
 
#define BYTE_0(num) ((unsigned8_t) (num & MASK_BYTE0))
#define BYTE_1(num) ((unsigned8_t)((num & MASK_BYTE1)>>0x08))
#define BYTE_2(num) ((unsigned8_t)((num & MASK_BYTE2)>>0x10))
#define BYTE_3(num) ((unsigned8_t)((num & MASK_BYTE3)>>0x18))
 
#define BYTE_4(num) ((unsigned8_t)((num & MASK_BYTE4)>>0x20))
#define BYTE_5(num) ((unsigned8_t)((num & MASK_BYTE5)>>0x28))
#define BYTE_6(num) ((unsigned8_t)((num & MASK_BYTE6)>>0x30))
#define BYTE_7(num) ((unsigned8_t)((num & MASK_BYTE7)>>0x38))
 
 
 
#define PROPERTY_DFLT_NOTUSED        0x00
#define PROPERTY_MAX_NAME_LENGTH    32
 
#define PROPERTY_TYPE_DIR            0x01
#define PROPERTY_TYPE_FILE            0x02
#define PROPERTY_TYPE_ROOT            0x05
 
#define PROPERTY_COLOR_NODE_RED        0x00
#define PROPERTY_COLOR_NODE_BLACK    0x01
#define PROPERTY_LINK_EMPTY            (-1)
 
#define PPTPOS_NAME                    0x00
#define PPTPOS_NAMELENGTH            0x40
#define PPTPOS_TYPE                    0x42
#define PPTPOS_NODECOLOR            0x43
#define PPTPOS_PREVIOUS                0x44
#define PPTPOS_NEXT                    0x48
#define PPTPOS_CHILD                0x4C
#define PPTPOS_UNUSED_EMPTY0        0x50
 
 
#define PPTPOS_SECS1                0x64
#define PPTPOS_SECS2                0x68
#define PPTPOS_DAYS1                0x6c
#define PPTPOS_DAYS2                0x70
 
#define PPTPOS_STARTBLOCK            0x74
#define PPTPOS_SIZE                    0x78
 
 
#define PPT_DFLT_SECS1                0
#define PPT_DFLT_SECS2                0
#define PPT_DFLT_DAYS1                0
#define PPT_DFLT_DAYS2                0
 
 
// More macros
 
/*  
****************************************
****************************************
*/
#define Delete_Pointer(pt) {                    \
  if(pt != NULL)                                \
    {                                           \
      delete pt;                                \
      pt = NULL;                                \
    }                                           \
}
 
 
/*  
****************************************
****************************************
*/
#ifdef __DEBUG__
 
#define XTRACE(str) {                           \
  std::cerr<<"DEBUG: "<<str<<std::endl;         \
}
#define XTRACE2(str, arg) {                     \
  std::cerr<<"DEBUG: "<<str<<arg<<std::endl;    \
}
 
#else
 
#define XTRACE(str)
#define XTRACE2(str, arg)
 
#endif
 
 
#ifdef __PHP_DEBUG__
 
#define PHPTRACE(str) {                         \
    std::cerr<<"PHPDEBUG: "<<str<<std::endl;    \
}
 
#else
 
#define PHPTRACE(str)
 
#endif
 
 
#if defined(__cplusplus)
extern "C"
{
#endif
 
#if defined(HAVE___FUNCTION__)
#define XL_FUNCNAME()                   __FUNCTION__
#elif defined(HAVE___FUNC__)
#define XL_FUNCNAME()                   __func__
#else
#define XL_FUNCNAME()                   "???"
#endif
 
/**
Custom ASSERT macro; since we create a library, we'ld better allow the user of that
lib to set up how [s]he wants to have her/his assertion failures reported.
 
stdlib's version, which dumps to stderr and calls abort() isn't exactly what you'd 
wish for in a UI or other non-UNIX/WIN-consolish environment!
 
@note
Users of xlslib may want to call xlslib_register_assert_reporter() at program initialization.
 
@note
The macro is constructed in such a way that the expression is only evaluated once (no
side effects from double invocations) and consumes the semicolon which follows it, so
that code like this will compile as expected in all conditions:
 
  if (cond)
    XL_ASSERT(some_expression);
  else
    do_something();
 
*/
#define XL_ASSERTS(str)                                                                    \
    do                                                                                    \
    {                                                                                    \
        xlslib_report_failed_assertion(#str, __FILE__, __LINE__, XL_FUNCNAME());        \
    }  while (0)
 
#define XL_ASSERT(expr)                                                                    \
    do                                                                                    \
    {                                                                                    \
        if (!(expr))                                                                    \
        {                                                                                \
            xlslib_report_failed_assertion(#expr, __FILE__, __LINE__, XL_FUNCNAME());    \
        }                                                                                \
    }  while (0)
 
#define XL_VERIFY(expr)                                                                    \
    do                                                                                    \
    {                                                                                    \
        if (!(expr))                                                                    \
        {                                                                                \
            xlslib_report_failed_assertion(#expr, __FILE__, __LINE__, XL_FUNCNAME());    \
        }                                                                                \
    }  while (0)
 
#define XL_WITH_ASSERTIONS            1
 
/*
override for 'release' type builds: the compiler optimizer will make sure this
empty statement will be discarded, while we still ensure the trailing semicolon 
will be properly 'munched'.
*/
#if defined(XLSLIB_DONT_ASSERT)
 
#undef XL_ASSERT
#define XL_ASSERT(expr)                                                                \
    (void)0
 
#undef XL_VERIFY
#define XL_VERIFY(expr)                                                                \
    (void)(expr)
 
#undef XL_WITH_ASSERTIONS
 
#endif
 
typedef void xlslib_userdef_assertion_reporter(const char *expr, const char *fname, int lineno, const char *funcname);
 
void xlslib_report_failed_assertion(const char *expr, const char *fname, int lineno, const char *funcname);
 
/**
override the default (C++ exception throwing) assertion failure reporting function within xlslib.
*/
void xlslib_register_assert_reporter(xlslib_userdef_assertion_reporter *user_func);
 
#if defined(__cplusplus)
};
#endif
 
#endif