1 /**
2 * @file lv_xml.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_xml.h"
10 #if LV_USE_XML
11
12 #include "lv_xml_private.h"
13 #include "lv_xml_parser.h"
14 #include "lv_xml_style.h"
15 #include "lv_xml_component_private.h"
16 #include "lv_xml_base_types.h"
17
18 /*********************
19 * DEFINES
20 *********************/
21
22 /**********************
23 * TYPEDEFS
24 **********************/
25
26 /**********************
27 * STATIC PROTOTYPES
28 **********************/
29
30 /**********************
31 * STATIC VARIABLES
32 **********************/
33
34 /**********************
35 * MACROS
36 **********************/
37
38 /**********************
39 * GLOBAL FUNCTIONS
40 **********************/
41
lv_xml_parser_state_init(lv_xml_parser_state_t * state)42 void lv_xml_parser_state_init(lv_xml_parser_state_t * state)
43 {
44 lv_memzero(state, sizeof(lv_xml_parser_state_t));
45 lv_ll_init(&state->ctx.style_ll, sizeof(lv_xml_style_t));
46 lv_ll_init(&state->ctx.const_ll, sizeof(lv_xml_const_t));
47 lv_ll_init(&state->ctx.param_ll, sizeof(lv_xml_param_t));
48 lv_ll_init(&state->parent_ll, sizeof(lv_obj_t *));
49 }
50
lv_xml_parser_start_section(lv_xml_parser_state_t * state,const char * name)51 void lv_xml_parser_start_section(lv_xml_parser_state_t * state, const char * name)
52 {
53 /* Check for context changes */
54 if(lv_streq(name, "api")) {
55 state->section = LV_XML_PARSER_SECTION_API;
56 return;
57 }
58 else if(lv_streq(name, "consts")) {
59 state->section = LV_XML_PARSER_SECTION_CONSTS;
60 return;
61 }
62 else if(lv_streq(name, "styles")) {
63 state->section = LV_XML_PARSER_SECTION_STYLES;
64 return;
65 }
66 else if(lv_streq(name, "view")) {
67 state->section = LV_XML_PARSER_SECTION_VIEW;
68 return;
69 }
70 }
71
lv_xml_parser_end_section(lv_xml_parser_state_t * state,const char * name)72 void lv_xml_parser_end_section(lv_xml_parser_state_t * state, const char * name)
73 {
74
75 /* Reset context when leaving a block */
76 if(lv_streq(name, "params") ||
77 lv_streq(name, "consts") ||
78 lv_streq(name, "styles") ||
79 lv_streq(name, "view")) {
80 state->section = LV_XML_PARSER_SECTION_NONE;
81 }
82 }
83
lv_xml_state_get_parent(lv_xml_parser_state_t * state)84 void * lv_xml_state_get_parent(lv_xml_parser_state_t * state)
85 {
86 return state->parent;
87 }
88
lv_xml_state_get_item(lv_xml_parser_state_t * state)89 void * lv_xml_state_get_item(lv_xml_parser_state_t * state)
90 {
91 return state->item;
92 }
93
94 /**********************
95 * STATIC FUNCTIONS
96 **********************/
97
98 #endif /* LV_USE_XML */
99