2 * Copyright (c) 2012 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "string_encoder.h"
21 #include "metadata_handler.h"
22 #include "encode_layout.h"
23 #include "encode_input_mode_configure.h"
24 #include "encode_key_coordinate_frame.h"
25 #include "encode_label_properties_frame.h"
26 #include "encode_modifier_decoration.h"
27 #include "encode_default_configure.h"
28 #include "encode_magnifier_configure.h"
29 #include "encode_autopopup_configure.h"
30 #include "encode_nine_patch.h"
31 #include "xmlresource.h"
32 using namespace xmlresource;
35 String_Encoder actual_string_encoder;
36 IString_Encoder& string_encoder = actual_string_encoder;
38 static inline void show_usage() {
39 static const char* message = { "xml2binary: missing folder operand\n"
40 "-------------------------------------------------------\n"
41 "| Usage: xml2binary operand1 operand2 |\n"
42 "| operand1: the folder where xml text files located |\n"
43 "| operand2: the folder you want to place the bin file|\n"
44 "------------------------------------------------------- \n"};
45 printf("%s", message);
48 int main(const int argc, char* argv[]) {
54 char* xml_text_dir = NULL;
56 xml_text_dir = strdup(argv[1]);
59 if (0 != access(xml_text_dir, R_OK)) {
69 char* xml_bin_dir = NULL;
72 xml_bin_dir = strdup(argv[1]);
75 xml_bin_dir = strdup(argv[2]);
79 if (0 != access(xml_bin_dir, W_OK)) {
89 XMLResource *xmlresource = XMLResource::get_instance();
91 printf("Failed build xmlresource instance.\n");
95 xmlresource->set_resource_directory(xml_text_dir);
96 xmlresource->init("main_entry.xml");
98 static const char* metadata_path = "/usr/share/libscl-ui/metadata.xml";
99 if (0 != access(metadata_path, R_OK)) {
100 perror(metadata_path);
103 MetaData_Handler md_handler(metadata_path);
105 char bin_file[_POSIX_PATH_MAX] = {0};
106 snprintf(bin_file, _POSIX_PATH_MAX, "%s/%s", xml_bin_dir, "sclresource.bin");
108 FILE *fp = fopen(bin_file, "wb");
118 INPUT_MODE_CONFIGURE,
120 KEY_COORDINATE_FRAME,
121 LABEL_PROPERTIES_FRAME,
131 int size_table[MAX_DATATYPE] = {0};
132 int offset_table[MAX_DATATYPE] = {0};
133 const int SIZE_WIDTH = 8;
134 const int OFFSET_WIDTH = 8;
137 //Reserve for size_table
139 rs.reserve(MAX_DATATYPE * (SIZE_WIDTH + OFFSET_WIDTH));
140 int ret = rs.toFile(bin_file, offset);
147 offset_table[METADATA] = offset;
148 size_table[METADATA] = md_handler.encode(bin_file, offset);
149 offset_table[INPUT_MODE_CONFIGURE] = offset;
150 size_table[INPUT_MODE_CONFIGURE] = encode_input_mode_configure_file(bin_file, offset, md_handler);
152 offset_table[LAYOUT] = offset;
153 size_table[LAYOUT] = encode_layout_file(bin_file, offset, md_handler);
155 offset_table[KEY_COORDINATE_FRAME] = offset;
156 size_table[KEY_COORDINATE_FRAME] = encode_key_coordinate_frame_file(bin_file, offset, md_handler);
158 offset_table[LABEL_PROPERTIES_FRAME] = offset;
159 size_table[LABEL_PROPERTIES_FRAME] = encode_label_properties_frame_file(bin_file, offset, md_handler);
161 offset_table[MODIFIER_DECORATION] = offset;
162 size_table[MODIFIER_DECORATION] = encode_modifier_decoration_file(bin_file, offset, md_handler);
164 offset_table[DEFAULT_CONFIGURE] = offset;
165 size_table[DEFAULT_CONFIGURE] = encode_default_configure_file(bin_file, offset, md_handler);
167 offset_table[AUTOPOPUP_CONFIGURE] = offset;
168 size_table[AUTOPOPUP_CONFIGURE] = encode_autopopup_configure_file(bin_file, offset, md_handler);
170 offset_table[MAGNIFIER_CONFIGURE] = offset;
171 size_table[MAGNIFIER_CONFIGURE] = encode_magnifier_configure_file(bin_file, offset, md_handler);
173 offset_table[NINE_PATCH] = offset;
174 size_table[NINE_PATCH] = encode_nine_patch_file(bin_file, offset, md_handler);
176 offset_table[STRING] = offset;
177 actual_string_encoder.set_path(bin_file);
178 size_table[STRING] = string_encoder.encode(offset);
180 offset_table[ALLDATA] = 0;
181 size_table[ALLDATA]= offset;
185 for (int i = 0; i < MAX_DATATYPE; ++i) {
186 rs.put<sint_t>(size_table[i], SIZE_WIDTH);
187 rs.put<sint_t>(offset_table[i], OFFSET_WIDTH);
191 int ret = rs.toFile(bin_file, bin_offset);
198 printf("xml2binary succesfully.\n");