kmadej_fast_excel_fork 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.travis.yml +28 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +70 -0
- data/Makefile +14 -0
- data/README.md +95 -0
- data/Rakefile +24 -0
- data/appveyor.yml +25 -0
- data/benchmarks/1k_rows.rb +59 -0
- data/benchmarks/20k_rows.rb +26 -0
- data/benchmarks/init.rb +59 -0
- data/benchmarks/memory.rb +49 -0
- data/examples/example.rb +42 -0
- data/examples/example_align.rb +23 -0
- data/examples/example_chart.rb +21 -0
- data/examples/example_colors.rb +37 -0
- data/examples/example_formula.rb +18 -0
- data/examples/example_image.rb +13 -0
- data/examples/example_styles.rb +27 -0
- data/examples/logo.png +0 -0
- data/extconf.rb +0 -0
- data/fast_excel.gemspec +20 -0
- data/lib/fast_excel.rb +600 -0
- data/lib/fast_excel/binding.rb +2819 -0
- data/lib/fast_excel/binding/chart.rb +2666 -0
- data/lib/fast_excel/binding/format.rb +1177 -0
- data/lib/fast_excel/binding/workbook.rb +338 -0
- data/lib/fast_excel/binding/worksheet.rb +1555 -0
- data/libxlsxwriter/.gitignore +49 -0
- data/libxlsxwriter/.indent.pro +125 -0
- data/libxlsxwriter/.travis.yml +25 -0
- data/libxlsxwriter/CONTRIBUTING.md +226 -0
- data/libxlsxwriter/Changes.txt +557 -0
- data/libxlsxwriter/LICENSE.txt +89 -0
- data/libxlsxwriter/Makefile +156 -0
- data/libxlsxwriter/Readme.md +78 -0
- data/libxlsxwriter/cocoapods/libxlsxwriter-umbrella.h +30 -0
- data/libxlsxwriter/cocoapods/libxlsxwriter.modulemap +7 -0
- data/libxlsxwriter/include/xlsxwriter.h +23 -0
- data/libxlsxwriter/include/xlsxwriter/app.h +79 -0
- data/libxlsxwriter/include/xlsxwriter/chart.h +3476 -0
- data/libxlsxwriter/include/xlsxwriter/common.h +372 -0
- data/libxlsxwriter/include/xlsxwriter/content_types.h +74 -0
- data/libxlsxwriter/include/xlsxwriter/core.h +51 -0
- data/libxlsxwriter/include/xlsxwriter/custom.h +52 -0
- data/libxlsxwriter/include/xlsxwriter/drawing.h +111 -0
- data/libxlsxwriter/include/xlsxwriter/format.h +1214 -0
- data/libxlsxwriter/include/xlsxwriter/hash_table.h +76 -0
- data/libxlsxwriter/include/xlsxwriter/packager.h +80 -0
- data/libxlsxwriter/include/xlsxwriter/relationships.h +77 -0
- data/libxlsxwriter/include/xlsxwriter/shared_strings.h +83 -0
- data/libxlsxwriter/include/xlsxwriter/styles.h +77 -0
- data/libxlsxwriter/include/xlsxwriter/theme.h +47 -0
- data/libxlsxwriter/include/xlsxwriter/third_party/ioapi.h +214 -0
- data/libxlsxwriter/include/xlsxwriter/third_party/queue.h +694 -0
- data/libxlsxwriter/include/xlsxwriter/third_party/tmpfileplus.h +53 -0
- data/libxlsxwriter/include/xlsxwriter/third_party/tree.h +801 -0
- data/libxlsxwriter/include/xlsxwriter/third_party/zip.h +375 -0
- data/libxlsxwriter/include/xlsxwriter/utility.h +166 -0
- data/libxlsxwriter/include/xlsxwriter/workbook.h +757 -0
- data/libxlsxwriter/include/xlsxwriter/worksheet.h +2641 -0
- data/libxlsxwriter/include/xlsxwriter/xmlwriter.h +178 -0
- data/libxlsxwriter/lib/.gitignore +0 -0
- data/libxlsxwriter/libxlsxwriter.podspec +47 -0
- data/libxlsxwriter/src/Makefile +130 -0
- data/libxlsxwriter/src/app.c +443 -0
- data/libxlsxwriter/src/chart.c +6346 -0
- data/libxlsxwriter/src/content_types.c +345 -0
- data/libxlsxwriter/src/core.c +293 -0
- data/libxlsxwriter/src/custom.c +224 -0
- data/libxlsxwriter/src/drawing.c +746 -0
- data/libxlsxwriter/src/format.c +729 -0
- data/libxlsxwriter/src/hash_table.c +223 -0
- data/libxlsxwriter/src/packager.c +948 -0
- data/libxlsxwriter/src/relationships.c +245 -0
- data/libxlsxwriter/src/shared_strings.c +266 -0
- data/libxlsxwriter/src/styles.c +1088 -0
- data/libxlsxwriter/src/theme.c +348 -0
- data/libxlsxwriter/src/utility.c +515 -0
- data/libxlsxwriter/src/workbook.c +1930 -0
- data/libxlsxwriter/src/worksheet.c +5022 -0
- data/libxlsxwriter/src/xmlwriter.c +355 -0
- data/libxlsxwriter/third_party/minizip/Makefile +44 -0
- data/libxlsxwriter/third_party/minizip/Makefile.am +45 -0
- data/libxlsxwriter/third_party/minizip/Makefile.orig +25 -0
- data/libxlsxwriter/third_party/minizip/MiniZip64_Changes.txt +6 -0
- data/libxlsxwriter/third_party/minizip/MiniZip64_info.txt +74 -0
- data/libxlsxwriter/third_party/minizip/README.txt +5 -0
- data/libxlsxwriter/third_party/minizip/configure.ac +32 -0
- data/libxlsxwriter/third_party/minizip/crypt.h +131 -0
- data/libxlsxwriter/third_party/minizip/ioapi.c +247 -0
- data/libxlsxwriter/third_party/minizip/ioapi.h +208 -0
- data/libxlsxwriter/third_party/minizip/iowin32.c +456 -0
- data/libxlsxwriter/third_party/minizip/iowin32.h +28 -0
- data/libxlsxwriter/third_party/minizip/make_vms.com +25 -0
- data/libxlsxwriter/third_party/minizip/miniunz.c +660 -0
- data/libxlsxwriter/third_party/minizip/miniunzip.1 +63 -0
- data/libxlsxwriter/third_party/minizip/minizip.1 +46 -0
- data/libxlsxwriter/third_party/minizip/minizip.c +520 -0
- data/libxlsxwriter/third_party/minizip/minizip.pc.in +12 -0
- data/libxlsxwriter/third_party/minizip/mztools.c +291 -0
- data/libxlsxwriter/third_party/minizip/mztools.h +37 -0
- data/libxlsxwriter/third_party/minizip/unzip.c +2125 -0
- data/libxlsxwriter/third_party/minizip/unzip.h +437 -0
- data/libxlsxwriter/third_party/minizip/zip.c +2007 -0
- data/libxlsxwriter/third_party/minizip/zip.h +367 -0
- data/libxlsxwriter/third_party/tmpfileplus/Makefile +42 -0
- data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +342 -0
- data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.h +53 -0
- data/libxlsxwriter/version.txt +1 -0
- data/test/date_test.rb +22 -0
- data/test/default_format_test.rb +19 -0
- data/test/format_test.rb +171 -0
- data/test/test_helper.rb +52 -0
- data/test/tmpfile_test.rb +23 -0
- data/test/worksheet_test.rb +86 -0
- metadata +182 -0
@@ -0,0 +1,345 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
* content_types - A library for creating Excel XLSX content_types files.
|
3
|
+
*
|
4
|
+
* Used in conjunction with the libxlsxwriter library.
|
5
|
+
*
|
6
|
+
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include "xlsxwriter/xmlwriter.h"
|
11
|
+
#include "xlsxwriter/content_types.h"
|
12
|
+
#include "xlsxwriter/utility.h"
|
13
|
+
|
14
|
+
/*
|
15
|
+
* Forward declarations.
|
16
|
+
*/
|
17
|
+
|
18
|
+
/*****************************************************************************
|
19
|
+
*
|
20
|
+
* Private functions.
|
21
|
+
*
|
22
|
+
****************************************************************************/
|
23
|
+
|
24
|
+
/*
|
25
|
+
* Create a new content_types object.
|
26
|
+
*/
|
27
|
+
lxw_content_types *
|
28
|
+
lxw_content_types_new()
|
29
|
+
{
|
30
|
+
lxw_content_types *content_types = calloc(1, sizeof(lxw_content_types));
|
31
|
+
GOTO_LABEL_ON_MEM_ERROR(content_types, mem_error);
|
32
|
+
|
33
|
+
content_types->default_types = calloc(1, sizeof(struct lxw_tuples));
|
34
|
+
GOTO_LABEL_ON_MEM_ERROR(content_types->default_types, mem_error);
|
35
|
+
STAILQ_INIT(content_types->default_types);
|
36
|
+
|
37
|
+
content_types->overrides = calloc(1, sizeof(struct lxw_tuples));
|
38
|
+
GOTO_LABEL_ON_MEM_ERROR(content_types->overrides, mem_error);
|
39
|
+
STAILQ_INIT(content_types->overrides);
|
40
|
+
|
41
|
+
lxw_ct_add_default(content_types, "rels",
|
42
|
+
LXW_APP_PACKAGE "relationships+xml");
|
43
|
+
lxw_ct_add_default(content_types, "xml", "application/xml");
|
44
|
+
|
45
|
+
lxw_ct_add_override(content_types, "/docProps/app.xml",
|
46
|
+
LXW_APP_DOCUMENT "extended-properties+xml");
|
47
|
+
lxw_ct_add_override(content_types, "/docProps/core.xml",
|
48
|
+
LXW_APP_PACKAGE "core-properties+xml");
|
49
|
+
lxw_ct_add_override(content_types, "/xl/styles.xml",
|
50
|
+
LXW_APP_DOCUMENT "spreadsheetml.styles+xml");
|
51
|
+
lxw_ct_add_override(content_types, "/xl/theme/theme1.xml",
|
52
|
+
LXW_APP_DOCUMENT "theme+xml");
|
53
|
+
lxw_ct_add_override(content_types, "/xl/workbook.xml",
|
54
|
+
LXW_APP_DOCUMENT "spreadsheetml.sheet.main+xml");
|
55
|
+
|
56
|
+
return content_types;
|
57
|
+
|
58
|
+
mem_error:
|
59
|
+
lxw_content_types_free(content_types);
|
60
|
+
return NULL;
|
61
|
+
}
|
62
|
+
|
63
|
+
/*
|
64
|
+
* Free a content_types object.
|
65
|
+
*/
|
66
|
+
void
|
67
|
+
lxw_content_types_free(lxw_content_types *content_types)
|
68
|
+
{
|
69
|
+
lxw_tuple *default_type;
|
70
|
+
lxw_tuple *override;
|
71
|
+
|
72
|
+
if (!content_types)
|
73
|
+
return;
|
74
|
+
|
75
|
+
if (content_types->default_types) {
|
76
|
+
while (!STAILQ_EMPTY(content_types->default_types)) {
|
77
|
+
default_type = STAILQ_FIRST(content_types->default_types);
|
78
|
+
STAILQ_REMOVE_HEAD(content_types->default_types, list_pointers);
|
79
|
+
free(default_type->key);
|
80
|
+
free(default_type->value);
|
81
|
+
free(default_type);
|
82
|
+
}
|
83
|
+
free(content_types->default_types);
|
84
|
+
}
|
85
|
+
|
86
|
+
if (content_types->overrides) {
|
87
|
+
while (!STAILQ_EMPTY(content_types->overrides)) {
|
88
|
+
override = STAILQ_FIRST(content_types->overrides);
|
89
|
+
STAILQ_REMOVE_HEAD(content_types->overrides, list_pointers);
|
90
|
+
free(override->key);
|
91
|
+
free(override->value);
|
92
|
+
free(override);
|
93
|
+
}
|
94
|
+
free(content_types->overrides);
|
95
|
+
}
|
96
|
+
|
97
|
+
free(content_types);
|
98
|
+
}
|
99
|
+
|
100
|
+
/*****************************************************************************
|
101
|
+
*
|
102
|
+
* XML functions.
|
103
|
+
*
|
104
|
+
****************************************************************************/
|
105
|
+
|
106
|
+
/*
|
107
|
+
* Write the XML declaration.
|
108
|
+
*/
|
109
|
+
STATIC void
|
110
|
+
_content_types_xml_declaration(lxw_content_types *self)
|
111
|
+
{
|
112
|
+
lxw_xml_declaration(self->file);
|
113
|
+
}
|
114
|
+
|
115
|
+
/*
|
116
|
+
* Write the <Types> element.
|
117
|
+
*/
|
118
|
+
STATIC void
|
119
|
+
_write_types(lxw_content_types *self)
|
120
|
+
{
|
121
|
+
struct xml_attribute_list attributes;
|
122
|
+
struct xml_attribute *attribute;
|
123
|
+
|
124
|
+
LXW_INIT_ATTRIBUTES();
|
125
|
+
LXW_PUSH_ATTRIBUTES_STR("xmlns", LXW_SCHEMA_CONTENT);
|
126
|
+
|
127
|
+
lxw_xml_start_tag(self->file, "Types", &attributes);
|
128
|
+
|
129
|
+
LXW_FREE_ATTRIBUTES();
|
130
|
+
}
|
131
|
+
|
132
|
+
/*
|
133
|
+
* Write the <Default> element.
|
134
|
+
*/
|
135
|
+
STATIC void
|
136
|
+
_write_default(lxw_content_types *self, const char *ext, const char *type)
|
137
|
+
{
|
138
|
+
struct xml_attribute_list attributes;
|
139
|
+
struct xml_attribute *attribute;
|
140
|
+
|
141
|
+
LXW_INIT_ATTRIBUTES();
|
142
|
+
LXW_PUSH_ATTRIBUTES_STR("Extension", ext);
|
143
|
+
LXW_PUSH_ATTRIBUTES_STR("ContentType", type);
|
144
|
+
|
145
|
+
lxw_xml_empty_tag(self->file, "Default", &attributes);
|
146
|
+
|
147
|
+
LXW_FREE_ATTRIBUTES();
|
148
|
+
}
|
149
|
+
|
150
|
+
/*
|
151
|
+
* Write the <Override> element.
|
152
|
+
*/
|
153
|
+
STATIC void
|
154
|
+
_write_override(lxw_content_types *self, const char *part_name,
|
155
|
+
const char *type)
|
156
|
+
{
|
157
|
+
struct xml_attribute_list attributes;
|
158
|
+
struct xml_attribute *attribute;
|
159
|
+
|
160
|
+
LXW_INIT_ATTRIBUTES();
|
161
|
+
LXW_PUSH_ATTRIBUTES_STR("PartName", part_name);
|
162
|
+
LXW_PUSH_ATTRIBUTES_STR("ContentType", type);
|
163
|
+
|
164
|
+
lxw_xml_empty_tag(self->file, "Override", &attributes);
|
165
|
+
|
166
|
+
LXW_FREE_ATTRIBUTES();
|
167
|
+
}
|
168
|
+
|
169
|
+
/*****************************************************************************
|
170
|
+
*
|
171
|
+
* XML file assembly functions.
|
172
|
+
*
|
173
|
+
****************************************************************************/
|
174
|
+
|
175
|
+
/*
|
176
|
+
* Write out all of the <Default> types.
|
177
|
+
*/
|
178
|
+
STATIC void
|
179
|
+
_write_defaults(lxw_content_types *self)
|
180
|
+
{
|
181
|
+
lxw_tuple *tuple;
|
182
|
+
|
183
|
+
STAILQ_FOREACH(tuple, self->default_types, list_pointers) {
|
184
|
+
_write_default(self, tuple->key, tuple->value);
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
/*
|
189
|
+
* Write out all of the <Override> types.
|
190
|
+
*/
|
191
|
+
STATIC void
|
192
|
+
_write_overrides(lxw_content_types *self)
|
193
|
+
{
|
194
|
+
lxw_tuple *tuple;
|
195
|
+
|
196
|
+
STAILQ_FOREACH(tuple, self->overrides, list_pointers) {
|
197
|
+
_write_override(self, tuple->key, tuple->value);
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
/*
|
202
|
+
* Assemble and write the XML file.
|
203
|
+
*/
|
204
|
+
void
|
205
|
+
lxw_content_types_assemble_xml_file(lxw_content_types *self)
|
206
|
+
{
|
207
|
+
/* Write the XML declaration. */
|
208
|
+
_content_types_xml_declaration(self);
|
209
|
+
|
210
|
+
_write_types(self);
|
211
|
+
_write_defaults(self);
|
212
|
+
_write_overrides(self);
|
213
|
+
|
214
|
+
/* Close the content_types tag. */
|
215
|
+
lxw_xml_end_tag(self->file, "Types");
|
216
|
+
}
|
217
|
+
|
218
|
+
/*****************************************************************************
|
219
|
+
*
|
220
|
+
* Public functions.
|
221
|
+
*
|
222
|
+
****************************************************************************/
|
223
|
+
/*
|
224
|
+
* Add elements to the ContentTypes defaults.
|
225
|
+
*/
|
226
|
+
void
|
227
|
+
lxw_ct_add_default(lxw_content_types *self, const char *key,
|
228
|
+
const char *value)
|
229
|
+
{
|
230
|
+
lxw_tuple *tuple;
|
231
|
+
|
232
|
+
if (!key || !value)
|
233
|
+
return;
|
234
|
+
|
235
|
+
tuple = calloc(1, sizeof(lxw_tuple));
|
236
|
+
GOTO_LABEL_ON_MEM_ERROR(tuple, mem_error);
|
237
|
+
|
238
|
+
tuple->key = lxw_strdup(key);
|
239
|
+
GOTO_LABEL_ON_MEM_ERROR(tuple->key, mem_error);
|
240
|
+
|
241
|
+
tuple->value = lxw_strdup(value);
|
242
|
+
GOTO_LABEL_ON_MEM_ERROR(tuple->value, mem_error);
|
243
|
+
|
244
|
+
STAILQ_INSERT_TAIL(self->default_types, tuple, list_pointers);
|
245
|
+
|
246
|
+
return;
|
247
|
+
|
248
|
+
mem_error:
|
249
|
+
if (tuple) {
|
250
|
+
free(tuple->key);
|
251
|
+
free(tuple->value);
|
252
|
+
free(tuple);
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
/*
|
257
|
+
* Add elements to the ContentTypes overrides.
|
258
|
+
*/
|
259
|
+
void
|
260
|
+
lxw_ct_add_override(lxw_content_types *self, const char *key,
|
261
|
+
const char *value)
|
262
|
+
{
|
263
|
+
lxw_tuple *tuple;
|
264
|
+
|
265
|
+
if (!key || !value)
|
266
|
+
return;
|
267
|
+
|
268
|
+
tuple = calloc(1, sizeof(lxw_tuple));
|
269
|
+
GOTO_LABEL_ON_MEM_ERROR(tuple, mem_error);
|
270
|
+
|
271
|
+
tuple->key = lxw_strdup(key);
|
272
|
+
GOTO_LABEL_ON_MEM_ERROR(tuple->key, mem_error);
|
273
|
+
|
274
|
+
tuple->value = lxw_strdup(value);
|
275
|
+
GOTO_LABEL_ON_MEM_ERROR(tuple->value, mem_error);
|
276
|
+
|
277
|
+
STAILQ_INSERT_TAIL(self->overrides, tuple, list_pointers);
|
278
|
+
|
279
|
+
return;
|
280
|
+
|
281
|
+
mem_error:
|
282
|
+
if (tuple) {
|
283
|
+
free(tuple->key);
|
284
|
+
free(tuple->value);
|
285
|
+
free(tuple);
|
286
|
+
}
|
287
|
+
}
|
288
|
+
|
289
|
+
/*
|
290
|
+
* Add the name of a worksheet to the ContentTypes overrides.
|
291
|
+
*/
|
292
|
+
void
|
293
|
+
lxw_ct_add_worksheet_name(lxw_content_types *self, const char *name)
|
294
|
+
{
|
295
|
+
lxw_ct_add_override(self, name,
|
296
|
+
LXW_APP_DOCUMENT "spreadsheetml.worksheet+xml");
|
297
|
+
}
|
298
|
+
|
299
|
+
/*
|
300
|
+
* Add the name of a chart to the ContentTypes overrides.
|
301
|
+
*/
|
302
|
+
void
|
303
|
+
lxw_ct_add_chart_name(lxw_content_types *self, const char *name)
|
304
|
+
{
|
305
|
+
lxw_ct_add_override(self, name, LXW_APP_DOCUMENT "drawingml.chart+xml");
|
306
|
+
}
|
307
|
+
|
308
|
+
/*
|
309
|
+
* Add the name of a drawing to the ContentTypes overrides.
|
310
|
+
*/
|
311
|
+
void
|
312
|
+
lxw_ct_add_drawing_name(lxw_content_types *self, const char *name)
|
313
|
+
{
|
314
|
+
lxw_ct_add_override(self, name, LXW_APP_DOCUMENT "drawing+xml");
|
315
|
+
}
|
316
|
+
|
317
|
+
/*
|
318
|
+
* Add the sharedStrings link to the ContentTypes overrides.
|
319
|
+
*/
|
320
|
+
void
|
321
|
+
lxw_ct_add_shared_strings(lxw_content_types *self)
|
322
|
+
{
|
323
|
+
lxw_ct_add_override(self, "/xl/sharedStrings.xml",
|
324
|
+
LXW_APP_DOCUMENT "spreadsheetml.sharedStrings+xml");
|
325
|
+
}
|
326
|
+
|
327
|
+
/*
|
328
|
+
* Add the calcChain link to the ContentTypes overrides.
|
329
|
+
*/
|
330
|
+
void
|
331
|
+
lxw_ct_add_calc_chain(lxw_content_types *self)
|
332
|
+
{
|
333
|
+
lxw_ct_add_override(self, "/xl/calcChain.xml",
|
334
|
+
LXW_APP_DOCUMENT "spreadsheetml.calcChain+xml");
|
335
|
+
}
|
336
|
+
|
337
|
+
/*
|
338
|
+
* Add the custom properties to the ContentTypes overrides.
|
339
|
+
*/
|
340
|
+
void
|
341
|
+
lxw_ct_add_custom_properties(lxw_content_types *self)
|
342
|
+
{
|
343
|
+
lxw_ct_add_override(self, "/docProps/custom.xml",
|
344
|
+
LXW_APP_DOCUMENT "custom-properties+xml");
|
345
|
+
}
|
@@ -0,0 +1,293 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
* core - A library for creating Excel XLSX core files.
|
3
|
+
*
|
4
|
+
* Used in conjunction with the libxlsxwriter library.
|
5
|
+
*
|
6
|
+
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include "xlsxwriter/xmlwriter.h"
|
11
|
+
#include "xlsxwriter/core.h"
|
12
|
+
#include "xlsxwriter/utility.h"
|
13
|
+
|
14
|
+
/*
|
15
|
+
* Forward declarations.
|
16
|
+
*/
|
17
|
+
|
18
|
+
/*****************************************************************************
|
19
|
+
*
|
20
|
+
* Private functions.
|
21
|
+
*
|
22
|
+
****************************************************************************/
|
23
|
+
|
24
|
+
/*
|
25
|
+
* Create a new core object.
|
26
|
+
*/
|
27
|
+
lxw_core *
|
28
|
+
lxw_core_new()
|
29
|
+
{
|
30
|
+
lxw_core *core = calloc(1, sizeof(lxw_core));
|
31
|
+
GOTO_LABEL_ON_MEM_ERROR(core, mem_error);
|
32
|
+
|
33
|
+
return core;
|
34
|
+
|
35
|
+
mem_error:
|
36
|
+
lxw_core_free(core);
|
37
|
+
return NULL;
|
38
|
+
}
|
39
|
+
|
40
|
+
/*
|
41
|
+
* Free a core object.
|
42
|
+
*/
|
43
|
+
void
|
44
|
+
lxw_core_free(lxw_core *core)
|
45
|
+
{
|
46
|
+
if (!core)
|
47
|
+
return;
|
48
|
+
|
49
|
+
free(core);
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
* Convert a time_t struct to a ISO 8601 style "2010-01-01T00:00:00Z" date.
|
54
|
+
*/
|
55
|
+
static void
|
56
|
+
_localtime_to_iso8601_date(time_t *timer, char *str, size_t size)
|
57
|
+
{
|
58
|
+
struct tm *tmp_localtime;
|
59
|
+
time_t current_time = time(NULL);
|
60
|
+
|
61
|
+
if (*timer)
|
62
|
+
tmp_localtime = localtime(timer);
|
63
|
+
else
|
64
|
+
tmp_localtime = localtime(¤t_time);
|
65
|
+
|
66
|
+
strftime(str, size - 1, "%Y-%m-%dT%H:%M:%SZ", tmp_localtime);
|
67
|
+
}
|
68
|
+
|
69
|
+
/*****************************************************************************
|
70
|
+
*
|
71
|
+
* XML functions.
|
72
|
+
*
|
73
|
+
****************************************************************************/
|
74
|
+
|
75
|
+
/*
|
76
|
+
* Write the XML declaration.
|
77
|
+
*/
|
78
|
+
STATIC void
|
79
|
+
_core_xml_declaration(lxw_core *self)
|
80
|
+
{
|
81
|
+
lxw_xml_declaration(self->file);
|
82
|
+
}
|
83
|
+
|
84
|
+
/*
|
85
|
+
* Write the <cp:coreProperties> element.
|
86
|
+
*/
|
87
|
+
STATIC void
|
88
|
+
_write_cp_core_properties(lxw_core *self)
|
89
|
+
{
|
90
|
+
struct xml_attribute_list attributes;
|
91
|
+
struct xml_attribute *attribute;
|
92
|
+
|
93
|
+
LXW_INIT_ATTRIBUTES();
|
94
|
+
LXW_PUSH_ATTRIBUTES_STR("xmlns:cp",
|
95
|
+
"http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
|
96
|
+
LXW_PUSH_ATTRIBUTES_STR("xmlns:dc", "http://purl.org/dc/elements/1.1/");
|
97
|
+
LXW_PUSH_ATTRIBUTES_STR("xmlns:dcterms", "http://purl.org/dc/terms/");
|
98
|
+
LXW_PUSH_ATTRIBUTES_STR("xmlns:dcmitype", "http://purl.org/dc/dcmitype/");
|
99
|
+
LXW_PUSH_ATTRIBUTES_STR("xmlns:xsi",
|
100
|
+
"http://www.w3.org/2001/XMLSchema-instance");
|
101
|
+
|
102
|
+
lxw_xml_start_tag(self->file, "cp:coreProperties", &attributes);
|
103
|
+
|
104
|
+
LXW_FREE_ATTRIBUTES();
|
105
|
+
}
|
106
|
+
|
107
|
+
/*
|
108
|
+
* Write the <dc:creator> element.
|
109
|
+
*/
|
110
|
+
STATIC void
|
111
|
+
_write_dc_creator(lxw_core *self)
|
112
|
+
{
|
113
|
+
if (self->properties->author) {
|
114
|
+
lxw_xml_data_element(self->file, "dc:creator",
|
115
|
+
self->properties->author, NULL);
|
116
|
+
}
|
117
|
+
else {
|
118
|
+
lxw_xml_data_element(self->file, "dc:creator", "", NULL);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
/*
|
123
|
+
* Write the <cp:lastModifiedBy> element.
|
124
|
+
*/
|
125
|
+
STATIC void
|
126
|
+
_write_cp_last_modified_by(lxw_core *self)
|
127
|
+
{
|
128
|
+
if (self->properties->author) {
|
129
|
+
lxw_xml_data_element(self->file, "cp:lastModifiedBy",
|
130
|
+
self->properties->author, NULL);
|
131
|
+
}
|
132
|
+
else {
|
133
|
+
lxw_xml_data_element(self->file, "cp:lastModifiedBy", "", NULL);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
/*
|
138
|
+
* Write the <dcterms:created> element.
|
139
|
+
*/
|
140
|
+
STATIC void
|
141
|
+
_write_dcterms_created(lxw_core *self)
|
142
|
+
{
|
143
|
+
struct xml_attribute_list attributes;
|
144
|
+
struct xml_attribute *attribute;
|
145
|
+
char datetime[LXW_ATTR_32];
|
146
|
+
|
147
|
+
_localtime_to_iso8601_date(&self->properties->created, datetime,
|
148
|
+
LXW_ATTR_32);
|
149
|
+
|
150
|
+
LXW_INIT_ATTRIBUTES();
|
151
|
+
LXW_PUSH_ATTRIBUTES_STR("xsi:type", "dcterms:W3CDTF");
|
152
|
+
|
153
|
+
lxw_xml_data_element(self->file, "dcterms:created", datetime,
|
154
|
+
&attributes);
|
155
|
+
|
156
|
+
LXW_FREE_ATTRIBUTES();
|
157
|
+
}
|
158
|
+
|
159
|
+
/*
|
160
|
+
* Write the <dcterms:modified> element.
|
161
|
+
*/
|
162
|
+
STATIC void
|
163
|
+
_write_dcterms_modified(lxw_core *self)
|
164
|
+
{
|
165
|
+
struct xml_attribute_list attributes;
|
166
|
+
struct xml_attribute *attribute;
|
167
|
+
char datetime[LXW_ATTR_32];
|
168
|
+
|
169
|
+
_localtime_to_iso8601_date(&self->properties->created, datetime,
|
170
|
+
LXW_ATTR_32);
|
171
|
+
|
172
|
+
LXW_INIT_ATTRIBUTES();
|
173
|
+
LXW_PUSH_ATTRIBUTES_STR("xsi:type", "dcterms:W3CDTF");
|
174
|
+
|
175
|
+
lxw_xml_data_element(self->file, "dcterms:modified", datetime,
|
176
|
+
&attributes);
|
177
|
+
|
178
|
+
LXW_FREE_ATTRIBUTES();
|
179
|
+
}
|
180
|
+
|
181
|
+
/*
|
182
|
+
* Write the <dc:title> element.
|
183
|
+
*/
|
184
|
+
STATIC void
|
185
|
+
_write_dc_title(lxw_core *self)
|
186
|
+
{
|
187
|
+
if (!self->properties->title)
|
188
|
+
return;
|
189
|
+
|
190
|
+
lxw_xml_data_element(self->file, "dc:title", self->properties->title,
|
191
|
+
NULL);
|
192
|
+
}
|
193
|
+
|
194
|
+
/*
|
195
|
+
* Write the <dc:subject> element.
|
196
|
+
*/
|
197
|
+
STATIC void
|
198
|
+
_write_dc_subject(lxw_core *self)
|
199
|
+
{
|
200
|
+
if (!self->properties->subject)
|
201
|
+
return;
|
202
|
+
|
203
|
+
lxw_xml_data_element(self->file, "dc:subject", self->properties->subject,
|
204
|
+
NULL);
|
205
|
+
}
|
206
|
+
|
207
|
+
/*
|
208
|
+
* Write the <cp:keywords> element.
|
209
|
+
*/
|
210
|
+
STATIC void
|
211
|
+
_write_cp_keywords(lxw_core *self)
|
212
|
+
{
|
213
|
+
if (!self->properties->keywords)
|
214
|
+
return;
|
215
|
+
|
216
|
+
lxw_xml_data_element(self->file, "cp:keywords",
|
217
|
+
self->properties->keywords, NULL);
|
218
|
+
}
|
219
|
+
|
220
|
+
/*
|
221
|
+
* Write the <dc:description> element.
|
222
|
+
*/
|
223
|
+
STATIC void
|
224
|
+
_write_dc_description(lxw_core *self)
|
225
|
+
{
|
226
|
+
if (!self->properties->comments)
|
227
|
+
return;
|
228
|
+
|
229
|
+
lxw_xml_data_element(self->file, "dc:description",
|
230
|
+
self->properties->comments, NULL);
|
231
|
+
}
|
232
|
+
|
233
|
+
/*
|
234
|
+
* Write the <cp:category> element.
|
235
|
+
*/
|
236
|
+
STATIC void
|
237
|
+
_write_cp_category(lxw_core *self)
|
238
|
+
{
|
239
|
+
if (!self->properties->category)
|
240
|
+
return;
|
241
|
+
|
242
|
+
lxw_xml_data_element(self->file, "cp:category",
|
243
|
+
self->properties->category, NULL);
|
244
|
+
}
|
245
|
+
|
246
|
+
/*
|
247
|
+
* Write the <cp:contentStatus> element.
|
248
|
+
*/
|
249
|
+
STATIC void
|
250
|
+
_write_cp_content_status(lxw_core *self)
|
251
|
+
{
|
252
|
+
if (!self->properties->status)
|
253
|
+
return;
|
254
|
+
|
255
|
+
lxw_xml_data_element(self->file, "cp:contentStatus",
|
256
|
+
self->properties->status, NULL);
|
257
|
+
}
|
258
|
+
|
259
|
+
/*****************************************************************************
|
260
|
+
*
|
261
|
+
* XML file assembly functions.
|
262
|
+
*
|
263
|
+
****************************************************************************/
|
264
|
+
|
265
|
+
/*
|
266
|
+
* Assemble and write the XML file.
|
267
|
+
*/
|
268
|
+
void
|
269
|
+
lxw_core_assemble_xml_file(lxw_core *self)
|
270
|
+
{
|
271
|
+
/* Write the XML declaration. */
|
272
|
+
_core_xml_declaration(self);
|
273
|
+
|
274
|
+
_write_cp_core_properties(self);
|
275
|
+
_write_dc_title(self);
|
276
|
+
_write_dc_subject(self);
|
277
|
+
_write_dc_creator(self);
|
278
|
+
_write_cp_keywords(self);
|
279
|
+
_write_dc_description(self);
|
280
|
+
_write_cp_last_modified_by(self);
|
281
|
+
_write_dcterms_created(self);
|
282
|
+
_write_dcterms_modified(self);
|
283
|
+
_write_cp_category(self);
|
284
|
+
_write_cp_content_status(self);
|
285
|
+
|
286
|
+
lxw_xml_end_tag(self->file, "cp:coreProperties");
|
287
|
+
}
|
288
|
+
|
289
|
+
/*****************************************************************************
|
290
|
+
*
|
291
|
+
* Public functions.
|
292
|
+
*
|
293
|
+
****************************************************************************/
|