func (c *Cpp_generator) gen_cpp_file(cpp_file *string) bool { var text string tool.GetFileText(&c.M_cpp_templet_path, &text) if text == "" { tool.EchoErr("生成c++文件失败:找不到模板文件<%s>", c.M_cpp_templet_path) return false } text = strings.Replace(text, "%cfg%", c.M_cfgbase.Filename, -1) text = strings.Replace(text, "%structs_ctor%", splice(c.M_cfgbase, gen_struct_ctor, "\n\n"), -1) text = strings.Replace(text, "%structs_print%", splice(c.M_cfgbase, gen_struct_print, "\n\n"), -1) text = strings.Replace(text, "%load_funcs%", splice(c.M_cfgbase, gen_load_func, "\n"), -1) text = strings.Replace(text, "%clear_funcs%", splice(c.M_cfgbase, gen_clear_func, "\n"), -1) text = strings.Replace(text, "%find_funcs%", splice(c.M_cfgbase, gen_find_func, "\n"), -1) text = strings.Replace(text, "%mgr%", get_mgr_name(c.M_cfgbase), -1) text = strings.Replace(text, "%load_stmt%", splice(c.M_cfgbase, gen_call_load_func_stmt, "\n"), -1) text = strings.Replace(text, "%clear_stmt%", splice(c.M_cfgbase, gen_call_clear_func_stmt, "\n"), -1) text = strings.Replace(text, "%cfg_member%", get_member_comment_list(c.M_cfgbase), -1) enc := mahonia.NewEncoder("GB18030") if ret, ok := enc.ConvertStringOK(text); ok { // fmt.Println("UTF-8 to GBK: ", ret, " bytes: ", []byte(ret)) text = string(ret) } var is_overwrite_file_ok bool = tool.OverWriteFile(cpp_file, &text) return is_overwrite_file_ok }
func (x *Json_generator) Generate() { if false == tool.Exist(&x.M_json_dir) { tool.EchoErr("错误: <%s>路径不存在", x.M_json_dir) return } x.save_as_json() }
func (x *Xml_generator) Generate() { if false == tool.Exist(&x.M_xml_dir) { tool.EchoErr("错误: <%s>路径不存在", x.M_xml_dir) return } x.save_as_xml() }
func (c *Cpp_generator) Generate() { if false == tool.Exist(&c.M_to_dir) { tool.EchoErr("参数错误: 找不到指定的生成源文件的路径<%s>,请确认路径是否存在!", c.M_to_dir) return } if false == tool.Exist(&c.M_h_templet_path) { tool.EchoErr("参数错误: 找不到.h模板头文件<%s>", c.M_h_templet_path) return } if false == tool.Exist(&c.M_cpp_templet_path) { tool.EchoErr("参数错误: 找不到cpp模板源文件<%s>", c.M_cpp_templet_path) return } var filename string = tool.Strip_ext(tool.Strip_dir(c.M_cfgbase.Filename)) var h_file string = c.M_to_dir + "\\" + filename + ".h" var cpp_file string = c.M_to_dir + "\\" + filename + ".cpp" // 开始生成 // 1. c++的h头文件 if !c.gen_h_file(&h_file) { tool.EchoErr("生成h头文件<%s>失败", h_file) return } tool.EchoOk("生成h头文件<%s>成功", h_file) // 2. c++的cpp头文件 if !c.gen_cpp_file(&cpp_file) { tool.EchoErr("生成cpp源文件<%s>失败", cpp_file) return } tool.EchoOk("生成cpp源文件<%s>成功", cpp_file) }
// 解析excel文件 func ParseExcel(excel *string, parse_option Enum_parse_option, cfgbase *Cfgbase_t) bool { if false == tool.Exist(excel) { tool.EchoErr("错误: 找不到excel文件<%s>", *excel) return false } var errvec tool.Errvec_t if false == parse_excel(excel, cfgbase, &errvec, parse_option) { // tool.EchoErr("错误:解析<%s>文件失败,请确保该文件存在且未被打开", *excel) tool.Echo_errvec(&errvec) return false } return true }