Index: src/create.c =================================================================== --- src/create.c (revision 298) +++ src/create.c (revision 299) @@ -972,7 +972,7 @@ char temp[64]; sprintf (temp, " %s", name); - menu = GetLibraryMenuMemory (lib); + menu = GetLibraryMenuMemory (lib, NULL); menu->Name = strdup (temp); menu->flag = 1; /* net is enabled by default */ if (style == NULL || NSTRCMP ("(unknown)", style) == 0) Index: src/file.c =================================================================== --- src/file.c (revision 298) +++ src/file.c (revision 299) @@ -1174,6 +1174,7 @@ typedef struct { LibraryMenuTypePtr menu; list_dir_t *subdirs; + int children; } list_st_t; @@ -1196,6 +1197,7 @@ return 0; } + l->children++; entry = GetLibraryEntryMemory (l->menu); /* @@ -1227,13 +1229,15 @@ LibraryMenuTypePtr menu = NULL; /* Pointer to PCB's library menu structure */ list_st_t l; list_dir_t *d, *nextd; - char working[MAXPATHLEN + 1]; /* String holding abs path to working dir */ + char working[MAXPATHLEN + 1]; /* String holding abs path to working dir */ + int menuidx; sprintf(working, "%s%c%s", toppath, PCB_DIR_SEPARATOR_C, subdir); /* Get pointer to memory holding menu */ - menu = GetLibraryMenuMemory (&Library); + menu = GetLibraryMenuMemory (&Library, &menuidx); + /* Populate menuname and path vars */ menu->Name = strdup (pcb_basename(subdir)); menu->directory = strdup (pcb_basename(toppath)); @@ -1240,6 +1244,7 @@ l.menu = menu; l.subdirs = NULL; + l.children = 0; pcb_fp_list(working, 0, list_cb, &l); @@ -1246,12 +1251,16 @@ /* now recurse to each subdirectory mapped in the previous call; by now we don't care if menu is ruined by the realloc() in GetLibraryMenuMemory() */ for(d = l.subdirs; d != NULL; d = nextd) { - LoadNewlibFootprintsFromDir(d->subdir, d->parent); + l.children+=LoadNewlibFootprintsFromDir(d->subdir, d->parent); nextd = d->next; free(d->subdir); free(d->parent); free(d); } + if (l.children == 0) { + DeleteLibraryMenuMemory (&Library, menuidx); + } + return l.children; } @@ -1414,7 +1423,7 @@ i++; if (kind == 0) { - menu = GetLibraryMenuMemory (&PCB->NetlistLib); + menu = GetLibraryMenuMemory (&PCB->NetlistLib, NULL); menu->Name = strdup (temp); menu->flag = 1; kind++; Index: src/mymem.c =================================================================== --- src/mymem.c (revision 298) +++ src/mymem.c (revision 299) @@ -428,7 +428,7 @@ * get next slot for a library menu, allocates memory if necessary */ LibraryMenuTypePtr -GetLibraryMenuMemory (LibraryTypePtr lib) +GetLibraryMenuMemory (LibraryTypePtr lib, int *idx) { LibraryMenuTypePtr menu = lib->Menu; @@ -441,9 +441,20 @@ memset (menu + lib->MenuN, 0, STEP_LIBRARYMENU * sizeof (LibraryMenuType)); } + if (idx != NULL) + *idx = lib->MenuN; return (menu + lib->MenuN++); } +void +DeleteLibraryMenuMemory (LibraryTypePtr lib, int menuidx) +{ + LibraryMenuTypePtr menu = lib->Menu; + lib->MenuN--; + memmove(menu + menuidx, menu + menuidx+1, sizeof (LibraryMenuType) * (lib->MenuN-menuidx)); + +} + /* --------------------------------------------------------------------------- * get next slot for a library entry, allocates memory if necessary */ Index: src/mymem.h =================================================================== --- src/mymem.h (revision 298) +++ src/mymem.h (revision 299) @@ -81,7 +81,7 @@ ConnectionTypePtr GetConnectionMemory (NetTypePtr); NetTypePtr GetNetMemory (NetListTypePtr); NetListTypePtr GetNetListMemory (NetListListTypePtr); -LibraryMenuTypePtr GetLibraryMenuMemory (LibraryTypePtr); +LibraryMenuTypePtr GetLibraryMenuMemory (LibraryTypePtr, int *idx); LibraryEntryTypePtr GetLibraryEntryMemory (LibraryMenuTypePtr); ElementTypeHandle GetDrillElementMemory (DrillTypePtr); PinTypeHandle GetDrillPinMemory (DrillTypePtr); @@ -97,6 +97,7 @@ void FreeDataMemory (DataTypePtr); void FreeLibraryMemory (LibraryTypePtr); void FreePointerListMemory (PointerListTypePtr); +void DeleteLibraryMenuMemory (LibraryTypePtr lib, int menuidx); void DSAddCharacter (DynamicStringTypePtr, char); void DSAddString (DynamicStringTypePtr, const char *); void DSClearString (DynamicStringTypePtr); Index: src/rats.c =================================================================== --- src/rats.c (revision 298) +++ src/rats.c (revision 299) @@ -1001,7 +1001,7 @@ sprintf (ratname, " ratDrawn%i", ++ratDrawn); } - menu = GetLibraryMenuMemory (&PCB->NetlistLib); + menu = GetLibraryMenuMemory (&PCB->NetlistLib, NULL); menu->Name = strdup (ratname); entry = GetLibraryEntryMemory (menu); entry->ListEntry = strdup (name1);