Index: trunk/src/main.c =================================================================== --- trunk/src/main.c (revision 1581) +++ trunk/src/main.c (revision 1582) @@ -1598,7 +1598,6 @@ uninit_strflags_buf(); uninit_strflags_layerlist(); - fp_free_children(&library); fp_uninit(); file_uninit(); funchash_uninit(); @@ -1643,6 +1642,8 @@ setbuf(stdout, 0); InitPaths(argv[0]); + fp_init(); + #ifdef LOCALEDIR bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); textdomain(GETTEXT_PACKAGE); Index: trunk/src/plug_footprint.c =================================================================== --- trunk/src/plug_footprint.c (revision 1581) +++ trunk/src/plug_footprint.c (revision 1582) @@ -87,9 +87,16 @@ return e == NULL ? NULL : e->key; } +void fp_init() +{ + library.type = LIB_DIR; + library.name = "/"; +} + void fp_uninit() { htsp_entry_t *e; + fp_free_children(&library); for (e = htsp_first(fp_tags); e; e = htsp_next(fp_tags, e)) free(e->key); htsp_free(fp_tags); @@ -226,12 +233,6 @@ return parent; } -void fp_free_children(library_t *parent) -{ - -} - - void fp_sort_children(library_t *parent) { /* int i; @@ -240,11 +241,54 @@ qsort(lib->Menu[i].Entry, lib->Menu[i].EntryN, sizeof(lib->Menu[i].Entry[0]), netnode_sort);*/ } -void fp_rmdir(library_t *dir) +void fp_free_entry(library_t *l) { + switch(l->type) { + case LIB_DIR: + fp_free_children(l); + vtlib_uninit(&(l->data.dir.children)); + break; + case LIB_FOOTPRINT: + if (l->data.fp.loc_info != NULL) + free(l->data.fp.loc_info); + break; + } + if (l->name != NULL) { + free(l->name); + l->name = NULL; + } + l->type = LIB_INVALID; +} +void fp_free_children(library_t *parent) +{ + int n; + library_t *l; + + assert(parent->type == LIB_DIR); + + for(n = 0, l = parent->data.dir.children.array; n < parent->data.dir.children.used; n++, l++) + fp_free_entry(l); + + vtlib_truncate(&(parent->data.dir.children), 0); } + +void fp_rmdir(library_t *dir) +{ + library_t *l, *parent = dir->parent; + int n; + fp_free_entry(dir); + if (parent != NULL) { + for(n = 0, l = parent->data.dir.children.array; n < parent->data.dir.children.used; n++,l++) { + if (l = dir) { + vtlib_remove(&(parent->data.dir.children), n, 1); + break; + } + } + } +} + /* Debug functions */ void fp_dump_dir(library_t *dir, int level) { Index: trunk/src/plug_footprint.h =================================================================== --- trunk/src/plug_footprint.h (revision 1581) +++ trunk/src/plug_footprint.h (revision 1582) @@ -36,7 +36,8 @@ /* Resolve a tag ID to a tag name */ const char *fp_tagname(const void *tagid); -/* Uninit the footprint lib, free tag key memory */ +/* init/uninit the footprint lib, free tag key memory */ +void fp_init(); void fp_uninit(); /**************************** API definition *********************************/ Index: trunk/src/vtlibrary.h =================================================================== --- trunk/src/vtlibrary.h (revision 1581) +++ trunk/src/vtlibrary.h (revision 1582) @@ -3,6 +3,7 @@ #include "global_objs.h" typedef enum { + LIB_INVALID, LIB_DIR, LIB_FOOTPRINT } library_type_t; Index: trunk/util/gsch2pcb.c =================================================================== --- trunk/util/gsch2pcb.c (revision 1581) +++ trunk/util/gsch2pcb.c (revision 1582) @@ -1247,6 +1247,8 @@ if (argc < 2) usage(); + fp_init(); + gadl_list_init(&schematics, sizeof(char *), NULL, NULL); gadl_list_init(&extra_gnetlist_arg_list, sizeof(char *), NULL, NULL); gadl_list_init(&extra_gnetlist_list, sizeof(char *), NULL, NULL);