libxlsxwriter/include/xlsxwriter/common.h in fast_excel-0.4.1 vs libxlsxwriter/include/xlsxwriter/common.h in fast_excel-0.5.0
- old
+ new
@@ -1,17 +1,17 @@
/*
* libxlsxwriter
*
- * Copyright 2014-2019, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
+ * Copyright 2014-2022, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
*/
/**
* @file common.h
*
* @brief Common functions and defines for the libxlsxwriter library.
*
- * <!-- Copyright 2014-2019, John McNamara, jmcnamara@cpan.org -->
+ * <!-- Copyright 2014-2022, John McNamara, jmcnamara@cpan.org -->
*
*/
#ifndef __LXW_COMMON_H__
#define __LXW_COMMON_H__
@@ -23,10 +23,18 @@
#define STATIC static
#else
#define STATIC
#endif
+#if __GNUC__ >= 5
+#define DEPRECATED(func, msg) func __attribute__ ((deprecated(msg)))
+#elif defined(_MSC_VER)
+#define DEPRECATED(func, msg) __declspec(deprecated, msg) func
+#else
+#define DEPRECATED(func, msg) func
+#endif
+
/** Integer data type to represent a row value. Equivalent to `uint32_t`.
*
* The maximum row in Excel is 1,048,576.
*/
typedef uint32_t lxw_row_t;
@@ -40,11 +48,14 @@
/** Boolean values used in libxlsxwriter. */
enum lxw_boolean {
/** False value. */
LXW_FALSE,
/** True value. */
- LXW_TRUE
+ LXW_TRUE,
+ /** False value. Used to turn off a property that is default on, in order
+ * to distinguish it from an uninitialized value. */
+ LXW_EXPLICIT_FALSE
};
/**
* @brief Error codes from libxlsxwriter functions.
*
@@ -84,10 +95,13 @@
LXW_ERROR_ZIP_FILE_ADD,
/** Unknown zip error when closing xlsx file. */
LXW_ERROR_ZIP_CLOSE,
+ /** Feature is not currently supported in this configuration. */
+ LXW_ERROR_FEATURE_NOT_SUPPORTED,
+
/** NULL function parameter ignored. */
LXW_ERROR_NULL_PARAMETER_IGNORED,
/** Function parameter validation error. */
LXW_ERROR_PARAMETER_VALIDATION,
@@ -102,13 +116,10 @@
LXW_ERROR_SHEETNAME_START_END_APOSTROPHE,
/** Worksheet name is already in use. */
LXW_ERROR_SHEETNAME_ALREADY_USED,
- /** Worksheet name 'History' is reserved by Excel. */
- LXW_ERROR_SHEETNAME_RESERVED,
-
/** Parameter exceeds Excel's limit of 32 characters. */
LXW_ERROR_32_STRING_LENGTH_EXCEEDED,
/** Parameter exceeds Excel's limit of 128 characters. */
LXW_ERROR_128_STRING_LENGTH_EXCEEDED,
@@ -123,10 +134,13 @@
LXW_ERROR_SHARED_STRING_INDEX_NOT_FOUND,
/** Worksheet row or column index out of range. */
LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE,
+ /** Maximum hyperlink length (2079) exceeded. */
+ LXW_ERROR_WORKSHEET_MAX_URL_LENGTH_EXCEEDED,
+
/** Maximum number of worksheet URLs (65530) exceeded. */
LXW_ERROR_WORKSHEET_MAX_NUMBER_URLS_EXCEEDED,
/** Couldn't read image dimensions or DPI. */
LXW_ERROR_IMAGE_DIMENSIONS,
@@ -162,10 +176,13 @@
LXW_CUSTOM_INTEGER,
LXW_CUSTOM_BOOLEAN,
LXW_CUSTOM_DATETIME
};
+/* Size of MD5 byte arrays. */
+#define LXW_MD5_SIZE 16
+
/* Excel sheetname max of 31 chars. */
#define LXW_SHEETNAME_MAX 31
/* Max with all worksheet chars 4xUTF-8 bytes + start and end quotes + \0. */
#define LXW_MAX_SHEETNAME_LENGTH ((LXW_SHEETNAME_MAX * 4) + 2 + 1)
@@ -186,10 +203,13 @@
#define LXW_MAX_FORMULA_RANGE_LENGTH (LXW_MAX_SHEETNAME_LENGTH + LXW_MAX_CELL_RANGE_LENGTH)
/* Datetime string length. */
#define LXW_DATETIME_LENGTH sizeof("2016-12-12T23:00:00Z")
+/* GUID string length. */
+#define LXW_GUID_LENGTH sizeof("{12345678-1234-1234-1234-1234567890AB}\0")
+
#define LXW_EPOCH_1900 0
#define LXW_EPOCH_1904 1
#define LXW_UINT32_T_LENGTH sizeof("4294967296")
#define LXW_FILENAME_LENGTH 128
@@ -204,96 +224,137 @@
#define LXW_SCHEMA_OFFICEDOC LXW_SCHEMA_ROOT "/officeDocument/2006"
#define LXW_SCHEMA_PACKAGE LXW_SCHEMA_ROOT "/package/2006/relationships"
#define LXW_SCHEMA_DOCUMENT LXW_SCHEMA_ROOT "/officeDocument/2006/relationships"
#define LXW_SCHEMA_CONTENT LXW_SCHEMA_ROOT "/package/2006/content-types"
+/* Use REprintf() for error handling when compiled as an R library. */
+#ifdef USE_R_LANG
+#include <R.h>
+#define LXW_PRINTF REprintf
+#define LXW_STDERR
+#else
+#define LXW_PRINTF fprintf
+#define LXW_STDERR stderr,
+#endif
+
#define LXW_ERROR(message) \
- fprintf(stderr, "[ERROR][%s:%d]: " message "\n", __FILE__, __LINE__)
+ LXW_PRINTF(LXW_STDERR "[ERROR][%s:%d]: " message "\n", __FILE__, __LINE__)
#define LXW_MEM_ERROR() \
LXW_ERROR("Memory allocation failed.")
#define GOTO_LABEL_ON_MEM_ERROR(pointer, label) \
- if (!pointer) { \
- LXW_MEM_ERROR(); \
- goto label; \
- }
+ do { \
+ if (!pointer) { \
+ LXW_MEM_ERROR(); \
+ goto label; \
+ } \
+ } while (0)
#define RETURN_ON_MEM_ERROR(pointer, error) \
- if (!pointer) { \
- LXW_MEM_ERROR(); \
- return error; \
- }
+ do { \
+ if (!pointer) { \
+ LXW_MEM_ERROR(); \
+ return error; \
+ } \
+ } while (0)
#define RETURN_VOID_ON_MEM_ERROR(pointer) \
- if (!pointer) { \
- LXW_MEM_ERROR(); \
- return; \
- }
+ do { \
+ if (!pointer) { \
+ LXW_MEM_ERROR(); \
+ return; \
+ } \
+ } while (0)
#define RETURN_ON_ERROR(error) \
- if (error) \
- return error;
+ do { \
+ if (error) \
+ return error; \
+ } while (0)
+#define RETURN_AND_ZIPCLOSE_ON_ERROR(error) \
+ do { \
+ if (error) { \
+ zipClose(self->zipfile, NULL); \
+ return error; \
+ } \
+ } while (0)
+
#define LXW_WARN(message) \
- fprintf(stderr, "[WARNING]: " message "\n")
+ LXW_PRINTF(LXW_STDERR "[WARNING]: " message "\n")
/* We can't use variadic macros here since we support ANSI C. */
#define LXW_WARN_FORMAT(message) \
- fprintf(stderr, "[WARNING]: " message "\n")
+ LXW_PRINTF(LXW_STDERR "[WARNING]: " message "\n")
#define LXW_WARN_FORMAT1(message, var) \
- fprintf(stderr, "[WARNING]: " message "\n", var)
+ LXW_PRINTF(LXW_STDERR "[WARNING]: " message "\n", var)
#define LXW_WARN_FORMAT2(message, var1, var2) \
- fprintf(stderr, "[WARNING]: " message "\n", var1, var2)
+ LXW_PRINTF(LXW_STDERR "[WARNING]: " message "\n", var1, var2)
+#define LXW_WARN_FORMAT3(message, var1, var2, var3) \
+ LXW_PRINTF(LXW_STDERR "[WARNING]: " message "\n", var1, var2, var3)
+
/* Chart axis type checks. */
#define LXW_WARN_CAT_AXIS_ONLY(function) \
- if (!axis->is_category) { \
- fprintf(stderr, "[WARNING]: " \
- function "() is only valid for category axes\n"); \
- return; \
- }
+ do { \
+ if (!axis->is_category) { \
+ LXW_PRINTF(LXW_STDERR "[WARNING]: " \
+ function "() is only valid for category axes\n"); \
+ return; \
+ } \
+ } while (0)
#define LXW_WARN_VALUE_AXIS_ONLY(function) \
- if (!axis->is_value) { \
- fprintf(stderr, "[WARNING]: " \
+ do { \
+ if (!axis->is_value) { \
+ LXW_PRINTF(LXW_STDERR "[WARNING]: " \
function "() is only valid for value axes\n"); \
- return; \
- }
+ return; \
+ } \
+ } while (0)
#define LXW_WARN_DATE_AXIS_ONLY(function) \
- if (!axis->is_date) { \
- fprintf(stderr, "[WARNING]: " \
- function "() is only valid for date axes\n"); \
- return; \
- }
+ do { \
+ if (!axis->is_date) { \
+ LXW_PRINTF(LXW_STDERR "[WARNING]: " \
+ function "() is only valid for date axes\n"); \
+ return; \
+ } \
+ } while (0)
#define LXW_WARN_CAT_AND_DATE_AXIS_ONLY(function) \
- if (!axis->is_category && !axis->is_date) { \
- fprintf(stderr, "[WARNING]: " \
+ do { \
+ if (!axis->is_category && !axis->is_date) { \
+ LXW_PRINTF(LXW_STDERR "[WARNING]: " \
function "() is only valid for category and date axes\n"); \
- return; \
- }
+ return; \
+ } \
+ } while (0)
#define LXW_WARN_VALUE_AND_DATE_AXIS_ONLY(function) \
- if (!axis->is_value && !axis->is_date) { \
- fprintf(stderr, "[WARNING]: " \
+ do { \
+ if (!axis->is_value && !axis->is_date) { \
+ LXW_PRINTF(LXW_STDERR "[WARNING]: " \
function "() is only valid for value and date axes\n"); \
- return; \
- }
+ return; \
+ } \
+ } while (0)
#ifndef LXW_BIG_ENDIAN
+#define LXW_UINT16_HOST(n) (n)
+#define LXW_UINT32_HOST(n) (n)
+#define LXW_UINT16_NETWORK(n) ((((n) & 0x00FF) << 8) | (((n) & 0xFF00) >> 8))
#define LXW_UINT32_NETWORK(n) ((((n) & 0xFF) << 24) | \
(((n) & 0xFF00) << 8) | \
(((n) & 0xFF0000) >> 8) | \
(((n) & 0xFF000000) >> 24))
-#define LXW_UINT16_NETWORK(n) ((((n) & 0x00FF) << 8) | (((n) & 0xFF00) >> 8))
-#define LXW_UINT32_HOST(n) (n)
#else
-#define LXW_UINT32_NETWORK(n) (n)
#define LXW_UINT16_NETWORK(n) (n)
+#define LXW_UINT32_NETWORK(n) (n)
+#define LXW_UINT16_HOST(n) ((((n) & 0x00FF) << 8) | (((n) & 0xFF00) >> 8))
#define LXW_UINT32_HOST(n) ((((n) & 0xFF) << 24) | \
(((n) & 0xFF00) << 8) | \
(((n) & 0xFF0000) >> 8) | \
(((n) & 0xFF000000) >> 24))
#endif