Coverage Report

Created: 2025-12-28 06:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxlsxwriter/src/rich_value_rel.c
Line
Count
Source
1
/*****************************************************************************
2
 * rich_value_rel - A library for creating Excel XLSX rich_value_rel files.
3
 *
4
 * Used in conjunction with the libxlsxwriter library.
5
 *
6
 * Copyright 2014-2025, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
7
 *
8
 */
9
10
#include "xlsxwriter/xmlwriter.h"
11
#include "xlsxwriter/rich_value_rel.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 rich_value_rel object.
26
 */
27
lxw_rich_value_rel *
28
lxw_rich_value_rel_new(void)
29
0
{
30
0
    lxw_rich_value_rel *rich_value_rel =
31
0
        calloc(1, sizeof(lxw_rich_value_rel));
32
0
    GOTO_LABEL_ON_MEM_ERROR(rich_value_rel, mem_error);
33
34
0
    return rich_value_rel;
35
36
0
mem_error:
37
0
    lxw_rich_value_rel_free(rich_value_rel);
38
0
    return NULL;
39
0
}
40
41
/*
42
 * Free a rich_value_rel object.
43
 */
44
void
45
lxw_rich_value_rel_free(lxw_rich_value_rel *rich_value_rel)
46
0
{
47
0
    if (!rich_value_rel)
48
0
        return;
49
50
0
    free(rich_value_rel);
51
0
}
52
53
/*****************************************************************************
54
 *
55
 * XML functions.
56
 *
57
 ****************************************************************************/
58
59
/*
60
 * Write the XML declaration.
61
 */
62
STATIC void
63
_rich_value_rel_xml_declaration(lxw_rich_value_rel *self)
64
0
{
65
0
    lxw_xml_declaration(self->file);
66
0
}
67
68
/*****************************************************************************
69
 *
70
 * XML file assembly functions.
71
 *
72
 ****************************************************************************/
73
74
/*
75
 * Write the <rel> element.
76
 */
77
STATIC void
78
_rich_value_rel_write_rel(lxw_rich_value_rel *self, uint32_t rel_index)
79
0
{
80
0
    struct xml_attribute_list attributes;
81
0
    struct xml_attribute *attribute;
82
0
    char r_id[LXW_MAX_ATTRIBUTE_LENGTH];
83
84
0
    lxw_snprintf(r_id, LXW_ATTR_32, "rId%d", rel_index);
85
86
0
    LXW_INIT_ATTRIBUTES();
87
0
    LXW_PUSH_ATTRIBUTES_STR("r:id", r_id);
88
89
0
    lxw_xml_empty_tag(self->file, "rel", &attributes);
90
91
0
    LXW_FREE_ATTRIBUTES();
92
0
}
93
94
/*
95
 * Write the <richValueRels> element.
96
 */
97
STATIC void
98
_rich_value_rel_write_rich_value_rels(lxw_rich_value_rel *self)
99
0
{
100
0
    struct xml_attribute_list attributes;
101
0
    struct xml_attribute *attribute;
102
0
    char xmlns[] =
103
0
        "http://schemas.microsoft.com/office/spreadsheetml/2022/richvaluerel";
104
0
    char xmlns_r[] =
105
0
        "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
106
107
0
    LXW_INIT_ATTRIBUTES();
108
0
    LXW_PUSH_ATTRIBUTES_STR("xmlns", xmlns);
109
0
    LXW_PUSH_ATTRIBUTES_STR("xmlns:r", xmlns_r);
110
111
0
    lxw_xml_start_tag(self->file, "richValueRels", &attributes);
112
113
0
    LXW_FREE_ATTRIBUTES();
114
0
}
115
116
/*
117
 * Assemble and write the XML file.
118
 */
119
void
120
lxw_rich_value_rel_assemble_xml_file(lxw_rich_value_rel *self)
121
0
{
122
0
    uint32_t i;
123
124
    /* Write the XML declaration. */
125
0
    _rich_value_rel_xml_declaration(self);
126
127
    /* Write the richValueRels element. */
128
0
    _rich_value_rel_write_rich_value_rels(self);
129
130
0
    for (i = 1; i <= self->num_embedded_images; i++) {
131
        /* Write the rel element. */
132
0
        _rich_value_rel_write_rel(self, i);
133
0
    }
134
135
0
    lxw_xml_end_tag(self->file, "richValueRels");
136
0
}
137
138
/*****************************************************************************
139
 *
140
 * Public functions.
141
 *
142
 ****************************************************************************/