Index: bom2.c =================================================================== --- bom2.c (revision 38009) +++ bom2.c (revision 38010) @@ -9,9 +9,7 @@ #include "data.h" #include "data_it.h" #include -#include #include -#include #include #include "bom2_conf.h" @@ -58,37 +56,14 @@ static const rnd_export_opt_t *bom2_get_export_options(rnd_hid_t *hid, int *n, rnd_design_t *dsg, void *appspec) { - rnd_conf_listitem_t *li; const char *val = bom2_values[HA_bom2file].str; - int idx; /* load all formats from the config */ fmt_names.used = 0; fmt_ids.used = 0; - free_fmts(); - rnd_conf_loop_list(&conf_bom2.plugins.export_bom2.templates, li, idx) { - char id[MAX_TEMP_NAME_LEN]; - const char *sep = strchr(li->name, '.'); - int len; + build_fmts(&conf_bom2.plugins.export_bom2.templates); - if (sep == NULL) { - rnd_message(RND_MSG_ERROR, "export_bom2: ignoring invalid template name (missing period): '%s'\n", li->name); - continue; - } - if (strcmp(sep+1, "name") != 0) - continue; - len = sep - li->name; - if (len > sizeof(id)-1) { - rnd_message(RND_MSG_ERROR, "export_bom2: ignoring invalid template name (too long): '%s'\n", li->name); - continue; - } - memcpy(id, li->name, len); - id[len] = '\0'; - vts0_append(&fmt_names, (char *)li->payload); - vts0_append(&fmt_ids, rnd_strdup(id)); - } - if (fmt_names.used == 0) { rnd_message(RND_MSG_ERROR, "export_bom2: can not set up export options: no template available\n"); return NULL; Index: lib_bom.c =================================================================== --- lib_bom.c (revision 38009) +++ lib_bom.c (revision 38010) @@ -10,6 +10,36 @@ } } +static void build_fmts(const rnd_conflist_t *templates) +{ + rnd_conf_listitem_t *li; + int idx; + + free_fmts(); + + rnd_conf_loop_list(templates, li, idx) { + char id[MAX_TEMP_NAME_LEN]; + const char *sep = strchr(li->name, '.'); + int len; + + if (sep == NULL) { + rnd_message(RND_MSG_ERROR, "export_bom2: ignoring invalid template name (missing period): '%s'\n", li->name); + continue; + } + if (strcmp(sep+1, "name") != 0) + continue; + len = sep - li->name; + if (len > sizeof(id)-1) { + rnd_message(RND_MSG_ERROR, "export_bom2: ignoring invalid template name (too long): '%s'\n", li->name); + continue; + } + memcpy(id, li->name, len); + id[len] = '\0'; + vts0_append(&fmt_names, (char *)li->payload); + vts0_append(&fmt_ids, rnd_strdup(id)); + } +} + static void gather_templates(void) { rnd_conf_listitem_t *i; Index: lib_bom.h =================================================================== --- lib_bom.h (revision 38009) +++ lib_bom.h (revision 38010) @@ -6,6 +6,8 @@ #include #include #include +#include +#include /*** formats & templates ***/ typedef struct { @@ -17,6 +19,8 @@ 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 build_fmts(const rnd_conflist_t *templates); + static void free_fmts(void); static void gather_templates(void); static void bom_init_template(template_t *templ, const char *tid);