mirror of
https://github.com/jmcnamara/libxlsxwriter
synced 2025-03-28 21:13:14 +00:00
Initial structure for custom properties.
This commit is contained in:
parent
af0063a75f
commit
d3536296b0
2
.indent.pro
vendored
2
.indent.pro
vendored
@ -52,11 +52,13 @@
|
||||
-T lxw_chart_font
|
||||
-T lxw_chart_series
|
||||
-T lxw_chart_title
|
||||
-T lxw_chart_types
|
||||
-T lxw_col_options
|
||||
-T lxw_col_t
|
||||
-T lxw_color_t
|
||||
-T lxw_content_types
|
||||
-T lxw_core
|
||||
-T lxw_custom
|
||||
-T lxw_datetime
|
||||
-T lxw_defined_name
|
||||
-T lxw_doc_properties
|
||||
|
@ -117,13 +117,13 @@ enum lxw_error {
|
||||
#define LXW_FILENAME_LENGTH 128
|
||||
#define LXW_IGNORE 1
|
||||
|
||||
#define LXW_SCHEMA_MS "http://schemas.microsoft.com/office/2006/relationships"
|
||||
#define LXW_SCHEMA_ROOT "http://schemas.openxmlformats.org"
|
||||
#define LXW_SCHEMA_DRAWING LXW_SCHEMA_ROOT "/drawingml/2006"
|
||||
#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"
|
||||
#define LXW_SCHEMA_MS "http://schemas.microsoft.com/office/2006/relationships"
|
||||
|
||||
#define LXW_ERROR(message) \
|
||||
fprintf(stderr, "[ERROR][%s:%d]: " message "\n", __FILE__, __LINE__)
|
||||
|
49
include/xlsxwriter/custom.h
Normal file
49
include/xlsxwriter/custom.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* libxlsxwriter
|
||||
*
|
||||
* Copyright 2014-2016, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
|
||||
*
|
||||
* custom - A libxlsxwriter library for creating Excel XLSX custom files.
|
||||
*
|
||||
*/
|
||||
#ifndef __LXW_CUSTOM_H__
|
||||
#define __LXW_CUSTOM_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/*
|
||||
* Struct to represent a custom object.
|
||||
*/
|
||||
typedef struct lxw_custom {
|
||||
|
||||
FILE *file;
|
||||
|
||||
} lxw_custom;
|
||||
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
lxw_custom *lxw_custom_new();
|
||||
void lxw_custom_free(lxw_custom *custom);
|
||||
void lxw_custom_assemble_xml_file(lxw_custom *self);
|
||||
|
||||
/* Declarations required for unit testing. */
|
||||
#ifdef TESTING
|
||||
|
||||
STATIC void _custom_xml_declaration(lxw_custom *self);
|
||||
|
||||
#endif /* TESTING */
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* __LXW_CUSTOM_H__ */
|
91
src/custom.c
Normal file
91
src/custom.c
Normal file
@ -0,0 +1,91 @@
|
||||
/*****************************************************************************
|
||||
* custom - A library for creating Excel XLSX custom files.
|
||||
*
|
||||
* Used in conjunction with the libxlsxwriter library.
|
||||
*
|
||||
* Copyright 2014-2016, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter/xmlwriter.h"
|
||||
#include "xlsxwriter/custom.h"
|
||||
#include "xlsxwriter/utility.h"
|
||||
|
||||
/*
|
||||
* Forward declarations.
|
||||
*/
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Private functions.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Create a new custom object.
|
||||
*/
|
||||
lxw_custom *
|
||||
lxw_custom_new()
|
||||
{
|
||||
lxw_custom *custom = calloc(1, sizeof(lxw_custom));
|
||||
GOTO_LABEL_ON_MEM_ERROR(custom, mem_error);
|
||||
|
||||
return custom;
|
||||
|
||||
mem_error:
|
||||
lxw_custom_free(custom);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free a custom object.
|
||||
*/
|
||||
void
|
||||
lxw_custom_free(lxw_custom *custom)
|
||||
{
|
||||
if (!custom)
|
||||
return;
|
||||
|
||||
free(custom);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* XML functions.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Write the XML declaration.
|
||||
*/
|
||||
STATIC void
|
||||
_custom_xml_declaration(lxw_custom *self)
|
||||
{
|
||||
lxw_xml_declaration(self->file);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* XML file assembly functions.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Assemble and write the XML file.
|
||||
*/
|
||||
void
|
||||
lxw_custom_assemble_xml_file(lxw_custom *self)
|
||||
{
|
||||
/* Write the XML declaration. */
|
||||
_custom_xml_declaration(self);
|
||||
|
||||
lxw_xml_end_tag(self->file, "custom");
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Public functions.
|
||||
*
|
||||
****************************************************************************/
|
@ -36,6 +36,7 @@ SRCS += $(wildcard format/test*.c)
|
||||
SRCS += $(wildcard styles/test*.c)
|
||||
SRCS += $(wildcard drawing/test*.c)
|
||||
SRCS += $(wildcard chart/test*.c)
|
||||
SRCS += $(wildcard custom/test*.c)
|
||||
# End of SRCS
|
||||
|
||||
OBJS = $(patsubst %.c,%.o,$(SRCS))
|
||||
@ -59,6 +60,7 @@ all :
|
||||
$(Q)$(MAKE) -C styles
|
||||
$(Q)$(MAKE) -C drawing
|
||||
$(Q)$(MAKE) -C chart
|
||||
$(Q)$(MAKE) -C custom
|
||||
# END make all
|
||||
|
||||
clean :
|
||||
@ -75,6 +77,7 @@ clean :
|
||||
$(Q)$(MAKE) clean -C styles
|
||||
$(Q)$(MAKE) clean -C drawing
|
||||
$(Q)$(MAKE) clean -C chart
|
||||
$(Q)$(MAKE) clean -C custom
|
||||
# END make clean
|
||||
|
||||
|
||||
|
8
test/unit/custom/Makefile
Normal file
8
test/unit/custom/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Makefile for libxlsxwriter library.
|
||||
#
|
||||
# Copyright 2014-2015, John McNamara, jmcnamara@cpan.org
|
||||
#
|
||||
|
||||
include ../Makefile.unit
|
15
test/unit/custom/main.c
Normal file
15
test/unit/custom/main.c
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Test runner for xmlwriter using ctest.
|
||||
*
|
||||
* Copyright 2014-2016 John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
#define CTEST_MAIN
|
||||
|
||||
#include "../ctest.h"
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
return ctest_main(argc, argv);
|
||||
}
|
||||
|
28
test/unit/custom/test_custom_xml_declaration.c
Normal file
28
test/unit/custom/test_custom_xml_declaration.c
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Tests for the libxlsxwriter library.
|
||||
*
|
||||
* Copyright 2014-2016, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "xlsxwriter/custom.h"
|
||||
|
||||
// Test _xml_declaration().
|
||||
CTEST(custom, xml_declaration) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
|
||||
FILE* testfile = tmpfile();
|
||||
|
||||
lxw_custom *custom = lxw_custom_new();
|
||||
custom->file = testfile;
|
||||
|
||||
_custom_xml_declaration(custom);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_custom_free(custom);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user