def ns_data_create(self): res = LXB.Res("lxb_ns_data_t", self.ns_res_data, False, self.ns_last_entry_name) res_prefix = LXB.Res("lxb_ns_prefix_data_t", self.ns_res_prefix_data, False, self.ns_last_entry_name) for name in self.ns_list: str_name = '' if len(self.ns[name]["link"]) > 16: str_name = ".u.long_str = (lxb_char_t *) \"{}\"".format( self.ns[name]["link"]) else: str_name = ".u.short_str = \"{}\"".format( self.ns[name]["link"]) res.append( "{{{{{}, .length = {}, .next = NULL}}, {}, 1, true}}".format( str_name, len(self.ns[name]["link"]), self.ns[name]["c_name"])) if len(self.ns[name]["name"]) > 16: str_name = ".u.long_str = (lxb_char_t *) \"{}\"".format( self.ns[name]["name"].lower()) else: str_name = ".u.short_str = \"{}\"".format( self.ns[name]["name"].lower()) res_prefix.append( "{{{{{}, .length = {}, .next = NULL}}, {}, 1, true}}".format( str_name, len(self.ns[name]["name"]), self.ns[name]["c_name"])) return [res.create(1, True), res_prefix.create(1, True)]
def tag_data_create_default(self): res = LXB.Res("lxb_tag_data_t", self.tag_res_data, False, self.tag_last_entry_name) res_upper = LXB.Res("lxb_tag_data_t", self.tag_res_data_upper, False, self.tag_last_entry_name) for entry in self.enum_list: # res.append("{{{{.u.long_str = (lxb_char_t *) \"{}\", .length = {}, .next = NULL}},\n (const lxb_char_t *) \"{}\", {}, 1, true}}".format(entry["name"], len(entry["name"]), entry["name"].upper(), entry["c_name"])) if len(entry["name"]) > 16: res.append( "{{{{.u.long_str = (lxb_char_t *) \"{}\", .length = {}, .next = NULL}}, {}, 1, true}}" .format(entry["name"], len(entry["name"]), entry["c_name"])) res_upper.append( "{{{{.u.long_str = (lxb_char_t *) \"{}\", .length = {}, .next = NULL}}, {}, 1, true}}" .format(entry["name"].upper(), len(entry["name"]), entry["c_name"])) else: res.append( "{{{{.u.short_str = \"{}\", .length = {}, .next = NULL}}, {}, 1, true}}" .format(entry["name"], len(entry["name"]), entry["c_name"])) res_upper.append( "{{{{.u.short_str = \"{}\", .length = {}, .next = NULL}}, {}, 1, true}}" .format(entry["name"].upper(), len(entry["name"]), entry["c_name"])) return [res.create(1, True), res_upper.create(1, True)]
def make(self, name, temp_file_h, temp_file_c, save_to, save_to_c): tags = self.tags.enum_list res = LXB.Res("lxb_html_tree_insertion_mode_f", "{}_{}_res".format(self.prefix, name), False) res_closed = LXB.Res("lxb_html_tree_insertion_mode_f", "{}_{}_closed_res".format(self.prefix, name), False) for entry in tags: res.append("{}_{}_{} /* {} */".format(self.prefix, name, self.anything_else, entry["c_name"])) res_closed.append("{}_{}_{} /* {} */".format(self.prefix, name, self.anything_else_closed, entry["c_name"])) res_data = res.create(1, True) res_closed_data = res_closed.create(1, True) lxb_temp = LXB.Temp(temp_file_h, save_to) lxb_temp.pattern_append("%%NAME%%", name.upper()) lxb_temp.pattern_append("%%HASH%%", self.tags.enum_hash_ifdef()) lxb_temp.pattern_append("%%BODY-OPEN%%", ''.join(res_data)) lxb_temp.pattern_append("%%BODY-CLOSED%%", ''.join(res_closed_data)) lxb_temp.build() lxb_temp.save() lxb_temp = LXB.Temp(temp_file_c, save_to_c) lxb_temp.pattern_append("%%NAME%%", name) lxb_temp.build() lxb_temp.save()
def make_flat_index(self, name, values): buffer_size = self.buffer_size(values) print("Flat buffer size:", buffer_size) res = LXB.Res(self.flat_index_typename, self.make_var_name(name) + '[{}]'.format(buffer_size), False, None, 'LXB_API') for idx in range(0, buffer_size): if idx in values: entries = values[idx] res.append('{{(lxb_char_t *) "{}", {}, {}}}'.format( toHex(entries[2].decode('utf-8')), entries[3], entries[1].decode('utf-8'))) res.append('/* {} */'.format(entries[4].decode('utf-8')), is_comment=True) else: res.append('{NULL, 0, LXB_ENCODING_ERROR_CODEPOINT}') res.append('/* Not defined */', is_comment=True) buf = res.create() return buf
def tag_data_create_default(self): result = [] res = LXB.Res("lxb_tag_data_t", self.tag_res_data, True, self.tag_last_entry_name) for entry in self.enum_list: res.append("{{(const lxb_char_t *) \"{}\", (const lxb_char_t *) \"{}\", {}, {}}}".format(entry["name"], entry["name"].upper(), len(entry["name"]), entry["c_name"])) return res.create(1, False)
def ns_data_create(self): result = [] res = LXB.Res("lxb_ns_data_t", self.ns_res_data, True, self.ns_last_entry_name) for name in self.ns_list: res.append("{{\"{0}\", \"{1}\", {2}, \"{3}\", {4}, {5}}}".format( self.ns[name]["name"], self.ns[name]["name"].lower(), len(self.ns[name]["name"]), self.ns[name]["link"], len(self.ns[name]["link"]), self.ns[name]["c_name"])) return res.create(1, False)
def make_range_index(self, name, values): res = LXB.Res(self.range_index_typename, self.make_range_name(name) + '[{}]'.format(len(values)), False, None, 'LXB_API') for entry in values: res.append('{{{}, {}}}'.format(entry[0].decode('utf-8'), entry[1].decode('utf-8'))) buf = res.create(rate=4) return buf
def make_data(self, data_name): res = LXB.Res( self.data_typename, data_name + '[{}]'.format(self.make_name_upper(self.last_entry_name)), False, None, '') res.append( '{{{}, {}, {},\n {}, {}, (lxb_char_t *) "DEFAULT"}}'.format( self.make_name_upper('DEFAULT'), self.make_function_name("DEFAULT", 'encode'), self.make_function_name("DEFAULT", 'decode'), self.make_function_name("DEFAULT_SINGLE", 'encode'), self.make_function_name("DEFAULT_SINGLE", 'decode'))) res.append( '{{{}, {}, {},\n {}, {}, (lxb_char_t *) "AUTO"}}'.format( self.make_name_upper('AUTO'), self.make_function_name("AUTO", 'encode'), self.make_function_name("AUTO", 'decode'), self.make_function_name("AUTO_SINGLE", 'encode'), self.make_function_name("AUTO_SINGLE", 'decode'))) res.append( '{{{}, {}, {},\n {}, {}, (lxb_char_t *) "UNDEFINED"}}'.format( self.make_name_upper('UNDEFINED'), self.make_function_name("UNDEFINED", 'encode'), self.make_function_name("UNDEFINED", 'decode'), self.make_function_name("UNDEFINED_SINGLE", 'encode'), self.make_function_name("UNDEFINED_SINGLE", 'decode'))) for encode in self.strict: name = encode['name'] value = '{{{}, {}, {},\n {}, {}, (lxb_char_t *) "{}"}}'.format( self.make_name_upper(name), self.make_function_name(name, 'encode'), self.make_function_name(name, 'decode'), self.make_function_name(name + '_single', 'encode'), self.make_function_name(name + '_single', 'decode'), name) res.append(value) buf = res.create(rate=1) if not self.silent: print(''.join(buf)) return buf
def data_create(self): res = LXB.Res("lxb_dom_attr_data_t", self.data_name, False, self.make_enum_name("_LAST_ENTRY")) for name in attributes_name: variable = ".u.short_str = \"{}\"".format(name) if len(name) > 16: variable = ".u.long_str = (lxb_char_t *) \"{}\"".format(name) if name == '_undef': res.append( "{{{{.u.short_str = \"{}\", .length = {}, .next = NULL}},\n {}, 1, true}}" .format("#undef", len("#undef"), self.make_enum_name("_undef"))) else: res.append( "{{{{{}, .length = {}, .next = NULL}},\n {}, 1, true}}" .format(variable, len(name), self.make_enum_name(name))) return res.create(rate=1, is_const=True)
def tag_data_create_html(self): result = [] cats = LXB.Res("lxb_html_tag_category_t", "lxb_html_tag_res_cats", True, [self.tag_last_entry_name, self.ns_last_entry_name]) constructor = LXB.Res( "lxb_dom_interface_constructor_f", "lxb_html_interface_res_constructors", True, [self.tag_last_entry_name, self.ns_last_entry_name]) destructor = LXB.Res( "lxb_dom_interface_destructor_f", "lxb_html_interface_res_destructor", True, [self.tag_last_entry_name, self.ns_last_entry_name]) svg_fixname = LXB.Res("lxb_html_tag_fixname_t", "lxb_html_tag_res_fixname_svg", True, [self.tag_last_entry_name]) fixname = [] for idx in range(0, len(self.ns_list)): fixname.append([]) for entry in self.enum_list: ns = [" "] interface = [" "] interface_del = [" "] for idx in range(0, len(entry["ns"]) - 1): if len(entry["ns"][idx]) == 0: ns.append(self.cat_empty) ns.append(", ") else: ns.append("\n |".join(entry["ns"][idx])) if len(entry["ns"][idx]) > 1 and idx % 2 != 1: ns.append(",\n ") else: ns.append(",") interface.append("({}) {},".format(self.creation_interface, entry["interface"][idx])) interface.append("\n ") interface_del.append("({}) {},".format( self.deletion_interface, entry["interface_del"][idx])) interface_del.append("\n ") fixname[idx].append("/* {} */\n ".format(entry["c_name"])) if entry["fixname"][idx] != "NULL": fixname[idx].append( "{{(const lxb_char_t *) \"{}\", {}}},".format( entry["fixname"][idx], len(entry["fixname"][idx]))) else: fixname[idx].append("{NULL, 0},") fixname[idx].append("\n ") if idx % 2 == 1: ns.append("\n ") if len(entry["ns"][-1]) == 0: ns.append(self.cat_empty) else: ns.append("\n|".join(entry["ns"][-1])) interface.append("({}) {}".format(self.creation_interface, entry["interface"][-1])) interface_del.append("({}) {}".format(self.deletion_interface, entry["interface_del"][-1])) fixname[-1].append("/* {} */\n ".format(entry["c_name"])) if entry["fixname"][-1] != "NULL": fixname[-1].append( "{{(const lxb_char_t *) \"{}\", {}}},".format( entry["fixname"][-1], len(entry["fixname"][-1]))) else: fixname[-1].append("{NULL, 0},") # res.append("{{(const lxb_char_t *) \"{}\", {}, {},\n {{\n{}\n }},\n {{\n{}\n }},\n {{\n{}\n }}\n }}" # .format(entry["name"], len(entry["name"]), entry["c_name"], "".join(ns), "".join(interface), "".join(fixname))) cats.append("/* {} */".format(entry["c_name"]), True) constructor.append("/* {} */".format(entry["c_name"]), True) destructor.append("/* {} */".format(entry["c_name"]), True) cats.append("{{\n{}\n }}".format("".join(ns))) constructor.append("{{\n{}\n }}".format("".join(interface))) destructor.append("{{\n{}\n }}".format("".join(interface_del))) svg_fixname.append("{}".format("".join( fixname[4]))) # 4 == SVG namespace return [ cats.create(1, False), self.interfaces.make_includes(), constructor.create(1, False), destructor.create(1, False), svg_fixname.create(1, False) ]
def make(self, pseude_name, arr, names = None): idx = 0 state = "" entries = [] type_data_name = "" state_declaration = [] state_bodies = [] data_name = "lxb_css_selectors_pseudo_data_{}".format(pseude_name) make_func = names != None if make_func == True: type_data_name = "lxb_css_selectors_pseudo_data_func_t" else: type_data_name = "lxb_css_selectors_pseudo_data_t" res = LXB.Res(type_data_name, data_name, False, self.make_enum_name(pseude_name, "_LAST_ENTRY")) frmt_enum = LXB.FormatEnum("{}{}_id_t".format(self.prefix.lower(), self.make_name(pseude_name))) for name in arr: enum_name = self.make_enum_name(pseude_name, name) frmt_enum.append(enum_name, "0x{0:04x}".format(idx)) idx += 1 if make_func == True: state = "lxb_css_selectors_state_{}_{}".format(self.make_name(pseude_name), self.make_name(name)) state_declaration.append(self.make_state_declaration(state)) state_bodies.append(self.make_state_body(state)) success = pseudo_default_state_success can_empty = False combinator = "CLOSE" if name in names: success = names[name][0] can_empty = names[name][1] combinator = names[name][2] if name == "_undef": res.append("{{(lxb_char_t *) \"#undef\", 6, {},\n {}, {}," " {},\n {}}}".format(enum_name, success, state, str(can_empty).lower(), self.make_combinator_name(combinator))) continue else: res.append("{{(lxb_char_t *) \"{}\", {}, {},\n {}, {}," " {},\n {}}}".format(name, len(name), enum_name, success, state, str(can_empty).lower(), self.make_combinator_name(combinator))) else: if name == "_undef": res.append("{{(lxb_char_t *) \"#undef\", 6, {}}}".format(enum_name)) continue else: res.append("{{(lxb_char_t *) \"{}\", {}, {}}}".format(name, len(name), enum_name)) entries.append({"key": name, "value": "(void *) &{}[{}]".format(data_name, enum_name)}) frmt_enum.append(self.make_enum_name(pseude_name, "_LAST_ENTRY"), "0x{0:04x}".format(idx)) shs = LXB.SHS(entries, 0, False) test = shs.make_test(5, 256) shs.table_size_set(test[0][2]) result_enum = frmt_enum.build() result_res = res.create(rate = 1, is_const = True) result_sh = shs.create("lxb_css_selectors_{}_shs".format(pseude_name), rate = 1) print(self.shs_stat(shs)) return [result_enum, result_res, result_sh, state_declaration, state_bodies]