Index: bom2.c =================================================================== --- bom2.c (revision 38003) +++ bom2.c (revision 38004) @@ -241,13 +241,10 @@ static void bom2_do_export(rnd_hid_t *hid, rnd_design_t *design, rnd_hid_attr_val_t *options, void *appspec) { - template_t templ; + template_t templ = {0}; char **tid; pcb_cam_t cam; - memset(&templ, 0, sizeof(templ)); - - gather_templates(); if (!options) { @@ -266,13 +263,8 @@ rnd_message(RND_MSG_ERROR, "export_bom2: invalid template selected\n"); return; } - templ.header = get_templ(*tid, "header"); - templ.item = get_templ(*tid, "item"); - templ.footer = get_templ(*tid, "footer"); - templ.subc2id = get_templ(*tid, "subc2id"); - templ.escape = get_templ(*tid, "escape"); - templ.needs_escape = get_templ(*tid, "needs_escape"); + bom_init_template(&templ, *tid); PrintBOM(&templ, options[HA_format].str); pcb_cam_end(&cam); } Index: lib_bom.c =================================================================== --- lib_bom.c (revision 38003) +++ lib_bom.c (revision 38004) @@ -47,6 +47,16 @@ return NULL; } +static void bom_init_template(template_t *templ, const char *tid) +{ + templ->header = get_templ(tid, "header"); + templ->item = get_templ(tid, "item"); + templ->footer = get_templ(tid, "footer"); + templ->subc2id = get_templ(tid, "subc2id"); + templ->escape = get_templ(tid, "escape"); + templ->needs_escape = get_templ(tid, "needs_escape"); +} + /*** subst ***/ static void append_clean(subst_ctx_t *ctx, int escape, gds_t *dst, const char *text) Index: lib_bom.h =================================================================== --- lib_bom.h (revision 38003) +++ lib_bom.h (revision 38004) @@ -1,10 +1,16 @@ -/*** formats ***/ +/*** formats & templates ***/ +typedef struct { + const char *header, *item, *footer, *subc2id; + const char *needs_escape; /* list of characters that need escaping */ + const char *escape; /* escape character */ +} template_t; + static vts0_t fmt_names; /* array of const char * long name of each format, pointing into the conf database */ static vts0_t fmt_ids; /* array of strdup'd short name (ID) of each format */ static void free_fmts(void); static void gather_templates(void); -static const char *get_templ(const char *tid, const char *type); +static void bom_init_template(template_t *templ, const char *tid); @@ -19,11 +25,6 @@ const char *escape; /* escape character or NULL for replacing with _*/ } subst_ctx_t; -typedef struct { - const char *header, *item, *footer, *subc2id; - const char *needs_escape; /* list of characters that need escaping */ - const char *escape; /* escape character */ -} template_t; typedef struct { pcb_subc_t *subc; /* one of the subcircuits picked randomly, for the attributes */